Introduction
WavPack is an open audio compressor by David
Bryant, first released in 1998. Its normal mode is lossless. Its hybrid mode writes a
smaller lossy .wv file plus a correction file (.wvc); played
together they give back the exact original, and the .wv file alone still
plays.
WavPack handles integer, floating-point and DSD samples and multichannel audio, and is supported by many players and audio editors.
Structure
A WavPack file (version 4 and later) is a series of blocks. Each block starts with a
32-byte header: the ID wvpk,
the block size, the format version, the total number of samples in the file, the index
of the block’s first sample, the number of samples in the block, flags (bit depth, mono
or stereo, hybrid mode, float data and others) and a CRC.
Sub-blocks of metadata and audio data
follow inside each block. Numbers are little-endian. Tags, usually
APEv2, are stored at the end of the file. Older
versions used a different header.
0Block wvpk header, then sub-blocksrepeated+0Header wvpk, size, version, sample counts, flags, CRC32 bytes+32Sub-blocks decoding terms, weights, audio bitstreamvaries
endAPEv2 tag optionalvaries
Blocks can be decoded on their own, so there is no seek table. Mono and stereo files use one
block for each stretch of samples; multichannel files use a sequence of mono and stereo
blocks, as the block header page
shows. The first block with audio fixes the format of the whole file. A hybrid file’s
correction file (.wvc) has one block for each block of audio in the
.wv file, with the same headers apart from size and CRC.
The sub-blocks hold the decoder’s starting state (decorrelation terms, weights and history, and the entropy coder’s medians), the bit stream, and optional extras: the original file’s header and trailer, an MD5 of the audio, encoder settings, the channel layout and a checksum of the block. Floats, integers over 24 bits and DSD each add a layer of their own.
Not described
Known, not yet covered
- Viewer: the Checks list the first 200 problems of the sound; when there are more, a last line gives the number that are not listed.
- Reference and viewer: the audio coding of WavPack versions 1 to
3. The reference library’s source for the old reader (
unpack3.c) is public, but it is not described here and the viewer does not decode it: no real version 1 to 3 file with intact audio was available to check a decoder against (the nine version 3 files found are the library’s fuzzing cases, 104 to 10,000 bytes). Their headers are read; their audio is not decoded. Other routes tried: ffmpeg refuses versions below 4, the reference programs built here have the legacy reader switched off, and the only other decoder, WavPack 3.97, is a Windows program. - Viewer: the decoder matches ffmpeg sample for sample on every real
file found (the FFmpeg FATE samples, the library’s regression files, 56 files
from FL Studio; the stored MD5 also matches on real integer, float and DSD
files). It also matches the reference library itself: files made by
wavpackand decoded bywvunpack(both built from the library’s source) give the same samples, bit for bit, for 8 to 32-bit integers, floats, mono to 5.1, hybrid pairs (the lossy part alone and with the .wvc file), and DSD in raw, fast and high modes from DSF and DSDIFF input, and the stored MD5 matches, including the one over the original file’s layout (big-endian AIFF and CAF, DSF bit order and blocks). The PCM the viewer shows for DSD is an approximation: WavPack stores the one-bit data and defines no conversion, so the viewer shows a low-pass of the bits at a quarter of the byte rate, correlated at more than 0.97 with libwavpack’s own 24-bit conversion and with ffmpeg’s, which work at the byte rate. - Viewer: a hybrid .wv decodes losslessly when its .wvc file is beside it: opened from a folder, or dropped together with it, the explorer hands the NAME.wvc file over and the Correction file row says so. Opened alone, a hybrid .wv shows (and plays) its lossy part. The waveform, exact Peak and RMS levels, Play, the Checks and the rebuilt original file (the WAV, AIFF, CAF, W64, DSF or DSDIFF the stream came from) cover the whole stream with no length limit: each sequence of blocks decodes on its own, and the original file is read in windows.
Unknown
- Reference and viewer: the layout of
ID_ENCODER_INFO(ID 0x01), which the reference library names but neither writes nor reads, and the meaning of channel-identity values other than 0 (not allowed) and 255 (unknown). Shown as labelled bytes or numbers.
Links
Software
- WavPack command-line tools – the reference
wavpackencoder andwvunpackdecoder (Windows, macOS, Linux) - foobar2000 – free music player and converter (Windows, macOS, mobile)
- Audacity – free audio editor that opens and exports WavPack (Windows, macOS, Linux)
- VLC media player – free player for almost any audio or video file (Windows, macOS, Linux, mobile)
- FFmpeg – command-line tool that encodes and decodes WavPack (Windows, macOS, Linux)
Developers
- libwavpack – the reference library for encoding and decoding WavPack (C)
Reference
- WavPack 5 file format – the format document from WavPack’s author (PDF)