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. |
| 4D | 1 | u8 | ViD | Vibrato depth, 0 to 64. |
| 4E | 1 | u8 | ViT | Vibrato waveform. |
| 4F | 1 | u8 | ViR | Vibrato rate, 0 to 64. The depth grows by the rate each cycle; the depth used is the running sum divided by 256. |
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. |
Bits other than bit 0 exist for loading other formats. Modern players act only on bit 0 and, for compressed samples, on delta encoding (bit 2).
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. Stereo data, written by
other programs since Impulse Tracker has no stereo samples, holds the left channel
first and then the right.
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.