A raw PCM file has no header and no specification. Nothing in it says how to read it: the program must be told. This page sets out every way a sample can be stored that the explorer’s options bar offers. Linear PCM is the plain case, where equal steps in a sample’s value are equal steps in the signal. The other encodings are on their own pages: µ-law and A-law, DPCM and ADPCM and DSD and PDM.
Frames
Samples follow each other with no gaps or markers. A frame is one sample for every channel, and frames run in time order. The size of a frame is the channels times the bits per sample. The data rate is the frame size times the sample rate: CD audio, at two 16-bit channels and 44,100 Hz, uses 176,400 bytes a second. The number of frames is the file’s size divided by the frame size, which should have no remainder; a remainder is a trailer, a header that was not skipped, or a wrong guess. How channels are ordered is on Channels and layout.
Linear integer samples
The explorer’s Format is Linear PCM (integer); Bits and Sign choose the row.
| Bits | Stored in | Signed range | Unsigned range | Silence (signed) | Silence (unsigned) | FFmpeg names |
|---|---|---|---|---|---|---|
| 8 | 1 byte | −128 to 127 | 0 to 255 | 00 | 80 | s8, u8 |
| 16 | 2 bytes | −32,768 to 32,767 | 0 to 65,535 | 0000 | 8000 as 16-bit | s16le, s16be, u16le, u16be |
| 24 | 3 bytes | −8,388,608 to 8,388,607 | 0 to 16,777,215 | 000000 | 800000 as 24-bit | s24le, s24be, u24le, u24be |
| 32 | 4 bytes | −2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 | 00000000 | 80000000 as 32-bit | s32le, s32be, u32le, u32be |
In the explorer a code of n bits becomes a value from −1 to just under +1 by dividing by 2n−1, after the sign rule below has made it a signed number.
Signed, unsigned, sign and magnitude, ones’ complement
The Sign option says how the bits of a code stand for a number. For an 8-bit code
b:
| Rule | Value of a code | 00 | 7F | 80 | 81 | FF |
|---|---|---|---|---|---|---|
| Signed (two’s complement) | b, or b − 256 when the top bit is set | 0 | 127 | −128 | −127 | −1 |
| Unsigned (offset binary) | b − 128 | −128 | −1 | 0 | 1 | 127 |
| Sign and magnitude | the low seven bits, negative when the top bit is set | 0 | 127 | −0 | −1 | −127 |
| Ones’ complement | b, or b − 255 when the top bit is set | 0 | 127 | −127 | −126 | −0 |
Unsigned is the same bits as signed with the top bit flipped. 8-bit WAVE files are unsigned; 16-bit and wider ones are signed. Read the wrong way, the sound is the right wave shifted by half the range: a quiet recording becomes a loud buzz whose samples jump from one end of the range to the other each time the wave crosses zero. The explorer’s Is this the right reading? table shows how much smoother the other reading is. Sign and magnitude and ones’ complement are rare; they appear in some converters and old hardware.
Worked hex examples
The same sample values written in each width and byte order. The values 1,000 and −1,000 are the signed integers; every row is checked by the explorer’s tests.
| Encoding | +1000 | −1000 |
|---|---|---|
| 16-bit signed, little-endian | E8 03 | 18 FC |
| 16-bit signed, big-endian | 03 E8 | FC 18 |
| 16-bit unsigned, little-endian | E8 83 | 18 7C |
| 24-bit signed, little-endian | E8 03 00 | 18 FC FF |
| 24-bit signed, big-endian | 00 03 E8 | FF FC 18 |
| 32-bit signed, little-endian | E8 03 00 00 | 18 FC FF FF |
| 32-bit signed, big-endian | 00 00 03 E8 | FF FF FC 18 |
Byte order is the Byte order option. A stereo frame with a left sample of +1,000 and a
right sample of −1,000 as 16-bit signed little-endian is the four bytes
E8 03 18 FC. 8-bit examples: unsigned 80 is silence,
C0 is half of the positive range (+0.5) and 40 is −0.5;
signed 40 is +0.5 and C0 is −0.5.
Byte order
A sample of more than one byte is little-endian (low byte first) or big-endian (high byte
first). Little-endian is usual on PCs and in 16-bit files from Windows software.
Big-endian comes from Motorola, SPARC and PowerPC machines, from Sun AU and AIFF, and
is the order of the audio in audio/L16. A sample is 16 bits whichever
order it is stored in, so a file read in the wrong order has the right bytes in the
wrong places: the high byte, which moves slowly, is read as the low one, which is
nearly random. The result is the same tune buried in loud noise.
Floating-point samples
IEEE 754 binary floats, nominally from −1.0 to +1.0 with 0.0 as silence. The explorer offers 32 and 64 bits, and the 16-bit half float and the 24-bit float some recorders write (1 sign bit, 7 exponent bits, 16 fraction bits). Floats may go past ±1.0, which software usually clips; the explorer clips to full scale and shows a NaN as silence.
| Value | 32-bit little-endian | 32-bit big-endian | 64-bit little-endian |
|---|---|---|---|
| +1.0 | 00 00 80 3F | 3F 80 00 00 | 00 00 00 00 00 00 F0 3F |
| +0.5 | 00 00 00 3F | 3F 00 00 00 | 00 00 00 00 00 00 E0 3F |
| −0.5 | 00 00 00 BF | BF 00 00 00 | 00 00 00 00 00 00 E0 BF |
| 0.0 | 00 00 00 00 | 00 00 00 00 | 00 00 00 00 00 00 00 00 |
Software differs on the factor that converts a float to an integer, 32,767 or 32,768 for 16 bits, so a round trip is not always exact. Float data read as integers is small, smooth and wrong: a 32-bit float at 0.5 as a signed 32-bit integer is about 1.06 billion.
Packed samples: 1, 2, 4, 12 and 20 bits
Samples narrower than a byte, and 12 and 20 bits, are packed with no padding. The Byte order option chooses which end comes first: big-endian puts the first sample in the high bits (how most packed formats are drawn), little-endian puts it in the low bits.
| Bits | Samples in | Bytes | First sample is | Example bytes | Samples |
|---|---|---|---|---|---|
| 1 | 1 byte | B7 … B0 | big: bit 7, little: bit 0 | B0 (10110000), unsigned, big | 1, 0, 1, 1, 0, 0, 0, 0 as the codes |
| 2 | 1 byte | big: bits 7–6, little: bits 1–0 | E4 (11 10 01 00), big | 3, 2, 1, 0 as the codes | |
| 4 | 1 byte | big: high nibble, little: low nibble | 1F, signed, big | +1, −1 | |
| 4 | 1 byte | 1F, signed, little | −1, +1 | ||
| 12 | 2 samples in 3 bytes | a b c | big: a followed by the high nibble of b; little: a with the low nibble of b above it | 12 34 56, big | 0x123, 0x456 |
| 12 | 12 34 56, little | 0x412, 0x563 | |||
| 12 | 23 61 45, little | 0x123, 0x456 | |||
| 20 | 2 samples in 5 bytes | a b c d e | big: the first 20 bits; little: a, b and the low nibble of c | 12 34 56 78 9A, big | 0x12345, 0x6789A |
| 20 | 45 23 A1 89 67, little | 0x12345, 0x6789A |
The codes are turned into values by the Sign rule like any other width: a signed 4-bit
F is −1 and 8 is −8, which are −1/8 and −1 of full scale.
A 20-bit sample stored in a 24-bit container, left-justified with the low four
bits zero, is simply 24-bit audio; the 20-bit option is for the packed form.
IEC 60958 subframes
The IEC 60958 subframes format reads 32-bit words as S/PDIF and AES3 send them: the audio is the 24-bit two’s-complement value in bits 4 to 27, and bits 28 to 31 are the validity, user, channel-status and parity bits. The layout and what the viewer checks are on S/PDIF, AES3 and HDMI captures, together with IEC 61937 data bursts, which the viewer recognises as compressed data rather than sound.
The other encodings
| Format option | What a sample is | Page |
|---|---|---|
| µ-law, A-law, VIDC | one byte indexing a logarithmic table | µ-law and A-law |
| DPCM | the change from the last sample: a byte or word, a square-root step, or a 4-bit table index | DPCM and ADPCM |
| ADPCM | a 2 to 5-bit step the decoder adapts to; IMA and Microsoft in blocks that start their own state; G.726 and G.722 as bare streams | DPCM and ADPCM |
| DSD, PDM | one bit at a very high rate | DSD and PDM |
File name extensions
Beyond .pcm and .raw, some tools identify a format by
extension. The explorer reads these as the Format, Bits, Sign and Byte order shown:
| Extension | Meaning |
|---|---|
.ub, .u8 | 8-bit unsigned |
.sb, .s8 | 8-bit signed |
.sw, .s16 | 16-bit signed, little-endian (SoX and FFmpeg say “the machine’s byte order”) |
.uw, .u16 | 16-bit unsigned, little-endian |
.sl, .s32 | 32-bit signed, little-endian |
.s24, .u24, .u32 | 24-bit signed, 24-bit unsigned and 32-bit unsigned, little-endian |
.s1 to .s4, .u1 to .u4 | SoX’s deprecated names for 8, 16, 24 and 32 bits (signed and unsigned) |
.lu, .la | SoX’s µ-law and A-law with the bits of each byte in the opposite order (the explorer’s Law option “Bits of each byte in reverse order”) |
.f4, .f32 | 32-bit float, little-endian |
.f8, .f64 | 64-bit float, little-endian |
.ul, .ulaw | µ-law |
.al, .alaw | A-law |
.sln | Asterisk’s raw format: 16-bit signed little-endian, 8,000 Hz (also .sln16, 16 kHz, and .sln48, 48 kHz) |
.vox | Dialogic OKI ADPCM, 6,000 or 8,000 Hz |
.g726, .g726le | ITU G.726 ADPCM, 4 bits a code, 8,000 Hz; big-endian and little-endian bit order (FFmpeg’s demuxer names) |
.g722, .722 | ITU G.722 sub-band ADPCM, 16,000 Hz |
.cu8, .cs8, .cs16, .cf32, .cfile, .iq | radio I/Q pairs; see Where raw audio comes from |
FFmpeg’s raw PCM readers default to 44,100 Hz and one channel unless given
-ar and -ac; its sln reader defaults to 8,000 Hz.
SoX’s own types assume 8,000 Hz and one channel unless told otherwise (SoX format manual, “Raw (headerless) audio files”; the explorer does not
set a rate from .sw, .ub and the like, because a rate is not in the extension).
The extension is a convention: none of these names is checked by anything in the file.