IMF

From ZDoom Wiki
Jump to navigation Jump to search

The Id Music Format contains instructions for Adlib soundcards. This format was created by Jason Blochiowak, a programmer from MiniWikipediaLogoIcon.pngApogee who joined Id Software prior to the development of the second MiniWikipediaLogoIcon.pngCommander Keen engine, allowing the use of music in Keen 4 and later. The format would also be used in DoomWikiLogoIcon.pngWolfenstein 3D and Spear of Destiny. Afterwards, Id software used DoomWikiLogoIcon.pngDMX and MIDI music instead, then moved to MiniWikipediaLogoIcon.pngRedbook audio in DoomWikiLogoIcon.pngQuake and streamed formats afterwards. As a result, Id only used the format in two engines and a total of five games and the format was mostly used by games developed or published by Apogee.

Technical information

There exist three "different" formats for IMF music. The core remains always the same, however: a series of four-byte instructions for an OPL2 sound chip, represented in this way:

Size Description
uint8 Register of the OPL2 chip
uint8 Data to write in the register
uint16 Delay before processing next instruction

The length of the delay depends on the playback rate used. In Wolfenstein 3D and Spear of Destiny, the rate is 700 ticks per seconds, so a delay of 5 corresponds to 1/140th of a second. Three different update rates have been known to be used, all multiples of 140: 280, 560, and 700. ZDoom assumes an update rate of 700. Although it is meaningless, an IMF song always begin with a four bytes of null (telling to write zero in the non-existent register 0 and to wait 0 tics). A similar null instruction can also be used to mark the end of the song. Presumably, this was done so that when songs are packed together, the beginning of a new song would signal the end of the previous.

The so-called type-0 format only contains these instructions, with no header and no footer. So-called type-1 starts with a two-byte little endian value indicating the total size of the OPL data stream, as a result information after the end is ignored and can be used to store a footer with information. Id Software's "MUSE" tool notably used this type-1 format in the Keen and Wolf games. Since an IMF song always begin with null bytes, checking the value of the first two bytes can be used to distinguish between type-0 and type-1.

ZDoom, however, requires a different variant format, created by Martin Fernandez. This format begins with a proper header:

Size Description
char[5] Signature (must be ADLIB)
uint8 Version (must be 1 — this format has no other version)
char* Track name as a MiniWikipediaLogoIcon.pngnull-terminated string
char* Game name as a null-terminated string
byte Ignored unknown value, generally 1
uint32 Track length (if 0: until end of file or null instruction)

The presence of this header means that the data stream begins at offset 13 at the soonest (track and game names are empty and only consist of their respective terminating null bytes). SLADE 3 can be used to add the header ZDoom requires to an IMF file in type-0 or type-1. See using OPL music in ZDoom for further explanations.

External links