In a 0x0104 file the instruments follow the patterns. Each has an instrument
header, and if it has samples, an extended header, then the headers of its samples, then
the data of its samples. Numbers are little-endian.
Instrument header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | header size | Size of the whole instrument header. Often larger than the documented structure, so a reader should skip by it. |
| 4 | 22 | text | name | The instrument name. |
| 26 | 1 | u8 | type | Usually 0, but unreliable. |
| 27 | 2 | u16 | samples | Number of samples in this instrument. |
Extended instrument header
Present only when the instrument has samples.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 29 | 4 | u32 | sample header size | Size of each sample header, normally 40. |
| 33 | 96 | u8 × 96 | note map | The sample number for each note. |
| 129 | 48 | points | volume envelope | 12 points of 4 bytes. |
| 177 | 48 | points | panning envelope | 12 points of 4 bytes. |
| 225 | 1 | u8 | volume points | Number of points used. |
| 226 | 1 | u8 | panning points | Number of points used. |
| 227 | 1 | u8 | volume sustain | A point number. |
| 228 | 1 | u8 | volume loop start | A point number. |
| 229 | 1 | u8 | volume loop end | A point number. |
| 230 | 1 | u8 | panning sustain | A point number. |
| 231 | 1 | u8 | panning loop start | A point number. |
| 232 | 1 | u8 | panning loop end | A point number. |
| 233 | 1 | u8 | volume type | Envelope flags. |
| 234 | 1 | u8 | panning type | Envelope flags. |
| 235 | 1 | u8 | vibrato type | Waveform. |
| 236 | 1 | u8 | vibrato sweep | |
| 237 | 1 | u8 | vibrato depth | |
| 238 | 1 | u8 | vibrato rate | |
| 239 | 2 | u16 | volume fadeout | 0 to 0FFF. |
| 241 | 2 | – | reserved |
Envelope points
Each point is two 16-bit words: the frame number (X), then the value (Y), which is 0 to 64. Envelopes advance once per frame.
Envelope flags
| Bit | Value | Meaning when set |
|---|---|---|
| 0 | 01 | Envelope on. |
| 1 | 02 | Sustain. |
| 2 | 04 | Loop. |
Automatic vibrato
Automatic vibrato runs by itself, separately from the envelopes.
| Value | Waveform |
|---|---|
| 0 | Sine |
| 1 | Square |
| 2 | Ramp up |
| 3 | Ramp down |
The waveform codes come from the FastTracker 2 clone’s replayer. Speed (rate) is
00 to 3F, depth 00 to 0F, and sweep
00 to FF; other trackers may use up to FFFF.
Volume fadeout
After a key off, a fade value starts at 65,536 and drops by the instrument’s fadeout value each tick. It is not processed when the volume envelope is off. See the volume formula.
Sample header
All of an instrument’s sample headers come before any of its sample data. Each is 40 bytes.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | u32 | length | Length in bytes. |
| 4 | 4 | u32 | loop start | In bytes. |
| 8 | 4 | u32 | loop length | In bytes. |
| 12 | 1 | u8 | volume | 0 to 64. |
| 13 | 1 | s8 | finetune | Signed, in steps of 1/128 of a semitone in FastTracker 2. |
| 14 | 1 | u8 | type | Loop mode and bit depth. |
| 15 | 1 | u8 | panning | 0 to 255. |
| 16 | 1 | s8 | relative note | −96 to 95. The played note is pattern note + relative note. |
| 17 | 1 | – | reserved | |
| 18 | 22 | text | name | The sample name. |
Sample type bits
| Bits | Value | Meaning |
|---|---|---|
| 0–1 | 0 | No loop. |
| 0–1 | 1 | Forward loop. |
| 0–1 | 2 | Ping-pong loop. The XM notes write this as binary 11 and decimal 2, which disagree; FastTracker 2 clone uses 2. |
| 4 | 10 | 16-bit sample data. |
Sample data
Samples are signed and stored as differences from the previous value, starting from 0. 16-bit data works the same way in 16-bit units.
old = 0
for each stored value v:
new = v + old
write new
old = new
Length and loop values are in bytes even for 16-bit samples, so a 16-bit sample of 1,000 values has a length of 2,000.