A WavPack file is made of blocks, and every block starts with this 32-byte header. The format applies from WavPack 4.0 on; older files use the legacy header. Numbers are little-endian.
Fields
| Offset | Size | Type | Field | Meaning |
|---|---|---|---|---|
| 0 | 4 | char[4] | ckID | wvpk |
| 4 | 4 | uint32 | ckSize | Bytes in the block after this field: the block’s total size minus 8. Even, and at least 24 |
| 8 | 2 | int16 | version | The stream version, 0x402 to 0x410 |
| 10 | 1 | uint8 | block_index_u8 | Bits 32 to 39 of block_index |
| 11 | 1 | uint8 | total_samples_u8 | Bits 32 to 39 of total_samples |
| 12 | 4 | uint32 | total_samples | Samples per channel in the file. All 1s in these 32 bits means unknown |
| 16 | 4 | uint32 | block_index | Index of this block’s first sample |
| 20 | 4 | uint32 | block_samples | Samples per channel in this block; 0 means the block has no audio |
| 24 | 4 | uint32 | flags | See below |
| 28 | 4 | uint32 | crc | A checksum of the decoded samples, or of the DSD bytes |
Both sample counts are 40 bits, so the most samples a file can hold is 2⁴⁰ − 257.
Flags
| Bits | Mask | Name | Meaning |
|---|---|---|---|
| 0–1 | 0x00000003 | BYTES_STORED | Bytes per sample minus 1, so 0 to 3 for 1 to 4 bytes |
| 2 | 0x00000004 | MONO_FLAG | Mono: not stereo |
| 3 | 0x00000008 | HYBRID_FLAG | Hybrid mode, so the block is lossy on its own |
| 4 | 0x00000010 | JOINT_STEREO | Stereo is coded as mid and side |
| 5 | 0x00000020 | CROSS_DECORR | Cross-channel decorrelation |
| 6 | 0x00000040 | HYBRID_SHAPE | Hybrid noise shaping |
| 7 | 0x00000080 | FLOAT_DATA | IEEE 32-bit floating-point samples |
| 8 | 0x00000100 | INT32_DATA | Integer samples of more than 24 bits, or that need special handling |
| 9 | 0x00000200 | HYBRID_BITRATE | Set: the hybrid parameters control the bit rate. Clear: they control the noise level |
| 10 | 0x00000400 | HYBRID_BALANCE | Hybrid balance between channels |
| 11 | 0x00000800 | INITIAL_BLOCK | First block of a multichannel set |
| 12 | 0x00001000 | FINAL_BLOCK | Last block of a multichannel set |
| 13–17 | 0x0003E000 | SHIFT | Left shift applied to the data after decoding, 0 to 31 places |
| 18–22 | 0x007C0000 | MAG | The largest magnitude in the block, as a bit count minus 1. The reference decoder mutes a block whose samples come out larger than 2^MAG + 2 (three times that plus 128 for lossy hybrid decoding) |
| 23–26 | 0x07800000 | SRATE | Sample rate index; see below |
| 27 | 0x08000000 | IGNORED_FLAGS | Reserved, and ignored by decoders |
| 28 | 0x10000000 | HAS_CHECKSUM | The block contains a block checksum |
| 29 | 0x20000000 | NEW_SHAPING | Hybrid noise shaping uses an IIR filter when the shaping weight is negative; this changes how the correction stream is applied |
| 30 | 0x40000000 | FALSE_STEREO | Mono data stored for a stereo stream: the two channels are the same |
| 31 | 0x80000000 | DSD_FLAG | The block holds DSD audio |
A block carrying one channel’s data has MONO_FLAG or FALSE_STEREO set.
Sample rate index
| Index | Rate | Index | Rate |
|---|---|---|---|
| 0 | 6,000 | 8 | 32,000 |
| 1 | 8,000 | 9 | 44,100 |
| 2 | 9,600 | 10 | 48,000 |
| 3 | 11,025 | 11 | 64,000 |
| 4 | 12,000 | 12 | 88,200 |
| 5 | 16,000 | 13 | 96,000 |
| 6 | 22,050 | 14 | 192,000 |
| 7 | 24,000 | 15 | Another rate: see ID_SAMPLE_RATE |
How blocks make up a stream
A block has one or two channels, so a multichannel stream uses several blocks for each time slice, all covering the same samples. The first has INITIAL_BLOCK set, the last FINAL_BLOCK, and a block with both stands alone. Channels are in Microsoft’s speaker order, and their speakers are named by the channel mask in ID_CHANNEL_INFO. Channels that belong together, such as left and right, share a stereo block.
| Block | Channels | Sequence flags |
|---|---|---|
| 1 | Front left and front right (stereo) | INITIAL_BLOCK |
| 2 | Front centre (mono) | |
| 3 | Low frequency (mono) | |
| 4 | Back left and back right (stereo) | FINAL_BLOCK |
That is how the format document lays out 5.1 audio, whose channel mask is 0x3F: four blocks for every stretch of samples.
The first block that holds audio sets the format of the whole file: bit depth, integer or float, sample rate, channel count and layout. Later blocks may still change what a player does not see, such as lossless or hybrid, the hybrid bit rate and the speed mode.
The format document allows up to 131,072 samples in a block and 1 MiB for the whole block, though blocks are normally much smaller; WavPack 5 halved the encoder’s default block length so that seeking is quicker. There are no seek tables: each block can be decoded on its own.
A block with block_samples of 0 holds only metadata. The reference library
looks past up to 16 of these when opening a file.
Sample counts
total_samples is meaningful in a block whose block_index is 0;
the low 32 bits all set means the length was not known when the file was written (as
when encoding from a pipe), and a decoder then finds the length from the last block. A file
cut from a longer one starts with a block whose block_index is not 0. In
streamed WavPack both fields are ignored and every block is simply decoded.
Correction files
A hybrid file’s correction file (.wvc) is made of blocks of the same shape.
Each block of the main file that holds audio has one matching block in the correction file;
metadata-only blocks have none. The two headers differ only in their sizes and CRCs: the
correction block’s CRC is that of the lossless samples. Its sub-blocks are
ID_WVC_BITSTREAM, and for floats
and wide integers in hybrid mode the extended stream.
Finding a block
To find a block in damaged data, the reference reader looks for wvpk, then checks
that ckSize is even, at least 24 and below 1 MiB, and that the version is
in range. It also requires byte 22 to be below 3 and byte 23 to be 0, which keeps
block_samples under 196,608.
Worked example
Flags for 16-bit joint stereo at 44,100 Hz in a single block:
| Part | Value |
|---|---|
| Bytes stored 2, so 1 | 0x00000001 |
| JOINT_STEREO | 0x00000010 |
| INITIAL_BLOCK and FINAL_BLOCK | 0x00001800 |
| Magnitude 15, shifted by 18 | 0x003C0000 |
| Rate index 9, shifted by 23 | 0x04800000 |
| Total | 0x04BC1811, stored as 11 18 BC 04 |
Source: David Bryant, WavPack 4 & 5 Binary File / Block Format (12 April 2020), section 2.0 Block Header (the 32-byte structure, the flag bit assignments, the 5.1 example), and libwavpack’s include/wavpack.h (the flag masks, WavpackHeader with int16_t version, where the document says uint16_t) and src/common_utils.c (the sample-rate table). The document’s line for 3 bytes a sample says “15-24 bits”; the table above says 17 to 24, as the library does (a block with 16 bits or fewer uses 2 bytes). Every value is compared with these texts by scripts/wv/spec-check.mjs.