Info

This is an exploratory post as part of my MIDI-VPN project.

… goodput is the number of useful information bits delivered by the network to a certain destination per unit of time.
— Wikipedia, “Goodput”

Emulating MIDI traffic is going to be a dance between looking like music while hiding ordinary web traffic. For this, we need to push 2 variables to their limits: How much can we get away with sending | How much can we hide in what we send. We’re dealing with the latter here, in the form of goodput. In other words, how many bits can we use.

When considering standards to emulate for this project, I’ve looked into both RTP-MIDI, which is most commonly implemented as AppleMIDI, and MIDI 2.0. RTP-MIDI was created as a payload format for MIDI, which was originally a serial format. As it was handling a continuous stream of bytes as opposed to datagrams of bytes, each byte’s first bit was reserved for indicating what kind it was (0 for data, 1 for status). RTP-MIDI, and by extension AppleMIDI adopted this format, cutting our potential goodput down by 1/8 immediately. You’d be surprised to hear, this is still better than MIDI 2.0.

We’ll look at note packets later on, but SysEx packets are what’s going to push this concept further. SysEx, or System Exclusive, are packets that send arbitrary data over our MIDI connection. Think parameter changes, settings, firmware updates, etc. This is perfect for disguising web traffic - the larger inbound packet sizes can be explained away as any request and response a synth might send, and I hope to model this accurately.

SysEx7, used by AppleMIDI, requires 7 bit encoding, but the byte content can be continuous with only 2 bytes for the header. MIDI 2.0 however requires all traffic to be contained within a Universal MIDI Packet (UMP), which can be at most 16 bytes and has a 3 byte header per UMP. The exact percentage of goodput changes with the number of bytes transmitted, so lets look at those instead.

Here are the functions for calculating the number of bytes where n = number of raw input bytes and W(n) = number of transmitted MIDI bytes.

And here is the output plotted. Note that SysEx8 only bests SysEx7 here, as the linear growth from the 7 bit encoding is still more goodput than the 3 byte header cost in each 16 byte block.

xychart-beta
    title "SysEx input vs transmitted bytes"
    x-axis "Raw input bytes" 1 --> 66
    y-axis "Transmitted bytes" 0 --> 100
    line "SysEx7 byte stream" [4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 74, 76, 77, 78]
    line "SysEx8 UMP" [16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 96]

(Unused bytes in the SysEx8 block are zero padding)

This reminds me of TCP Reno’s classic sawtooth pattern, with SysEx7 mapping closer to the trend we expect/want. A clear win for MIDI 1.0, but I’m still leaning towards the later protocol for reasons I’ll cover later.