Notes about the MIDI protocol format
MIDI (Musical Instrument Digital Interface) is a protocol designed for musical devices, using simple byte-level communication.
MIDI Message Structure
See the midi/messages page for a detailed description of MIDI messages.
- Data Format: MIDI messages are typically made up of 1 to 3 bytes. System-exclusive messages (SysEx) can be more than 3 bytes long.
- Bit Structure: the msb (Most Significant Bit) determines whether the byte is a status byte (msb = 1) or data byte (msb = 0).
- Status Byte: Indicates the type of MIDI message (e.g., Note On, Note Off). It contains a 4-bit message type and a 4-bit channel number.
- Data Bytes: Contain additional information (e.g., note number, velocity) with values ranging from 0 to 127 (7-bit data).
Polarity on the Wire
- The original MIDI protocol uses current loop signaling, where data is transmitted using negative polarity over a 5-pin DIN connector. A logical “1” is represented by no current flow, while a logical “0” is current flowing (around 5mA).
MIDI via DIN (traditional 5-pin connector)
- Data Rate: 31,250 bits per second (bps).
- Bandwidth: This low data rate limits how much data can be transmitted at once, which means some MIDI-heavy performances may experience delays or congestion when using traditional MIDI connections.
Ref : page 6 of the The Complete MIDI 1.0 Detailed Specification (version 96.1 third edition) (complete_midi_96-1-3.pdf) :
The MIDI data stream is a unidirectional asynchronous bit stream at 31.25 Kbits/sec. with 10 bits transmitted per byte (a start bit, 8 data bits, and one stop bit).
(CA-033) MIDI 1.0 Electrical Specification Update [2014] (ca33 5 PIn DIN Electrical Spec.pdf) :
The hardware MIDI interface operates at 31.25 (+/- 1%) Kbaud, asynchronous, with a start bit, 8 data bits (D0 to D7), and a stop bit. This makes a total of 10 bits for a period of 320 microseconds per serial byte. The start bit is a logical 0 (current ON) and the stop bit is a logical 1 (current OFF). Bytes are sent LSB first.
see https://learn.sparkfun.com/tutorials/midi-tutorial/hardware—electronic-implementation
MIDI via USB
- Data Rate: USB MIDI offers much higher data rates, typically 12 Mbps (Full Speed USB), far surpassing the traditional DIN’s 31.25 kbps.
- Bandwidth: USB MIDI supports much greater throughput, allowing multiple channels of data to be transmitted simultaneously without noticeable delay.
Data Rates and Bandwidth Comparison
| Connection Type | Data Rate | Max Bandwidth | msg/s (1) | time per msg (1) |
|---|---|---|---|---|
| DIN MIDI | 31,250 bits per second (bps) | 31.25 kbps | 10’416 | 0.1 ms |
| USB MIDI | 12 Mbps (Full Speed USB) | 12’000 kbps | 4’000’000 | 0.25 us |
(1) : for typical 3 bytes messages (status byte + 2 data bytes)
In practice, you cannot know what hardware sits behind some generic MIDI port. You should use the 3125 bytes/s limit unless you have special knowledge about the device.