MIDI Audio

MIDI, the Musical Instrument Digital Interface, is a protocol for sending musical performance data between instruments and computers. It carries no audio itself; it sends short messages, up to sixteen channels of them, that a synthesiser turns into sound. A Standard MIDI File stores those messages with timing, so a whole performance can be replayed.

MIDI Audio

Overview

A MIDI stream is a sequence of byte messages. Most are channel messages tagged with one of sixteen channel numbers, so up to sixteen parts play at once, each on its own instrument. A message is a status byte followed by one or two data bytes, and running status lets repeated messages drop the status byte to save space. The classic hardware link runs at 31250 baud, but a file or an internal sequencer has no such limit.

PropertyValue
Channels16
Message formStatus byte plus 1 or 2 data bytes
Note range128 notes (0 to 127)
Velocity7-bit (0 to 127)
Serial rate31250 baud (hardware link)

Channel voice messages

The messages that actually make notes are the channel voice messages. Note on and note off start and stop a pitch with a velocity; program change picks the instrument for a channel; control change sets continuous parameters such as volume, pan and modulation; pitch bend slides a note; and aftertouch responds to key pressure. Each carries a channel number, so the same message type drives any of the sixteen parts.

MessageDataRole
Note onKey, velocityStart a note; velocity 0 acts as note off.
Note offKey, velocityStop a note.
Program changeProgramChoose the channel's instrument (0 to 127).
Control changeController, valueSet a parameter: volume, pan, modulation, sustain.
Pitch bend14-bit valueBend every note on the channel.
AftertouchPressureRespond to key or channel pressure.

General MIDI

General MIDI fixes what the program numbers mean, so a file sounds broadly right on any GM device. Programs 0 to 127 name a standard instrument set grouped into families, and channel 10 is reserved for percussion, where each note number is a different drum. This is what lets a tune play back with piano as piano and drums as drums on unrelated hardware.

Program rangeFamily
0 to 7Pianos
16 to 23Organs
24 to 31Guitars
32 to 39Basses
40 to 47Strings
56 to 63Brass
Channel 10Percussion kit, note number selects the drum

Timing and files

A Standard MIDI File (SMF) stores the messages with timing. Time is measured in ticks, a division set in the header as pulses per quarter note, and tempo events say how long a tick lasts. Events are stored with delta times, the gap since the previous event. Files come in three types: one merged track, several parallel tracks, or a set of independent sequences.

ElementMeaning
Format 0One track, all channels merged.
Format 1Several tracks played together.
Format 2Independent sequences.
DivisionTicks per quarter note (PPQN).
Delta timeTicks since the previous event.
TempoMicroseconds per quarter note.

Playback and synthesis

Because MIDI makes no sound on its own, playback needs a synthesiser to render the messages: a General MIDI sound module, a wavetable card, an FM chip such as the OPL, or a software synth. In the sequencer, the MIDI data is the score, and the chosen voice, whether a real device or an emulated chip, provides the sound. This is why the same MIDI file can drive very different timbres.

Source of soundNotes
GM sound module or wavetableSample-based instruments per program number.
FM synth (OPL)Register writes per note, as on AdLib.
Software synthRendered on the host from the message stream.

Sequencer role

As a sequencer target MIDI is the common command core in protocol form. The sequence sends discrete events and continuous-controller streams, and the chosen synthesiser turns them into sound and runs the envelopes, so from the sequencer's side MIDI is all event-driven; nothing is latched in a chip.

CommandKind
Note on / offEvent
Program changeEvent
Control change (volume, pan, modulation)Event or automation
Pitch bendAutomation