MDX File Format
MDX is a binary MML format, compiled from plaintext MXDRV MML. It is specific to MXDRV for the X68000.
MDX files consist of a header, a list of instrument voices, and the MML commands.
Header format
- Title in Shift_JIS encoding, followed by
0x0d 0x0a 0x1a - PDX file name, followed by
0x00(just0x00if 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 value's 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, others use 16. To detect which one it is, two methods exist:
- subtract the file position of the first MML data offset word from its value, then divide by 2. See MDX.h for the implementation.
- as in mxd2063.lzh / SRC/MDX2MUS.ASM (search for `#EX-PCM`), take the first byte of the first MML channel, and set channels to 16 if it is E8h.
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.
Voice format
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
MDX Commands
Each command consists of one byte, followed by specific parameters.
0x00-0x7f• Rest +1 clock cycles0x80-0xdfn• Note data, followed by durationn+ 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 (???).0xffn• Set tempo ton. Equivalent to mml command @t#. Tempo applies to all tracks at the same time, not just current track.0xfenm• Set OPM registernto valuem.0xfdn• Set current voice.0xfcn• Pan.0xfbn• Set volume.0xfa• Decrease volume. Corresponds to MML command (.0xf9• Increase volume. Corresponds to MML command ).0xf8n• Sound length0xf7• Disable key off for next note. Corresponds to MML command &, except it precedes the note instead of following it.0xf6n0x00• Repeatntimes until a Repeat end command.0xf5nn• Repeat end. Loop backnn(signed word) bytes.0xf4nn• Repeat escape. In the last repetition, skipnnbytes, thus shortening it.0xf3nn• Detunenn/64 semitones. Corresponds to MML command D#.0xf2nn• Portamento. Change pitchnn/16384 semitones per clock. This is issued before the starting note.0xf10x00• Performance end.0xf1nn• Performance end, but loop fromnnbytes (nnis a negative int16).0xf0n• Delay key-onnticks. Corresponds to MML command k#.0xefn• Sync send on channeln. If channelnis 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.0xedn• ADPCM / noise frequency set ton. 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#.0xec0x80• Pitch LFO disable (MPOF).0xec0x81• Pitch LFO enable (MPON).0xecmnnaa• LFO Pitch control.mcontrols the waveform (0=sawtooth, 1=square, 2=triangle),nnis the frequency, expressed in clock cycles / 4, andaais the amplitude.0xeb0x80• LFO Volume MAOF.0xeb0x81• LFO Volume MAON.0xebmnnaa• LFO Volume control. Same as LFO Pitch.0xea0x80• LFO OPM MHOF.0xea0x81• LFO OPM MHON.0xeamnopq• OPM LFOm=sync/wave,n=lfrq,o=pmd,p=amd,q=pms/ams (???)0xe9n• Set LFO key-on delay. Corresponds to MML command MD#.0xe8• PCM8 expansion/ mode shift. (???)0xe70x01n• Fade-out at speedn.
External Links
- @Wiki MDX description (Japanese)
- MDX Tools by User:Vampirefrog