An XM file starts with a 60-byte identification block and then a header whose size is
stored first. Numbers are little-endian. Offsets are decimal. Sources read this session (xm.txt and the OpenMPT wiki page in full; of the code, the header, pattern, instrument and sample loading, and the clone’s auto-vibrato and retrigger code, not the whole replayer):
xm.txt (the format description in libxmp’s docs/formats/), the loaders xm_load.c of libxmp,
LoaderXM.cpp of MilkyTracker and ft2_load_xm.c, ft2_module_loader.c and ft2_replayer.c of the FT2 clone, and the OpenMPT wiki page “Development: Formats/XM”. The description by Mr.H of
Triton that came with FastTracker 2 covers version 1.04; Matti Hamalainen's notes, the
FastTracker 2 clone's loader and the loaders of OpenMPT and libxmp fill in what it
leaves out, and the explorer follows the clone where they differ.
Layout
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 17 | ASCII | ID text | Extended Module: , with a trailing space. |
| 17 | 20 | text | module name | The song title. |
| 37 | 1 | u8 | marker | Always 1A. |
| 38 | 20 | text | tracker name | The program that wrote the file. |
| 58 | 2 | u16 | version | High byte major, low byte minor. 0x0104 is the current one. |
| 60 | 4 | u32 | header size | Size of the header counted from offset 60, including these four bytes. 276 in FT2's files. |
| 64 | 2 | u16 | song length | Entries of the order table that are played. |
| 66 | 2 | u16 | restart position | Position in the order table to go back to at the end. |
| 68 | 2 | u16 | channels | Number of channels in every pattern. |
| 70 | 2 | u16 | patterns | Number of patterns stored. |
| 72 | 2 | u16 | instruments | Number of instrument headers that follow the patterns. |
| 74 | 2 | u16 | flags | Frequency table. |
| 76 | 2 | u16 | default tempo | Default speed: ticks per row. |
| 78 | 2 | u16 | default BPM | Default beats per minute. |
| 80 | up to 256 | u8 × 256 | order table | The pattern for each position. |
Limits of FastTracker 2 itself: 32 channels, 256 patterns, 128 instruments, 16 samples per instrument, 256 rows per pattern and 255 positions in the song. ModPlug Tracker and OpenMPT go beyond them (OpenMPT 0.8: up to 192 channels, 255 instruments and 32 samples an instrument), and the explorer reads such files.
Worked example
The first 96 bytes of a real song written by FastTracker 2, with four channels and nine positions:
00000000 45 78 74 65 6E 64 65 64 20 4D 6F 64 75 6C 65 3A Extended Module:
00000010 20 6D 61 72 69 6F 20 6C 61 6E 64 20 32 20 74 68 mario land 2 th
00000020 65 6D 65 20 20 1A 46 61 73 74 54 72 61 63 6B 65 eme .FastTracke
00000030 72 20 76 32 2E 30 30 20 20 20 04 01 14 01 00 00 r v2.00 ......
00000040 09 00 01 00 04 00 08 00 06 00 01 00 05 00 76 00 ..............v.
00000050 07 00 01 00 02 03 04 05 06 00 00 00 00 00 00 00 ................
| Offset | Bytes | Meaning |
|---|---|---|
| 0 | 45 78 … | "Extended Module: " |
| 17 | 6D 61 72 69 6F … | the name "mario land 2 theme", padded to 20 bytes with spaces |
| 37 | 1A | the marker |
| 38 | 46 61 73 74 54 … | "FastTracker v2.00 ", 20 bytes |
| 58 | 04 01 | version 0x0104 |
| 60 | 14 01 00 00 | header size 0x0114 = 276 |
| 64 | 09 00 | song length 9 |
| 66 | 01 00 | restart position 1 |
| 68 | 04 00 | 4 channels |
| 70 | 08 00 | 8 patterns |
| 72 | 06 00 | 6 instruments |
| 74 | 01 00 | flags: linear frequency table |
| 76 | 05 00 | 5 ticks a row |
| 78 | 76 00 | 118 BPM |
| 80 | 07 00 01 00 02 03 04 05 06 | the played positions: patterns 7, 0, 1, 0, 2, 3, 4, 5, 6; the rest of the 256 bytes are zero |
OpenMPT writes the header differently. The song of the OpenMPT test module below has
one position, and its header size is 21, which is the 20 bytes of fields and one byte of
order table, so the first pattern header (09 00 00 00 00 40 00 …) starts
right after at offset 81:
00000030 31 2E 30 37 2E 30 30 20 20 04 01 15 00 00 00 1.07.00 ......
00000040 01 00 00 00 04 00 01 00 02 00 01 00 06 00 78 00 ..............x.
00000050 00 09 00 00 00 00 40 00 FF 01 8B 34 01 08 83 3F ......@....4...?
ID text
The 17 bytes Extended Module: , the last one a space (20). A
file with any other start is not an XM file. libxmp’s xm_test compares exactly these 17
bytes (memcmp with "Extended Module: "); MilkyTracker’s loader compares only the first
16, "Extended Module:", without the space. The format description (xm.txt, by Mr.H) spells the text with a lower-case m,
'Extended module: ', which no loader read here accepts, since both comparisons are case-sensitive; real files have the capital M.
Module name
The song title, 20 bytes. FastTracker 2 pads it with spaces; ModPlug Tracker, OpenMPT and some other programs pad it with zero bytes. The padding is one of the clues to the program that wrote the file. The text is in the DOS code page 437 in files from FastTracker 2 and in Windows-1252 in files from ModPlug Tracker and OpenMPT.
Marker
One byte, 1A (Ctrl-Z, the DOS end-of-file character, which made
TYPE stop printing before the binary data). FastTracker 2 always writes it
and no loader checks it.
Tracker name
20 bytes naming the program, padded with spaces. FastTracker 2 writes
FastTracker v2.00 , and many other programs copy that text so that old
players accept their files. Which programs write what is on
versions and trackers.
Version
A 16-bit number, the major version in the high byte and the minor in the low byte, so
04 01 in the file is 1.04. FastTracker 2 writes 0x0104. The
original description says the file is version 0x0103 in one place and
0x0104 in another; the files written by FT2 2.x all say 1.04. Versions
1.02 and 1.03 come from FastTracker 2's betas and lay the file out differently:
the layouts. The FT2 clone
refuses anything below 1.02 and above 1.04; OpenMPT and libxmp read a later version as
1.04 and an earlier one as 1.03.
Header size
The size of the rest of the header, counted from this field. The patterns start at offset 60 plus this value. FastTracker 2 writes 276: 4 bytes for this field, 16 for the eight 16-bit fields that follow it, and 256 for the order table. Other programs write other values, and a reader must use it rather than assume 276:
| Value | Written by |
|---|---|
| 276 | FastTracker 2 and most others. |
| 20 + song length | OpenMPT: the order table holds only the played positions. The example above is 21. |
| 275 | Modules by Filip Skutela with the tracker name FastTracker v2.00, per libxmp's notes. |
| more than 276 | The extra bytes are skipped. |
| less than 276 | BoobieSqueezer, a packer that strips unused data, keeps the header size honest (libxmp reads it for that reason). |
The loaders copy the song-length entries of the order table from offset 80 whatever the header size is. When the header is shorter than 276, the bytes they copy past the header's end are the start of the first pattern, but only entries inside the song length are used, so it makes no difference unless the song length is larger than the header allows. A header size below 20 leaves no room for the song fields and the explorer reports the file as damaged.
Song length
How many positions of the order table are played, 1 to 256. FastTracker 2 plays at most
255; for 256 the explorer's replayer plays 255 as well. A length of 0 is treated as 1,
so the song plays pattern 0 (OpenMPT instead allows an empty order list in files it
wrote). Some programs pad the order table with FF after the song length
and some count them in the length; the FT2 clone's loader removes FF
entries from the end of the played part.
Restart position
The position the song jumps to when it reaches the end of the order list. A value at or past the song length means position 0 (libxmp and the clone both do this). FastTracker 2's own player follows it every time the song ends; the explorer stops at the first end of the order list and shows how long the song plays once.
Channels
The number of channels in every pattern: 2 to 32 in FastTracker 2, an even number there (the clone reads an odd one and adds a channel). OpenMPT and ModPlug Tracker allow more, up to 192 in OpenMPT 0.8. Zero is invalid. The clone reads 33 or more channels from the patterns, keeps the first 32 and discards the rest; the explorer plays all of them.
Patterns
The number of patterns stored, 0 to 256. It may be fewer than the highest pattern number in the order table plus one: FastTracker 2 does not save empty patterns at the end of the list. A position that names a pattern past this count plays an empty pattern of 64 rows.
Instruments
The number of instrument headers that follow, 0 to 128. OpenMPT writes up to 255, and libxmp reads that many. MOD2XM, a converter, always writes 31 here and then cuts the file short after the last real instrument; a reader must stop at the end of the file rather than fail.
Flags
| Bit | Mask | Meaning |
|---|---|---|
| 0 | 0001 | Frequency table: 0 Amiga, 1 linear. See frequency tables. |
| 12 | 1000 | OpenMPT only: extended filter range. |
| all others | Unused; FastTracker 2 writes 0. |
Default tempo
The speed: how many ticks make a row, 1 to 31, 6 by default. The name is confusing: the format description calls this field the tempo and the next one the BPM, and the Fxx effect with xx below 32 changes it. The FT2 clone plays a value of 0 as 1 and clamps one above 31 to 31.
Default BPM
The tempo in beats per minute, 32 to 255, 125 by default. A tick lasts 2.5 / BPM seconds, so 125 BPM is 50 ticks a second and a row at speed 6 is 120 ms. The clone clamps the value to 32 to 255 and OpenMPT allows more. MED2XM stores a different tempo scheme: a value below 10 is converted by libxmp as 125 × (53 − 2 × BPM) / 33.
Order table
Up to 256 bytes, one pattern number for each position of the song. FT2 always writes all 256; OpenMPT writes only the played ones (see header size). The pattern numbers are 0 to 255. A pattern number that is not stored plays as an empty pattern of 64 rows.
How readers treat bad values
| Field | FT2 clone | OpenMPT | libxmp |
|---|---|---|---|
| version | refuses below 1.02 and above 1.04 | reads any; below 1.04 as the old layout | up to 1.03 as the old layout |
| song length | over 256 is an error; 0 becomes 1 | any; 0 gives an empty order list in OpenMPT's own files, else pattern 0 | over 256 is an error |
| channels | 0 is an error; over 32 keeps 32 | 0 or over 192 is not an XM file | over the player's limit is an error |
| patterns | over 256 is an error | reads them all | over 256 is an error |
| instruments | over 256 is an error; keeps 128 | keeps 255 | over 255 is an error |
| speed and BPM | clamped to 1 to 31 and 32 to 255 | a speed of 0 is left at the default; BPM clamped to its range | a speed of 32 or more, or a BPM below 32 or above 1000, is an error (except from MED2XM) |
| header size | seeks to 60 plus the size | the same | the same, and refuses a size below 20 or above 276 |