In version 1.04 each instrument is a header, then that instrument's sample headers, then the data of its samples; the next instrument follows. In 1.02 and 1.03 the headers (with their sample headers) all come first, then the patterns, then every sample's data (layouts). An instrument holds up to 16 samples in FastTracker 2 (32 in OpenMPT) and says which one each of the 96 notes plays. Numbers are little-endian; offsets in the tables are from the start of the instrument header.
Instrument header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | header size | The size of the instrument header, counting this field. The sample headers start this many bytes from the start of the instrument. FT2 writes 263 for an instrument with samples and 33 for one without. 0 is read as 263. |
| 4 | 22 | text | name | The instrument name. |
| 26 | 1 | u8 | type | Always 0 in the format description, but FT2 writes a random value, the same in every instrument of a module. |
| 27 | 2 | u16 | number of samples | How many sample headers follow, 0 to 16 (OpenMPT 32). If it is 0, the header may end here (size 29) or after the next field (33). |
| 29 | 4 | u32 | sample header size | The size of one sample header: 40. FT2 writes it here, in the instrument header, even for an instrument with no samples (33 bytes); the original description put it at the start of the sample headers. |
| 33 | 96 | u8 × 96 | sample map | The sample (0 to 15) each note C-0 to B-7 plays. |
| 129 | 48 | 12 × (u16, u16) | volume envelope points | A tick and a value for each point. |
| 177 | 48 | 12 × (u16, u16) | panning envelope points | |
| 225 | 1 | u8 | volume points | How many points of the volume envelope are used, up to 12. |
| 226 | 1 | u8 | panning points | The same for the panning envelope. |
| 227 | 1 | u8 | volume sustain point | An index into the volume points. |
| 228 | 1 | u8 | volume loop start | |
| 229 | 1 | u8 | volume loop end | |
| 230 | 1 | u8 | panning sustain point | |
| 231 | 1 | u8 | panning loop start | |
| 232 | 1 | u8 | panning loop end | |
| 233 | 1 | u8 | volume type | Bit 0 on, bit 1 sustain, bit 2 loop. |
| 234 | 1 | u8 | panning type | The same bits. |
| 235 | 1 | u8 | vibrato type | 0 sine, 1 square, 2 and 3 ramps: see the table. |
| 236 | 1 | u8 | vibrato sweep | 0 to 255. |
| 237 | 1 | u8 | vibrato depth | 0 to 15. |
| 238 | 1 | u8 | vibrato rate | 0 to 63. |
| 239 | 2 | u16 | volume fadeout | 0 to 4095. |
| 241 | 1 | u8 | MIDI on | FT2's MIDI output: 1 sends the instrument to MIDI. |
| 242 | 1 | u8 | MIDI channel | 0 to 15. |
| 243 | 2 | u16 | MIDI program | 0 to 127. |
| 245 | 2 | u16 | MIDI pitch bend range | In half-tones, 0 to 36. |
| 247 | 1 | u8 | mute computer | FT2: 1 mutes the sound card for this instrument when MIDI is on. |
| 248 | 15 | bytes | reserved | Whatever was in memory; FT2 does not clear them. |
The format description of 1994 lists only two reserved bytes after the fadeout; FT2 files have 22 (the MIDI fields and the 15 reserved bytes), per libxmp's notes. The header is 263 bytes in all.
| Header size | Where it comes from |
|---|---|
| 263 | FastTracker 2 for an instrument with samples; ModPlug Tracker 1.0 beta and OpenMPT for all instruments (empty ones too). |
| 33 | FastTracker 2 for an instrument with no samples. |
| 29 | An instrument with no samples written by DigiTrakker, the XM Commenter and some converters: the sample header size field is missing. It means the field belongs to the sample headers, as the original description said ("Braintomb" by Jazztiz). |
| 245 | ModPlug Tracker 1.0 alpha. |
| less than 263 with samples | BoobieSqueezer strips the instrument data (envelopes and the rest) and keeps the sample headers; the instrument then has no keyboard map, envelopes or vibrato. libxmp supports it; the explorer shows the fields that fit and zeros for the rest. |
| more than 263 | The extra bytes are skipped. |
| 0 | Read as 263 (it usually means that). |
An instrument at the end of the list with no samples may have size 29 or 33. MOD2XM writes 31 instruments and cuts the file after the last used one, so the instrument count can be larger than what the file holds.
Worked example
The first instrument of a real song by FastTracker 2: a 263-byte header and a 40-byte sample header, then the data. The bytes of the envelope counts, flags, vibrato and fadeout (offset 225 to 240 of the header) are marked.
0000129A 07 01 00 00 6B 62 00 00 00 00 00 00 00 00 00 00 ....kb..........
000012AA 00 00 00 00 00 00 00 00 00 00 4F 01 00 28 00 00 ..........O..(..
…
0000137B 02 06 00 00 00 02 03 05 03 00 00 1C 0F 28 5D 01 .............(].
…
000013A1 54 00 00 00 00 00 00 00 54 00 00 00 40 E4 11 40 T.......T...@..@
000013B1 05 00 20 20 20 20 20 20 20 20 20 20 20 20 20 20 ..
000013C1 20 20 20 20 20 20 20 20 A8 70 12 00 FB FF B2 FF .p......
| Bytes | Meaning |
|---|---|
07 01 00 00 | header size 263 |
6B 62 00 … | name "kb", zero-padded to 22 bytes |
01 00, 28 00 00 00 | (offsets 27 and 29) one sample; sample header size 40 |
02, 06 | (225, 226) 2 volume points, 6 panning points |
00 00 00 | volume sustain 0, loop start 0, loop end 0 |
02 03 05 | panning sustain point 2, loop 3 to 5 |
03, 00 | volume type 3 (on, sustain), panning type 0 (off) |
00 1C 0F 28 | vibrato sine, sweep 28, depth 15, rate 40 |
5D 01 | fadeout 0x015D = 349 |
54 00 00 00 | sample length 84 bytes (42 16-bit points) |
00 00 00 00, 54 00 00 00 | loop start 0, loop length 84 bytes |
40, E4, 11, 40, 05, 00 | volume 64, finetune 0xE4 = −28, type 0x11 (16-bit, forward loop), panning 64, relative note +5, reserved 0 |
22 × 20 | sample name, blank |
A8 70, 12 00, FB FF … | the data: 16-bit deltas, so the points are 0x70A8, then 0x70A8 + 0x0012 = 0x70BA, then 0x70BA − 5 = 0x70B5 … |
Sample map
96 bytes, one for each note from C-0 (the first byte) to B-7. Each is the index of a sample of this instrument, 0 to 15. An index at or past the number of samples is not an error in FastTracker 2: it plays that slot of its 16, which is empty, so the note is silent (the clone clamps indexes above 15 to 15). libxmp marks such a note as playing nothing.
Envelopes
An envelope is up to 12 points, each a tick (the position in time) and a value. The volume envelope's values are 0 to 64 and the panning envelope's 0 to 64 with 32 in the middle (FT2 limits the panning values to 63; the clone clamps them). Ticks start at 0 and grow from point to point. FT2 uses ticks up to 255; other trackers may go to 65535, and the clone clamps them to 32767. Between points the value is interpolated in a straight line.
| Bit | Value | Type byte meaning |
|---|---|---|
| 0 | 01 | The envelope is on. |
| 1 | 02 | The sustain point is used: the envelope waits there until the note is released. |
| 2 | 04 | The loop between the loop start and loop end points is used. |
The point counts are up to 12; the sustain and loop indexes are 0 to 11 (the clone clamps them). How the envelope is stepped each tick, how it starts and stops on key off, and the effects that reposition it (Lxx) are on the playback page. The explorer draws each envelope with the points, the sustain point as an orange line and the loop as green lines.
Automatic vibrato
Each instrument can make its notes vibrate by itself, apart from the vibrato effect. The type is the waveform, the rate how fast the position moves a tick, the depth how far the pitch swings and the sweep how many ticks the depth takes to grow from zero.
| Type | Waveform |
|---|---|
| 0 | sine |
| 1 | square |
| 2 | ramp: the FT2 clone’s code is commented “ramp up”, a value that rises with the position ((((pos >> 1) + 64) & 127) − 64) |
| 3 | ramp: the clone’s code is commented “ramp down”, a value that falls with the position (((−(pos >> 1) + 64) & 127) − 64) |
The format description (xm.txt) only says “Vibrato type” and gives no values; the table above is read from the clone’s ft2_replayer.c (any other type value is a sine there). The value is added to the period, so the names describe the value, not the direction of the pitch.
The depth is 0 to 15 and the rate 0 to 63 (above them the clone clamps and an unknown type becomes 0). With a sweep of 0 the full depth applies from the first tick; otherwise the depth grows by depth × 256 / sweep (in 1/256 units) each tick until it reaches the depth, and keeps its value from the moment of a key off. The calculation is on the playback page.
Volume fadeout
After the note is released (by key off or a note-off note), its volume is lowered by this amount each tick, from 32768 to 0: a fadeout of 349 takes 94 ticks. The format description says 65536, but FT2 starts from 32768 and the values are 0 to 4095. A fadeout of 0 means no fade. Without a volume envelope, a key off sets the volume to 0 at once, so the fadeout is only heard on an instrument whose volume envelope is on, as the format description says. See playback.
Sample header
Forty bytes for each sample. After the instrument header come all the sample headers of the instrument, one after another; in version 1.04 the data of the instrument's samples follows them all.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | length | The length of the sample data in bytes: for 16-bit data two bytes a point, for stereo both channels. For an ADPCM sample, the length of the decoded data in bytes. |
| 4 | 4 | u32 | loop start | In bytes from the start of the sample. |
| 8 | 4 | u32 | loop length | In bytes. 0 means no loop. |
| 12 | 1 | u8 | volume | 0 to 64. |
| 13 | 1 | i8 | finetune | −128 to 127: 128 steps make one semitone (FT2 uses the top five bits). |
| 14 | 1 | u8 | type | Loop mode, 16-bit, stereo. |
| 15 | 1 | u8 | panning | 0 (left) to 255 (right); 128 is the middle. |
| 16 | 1 | i8 | relative note | Semitones added to the note. FT2 allows −48 to 71 (the description says −96 to 95). |
| 17 | 1 | u8 | reserved | FT2 stores the length of the sample name here. ModPlug Tracker stores 0xAD for an ADPCM sample. |
| 18 | 22 | text | name | The sample name. |
A note C-4 plays a sample with relative note 0 and finetune 0 at 8,363 Hz. Each semitone of relative note multiplies the rate by 21/12, and the sample's own rate is whatever the musician recorded it at: it is played back at the rate the note gives, not resampled.
Sample type bits
| Bits | Value | Meaning |
|---|---|---|
| 0–1 | 0 | No loop. |
| 0–1 | 1 | Forward loop. |
| 0–1 | 2 | Ping-pong loop: the loop plays forward, then backward, then forward again. |
| 0–1 | 3 | Both bits set: played as ping-pong by FT2, OpenMPT and the clone (ModPlug Tracker up to 1.11 set both). |
| 2–3 | Unused. | |
| 4 | 10 | 16-bit data. |
| 5 | 20 | Stereo data (MilkyTracker and OpenMPT): the left channel's points, then the right's. FT2 does not know it. |
| 6–7 | Unused. |
A loop is used only if its start and its length are inside the sample: if the loop start plus the loop length is past the end of the sample, or the length is 0, the FT2 clone turns the loop off and plays the sample once. (OpenMPT instead cuts the loop end back to the end of the sample.) For 16-bit samples the lengths and the loop are halved to count points, and for stereo halved again.
Sample data
Samples are signed and stored as differences: the first value is the first point, and every later value is the change from the point before. To decode, add up the values, wrapping at 8 or 16 bits:
old = 0
for each stored value d (8-bit signed, or 16-bit little-endian signed):
new = old + d (wraps at 256 or 65536)
point = new
old = new
A 16-bit sample is two bytes a point, little-endian. If a 16-bit sample's length in bytes is odd, the last byte is left over and ignored (a real song, "dirtysex.xm", has one); the reader must still skip the bytes the header says. A stereo sample stores all the left channel's differences first, then the right channel's, each decoded on its own; FT2-based players mix the two channels down to one by averaging.
The data of a sample is the number of bytes in its length (the ADPCM case below has its own). A file that ends in the middle of sample data is accepted: the explorer decodes the bytes that are there and treats the rest as zero differences.
Sample data is the largest part of most files. The data of the samples of one instrument follow their headers in order; an instrument with a sample of length 0 has no data for it.
ADPCM samples
ModPlug Tracker could pack an 8-bit mono sample with a 4-bit ADPCM. Such a sample has 0xAD in the reserved byte of its header and neither the 16-bit nor the stereo bit set. The data in the file is 16 bytes of a table of signed steps, then (length + 1) / 2 bytes of codes, each byte holding two 4-bit codes, the low one first. To decode, start at 0 and for each code add the step it picks from the table; the value is an 8-bit one that wraps. The header's length is the number of decoded points; the data in the file is 16 + (length + 1) / 2 bytes.
value = 0
for each byte of the codes:
value = (value + table[byte & 15]) and 255 ; output value
value = (value + table[byte >> 4]) and 255 ; output value
OpenMPT, libxmp and the FT2 clone read these samples.
OggMod samples
The OggMod tool converts the samples of an XM to Ogg Vorbis, to make the file smaller for
use with the FMOD library; it changes nothing else in the file (OpenMPT wiki, “Development: Formats/XM”; libxmp’s comments
name the extension .oxm). A Vorbis sample is a 32-bit field giving the decoded size in bytes, directly followed by the
Ogg Vorbis stream (its first page has OggS at offset 4 of the data: libxmp reads the 4 bytes and tests the next four for OggS). The header’s length is the size of this data in the file.
The wiki advises validating the Vorbis stream before treating a sample as Vorbis, so that a plain sample with OggS in that place is not mistaken for one. The tool does not know stereo
samples and does not clear their stereo flag, so such a sample is a mono Vorbis stream with the stereo flag still set; libxmp comments that “OXM stereo is a single channel non-interleaved stream” and halves
the length for the flag, and libxmp refuses a stream that is not mono.
How OpenMPT reads one (soundlib/Load_xm.cpp, ReadSampleData):
the data is OggMod only when OggS follows the 32-bit size and every Ogg page after it
is whole and has a correct checksum, with no byte left over; any other data is an ordinary
delta-coded sample. The pages are the Ogg framing of RFC 3533 (page header of 27 bytes and a
segment table; the CRC-32 has the generator polynomial 0x04C11DB7, is computed with the checksum
field set to zero and starts from zero), and the packets inside are Vorbis I packets. The decoded
audio is the sample itself: it is not delta coded. The number of points is the 32-bit size
divided by 2 for 16-bit data and by 2 again for the stereo flag; a stream that decodes to fewer points
leaves the rest of the sample silent, and one that decodes to more is cut. A stream whose channel
count is neither the one the flags say nor one channel under the stereo flag leaves the sample empty.
The decoded values are the float samples multiplied by 32768 (or 128 for 8-bit data), rounded and
clipped.
The explorer does all of this: the stream is shown as its Ogg pages with each page's checksum checked, decoded with its Vorbis I decoder, and the points play in the song and in the waveform of the sample. A stream it cannot decode is reported in the issues and the sample stays silent. The decoding was checked against libavcodec (ffmpeg) for a mono and a stereo stream made by libvorbis: every point within one step of 16 bits. libopenmpt 0.8.9 built with its stb_vorbis decoder renders a module with such a sample at a signal-to-error ratio of 31 to 34 dB against the explorer's replay (playback).