Table
of Contents
- Introduction
- MIDI Header Chunks
- MIDI Track Chunks
- MIDI Delta Time
- MIDI Events
- MIDI Running Status
- Example
1. Introduction
MIDI files are a flexible format for encoding music. They
can support multiple instruments on multiple tracks.
This document describes the subset supported by the ERS-110/210/220/310
AIBO models.
2. MIDI Header
Chunks
MIDI files are composed of a header chunk, and one or more track
chunks. Each chunk starts with a 4-byte signature &
4-byte chunk length field. The first chunk in a file is the
header chunk. Header chunks specify MIDI
format & the time base.
struct header_chunk_type { unsigned int signature; // "MThd" = header unsigned int chunk_len; unsigned short format; // MIDI format (types 0, 1, 2 are valid) unsigned short tracks; // Number of tracks. unsigned short division; // Time delta units per quarter-note. };
|
NOTE: The ERS-110/210/220/310 AIBO platforms only support single
track files (format 0 MIDI files). However, Skitter can automatically convert
multi-track MIDI
to work on AIBO.
Format 0 is a single-track MIDI file. The track contains
all note and tempo information.
Format 1 is a multi-track MIDI file, where the first track holds the
tempo map & meta-data. All tracks play at once.
Format 2 is also a multi-track MIDI file, where each track is a
seperate sequence.
3. MIDI Track
Chunks
MIDI track chunks contain a sequence of one or more <delta-time>,<event>
pairs following the
signature/chunk-length:
struct track_chunk_type { unsigned int signature; // "MTrk" = track unsigned int chunk_len; };
|
4. MIDI Delta Time
The delta-time fields are a variable length value. The MSB
(bit 7)
of each byte is a continuation flag if set. The lower 7-bits
are the time value. Each additional byte adds 7-bits to the
time-delta, up to a maximum of 0x0FFFFFFF. You repeat
shifting a running total by 7 bits & adding the new 7-bits while
the MSB is set. ie:
0x7F = 0x7F 0x86 0x21 = 0x321 0x84 0xC2 0x21 = 0x12121
|
5. MIDI Events
MIDI events control turning notes on & off, plus various effects
for simulating musical instruments. There are four types:
5.1 MIDI Channel Voice
Events
The following channel voice events are used. The values
(status bytes) shown are in hexadecimal. The range of
values support up to
16 MIDI channels. However, AIBO just combines them.
0x80 - 0x8F Note Off. 0x90 - 0x9F Note On. 0xA0 - 0xAF Polyphonic pressure. Ignored by AIBO. 0xB0 - 0xBF Controller Change. Ignored by AIBO. 0xC0 - 0xCF Program/Instrument Change. 0xD0 - 0xDF Channel Key Pressure. Ignored by AIBO. 0xE0 - 0xEF Pitch Bend.
NOTE OFF/ON.
These events take two additional parameter bytes: The "key"
(pitch) and "velocity" (volume). As a special case, a NOTE-ON
event with zero volume is equivilent to a NOTE-OFF event.
0x90 0x3C 0x7F = Turn on middle-C at maximum volume. 0x80 0x3C 0x00 = Turn off middle-C.
|
POLYPHONE PRESSURE.
Takes two additional parameter bytes. The "key" (pitch) and
"pressure" applied.
0xA0 0x3C 0x7F = Turn on middle-C at maximum volume.
|
CONTROLLER CHANGE.
Takes two additional parameter bytes. The controller "number" and
controller "value".
0xB0 0x12 0x34 = Set controller number 0x12 to value 0x34. Controller number range is 0x00 to 0x77. Higher values are reserved for channel mode events.
|
PROGRAM CHANGE.
Takes one additional parameter byte. The new "program" (or
instrument) number.
0xC0 0x47 = Set instrument number to 0x47 (Clarinet).
|
CHANNEL KEY PRESSURE.
Takes one additional parameter byte. The channel "pressure"
value.
0xD0 0x7F = Change overall channel pressure to maximum.
|
PITCH BEND.
Takes two additional parameter bytes. The LSB & MSB of
the pitch value.
0xE0 0x00 0x7F = Change channel pitch to mid-range.
|
5.2 MIDI Channel Mode
Events
Channel mode events overload the "Controller Change" event
above. They support optional extended features.
The messages are always three bytes in length -- the same as the
controller
change event. The values
(status bytes) shown are in hexadecimal.
0xB0 0x78 0x00 Turn off all sound. 0xB0 0x79 0x00 Reset All Controllers. 0xB0 0x7A 0x00 Disconnect Local Keyboard. 0xB0 0x7A 0xFF Reconnect Local Keyboard. 0xB0 0x7B 0x00 All Notes Off. 0xB0 0x7C 0x00 Omni Mode Off. 0xB0 0x7D 0x00 Omni Mode On. 0xB0 0x7E 0x00 Mono Mode On. 0xB0 0x7F 0x00 Poly Mode On.
These are ignored by
AIBO, and filtered by Skitter.
5.3 System Exclusive
(Sysex) Events
These events are for including information other than MIDI events into
a MIDI file. There are two: 0xF0 &
0xF7. Both are followed by a variable-length byte count
(ie: delta-time format), then the message data. ie:
0xF0 0x06 0x11 0x22 0x33 0x44 0x55 0x66 SysEx <length> <six bytes of misc data>
|
These are ignored by AIBO, and filtered by Skitter.
5.4 Meta Events
These events store music related information, such as track names,
tempo, instruments names, etc... The events start with
0xFF, followed by a variable-length byte count (ie: delta-time format),
then the message data. ie:
0xFF 01 len msg Misc Text Event (any message you like) 0xFF 02 len msg Copyright notice 0xFF 03 len msg Track name 0xFF 04 len msg Instrument name 0xFF 51 03 tt tt tt Tempo in microseconds per quarter note (24-bit value). 0xFF 58 04 nn dd cc bb Time signature (ie: 3/4 time). nn = numerator dd = denominator power of 2). 1=>2, 2=>4, 3=>8, ... cc = MIDI clocks per tick bb = Number of 1/32 notes per 24 MIDI clocks. 0xFF 2F 00 End of Track (should be last event on all tracks).
|
6. MIDI Running
Status
To reduce file size, MIDI supports the so called "Running
Status". So long as the status byte (ie: note on/off
events) doesn't change, there is no need to repeat it.
Status bytes are the MIDI channel voice/mode event bytes described
above.
Without Running Status:
0x90 0x3C 0x7F 0x90 0x3D 0x6F 0x90 0x3E 0x5F status key velocity status key velocity status key velocity
|
Since the subsequent status bytes doesn't change, they can be omitted...
With Running Status:
0x90 0x3C 0x7F 0x3D 0x6F 0x3E 0x5F status key velocity key velocity key velocity
|
6.1 Rules for Running
Status
- In effect while status byte doesn't change.
- Applies to channel voice/mode events only.
- System Exclusive (SysEx) Events cancel running status.
6.2 Running Status Efficiency
To improve running status efficiency, use note-on events with velocity
0 instead of note-off events. This avoids needing to issue
new status bytes. For example, the following cannot use
running status:
0x90 0x3C 0x7F 0x80 0x3C 0x40 0x90 0x3E 0x5F status key velocity status key velocity status key velocity (note on) (note off) (note on)
|
However, changing the note-off event to a note-on with zero-velocity
permits:
0x90 0x3C 0x7F 0x3C 0x00 0x3E 0x5F status key velocity key velocity key velocity (note on) (note off) (note on)
|
7.
Example
Chunk
Headers
Meta
Events & Status Bytes
Time
Delta's
000000: 4d 54 68 64 00 00 00 06 00 00 00 01 00 78 4d 54 |MThd.........xMT| 000010: 72 6b 00 00 01 27 00 ff 51 03 05 b8 d8 00 ff 58 |rk...'..Q......X| 000020: 04 04 02 18 08 00 c0 00 00 90 4f 60 50 4f 00 28 |..........O`PO.(| 000030: 4f 60 50 4f 00 28 4f 60 50 4f 00 28 4f 60 50 4f |O`PO.(O`PO.(O`PO| 000040: 00 28 4f 60 50 4f 00 28 4f 60 50 4f 00 28 4e 7f |.(O`PO.(O`PO.(N.| 000050: 50 4e 00 28 4e 7f 50 4e 00 28 4e 7f 50 4e 00 28 |PN.(N.PN.(N.PN.(| 000060: 4e 7f 50 4e 00 28 4e 7f 50 4e 00 28 4e 7f 50 4e |N.PN.(N.PN.(N.PN| 000070: 00 28 52 7f 50 52 00 28 52 7f 50 52 00 28 52 7f |.(R.PR.(R.PR.(R.| 000080: 50 52 00 28 52 7f 50 52 00 28 50 7f 50 50 00 28 |PR.(R.PR.(P.PP.(| 000090: 52 7f 50 52 00 28 53 7f 50 53 00 28 53 7f 50 53 |R.PR.(S.PS.(S.PS| 0000a0: 00 28 53 7f 50 53 00 28 53 7f 50 53 00 28 52 7f |.(S.PS.(S.PS.(R.| 0000b0: 50 52 00 28 50 7f 50 50 00 28 4e 7f 50 4e 00 28 |PR.(P.PP.(N.PN.(| 0000c0: 4e 7f 50 4e 00 28 4e 7f 50 4e 00 28 4e 7f 50 4e |N.PN.(N.PN.(N.PN| 0000d0: 00 28 4e 7f 50 4e 00 28 4e 7f 50 4e 00 28 4e 7f |.(N.PN.(N.PN.(N.| 0000e0: 50 4e 00 28 4e 7f 50 4e 00 28 4e 7f 50 4e 00 28 |PN.(N.PN.(N.PN.(| 0000f0: 4e 7f 50 4e 00 28 4e 7f 50 4e 00 28 4e 7f 50 4e |N.PN.(N.PN.(N.PN| 000100: 00 28 52 7f 50 52 00 28 52 7f 50 52 00 28 52 7f |.(R.PR.(R.PR.(R.| 000110: 50 52 00 28 52 7f 50 52 00 28 50 7f 50 50 00 28 |PR.(R.PR.(P.PP.(| 000120: 52 7f 50 52 00 28 53 7f 50 53 00 81 20 4e 7f 50 |R.PR.(S.PS.. N.P| 000130: 4e 00 28 53 7f 81 70 53 00 00 ff 2f 00 |N.(S..pS.../. |
Download Example
|