Format:RIFF WAVE
| Developer | Microsoft and IBM |
|---|---|
| Versions | RIFF 1.0 (1991); RF64/BW64 for files over 4 GiB |
| Magic | 52 49 46 46 xx xx xx xx 57 41 56 45 ("RIFF", size, "WAVE") |
| Extensions | .wav, .wave, .bwf |
| Endianness | little (RIFX: big) |
| On this wiki | Facts · Code · Notes · Topics |
Microsoft's RIFF-based PCM and compressed audio file (.wav): a RIFF chunk of form type WAVE holding a fmt chunk (format tag, channels, rate, block align, bits) and a data chunk; the same RIFF skeleton is reused by AVI, Wwise WEM and FMOD banks.
Overview
RIFF (Resource Interchange File Format) is a chunk container: a 4-character code (FourCC), a 32-bit little-endian size, the data, and one pad byte when the size is odd (chunks are word aligned and the pad is not counted in the size). Two chunk ids are containers: RIFF (the file, followed by a form type) and LIST (followed by a list type). A WAVE file is RIFF <size> WAVE followed by sub-chunks, usually fmt (note the trailing space) then data. The same skeleton carries Format:AVI (form type AVI ), Format:WEM (Wwise RIFF audio) (WAVE with a Wwise codec tag), Format:FMOD bank (RIFF FEV) (form type FEV ) and others, so check the form type at offset 8.
Variants
RIFX: the same layout with big-endian sizes and fields (seen on big-endian consoles).RF64/BW64(EBU TECH 3306, ITU-R BS.2088): used when the file exceeds 4 GiB; theRIFFsize is 0xFFFFFFFF and ads64chunk must directly follow the form type. FFmpeg's WAV probe requiresds64at offset 12 for these ids (libavformat/wavdec.c).
fmt chunk
WAVEFORMAT / WAVEFORMATEX, little endian:
| Offset | Size | Field |
|---|---|---|
| 0 | 2 | wFormatTag |
| 2 | 2 | nChannels |
| 4 | 4 | nSamplesPerSec |
| 8 | 4 | nAvgBytesPerSec |
| 12 | 2 | nBlockAlign (bytes per sample frame, or per block for ADPCM) |
| 14 | 2 | wBitsPerSample |
| 16 | 2 | cbSize: bytes of extra data that follow (absent in the 16-byte PCM form) |
Format tags seen in games
| Tag | Meaning |
|---|---|
| 0x0001 | PCM (integer; 8-bit is unsigned, 16 bit and more are signed) |
| 0x0002 | Microsoft ADPCM: cbSize 32, then samples per block, coefficient count (7) and 7 pairs of s16 coefficients |
| 0x0003 | IEEE float |
| 0x0006 / 0x0007 | A-law / mu-law |
| 0x0011 | IMA (DVI) ADPCM: cbSize 2, then samples per block; 4 bits per sample with a 4-byte header per channel and block |
| 0x0031 | GSM 6.10 |
| 0x0050 / 0x0055 | MPEG layer 1-2 / MP3 (Format:MPEG audio) |
| 0x0069 | Xbox IMA ADPCM (FFmpeg: ADPCM_IMA_XBOX) |
| 0x0160-0x0163 | Windows Media Audio v1, v2, Pro, Lossless |
| 0x0270 | ATRAC3 |
| 0x2000 | AC-3 |
| 0xFFFE | WAVE_FORMAT_EXTENSIBLE: the real format is a GUID, see below |
The tag list above comes from FFmpeg's tag table (libavformat/riff.c). Wwise reuses tags in the 0xFFxx range for its own codecs; see Format:WEM (Wwise RIFF audio).
Extensible (0xFFFE)
With tag 0xFFFE, cbSize is 22 and the extra data holds: valid bits per sample (u16, or samples per block), channel mask (u32, speaker position bits: bit 0 front left, bit 1 front right, bit 2 front centre, bit 3 LFE ...) and a 16-byte SubFormat GUID. For the classic tags the GUID is the tag in its first 4 bytes followed by 00 00 00 00 10 00 80 00 00 AA 00 38 9B 71. FFmpeg reads dwChannelMask and hands it unchanged to av_channel_layout_from_mask (libavformat/riffdec.c lines 72-73 at 7045cc9b80), and its AV_CH_* bit order (libavutil/channel_layout.h, enum at lines 49-67) is therefore the WAVE mask order: bit 0 front left, 1 front right, 2 front centre, 3 LFE, 4 back left, 5 back right, 6 front left of centre, 7 front right of centre, 8 back centre, 9 side left, 10 side right, 11 top centre, 12 top front left, 13 top front centre, 14 top front right, 15 top back left, 16 top back centre, 17 top back right.
Other chunks
fact (sample count, mandatory for compressed formats), cue and LIST adtl (cue points, labels), smpl (loop points and root note: samplers and game engines read loops from here), inst, bext (broadcast WAV), LIST INFO (text tags) and JUNK/PAD (padding, ignore). FFmpeg treats a data chunk size of 0 or 0xFFFFFFFF in a plain RIFF file as unknown: wavdec.c (7045cc9b80, lines 472-480) only trusts size > 0 && size != 0xFFFFFFFF, otherwise it logs "Ignoring maximum wav data size, file may be invalid" and sets the end of data to INT64_MAX, i.e. it reads to the end of the file.
Reversing notes
- Walk the chunks, never assume
datastarts at offset 44:fmtmay be 16, 18 or 40 bytes andLISTorfactmay sit in between. - Game archives often keep the header untouched but replace the codec with an engine-specific one under an unknown tag; an unknown wFormatTag with plausible channels and rate is the sign. Check Technique:Game audio and video middleware.
- Duration for PCM = data size / nBlockAlign / nSamplesPerSec.
Code & repositories
FFmpeg libavformat (wavdec.c, riff.c) is the practical reference; see Library:FFmpeg.
- https://github.com/FFmpeg/FFmpeg @
7045cc9b8020ebaae156f4947baa752625056f90· license: LGPL-2.1-or-later (declared by the contributor; GitHub's detector did not recognize LICENSE.md)
FFmpeg libavformat demuxers: riff.c (wFormatTag and FourCC tables), wavdec.c, avidec.c/avi.h, matroska.h (element ids), id3v2.h, isom.h/mov.c.
Tested on: source read, not run: Read riff.c tag table, wavdec.c probe, avi.h, matroska.h and id3v2.h at this commit (sparse checkout). Not built. · checked 2026-10-18