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 the choices. Linear PCM is the plain case, where equal steps in a sample’s value are equal steps in the signal.
Layout
Samples follow each other with no gaps or markers. A sample frame is one sample per channel, and frames run in time order. The channels are interleaved, so stereo is left, right, left, right.
The size of a frame is the channels times the bytes 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.
Sample formats
| Encoding | Bytes | Range | Silence | FFmpeg name |
|---|---|---|---|---|
| 8-bit unsigned | 1 | 0 to 255 | 128 (80) | u8 |
| 8-bit signed | 1 | −128 to 127 | 0 | s8 |
| 16-bit signed | 2 | −32,768 to 32,767 | 0 | s16le, s16be |
| 16-bit unsigned | 2 | 0 to 65,535 | 32,768 | u16le, u16be |
| 24-bit signed | 3 | −8,388,608 to 8,388,607 | 0 | s24le, s24be |
| 24-bit unsigned | 3 | 0 to 16,777,215 | 8,388,608 | u24le, u24be |
| 32-bit signed | 4 | −2,147,483,648 to 2,147,483,647 | 0 | s32le, s32be |
| 32-bit unsigned | 4 | 0 to 4,294,967,295 | 2,147,483,648 | u32le, u32be |
| 32-bit float | 4 | nominally −1.0 to 1.0 | 0.0 | f32le, f32be |
| 64-bit float | 8 | nominally −1.0 to 1.0 | 0.0 | f64le, f64be |
| µ-law | 1 | companded | FF | mulaw |
| A-law | 1 | companded | D5 | alaw |
| Archimedes VIDC | 1 | companded, Acorn’s own | vidc |
Signed integers are two’s complement. Floats are IEEE 754, and may go past ±1.0, which software usually clips. Software differs on the factor to convert a float to an integer, such as 32,767 or 32,768 for 16 bits, so the conversion is not always exact. Companded formats are on the µ-law and A-law page.
Byte order
A sample of more than one byte is little-endian or big-endian. Little-endian is usual
on PCs and in 16-bit files from Windows software. Big-endian comes from older
Motorola, SPARC and PowerPC machines, and is the order of the audio in
audio/L16.
| Value | Little-endian | Big-endian |
|---|---|---|
| 1,000 (16-bit) | E8 03 | 03 E8 |
| −1,000 (16-bit) | 18 FC | FC 18 |
A stereo frame with a left sample of 1,000 and a right sample of −1,000, 16-bit
little-endian, is the four bytes E8 03 18 FC.
Telling how a file is encoded
Only the contents can suggest it. Sixteen-bit audio read with the right byte order shows the high byte moving slowly and the low byte quickly; read in the wrong order, the result plays as noise. A wrong channel count or sample rate changes the speed. A file of raw samples should have a size that is a whole multiple of the frame size.
File name extensions
Beyond .pcm and .raw, some tools identify a format by
extension:
| Extension | Meaning in FFmpeg |
|---|---|
.ub | 8-bit unsigned |
.sb | 8-bit signed |
.sw | 16-bit signed, in the machine’s byte order |
.uw | 16-bit unsigned, in the machine’s byte order |
.ul | µ-law |
.al | A-law |
.sln | Asterisk’s raw format: 16-bit signed little-endian, 8,000 Hz |
FFmpeg’s raw PCM readers default to 44,100 Hz mono unless given
-ar and -ac options. Its sln reader defaults to
8,000 Hz.