7-Zip plugins\WavPack7z\Tech notes

Decoder properties

Each time the encoder’s WriteCoderProperties method is invoked, the encoder uses one byte to store properties. The encoder version is stored in the upper 4 bits; in the current implementation, the version is 0x0. The compression level is stored in the lower 4 bits; it is used for informational purposes only.

Decoding data streams created with WavPack2

When audio data is packed with the WavPack2 codec, three output data streams are created. The first data stream contains compressed audio data, the second one contains uncompressed headers and footers, and the third one contains control data. The data contained in the third data stream is used to unpack the original audio file.

The control data stream consists of a sequence of ID–Size pairs. Each pair defines a continuous data block. ID defines the data type and the data stream to read from, and Size defines the size of block in the compressed format. The ID and Size values are stored in a packed format. The packing method is described in the file 7zFormat.txt that you can find in the 7-Zip source code.

The following ID values can be used:

  • 0 - The audio data from the first data stream. The audio data is a standard WavPack container. When decoding the WavPack container, the decoder must decode audio data only. It must ignore any additional data (such as headers and footers) stored in the container. The decoded audio data is little-endian. For more details about the WavPack container unpacking algorithm, please refer to the WvUnpack source files, which you can download from www.wavpack.com.
  • 1 – Same as 0, but the decoded audio data is big-endian. So the compressed audio data can be little-endian or big-endian. The QMODE_BIG_ENDIAN flag is not passed to the WavPack library when packing audio data because the flag increases the WavPack container size.
  • 2 – The data from the second data stream. The decoder must copy the bytes "as is" into the output data stream.
  • 3 – The data from the first data stream. The decoder must copy the bytes "as is" into the output data stream.
  • 4 – The data from the second data stream, with a filter applied. The decoder must copy the bytes into the output data stream, after applying a filter decoder. The filter ID is stored in a packed format in the third data stream, immediately following the block size. The filter ID is followed by the number of bytes (in a packed format) of data to be passed to the decoder via the ICompressSetDecoderProperties2 interface and the data intended for the decoder.

An example of a control data stream:

02 B0 00 00 E6 EE DA 75 02 08 04 C2 20 BB 03 01 01


02 B0 00ID = 2, Size = 0x3000
00 E6 EE DA 75ID = 0, Size = 0x675DAEE
02 08ID = 2, Size = 0x8
04 C2 20 BB 03 01 01ID = 4, Size = 0x2BB20, FilterID = 0x3, FilterDataSize = 0x1, FilterData = [0x1]