voltergeist

voltergeist, draft v1

This page is SPEC.md from the repository.

A binary wire format for control voltage (continuous sampled signals) and events (gates, triggers, notes) between machines, over UDP datagrams or WebSocket binary messages. One frame is one datagram or one message. On a byte stream (TCP, serial) each frame carries a length prefix (section 1.1).

Status: draft v1, 2026-12-06; the owner's answers to the open questions are in section 10, six rules the C core asked to have stated are in section 11, and two v1.x additions (MIDI frames, safety limits) in section 12. Nothing is frozen until the owner says so. There is no negotiation: a reader accepts version 1 and rejects anything else (section 2.3).

The words MUST, MUST NOT, SHOULD and MAY are used as in RFC 2119.

1. Conventions

1.1 Byte streams

A transport that carries bytes rather than messages (TCP without WebSocket, a serial line) puts each frame's length in front of it as a u16, little endian, and the frame follows:

offsetsizefield
0u16L, the frame's length in bytes, 16 to 65535
2L bytesone frame, read exactly as a datagram of length L

A reader collects bytes until it has L of them, whatever the chunks the transport hands it. An L under 16 cannot be a frame, and a byte stream cannot be resynchronised after one, so the reader stops reading that connection. A frame longer than 65535 bytes does not exist (section 1.2). Datagrams and WebSocket messages never carry the prefix.

1.2 Frame size

A frame is at most 65535 bytes, on every transport, so that every frame fits the byte stream's prefix. A writer MUST NOT produce a longer one and a reader rejects one (the reference says length), whatever its type, unknown types included. The fields allow more (a SAMPLES frame of 255 channels and 255 samples of f32 would be 260,124 bytes); such a frame is split into several.

Advice, not a rule: on UDP keep a frame under about 1,200 bytes, so that it fits one datagram on any path without IP fragmentation (a fragmented datagram is lost when any fragment is). Section 7 gives the sizes that fit.

2. The head (every frame, 16 bytes)

offsetsizefieldmeaning
0u8version and flagshigh 4 bits: version, 1. Low 4 bits: flags, below
1u8typethe frame type, section 3
2u16streamthe stream id. One per stream, as RTP's SSRC. A sender MAY have several streams, and picks each id at random when it starts
4u32seqfor SAMPLES the index of the first sample in the frame, for EVENTS of the first event; samples and events are numbered one by one and wrap at 2^32 (49.7 days at 1 kHz; a receiver extends it past the wrap). Other types say what they put here
8f64clockfor SAMPLES and EVENTS the clock of the first sample or event in the frame, on the sender's clock, in microseconds. Other types say what they put here. MUST be finite

Stream ids. A sender picks each stream id at random from 1 to 65535 when it starts. A receiver keys streams by source and id, so two senders on one id only clash where sources merge, at a relay or at a receiver that is told one source. A receiver or relay that sees two senders on one id tells the later one by means outside v1 (a relay's own message, or a type added in v1.x), and that sender picks a new id and sends its MAP again.

Flags (byte 0, low nibble):

bitvaluenamemeaning
00x1Xan extension follows the head (section 2.1)
10x2Iirregular timing: a SAMPLES frame carries one offset per sample
20x4Rredundant: the first r samples or events repeat the end of the previous frame
30x8reservedMUST be 0. A reader rejects a frame with it set

I is allowed only on SAMPLES, R only on SAMPLES and EVENTS. Either flag on another known type is a reject.

On a type the reader does not know (section 2.2) the reader checks the head and nothing after it: the frame size (section 1.2), the version, the reserved bit 3 (a reject), the clock (finite), and with X the extension's length (its words must fit in the frame, else a reject). I and R are not checked and the body is not read.

So byte 0 reads 0x10 for a plain frame, 0x12 irregular, 0x14 redundant, 0x16 both, 0x11 with an extension.

2.1 Extension (only when X is set)

offsetsizefield
16u16extension type
18u16length in 32 bit words, w
204w bytesextension data

The body starts at B = 20 + 4w. A reader that does not know the extension type skips its data and reads the body as usual (RTP's idea, RFC 3550 5.3.1). There is at most one extension block per frame; an extension type that needs several items defines its own layout inside its data. Without X, B = 16.

extension typenamestatus
0unassigned
1authreserved: a key id and a MAC over the frame. The layout is not defined yet
2 to 65535unassigned

Authentication. v1 has none and no encryption. Type 1 is reserved so that a key id and a MAC can be added in v1.x without a version change; a reader that does not implement it skips it like any extension and reads the frame. Until it is defined, senders and receivers run on trusted networks, or behind a relay that holds keys of its own outside the frame (the v2in relay put an 8 byte key in front of each datagram).

2.2 Unknown types

A frame whose version is 1 and whose type the reader does not know is skipped, not rejected: the reader ignores it and keeps the connection. This lets v1.x add types without a version change.

2.3 Versions

3. Types

typenamesectionkind
0reserved
1SAMPLES4.1data
2EVENTS4.2data
3MAP4.3data
4MIDI4.4data, v1.x
5 to 15unassigned data types
16HELLO5.1transport
17PING5.2transport
18PONG5.3transport
19CLOCK5.4transport
20REPORT5.5transport
21 to 255unassigned

The data types are the format. The transport messages (section 5) are a separate, optional layer: a relay, a file recorder or a receiver that is told its offset another way does not need them.

4. Data types

4.1 SAMPLES (type 1)

k consecutive samples of n channels. Body at B:

offsetsizefieldrule
B+0u8n, channels1 to 255
B+1u8format1 f32, 2 i16, 3 i24; anything else is a reject
B+2u16map id1 to 65535 names a MAP; 0 means no map, raw values (below)
B+4u8k, samples in this frame, repeats included1 to 255
B+5u8r, how many of the k are repeats0 unless R; with R, 1 to floor(k/2)
B+6u16reservedMUST be 0 on send; a reader ignores it
B+84k bytes, only with Ik x i32 offsetsthe first MUST be 0; never decreasing
thenk x n x sizevaluessample major: sample 0 channel 0, sample 0 channel 1, ...

The length MUST be exactly B + 8 + (I ? 4k : 0) + k x n x size, where size is 4, 2 or 3.

Size at 1 kHz, 4 channels f32, k 10: 16 + 8 + 160 = 184 bytes a frame, 100 frames a second.

4.2 EVENTS (type 2)

Gates, triggers and notes at exact times, on their own stream id. Body at B:

offsetsizefieldrule
B+0u8m, events in this frame, repeats included1 to 255
B+1u8r, repeatsas for SAMPLES: 0 unless R; with R 1 to floor(m/2)
B+2u16map id1 to 65535 names a MAP; 0 means no map, and the channel is just an index
B+4m x 12eventsbelow

Each event, 12 bytes:

offsetsizefieldrule
0i32offset, microseconds from the head clock0 or more, never decreasing within the frame
4u8channelindex into the map's channels
5u8kind1 gate, 2 trigger, 3 note on, 4 note off; 0 is a reject; 5 to 255 are valid and ignored by a player that does not know them
6u16notethe note number for kinds 3 and 4, else 0
8f32valuegate: 0 off, anything else on at that level; trigger: amplitude; note on: velocity 0 to 1; note off: release velocity. MUST be finite

The length MUST be exactly B + 4 + 12m. Event i is number seq + i, at clock + offset. The I flag is a reject.

There are four kinds and no more are planned for v1. Any other MIDI message travels in a MIDI frame (section 4.4), not as an event kind. A value that steps at an exact time is not an event: it is a SAMPLES frame with I set and k 1 (one sample, its offset 0, its clock the step's time). The note field is a u16 so a note number can index an MPE or microtonal table.

Redundancy. A single event cannot carry a repeat under 2r <= m, so a sender SHOULD send every EVENTS frame twice, a few milliseconds apart, on a datagram transport; the copy carries the same seq and the receiver drops it. This is the recommended practice (the reference sender does it with a 5 ms gap). R on EVENTS keeps the 2r <= m rule and stays available for frames of several events.

Events are sent when they happen, so a receiver cannot see a lost last event until the next one, or until the next MAP of the stream (its seq is the next event number, section 4.3).

4.3 MAP (type 3)

What a stream is. Sent when a stream starts, when it changes (with a new map id), and re-sent periodically for UDP (the reference sends it every second). Body at B:

offsetsizefieldrule
B+0u16map id1 to 65535; 0 is a reject, since 0 means no map
B+2u16L, JSON length in bytes
B+4L bytesUTF-8 JSON objectMUST be valid UTF-8 and a JSON object (RFC 8259), with no byte order mark

The length MUST be exactly B + 4 + L. The head's stream is the stream described, seq is the stream's next sample or event number at the time of sending (so a receiver counts trailing loss), and clock is the sender's clock when sent.

The JSON:

{ "name": "desk", "kind": "samples", "rate": 1000, "format": "f32",
  "channels": [
    { "name": "pitch", "node": "keys", "port": "cv-out", "unit": "V", "min": -5, "max": 5, "voct": 1 },
    { "name": "cutoff", "unit": "V", "min": 0, "max": 10 } ] }
keyrequiredmeaning
nameyesthe stream's name, a non empty string (the OSC bridge uses it as the first address part)
kindyes"samples" or "events"
ratesamplessamples per second, a finite number above 0 (a JSON number too large for a double, such as 1e999, is infinite and a reject)
formatsamples"f32", "i16" or "i24"
channelsyes1 to 255 objects; for samples their count is n
channels[].nameyesnon empty string
channels[].node, port, unitnostrings: where the channel comes from, and its unit
channels[].min, maxnonumbers: the channel's range in its unit (and the integer formats' scale)
channels[].voctnovolts per octave, a number
channels[].clampno[lo, hi], two finite numbers with lo <= hi, in the channel's unit: a safety limit (section 6.1)
channels[].slewnoa finite number above 0: the most the channel may change per second, in its unit (section 6.1)

A MAP that breaks a rule in this table is a reject. Keys not listed are allowed and ignored, so a studio can add its own. clamp and slew were added in v1.x: a reader that predates them ignores them as unknown keys and limits nothing; a reader that knows them rejects a MAP whose clamp or slew breaks its rule, because a safety limit that cannot be read must not be dropped quietly.

4.4 MIDI (type 4, v1.x)

Any MIDI 1.0 message, timed on the shared clock, on its own stream id. An old v1 reader skips the type (section 2.2). Body at B:

offsetsizefieldrule
B+0u8m, messages in this frame, repeats included1 to 255
B+1u8r, repeatsas for EVENTS: 0 unless R; with R 1 to floor(m/2)
B+2u16reservedMUST be 0 on send; a reader ignores it
B+4m recordsmessagesbelow, one after another, no padding

Each record, 6 + L bytes:

offsetsizefieldrule
0i32offset, microseconds from the head clock0 or more, never decreasing within the frame
4u16L, the message's length in bytes1 to 1024
6L bytesone whole MIDI 1.0 messagebelow

The length MUST be exactly B + 4 + sum(6 + L). Message i is number seq + i, at clock + offset. The I flag is a reject. A frame of 1024 byte messages holds at most 63 of them (section 1.2).

A message is one complete MIDI message, as the MIDI 1.0 Detailed Specification defines it:

SysEx is off by default in every receiver. A receiver drops a valid SysEx message and counts it unless its owner allowed SysEx (the reference: receive --midi-sysex). SysEx can overwrite an instrument's memory: patches, sessions, firmware. The 1024 byte limit keeps a frame small and still carries a patch dump of most instruments; a larger dump is not a live control and does not belong on this wire.

A receiver plays MIDI out as it plays events (section 6): each message at clock + offset + D on the shared clock, late ones by the same rule, repeats (by seq) dropped. A MIDI output passes the bytes through unchanged; an output that cannot carry MIDI (OSC, a DAC) ignores the stream. On UDP a sender SHOULD send each MIDI frame twice, as EVENTS.

Why this layout. The 12 byte event slot holds at most 3 MIDI bytes (channel and note), and an f32 value cannot carry raw bytes because it must be finite. The alternative, a MIDI event kind for 3 byte messages plus a second frame type for SysEx, gives a C implementer two paths and two sets of rules for one stream. One record shape (offset, length, bytes) carries every MIDI message: a reader walks the records with one loop, checks each message with one function, and skips a frame without knowing MIDI. The length is a u16 because a u8 cannot hold a 1024 byte SysEx. No padding, because nothing in a frame is padded (section 1) and every field is read byte by byte. A MIDI frame needs no MAP: the bytes describe themselves, and a stream's id names it.

5. Transport messages (optional)

These carry the clock and the receiver's feedback. They are not needed to read data frames. Each has a fixed length (except HELLO); the X flag is allowed, I and R are rejects.

5.1 HELLO (type 16)

offsetsizefield
B+0u8role: 1 sender, 2 receiver, 3 both; 0 is a reject
B+13 bytesreserved, 0
B+4resta name, UTF-8 (may be empty; invalid UTF-8 is a reject; a leading U+FEFF is part of the name, not stripped)

A receiver behind NAT sends HELLO to a relay or a sender so that frames can come back to it; a sender sends it to keep its address fresh at a relay. stream, seq and clock are the sender's choice (the reference sends 0, 0, now).

5.2 PING (type 17)

The head alone (16 bytes, or 16 plus an extension). stream names the asker's stream (or 0), seq is the ping's number, clock is the asker's send time t0.

5.3 PONG (type 18)

offsetsizefield
B+0f64t0, the ping's clock, copied
B+8f64t1, when the ping arrived, on the answerer's clock

The head's stream and seq are the ping's; its clock is t2, when the answer left. With t3 the arrival of the PONG on the asker's clock (NTP, RFC 5905):

rtt = (t3 - t0) - (t2 - t1) offset = ((t1 - t0) + (t2 - t3)) / 2 the answerer's clock minus the asker's

Estimator. Keep the last 120 results; take the third with the smallest rtt; the offset is the median of their offsets. The single fastest ping is not used alone: with jitter in both directions it is often fast one way only, which v2in measured as a -3.1 to +10.6 ms error on a jittered line where the truth was 0.05 ms.

5.4 CLOCK (type 19)

offsetsizefield
B+0f64offset, microseconds: the peer's clock minus this sender's clock
B+8f64rtt, microseconds, of the fastest ping the estimate used

A sender that pinged a receiver (or a relay) tells it the result, so the receiver can put the sender's clocks on its own: receiver time = sender clock + offset. stream 0 means every stream from this source; another value applies to that stream only. seq counts CLOCK messages; clock is the send time. Sent after the first estimate and then every second in the reference.

Through a relay the clock has two legs: the sender pings the relay and the relay pings the receiver (or each end pings the relay), and the receiver adds the two offsets. A relay never rewrites a frame, clocks included, so a frame is the same bytes at both ends and a MAC over it (section 2.1) can survive the relay.

5.5 REPORT (type 20)

A receiver's report on one stream (the head's stream), sent back to its sender, as RTCP's receiver report (RFC 3550 6.4.1), so a sender can raise its batching or redundancy when a line gets worse.

offsetsizefieldmeaning
B+0u8fraction lostsamples lost since the previous report, in 1/256, 0 when none or when duplicates outnumber losses
B+1u8reserved, 0
B+2u16late firedevents that arrived late but within the receiver's threshold and were still fired (section 6), cumulative, wraps at 2^16
B+4i32cumulative lostexpected minus received since the stream began (signed, as RTCP's)
B+8u32highest seqthe extended highest sample or event number received, mod 2^32
B+12u32jitter, microsecondsRFC 3550 A.8 on the transit of each frame's last sample: `J += (D- J) / 16`
B+16u32latesamples that arrived after their playout time, and events dropped for arriving more than the threshold late, cumulative
B+20u32recoveredsamples or events received only as a repeat, cumulative

seq counts reports; clock is the receiver's send time. The reference sends one per stream twice a second.

6. Playout

A receiver plays a stream out a fixed delay D after its clock, on the shared clock:

play time (receiver clock) = sample clock + offset + D

6.1 Safety limits

A channel MAY carry limits: clamp (a value outside [lo, hi] becomes lo or hi) and slew (the most the value may change per second, in the channel's unit). A receiver applies them to every samples channel before any output (a DAC, MIDI, OSC, anything), after the playout of section 6 and on the receiver's clock:

y = the previous output moved toward x by at most slew x (now - then) (no previous output, or no slew: y = x) y = min(hi, max(lo, y)) (with clamp)

So a step becomes a ramp, the clamp is the hard bound, and a channel without limits passes unchanged. Limits apply to samples channels only; an event's value is not limited (a clamp would turn a gate off into a gate on).

The instrument's owner decides, not the remote player. A receiver MAY be given limits of its own (the reference: receive --limit <channel>:<lo>..<hi>[@<slew>], the channel by index or name). For a channel it names, the receiver's limit replaces the map's clamp and slew together; the map's limits apply only to channels the receiver did not name. A receiver keeps each channel's last output when a MAP is re-sent or its limits change, so a new limit slews on from where the channel is and never lets a step through.

7. Senders

8. Conformance

A reader conforms when, for the files in vectors/:

  1. every entry of valid.json decodes to exactly its frame (an extension's data written as hex),
  2. every entry of skip.json is skipped as an unknown type, not rejected,
  3. every entry of reject.json is rejected. The error field is the reason the reference reader gives; matching it is recommended, not required.

The order of the checks is not normative. A frame with several faults may be rejected for any of them, so two conforming readers can give different reasons for one frame. For EVENTS the reference checks the flags, the count, the repeats, the length, then each event's kind and value in order, then the offsets; a reader that checks the offsets first conforms. The vectors carry one fault each where it matters.

A valid.json entry marked decodeOnly holds bytes no writer produces (a MAP key given twice): it is decoded, not encoded.

A writer conforms when encoding each valid.json frame (except decodeOnly ones) gives its hex. For MAP the JSON is written compactly with the keys in the vector's order; a writer that orders keys differently conforms when its MAP decodes to the same object.

The vectors are built by vectors/make.mjs from this document's tables with a byte writer of its own, so they are not the reference encoder's output checked against itself.

9. What was taken from existing specs

10. Decided (2026-12-06)

The thirteen questions this draft left open, as the owner answered them, each with its reason.

  1. Stream id stays u16, picked at random by the sender at start and picked again on a clash (section 2). The head stays 16 bytes, and a clash only matters where sources merge, which a relay can see and report.
  2. n and format stay in every SAMPLES frame. Two bytes buy a frame that parses with no map and a stale map caught even when a map id was reused.
  3. Map id 0 means no map, raw values (section 4.1), no longer a reject; EVENTS too, the channel being an index. A quick sender or a sensor can stream without writing a map; a MAP still cannot use id 0.
  4. Integer scaling is by the map's min and max, and to -1..1 without them or without a map. Symmetric and already implemented; an explicit scale and offset would be a second way to say the same thing.
  5. Exact length stays strict for datagrams and WebSocket messages; byte streams get a u16 length prefix (section 1.1). Padding hides bugs, and TCP or serial needs framing that the datagram does not.
  6. Event redundancy is sending each EVENTS frame twice, now the recommended practice (section 4.2); r for events is unchanged. A copy costs one small frame and needs no new rule.
  7. No fifth event kind, note stays u16. A value step at an exact time is an irregular SAMPLES frame of one sample.
  8. Late events fire if at most 10 ms late and are dropped if later, both counted in REPORT (late fired in the reserved bytes, late for drops; section 6), the threshold a receiver setting. A slightly late gate off must still close the gate; a trigger far too late is a wrong beat.
  9. Clock through a relay is two legs, and the relay never rewrites frames (section 5.4). Frames stay the same bytes end to end, which a MAC will need.
  10. Versions (section 2.3): what an old reader can skip is v1.x, any change to the meaning of existing bytes is v2, and a reader rejects an unknown version.
  11. Seq wraps at 2^32, extended by the receiver. 49.7 days at 1 kHz is longer than a session, and REPORT's highest seq mod 2^32 is RTCP's choice too.
  12. Extension type 1 is reserved for authentication (a key id and a MAC, layout not defined; section 2.1). Until it is defined, run on trusted networks or behind a relay with keys; a reader that does not implement it skips it.
  13. Steady OSC is an option: receive --osc host:port --osc-steady <Hz> sends every channel's current value every period; changes only stays the default. Some hosts want a steady stream, most want less traffic.

11. Stated for the C core (2026-12-06)

Writing c/voltergeist.h from this document found six places where only the JavaScript said what happens. Each is now a rule; where the JavaScript was not clearly wrong, its behaviour became the rule.

  1. An unknown type's flags (section 2): the head is checked (size, version, reserved bit 3, finite clock, the extension's length with X); I, R and the body are not. This is what the JavaScript did.
  2. A byte order mark (sections 4.3 and 5.1) has no special meaning: a MAP starting with one is not JSON, a HELLO name keeps it. The JavaScript used to drop it (TextDecoder's default) and now does not; this is the choice that needs no code in C.
  3. A JSON key given twice keeps its last value (section 4.3), as JSON.parse and the C scanner already did; forbidding duplicates would make a C reader remember every key.
  4. rate is a finite number above 0 (section 4.3), as both implementations already checked.
  5. A frame is at most 65535 bytes (section 1.2), so every frame fits the byte stream prefix; new in both. UDP's 1,200 bytes stays advice.
  6. The order of reject checks is not normative (section 8); a frame with several faults may report any of them.

12. Added in v1.x (2026-12-06)

Both are additions an old v1 reader skips or ignores (section 2.3).

  1. MIDI frames (type 4, section 4.4). voltergeist can carry any MIDI 1.0 message timed on the shared clock, so a remote player's controller or sequencer reaches an instrument with its timing intact. Every message carries its status byte, SysEx is off by default in every receiver and at most 1024 bytes, and real-time bytes are allowed.
  2. Safety limits (clamp and slew in a MAP channel, section 6.1), enforced by the receiver before every output, with the receiver's own limits winning. Historic instruments need a bound on what a remote sender can do to a voltage. Patchwerk (MIT, 2012) set each patch's voltage ranges in a configuration file on the instrument's side, and the 20N02 (NIME 2019) named a security layer as future work (research/prior-art-2026-12-06.md).