WavPack files from before version 4.0 have a different header and no sub-blocks. These are the definitions the reference library keeps for reading them, with its legacy reader (which is built only on request). How versions 1 to 3 code the audio itself is not described here.
How the file is laid out
A legacy file begins with the WAV file that was compressed, up to and including the header
of its data chunk. The WavPack header follows, then the compressed audio. The
reference reader:
- requires
RIFFandWAVE, then reads chunks until it reachesdata, skipping each one’s padded size (up to 1 MiB) and reading the format fromfmt; - accepts only plain PCM, 1 or 2 channels, a nonzero rate and 9 to 24 bits, with a block align that gives 2 or 3 bytes a sample (versions 1 and 2: at most 16 bits);
- takes the sample count from the data chunk’s size: bytes ÷ channels ÷ 2, or ÷ 3 above 16 bits;
- reads the
wvpkheader: 10 bytes for version 1, 12 for version 2, 36 for version 3.
A file that does not start with a RIFF header is not opened. Version 3’s RAW_FLAG marks raw audio, but the reader has no path for it.
Versions 1 and 2
They have no flags or shift. The reader sets the flags to MONO_FLAG for one channel and to 0
for two, and the shift to 16 − bits per sample; version 1 also has no
bits, which counts as 0 (lossless). The channel count in the flags must match
the WAV header’s.
Version 3 settings
shiftmust be 0 to 31.- With EXTREME_DECORR set, CANCEL_EXTREME clears both; without it, CROSS_DECORR is cleared.
bitsof 0 is lossless (fast unless HIGH_FLAG is set); otherwise the file is hybrid when NEW_HIGH_FLAG is set, and lossy when it is not.- A correction file is used only with version 3, a nonzero
bitsand NEW_HIGH_FLAG.
Version 3 header
| Offset | Size | Type | Field | Notes |
|---|---|---|---|---|
| 0 | 4 | char[4] | ckID | wvpk |
| 4 | 4 | int32 | ckSize | |
| 8 | 2 | int16 | version | 1, 2 or 3. Version 1 ends here (10 bytes) |
| 10 | 2 | int16 | bits | Added in version 2.00, whose header ends here (12 bytes). 0 means lossless |
| 12 | 2 | int16 | flags | Added in version 3.00 |
| 14 | 2 | int16 | shift | Added in version 3.00 |
| 16 | 4 | int32 | total_samples | |
| 20 | 4 | uint32 | crc | |
| 24 | 4 | uint32 | crc2 | |
| 28 | 4 | char[4] | extension | |
| 32 | 1 | char | extra_bc | |
| 33 | 3 | char[3] | extras |
Flags
| Mask | Name | Meaning |
|---|---|---|
0x0001 | MONO_FLAG | Not stereo |
0x0002 | FAST_FLAG | Non-adaptive predictor and stereo mode |
0x0004 | RAW_FLAG | Raw mode, with no .wav header |
0x0008 | CALC_NOISE | Calculate noise in lossy mode (not stored) |
0x0010 | HIGH_FLAG | High quality mode, in all modes |
0x0020 | BYTES_3 | Files have 3-byte samples |
0x0040 | OVER_20 | Samples of more than 20 bits |
0x0080 | WVC_FLAG | Create or use a .wvc file (not stored) |
0x0100 | LOSSY_SHAPE | Noise shaping, lossy only |
0x0200 | VERY_FAST_FLAG | Double fast (not stored) |
0x0400 | NEW_HIGH_FLAG | New high quality mode, lossless only |
0x0800 | CANCEL_EXTREME | Cancels EXTREME_DECORR |
0x1000 | CROSS_DECORR | Decorrelate channels, with EXTREME_DECORR |
0x2000 | NEW_DECORR_FLAG | New decorrelator for high mode |
0x4000 | JOINT_STEREO | Joint stereo, lossy and high lossless |
0x8000 | EXTREME_DECORR | Extra decorrelation, which enables other flags |
The flags that affect unpacking, STORED_FLAGS, are 0xFD77.
Some of these names were reused with new meanings in WavPack 4.0. The flags on the block header page are the current ones.
Source: libwavpack 5.x, src/unpack3.c and src/unpack3_open.c (the version 1 to 3 header and flags). No other specification of these versions was found; the header and flags were not compared by script in this pass.