Each sample has an 80-byte header that starts IMPS, found through the
sample offset table. The sample data
itself sits wherever the header’s SamplePointer says. Offsets on this page are in
hexadecimal.
Sample header
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 00 | 4 | ASCII | magic | IMPS. |
| 04 | 12 | text | filename | DOS 8.3 file name. |
| 10 | 1 | u8 | null | Always 0. |
| 11 | 1 | u8 | GvL | Global volume, 0 to 64. |
| 12 | 1 | u8 | Flg | Sample flags. |
| 13 | 1 | u8 | Vol | Default volume, 0 to 64. |
| 14 | 26 | text | name | Includes the terminating zero byte. |
| 2E | 1 | u8 | Cvt | Convert flags. |
| 2F | 1 | u8 | DfP | Default pan: bits 0 to 6 the pan, bit 7 set to use it. This is the opposite sense to the instrument’s DfP. |
| 30 | 4 | u32 | Length | Length in samples, not bytes. |
| 34 | 4 | u32 | Loop begin | In samples. |
| 38 | 4 | u32 | Loop end | The sample after the loop’s last. |
| 3C | 4 | u32 | C5Speed | Samples per second at note C-5, 0 to 9,999,999. |
| 40 | 4 | u32 | Sustain loop begin | In samples. |
| 44 | 4 | u32 | Sustain loop end | The sample after the sustain loop’s last. |
| 48 | 4 | u32 | SamplePointer | File offset of the sample data. |
| 4C | 1 | u8 | ViS | Vibrato speed, 0 to 64: the position in the waveform table moves by this each tick. With 0 there is no vibrato. |
| 4D | 1 | u8 | ViD | Vibrato depth, 0 to 64: the most the depth grows to. |
| 4E | 1 | u8 | ViR | Vibrato rate, 0 to 64: how fast the depth builds up. A counter grows by the rate each tick; its high byte is the depth, held at ViD. With a rate of 0 the depth stays 0. OpenMPT and XM call this field “sweep”. |
| 4F | 1 | u8 | ViT | Vibrato waveform. |
A sample file (.its) adds cache information after the 80 bytes: the file
size (4 bytes), date and time (2 bytes each) and a format byte (0 unchecked, 1
directory, 2 IT sample, 3 ST sample).
Sample flags
| Bit | Value | Meaning when set |
|---|---|---|
| 0 | 01 | A sample is associated with this header. |
| 1 | 02 | 16-bit samples (clear: 8-bit). |
| 2 | 04 | Stereo. Not supported in Impulse Tracker itself. |
| 3 | 08 | Compressed. |
| 4 | 10 | Loop on. |
| 5 | 20 | Sustain loop on. |
| 6 | 40 | Ping-pong loop (clear: forwards). |
| 7 | 80 | Ping-pong sustain loop (clear: forwards). |
Convert flags
| Bit | Value | Meaning when set |
|---|---|---|
| 0 | 01 | Samples are signed. Impulse Tracker 2.01 and earlier used unsigned; 2.02 and later use signed. |
| 1 | 02 | Motorola byte order for 16-bit samples. |
| 2 | 04 | Delta-encoded samples. |
| 3 | 08 | Byte delta (PTM loader). |
| 4 | 10 | TX-Wave 12-bit samples. |
| 5 | 20 | Prompt for left, right or all stereo. |
| 6–7 | C0 | Reserved. |
ITTECH.TXT calls bits 1 to 5 “safe to ignore”; Impulse Tracker itself uses them for loading other formats, and libopenmpt acts on them: bit 1
(big-endian), bit 2 (delta values, or IT 2.15 when the sample is compressed), bit 3 (with a 16-bit sample: each point is two delta-coded bytes,
the first the low byte, the second the high byte; used by the PTM loader). A convert byte of FF on an uncompressed 8-bit sample is
ModPlug Tracker’s ADPCM packing: 16 signed step values, then one byte for every two points, low nibble first; each step is added to a running 8-bit value.
Bits 4 and 5 (TX-Wave 12-bit values, the stereo prompt) are only used inside Impulse Tracker’s own loaders. OpenMPT also uses 40 and 80 in .mptm files
(FM instruments, samples kept on disk). The explorer’s decoder was compared with libxmp’s on 481 samples of the IT 2.14, IT 2.15, ADPCM, 16-bit,
unsigned and delta kinds and agrees on all of them.
Vibrato waveforms
| Value | Waveform |
|---|---|
| 0 | Sine |
| 1 | Ramp down |
| 2 | Square |
| 3 | Random (the speed is ignored) |
Sample data
Uncompressed data is Length values of 8 or 16 bits, little-endian unless convert bit 1 is set.
Stereo (flag bit 2) is not supported by Impulse Tracker (“Stereo samples not supported yet” in ITTECH.TXT). Other programs write it
as two blocks: all the points of the left channel, then all the points of the right (libopenmpt’s stereoSplit
in ITSample::GetSampleFormat), and for a compressed sample the left channel’s blocks and then the right’s. The flag is honoured when the
file’s Cwt/v is 0214 or later; before that some Impulse Tracker versions left it set by mistake. When the sample plays, OpenMPT mixes both
channels; this explorer’s replayer does the same and the waveform shows both.
Compressed sample data
When bit 3 of the flags is set the data is split into blocks. Each block expands to at
most 32,768 bytes (32,768 samples at 8 bits, 16,384 at 16 bits), and the last block may
be shorter. The header’s Length gives the uncompressed length and says
when to stop. Each block starts with a 16-bit size of the compressed data that follows,
not counting those two bytes. The stream is read bit by bit, least significant bit
first.
A block starts with a width of 9 bits (8-bit samples) or 17 bits (16-bit samples) and a running value of 0. Read width bits as v; depending on the width, v is either a change of width or a sample delta:
| Width | Change of width |
|---|---|
| 1 to 6 | v equals the top bit alone. Read 3 more bits (8-bit) or 4 (16-bit) to get the new width. |
| 7 up to one below the starting width | v lies from top bit − 4 to top bit + 3 (8-bit), or top bit − 8 to top bit + 7 (16-bit). The new width comes from v − (top bit + lower bound), where the lower bound is −4 or −8. |
| The starting width (9 or 17) | The top bit is set. The new width is (v without the top bit) + 1. |
In the first two cases, the value read is increased by 1 to give a width, and by 1 more if the result is not less than the current width, so the width can never stay the same. In the third case the value is used as it stands. A width greater than the starting width means the block is damaged; the decoder gives up on that block.
Anything else is a sample: treat v as a signed number of width bits (sign-extend it), add it to the running value, and write the running value as a sample. The running value resets to 0 at each block.
| Constant | 8-bit | 16-bit |
|---|---|---|
| Starting width | 9 | 17 |
| Bits for a change at widths 1 to 6 | 3 | 4 |
| Lower bound for the second case | −4 | −8 |
| Upper bound for the second case | 3 | 7 |
Samples compressed by version 2.15 and later are marked by bit 2 (delta) in the convert flags. For these, a second running value accumulates the first, and the second value is what gets written, so the data is delta-coded twice. Older files use one running value. Header values such as Cmwt do not distinguish the two; only the convert flag does. Convert flags apply per block. Stereo compressed data is the left channel in full, then the right.