After the 32-byte header, a block is a sequence of sub-blocks, filling it exactly. Everything a block needs is in these, from its predictor settings to its audio.
Sub-block header
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 1 | ID | The low 6 bits are the ID; the top bits are flags, below |
| 1 | 1 | Size | The size of the data in 16-bit words |
| 2 | 2 | Size, high part | Only with the large flag: bits 8 to 23 of the word count |
| Mask | Name | Meaning |
|---|---|---|
0x3F | ID_UNIQUE | Mask for the ID |
0x20 | ID_OPTIONAL_DATA | A decoder that does not know this ID may skip it |
0x40 | ID_ODD_SIZE | The data is one byte shorter than the size says, and one padding byte follows it |
0x80 | ID_LARGE | The size uses three bytes |
The byte length is twice the word count, minus one with the odd flag. Data is padded to an even length, so the next sub-block starts on an even byte. A small sub-block holds up to 510 bytes; a sub-block may also hold nothing at all (a word count of 0), two bytes that can still signal something by being there.
An unknown ID without the optional bit makes the reference library reject the block. The format document reserves every ID it does not list. The audio bit stream is usually the last sub-block, but that is not required; a block checksum, when there is one, comes after it.
Worked example
Decorrelation terms with one term, 18, and a delta of 2. The term byte is
(18 + 5) | (2 << 5), which is 0x57. It is one byte, so the odd flag is set
and a padding byte follows:
42 01 57 00 id 0x02 | ID_ODD_SIZE, 1 word, term byte, padding
Sub-block IDs
| ID | Name | Holds |
|---|---|---|
0x00 | ID_DUMMY | Padding. Ignored |
0x01 | ID_ENCODER_INFO | Reserved, never written, and it has no layout to describe. Two independent code bases define the ID and do nothing else with it: the reference library names it in wavpack.h (line 166), and no file of its source tree writes or reads it; FFmpeg lists it as WP_ID_ENCINFO in libavcodec/wavpack.h (second entry of the ID enumeration), and neither its decoder (wavpack.c) nor its encoder (wavpackenc.c) mentions it. The format document does not list it. No block with this ID was found in about 22,000 blocks examined, and a reader skips an unknown ID by its size, so a block that carries it is shown as labelled bytes (verified, V) |
0x02 | ID_DECORR_TERMS | Decorrelation terms and deltas |
0x03 | ID_DECORR_WEIGHTS | Weights |
0x04 | ID_DECORR_SAMPLES | Decorrelation sample history |
0x05 | ID_ENTROPY_VARS | Medians for the entropy coder |
0x06 | ID_HYBRID_PROFILE | Hybrid parameters |
0x07 | ID_SHAPING_WEIGHTS | Noise-shaping state, needed only to decode with the correction file |
0x08 | ID_FLOAT_INFO | Floating-point settings |
0x09 | ID_INT32_INFO | Settings for wide integers |
0x0A | ID_WV_BITSTREAM | The audio bit stream |
0x0B | ID_WVC_BITSTREAM | The correction bit stream of a .wvc file |
0x0C | ID_WVX_BITSTREAM | Extended precision bits, for floats and integers over 24 bits. It can be in the main file or, in hybrid mode, in the correction file |
0x0D | ID_CHANNEL_INFO | Channel count and mask |
0x0E | ID_DSD_BLOCK | DSD audio |
0x21 | ID_RIFF_HEADER | The start of the original file, before the audio |
0x22 | ID_RIFF_TRAILER | The end of the original file, after the audio |
0x23 | ID_ALT_HEADER | The same as 0x21, for other file types |
0x24 | ID_ALT_TRAILER | The same as 0x22, for other file types |
0x25 | ID_CONFIG_BLOCK | Encoder settings |
0x26 | ID_MD5_CHECKSUM | 16-byte MD5 of the audio |
0x27 | ID_SAMPLE_RATE | A rate that is not in the table |
0x28 | ID_ALT_EXTENSION | The original file’s extension |
0x29 | ID_ALT_MD5_CHECKSUM | 16-byte MD5 for other file types |
0x2A | ID_NEW_CONFIG_BLOCK | Newer encoder settings |
0x2B | ID_CHANNEL_IDENTITIES | Named channels |
0x2C | ID_WVX_NEW_BITSTREAM | Extended precision bits, newer form. Added to the reference library after the 2020 format document, which does not list it |
0x2F | ID_BLOCK_CHECKSUM | A checksum of the block |
Bit streams
The WV and WVC streams have a nonzero, even length, and hold nothing but the bit stream. The WVX stream is longer than 4 bytes and even: it starts with a 32-bit little-endian CRC, and the bit stream starts at offset 4.
The newer WVX form 0x2C reads 5-bit fields from the start of its bit stream, after the CRC. For floating point there are two, the minimum shifted zeros and the maximum shifted ones; for integers there is one, the largest integer width. They let the encoder leave out bits that are known to be 0; the data types page gives the rules.
All three streams are read least significant bit first, a byte at a time.
Channel information
The payload of ID_CHANNEL_INFO is 1 to 7 bytes. A length of 6 or more is the newer form.
| Form | Bytes | Field |
|---|---|---|
| 1 to 5 bytes | 0 | Number of channels |
| 1 to 4 | Channel mask, little-endian | |
| The maximum stream count is 8, or the channel count if higher | ||
| 6 or 7 bytes | 0, and the low 4 bits of byte 2 | Channels minus 1, 12 bits |
| 1, and the high 4 bits of byte 2 | Streams minus 1, 12 bits | |
| 3 to 5 | Channel mask, bits 0 to 23 | |
| 6 | Channel mask, bits 24 to 31, if present |
The channel count cannot exceed twice the stream count, and the mask cannot have more bits than
there are channels. There can be at most 4,096 streams. In the newer form the library also refuses a block whose
channel count is below its stream count (open_utils.c lines 500 to 505, 532 and 537 to 539). A payload of 0 or
more than 7 bytes is refused (line 493).
The reference library reads ID_CHANNEL_INFO only once, from the first block that has it.
ID_CHANNEL_IDENTITIES holds one byte for each channel the mask does not name. No byte may be
0; 0xFF means unknown. Neither the format document nor wavpack.h lists the other values, but the
library’s own text says that the Microsoft channels are numbered 1 to 18 (the position of the bit in the mask, plus 1)
and the others 33 to 254 (common_utils.c, comment above WavpackGetChannelIdentities), and the
reference programs write these (cli/caff.c lines 366 to 373, from a Core Audio file’s channel labels): the
Core Audio label itself for the labels 33 to 44 and 200 to 207, and the label minus 80 for 301 to 305. With the names of
Apple’s CoreAudioBaseTypes.h: 33 rear surround left, 34 rear surround right, 35 left wide, 36 right wide,
37 LFE 2, 38 left total, 39 right total, 40 hearing impaired, 41 narration, 42 mono, 43 dialog centric mix,
44 centre surround direct; 200 to 203 ambisonic W, X, Y, Z; 204 mid, 205 side, 206 X, 207 Y; 221 headphones left,
222 headphones right, 224 click track, 225 foreign language. Any other value from 1 to 254 is accepted by the library and
shown as it is. An unlabelled, unused or label-100 channel is written as 0xFF.
Configuration
| ID | Offset | Field |
|---|---|---|
| ID_CONFIG_BLOCK | 0 to 2 | Bits 8 to 31 of the encoder’s configuration flags |
| 3 | If CONFIG_EXTRA_MODE is set: the extra mode | |
| 3 or 4 | If a byte remains: the low byte of qmode. Marks a WavPack 5 stream | |
| ID_NEW_CONFIG_BLOCK | 0 | File format code, below |
| 1 | The low byte of qmode | |
| 2 | Channel layout, as bits 16 to 23 | |
| 3, then 4 onwards | Channel count for the layout, then a channel reordering table |
The layout is the Core Audio channel layout tag with its high word (100 to 146) in bit 16 to 23 and the count in the low byte:
the library keeps (byte 2 << 16) + byte 3; if byte 3 is absent the count is the file’s channel count. The
reordering table has one byte for each of the layout’s channels, 0-based, and is at most as long as the count (a longer one makes
the block refused); bytes missing from the end mean the channel stays where it is, and a value not below the count is read as 0.
It says how to put the channels, which WavPack stores in Microsoft order, back into the Core Audio order (the encoder subtracts the
smallest value, so the table starts at 0). The encoder sets QMODE_REORDERED_CHANS whenever it writes a table; the decoder does not require the bit.
(open_utils.c lines 605 to 671, pack_utils.c lines 512 to 541, cli/caff.c lines 87 to 141 for the
tags the programs know, with their masks and tables.) An ID_NEW_CONFIG_BLOCK with fewer than 2 bytes carries nothing.
| File format | Original file |
|---|---|
| 0 | Microsoft RIFF, including BWF and RF64 |
| 1 | Sony Wave64 |
| 2 | Apple Core Audio |
| 3 | Philips DSDIFF |
| 4 | Sony DSD Stream |
| 5 | Apple AIFF |
| qmode bit | Name | Meaning |
|---|---|---|
0x01 | QMODE_BIG_ENDIAN | The original data is big-endian |
0x02 | QMODE_SIGNED_BYTES | Bytes in the original data are signed |
0x04 | QMODE_UNSIGNED_WORDS | Words in the original data are unsigned |
0x08 | QMODE_REORDERED_CHANS | Channels were reordered |
0x10 | QMODE_DSD_LSB_FIRST | DSD bytes hold bits lowest first |
0x20 | QMODE_DSD_MSB_FIRST | DSD bytes hold bits highest first |
0x40 | QMODE_DSD_IN_BLOCKS | DSD data was in channel blocks, as in DSF |
0x1000 | QMODE_RAW_PCM | Raw PCM with no header. Above the low byte, so a program flag rather than a stored bit |
The other bits above the low byte (0x100 to 0x4000) are likewise options of the command-line programs and are never stored.
Configuration flags
ID_CONFIG_BLOCK stores bits 8 to 31 of the encoder’s settings, for information; a decoder does not need them. The low byte is not stored.
| Mask | Name | Meaning |
|---|---|---|
0x00000008 | CONFIG_HYBRID_FLAG | Hybrid mode (in the low byte, so not stored) |
0x00000010 | CONFIG_JOINT_STEREO | Joint stereo (not stored) |
0x00000020 | CONFIG_CROSS_DECORR | Cross-channel decorrelation with no delay (not stored) |
0x00000040 | CONFIG_HYBRID_SHAPE | Noise shaping, hybrid only (not stored) |
0x00000200 | CONFIG_FAST_FLAG | Fast mode |
0x00000800 | CONFIG_HIGH_FLAG | High quality mode |
0x00001000 | CONFIG_VERY_HIGH_FLAG | Very high quality mode |
0x00002000 | CONFIG_BITRATE_KBPS | The hybrid bit rate was given in kbit/s, not bits a sample |
0x00008000 | CONFIG_SHAPE_OVERRIDE | The noise shaping was chosen by the user |
0x00010000 | CONFIG_JOINT_OVERRIDE | Joint stereo was chosen by the user |
0x00020000 | CONFIG_DYNAMIC_SHAPING | Dynamic noise shaping |
0x00040000 | CONFIG_CREATE_EXE | A self-extracting program was made |
0x00080000 | CONFIG_CREATE_WVC | A correction file was made |
0x00100000 | CONFIG_OPTIMIZE_WVC | Hybrid compression maximised |
0x00400000 | CONFIG_COMPATIBLE_WRITE | Written for decoders before 4.3 |
0x00800000 | CONFIG_CALC_NOISE | Noise was measured in hybrid mode |
0x02000000 | CONFIG_EXTRA_MODE | Extra processing; the extra mode byte follows |
0x04000000 | CONFIG_SKIP_WVX | No extended stream for floats and wide integers, so they are stored lossily |
0x08000000 | CONFIG_MD5_CHECKSUM | An MD5 is stored |
0x10000000 | CONFIG_MERGE_BLOCKS | Blocks of equal redundancy were merged (for lossyWAV files) |
0x20000000 | CONFIG_PAIR_UNDEF_CHANS | Channels outside the mask were paired into stereo blocks |
0x40000000 | CONFIG_OPTIMIZE_32BIT | The newer optimisations for 32-bit integer audio |
0x80000000 | CONFIG_OPTIMIZE_MONO | Mono audio stored as stereo was optimised |
Other payloads
| ID | Payload |
|---|---|
| ID_RIFF_HEADER, ID_RIFF_TRAILER, ID_ALT_HEADER, ID_ALT_TRAILER | The bytes kept from the original file: everything before the audio, and everything after it. The original file is the header, the samples in its own layout, then the trailer. The reference library accepts up to 16 MiB in total. Players do not need them, but decoders before 4.40 would not write a .wav file without ID_RIFF_HEADER |
| ID_MD5_CHECKSUM | Exactly 16 bytes: the MD5 of the audio as a WAV file holds it, the samples of all channels in turn, little-endian, in the stored width, with 8-bit samples unsigned. Float audio is hashed as the four bytes of each IEEE single, little-endian (checked on a real float file). DSD audio is hashed as its bytes, one byte for each channel in turn, in ID_ALT_MD5_CHECKSUM (the real DSD files checked carry that one, and it matches). The format document does not describe either layout; both come from the reference library and the real files. |
| ID_ALT_MD5_CHECKSUM | Exactly 16 bytes: the MD5 of the audio laid out as the original file had it, as qmode says (big-endian, signed bytes, unsigned words) |
| ID_SAMPLE_RATE | 3 bytes: the rate, little-endian. If 4 bytes: byte 3’s low 7 bits are bits 24 to 30 |
| ID_ALT_EXTENSION | Text of the extension; the reference library keeps only letters and digits |
The block checksum
The payload is 2 or 4 bytes, never odd. It is calculated over the 16-bit little-endian words of the block, from its first byte up to, but not including, this sub-block’s own header:
csum = 0xFFFFFFFF
for each word w: csum = csum × 3 + w
4-byte payload: compare csum
2-byte payload: csum ^= csum >> 16, then compare the low 16 bits
Source: David Bryant, WavPack 4 & 5 Binary File / Block Format (12 April 2020), section 3.0 Metadata Sub-Blocks (the sub-block header, the ID byte masks and the 26 IDs it lists); IDs 0x01 and 0x2C and the CONFIG_ and QMODE_ bits are from libwavpack’s include/wavpack.h, and are marked on the page as not in the document. The byte layouts of the channel, configuration and sample-rate payloads were read from the library’s src/unpack.c in earlier rounds and are not compared by script.