MP3 to MIDI Pitch Steps: How Small an Interval the File Can Name

A MIDI file names pitch with 128 integers and 127 gaps, and the format never states how wide a gap is. The interval you call a semitone comes from the twelve columns of the specification's own note-number table. Half a gap is where the nearest integer becomes a different note, and because the grid is geometric, that tolerance is a fraction of the frequency rather than a number of hertz.

Pitch steps, answered

  • 128 note numbers, 127 steps. A note number is seven bits, so the axis runs from 0 to 127: 127 intervals, which is ten octaves of twelve steps plus seven.
  • The interval is not in the file. The specification contains no frequency, no hertz and no ratio; the spacing appears only as the twelve columns of its note-number table.
  • The tolerance is a fraction, not a frequency. Half a step is the ratio 1.0293, or 2.93 percent. That is 0.24 Hz at note 0, 7.67 Hz at note 60 and 368 Hz at note 127.
  • A leftover has nowhere to go. The file stores whole numbers, and per-note scale tuning is a GM2 addition rather than a Level 1 requirement.

The axis is 128 integers and 127 steps

A note number is seven bits, carried as the first data byte of a Note On message and written 0kkkkkkk, so the file can name 128 pitches. That is 127 steps between neighbours: ten octaves of twelve is 120, and the seven left over put the highest note seven steps past the tenth octave.

The specification's own table shows the grid

Appendix 1.3 of the MIDI file specification is a table of note numbers by octave: twelve columns, one per note name, and eleven rows. The first ten rows run from 0 to 119 with every cell filled; the last holds eight entries and stops. That column count is the only place the spacing of the axis appears in the document, and it appears as a count of cells rather than a stated ratio.

The table carries its own caveat: the octave designations rest on Middle C = C5, which it calls an arbitrary assignment. What the file stores is the integer; twelve equal steps to the octave, and the ratio 1.0594631 for each step, are supplied by whoever reads the file.

Half a step is where the note changes

Because the steps are equal in ratio, the boundary between neighbouring note numbers sits exactly halfway, so half a step is the whole tolerance. Half a step is the ratio 1.0293, or 2.93 percent of whatever frequency the note sits at. In hertz that is not constant: 0.24 Hz at note 0, 8.18 Hz; 7.67 Hz at note 60, 261.63 Hz; 12.89 Hz at A4; 368 Hz at note 127, 12,543.9 Hz. The same 2.93 percent is a sliver at the bottom of the range and a wide margin at the top.

What the file can and cannot store

The nearest-note rule always leaves a remainder. A reading sitting 40 of the 100 cents below an integer is still recorded as that integer, and no field can hold the leftover: a note number has no fractional part.

The only pitch control finer than a step is the pitch wheel, fourteen bits wide, and it moves a whole channel rather than one note. Per-note scale tuning is a General MIDI 2 addition, not a Level 1 requirement, so a conversion that hears one note in a chord slightly low has a whole integer, a channel-wide wheel, and nothing between them.

What this means for a conversion

An accuracy figure quoted in cents describes the detector, not the file: any error smaller than half a step leaves no trace in the output. The tolerance also scales with pitch, so a fixed error in hertz is a different fraction of the allowance at each end of the range.

Related