Author Topic: Preserving OPL instruments  (Read 561 times)


  • Posts: 2325
Preserving OPL instruments
« on: 23 Nov '19 - 14:49 »
While XMPlay/BASS don't support it, it would still be nice if the MO3 format could preserve OPL instruments in S3M and MPTM files. I think the only format change required would be to add a new sample format flag, and then store the instrument bytes as regular sample data. Also the encoder should obviously never try to use MP3 or Vorbis compression for such sample slots (although I assume that due to the low size of 12 bytes, it would always fall back to lossless sample data anway - this would mostly be a cosmetic change).

- For the S3M format, OPL instruments can be identified by sample type being set to 2, and the 12 instrument bytes are stored in the length, loop start and loop end fields of the sample header.
- For the MPTM format, OpenMPT already saves the instrument data as regular sample data and sets the sample length to 12, but sets the "cvt" value in the sample header to 0x40, which is a reserved value according to ITTECH.TXT. Note that the check for this flag should be an equal comparison (cvt == 0x40), not a bitwise AND, due to ModPlug's legacy ADPCM sample cvt type (0xFF). Any combination with other cvt flags is considered to be illegal.

As ScreamTracker can only handle either PCM or OPL instruments on a channel, the channel pan/type table would have to be adjusted in the UNMO3 tool as well: Channels carrying AdLib instruments should use channel types A1 through A9 (16...25) instead of L1....R8. Alternatively, the original channel configuration table of the S3M file could of course be preserved in a new chunk at the end of the music data. This would probably be less work to implement and it would in general allow for a more accurate restoration of the original S3M file, even if no OPL instruments are used.
« Last Edit: 23 Nov '19 - 15:40 by saga »