<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.multimedia.cx/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bryant</id>
	<title>MultimediaWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.multimedia.cx/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Bryant"/>
	<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php/Special:Contributions/Bryant"/>
	<updated>2026-08-08T05:52:59Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=WavPack&amp;diff=8281</id>
		<title>WavPack</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=WavPack&amp;diff=8281"/>
		<updated>2007-08-15T05:37:18Z</updated>

		<summary type="html">&lt;p&gt;Bryant: fleshed out some format details&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Extension: wv&lt;br /&gt;
* Website: http://www.wavpack.com/&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/lossless/ (luckynight.wv)&lt;br /&gt;
* Theory/Whitepaper: http://www.wavpack.com/WavPack.pdf&lt;br /&gt;
* FOURCC (unofficial): WVPK&lt;br /&gt;
&lt;br /&gt;
WavPack is an open source lossless audio coding algorithm with floating point data support and optional lossy audio compression.&lt;br /&gt;
&lt;br /&gt;
== WavPack v.4 ==&lt;br /&gt;
=== File Format ===&lt;br /&gt;
General details of WavPack format can be found in file 'format.txt' in wavpack sources archive.&lt;br /&gt;
WavPack file consists of blocks each beginning with 'wvpk'. Every block contains all information about sound data - sampling rate, channels, bits per sample, etc.&lt;br /&gt;
and so-called metadata. Metadata may contain different coefficients using for restoring samples, correction bitstream and actual compressed samples.&lt;br /&gt;
&lt;br /&gt;
=== Block structure ===&lt;br /&gt;
Each block contains compressed data&lt;br /&gt;
&lt;br /&gt;
Block header (all data is stored in little-endian words)&lt;br /&gt;
  4 bytes - 'wvpk'&lt;br /&gt;
  32 bits - total block size (not counting this field or 'wvpk')&lt;br /&gt;
  16 bits - version (current valid versions are 0x402 - 0x410)&lt;br /&gt;
  8  bits - track number (not currently implemented)&lt;br /&gt;
  8  bits - track sub index (not currently implemented)&lt;br /&gt;
  32 bits - total samples in file (may be 0xFFFFFFFF if unknown)&lt;br /&gt;
  32 bits - offset in samples for current block (i.e. how many samples should be decoded by now)&lt;br /&gt;
  32 bits - samples in this block (may be 0 if no audio present)&lt;br /&gt;
  32 bits - flags&lt;br /&gt;
  32 bits - CRC&lt;br /&gt;
&lt;br /&gt;
Flags meaning:&lt;br /&gt;
  bits  0- 1 - bytes per sample minus one&lt;br /&gt;
  bit      2 - sound is monaural&lt;br /&gt;
  bit      3 - hybrid profile (lossy compression)&lt;br /&gt;
  bit      4 - joint stereo coding scheme&lt;br /&gt;
  bit      5 - cross-decorrelation scheme is used&lt;br /&gt;
  bit      6 - shaping for hybrid profile is present&lt;br /&gt;
  bit      7 - floating point data present&lt;br /&gt;
  bit      8 - int32 mode&lt;br /&gt;
  bits  9-10 - hybrid profile flags&lt;br /&gt;
  bits 11-12 - multi-channel start and end blocks&lt;br /&gt;
  bits 13-17 - left-shift places when bitdepth is not a multiple of 8 (e.g. 12-bit, 20-bit)&lt;br /&gt;
  bits 18-22 - maximum magnitude of decoded data (can be used to optimize decoding arithmetic)&lt;br /&gt;
  bits 23-26 - sampling rate index (15 = unknown/custom)&lt;br /&gt;
  bit     27 - reserved (okay to ignore if encountered)&lt;br /&gt;
  bit     28 - robust block (experimental, okay to ignore if encountered)&lt;br /&gt;
  bit     29 - IIR filter for negative noise shaping in hybrid mode&lt;br /&gt;
  bit     30 - false stereo (stream is stereo but this block's data is mono, version &amp;gt;= 0x410)&lt;br /&gt;
  bit     31 - low-latency block (experimental, do not decode if encountered)&lt;br /&gt;
&lt;br /&gt;
=== Metadata ===&lt;br /&gt;
Metadata can be divided into three parts: ID, length and data. Every metadata block has even length and data size is stored in words in either one or three bytes depending on ID flag&lt;br /&gt;
&lt;br /&gt;
Flags for ID:&lt;br /&gt;
  0x20 - decoder may ignore data contained here&lt;br /&gt;
  0x40 - data size is odd&lt;br /&gt;
  0x80 - data size is large&lt;br /&gt;
&lt;br /&gt;
IDs:&lt;br /&gt;
  * 0x00 - dummy (used for padding)&lt;br /&gt;
  * 0x02 - decorrelation terms&lt;br /&gt;
  * 0x03 - decorrelation weights&lt;br /&gt;
  * 0x04 - decorrelation samples&lt;br /&gt;
  * 0x05 - entropy info&lt;br /&gt;
  * 0x06 - hybrid profile&lt;br /&gt;
  * 0x07 - noise shaping profile (wvc file)&lt;br /&gt;
  * 0x08 - floating-point data profile&lt;br /&gt;
  * 0x09 - large or shifted integer profile&lt;br /&gt;
  * 0x0A - packed samples&lt;br /&gt;
  * 0x0B - packed correction data (wvc file)&lt;br /&gt;
  * 0x0C - packed overflow bits from floating-point or large integers&lt;br /&gt;
  * 0x0D - multichannel information (including Microsoft channel mask)&lt;br /&gt;
&lt;br /&gt;
  * 0x20 - RIFF header for .wav files (before audio)&lt;br /&gt;
  * 0x21 - RIFF trailer for .wav files (after audio)&lt;br /&gt;
  * 0x25 - some encoding details for info purposes&lt;br /&gt;
  * 0x26 - 16-byte MD5 sum of raw audio data&lt;br /&gt;
  * 0x27 - non-standard sampling rate&lt;br /&gt;
&lt;br /&gt;
=== Decorrelation terms ===&lt;br /&gt;
Decorrelation terms are stored in one byte, lower 5 bits indicate predictor type, high 3 bits contain delta value.&lt;br /&gt;
&lt;br /&gt;
Possible predictor values:&lt;br /&gt;
  0-5 - predictors for stereo, only predictors 2-4 are implemented&lt;br /&gt;
  6-12 - predictor uses 1-7 samples for prediction&lt;br /&gt;
  13-16 - reserved&lt;br /&gt;
  17-18 - predictor does prediction by two samples&lt;br /&gt;
&lt;br /&gt;
=== Decorrelation weights ===&lt;br /&gt;
Each decorrelation term should have one or two weights depending on channels.&lt;br /&gt;
Each weight is packed into one byte and can be restored in this way:&lt;br /&gt;
&lt;br /&gt;
  n = getchar() &amp;lt;&amp;lt; 3;&lt;br /&gt;
  if(n &amp;gt; 0) n += (n + 64) &amp;gt;&amp;gt; 7;&lt;br /&gt;
&lt;br /&gt;
=== Decorrelation samples ===&lt;br /&gt;
Each decorrelation term may have up to 16 samples depending on its value. Each sample is 32-bit but stored in 16 bits, lower 8 bits are mantiss and high 8 bits are exponent-9, i.e if exponent &amp;lt; 9 shift mantiss right, otherwise left&lt;br /&gt;
&lt;br /&gt;
=== Entropy info ===&lt;br /&gt;
This section contains one or two sets of medians for samples decoding. Each median is log-packed into 16 bits as described above.&lt;br /&gt;
&lt;br /&gt;
=== Samples coding ===&lt;br /&gt;
Samples are stored in metadata block with ID=0x0A and are packed with modified Golomb codes. Decoding process is specified below where get_unary() is the function which returns length of '1'-bits string (i.e. 111110b = 5, 10b = 1).&lt;br /&gt;
Codeset is adaptively divided into four sets and every code has unary prefix (possibly escaped) defining interval of this code and mantis part like in Golomb code.&lt;br /&gt;
&lt;br /&gt;
  if(last_zero){&lt;br /&gt;
    n = 0;&lt;br /&gt;
    last_zero = 0;&lt;br /&gt;
  }else{&lt;br /&gt;
    n = get_unary();&lt;br /&gt;
    if(n == 16){&lt;br /&gt;
      n2 = get_unary();&lt;br /&gt;
      if(n2 &amp;lt; 2) n += n2;&lt;br /&gt;
      else n += (1 &amp;lt;&amp;lt; (n2-1)) | getbits(n2-1);&lt;br /&gt;
    }&lt;br /&gt;
    last_one = n &amp;amp; 1;&lt;br /&gt;
    if(last_one)&lt;br /&gt;
      n = (n&amp;gt;&amp;gt;1) + 1;&lt;br /&gt;
    else&lt;br /&gt;
      n = n &amp;gt;&amp;gt; 1;&lt;br /&gt;
    last_zero = !last_one;&lt;br /&gt;
  }&lt;br /&gt;
  if(n == 0){&lt;br /&gt;
    base = 0;&lt;br /&gt;
    add = median[0] - 1;&lt;br /&gt;
    decrease median[0];&lt;br /&gt;
  } else if(n == 1){&lt;br /&gt;
    base = median[0];&lt;br /&gt;
    add = median[1] - 1;&lt;br /&gt;
    increase median[0];&lt;br /&gt;
    decrease median[1];&lt;br /&gt;
  } else {&lt;br /&gt;
    base = median[0] + median[1] + median[2] * (n - 2);&lt;br /&gt;
    add = median[2] - 1;&lt;br /&gt;
    increase median[0];&lt;br /&gt;
    increase median[1];&lt;br /&gt;
    if(n == 2) derease median[2];&lt;br /&gt;
    else increase median[2];&lt;br /&gt;
  }&lt;br /&gt;
  k = log2(add);&lt;br /&gt;
  ex = (1 &amp;lt;&amp;lt; k) - add - 1;&lt;br /&gt;
  t2 = getbits(k - 1);&lt;br /&gt;
  if(t2 &amp;gt;= ex)&lt;br /&gt;
    t2 = t2 * 2 - ex + getbit();&lt;br /&gt;
  sign = getbit();&lt;br /&gt;
  if(sign==0) result = base + t2;&lt;br /&gt;
  else result = ~(base + t2);&lt;br /&gt;
&lt;br /&gt;
[[Category:Container Formats]]&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category:Lossless Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Bryant</name></author>
	</entry>
</feed>