Some “raw” audio files are not a run of samples but a run of codes: each says how the next sample differs from the last. Differential PCM (DPCM) codes the difference; adaptive differential PCM (ADPCM) also changes the size of a step as it goes, so loud passages get coarse steps and quiet ones fine steps. In every one, the decoder carries a state from code to code, so a file cannot be decoded from the middle, only from a place where the state is known: the start, or the start of a block. The explorer’s Format option lists each one under DPCM or ADPCM.
Byte and word deltas
Each code is a signed number, 8 or 16 bits, that is added to the running value, which
starts at 0 and wraps at the width of the code. This is the plain DPCM of a few
capture programs and the delta filter of audio compressors. Example, 8 bits: the
bytes 05 05 FB 00 give 5, 10, 5, 5.
SDX2 square-root delta
Interplay’s SDX2 codes each sample in one byte n (signed). Its value is
2 × n × |n|. When the byte is even this is the sample itself; when the byte is
odd it is added to the previous sample. The result is clipped to 16 bits. The bytes
10 20 30 03 04 05 F0 81 00 decode to 512, 2048, 4608, 4626, 32, 82,
−512, −32768 and 0: FFmpeg’s sdx2_dpcm decoder gives the same nine values.
8SVX Fibonacci-delta and exponential-delta
Two 4-bit codes to a byte; each code indexes a table of deltas added to an 8-bit running value that is clipped to −128…127.
| Code | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Fibonacci | −34 | −21 | −13 | −8 | −5 | −3 | −2 | −1 | 0 | 1 | 2 | 3 | 5 | 8 | 13 | 21 |
| Exponential | −128 | −64 | −32 | −16 | −8 | −4 | −2 | −1 | 0 | 1 | 2 | 4 | 8 | 16 | 32 | 64 |
In an IFF 8SVX file the packed body starts with a pad byte and the first sample’s value,
and the high nibble comes first; the explorer’s raw reading has no such start, begins at 0 and
takes the nibble order from Byte order (big-endian is high first, the 8SVX
order). The IFF file itself is on the
8SVX pages. Example: the byte 9A,
high nibble first, is codes 9 and A, deltas +1 and +2, so the samples are 1 and 3.
IMA (DVI) ADPCM
The Interactive Multimedia Association’s 4-bit ADPCM. The decoder keeps a 16-bit predictor and a step index from 0 to 88 into this table of steps:
7 8 9 10 11 12 13 14 16 17 19 21 23 25 28 31 34 37 41 45 50 55 60 66 73 80 88 97 107 118 130 143 157 173 190 209 230 253 279 307 337 371 408 449 494 544 598 658 724 796 876 963 1060 1166 1282 1411 1552 1707 1878 2066 2272 2499 2749 3024 3327 3660 4026 4428 4871 5358 5894 6484 7132 7845 8630 9493 10442 11487 12635 13899 15289 16818 18500 20350 22385 24623 27086 29794 32767
For each 4-bit code c with step s: the difference starts at
s >> 3; add s if bit 2 of c is set, s >> 1 if bit 1,
s >> 2 if bit 0; subtract it from the predictor if bit 3 is set, else add it;
clamp to 16 bits. The index then moves by −1, −1, −1, −1, 2, 4, 6, 8 for the low three
bits of c (the same whichever sign), and is held to 0…88.
Example, bare nibbles from predictor 0 and index 0: the byte 77 is two codes 7.
Code 7 at step 7: 0 + 7 + 3 + 1 = 11, so the sample is 11 and the index becomes 8.
The second 7 at step 16: 2 + 16 + 8 + 4 = 30, so the sample is 41.
Three arrangements of IMA ADPCM are offered:
| Format option | Layout | Samples in a block |
|---|---|---|
| IMA / DVI in blocks (WAVE 0x11) | per channel a 4-byte header (predictor as a 16-bit little-endian number, step index in one byte, one reserved byte), then groups of 4 bytes a channel, the channels in turn; each group is 8 codes, low nibble first | 1 + 8 × ((block − 4 × channels) ÷ (4 × channels)), a channel |
| IMA, bare nibbles | no headers: predictor 0 and index 0 at the start of the data and then a continuous stream of codes, the channels’ codes alternating; Byte order picks the nibble | 2 per byte |
IMA 4:1 (QuickTime ima4) | 34 bytes a channel and packet: a 16-bit big-endian header holding the top 9 bits of the predictor and the 7-bit step index, then 32 bytes of codes, low nibble first; the channels’ packets alternate | 64 a channel |
The Block size option is the WAVE nBlockAlign: the bytes in one block. A
mono block of 256 bytes holds 1 + 252 × 2 = 505 samples; a stereo block of 512
bytes holds 505 samples a channel. FFmpeg writes 1,024-byte blocks (2,041 samples a
channel for mono at 22,050 Hz); other encoders use 256, 512 or 2,048.
When the block size is wrong the first block decodes and the next starts in the wrong
place: the sound is right for a moment at every block that happens to line up and noise between.
Microsoft ADPCM
Blocks again (WAVE 0x02). Each block starts with a header, for each channel in
turn: one byte per channel for the predictor index, then a 16-bit little-endian
delta for each channel, then the channel’s previous sample s1, then
the sample before it s2 (each as a group of one value for every channel).
The first two samples of the block are s2 then s1. Then come 4-bit codes, the high nibble
first, taking the channels in turn.
A code is a signed nibble n (−8…7). The predictor index chooses a pair of coefficients (c1, c2) from
| Index | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| c1 | 256 | 512 | 0 | 192 | 240 | 460 | 392 |
| c2 | 0 | −256 | 0 | 64 | 0 | −208 | −232 |
The new sample is (s1 × c1 + s2 × c2) ÷ 256 + n × delta with the division
truncating toward zero, clamped to 16 bits; then s2 = s1,
s1 = the new sample, and delta = max(16, delta × A[code] ÷ 256) with
A = 230, 230, 230, 230, 307, 409, 512, 614, 768, 614, 512, 409, 307, 230, 230, 230 for
the unsigned code 0…15. A block of B bytes holds 2 + 2 × (B − 7 × channels) ÷ channels samples
a channel; a stereo block of 512 bytes holds 500. FFmpeg’s adpcm_ms decoder is
the reference these steps follow.
Yamaha, OKI and Creative: streams of codes
These have no blocks and no headers: a stream of 4-bit codes with the decoder state starting at its initial value. With two channels the codes alternate left and right.
| Codec | Nibble first | State | Output |
|---|---|---|---|
Yamaha (FFmpeg adpcm_yamaha) | low | 16-bit predictor, step from 127 to 24,576; difference table ±1, 3 … 15 times step ÷ 8; step scaled by 230, 230, 230, 230, 307, 409, 512, 614 ÷ 256 (the same eight for the negative codes) | 16-bit |
Dialogic / OKI VOX (FFmpeg adpcm_ima_oki) | high | 12-bit predictor; the IMA index rules over the first 49 steps of the IMA table, from 16 to 1,552 | 12-bit, shown ×16 |
Creative Technology (FFmpeg adpcm_ct) | high | 16-bit predictor that decays by 254/256 each step; step from 511 to 32,767, scaled by 230, 230, 230, 230, 307, 409, 512, 614 ÷ 256 | 16-bit |
All three are verified against FFmpeg’s decoders on the same bytes, for one and two
channels, by the explorer’s tests. Dialogic .vox files are OKI ADPCM at
6,000 or 8,000 Hz and are what the explorer assumes for that extension.
ITU G.726 and G.722
G.726 (which takes in G.721 and the 24 and 40 kbit/s G.723) codes 8,000 samples a second at 2, 3, 4 or 5 bits a sample: 16, 24, 32 or 40 kbit/s. The codes follow each other with no padding, so a 3-bit stream of 1,000 samples is 375 bytes. Two bit orders are in use, and they are the Byte order option:
| Byte order option | Order | Where | FFmpeg |
|---|---|---|---|
| Big-endian (default) | the first code is in the high bits of the first byte (“left-justified”) | WAVE and AU files, most hardware | -f g726 |
| Little-endian | the first code is in the low bits of the first byte (“right-justified”) | RFC 3551 packing, as the shared decoder’s littleBits option | -f g726le |
The Bits option is the code size. With several channels the codes alternate channel by channel, as in AU and WAVE files; each channel has
its own predictor. The decoder is the explorer’s shared/audio/g726.js (the one AU and WAVE use).
G.722 is sub-band ADPCM: each byte holds a 6-bit code for the low band and a 2-bit code for the high band and makes two 16-bit samples, so 8,000 bytes a second give 16 kHz audio. The 64 kbit/s mode (this reading) uses all eight bits; the 56 and 48 kbit/s modes drop one or two low-band bits, which a raw file cannot say. The Sample rate option is the rate of the output, 16,000 Hz.
Checked against FFmpeg’s raw demuxers on streams FFmpeg’s own encoders wrote from a two-tone signal: G.722 24,000 samples, equal. G.726 at each of the four code sizes and both bit orders: the explorer’s decoder is ITU STL-exact (checked against the ITU test sequences), and FFmpeg’s g726.c is not, so the two differ (measured per code size, from 23 to nearly all of 12,800 samples; scripts/pcm/g726-ffmpeg-compare.mjs). The packing and the code-size mapping do agree: the same codes are read in the same order, and the frame count equals FFmpeg’s.
The streams FFmpeg decodes from random bytes also drive the predictor to saturation and differ in the last bits.
Extensions: .g726 (4 bits, big-endian, 8,000 Hz), .g726le (little-endian), .g722 and .722 (16,000 Hz).
What is not here
Scope (pending the owner’s ruling on how far a container or raw page goes: marked so in the project notes): these codecs have their own formats, and their bitstreams belong to those pages, not to “raw PCM”, whose job is a stream that has no header: Sound Blaster 2, 2.6 and 4-bit ADPCM (inside VOC files, whose blocks carry the codec’s own header), the Duck, Xbox, Nintendo and PlayStation families, and the MPEG-4 and Apple formats. A bare stream of such a codec has no raw convention to describe, and the explorer reads it from its container. See the overview’s Not described list.
Source: IMA ADPCM: the Interactive Multimedia Association’s Recommended Practices for Enhancing Digital Audio Compatibility in Multimedia Systems (DATWG, 21 October 1992), section 6 (the step table, the index table, the 4-bit decompression algorithm and its worked example, 0x8700 plus 63 giving 0x873F) and Appendix A (data types). The tables, the example and the viewer’s block decoder were compared by script. The WAVE block layouts of IMA and Microsoft ADPCM and the Yamaha, OKI and Creative codecs are not in that text: they follow FFmpeg’s decoders (the Microsoft ADPCM tables are FFmpeg’s copy of libsndfile’s; Microsoft’s own document was not obtained). Fibonacci-delta: EA’s 8SVX supplement, Appendix C. G.722 and G.726: the ITU recommendations themselves were not read for this page.