Introduction
A raw PCM file holds audio samples and nothing else: no header, no sample rate, no channel count. It is what is left of a WAV or AIFF file without its chunks. Raw files come from recording tools, embedded devices, games and audio programming, where the program that reads the file already knows the format.
To play one, you have to tell the software how the samples are stored. The extensions
.pcm and .raw are common, but nothing in the file confirms
it is audio.
Structure
The file is a plain run of sample values, interleaved by channel: for stereo, left, right, left, right. Four things must be known from outside the file: the sample format (8-, 16-, 24- or 32-bit integer, or floating point; signed or unsigned), the byte order, the number of channels and the sample rate. Read with the wrong settings, the audio plays as noise, at the wrong speed or with the channels mixed up.
| Typical use | Sample format | Channels | Rate |
|---|---|---|---|
| CD audio | 16-bit signed, little-endian | 2 | 44100 Hz |
| Telephone | 8-bit µ-law or A-law | 1 | 8000 Hz |
| Speech recognition | 16-bit signed, little-endian | 1 | 16000 Hz |
| Audio processing | 32-bit float, little-endian | 1 or 2 | 48000 Hz |
Links
Software
- Audacity – free audio editor that opens raw audio with File, Import, Raw Data (Windows, macOS, Linux)
- SoX – command-line sound converter that reads and writes raw audio when told its format (Windows, macOS, Linux)
- FFmpeg – command-line tool that reads raw audio with input options such as
-f s16le(Windows, macOS, Linux)
Developers
- libsndfile – library that reads raw files when given their format (C)
- NumPy – array library whose
fromfilereads raw samples into an array (Python)