OggMIDI

From XiphWiki
Jump to navigation Jump to search

Mapping for embedding MIDI data streams in Ogg.

This mapping was designed by Jack Moffitt. See this mailing list post for documentation of his scheme.

Header packet

OggMIDI streams have a single header packet for codec identification.

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1| Byte
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identifier 'OggMIDI\0'                                        | 0-3
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                                                               | 4-7
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|        version number         |         time format           | 8-11
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           timebase            |                                 12-13
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The header packet begins with the character sequence 'OggMIDI\0' for codec identification.

This is followed by an 8 bit version field. The version must be 0 for the mapping described here.

The time format field is also 8 bits, and describes the timestamp format used by the midi data. It is interpreted as follows:

  • 1 one beat per quarter note
  • 24, 25, 29, 30, (50, 59, 60?) corresponding smpte frame
  • other values are undefined

The timebase occupies the final 16 bits and gives the number of ticks per time format unit.

Data packets

The header packet is followed by a series of data packets, each of which contains an integral number of midi events.

Granulepos

The granulepos field used for the Ogg page timestamps records microseconds since the beginning of the stream.