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, usually interleaved by channel: for stereo, left, right, left, right. Six things must be known from outside the file: how a sample is stored (the sample format: 1 to 64 bits, integer or float, signed or not, or a µ-law or A-law byte, a delta or ADPCM code, or a single bit), its byte order, the number of channels and how they share the bytes, the sample rate, and where the samples start and end (a header or trailer may be left on). Read with the wrong settings, the audio plays as noise, at the wrong speed or with the channels mixed up. No specification exists for such a file: what these pages describe is the sample data of other formats’ specifications, what other software accepts (FFmpeg, SoX, Audacity, libsndfile) and the codes of ITU-T G.711 and the codecs that have their own pages. Identifying a raw file says how to find the settings, Where raw audio comes from lists the usual sources and Conversion commands the commands.
| 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 |
| Software radio (RTL-SDR) | 8-bit unsigned I/Q pairs (.cu8) | 2 (I and Q) | 2,048,000 Hz |
| Super Audio CD | one bit, DSD64 | 2 | 2,822,400 Hz |
Reading a raw file in the explorer
Drop a raw file on the page (or any file, and use Read as, Raw PCM audio). Because nothing in the file says how to read it, an options bar sits above the viewer; every change reads the file again and the waveform, spectrogram and Play follow. The bar remembers what you chose for the next file in the same window.
| Group | Option | Choices |
|---|---|---|
| Range | Skip, Length | bytes to skip at the start, and how many to read (a header or trailer to leave out) |
| Detect | Detect | Manual, or one of the six best-ranked readings with its score; the Detected formats table lists twelve |
| Samples | Format | Linear integer, IEEE float, µ-law, A-law, Acorn VIDC, DPCM (byte or word deltas, SDX2, 8SVX Fibonacci and exponential), ADPCM (IMA in blocks, bare IMA, QuickTime IMA4, Microsoft, Yamaha, OKI/Dialogic, Creative, ITU G.726 and G.722), IEC 60958 (S/PDIF, AES3) subframes, DSD, PDM |
| Bits | 8, 12, 16, 20, 24, 32, and 1, 2, 4 packed (integers); 16, 24, 32, 64 (floats); 8, 16 (deltas); 2 to 5 (G.726) | |
| Sign | signed, unsigned, sign and magnitude, ones’ complement | |
| Byte order | little-endian or big-endian (for packed samples and nibbles: which end comes first; for DSD: LSB or MSB first) | |
| Law, Block size, Decimation | the µ-law or A-law variant; the ADPCM block in bytes (presets 128 to 4,096); the DSD and PDM decimation 8 to 128 | |
| Channels | Channels, Layout, Run size, Signal | 1 to 8, 10, 12, 16, 24 or 32; interleaved, planar or blocked; audio or radio I/Q |
| Timing | Sample rate, Playback speed | any rate from 100 Hz to 100 MHz with presets from 8,000 Hz to DSD512 and radio rates; 0.25× to 4× |
| Clean-up | Remove DC offset, Demodulate | centre each channel; AM or FM for I/Q recordings |
The fields marked Auto take their value from the file’s extension (.sw, .ub, .ul,
.cu8 …) and its name (voice_16k_mono_s16le.raw). Under the options the viewer shows the
facts (frames, duration, peak and RMS level, DC offset, bytes left over), a table that reads the same bytes the
other way round (signed against unsigned, the other byte order) so a wrong guess is visible, the ranked
readings with their scores, the waveform with Play (clicking it selects the bytes of that frame), a
spectrogram and, for radio files, the demodulated sound. A file that is really a compressed bitstream
carried as PCM (IEC 61937 or SMPTE 337M data bursts, as S/PDIF and HDMI carry AC-3 and DTS) is recognised
by its preamble and flagged as not sound, and a six- or eight-channel reading shows the channel order
FFmpeg assumes (channel order).
Not described
A headerless file has no specification, so these pages follow ITU-T G.711, the IMA recommended practices, the Sony DSF specification, and FFmpeg’s decoders and documentation (downloaded and listed in Research/Specs/pcm/SOURCES.md). Every encoding the options bar offers was built, converted with FFmpeg and compared with FFmpeg’s decode of the same bytes.
Scope, stated so that it is not a gap (pending the owner’s ruling on how far a raw or container page goes): a raw reading is a convention for a stream with no header. Codecs whose streams have their own format are read from it, not here: Sound Blaster ADPCM (VOC), the Duck, Xbox, PlayStation, Nintendo and AICA game codecs, the MPEG-4 and Apple ADPCMs, and DST-compressed DSD, none of which has a bare-stream convention (DPCM and ADPCM). DVD and Blu-ray LPCM lives inside the MPEG streams, with its header on every packet; its layouts are written down (sources) and are not a headerless file. The sample rate and the channel count are not in the bytes, so they cannot be guessed and are options; the detector ranks one and two channels. Yamaha, OKI and Creative ADPCM decode one or two interleaved channels and need the planar layout for more, because their codecs are defined per channel; the block ADPCMs ignore the layout, because their blocks carry every channel.
Known, not yet covered
- None.
Unknown
- Reference: the SoX, Audacity and NumPy instructions come from their documentation: none of the three is installed on the Mac where the pages were checked (installing software was not allowed), so they were not run. FFmpeg’s equivalents were. The SoX format manual could not be downloaded.
- Reference: the console and machine table on Where raw audio comes from follows the
machines’ documentation. The Acorn VIDC data sheet and Microsoft’s ADPCM specification
were not obtained: VIDC is derived from FFmpeg’s table (all 256 codes agree) and Microsoft ADPCM follows FFmpeg’s decoder.
The DSDIFF (
.dff) bit order and byte interleaving are not described because no specification was obtained; DSF is from Sony’s specification. - Reference: the Sega, Nintendo and PlayStation rows, the telephone-recorder habits and the PDM microphone rates on the pages are common knowledge and not tied to a file here.
- Reference and viewer: the IEC 60958 subframe layout rests on the standard’s description as ALSA and the AES3 summaries give it (the standards are paid). Where SMPTE 337M puts Pc and Pd in 24-bit words is not known (the standard was not obtained), so a 24-bit burst is reported by its preamble alone.
- Reference: the DVD and Blu-ray LPCM layouts follow FFmpeg’s decoders.
- Reference: a single right way to convert floating-point samples to integers does not exist; software differs, as the page says.
- Reference and viewer: the nibble order of 8SVX Fibonacci-delta data: the EA specification takes the high nibble first and FFmpeg the low one. The waveform of the one long real Fibonacci-delta file is the smoother in the specification’s order (evidence on the 8SVX page), which is the raw reading’s default; the Byte order option switches it.
- Reference: whether the many Yamaha ADPCM variants (YM2608 ADPCM-B, AICA, OKI MSM6258) are what FFmpeg’s
adpcm_yamahadecodes; only that decoder was compared. - Viewer: the detector was measured on 63 real raw files: a 16-bit speech recording, six 32-bit float wavetables, and libsndfile’s fourteen test sounds (16, 24 and 32-bit, signed and unsigned 8-bit, 32 and 64-bit float, A-law, µ-law, OKI ADPCM: all read equal to FFmpeg’s decode of the same sound, and the detector ranks the right reading first for all nine it can guess). How well the detector works on other recordings is not known beyond those files.
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)
Specifications and documentation
- ITU-T G.711 – pulse code modulation of voice frequencies: the µ-law and A-law codes
- FFmpeg formats documentation – the raw demuxers and their
-fnames - IMA Recommended Practices for Enhancing Digital Audio Compatibility – the IMA ADPCM algorithm (PDF)
- DSF File Format Specification – Sony’s one-bit stream file, with its bit order and block layout (PDF)