MDX File Format
MDX files consist of a header, a list of instrument voices, and the MML commands.
- Title in Shift_JIS encoding, followed by
0x0d 0x0a 0x10
- PDX file name, followed by
0x00if there is no PDX file)
- Word: Voice data offset
- 9 or 16 Words: MML data offset
The voice and MML offsets are relative to the voice data offset position (right after the title and PDX file name). To implement this in code, just use a ftell() after you've read the PDX file name. The MML data offset array points to each of the channels. Some files use 9 channels, other use 16. To detect which is which, subtract the file position of the first MML data offset word from its value, then divide by 2. See MDX.h for the implementation.
The FM channels are labeled A through H. The PCM channel is labeled P. The extra channels, when the Mercury expansion card is present, are labeled Q through W.
This corresponds to the registers in the YM2151 sound chip. Each field is 1 byte. The x4 fields are 4 bytes corresponding to M1, M2, C1, C2. Total is 27 bytes per voice.
- Voice ID
- FL & CON
- Slot Mask
- DT1 & MUL x 4
- TL x 4
- KS & AR x 4
- AME & D1R x 4
- DT2 & D2R x 4
- D1R & RR x 4
Each command consists of one byte, followed by specific parameters.
0x00-0x7f• Rest +1 clock cycles
n• Note data, followed by duration
n+ 1. Corresponds to MML command n#,#.
0x80corresponds to MML o0d+, which means octave 0, note D♯.
0xdfcorresponds to o8d, octave 8, D. To calculate the MIDI equivalent note, subtract 0x80 and add 3. For the PCM channels, P through W, this represents data number (???).
n• Set tempo to
n. Equivalent to mml command @t#. Tempo applies to all tracks at the same time, not just current track.
m• Set OPM register
n• Set current voice.
n• Set volume.
0xfa• Decrease volume. Corresponds to MML command (.
0xf9• Increase volume. Corresponds to MML command ).
n• Sound length
0xf7• Disable key off for next note. Corresponds to MML command &, except it precedes the note instead of following it.
ntimes until a Repeat end command.
nn• Repeat end. Loop back
nn(signed word) bytes.
nn• Repeat escape. In the last repetition, skip
nnbytes, thus shortening it.
nn/64 semitones. Corresponds to MML command D#.
nn• Portamento. Change pitch
nn/16384 semitones per clock. This is issued before the starting note.
0x00• Performance end.
nn• Performance end, but loop from
nnis a negative int16).
n• Delay key-on
nticks. Corresponds to MML command k#.
n• Sync send on channel
n. If channel
nis in Sync Wait, resume playback on that channel. MML command S#
0xee• Sync Wait on current channel. Pause playback on this channel until resumed by a Sync Send signal (see above). MML Command W.
n• ADPCM / noise frequency set to
n. For FM channels (A-H), 0 means disable noise, 128+ means set noise frequency (without bit 7). For ADPCM channels (P-W), sets sampling frequency, corresponding to MML command F#.
0x80• Pitch LFO disable (MPOF).
0x81• Pitch LFO enable (MPON).
aa• LFO Pitch control.
mcontrols the waveform (0=sawtooth, 1=square, 2=triangle),
nnis the frequency, expressed in clock cycles / 4, and
aais the amplitude.
0x80• LFO Volume MAOF.
0x81• LFO Volume MAON.
aa• LFO Volume control. Same as LFO Pitch.
0x80• LFO OPM MHOF.
0x81• LFO OPM MHON.
q• OPM LFO
n• Set LFO key-on delay. Corresponds to MML command MD#.
0xe8• PCM8 expansion/ mode shift. (???)
n• Fade-out at speed