[vorbis-dev] Ogg MIDI proposal

Jack Moffitt
Sat, 25 Aug 2001 17:34:30 -0000

This is a proposal for Ogg MIDI streams.  It will also help other
stream additions to Vorbis, as they should follow a similar model.
Ralph has done much of the work on this, and also is working on MNG
Ogg streams.

Background
----------
I was contracted to do this work, so even if you can't think of a use
for this, there is one ;)  Basically with midi in Ogg, we can have
a synchronized midi+vorbis stream where vorbis plays audio and MIDI
controls some external device (synthesizer, digital piano, lights, etc).
There is also a provision of MIDI that allows lyrics, and this might be
a good use also.

Goals
-----
- tool for combining Vorbis and a MIDI into on Ogg file (oggmerge)
- streamable
- tool for playing back said Ogg file

Current Tradeoffs
-----------------
There are three foramts of standard MIDI files, Format 0, 1, and 2.
Format 2 is not a song, but multiple idependent patterns, so is
irrelevant to this discussion.  Format 0 files are one track, and
Foramt 1 files are multiple tracks (note that these are logical
divisions for sequencers, and all the data of a format 1 file could be
 represented in one track).  Since tracks are stored serially, which
breaks streaming, Ogg MIDI will use only format 0 MIDI files, which means
any Format 1 files will have to be collapsed into Format 0.

File Format
----------
A file with Vorbis and Midi will look like:

<Vorbis header pages><MIDI header page><Vorbis data
page><MIDI data page>...

MIDI pages will be placed in sync with vorbis pages (immediately following
their corresponding Vorbis page).  Since MIDIs are tiny, it is likely
there will be very few pages of MIDI data.

Each MIDI Ogg packet will contain rougly 512 bytes aligned to MIDI event
boundaries.  This means approximately 8 MIDI packets will normally be place
in an Ogg page.

MIDI header packet format
-------------------------
The MIDI header will be:

'OggMIDI\000'
version (1 byte) - this is the OggMIDI version supported, starts from 0
time format (1 byte) - this is the time format, 1 for ticks per
        quarternote; 24,25,29,30 for SMTPE time
timebase (2 bytes) - subdivisions per SMTPE frame or ticks per quarternote

MIDI packet format
------------------
<midi event><midi event>...

Changes to Vorbis
-----------------
libvorbisfile will need to be modified to recognize substreams and ignore
all but the first valid Vorbis stream.

Comments, suggestions?

jack.