<?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=Maxpol</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=Maxpol"/>
	<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php/Special:Contributions/Maxpol"/>
	<updated>2026-07-09T21:37:58Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.5</generator>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=OpenMG&amp;diff=15405</id>
		<title>OpenMG</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=OpenMG&amp;diff=15405"/>
		<updated>2018-11-29T15:34:06Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Mor links.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Website: [http://www.sony.net/Products/OpenMG/ http://www.sony.net/Products/OpenMG/]&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
&lt;br /&gt;
Open Media Gate (OpenMG) is a legacy DRM system developed by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Multimedia DRM]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15404</id>
		<title>Sony ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15404"/>
		<updated>2018-11-29T15:33:08Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Tiny improvement.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Product overview: http://www.sony.net/Products/ATRAC3/overview/index.html#family&lt;br /&gt;
* Developer's interview: https://www.sony.net/Products/ATRAC3/special/developers01.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ATRAC ('''A'''daptive '''TR'''ansform '''A'''coustic '''C'''oding) is the collective name for audio compression technologies&lt;br /&gt;
developed by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
This codec family includes the following compression algorithms today:&lt;br /&gt;
&lt;br /&gt;
* [[ATRAC]]&lt;br /&gt;
* [[ATRAC3]]&lt;br /&gt;
* [[ATRAC3plus]]&lt;br /&gt;
* ATRAC Advanced Lossless (AAL)&lt;br /&gt;
&lt;br /&gt;
ATRAC-compressed audio is usually stored in [[Microsoft_Wave|WAV]]/[[Microsoft_Audio/Video_Interleaved|AVI]], [[RealMedia|RM]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;br /&gt;
[[Category: Lossless Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=15403</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=15403"/>
		<updated>2018-11-29T15:31:23Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: More links.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of its predecessor [[ATRAC3]], ATRAC3plus represents the next generation of the [[ATRAC]] codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Polyphase_quadrature_filter Polyphase Quadrature Filter] (further PQF) before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the PQF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] += [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Oma&amp;diff=15402</id>
		<title>Oma</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Oma&amp;diff=15402"/>
		<updated>2018-11-29T15:27:50Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Revamp OpenMG description, part 1.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Extension: oma, aa3&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/oma/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The OpenMG Audio (further OMA) container format is used to encapsulate digital music content for use with Sony's portable players. Files ending with .omg are protected with the [[OpenMG]] [[DRM]] system.&lt;br /&gt;
&lt;br /&gt;
The format is known to carry audio streams encoded with:&lt;br /&gt;
&lt;br /&gt;
* [[ATRAC3]]&lt;br /&gt;
* [[ATRAC3plus]]&lt;br /&gt;
* [[ATRAC Advanced Lossless]]&lt;br /&gt;
* [[MP3]]&lt;br /&gt;
* [[PCM|Linear PCM]]&lt;br /&gt;
* [[WMA]] (confirmation required)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== File structure ==&lt;br /&gt;
&lt;br /&gt;
A typical OMA file consists of the following three parts:&lt;br /&gt;
* metadata container&lt;br /&gt;
* extended audio header&lt;br /&gt;
* actual sound data&lt;br /&gt;
&lt;br /&gt;
=== Metadata container ===&lt;br /&gt;
&lt;br /&gt;
The metadata container carries overall music info. Except for starting with &amp;quot;ea3&amp;quot; instead of &amp;quot;ID3&amp;quot;, it's fully compatible with the ID3v2 format. It uses standard ID3v2 frame types, such as TIT2, TPE1, TALB and TCON. In addition to these standard frame types, TXXX and GEOB frames contain OpenMG-specific metadata.&lt;br /&gt;
&lt;br /&gt;
  TXX   OMG_TRACK  &amp;quot;track number (ASCII)&amp;quot;&lt;br /&gt;
  TXX   OMG_AGENR  &amp;quot;content description (ASCII)&amp;quot;&lt;br /&gt;
  TXX   OMG_ATPE1  &amp;quot;leader performer (ASCII)&amp;quot;&lt;br /&gt;
  GEOB  OMG_BLKSI  contains a metadata structure. observed strings include:&lt;br /&gt;
                      KEYRING&lt;br /&gt;
                      EKB&lt;br /&gt;
                      SHARE_P_SID&lt;br /&gt;
                      REFID&lt;br /&gt;
  GEOB  OMG_OLINF  binary blob &lt;br /&gt;
&lt;br /&gt;
=== Extended audio header ===&lt;br /&gt;
&lt;br /&gt;
Extended audio header contains information about the encapsulated OpenMG audio. This includes codec type, codec specific info (packet size, sample rate, channels and so on) as well as DRM related info (file encryption, content id).&lt;br /&gt;
&lt;br /&gt;
=== Sound data ===&lt;br /&gt;
&lt;br /&gt;
Encrypted or plain-text sound data organized in packets follows the extended audio header.&lt;br /&gt;
&lt;br /&gt;
== Further reading ==&lt;br /&gt;
&lt;br /&gt;
The OMA file format contains a payload scrambled with a 32-bit value [http://www.waider.ie/hacks/workshop/c/mple/FILE_FORMAT_v2.txt].&lt;br /&gt;
&lt;br /&gt;
[[Category:Container Formats]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC&amp;diff=15401</id>
		<title>ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC&amp;diff=15401"/>
		<updated>2018-11-29T14:02:43Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Add company name and link.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Company: [[Sony]]&lt;br /&gt;
* Technical: http://www.minidisc.org/aes_atrac.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The ATRAC codec was introduced in 1992 with the MiniDisc. Common use of the codec is in Sony made Minidisc and Flash based players.&lt;br /&gt;
&lt;br /&gt;
Sony Dynamic Digital System (SDDS), used in theatres, is based on ATRAC.&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15400</id>
		<title>ATRAC3</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15400"/>
		<updated>2018-11-29T13:57:52Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Link to the original ATRAC codec page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: 0x270&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= ATRAC3 Introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3 is the next generation of the [[ATRAC]] codec. There are three major implementations for the PC:&lt;br /&gt;
[[RealAudio atrc]], the Sony ATRAC3 for [[Microsoft Audio Compression Manager API|Audio Compression Manager]] (ACM) and the Sonic Stage implementation.&lt;br /&gt;
&lt;br /&gt;
ATRAC3 supports several different constant bitrates (&amp;quot;flavors&amp;quot;). The following table shows the&lt;br /&gt;
bitrate, the size of a frame and the coding mode for each flavor respectively:&lt;br /&gt;
&lt;br /&gt;
 No             bitrate   frame size (stereo)     coding mode   samples per frame&lt;br /&gt;
 --   -----------------   -------------------   -------------   -----------------&lt;br /&gt;
 0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel&lt;br /&gt;
 1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel&lt;br /&gt;
 2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel&lt;br /&gt;
 3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel&lt;br /&gt;
 4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel&lt;br /&gt;
 5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel&lt;br /&gt;
 6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel&lt;br /&gt;
 7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel&lt;br /&gt;
&lt;br /&gt;
== Encoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Split the input signal into 4 bands using a Quadrature mirror filter (QMF).&lt;br /&gt;
* Perform gain control analysis to obtain gain control data.&lt;br /&gt;
* Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).&lt;br /&gt;
* Find tonal components.&lt;br /&gt;
* Quantization&lt;br /&gt;
* Encode the bitstream.&lt;br /&gt;
&lt;br /&gt;
Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.&lt;br /&gt;
&lt;br /&gt;
== Decoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Parse the bitstream and extract the following:&lt;br /&gt;
** gain control data&lt;br /&gt;
** tonal components&lt;br /&gt;
** quantized spectral coefficients&lt;br /&gt;
* inverse quantization of the tonal components and spectral coefficients&lt;br /&gt;
* Merge tonal components and other spectral coefficients together.&lt;br /&gt;
* Reconstruct the timedomain signal using inverse MDCT.&lt;br /&gt;
* gain compensation&lt;br /&gt;
* Apply the QMF synthesis filter to reconstruct the sound.&lt;br /&gt;
&lt;br /&gt;
== Tonal components ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra&lt;br /&gt;
and encodes them separate from the less important spectral data. A tone component is a group of&lt;br /&gt;
consecutive spectral coefficients, described with parameters such as location and with. This allows&lt;br /&gt;
finer quantization of such coefficients than a quantization within fixed subbands.&lt;br /&gt;
&lt;br /&gt;
== Joint-stereo mode ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The ATRAC3 bitstream consists of so-called &amp;quot;Channel Sound Units&amp;quot;. In stereo mode there are&lt;br /&gt;
two such units. The structure of an unit is shown below:&lt;br /&gt;
&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Header                             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Gain compensation data             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Tonal components                   |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Other spectral coefficients        |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
&lt;br /&gt;
= Decoding Specification =&lt;br /&gt;
&lt;br /&gt;
== Bitstream parsing ==&lt;br /&gt;
&lt;br /&gt;
Parts is '''bold''' mean that a certain amount of bits are to be consumed from the bitstream.&lt;br /&gt;
&lt;br /&gt;
===Header===&lt;br /&gt;
&lt;br /&gt;
If not in the joint-stereo mode, this header should be interpreted as follows:&lt;br /&gt;
* '''id (6 bits)''' - should contain the value 0x28&lt;br /&gt;
* '''nBandsCoded (2 bits)''' - number of QMF bands were coded. The value of 0 indicates one coded band.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Gain compensation data===&lt;br /&gt;
&lt;br /&gt;
For each coded QMF band (see nBandsCoded above) the following data will be transmitted:&lt;br /&gt;
* '''numGainData (3 bits)''' - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:&lt;br /&gt;
* '''levcode (4 bits)''' - level code&lt;br /&gt;
* '''loccode (5 bits)''' - location code&lt;br /&gt;
This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by [[Sony]]. Please refer to section &amp;quot;Gain compensation&amp;quot; below for a description how to interpret this data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tonal components===&lt;br /&gt;
&lt;br /&gt;
The presence of tonal components is indicated by the following field:&lt;br /&gt;
* '''numToneComp (5 bits)''' - Number of coded tonal components. The value of 0 indicates no coded tonal components.&lt;br /&gt;
* '''coding_mode_selector(2 bits)''' -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)&lt;br /&gt;
&lt;br /&gt;
* For each tonal component&lt;br /&gt;
** For each number of bands, get band flags&lt;br /&gt;
*** '''band_flags (1 bit)''' -- Flag per band in the Tonal Component to be processed&lt;br /&gt;
** '''coded_values (3 bits)''' -- amount of coded coefficients&lt;br /&gt;
** '''quant_step_index (3 bits)''' -- index into the quant step table, if it is less then/equal to 1 then return error&lt;br /&gt;
** if coding_mode_selector is 3&lt;br /&gt;
*** '''coding_mode (1 bit)''' -- get the bands coding mode (CLC/VLC)&lt;br /&gt;
&lt;br /&gt;
===Other spectral coefficients===&lt;br /&gt;
&lt;br /&gt;
The coefficients coded in this block are assumed not to be &amp;quot;tonal&amp;quot; (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:&lt;br /&gt;
* '''numSubbands (5 bits)''' - number of coded subbands. The value of 0 indicates no coded subbands.&lt;br /&gt;
* '''codingMode (1 bit)''' - value indicates the coding mode for ALL subbands:&lt;br /&gt;
&lt;br /&gt;
 0 - coefficients are coded using variable length codes (VLC)&lt;br /&gt;
 1 - coefficients are coded using constant length codes (CLC)&lt;br /&gt;
&lt;br /&gt;
Then follow the array of coding table indexes for each coded band:&lt;br /&gt;
* '''tblIndex (3 bits)''' - indicates the coding table used (VLC) or number of bits used (CLC). The value of &amp;quot;0&amp;quot; indicates &amp;quot;skipped&amp;quot; (not coded) subband.&lt;br /&gt;
Then follows the array of scalefactor indexes for each coded subband:&lt;br /&gt;
* '''sfIndex (6 bits)''' - indicates the index into scalefactor decoding table (see below).&lt;br /&gt;
Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Transforms ==&lt;br /&gt;
&lt;br /&gt;
=== QMF ===&lt;br /&gt;
&lt;br /&gt;
Three stacked [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filters] are used to split the signal into 4 different frequency bands.&lt;br /&gt;
&lt;br /&gt;
* 0 to 2.75625 kHz (DC to ''f''/16)&lt;br /&gt;
* 2.75625 to 5.5125 kHz (''f''/16 to ''f''/8)&lt;br /&gt;
* 5.5125 to 11.025 kHz (''f''/8 to ''f''/4)&lt;br /&gt;
* 11.025 to 22.05 kHz (''f''/4 to ''f''/2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QMF window ====&lt;br /&gt;
&lt;br /&gt;
The coeffs used in the QMF filter.&lt;br /&gt;
&lt;br /&gt;
 float qmf_48tap_half[24] = {&lt;br /&gt;
   -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,&lt;br /&gt;
   0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,&lt;br /&gt;
   0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,&lt;br /&gt;
   -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,&lt;br /&gt;
   -0.007801671, -0.034090221, 0.01880949, 0.054326009,&lt;br /&gt;
   -0.043596379, -0.099384367, 0.13207909, 0.46424159&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
These coeffs need to be mirrored and scaled by 2.&lt;br /&gt;
&lt;br /&gt;
 for (i=0 ; i&amp;lt;24; i++) {&lt;br /&gt;
   s = qmf_48tap_half[i] * 2.0;&lt;br /&gt;
   qmf_window[i] = s;&lt;br /&gt;
   qmf_window[47 - i] = s;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== MLT ===&lt;br /&gt;
&lt;br /&gt;
The transform is a regular MDCT.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [http://research.microsoft.com/~malvar/papers/dfsp98.pdf]&lt;br /&gt;
&lt;br /&gt;
====== Encoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
====== Decoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   wd[i] = we[i]/(we[i]^2 + we[255-i]^2)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Huffman coding ==&lt;br /&gt;
&lt;br /&gt;
VLC coding is used to compress the tonal and spectral coefficients.&lt;br /&gt;
&lt;br /&gt;
=== Huffman tables ===&lt;br /&gt;
&lt;br /&gt;
 huffcode1[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits1[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode2[5] = {&lt;br /&gt;
   0x0,0x4,0x5,0x6,0x7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits2[5] = {&lt;br /&gt;
   1,3,3,3,3,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode3[7] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0xE,0xF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits3[7] = {&lt;br /&gt;
   1,3,3,4,4,4,4,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode4[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits4[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode5[15] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits5[15] = {&lt;br /&gt;
   2,3,3,4,4,4,4,4,4,5,5,6,6,6,6,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode6[31] = {&lt;br /&gt;
   0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35,&lt;br /&gt;
   0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits6[31] = {&lt;br /&gt;
   3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode7[63] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28,&lt;br /&gt;
   0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C,&lt;br /&gt;
   0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,&lt;br /&gt;
   0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits7[63] = {&lt;br /&gt;
   3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,&lt;br /&gt;
   7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15399</id>
		<title>Sony ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15399"/>
		<updated>2018-11-29T13:56:33Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Better formatting + developer's interview.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Product overview: http://www.sony.net/Products/ATRAC3/overview/index.html#family&lt;br /&gt;
* Developer's interview: https://www.sony.net/Products/ATRAC3/special/developers01.html&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ATRAC ('''A'''daptive '''TR'''ansform '''A'''coustic '''C'''oding) is the collective name for audio compression technologies&lt;br /&gt;
developed by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
This codec family includes the following codecs today:&lt;br /&gt;
&lt;br /&gt;
* [[ATRAC]]&lt;br /&gt;
* [[ATRAC3]]&lt;br /&gt;
* [[ATRAC3plus]]&lt;br /&gt;
* ATRAC Advanced Lossless (AAL)&lt;br /&gt;
&lt;br /&gt;
ATRAC-compressed audio is usually stored in [[Microsoft_Wave|WAV]]/[[Microsoft_Audio/Video_Interleaved|AVI]], [[RealMedia|RM]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;br /&gt;
[[Category: Lossless Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15398</id>
		<title>Sony ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15398"/>
		<updated>2018-11-29T13:51:45Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Revamp ATRAC family description.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;ATRAC (Adaptive TRansform Acoustic Coding) is the collective name for audio compression technologies&lt;br /&gt;
developed by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
This codec family includes the following codecs today:&lt;br /&gt;
&lt;br /&gt;
* [[ATRAC]]&lt;br /&gt;
* [[ATRAC3]]&lt;br /&gt;
* [[ATRAC3plus]]&lt;br /&gt;
* ATRAC Advanced Lossless (AAL)&lt;br /&gt;
&lt;br /&gt;
An overview of this product family can be found here: http://www.sony.net/Products/ATRAC3/overview/index.html#family&lt;br /&gt;
&lt;br /&gt;
ATRAC-compressed audio is usually stored in [[Microsoft_Wave|WAV]]/[[Microsoft_Audio/Video_Interleaved|AVI]], [[RealMedia|RM]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;br /&gt;
[[Category: Lossless Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC&amp;diff=15397</id>
		<title>ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC&amp;diff=15397"/>
		<updated>2018-11-29T13:51:27Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Create a basic page for the old famous ATRAC codec.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Technical: http://www.minidisc.org/aes_atrac.html&lt;br /&gt;
&lt;br /&gt;
The ATRAC codec was introduced in 1992 with the MiniDisc. Common use of the codec is in Sony made Minidisc and Flash based players.&lt;br /&gt;
&lt;br /&gt;
Sony Dynamic Digital System (SDDS), used in theatres, is based on ATRAC.&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15396</id>
		<title>ATRAC3</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15396"/>
		<updated>2018-11-29T13:43:26Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Move format tag and samples to the right place.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: 0x270&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3/&lt;br /&gt;
&lt;br /&gt;
= ATRAC3 Introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:&lt;br /&gt;
[[RealAudio atrc]], the Sony ATRAC3 for [[Microsoft Audio Compression Manager API|Audio Compression Manager]] (ACM) and the Sonic Stage implementation.&lt;br /&gt;
&lt;br /&gt;
ATRAC3 supports several different constant bitrates (&amp;quot;flavors&amp;quot;). The following table shows the&lt;br /&gt;
bitrate, the size of a frame and the coding mode for each flavor respectively:&lt;br /&gt;
&lt;br /&gt;
 No             bitrate   frame size (stereo)     coding mode   samples per frame&lt;br /&gt;
 --   -----------------   -------------------   -------------   -----------------&lt;br /&gt;
 0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel&lt;br /&gt;
 1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel&lt;br /&gt;
 2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel&lt;br /&gt;
 3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel&lt;br /&gt;
 4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel&lt;br /&gt;
 5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel&lt;br /&gt;
 6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel&lt;br /&gt;
 7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel&lt;br /&gt;
&lt;br /&gt;
== Encoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Split the input signal into 4 bands using a Quadrature mirror filter (QMF).&lt;br /&gt;
* Perform gain control analysis to obtain gain control data.&lt;br /&gt;
* Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).&lt;br /&gt;
* Find tonal components.&lt;br /&gt;
* Quantization&lt;br /&gt;
* Encode the bitstream.&lt;br /&gt;
&lt;br /&gt;
Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.&lt;br /&gt;
&lt;br /&gt;
== Decoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Parse the bitstream and extract the following:&lt;br /&gt;
** gain control data&lt;br /&gt;
** tonal components&lt;br /&gt;
** quantized spectral coefficients&lt;br /&gt;
* inverse quantization of the tonal components and spectral coefficients&lt;br /&gt;
* Merge tonal components and other spectral coefficients together.&lt;br /&gt;
* Reconstruct the timedomain signal using inverse MDCT.&lt;br /&gt;
* gain compensation&lt;br /&gt;
* Apply the QMF synthesis filter to reconstruct the sound.&lt;br /&gt;
&lt;br /&gt;
== Tonal components ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra&lt;br /&gt;
and encodes them separate from the less important spectral data. A tone component is a group of&lt;br /&gt;
consecutive spectral coefficients, described with parameters such as location and with. This allows&lt;br /&gt;
finer quantization of such coefficients than a quantization within fixed subbands.&lt;br /&gt;
&lt;br /&gt;
== Joint-stereo mode ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The ATRAC3 bitstream consists of so-called &amp;quot;Channel Sound Units&amp;quot;. In stereo mode there are&lt;br /&gt;
two such units. The structure of an unit is shown below:&lt;br /&gt;
&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Header                             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Gain compensation data             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Tonal components                   |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Other spectral coefficients        |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
&lt;br /&gt;
= Decoding Specification =&lt;br /&gt;
&lt;br /&gt;
== Bitstream parsing ==&lt;br /&gt;
&lt;br /&gt;
Parts is '''bold''' mean that a certain amount of bits are to be consumed from the bitstream.&lt;br /&gt;
&lt;br /&gt;
===Header===&lt;br /&gt;
&lt;br /&gt;
If not in the joint-stereo mode, this header should be interpreted as follows:&lt;br /&gt;
* '''id (6 bits)''' - should contain the value 0x28&lt;br /&gt;
* '''nBandsCoded (2 bits)''' - number of QMF bands were coded. The value of 0 indicates one coded band.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Gain compensation data===&lt;br /&gt;
&lt;br /&gt;
For each coded QMF band (see nBandsCoded above) the following data will be transmitted:&lt;br /&gt;
* '''numGainData (3 bits)''' - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:&lt;br /&gt;
* '''levcode (4 bits)''' - level code&lt;br /&gt;
* '''loccode (5 bits)''' - location code&lt;br /&gt;
This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by [[Sony]]. Please refer to section &amp;quot;Gain compensation&amp;quot; below for a description how to interpret this data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tonal components===&lt;br /&gt;
&lt;br /&gt;
The presence of tonal components is indicated by the following field:&lt;br /&gt;
* '''numToneComp (5 bits)''' - Number of coded tonal components. The value of 0 indicates no coded tonal components.&lt;br /&gt;
* '''coding_mode_selector(2 bits)''' -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)&lt;br /&gt;
&lt;br /&gt;
* For each tonal component&lt;br /&gt;
** For each number of bands, get band flags&lt;br /&gt;
*** '''band_flags (1 bit)''' -- Flag per band in the Tonal Component to be processed&lt;br /&gt;
** '''coded_values (3 bits)''' -- amount of coded coefficients&lt;br /&gt;
** '''quant_step_index (3 bits)''' -- index into the quant step table, if it is less then/equal to 1 then return error&lt;br /&gt;
** if coding_mode_selector is 3&lt;br /&gt;
*** '''coding_mode (1 bit)''' -- get the bands coding mode (CLC/VLC)&lt;br /&gt;
&lt;br /&gt;
===Other spectral coefficients===&lt;br /&gt;
&lt;br /&gt;
The coefficients coded in this block are assumed not to be &amp;quot;tonal&amp;quot; (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:&lt;br /&gt;
* '''numSubbands (5 bits)''' - number of coded subbands. The value of 0 indicates no coded subbands.&lt;br /&gt;
* '''codingMode (1 bit)''' - value indicates the coding mode for ALL subbands:&lt;br /&gt;
&lt;br /&gt;
 0 - coefficients are coded using variable length codes (VLC)&lt;br /&gt;
 1 - coefficients are coded using constant length codes (CLC)&lt;br /&gt;
&lt;br /&gt;
Then follow the array of coding table indexes for each coded band:&lt;br /&gt;
* '''tblIndex (3 bits)''' - indicates the coding table used (VLC) or number of bits used (CLC). The value of &amp;quot;0&amp;quot; indicates &amp;quot;skipped&amp;quot; (not coded) subband.&lt;br /&gt;
Then follows the array of scalefactor indexes for each coded subband:&lt;br /&gt;
* '''sfIndex (6 bits)''' - indicates the index into scalefactor decoding table (see below).&lt;br /&gt;
Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Transforms ==&lt;br /&gt;
&lt;br /&gt;
=== QMF ===&lt;br /&gt;
&lt;br /&gt;
Three stacked [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filters] are used to split the signal into 4 different frequency bands.&lt;br /&gt;
&lt;br /&gt;
* 0 to 2.75625 kHz (DC to ''f''/16)&lt;br /&gt;
* 2.75625 to 5.5125 kHz (''f''/16 to ''f''/8)&lt;br /&gt;
* 5.5125 to 11.025 kHz (''f''/8 to ''f''/4)&lt;br /&gt;
* 11.025 to 22.05 kHz (''f''/4 to ''f''/2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QMF window ====&lt;br /&gt;
&lt;br /&gt;
The coeffs used in the QMF filter.&lt;br /&gt;
&lt;br /&gt;
 float qmf_48tap_half[24] = {&lt;br /&gt;
   -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,&lt;br /&gt;
   0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,&lt;br /&gt;
   0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,&lt;br /&gt;
   -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,&lt;br /&gt;
   -0.007801671, -0.034090221, 0.01880949, 0.054326009,&lt;br /&gt;
   -0.043596379, -0.099384367, 0.13207909, 0.46424159&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
These coeffs need to be mirrored and scaled by 2.&lt;br /&gt;
&lt;br /&gt;
 for (i=0 ; i&amp;lt;24; i++) {&lt;br /&gt;
   s = qmf_48tap_half[i] * 2.0;&lt;br /&gt;
   qmf_window[i] = s;&lt;br /&gt;
   qmf_window[47 - i] = s;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== MLT ===&lt;br /&gt;
&lt;br /&gt;
The transform is a regular MDCT.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [http://research.microsoft.com/~malvar/papers/dfsp98.pdf]&lt;br /&gt;
&lt;br /&gt;
====== Encoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
====== Decoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   wd[i] = we[i]/(we[i]^2 + we[255-i]^2)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Huffman coding ==&lt;br /&gt;
&lt;br /&gt;
VLC coding is used to compress the tonal and spectral coefficients.&lt;br /&gt;
&lt;br /&gt;
=== Huffman tables ===&lt;br /&gt;
&lt;br /&gt;
 huffcode1[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits1[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode2[5] = {&lt;br /&gt;
   0x0,0x4,0x5,0x6,0x7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits2[5] = {&lt;br /&gt;
   1,3,3,3,3,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode3[7] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0xE,0xF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits3[7] = {&lt;br /&gt;
   1,3,3,4,4,4,4,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode4[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits4[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode5[15] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits5[15] = {&lt;br /&gt;
   2,3,3,4,4,4,4,4,4,5,5,6,6,6,6,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode6[31] = {&lt;br /&gt;
   0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35,&lt;br /&gt;
   0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits6[31] = {&lt;br /&gt;
   3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode7[63] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28,&lt;br /&gt;
   0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C,&lt;br /&gt;
   0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,&lt;br /&gt;
   0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits7[63] = {&lt;br /&gt;
   3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,&lt;br /&gt;
   7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15395</id>
		<title>RealAudio atrc</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15395"/>
		<updated>2018-11-29T13:40:50Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Add Sony to the list of companies.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCC: atrc&lt;br /&gt;
* Company: [[Sony]], [[Real]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/real/AC-atrc/&lt;br /&gt;
&lt;br /&gt;
Found in some old [[RealMedia]] files. The same as the [[ATRAC3]].&lt;br /&gt;
&lt;br /&gt;
== Scrambling ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files, the ATRAC3 bitstream is scrambled. To unscramble the stream, perform a XOR on every 32 bits in the frame. The hex value to XOR with is 0x537F6103.&lt;br /&gt;
&lt;br /&gt;
== Extra data format ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files, ATRAC3 extra data has the following format (big-endian order):&lt;br /&gt;
&lt;br /&gt;
 INT32	id, always 4&lt;br /&gt;
 INT16	samples per frame, always 1024 * 2&lt;br /&gt;
 INT16	delay, not used but always 0x88E&lt;br /&gt;
 INT16	stereo coding mode, 2 - normal stereo, 0x12 - joint stereo&lt;br /&gt;
&lt;br /&gt;
The length of this data is always 10 bytes.&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Oma&amp;diff=15394</id>
		<title>Oma</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Oma&amp;diff=15394"/>
		<updated>2018-11-29T13:37:19Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Repair ATRAC3 link.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Extension: oma, aa3&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/oma/&lt;br /&gt;
&lt;br /&gt;
Container format used to encapsulate [[ATRAC3]] and [[ATRAC3plus]] for use with Sony's portable players. Files ending with .omg are protected with the [[OpenMG]] [[DRM]] system.&lt;br /&gt;
&lt;br /&gt;
The OMA file format contains a payload scrambled with a 32-bit value [http://www.waider.ie/hacks/workshop/c/mple/FILE_FORMAT_v2.txt]. The format is known to carry MP3 and ATRAC3 audio. The metadata format is a variant of ID3v2 and uses standard ID3v2 frame types, such as TIT2, TPE1, TALB and TCON. In addition to these standard frame types, TXXX and GEOB frames contain OpenMG-specific metadata.&lt;br /&gt;
&lt;br /&gt;
  TXX   OMG_TRACK  &amp;quot;track number (ASCII)&amp;quot;&lt;br /&gt;
  TXX   OMG_AGENR  &amp;quot;content description (ASCII)&amp;quot;&lt;br /&gt;
  TXX   OMG_ATPE1  &amp;quot;leader performer (ASCII)&amp;quot;&lt;br /&gt;
  GEOB  OMG_BLKSI  contains a metadata structure. observed strings include:&lt;br /&gt;
                      KEYRING&lt;br /&gt;
                      EKB&lt;br /&gt;
                      SHARE_P_SID&lt;br /&gt;
                      REFID&lt;br /&gt;
  GEOB  OMG_OLINF  binary blob &lt;br /&gt;
&lt;br /&gt;
[[Category:Container Formats]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=RealMedia&amp;diff=15393</id>
		<title>RealMedia</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=RealMedia&amp;diff=15393"/>
		<updated>2018-11-29T13:36:32Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: RealAudio atrc ==&amp;gt; ATRAC3&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Extensions: rm, ra, rmvb&lt;br /&gt;
* Company: [[Real]]&lt;br /&gt;
* Specifications: https://common.helixcommunity.org/2003/HCS_SDK_r5/htmfiles/rmff.htm&lt;br /&gt;
&lt;br /&gt;
Multimedia container format developed by [[Real]] and used almost exclusively for codecs developed by [[Real]].&lt;br /&gt;
&lt;br /&gt;
The old .ra files are just for audio.  The newer RealMedia (.rm) files are for audio and video.&lt;br /&gt;
&lt;br /&gt;
== RA Format ==&lt;br /&gt;
&lt;br /&gt;
This is the old audio-only RealAudio file format.&lt;br /&gt;
A very similar structure is also used to describe audio streams in RM files.&lt;br /&gt;
&lt;br /&gt;
The audio data part is just a stream of bytes with no structure.&lt;br /&gt;
There is no index in .ra files, but seeking is possible because the codecs are CBR.&lt;br /&gt;
&lt;br /&gt;
=== RealAudio 1.0 file  (.ra version 3) ===&lt;br /&gt;
&lt;br /&gt;
This is from the very first version of RealAudio (1995).  These files can only contain [[RealAudio 14.4|8kbps VSELP]] audio data.  A [[FourCC]] (lpcJ) may be present, but it is ignored.  Byte order is big-endian.&lt;br /&gt;
&lt;br /&gt;
 byte[4]  Header signature ('.', 'r', 'a', 0xfd)&lt;br /&gt;
 word     Version (always 3)&lt;br /&gt;
 word     Header size, not including first 8 bytes&lt;br /&gt;
 byte[10] Unknown&lt;br /&gt;
 dword    Data size&lt;br /&gt;
 byte     Title string length&lt;br /&gt;
 byte[]   Title string&lt;br /&gt;
 byte     Author string length&lt;br /&gt;
 byte[]   Author string&lt;br /&gt;
 byte     Copyright string length&lt;br /&gt;
 byte[]   Copyright string&lt;br /&gt;
 byte     Comment string length&lt;br /&gt;
 byte[]   Comment string&lt;br /&gt;
 byte     Unknown *&lt;br /&gt;
 byte     Fourcc string length (always 4) *&lt;br /&gt;
 byte[]   Fourcc string (always &amp;quot;lpcJ&amp;quot;) *&lt;br /&gt;
  Audio data&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* Fields marked with * may be missing. Based on the only known sample with no [[FourCC]], it's assumed that all these fields are either present or missing.  To determine if they are missing, check the header size (bytes 6-7).&lt;br /&gt;
* The informative fields (title, author, copyright and comment) can have zero length.&lt;br /&gt;
&lt;br /&gt;
=== RealAudio 2.0 file (.ra version 4) ===&lt;br /&gt;
&lt;br /&gt;
This is second version of the RealAudio file format.  It is distinguished from the above by the value in byte 5 (=0x04).  This type of file must contain a valid [[FourCC]] to identify the audio codec.&lt;br /&gt;
&lt;br /&gt;
Possible [[FourCC]] values are [[RealAudio 28.8|28_8]], [[RealAudio_dnet|dnet]] and [[RealAudio_sipr|sipr]].&lt;br /&gt;
&lt;br /&gt;
 byte[4]  Header signature ('.', 'r', 'a', 0xfd)&lt;br /&gt;
 word     Version (always 4)&lt;br /&gt;
 word     Unused (always 0)&lt;br /&gt;
 byte[4]  ra4 signature (always &amp;quot;.ra4&amp;quot;)&lt;br /&gt;
 dword    Data size - 0x27&lt;br /&gt;
 word     Version2 (always equal to version)&lt;br /&gt;
 dword    Header size - 16&lt;br /&gt;
 word     Codec flavor&lt;br /&gt;
 dword    Coded frame size&lt;br /&gt;
 byte[12] Unknown&lt;br /&gt;
 word     Sub packet h&lt;br /&gt;
 word     Frame size&lt;br /&gt;
 word     Subpacket size&lt;br /&gt;
 word     Unknown&lt;br /&gt;
 word     Samplerate&lt;br /&gt;
 word     Unknown&lt;br /&gt;
 word     Sample size&lt;br /&gt;
 word     Channels&lt;br /&gt;
 byte     Interleaver ID string length (always 4)&lt;br /&gt;
 byte[]   Interleaver ID string&lt;br /&gt;
 byte     [[FourCC]] string length (always 4)&lt;br /&gt;
 byte[]   [[FourCC]] string&lt;br /&gt;
 byte[3]  Unknown&lt;br /&gt;
 byte     Title string length&lt;br /&gt;
 byte[]   Title string&lt;br /&gt;
 byte     Author string length&lt;br /&gt;
 byte[]   Author string&lt;br /&gt;
 byte     Copyright string length&lt;br /&gt;
 byte[]   Copyright string&lt;br /&gt;
 byte     Comment string length&lt;br /&gt;
 byte[]   Comment string&lt;br /&gt;
  Audio Data&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* The 0x27 in data size is the size of the fixed-length part of the header (up to channels).&lt;br /&gt;
* The informative fields (title, author, copyright and comment) can have zero length.&lt;br /&gt;
&lt;br /&gt;
=== .ra version 5 ===&lt;br /&gt;
&lt;br /&gt;
While the .ra header can contain version 5, there are no known RealAudio files with this format, and it's not known if they really exist.&lt;br /&gt;
&lt;br /&gt;
== RealMedia Format ==&lt;br /&gt;
&lt;br /&gt;
This is the newer format which stores both audio and video.  All multi-byte numbers are stored in big-endian format.&lt;br /&gt;
&lt;br /&gt;
A RealMedia file consists of a series of chunks. Each chunk has the following format:&lt;br /&gt;
&lt;br /&gt;
 dword  chunk type ([[FOURCC]])&lt;br /&gt;
 dword  chunk size, including 8-byte preamble&lt;br /&gt;
 word   chunk version&lt;br /&gt;
 byte[] chunk payload&lt;br /&gt;
&lt;br /&gt;
Real chunk types:&lt;br /&gt;
* .RMF: RealMedia file header (only one per file, must be the first chunk)&lt;br /&gt;
* PROP: File properties (only one per file)&lt;br /&gt;
* MDPR: Stream properties (one for each stream)&lt;br /&gt;
* CONT: Content description/metadata (typically one per file)&lt;br /&gt;
* DATA: File data&lt;br /&gt;
* INDX: File index (typically one per stream)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RealMedia file header (.RMF) ===&lt;br /&gt;
&lt;br /&gt;
This must be the first chunk in a RealMedia file. Only one .RMF can be present in a file. The only useful information carried by .RMF is the number of headers.&lt;br /&gt;
&lt;br /&gt;
A .RMF chunk has the following format&lt;br /&gt;
&lt;br /&gt;
 dword chunk type ('.RMF')&lt;br /&gt;
 dword chunk size (typically 0x12)&lt;br /&gt;
 word  chunk version (always 0, for every known file)&lt;br /&gt;
 dword file version&lt;br /&gt;
 dword number of headers&lt;br /&gt;
&lt;br /&gt;
Notes:&lt;br /&gt;
* All known sample files have version equal to 0.&lt;br /&gt;
* There is a sample with chunk size = 0x10, in that case file version is a word. Note that the sample has chunk version = 0 like all other files.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== File properties header (PROP) ===&lt;br /&gt;
&lt;br /&gt;
This chunk contains some information about the general properties of a RealMedia file. Only one PROP chunk can be present in a file.&lt;br /&gt;
&lt;br /&gt;
A PROP chunk has the following format&lt;br /&gt;
&lt;br /&gt;
 dword  Chunk type ('PROP')&lt;br /&gt;
 dword  Chunk size (typically 0x32)&lt;br /&gt;
 word   Chunk version (always 0, for every known file)&lt;br /&gt;
 dword  Maximum bit rate&lt;br /&gt;
 dword  Average bit rate&lt;br /&gt;
 dword  Size of largest data packet&lt;br /&gt;
 dword  Average size of data packet&lt;br /&gt;
 dword  Number of data packets in the file&lt;br /&gt;
 dword  File duration in ms&lt;br /&gt;
 dword  Suggested number of ms to buffer before starting playback&lt;br /&gt;
 dword  Offset of the first INDX chunk form the start of the file&lt;br /&gt;
 dword  Offset of the first DATA chunk form the start of the file&lt;br /&gt;
 word   Number of streams in the file&lt;br /&gt;
 word   Flags (bitfield, see below)&lt;br /&gt;
&lt;br /&gt;
Flags:&lt;br /&gt;
* bit 0: file can be saved on disk&lt;br /&gt;
* bit 1: PerfectPlay can be used (extra buffering)&lt;br /&gt;
* bit 2: the file is a live broadcast&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Media properties header (MDPR) ===&lt;br /&gt;
&lt;br /&gt;
This chunk contains information about the properties of a RealMedia stream. This header defines the type of a stream and the codec used. All codec-related data is in the type specific part of this header.&lt;br /&gt;
&lt;br /&gt;
Many fields share the same meanings as the ones in PROP chunk, but in this case they are specific for one stream.&lt;br /&gt;
&lt;br /&gt;
There is one MDPR chunk for every stream in the file.&lt;br /&gt;
&lt;br /&gt;
A MDPR chunk has the following format&lt;br /&gt;
&lt;br /&gt;
 dword   Chunk type ('MDPR')&lt;br /&gt;
 dword   Chunk size&lt;br /&gt;
 word    Chunk version (always 0, for every known file)&lt;br /&gt;
 word    Stream number&lt;br /&gt;
 dword   Maximum bit rate&lt;br /&gt;
 dword   Average bit rate&lt;br /&gt;
 dword   Size of largest data packet&lt;br /&gt;
 dword   Average size of data packet&lt;br /&gt;
 dword   Stream start offset in ms&lt;br /&gt;
 dword   Preroll in ms (to be subtracted from timestamps?)&lt;br /&gt;
 dword   Stream duration in ms&lt;br /&gt;
 byte    Size of stream description string&lt;br /&gt;
 byte[]  Stream description string&lt;br /&gt;
 byte    Size of stream mime type string&lt;br /&gt;
 byte[]  Mime type string&lt;br /&gt;
 dword   Size of type specific part of the header&lt;br /&gt;
 byte[]  Type specific data, meaning and format depends on mime type&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Audio (audio/) ====&lt;br /&gt;
&lt;br /&gt;
===== audio/x-pn-realaudio and audio/x-pn-multirate-realaudio =====&lt;br /&gt;
These mimetypes are used to specify streams with RealAudio codecs. There are 3 known versions of this datablock: ra3, ra4, ra5. ra3 is used only with the old 14_4 codec, ra4 and ra5 can be used with all the other codecs.&lt;br /&gt;
&lt;br /&gt;
The audio block has this format&lt;br /&gt;
&lt;br /&gt;
  byte[4]  Header signature ('.', 'r', 'a', 0xfd)&lt;br /&gt;
  word     Version (3, 4 or 5)&lt;br /&gt;
 #if version == 3&lt;br /&gt;
  word     Header size, not including first 8 bytes&lt;br /&gt;
  byte[10] Unknown&lt;br /&gt;
  dword    Data size&lt;br /&gt;
  byte     Title string length&lt;br /&gt;
  byte[]   Title string&lt;br /&gt;
  byte     Author string length&lt;br /&gt;
  byte[]   Author string&lt;br /&gt;
  byte     Copyright string length&lt;br /&gt;
  byte[]   Copyright string&lt;br /&gt;
  byte     Comment string length&lt;br /&gt;
  byte[]   Comment string&lt;br /&gt;
  byte     Unknown *&lt;br /&gt;
  byte     Fourcc string length (always 4) *&lt;br /&gt;
  byte[]   Fourcc string (always &amp;quot;lpcJ&amp;quot;) *&lt;br /&gt;
 #elseif version == 4 or version == 5&lt;br /&gt;
  word     Unused (always 0)&lt;br /&gt;
  byte[4]  ra signature (&amp;quot;.ra4&amp;quot; or &amp;quot;.ra5&amp;quot;, depending on version)&lt;br /&gt;
  dword    Unknown (maybe data size)&lt;br /&gt;
  word     Version2 (always equal to version)&lt;br /&gt;
  dword    Header size&lt;br /&gt;
  word     Codec flavor&lt;br /&gt;
  dword    Coded frame size&lt;br /&gt;
  byte[12] Unknown&lt;br /&gt;
  word     Sub packet h&lt;br /&gt;
  word     Frame size&lt;br /&gt;
  word     Subpacket size&lt;br /&gt;
  word     Unknown&lt;br /&gt;
 #if version == 5&lt;br /&gt;
  byte[6]  Unknown&lt;br /&gt;
 #endif&lt;br /&gt;
  word     Samplerate&lt;br /&gt;
  word     Unknown&lt;br /&gt;
  word     Sample size&lt;br /&gt;
  word     Channels&lt;br /&gt;
 #if version == 4&lt;br /&gt;
  byte     Interleaver ID string length (always 4)&lt;br /&gt;
  byte[]   Interleaver ID string&lt;br /&gt;
  byte     [[FourCC]] string length (always 4)&lt;br /&gt;
  byte[]   [[FourCC]] string&lt;br /&gt;
 #endif&lt;br /&gt;
 #if version == 5&lt;br /&gt;
  dword    Interleaver ID&lt;br /&gt;
  dword    [[FourCC]]&lt;br /&gt;
 #endif&lt;br /&gt;
  byte[3]  Unknown&lt;br /&gt;
 #if version == 5&lt;br /&gt;
  byte     Unknown&lt;br /&gt;
 #endif&lt;br /&gt;
  dword    Codec extradata length&lt;br /&gt;
  byte[]   Codec extradata&lt;br /&gt;
 #endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== audio/X-MP3-draft-00 =====&lt;br /&gt;
This is used to store MP3 audio in rm container.&lt;br /&gt;
When this mimetype is used the type-specific part of the MDPR header is not used, and its length is set to 0.&lt;br /&gt;
&lt;br /&gt;
The MP3 frames are stored in ADU format (see RFC 3119 for details) with no interleaving (at least this is true in the only known sample).&lt;br /&gt;
&lt;br /&gt;
===== audio/x-ralf-mpeg4 =====&lt;br /&gt;
This is used to store [[Real Lossless Codec|ralf]] lossless audio. This is the only known RealAudio codec that does not use the x-pn-realaudio mimetype.&lt;br /&gt;
&lt;br /&gt;
The format of this type-specific data is not known.&lt;br /&gt;
&lt;br /&gt;
=== Content description header (CONT) ===&lt;br /&gt;
&lt;br /&gt;
This chunk contains some text information (like title, author, ...) about the content of the file. This header has an informative purpose only and it's not needed to demux the file.&lt;br /&gt;
&lt;br /&gt;
A CONT chunk has the following format&lt;br /&gt;
&lt;br /&gt;
 dword   Chunk type ('CONT')&lt;br /&gt;
 dword   Chunk size&lt;br /&gt;
 word    Chunk version (always 0, for every known file)&lt;br /&gt;
 word    Title string length&lt;br /&gt;
 byte[]  Title string&lt;br /&gt;
 word    Author string length&lt;br /&gt;
 byte[]  Author string&lt;br /&gt;
 word    Copyright string length&lt;br /&gt;
 byte[]  Copyright string&lt;br /&gt;
 word    Comment string length&lt;br /&gt;
 byte[]  Comment string&lt;br /&gt;
&lt;br /&gt;
=== Data header (DATA) ===&lt;br /&gt;
&lt;br /&gt;
This chunk contains a group of data packets. Packets from each stream are interleaved, except for multirate files.&lt;br /&gt;
&lt;br /&gt;
A DATA chunk has the following format&lt;br /&gt;
&lt;br /&gt;
 dword   Chunk type ('DATA')&lt;br /&gt;
 dword   Chunk size&lt;br /&gt;
 word    Chunk version (always 0, for every known file)&lt;br /&gt;
 dword   Number of data packets in this chunk&lt;br /&gt;
 dword   Offset of the next DATA chunk (form the start of the file)&lt;br /&gt;
 byte[]  Data packets&lt;br /&gt;
&lt;br /&gt;
Each data packet has this format&lt;br /&gt;
&lt;br /&gt;
  word   Packet version (0 or 1 in available samples)&lt;br /&gt;
  word   Packet size&lt;br /&gt;
  word   Stream number&lt;br /&gt;
  dword  Timestamp (in ms)&lt;br /&gt;
  byte   Unknown&lt;br /&gt;
  byte   Flags (bitfield, see below)&lt;br /&gt;
 #if version == 1&lt;br /&gt;
  byte   Unknown&lt;br /&gt;
 #endif&lt;br /&gt;
  byte[]  Stream-specific data&lt;br /&gt;
&lt;br /&gt;
Flags:&lt;br /&gt;
* bit 0: reliable packet (refers to network transmission method)&lt;br /&gt;
* bit 1: keyframe&lt;br /&gt;
&lt;br /&gt;
Note:&lt;br /&gt;
The previous description of the data packet comes from working demuxer code, the description in official [[Real]] docs (somewhere on [[Helix]] site) is a bit different:&lt;br /&gt;
&lt;br /&gt;
  word   Packet version&lt;br /&gt;
  word   Packet size&lt;br /&gt;
  word   Stream number&lt;br /&gt;
  dword  Timestamp&lt;br /&gt;
 #if version == 0&lt;br /&gt;
  byte   Packet group&lt;br /&gt;
  byte   Flags&lt;br /&gt;
 #endif&lt;br /&gt;
 #if version == 1&lt;br /&gt;
  word   ASM rule&lt;br /&gt;
  byte   ASM flags&lt;br /&gt;
 #endif&lt;br /&gt;
  byte[]  Stream-specific data&lt;br /&gt;
&lt;br /&gt;
where packet group is &amp;quot;The packet group to which the packet belongs. If packet grouping is not used, set this field to 0 (zero)&amp;quot;, asm rule is &amp;quot;The ASM rule assigned to this packet&amp;quot; and asm flags &amp;quot;Contains HX_  flags that dictate stream switching points&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Index header (INDX) ===&lt;br /&gt;
&lt;br /&gt;
This chunk contains index entries. It comes after all the DATA chunks.&lt;br /&gt;
An index chunk contains data for a single stream, A file can have more than one INDX chunk.&lt;br /&gt;
&lt;br /&gt;
A INDX chunk has the following format&lt;br /&gt;
&lt;br /&gt;
 dword   Chunk type ('INDX')&lt;br /&gt;
 dword   Chunk size&lt;br /&gt;
 word    Chunk version (always 0, for every known file)&lt;br /&gt;
 dword   Number of entries in this chunk&lt;br /&gt;
 word    Stream number&lt;br /&gt;
 dword   Offset of the next INDX chunk (form the start of the file)&lt;br /&gt;
 byte[]  Index entries&lt;br /&gt;
&lt;br /&gt;
Each index entry has this format&lt;br /&gt;
&lt;br /&gt;
  word   Entry version (always 0, for every known file)&lt;br /&gt;
  dword  Timestamp (in ms)&lt;br /&gt;
  dword  Packet offset in file (form the start of the file)&lt;br /&gt;
  dword  Packet number&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Codecs ==&lt;br /&gt;
&lt;br /&gt;
Codecs in RealMedia are identified by the following four character codes:&lt;br /&gt;
&lt;br /&gt;
===== Audio =====&lt;br /&gt;
&lt;br /&gt;
* [[RealAudio 14.4|lpcJ]] - RealAudio 1.0 (VSELP)&lt;br /&gt;
* [[RealAudio 28.8|28_8]] - RealAudio 2.0 (LD-CELP)&lt;br /&gt;
* [[RealAudio_dnet|dnet]] - AC3&lt;br /&gt;
* [[RealAudio_sipr|sipr]] - Sipro&lt;br /&gt;
* [[RealAudio_cook|cook]] - Cook&lt;br /&gt;
* [[RealAudio_atrc|atrc]] - ATRAC3&lt;br /&gt;
* [[Real Lossless Codec|ralf]] - RealAudio Lossless Format&lt;br /&gt;
* [[RealAudio_raac|raac]] - LC-AAC&lt;br /&gt;
* [[RealAudio_racp|racp]] - HE-AAC&lt;br /&gt;
&lt;br /&gt;
===== Video =====&lt;br /&gt;
&lt;br /&gt;
* [[ClearVideo|CLV1]] - ClearVideo (from helix spec)&lt;br /&gt;
* [[RealVideo|RV10]] - H.263&lt;br /&gt;
* [[RealVideo|RV13]] - H.263&lt;br /&gt;
* [[RealVideo G2|RV20]] - H.263+&lt;br /&gt;
* [[RealVideo 3|RV30]] - H.264 precursor&lt;br /&gt;
* [[RealVideo 4|RV40]] - H.264 precursor&lt;br /&gt;
* [[BeHere_iVideo|RVTR]] - H.263+ (RV20)&lt;br /&gt;
* [[BeHere_iVideo|RVT2]] - RV30 ? (from helix spec hxmtypes.h)&lt;br /&gt;
&lt;br /&gt;
[[Category: Container Formats]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15392</id>
		<title>RealAudio atrc</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15392"/>
		<updated>2018-11-29T13:31:13Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Minor spelling improvements.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCC: atrc&lt;br /&gt;
* Company: [[Real]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/real/AC-atrc/&lt;br /&gt;
&lt;br /&gt;
Found in some old [[RealMedia]] files. The same as the [[ATRAC3]].&lt;br /&gt;
&lt;br /&gt;
== Scrambling ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files, the ATRAC3 bitstream is scrambled. To unscramble the stream, perform a XOR on every 32 bits in the frame. The hex value to XOR with is 0x537F6103.&lt;br /&gt;
&lt;br /&gt;
== Extra data format ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files, ATRAC3 extra data has the following format (big-endian order):&lt;br /&gt;
&lt;br /&gt;
 INT32	id, always 4&lt;br /&gt;
 INT16	samples per frame, always 1024 * 2&lt;br /&gt;
 INT16	delay, not used but always 0x88E&lt;br /&gt;
 INT16	stereo coding mode, 2 - normal stereo, 0x12 - joint stereo&lt;br /&gt;
&lt;br /&gt;
The length of this data is always 10 bytes.&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15391</id>
		<title>ATRAC3</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15391"/>
		<updated>2018-11-29T13:29:41Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Repair RealAudio atrc link.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= ATRAC3 Introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:&lt;br /&gt;
[[RealAudio atrc]], the Sony ATRAC3 for [[Microsoft Audio Compression Manager API|Audio Compression Manager]] (ACM) and the Sonic Stage implementation.&lt;br /&gt;
&lt;br /&gt;
ATRAC3 supports several different constant bitrates (&amp;quot;flavors&amp;quot;). The following table shows the&lt;br /&gt;
bitrate, the size of a frame and the coding mode for each flavor respectively:&lt;br /&gt;
&lt;br /&gt;
 No             bitrate   frame size (stereo)     coding mode   samples per frame&lt;br /&gt;
 --   -----------------   -------------------   -------------   -----------------&lt;br /&gt;
 0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel&lt;br /&gt;
 1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel&lt;br /&gt;
 2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel&lt;br /&gt;
 3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel&lt;br /&gt;
 4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel&lt;br /&gt;
 5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel&lt;br /&gt;
 6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel&lt;br /&gt;
 7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel&lt;br /&gt;
&lt;br /&gt;
== Encoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Split the input signal into 4 bands using a Quadrature mirror filter (QMF).&lt;br /&gt;
* Perform gain control analysis to obtain gain control data.&lt;br /&gt;
* Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).&lt;br /&gt;
* Find tonal components.&lt;br /&gt;
* Quantization&lt;br /&gt;
* Encode the bitstream.&lt;br /&gt;
&lt;br /&gt;
Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.&lt;br /&gt;
&lt;br /&gt;
== Decoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Parse the bitstream and extract the following:&lt;br /&gt;
** gain control data&lt;br /&gt;
** tonal components&lt;br /&gt;
** quantized spectral coefficients&lt;br /&gt;
* inverse quantization of the tonal components and spectral coefficients&lt;br /&gt;
* Merge tonal components and other spectral coefficients together.&lt;br /&gt;
* Reconstruct the timedomain signal using inverse MDCT.&lt;br /&gt;
* gain compensation&lt;br /&gt;
* Apply the QMF synthesis filter to reconstruct the sound.&lt;br /&gt;
&lt;br /&gt;
== Tonal components ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra&lt;br /&gt;
and encodes them separate from the less important spectral data. A tone component is a group of&lt;br /&gt;
consecutive spectral coefficients, described with parameters such as location and with. This allows&lt;br /&gt;
finer quantization of such coefficients than a quantization within fixed subbands.&lt;br /&gt;
&lt;br /&gt;
== Joint-stereo mode ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The ATRAC3 bitstream consists of so-called &amp;quot;Channel Sound Units&amp;quot;. In stereo mode there are&lt;br /&gt;
two such units. The structure of an unit is shown below:&lt;br /&gt;
&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Header                             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Gain compensation data             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Tonal components                   |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Other spectral coefficients        |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
&lt;br /&gt;
= Decoding Specification =&lt;br /&gt;
&lt;br /&gt;
== Bitstream parsing ==&lt;br /&gt;
&lt;br /&gt;
Parts is '''bold''' mean that a certain amount of bits are to be consumed from the bitstream.&lt;br /&gt;
&lt;br /&gt;
===Header===&lt;br /&gt;
&lt;br /&gt;
If not in the joint-stereo mode, this header should be interpreted as follows:&lt;br /&gt;
* '''id (6 bits)''' - should contain the value 0x28&lt;br /&gt;
* '''nBandsCoded (2 bits)''' - number of QMF bands were coded. The value of 0 indicates one coded band.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Gain compensation data===&lt;br /&gt;
&lt;br /&gt;
For each coded QMF band (see nBandsCoded above) the following data will be transmitted:&lt;br /&gt;
* '''numGainData (3 bits)''' - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:&lt;br /&gt;
* '''levcode (4 bits)''' - level code&lt;br /&gt;
* '''loccode (5 bits)''' - location code&lt;br /&gt;
This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by [[Sony]]. Please refer to section &amp;quot;Gain compensation&amp;quot; below for a description how to interpret this data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tonal components===&lt;br /&gt;
&lt;br /&gt;
The presence of tonal components is indicated by the following field:&lt;br /&gt;
* '''numToneComp (5 bits)''' - Number of coded tonal components. The value of 0 indicates no coded tonal components.&lt;br /&gt;
* '''coding_mode_selector(2 bits)''' -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)&lt;br /&gt;
&lt;br /&gt;
* For each tonal component&lt;br /&gt;
** For each number of bands, get band flags&lt;br /&gt;
*** '''band_flags (1 bit)''' -- Flag per band in the Tonal Component to be processed&lt;br /&gt;
** '''coded_values (3 bits)''' -- amount of coded coefficients&lt;br /&gt;
** '''quant_step_index (3 bits)''' -- index into the quant step table, if it is less then/equal to 1 then return error&lt;br /&gt;
** if coding_mode_selector is 3&lt;br /&gt;
*** '''coding_mode (1 bit)''' -- get the bands coding mode (CLC/VLC)&lt;br /&gt;
&lt;br /&gt;
===Other spectral coefficients===&lt;br /&gt;
&lt;br /&gt;
The coefficients coded in this block are assumed not to be &amp;quot;tonal&amp;quot; (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:&lt;br /&gt;
* '''numSubbands (5 bits)''' - number of coded subbands. The value of 0 indicates no coded subbands.&lt;br /&gt;
* '''codingMode (1 bit)''' - value indicates the coding mode for ALL subbands:&lt;br /&gt;
&lt;br /&gt;
 0 - coefficients are coded using variable length codes (VLC)&lt;br /&gt;
 1 - coefficients are coded using constant length codes (CLC)&lt;br /&gt;
&lt;br /&gt;
Then follow the array of coding table indexes for each coded band:&lt;br /&gt;
* '''tblIndex (3 bits)''' - indicates the coding table used (VLC) or number of bits used (CLC). The value of &amp;quot;0&amp;quot; indicates &amp;quot;skipped&amp;quot; (not coded) subband.&lt;br /&gt;
Then follows the array of scalefactor indexes for each coded subband:&lt;br /&gt;
* '''sfIndex (6 bits)''' - indicates the index into scalefactor decoding table (see below).&lt;br /&gt;
Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Transforms ==&lt;br /&gt;
&lt;br /&gt;
=== QMF ===&lt;br /&gt;
&lt;br /&gt;
Three stacked [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filters] are used to split the signal into 4 different frequency bands.&lt;br /&gt;
&lt;br /&gt;
* 0 to 2.75625 kHz (DC to ''f''/16)&lt;br /&gt;
* 2.75625 to 5.5125 kHz (''f''/16 to ''f''/8)&lt;br /&gt;
* 5.5125 to 11.025 kHz (''f''/8 to ''f''/4)&lt;br /&gt;
* 11.025 to 22.05 kHz (''f''/4 to ''f''/2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QMF window ====&lt;br /&gt;
&lt;br /&gt;
The coeffs used in the QMF filter.&lt;br /&gt;
&lt;br /&gt;
 float qmf_48tap_half[24] = {&lt;br /&gt;
   -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,&lt;br /&gt;
   0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,&lt;br /&gt;
   0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,&lt;br /&gt;
   -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,&lt;br /&gt;
   -0.007801671, -0.034090221, 0.01880949, 0.054326009,&lt;br /&gt;
   -0.043596379, -0.099384367, 0.13207909, 0.46424159&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
These coeffs need to be mirrored and scaled by 2.&lt;br /&gt;
&lt;br /&gt;
 for (i=0 ; i&amp;lt;24; i++) {&lt;br /&gt;
   s = qmf_48tap_half[i] * 2.0;&lt;br /&gt;
   qmf_window[i] = s;&lt;br /&gt;
   qmf_window[47 - i] = s;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== MLT ===&lt;br /&gt;
&lt;br /&gt;
The transform is a regular MDCT.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [http://research.microsoft.com/~malvar/papers/dfsp98.pdf]&lt;br /&gt;
&lt;br /&gt;
====== Encoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
====== Decoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   wd[i] = we[i]/(we[i]^2 + we[255-i]^2)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Huffman coding ==&lt;br /&gt;
&lt;br /&gt;
VLC coding is used to compress the tonal and spectral coefficients.&lt;br /&gt;
&lt;br /&gt;
=== Huffman tables ===&lt;br /&gt;
&lt;br /&gt;
 huffcode1[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits1[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode2[5] = {&lt;br /&gt;
   0x0,0x4,0x5,0x6,0x7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits2[5] = {&lt;br /&gt;
   1,3,3,3,3,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode3[7] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0xE,0xF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits3[7] = {&lt;br /&gt;
   1,3,3,4,4,4,4,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode4[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits4[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode5[15] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits5[15] = {&lt;br /&gt;
   2,3,3,4,4,4,4,4,4,5,5,6,6,6,6,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode6[31] = {&lt;br /&gt;
   0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35,&lt;br /&gt;
   0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits6[31] = {&lt;br /&gt;
   3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode7[63] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28,&lt;br /&gt;
   0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C,&lt;br /&gt;
   0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,&lt;br /&gt;
   0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits7[63] = {&lt;br /&gt;
   3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,&lt;br /&gt;
   7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15390</id>
		<title>RealAudio atrc</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15390"/>
		<updated>2018-11-29T13:27:33Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Create its own page for RealMedia clone of Sony ATRAC3.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCC: atrc&lt;br /&gt;
* Company: [[Real]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/real/AC-atrc/&lt;br /&gt;
&lt;br /&gt;
Found in some old [[RealMedia]] files. The same as the [[ATRAC3]].&lt;br /&gt;
&lt;br /&gt;
== Scrambling ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files the bitstream is scrambled. To unscramble the stream, perform a XOR on every 32 bits in the frame. The hex value to XOR with is 0x537F6103.&lt;br /&gt;
&lt;br /&gt;
== Extra data format ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files the extra data is as follows (big-endian order):&lt;br /&gt;
&lt;br /&gt;
 INT32	id, always 4&lt;br /&gt;
 INT16	samples per frame, always 1024 * 2&lt;br /&gt;
 INT16	delay, not used but always 0x88E&lt;br /&gt;
 INT16	stereo coding mode, 2 - normal stereo, 0x12 - joint stereo&lt;br /&gt;
&lt;br /&gt;
The length of this data is always 10 bytes.&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15389</id>
		<title>ATRAC3</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15389"/>
		<updated>2018-11-29T13:26:35Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Move out RealMedia atrc related stuff to its own page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= ATRAC3 Introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:&lt;br /&gt;
RealAudio8 atrc, the Sony ATRAC3 for [[Microsoft Audio Compression Manager API|Audio Compression Manager]] (ACM) and the Sonic Stage implementation.&lt;br /&gt;
&lt;br /&gt;
ATRAC3 supports several different constant bitrates (&amp;quot;flavors&amp;quot;). The following table shows the&lt;br /&gt;
bitrate, the size of a frame and the coding mode for each flavor respectively:&lt;br /&gt;
&lt;br /&gt;
 No             bitrate   frame size (stereo)     coding mode   samples per frame&lt;br /&gt;
 --   -----------------   -------------------   -------------   -----------------&lt;br /&gt;
 0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel&lt;br /&gt;
 1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel&lt;br /&gt;
 2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel&lt;br /&gt;
 3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel&lt;br /&gt;
 4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel&lt;br /&gt;
 5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel&lt;br /&gt;
 6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel&lt;br /&gt;
 7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel&lt;br /&gt;
&lt;br /&gt;
== Encoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Split the input signal into 4 bands using a Quadrature mirror filter (QMF).&lt;br /&gt;
* Perform gain control analysis to obtain gain control data.&lt;br /&gt;
* Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).&lt;br /&gt;
* Find tonal components.&lt;br /&gt;
* Quantization&lt;br /&gt;
* Encode the bitstream.&lt;br /&gt;
&lt;br /&gt;
Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.&lt;br /&gt;
&lt;br /&gt;
== Decoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Parse the bitstream and extract the following:&lt;br /&gt;
** gain control data&lt;br /&gt;
** tonal components&lt;br /&gt;
** quantized spectral coefficients&lt;br /&gt;
* inverse quantization of the tonal components and spectral coefficients&lt;br /&gt;
* Merge tonal components and other spectral coefficients together.&lt;br /&gt;
* Reconstruct the timedomain signal using inverse MDCT.&lt;br /&gt;
* gain compensation&lt;br /&gt;
* Apply the QMF synthesis filter to reconstruct the sound.&lt;br /&gt;
&lt;br /&gt;
== Tonal components ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra&lt;br /&gt;
and encodes them separate from the less important spectral data. A tone component is a group of&lt;br /&gt;
consecutive spectral coefficients, described with parameters such as location and with. This allows&lt;br /&gt;
finer quantization of such coefficients than a quantization within fixed subbands.&lt;br /&gt;
&lt;br /&gt;
== Joint-stereo mode ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The ATRAC3 bitstream consists of so-called &amp;quot;Channel Sound Units&amp;quot;. In stereo mode there are&lt;br /&gt;
two such units. The structure of an unit is shown below:&lt;br /&gt;
&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Header                             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Gain compensation data             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Tonal components                   |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Other spectral coefficients        |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
&lt;br /&gt;
= Decoding Specification =&lt;br /&gt;
&lt;br /&gt;
== Bitstream parsing ==&lt;br /&gt;
&lt;br /&gt;
Parts is '''bold''' mean that a certain amount of bits are to be consumed from the bitstream.&lt;br /&gt;
&lt;br /&gt;
===Header===&lt;br /&gt;
&lt;br /&gt;
If not in the joint-stereo mode, this header should be interpreted as follows:&lt;br /&gt;
* '''id (6 bits)''' - should contain the value 0x28&lt;br /&gt;
* '''nBandsCoded (2 bits)''' - number of QMF bands were coded. The value of 0 indicates one coded band.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Gain compensation data===&lt;br /&gt;
&lt;br /&gt;
For each coded QMF band (see nBandsCoded above) the following data will be transmitted:&lt;br /&gt;
* '''numGainData (3 bits)''' - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:&lt;br /&gt;
* '''levcode (4 bits)''' - level code&lt;br /&gt;
* '''loccode (5 bits)''' - location code&lt;br /&gt;
This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by [[Sony]]. Please refer to section &amp;quot;Gain compensation&amp;quot; below for a description how to interpret this data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tonal components===&lt;br /&gt;
&lt;br /&gt;
The presence of tonal components is indicated by the following field:&lt;br /&gt;
* '''numToneComp (5 bits)''' - Number of coded tonal components. The value of 0 indicates no coded tonal components.&lt;br /&gt;
* '''coding_mode_selector(2 bits)''' -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)&lt;br /&gt;
&lt;br /&gt;
* For each tonal component&lt;br /&gt;
** For each number of bands, get band flags&lt;br /&gt;
*** '''band_flags (1 bit)''' -- Flag per band in the Tonal Component to be processed&lt;br /&gt;
** '''coded_values (3 bits)''' -- amount of coded coefficients&lt;br /&gt;
** '''quant_step_index (3 bits)''' -- index into the quant step table, if it is less then/equal to 1 then return error&lt;br /&gt;
** if coding_mode_selector is 3&lt;br /&gt;
*** '''coding_mode (1 bit)''' -- get the bands coding mode (CLC/VLC)&lt;br /&gt;
&lt;br /&gt;
===Other spectral coefficients===&lt;br /&gt;
&lt;br /&gt;
The coefficients coded in this block are assumed not to be &amp;quot;tonal&amp;quot; (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:&lt;br /&gt;
* '''numSubbands (5 bits)''' - number of coded subbands. The value of 0 indicates no coded subbands.&lt;br /&gt;
* '''codingMode (1 bit)''' - value indicates the coding mode for ALL subbands:&lt;br /&gt;
&lt;br /&gt;
 0 - coefficients are coded using variable length codes (VLC)&lt;br /&gt;
 1 - coefficients are coded using constant length codes (CLC)&lt;br /&gt;
&lt;br /&gt;
Then follow the array of coding table indexes for each coded band:&lt;br /&gt;
* '''tblIndex (3 bits)''' - indicates the coding table used (VLC) or number of bits used (CLC). The value of &amp;quot;0&amp;quot; indicates &amp;quot;skipped&amp;quot; (not coded) subband.&lt;br /&gt;
Then follows the array of scalefactor indexes for each coded subband:&lt;br /&gt;
* '''sfIndex (6 bits)''' - indicates the index into scalefactor decoding table (see below).&lt;br /&gt;
Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Transforms ==&lt;br /&gt;
&lt;br /&gt;
=== QMF ===&lt;br /&gt;
&lt;br /&gt;
Three stacked [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filters] are used to split the signal into 4 different frequency bands.&lt;br /&gt;
&lt;br /&gt;
* 0 to 2.75625 kHz (DC to ''f''/16)&lt;br /&gt;
* 2.75625 to 5.5125 kHz (''f''/16 to ''f''/8)&lt;br /&gt;
* 5.5125 to 11.025 kHz (''f''/8 to ''f''/4)&lt;br /&gt;
* 11.025 to 22.05 kHz (''f''/4 to ''f''/2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QMF window ====&lt;br /&gt;
&lt;br /&gt;
The coeffs used in the QMF filter.&lt;br /&gt;
&lt;br /&gt;
 float qmf_48tap_half[24] = {&lt;br /&gt;
   -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,&lt;br /&gt;
   0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,&lt;br /&gt;
   0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,&lt;br /&gt;
   -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,&lt;br /&gt;
   -0.007801671, -0.034090221, 0.01880949, 0.054326009,&lt;br /&gt;
   -0.043596379, -0.099384367, 0.13207909, 0.46424159&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
These coeffs need to be mirrored and scaled by 2.&lt;br /&gt;
&lt;br /&gt;
 for (i=0 ; i&amp;lt;24; i++) {&lt;br /&gt;
   s = qmf_48tap_half[i] * 2.0;&lt;br /&gt;
   qmf_window[i] = s;&lt;br /&gt;
   qmf_window[47 - i] = s;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== MLT ===&lt;br /&gt;
&lt;br /&gt;
The transform is a regular MDCT.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [http://research.microsoft.com/~malvar/papers/dfsp98.pdf]&lt;br /&gt;
&lt;br /&gt;
====== Encoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
====== Decoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   wd[i] = we[i]/(we[i]^2 + we[255-i]^2)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Huffman coding ==&lt;br /&gt;
&lt;br /&gt;
VLC coding is used to compress the tonal and spectral coefficients.&lt;br /&gt;
&lt;br /&gt;
=== Huffman tables ===&lt;br /&gt;
&lt;br /&gt;
 huffcode1[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits1[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode2[5] = {&lt;br /&gt;
   0x0,0x4,0x5,0x6,0x7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits2[5] = {&lt;br /&gt;
   1,3,3,3,3,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode3[7] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0xE,0xF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits3[7] = {&lt;br /&gt;
   1,3,3,4,4,4,4,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode4[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits4[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode5[15] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits5[15] = {&lt;br /&gt;
   2,3,3,4,4,4,4,4,4,5,5,6,6,6,6,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode6[31] = {&lt;br /&gt;
   0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35,&lt;br /&gt;
   0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits6[31] = {&lt;br /&gt;
   3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode7[63] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28,&lt;br /&gt;
   0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C,&lt;br /&gt;
   0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,&lt;br /&gt;
   0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits7[63] = {&lt;br /&gt;
   3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,&lt;br /&gt;
   7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15388</id>
		<title>Sony ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15388"/>
		<updated>2018-11-29T13:21:13Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Link with the ATRAC3 page.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: 0x270&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3/&lt;br /&gt;
* Technical: http://www.minidisc.org/aes_atrac.html&lt;br /&gt;
&lt;br /&gt;
ATRAC (Adaptive TRansform Acoustic Coding) is the collective name for audio compression technologies&lt;br /&gt;
developed by [[Sony]]. This codec family includes the following codecs today: ATRAC, ATRAC3,&lt;br /&gt;
ATRAC3plus and ATRAC Advanced lossless.&lt;br /&gt;
You can read about it at http://www.sony.net/Products/ATRAC3/overview/index.html#family&lt;br /&gt;
&lt;br /&gt;
The ATRAC codec was introduced in 1992 with the MiniDisc. There is a good description at&lt;br /&gt;
http://www.minidisc.org/aes_atrac.html. It is used in MiniDisc portable players&lt;br /&gt;
by many companies.&lt;br /&gt;
&lt;br /&gt;
Same as [[RealAudio atrc]], the RealAudio streams are XOR scrambled.&lt;br /&gt;
&lt;br /&gt;
Stored in [[Microsoft_Wave|WAV]]/[[Microsoft_Audio/Video_Interleaved|AVI]], [[RealMedia|RM]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
&lt;br /&gt;
Sony Dynamic Digital System (SDDS), used in theatres, is based on ATRAC. Common use of the codec is in Sony made Minidisc and Flash based players.&lt;br /&gt;
&lt;br /&gt;
There are some known variants:&lt;br /&gt;
* ATRAC&lt;br /&gt;
* [[ATRAC3]]&lt;br /&gt;
* [[ATRAC3plus]]&lt;br /&gt;
* ATRAC Advanced Lossless (AAL)&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;br /&gt;
[[Category: Lossless Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15387</id>
		<title>RealAudio atrc</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=RealAudio_atrc&amp;diff=15387"/>
		<updated>2018-11-29T13:20:19Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Maxpol moved page RealAudio atrc to ATRAC3: Rename to reflect codec's original name instead of its clone.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;#REDIRECT [[ATRAC3]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15386</id>
		<title>ATRAC3</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15386"/>
		<updated>2018-11-29T13:20:19Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Maxpol moved page RealAudio atrc to ATRAC3: Rename to reflect codec's original name instead of its clone.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCC: atrc&lt;br /&gt;
* Company: [[Real]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/real/AC-atrc/&lt;br /&gt;
&lt;br /&gt;
Found in some old [[RealMedia]] files. The same as the [[Sony ATRAC]].&lt;br /&gt;
&lt;br /&gt;
= ATRAC3 Introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:&lt;br /&gt;
RealAudio8 atrc, the Sony ATRAC3 for [[Microsoft Audio Compression Manager API|Audio Compression Manager]] (ACM) and the Sonic Stage implementation.&lt;br /&gt;
&lt;br /&gt;
ATRAC3 supports several different constant bitrates (&amp;quot;flavors&amp;quot;). The following table shows the&lt;br /&gt;
bitrate, the size of a frame and the coding mode for each flavor respectively:&lt;br /&gt;
&lt;br /&gt;
 No             bitrate   frame size (stereo)     coding mode   samples per frame&lt;br /&gt;
 --   -----------------   -------------------   -------------   -----------------&lt;br /&gt;
 0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel&lt;br /&gt;
 1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel&lt;br /&gt;
 2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel&lt;br /&gt;
 3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel&lt;br /&gt;
 4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel&lt;br /&gt;
 5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel&lt;br /&gt;
 6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel&lt;br /&gt;
 7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel&lt;br /&gt;
&lt;br /&gt;
== Encoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Split the input signal into 4 bands using a Quadrature mirror filter (QMF).&lt;br /&gt;
* Perform gain control analysis to obtain gain control data.&lt;br /&gt;
* Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).&lt;br /&gt;
* Find tonal components.&lt;br /&gt;
* Quantization&lt;br /&gt;
* Encode the bitstream.&lt;br /&gt;
&lt;br /&gt;
Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.&lt;br /&gt;
&lt;br /&gt;
== Decoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Parse the bitstream and extract the following:&lt;br /&gt;
** gain control data&lt;br /&gt;
** tonal components&lt;br /&gt;
** quantized spectral coefficients&lt;br /&gt;
* inverse quantization of the tonal components and spectral coefficients&lt;br /&gt;
* Merge tonal components and other spectral coefficients together.&lt;br /&gt;
* Reconstruct the timedomain signal using inverse MDCT.&lt;br /&gt;
* gain compensation&lt;br /&gt;
* Apply the QMF synthesis filter to reconstruct the sound.&lt;br /&gt;
&lt;br /&gt;
== Tonal components ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra&lt;br /&gt;
and encodes them separate from the less important spectral data. A tone component is a group of&lt;br /&gt;
consecutive spectral coefficients, described with parameters such as location and with. This allows&lt;br /&gt;
finer quantization of such coefficients than a quantization within fixed subbands.&lt;br /&gt;
&lt;br /&gt;
== Joint-stereo mode ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The ATRAC3 bitstream consists of so-called &amp;quot;Channel Sound Units&amp;quot;. In stereo mode there are&lt;br /&gt;
two such units. The structure of an unit is shown below:&lt;br /&gt;
&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Header                             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Gain compensation data             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Tonal components                   |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Other spectral coefficients        |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
&lt;br /&gt;
= Decoding Specification =&lt;br /&gt;
&lt;br /&gt;
== Bitstream parsing ==&lt;br /&gt;
&lt;br /&gt;
Parts is '''bold''' mean that a certain amount of bits are to be consumed from the bitstream.&lt;br /&gt;
&lt;br /&gt;
===Header===&lt;br /&gt;
&lt;br /&gt;
If not in the joint-stereo mode, this header should be interpreted as follows:&lt;br /&gt;
* '''id (6 bits)''' - should contain the value 0x28&lt;br /&gt;
* '''nBandsCoded (2 bits)''' - number of QMF bands were coded. The value of 0 indicates one coded band.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Gain compensation data===&lt;br /&gt;
&lt;br /&gt;
For each coded QMF band (see nBandsCoded above) the following data will be transmitted:&lt;br /&gt;
* '''numGainData (3 bits)''' - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:&lt;br /&gt;
* '''levcode (4 bits)''' - level code&lt;br /&gt;
* '''loccode (5 bits)''' - location code&lt;br /&gt;
This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by [[Sony]]. Please refer to section &amp;quot;Gain compensation&amp;quot; below for a description how to interpret this data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tonal components===&lt;br /&gt;
&lt;br /&gt;
The presence of tonal components is indicated by the following field:&lt;br /&gt;
* '''numToneComp (5 bits)''' - Number of coded tonal components. The value of 0 indicates no coded tonal components.&lt;br /&gt;
* '''coding_mode_selector(2 bits)''' -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)&lt;br /&gt;
&lt;br /&gt;
* For each tonal component&lt;br /&gt;
** For each number of bands, get band flags&lt;br /&gt;
*** '''band_flags (1 bit)''' -- Flag per band in the Tonal Component to be processed&lt;br /&gt;
** '''coded_values (3 bits)''' -- amount of coded coefficients&lt;br /&gt;
** '''quant_step_index (3 bits)''' -- index into the quant step table, if it is less then/equal to 1 then return error&lt;br /&gt;
** if coding_mode_selector is 3&lt;br /&gt;
*** '''coding_mode (1 bit)''' -- get the bands coding mode (CLC/VLC)&lt;br /&gt;
&lt;br /&gt;
===Other spectral coefficients===&lt;br /&gt;
&lt;br /&gt;
The coefficients coded in this block are assumed not to be &amp;quot;tonal&amp;quot; (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:&lt;br /&gt;
* '''numSubbands (5 bits)''' - number of coded subbands. The value of 0 indicates no coded subbands.&lt;br /&gt;
* '''codingMode (1 bit)''' - value indicates the coding mode for ALL subbands:&lt;br /&gt;
&lt;br /&gt;
 0 - coefficients are coded using variable length codes (VLC)&lt;br /&gt;
 1 - coefficients are coded using constant length codes (CLC)&lt;br /&gt;
&lt;br /&gt;
Then follow the array of coding table indexes for each coded band:&lt;br /&gt;
* '''tblIndex (3 bits)''' - indicates the coding table used (VLC) or number of bits used (CLC). The value of &amp;quot;0&amp;quot; indicates &amp;quot;skipped&amp;quot; (not coded) subband.&lt;br /&gt;
Then follows the array of scalefactor indexes for each coded subband:&lt;br /&gt;
* '''sfIndex (6 bits)''' - indicates the index into scalefactor decoding table (see below).&lt;br /&gt;
Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.&lt;br /&gt;
&lt;br /&gt;
== Scrambling ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files the bitstream is scrambled. To unscramble the stream, perform a XOR on every 32 bits in the frame. The hex value to XOR with is 0x537F6103.&lt;br /&gt;
&lt;br /&gt;
== Extra data format ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files the extra data is as follows (big-endian order):&lt;br /&gt;
&lt;br /&gt;
 INT32	id, always 4&lt;br /&gt;
 INT16	samples per frame, always 1024 * 2&lt;br /&gt;
 INT16	delay, not used but always 0x88E&lt;br /&gt;
 INT16	stereo coding mode, 2 - normal stereo, 0x12 - joint stereo&lt;br /&gt;
&lt;br /&gt;
The length of this data is always 10 bytes.&lt;br /&gt;
&lt;br /&gt;
== Transforms ==&lt;br /&gt;
&lt;br /&gt;
=== QMF ===&lt;br /&gt;
&lt;br /&gt;
Three stacked [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filters] are used to split the signal into 4 different frequency bands.&lt;br /&gt;
&lt;br /&gt;
* 0 to 2.75625 kHz (DC to ''f''/16)&lt;br /&gt;
* 2.75625 to 5.5125 kHz (''f''/16 to ''f''/8)&lt;br /&gt;
* 5.5125 to 11.025 kHz (''f''/8 to ''f''/4)&lt;br /&gt;
* 11.025 to 22.05 kHz (''f''/4 to ''f''/2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QMF window ====&lt;br /&gt;
&lt;br /&gt;
The coeffs used in the QMF filter.&lt;br /&gt;
&lt;br /&gt;
 float qmf_48tap_half[24] = {&lt;br /&gt;
   -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,&lt;br /&gt;
   0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,&lt;br /&gt;
   0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,&lt;br /&gt;
   -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,&lt;br /&gt;
   -0.007801671, -0.034090221, 0.01880949, 0.054326009,&lt;br /&gt;
   -0.043596379, -0.099384367, 0.13207909, 0.46424159&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
These coeffs need to be mirrored and scaled by 2.&lt;br /&gt;
&lt;br /&gt;
 for (i=0 ; i&amp;lt;24; i++) {&lt;br /&gt;
   s = qmf_48tap_half[i] * 2.0;&lt;br /&gt;
   qmf_window[i] = s;&lt;br /&gt;
   qmf_window[47 - i] = s;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== MLT ===&lt;br /&gt;
&lt;br /&gt;
The transform is a regular MDCT.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [http://research.microsoft.com/~malvar/papers/dfsp98.pdf]&lt;br /&gt;
&lt;br /&gt;
====== Encoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
====== Decoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   wd[i] = we[i]/(we[i]^2 + we[255-i]^2)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Huffman coding ==&lt;br /&gt;
&lt;br /&gt;
VLC coding is used to compress the tonal and spectral coefficients.&lt;br /&gt;
&lt;br /&gt;
=== Huffman tables ===&lt;br /&gt;
&lt;br /&gt;
 huffcode1[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits1[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode2[5] = {&lt;br /&gt;
   0x0,0x4,0x5,0x6,0x7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits2[5] = {&lt;br /&gt;
   1,3,3,3,3,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode3[7] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0xE,0xF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits3[7] = {&lt;br /&gt;
   1,3,3,4,4,4,4,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode4[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits4[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode5[15] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits5[15] = {&lt;br /&gt;
   2,3,3,4,4,4,4,4,4,5,5,6,6,6,6,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode6[31] = {&lt;br /&gt;
   0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35,&lt;br /&gt;
   0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits6[31] = {&lt;br /&gt;
   3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode7[63] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28,&lt;br /&gt;
   0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C,&lt;br /&gt;
   0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,&lt;br /&gt;
   0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits7[63] = {&lt;br /&gt;
   3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,&lt;br /&gt;
   7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15385</id>
		<title>Sony ATRAC</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Sony_ATRAC&amp;diff=15385"/>
		<updated>2018-11-29T13:16:08Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Add general ATRAC family description.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: 0x270&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3/&lt;br /&gt;
* Technical: http://www.minidisc.org/aes_atrac.html&lt;br /&gt;
&lt;br /&gt;
ATRAC (Adaptive TRansform Acoustic Coding) is the collective name for audio compression technologies&lt;br /&gt;
developed by [[Sony]]. This codec family includes the following codecs today: ATRAC, ATRAC3,&lt;br /&gt;
ATRAC3plus and ATRAC Advanced lossless.&lt;br /&gt;
You can read about it at http://www.sony.net/Products/ATRAC3/overview/index.html#family&lt;br /&gt;
&lt;br /&gt;
The ATRAC codec was introduced in 1992 with the MiniDisc. There is a good description at&lt;br /&gt;
http://www.minidisc.org/aes_atrac.html. It is used in MiniDisc portable players&lt;br /&gt;
by many companies.&lt;br /&gt;
&lt;br /&gt;
Same as [[RealAudio atrc]], the RealAudio streams are XOR scrambled.&lt;br /&gt;
&lt;br /&gt;
Stored in [[Microsoft_Wave|WAV]]/[[Microsoft_Audio/Video_Interleaved|AVI]], [[RealMedia|RM]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
&lt;br /&gt;
Sony Dynamic Digital System (SDDS), used in theatres, is based on ATRAC. Common use of the codec is in Sony made Minidisc and Flash based players.&lt;br /&gt;
&lt;br /&gt;
There are some known variants:&lt;br /&gt;
* ATRAC&lt;br /&gt;
* ATRAC3&lt;br /&gt;
* [[ATRAC3plus]]&lt;br /&gt;
* ATRAC Advanced Lossless (AAL)&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;br /&gt;
[[Category: Lossless Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15384</id>
		<title>ATRAC3</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3&amp;diff=15384"/>
		<updated>2018-11-29T13:15:31Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: Factor out general ATRAC description.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCC: atrc&lt;br /&gt;
* Company: [[Real]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/real/AC-atrc/&lt;br /&gt;
&lt;br /&gt;
Found in some old [[RealMedia]] files. The same as the [[Sony ATRAC]].&lt;br /&gt;
&lt;br /&gt;
= ATRAC3 Introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3 is the next generation of the ATRAC codec. There are three major implementations for the PC:&lt;br /&gt;
RealAudio8 atrc, the Sony ATRAC3 for [[Microsoft Audio Compression Manager API|Audio Compression Manager]] (ACM) and the Sonic Stage implementation.&lt;br /&gt;
&lt;br /&gt;
ATRAC3 supports several different constant bitrates (&amp;quot;flavors&amp;quot;). The following table shows the&lt;br /&gt;
bitrate, the size of a frame and the coding mode for each flavor respectively:&lt;br /&gt;
&lt;br /&gt;
 No             bitrate   frame size (stereo)     coding mode   samples per frame&lt;br /&gt;
 --   -----------------   -------------------   -------------   -----------------&lt;br /&gt;
 0     66 kbps  (66150)             192 bytes    joint stereo    1024 per channel&lt;br /&gt;
 1     94 kpbs  (93713)             272 bytes    joint stereo    1024 per channel&lt;br /&gt;
 2    105 kbps (104738)             304 bytes   normal stereo    1024 per channel&lt;br /&gt;
 3    132 kpbs (132300)             384 bytes   normal stereo    1024 per channel&lt;br /&gt;
 4    146 kbps (146081)             424 bytes   normal stereo    1024 per channel&lt;br /&gt;
 5    176 kbps (176400)             512 bytes   normal stereo    1024 per channel&lt;br /&gt;
 6    264 kbps (264600)             768 bytes   normal stereo    1024 per channel&lt;br /&gt;
 7    352 kbps (352800)            1024 bytes   normal stereo    1024 per channel&lt;br /&gt;
&lt;br /&gt;
== Encoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Split the input signal into 4 bands using a Quadrature mirror filter (QMF).&lt;br /&gt;
* Perform gain control analysis to obtain gain control data.&lt;br /&gt;
* Convert all four bands into frequency domain using Modified Cosine Transform (MDCT or MLT).&lt;br /&gt;
* Find tonal components.&lt;br /&gt;
* Quantization&lt;br /&gt;
* Encode the bitstream.&lt;br /&gt;
&lt;br /&gt;
Even though this is for ATRAC2 (http://www.minidisc.org/atrac2.html) most of it applies to ATRAC3.&lt;br /&gt;
&lt;br /&gt;
== Decoding algorithm ==&lt;br /&gt;
&lt;br /&gt;
* Parse the bitstream and extract the following:&lt;br /&gt;
** gain control data&lt;br /&gt;
** tonal components&lt;br /&gt;
** quantized spectral coefficients&lt;br /&gt;
* inverse quantization of the tonal components and spectral coefficients&lt;br /&gt;
* Merge tonal components and other spectral coefficients together.&lt;br /&gt;
* Reconstruct the timedomain signal using inverse MDCT.&lt;br /&gt;
* gain compensation&lt;br /&gt;
* Apply the QMF synthesis filter to reconstruct the sound.&lt;br /&gt;
&lt;br /&gt;
== Tonal components ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 extracts the psychoacoustically important tonal components from the input signal spectra&lt;br /&gt;
and encodes them separate from the less important spectral data. A tone component is a group of&lt;br /&gt;
consecutive spectral coefficients, described with parameters such as location and with. This allows&lt;br /&gt;
finer quantization of such coefficients than a quantization within fixed subbands.&lt;br /&gt;
&lt;br /&gt;
== Joint-stereo mode ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3 uses joint-stereo coding at low bitrates (66 and 94 kbps) to achieve better compression.&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The ATRAC3 bitstream consists of so-called &amp;quot;Channel Sound Units&amp;quot;. In stereo mode there are&lt;br /&gt;
two such units. The structure of an unit is shown below:&lt;br /&gt;
&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Header                             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Gain compensation data             |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Tonal components                   |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
 | Other spectral coefficients        |&lt;br /&gt;
 --------------------------------------&lt;br /&gt;
&lt;br /&gt;
= Decoding Specification =&lt;br /&gt;
&lt;br /&gt;
== Bitstream parsing ==&lt;br /&gt;
&lt;br /&gt;
Parts is '''bold''' mean that a certain amount of bits are to be consumed from the bitstream.&lt;br /&gt;
&lt;br /&gt;
===Header===&lt;br /&gt;
&lt;br /&gt;
If not in the joint-stereo mode, this header should be interpreted as follows:&lt;br /&gt;
* '''id (6 bits)''' - should contain the value 0x28&lt;br /&gt;
* '''nBandsCoded (2 bits)''' - number of QMF bands were coded. The value of 0 indicates one coded band.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Gain compensation data===&lt;br /&gt;
&lt;br /&gt;
For each coded QMF band (see nBandsCoded above) the following data will be transmitted:&lt;br /&gt;
* '''numGainData (3 bits)''' - number of gain change points coded as level/location pairs. Value of 0 indicates no coded pairs. Each coded pair consists of the following fields:&lt;br /&gt;
* '''levcode (4 bits)''' - level code&lt;br /&gt;
* '''loccode (5 bits)''' - location code&lt;br /&gt;
This data is identical with the gain control tool from the MPEG AAC SSR profile that were also developed by [[Sony]]. Please refer to section &amp;quot;Gain compensation&amp;quot; below for a description how to interpret this data.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Tonal components===&lt;br /&gt;
&lt;br /&gt;
The presence of tonal components is indicated by the following field:&lt;br /&gt;
* '''numToneComp (5 bits)''' - Number of coded tonal components. The value of 0 indicates no coded tonal components.&lt;br /&gt;
* '''coding_mode_selector(2 bits)''' -- If this is equal to 2, return error. If this is equal to 3 then every component has it's own bit to select the coefficients coding mode. (VLC/CLC). If this is equal to 1 then all the components are CLC coded. If this is 0 all components are VLC coded. (coding_mode)&lt;br /&gt;
&lt;br /&gt;
* For each tonal component&lt;br /&gt;
** For each number of bands, get band flags&lt;br /&gt;
*** '''band_flags (1 bit)''' -- Flag per band in the Tonal Component to be processed&lt;br /&gt;
** '''coded_values (3 bits)''' -- amount of coded coefficients&lt;br /&gt;
** '''quant_step_index (3 bits)''' -- index into the quant step table, if it is less then/equal to 1 then return error&lt;br /&gt;
** if coding_mode_selector is 3&lt;br /&gt;
*** '''coding_mode (1 bit)''' -- get the bands coding mode (CLC/VLC)&lt;br /&gt;
&lt;br /&gt;
===Other spectral coefficients===&lt;br /&gt;
&lt;br /&gt;
The coefficients coded in this block are assumed not to be &amp;quot;tonal&amp;quot; (noise etc.) They are quantized and coded within fixed subbands. The ATRAC3 divides the whole MDCT spectrum (1024 points) into 32 subbands of unequal width (higher frequencies - wider bands). For each subband ATRAC3 will transmit a scalefactor index and VLC codes for each quantized spectral coefficients. The format of this this block is shown below:&lt;br /&gt;
* '''numSubbands (5 bits)''' - number of coded subbands. The value of 0 indicates no coded subbands.&lt;br /&gt;
* '''codingMode (1 bit)''' - value indicates the coding mode for ALL subbands:&lt;br /&gt;
&lt;br /&gt;
 0 - coefficients are coded using variable length codes (VLC)&lt;br /&gt;
 1 - coefficients are coded using constant length codes (CLC)&lt;br /&gt;
&lt;br /&gt;
Then follow the array of coding table indexes for each coded band:&lt;br /&gt;
* '''tblIndex (3 bits)''' - indicates the coding table used (VLC) or number of bits used (CLC). The value of &amp;quot;0&amp;quot; indicates &amp;quot;skipped&amp;quot; (not coded) subband.&lt;br /&gt;
Then follows the array of scalefactor indexes for each coded subband:&lt;br /&gt;
* '''sfIndex (6 bits)''' - indicates the index into scalefactor decoding table (see below).&lt;br /&gt;
Then follows the codes for each spectral coefficient in this subband. The VLC codes are shown below.&lt;br /&gt;
&lt;br /&gt;
== Scrambling ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files the bitstream is scrambled. To unscramble the stream, perform a XOR on every 32 bits in the frame. The hex value to XOR with is 0x537F6103.&lt;br /&gt;
&lt;br /&gt;
== Extra data format ==&lt;br /&gt;
&lt;br /&gt;
In [[RealMedia]] files the extra data is as follows (big-endian order):&lt;br /&gt;
&lt;br /&gt;
 INT32	id, always 4&lt;br /&gt;
 INT16	samples per frame, always 1024 * 2&lt;br /&gt;
 INT16	delay, not used but always 0x88E&lt;br /&gt;
 INT16	stereo coding mode, 2 - normal stereo, 0x12 - joint stereo&lt;br /&gt;
&lt;br /&gt;
The length of this data is always 10 bytes.&lt;br /&gt;
&lt;br /&gt;
== Transforms ==&lt;br /&gt;
&lt;br /&gt;
=== QMF ===&lt;br /&gt;
&lt;br /&gt;
Three stacked [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filters] are used to split the signal into 4 different frequency bands.&lt;br /&gt;
&lt;br /&gt;
* 0 to 2.75625 kHz (DC to ''f''/16)&lt;br /&gt;
* 2.75625 to 5.5125 kHz (''f''/16 to ''f''/8)&lt;br /&gt;
* 5.5125 to 11.025 kHz (''f''/8 to ''f''/4)&lt;br /&gt;
* 11.025 to 22.05 kHz (''f''/4 to ''f''/2)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== QMF window ====&lt;br /&gt;
&lt;br /&gt;
The coeffs used in the QMF filter.&lt;br /&gt;
&lt;br /&gt;
 float qmf_48tap_half[24] = {&lt;br /&gt;
   -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269,&lt;br /&gt;
   0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169,&lt;br /&gt;
   0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944,&lt;br /&gt;
   -0.000061169922, -0.01344162, 0.0024626821, 0.021736089,&lt;br /&gt;
   -0.007801671, -0.034090221, 0.01880949, 0.054326009,&lt;br /&gt;
   -0.043596379, -0.099384367, 0.13207909, 0.46424159&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
These coeffs need to be mirrored and scaled by 2.&lt;br /&gt;
&lt;br /&gt;
 for (i=0 ; i&amp;lt;24; i++) {&lt;br /&gt;
   s = qmf_48tap_half[i] * 2.0;&lt;br /&gt;
   qmf_window[i] = s;&lt;br /&gt;
   qmf_window[47 - i] = s;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== MLT ===&lt;br /&gt;
&lt;br /&gt;
The transform is a regular MDCT.&lt;br /&gt;
&lt;br /&gt;
==== Windows ====&lt;br /&gt;
&lt;br /&gt;
The overlapping window is not the same for encoding and decoding. Perfect reconstruction is ensured by the encoding and decoding windows having a inverse relation. Technical details can be found in H. Malvar's paper Fast algorithms for orthogonal modulated lapped transforms [http://research.microsoft.com/~malvar/papers/dfsp98.pdf]&lt;br /&gt;
&lt;br /&gt;
====== Encoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   we[i] = (sin(((i + 0.5) / 256 - 0.5) * PI) + 1.0) * 0.5;&lt;br /&gt;
 } &lt;br /&gt;
&lt;br /&gt;
====== Decoding ======&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; 256; i++) {&lt;br /&gt;
   wd[i] = we[i]/(we[i]^2 + we[255-i]^2)&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Huffman coding ==&lt;br /&gt;
&lt;br /&gt;
VLC coding is used to compress the tonal and spectral coefficients.&lt;br /&gt;
&lt;br /&gt;
=== Huffman tables ===&lt;br /&gt;
&lt;br /&gt;
 huffcode1[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits1[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode2[5] = {&lt;br /&gt;
   0x0,0x4,0x5,0x6,0x7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits2[5] = {&lt;br /&gt;
   1,3,3,3,3,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode3[7] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0xE,0xF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits3[7] = {&lt;br /&gt;
   1,3,3,4,4,4,4,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode4[9] = {&lt;br /&gt;
   0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits4[9] = {&lt;br /&gt;
   1,3,3,4,4,5,5,5,5,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode5[15] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits5[15] = {&lt;br /&gt;
   2,3,3,4,4,4,4,4,4,5,5,6,6,6,6,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode6[31] = {&lt;br /&gt;
   0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x8,0x9,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35,&lt;br /&gt;
   0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits6[31] = {&lt;br /&gt;
   3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffcode7[63] = {&lt;br /&gt;
   0x0,0x2,0x3,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28,&lt;br /&gt;
   0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C,&lt;br /&gt;
   0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2,&lt;br /&gt;
   0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,&lt;br /&gt;
 };&lt;br /&gt;
 &lt;br /&gt;
 huffbits7[63] = {&lt;br /&gt;
   3,4,4,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,&lt;br /&gt;
   7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=15037</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=15037"/>
		<updated>2014-06-22T20:34:35Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Coding techniques */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of ATRAC3 ATRAC3plus represents the next generation of the ATRAC codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Polyphase_quadrature_filter Polyphase Quadrature Filter] (further PQF) before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the PQF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] += [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=15036</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=15036"/>
		<updated>2014-06-22T20:32:49Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Coding techniques */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of ATRAC3 ATRAC3plus represents the next generation of the ATRAC codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Polyphase_quadrature_filter Polyphase Quadrature Filter] before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the QMF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] += [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=GoToMeeting_Codec&amp;diff=14576</id>
		<title>GoToMeeting Codec</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=GoToMeeting_Codec&amp;diff=14576"/>
		<updated>2013-05-07T08:02:48Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* ELS values */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCC: G2M2, G2M3, G2M4&lt;br /&gt;
* Company: [http://www.gotomeeting.com GoToMeeting (Citrix)]&lt;br /&gt;
* Samples: &lt;br /&gt;
** G2M2: http://samples.mplayerhq.hu/V-codecs/G2M2/&lt;br /&gt;
** G2M3: http://samples.mplayerhq.hu/V-codecs/G2M3/&lt;br /&gt;
** G2M4: http://samples.mplayerhq.hu/V-codecs/G2M4/&lt;br /&gt;
&lt;br /&gt;
This is a codec used to save recordings in GoToMeeting.  The codec also calls itself GoToWebinar (see [http://www.gotowebinar.com/ http://www.gotowebinar.com/]).&lt;br /&gt;
&lt;br /&gt;
Win32 binary decoder available here: [http://www.gotomeeting.com/codec http://www.gotomeeting.com/codec]&lt;br /&gt;
&lt;br /&gt;
According to samples, all G2M video frames begin with the characters 'G2M[2-4]', followed by a series of chunks. Each chunk has the following layout:&lt;br /&gt;
&lt;br /&gt;
 bytes 0-3    length of chunk payload, not including this length field&lt;br /&gt;
 byte 4       type of chunk&lt;br /&gt;
 bytes 5..    remainder of payload, format unknown&lt;br /&gt;
&lt;br /&gt;
Supported chunk types are 0xC8-0xCD.&lt;br /&gt;
&lt;br /&gt;
It appears that the minimum size for a G2M frame (possibly a no-change frame) is 14 bytes. This includes the 4 signature bytes, a 4-byte length indicating a chunk length of 6, and a 6-byte payload of type 0xCA followed by 5 more bytes.&lt;br /&gt;
&lt;br /&gt;
G2M3 is the same as G2M2. G2M4 introduces new compression method but the structure remains the same.&lt;br /&gt;
&lt;br /&gt;
In general frame is divided into the number of tiles and each tile is coded separately. Usual tile size is 192x128 pixels&lt;br /&gt;
&lt;br /&gt;
== Frame structure ==&lt;br /&gt;
&lt;br /&gt;
=== Chunk C8 ===&lt;br /&gt;
&lt;br /&gt;
Display information.&lt;br /&gt;
&lt;br /&gt;
Chunk contents (all values are big-endian):&lt;br /&gt;
&lt;br /&gt;
   4 bytes  image width&lt;br /&gt;
   4 bytes  image height&lt;br /&gt;
   4 bytes  compression mode (should be 2 or 3)&lt;br /&gt;
   4 bytes  tile width&lt;br /&gt;
   4 bytes  tile height&lt;br /&gt;
   1 byte   colour depth (4, 8, 16, 24 or 32)&lt;br /&gt;
   for 4/8bpp there is a palette in standard RGBTUPLE format&lt;br /&gt;
   for 16-32bpp there are four bitmasks for each field&lt;br /&gt;
&lt;br /&gt;
=== Chunk C9 ===&lt;br /&gt;
&lt;br /&gt;
Image update.&lt;br /&gt;
&lt;br /&gt;
  1 byte tile position in row&lt;br /&gt;
  1 byte tile position in column&lt;br /&gt;
  ... compressed data&lt;br /&gt;
&lt;br /&gt;
=== Chunk CA ===&lt;br /&gt;
&lt;br /&gt;
Mouse cursor position.&lt;br /&gt;
&lt;br /&gt;
  2 bytes cursor position X&lt;br /&gt;
  2 bytes cursor position Y&lt;br /&gt;
  1 byte  seems to be always 1&lt;br /&gt;
&lt;br /&gt;
=== Chunk CB ===&lt;br /&gt;
&lt;br /&gt;
Mouse cursor shape:&lt;br /&gt;
&lt;br /&gt;
  4 bytes data size&lt;br /&gt;
  1 byte  width&lt;br /&gt;
  1 byte  height&lt;br /&gt;
  1 byte  hotspot x&lt;br /&gt;
  1 byte  hotspot y&lt;br /&gt;
  ...     cursor bitmask and its inverse (in M$ format)&lt;br /&gt;
&lt;br /&gt;
=== Chunk CC ===&lt;br /&gt;
&lt;br /&gt;
Maybe some resync chunk, it's supposed to contain only 4-byte value equal to 2000.&lt;br /&gt;
&lt;br /&gt;
=== Chunk CD ===&lt;br /&gt;
&lt;br /&gt;
One dword, something to do with time.&lt;br /&gt;
&lt;br /&gt;
== Video compression methods ==&lt;br /&gt;
&lt;br /&gt;
=== Compression method 1 (ELS image) ===&lt;br /&gt;
&lt;br /&gt;
Vanilla augmented ELS coder is used ([http://ieeexplore.ieee.org/xpls/abs_all.jsp?arnumber=582144 The ELS-coder: a rapid entropy coder]) with 36 jots per byte.&lt;br /&gt;
&lt;br /&gt;
==== ELS values ====&lt;br /&gt;
&lt;br /&gt;
Unsigned values are coded using Exponential Golomb notation:&lt;br /&gt;
&lt;br /&gt;
  unary prefix + stop bit + remainder, where number of bits in the prefix = number of bits in the remainder&lt;br /&gt;
&lt;br /&gt;
The unary prefix is coded as n -1 zero bits followed by a one bit. E.g. number 5 will be coded as &amp;lt;code&amp;gt;00 1 10&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Here is the decoding algorithm:&lt;br /&gt;
&lt;br /&gt;
  count number of bits in the prefix by reading bits from the arithmetic ELS decoder until a &amp;quot;1&amp;quot; is encountered&lt;br /&gt;
  n = number of zero bits in the prefix, i.e &amp;quot;001&amp;quot; ==&amp;gt; n = 2&lt;br /&gt;
  read the remainder r as plain binary number of n bits: &amp;quot;10&amp;quot; ==&amp;gt; 2&lt;br /&gt;
  value = 2&amp;lt;sup&amp;gt;n&amp;lt;/sup&amp;gt; - 1 + r = 2&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; - 1 + 2 = 5&lt;br /&gt;
&lt;br /&gt;
Signed values are coded as unsigned ones where the LSB indicates the sign:&lt;br /&gt;
&lt;br /&gt;
  if (val &amp;amp; 1)&lt;br /&gt;
    val = - ((val + 1) &amp;gt;&amp;gt; 1);&lt;br /&gt;
  else&lt;br /&gt;
    val = val &amp;gt;&amp;gt; 1;&lt;br /&gt;
&lt;br /&gt;
To make compression better every decoded bit uses a context-depended state, so every bit is decoded this way:&lt;br /&gt;
&lt;br /&gt;
  bit = els_decode_bit(ctx, &amp;amp;ctx-&amp;gt;current_state-&amp;gt;rung);&lt;br /&gt;
  if (bit) {&lt;br /&gt;
    if (!ctx-&amp;gt;current_state-&amp;gt;next1) {&lt;br /&gt;
        ctx-&amp;gt;current_state-&amp;gt;next1 = new State();&lt;br /&gt;
        ctx-&amp;gt;current_state-&amp;gt;next1-&amp;gt;rung = 0;&lt;br /&gt;
    }&lt;br /&gt;
    ctx-&amp;gt;current_state = ctx-&amp;gt;current_state-&amp;gt;next1;&lt;br /&gt;
  } else {&lt;br /&gt;
    if (!ctx-&amp;gt;current_state-&amp;gt;next0) {&lt;br /&gt;
        ctx-&amp;gt;current_state-&amp;gt;next0 = new State();&lt;br /&gt;
        ctx-&amp;gt;current_state-&amp;gt;next0-&amp;gt;rung = 0;&lt;br /&gt;
    }&lt;br /&gt;
    ctx-&amp;gt;current_state = ctx-&amp;gt;current_state-&amp;gt;next0;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Single pixel coding ====&lt;br /&gt;
&lt;br /&gt;
Decoding single pixel is performed like this:&lt;br /&gt;
&lt;br /&gt;
  if (!x &amp;amp;&amp;amp; !y) {&lt;br /&gt;
    R = decode_vlc();&lt;br /&gt;
    G = decode_vlc();&lt;br /&gt;
    B = decode_vlc();&lt;br /&gt;
  } else if (!x || !y) {&lt;br /&gt;
    if (!y) {&lt;br /&gt;
      pR = rgb[x - 1, y].R;&lt;br /&gt;
      pG = rgb[x - 1, y].G;&lt;br /&gt;
      pB = rgb[x - 1, y].B;&lt;br /&gt;
    } else {&lt;br /&gt;
      pR = rgb[x, y - 1].R;&lt;br /&gt;
      pG = rgb[x, y - 1].G;&lt;br /&gt;
      pB = rgb[x, y - 1].B;&lt;br /&gt;
    }&lt;br /&gt;
    R = pR + decode_vlc_signed();&lt;br /&gt;
    G = pG + decode_vlc_signed();&lt;br /&gt;
    B = pB + decode_vlc_signed();&lt;br /&gt;
  } else {&lt;br /&gt;
    G = decode_pred(rgb[x - 1, y].G, rgb[x, y - 1].G, rgb[x - 1, y - 1].G);&lt;br /&gt;
    R = G + decode_pred(rgb[x - 1, y    ].R - rgb[x - 1, y    ].G,&lt;br /&gt;
                        rgb[x,     y - 1].R - rgb[x,     y - 1].G,&lt;br /&gt;
                        rgb[x - 1, y - 1].R - rgb[x - 1, y - 1].G);&lt;br /&gt;
    B = G + decode_pred(rgb[x - 1, y    ].B - rgb[x - 1, y    ].G,&lt;br /&gt;
                        rgb[x,     y - 1].B - rgb[x,     y - 1].G,&lt;br /&gt;
                        rgb[x - 1, y - 1].B - rgb[x - 1, y - 1].G);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;code&amp;gt;decode_pred(A, B, C)&amp;lt;/code&amp;gt; looks like this:&lt;br /&gt;
&lt;br /&gt;
  diff = decode_vlc_signed();&lt;br /&gt;
  if (B &amp;lt; max(A, C)) {&lt;br /&gt;
    if (B &amp;gt; min(A, C)) {&lt;br /&gt;
      return A - B + C - diff;&lt;br /&gt;
    } else {&lt;br /&gt;
      return max(A, C) - diff;&lt;br /&gt;
    }&lt;br /&gt;
  } else {&lt;br /&gt;
    return min(A, C) - diff;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Image decoding ====&lt;br /&gt;
&lt;br /&gt;
Image decoding is context-dependent and always tries to check some flags and retrieve pixel value from cache instead of decoding it directly.&lt;br /&gt;
&lt;br /&gt;
Overall decoding scheme:&lt;br /&gt;
&lt;br /&gt;
  for (y = 0; y &amp;lt; height; y++) {&lt;br /&gt;
   x = 0;&lt;br /&gt;
   while (x &amp;lt; width) {&lt;br /&gt;
    if (x &amp;gt; 1 &amp;amp;&amp;amp; y &amp;gt; 0 &amp;amp;&amp;amp;&lt;br /&gt;
      rgb[x - 1, y] != rgb[x - 2, y] &amp;amp;&amp;amp;&lt;br /&gt;
      rgb[x - 1, y] != rgb[x,     y - 1] &amp;amp;&amp;amp;&lt;br /&gt;
      rgb[x - 1, y] != rgb[x - 1, y - 1] &amp;amp;&amp;amp;&lt;br /&gt;
      rgb[x - 1, y] != rgb[x - 2, y - 1] &amp;amp;&amp;amp;&lt;br /&gt;
      !pixel_in_cache(rgb[x - 1, y])) {&lt;br /&gt;
     rgb[x, y] = decode_pixel_with_prediction(x, y);&lt;br /&gt;
     x++;&lt;br /&gt;
     continue;&lt;br /&gt;
    }&lt;br /&gt;
    decode_run(x, y, &amp;amp;run_length, &amp;amp;pix);&lt;br /&gt;
    if (run_length &amp;gt; 0) {&lt;br /&gt;
     // pixel value may get changed here&lt;br /&gt;
     reuse_top_neighbours_if_possible(x, y, run_length, &amp;amp;pix);&lt;br /&gt;
     while (run_length--) {&lt;br /&gt;
      rgb[x, y] = pix;&lt;br /&gt;
      x++;&lt;br /&gt;
     }&lt;br /&gt;
    } else if (x &amp;gt; 0 &amp;amp;&amp;amp; decode_from_list(rgb[x - 1, y], &amp;amp;pix)) {&lt;br /&gt;
     rgb[x, y] = pix;&lt;br /&gt;
     x++;&lt;br /&gt;
    } else {&lt;br /&gt;
     rgb[x, y] = decode_pixel_with_prediction(x, y);&lt;br /&gt;
     if (x)&lt;br /&gt;
       add_to_list(pixel_list[rgb[x - 1, y]], rgb[x, y]);&lt;br /&gt;
     x++;&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Run decoding:&lt;br /&gt;
&lt;br /&gt;
  run_length = 0;&lt;br /&gt;
  &lt;br /&gt;
  if (x &amp;gt; 1 &amp;amp;&amp;amp; x &amp;lt; width - 1 &amp;amp;&amp;amp; y &amp;gt; 1) {&lt;br /&gt;
    L   = rgb[x - 1, y];&lt;br /&gt;
    LL  = rgb[x - 2, y];&lt;br /&gt;
    TR  = rgb[x + 1, y - 1];&lt;br /&gt;
    T   = rgb[x,     y - 1];&lt;br /&gt;
    TL  = rgb[x - 1, y - 1];&lt;br /&gt;
    TLL = rgb[x - 2, y - 1];&lt;br /&gt;
    TTR = rgb[x + 1, y - 2];&lt;br /&gt;
    TT  = rgb[x,     y - 2];&lt;br /&gt;
    TTL = rgb[x - 1, y - 2];&lt;br /&gt;
    &lt;br /&gt;
    if (x != ctx-&amp;gt;last_run_end) {&lt;br /&gt;
      idx = (TTL != TL) &amp;lt;&amp;lt; 0|&lt;br /&gt;
            (TT  != T)  &amp;lt;&amp;lt; 1 |&lt;br /&gt;
            (TTR != TR) &amp;lt;&amp;lt; 2 |&lt;br /&gt;
            (TLL != TL) &amp;lt;&amp;lt; 3 |&lt;br /&gt;
            (TL  != T)  &amp;lt;&amp;lt; 4 |&lt;br /&gt;
            (TR  != T)  &amp;lt;&amp;lt; 5 |&lt;br /&gt;
            (TL  != L)  &amp;lt;&amp;lt; 6 |&lt;br /&gt;
            (LL  != L)  &amp;lt;&amp;lt; 7;&lt;br /&gt;
      flag = els_decode_bit(ctx-&amp;gt;left_context[idx]);&lt;br /&gt;
    } else {&lt;br /&gt;
      flag = 1;&lt;br /&gt;
    }&lt;br /&gt;
    if (flag)&lt;br /&gt;
      add_to_cache(L);&lt;br /&gt;
    else&lt;br /&gt;
      pixel_val = L;&lt;br /&gt;
    for (;;) {&lt;br /&gt;
      if (flag) {&lt;br /&gt;
        // not perfect&lt;br /&gt;
        idx = (TTL != TL) &amp;lt;&amp;lt; 0|&lt;br /&gt;
              (TT  != T)  &amp;lt;&amp;lt; 1 |&lt;br /&gt;
              (TTR != TR) &amp;lt;&amp;lt; 2 |&lt;br /&gt;
              (TLL != TL) &amp;lt;&amp;lt; 3 |&lt;br /&gt;
              (TL  != T)  &amp;lt;&amp;lt; 4 |&lt;br /&gt;
              (TR  != T)  &amp;lt;&amp;lt; 5 |&lt;br /&gt;
              (TL  != L)  &amp;lt;&amp;lt; 6 |&lt;br /&gt;
              (LL  != L)  &amp;lt;&amp;lt; 7;&lt;br /&gt;
        if (els_decode_bit(ctx-&amp;gt;top_context[idx])) {&lt;br /&gt;
          pixel_val = T;&lt;br /&gt;
          flag2 = 0;&lt;br /&gt;
        } else {&lt;br /&gt;
          if (!pixel_in_cache(T))&lt;br /&gt;
            add_to_cache(T);&lt;br /&gt;
          flag2 = 1;&lt;br /&gt;
        }&lt;br /&gt;
      } else {&lt;br /&gt;
        flag2 = (pixel_val != T);&lt;br /&gt;
      }&lt;br /&gt;
      x++;&lt;br /&gt;
      if (x &amp;gt;= width - 1)&lt;br /&gt;
        break;&lt;br /&gt;
      update L, LL, LR, T, TL, TLL, TTR, TT and TTL;&lt;br /&gt;
      if (!flag2 &amp;amp;&amp;amp; TL == T &amp;amp;&amp;amp; T == TR) {&lt;br /&gt;
        if (!decode_run_length(&amp;amp;x))&lt;br /&gt;
          break;&lt;br /&gt;
        update L, LL, LR, T, TL, TLL, TTR, TT and TTL;&lt;br /&gt;
      }&lt;br /&gt;
      idx = (TTL != TL) &amp;lt;&amp;lt; 0|&lt;br /&gt;
            (TT  != T)  &amp;lt;&amp;lt; 1 |&lt;br /&gt;
            (TTR != TR) &amp;lt;&amp;lt; 2 |&lt;br /&gt;
            (TLL != TL) &amp;lt;&amp;lt; 3 |&lt;br /&gt;
            (TL  != T)  &amp;lt;&amp;lt; 4 |&lt;br /&gt;
            (TR  != T)  &amp;lt;&amp;lt; 5 |&lt;br /&gt;
            (TL  != L)  &amp;lt;&amp;lt; 6 |&lt;br /&gt;
            (LL  != L)  &amp;lt;&amp;lt; 7;&lt;br /&gt;
      if (els_decode_bit(ctx-&amp;gt;left_context[idx]))&lt;br /&gt;
        break;&lt;br /&gt;
    }&lt;br /&gt;
    ctx-&amp;gt;last_run_end = x;&lt;br /&gt;
    run_length = x - old_x;&lt;br /&gt;
    return !flag;&lt;br /&gt;
  } &lt;br /&gt;
  if (x &amp;gt; 0) {&lt;br /&gt;
    if (!els_decode_bit(ctx-&amp;gt;left_flag_ctx)) {&lt;br /&gt;
      pixel_val = rgb[x - 1, y];&lt;br /&gt;
      run_length = 1;&lt;br /&gt;
    } else {&lt;br /&gt;
      add_to_cache(rgb[x - 1, y]);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  if (y &amp;gt; 0) {&lt;br /&gt;
    top_pix = rgb[x, y - 1];&lt;br /&gt;
    if (empty_pixel_cache() || first_pixel_in_cache() != top_pix) {&lt;br /&gt;
      if (!els_decode_bit(ctx-&amp;gt;top_flag_ctx)) {&lt;br /&gt;
        pixel_val = top_pix;&lt;br /&gt;
        run_length = 1;&lt;br /&gt;
      } else {&lt;br /&gt;
        add_to_cache(top_pix);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Decoding run length (essentially the run on the above line is used as a reference and is either returned immediately or a value not greater than it is decoded):&lt;br /&gt;
&lt;br /&gt;
  pos_R  = x + 1;&lt;br /&gt;
  pos_RR = x + 2;&lt;br /&gt;
  while (pos_RR &amp;lt; width &amp;amp;&amp;amp; rgb[pos_RR, y - 1] == rgb[pos_R, y]) {&lt;br /&gt;
    pos_R++;&lt;br /&gt;
    pos_RR++;&lt;br /&gt;
  }&lt;br /&gt;
  bits = log2_int(pos_R - x);&lt;br /&gt;
  if (els_decode_bit(ctx-&amp;gt;dist_context[bits]))&lt;br /&gt;
    return pos_R - x;&lt;br /&gt;
  flag = 0;&lt;br /&gt;
  bit = 1 &amp;lt;&amp;lt; (bits - 1);&lt;br /&gt;
  mask = 0;&lt;br /&gt;
  run_length = 0;&lt;br /&gt;
  while (bits &amp;gt;= 0) {&lt;br /&gt;
    if (((run_length &amp;amp; mask) | bit) &amp;lt; pos_R - x) {&lt;br /&gt;
      if (els_decode_bit(flag ? ctx-&amp;gt;one_context : ctx-&amp;gt;length_context[bits])) {&lt;br /&gt;
        flag = 1;&lt;br /&gt;
        run_length |= 1 &amp;lt;&amp;lt; bits;&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
    mask |= bit;&lt;br /&gt;
    bit &amp;gt;&amp;gt;= 1;&lt;br /&gt;
    bits--;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Reuse neighbours if possible:&lt;br /&gt;
&lt;br /&gt;
  if (x &amp;gt; 0 &amp;amp;&amp;amp; y &amp;gt; 0) {&lt;br /&gt;
    TL = rgb[x - 1, y - 1];&lt;br /&gt;
    L  = rgb[x - 1, y];&lt;br /&gt;
    T  = rgb[x,     y - 1];&lt;br /&gt;
    if (TL != L &amp;amp;&amp;amp; TL != T &amp;amp;&amp;amp; !pixel_is_in_cache(TL)) {&lt;br /&gt;
      if (els_decode_bit(ctx-&amp;gt;TL_context[TL])) {&lt;br /&gt;
        modify current pixel value to be TL&lt;br /&gt;
        return&lt;br /&gt;
      }&lt;br /&gt;
      add_to_cache(TL);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  if (x + run_size &amp;lt; width - 1 &amp;amp;&amp;amp; y &amp;gt; 0) {&lt;br /&gt;
    TR = rgb[x + 1, y - 1];&lt;br /&gt;
    T  = rgb[x,     y - 1];&lt;br /&gt;
    if (T != TR &amp;amp;&amp;amp; !pixel_is_in_cache(TR)) {&lt;br /&gt;
      if (els_decode_bit(ctx-&amp;gt;TR_context[TR])) {&lt;br /&gt;
        modify current pixel value to be TR&lt;br /&gt;
        return&lt;br /&gt;
      }&lt;br /&gt;
      add_to_cache(TR);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Decoding from list:&lt;br /&gt;
&lt;br /&gt;
  list = get_list_for_pixel(rgb[x - 1, y]);&lt;br /&gt;
  while (list) {&lt;br /&gt;
    if (!pixel_is_in_cache(list-&amp;gt;pix_val)) {&lt;br /&gt;
      if (els_decode_bit(list-&amp;gt;rung)) {&lt;br /&gt;
        output_pixel_value = list-&amp;gt;pix_val;&lt;br /&gt;
        remove current entry from the list;&lt;br /&gt;
        return success;&lt;br /&gt;
      }&lt;br /&gt;
      add_to_cache(list-&amp;gt;pix_val);&lt;br /&gt;
    }&lt;br /&gt;
    list = list-&amp;gt;next;&lt;br /&gt;
  }&lt;br /&gt;
  return fail;&lt;br /&gt;
&lt;br /&gt;
=== Compression method 2 (ELS image + JPEG) ===&lt;br /&gt;
&lt;br /&gt;
This enhances compression method 1 by separating image into two pictures - the one with sharp details and the one with smooth details. The former is compressed as in compression method 1, the latter is coded as JPEG image. One of the layers can be absent in the tile.&lt;br /&gt;
&lt;br /&gt;
Overall coding is quite simple: ELS layer is coded as first 1x1 image containing value that will be used as a transparent color (i.e. the value that should be replaced with JPEG data) and the whole picture.&lt;br /&gt;
&lt;br /&gt;
JPEG data consists of raw scan data for the baseline JPEG with the standard quantisation matrix and VLCs. Only the macroblocks for the ELS image blocks with transparency are coded (or the whole image when ELS data is not present).&lt;br /&gt;
&lt;br /&gt;
  ELS-coded data size&lt;br /&gt;
  ELS-coded data for transparency pixel&lt;br /&gt;
  ELS-coded data for whole image&lt;br /&gt;
  JPEG data&lt;br /&gt;
&lt;br /&gt;
ELS-coded data size:&lt;br /&gt;
&lt;br /&gt;
  0xxxxxxx&lt;br /&gt;
  10xxxxxx xxxxxxxx&lt;br /&gt;
  110xxxxx xxxxxxxx xxxxxxxx&lt;br /&gt;
  111xxxxx xxxxxxxx xxxxxxxx xxxxxxxx&lt;br /&gt;
&lt;br /&gt;
=== Compression method 3 (deflated image + JPEG) ===&lt;br /&gt;
&lt;br /&gt;
This method resembles compression method 2 except that ELS image is replaced with simple deflated image and macroblock map (what blocks in image to code) is stored explicitly too.&lt;br /&gt;
&lt;br /&gt;
  compression subtype (1 byte)&lt;br /&gt;
  transparent pixel value (3 bytes)&lt;br /&gt;
  number of palette entries minus one (1 byte)&lt;br /&gt;
  palette (3-byte entries)&lt;br /&gt;
  deflated data size (2 bytes big-endian)&lt;br /&gt;
  deflated data&lt;br /&gt;
  JPEG macroblock map&lt;br /&gt;
  JPEG data&lt;br /&gt;
&lt;br /&gt;
Compression subtype (top 3 bits) tells what exact parts are present and how they should be decoded.&lt;br /&gt;
&lt;br /&gt;
* 0 - fill block with the following pixel value&lt;br /&gt;
* 1 - decode JPEG only, only JPEG data is present&lt;br /&gt;
* 2 - decode only deflated data, no transparent pixel or JPEG data present&lt;br /&gt;
* 3 - all features are present&lt;br /&gt;
&lt;br /&gt;
Deflated image data describes palettised mask image (or &amp;quot;synthetic layer&amp;quot;). The image is also compressed further by using the minimal amount of bits for palette indices (e.g. only 2 bits for 3- or 4-colour images) and every line can be skipped instead of coding.&lt;br /&gt;
&lt;br /&gt;
  for (y = 0; y &amp;lt; height; y++, dst += stride) {&lt;br /&gt;
    if (get_bits(8)) // 'line coded' flag&lt;br /&gt;
        continue;&lt;br /&gt;
    for (x = 0; x &amp;lt; width; x++)&lt;br /&gt;
        dst[x] = get_bit(bits_per_index);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
JPEG macroblock map consists of byte with the number of macroblocks coded minus one and an array of flags packed into bytes LSB first. Zero bit means that the next macroblock should be skipped, set bit means that the next decoded macroblock should be put here. This array continues until all coded macroblocks are flagges. Right after that information an actual JPEG data is stored.&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Incomplete Video Codecs]]&lt;br /&gt;
[[Category:Formats missing in FFmpeg]]&lt;br /&gt;
[[Category:Screen Capture Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13635</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13635"/>
		<updated>2011-09-21T01:55:47Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; Richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = chrominance factor (picture format):&lt;br /&gt;
** &amp;quot;2&amp;quot; - 422&lt;br /&gt;
** &amp;quot;3&amp;quot; - 444&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | primaries || align=&amp;quot;center&amp;quot; |  || Color primaries of the coded image (see the description of the 'nclc' extension by Apple).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | transf_func || align=&amp;quot;center&amp;quot; |  || Transfer function of the coded image (see the description of the 'nclc' extension by Apple).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | src_pix_fmt ||&lt;br /&gt;
* 0 - unknown&lt;br /&gt;
* 1 - '2vuy' (8-bit 4:2:2)&lt;br /&gt;
* 2 - 'v210' (10-bit 4:2:2)&lt;br /&gt;
* 3 - 'v216' (10,12,14,16-bit 4:2:2)&lt;br /&gt;
* 4 - 'r408' (8-bit 4:4:4:4 with alpha)&lt;br /&gt;
* 5 - 'v408' (8-bit 4:4:4:4 with alpha and super black)&lt;br /&gt;
* 6 - 'r4fl' (32-bit floating-point 4:4:4:4)&lt;br /&gt;
* 7 -   0x20 (8-bit RGB)&lt;br /&gt;
* 8 - 'BGRA' (8-bit RGB with alpha)&lt;br /&gt;
* 9 - 'n302' seems to be undocumented&lt;br /&gt;
* 10 - 'b64a' (16-bit ARGB)&lt;br /&gt;
* 11 - 'R10k' (AJA 10-bit RGB)&lt;br /&gt;
* 12 - 'l302' seems to be undocumented&lt;br /&gt;
* 13-15 invalid&lt;br /&gt;
|| Indicates source pixel format.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | alpha_info || align=&amp;quot;center&amp;quot; |  || Used in combination with alpha channel coding.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Picture layout ===&lt;br /&gt;
&lt;br /&gt;
Each picture has the following layout:&lt;br /&gt;
&lt;br /&gt;
            Picture header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
           Slice index table&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Slices data&lt;br /&gt;
&lt;br /&gt;
The picture header contains two important parameters: width and height factors of a slice. Therefore, those tell the decoder how the coded picture is subdivided.&lt;br /&gt;
&lt;br /&gt;
Slice index table consists of 16bit entries - one for each slice - giving the length of the data for each slice. Thus, it permits independent processing of the slices in means of multi-threading.&lt;br /&gt;
&lt;br /&gt;
Slices data array contains actual encoded macroblock data.&lt;br /&gt;
&lt;br /&gt;
==== Picture header ====&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | slice_hdr_size || size of this header in bits. Must be at least 48 bits (6 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | scale_factor || scale factor for scaling the quantization matrices (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | luma_data_size || size of the luma bitstream in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | u_data_size || size of the chroma U bitstream in bytes.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Although, the length of the chroma V data is not indcated in the slice header, it can be easily calculated as follows:&lt;br /&gt;
&lt;br /&gt;
v_data_size = slice_data_size from slice index table - luma_data_size - u_data_size - (slice_hdr_size / 8);&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13628</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13628"/>
		<updated>2011-09-19T01:27:10Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Slice header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; Richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = chrominance factor (picture format):&lt;br /&gt;
** &amp;quot;2&amp;quot; - 422&lt;br /&gt;
** &amp;quot;3&amp;quot; - 444&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture layout ===&lt;br /&gt;
&lt;br /&gt;
Each picture has the following layout:&lt;br /&gt;
&lt;br /&gt;
            Picture header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
           Slice index table&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Slices data&lt;br /&gt;
&lt;br /&gt;
The picture header contains two important parameters: width and height factors of a slice. Therefore, those tell the decoder how the coded picture is subdivided.&lt;br /&gt;
&lt;br /&gt;
Slice index table consists of 16bit entries - one for each slice - giving the length of the data for each slice. Thus, it permits independent processing of the slices in means of multi-threading.&lt;br /&gt;
&lt;br /&gt;
Slices data array contains actual encoded macroblock data.&lt;br /&gt;
&lt;br /&gt;
==== Picture header ====&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | slice_hdr_size || size of this header in bits. Must be at least 48 bits (6 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | scale_factor || scale factor for scaling the quantization matrices (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | luma_data_size || size of the luma bitstream in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bits || align=&amp;quot;center&amp;quot; | u_data_size || size of the chroma U bitstream in bytes.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Although, the length of the chroma V data is not indcated in the slice header, it can be easily calculated as follows:&lt;br /&gt;
&lt;br /&gt;
v_data_size = slice_data_size from slice index table - luma_data_size - u_data_size - (slice_hdr_size / 8);&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13627</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13627"/>
		<updated>2011-09-19T01:26:54Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Slice header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; Richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = chrominance factor (picture format):&lt;br /&gt;
** &amp;quot;2&amp;quot; - 422&lt;br /&gt;
** &amp;quot;3&amp;quot; - 444&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture layout ===&lt;br /&gt;
&lt;br /&gt;
Each picture has the following layout:&lt;br /&gt;
&lt;br /&gt;
            Picture header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
           Slice index table&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Slices data&lt;br /&gt;
&lt;br /&gt;
The picture header contains two important parameters: width and height factors of a slice. Therefore, those tell the decoder how the coded picture is subdivided.&lt;br /&gt;
&lt;br /&gt;
Slice index table consists of 16bit entries - one for each slice - giving the length of the data for each slice. Thus, it permits independent processing of the slices in means of multi-threading.&lt;br /&gt;
&lt;br /&gt;
Slices data array contains actual encoded macroblock data.&lt;br /&gt;
&lt;br /&gt;
==== Picture header ====&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
  bits 0-2 unused?&lt;br /&gt;
  bits 3-7 header size&lt;br /&gt;
  1 byte   quantiser scale (1-224)&lt;br /&gt;
  2 bytes  luma data size&lt;br /&gt;
  2 bytes  U data size&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | slice_hdr_size || size of this header in bits. Must be at least 48 bits (6 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | scale_factor || scale factor for scaling the quantization matrices (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | luma_data_size || size of the luma bitstream in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bits || align=&amp;quot;center&amp;quot; | u_data_size || size of the chroma U bitstream in bytes.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Although, the length of the chroma V data is not indcated in the slice header, it can be easily calculated as follows:&lt;br /&gt;
&lt;br /&gt;
v_data_size = slice_data_size from slice index table - luma_data_size - u_data_size - (slice_hdr_size / 8);&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13626</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13626"/>
		<updated>2011-09-19T01:19:02Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Field/Picture header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; Richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = chrominance factor (picture format):&lt;br /&gt;
** &amp;quot;2&amp;quot; - 422&lt;br /&gt;
** &amp;quot;3&amp;quot; - 444&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Picture layout ===&lt;br /&gt;
&lt;br /&gt;
Each picture has the following layout:&lt;br /&gt;
&lt;br /&gt;
            Picture header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
           Slice index table&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Slices data&lt;br /&gt;
&lt;br /&gt;
The picture header contains two important parameters: width and height factors of a slice. Therefore, those tell the decoder how the coded picture is subdivided.&lt;br /&gt;
&lt;br /&gt;
Slice index table consists of 16bit entries - one for each slice - giving the length of the data for each slice. Thus, it permits independent processing of the slices in means of multi-threading.&lt;br /&gt;
&lt;br /&gt;
Slices data array contains actual encoded macroblock data.&lt;br /&gt;
&lt;br /&gt;
==== Picture header ====&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
  bits 0-2 unused?&lt;br /&gt;
  bits 3-7 header size&lt;br /&gt;
  1 byte   quantiser scale (1-224)&lt;br /&gt;
  2 bytes  luma data size&lt;br /&gt;
  2 bytes  U data size&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13625</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13625"/>
		<updated>2011-09-19T00:55:56Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; Richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = chrominance factor (picture format):&lt;br /&gt;
** &amp;quot;2&amp;quot; - 422&lt;br /&gt;
** &amp;quot;3&amp;quot; - 444&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Field/Picture header ===&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
  bits 0-2 unused?&lt;br /&gt;
  bits 3-7 header size&lt;br /&gt;
  1 byte   quantiser scale (1-224)&lt;br /&gt;
  2 bytes  luma data size&lt;br /&gt;
  2 bytes  U data size&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13624</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13624"/>
		<updated>2011-09-19T00:50:49Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; Richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Field/Picture header ===&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
  bits 0-2 unused?&lt;br /&gt;
  bits 3-7 header size&lt;br /&gt;
  1 byte   quantiser scale (1-224)&lt;br /&gt;
  2 bytes  luma data size&lt;br /&gt;
  2 bytes  U data size&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13623</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13623"/>
		<updated>2011-09-19T00:49:28Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | creatorID ||&lt;br /&gt;
* 'apl0' -&amp;gt; Apple Inc.&lt;br /&gt;
* 'arri' -&amp;gt; Arnold &amp;amp; richter Cine Technik (A&amp;amp;R)&lt;br /&gt;
* 'aja0' -&amp;gt; AJA Kona Hardware&lt;br /&gt;
|| FOURCC of the creator of the present stream. Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Field/Picture header ===&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
  bits 0-2 unused?&lt;br /&gt;
  bits 3-7 header size&lt;br /&gt;
  1 byte   quantiser scale (1-224)&lt;br /&gt;
  2 bytes  luma data size&lt;br /&gt;
  2 bytes  U data size&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13622</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13622"/>
		<updated>2011-09-19T00:43:51Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Field/Picture header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://web.archive.org/web/20101205002240/http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-length coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [http://support.apple.com/kb/DL1396 AppleProResDecoder.component] || align=&amp;quot;center&amp;quot; | 3.0.0 || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
 &lt;br /&gt;
=== Field/Picture header ===&lt;br /&gt;
&lt;br /&gt;
This header is present for every picture (field).&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | pic_hdr_size || size of this header in bits. Must be at least 64 bits (8 bytes) long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | pic_data_size || size of the picture data in bytes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | total_slices || total number of slices in the picture.&lt;br /&gt;
At the same times it indicates the number of entries in the slice table.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_width_factor || slice width = 2 ^ slice_width_factor. Supported slice sizes are therefore 8, 4, 2 and 1 macroblocks wide.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bits || align=&amp;quot;center&amp;quot; | slice_height_factor || Ideally slice height = 2 ^ slice_height_factor but in all known decoders only the value of &amp;quot;0&amp;quot; for that factor is allowed.&lt;br /&gt;
Thus, only one slice height = 1 macroblock is supported.&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Slice coding ===&lt;br /&gt;
&lt;br /&gt;
==== Slice header ====&lt;br /&gt;
&lt;br /&gt;
  bits 0-2 unused?&lt;br /&gt;
  bits 3-7 header size&lt;br /&gt;
  1 byte   quantiser scale (1-224)&lt;br /&gt;
  2 bytes  luma data size&lt;br /&gt;
  2 bytes  U data size&lt;br /&gt;
&lt;br /&gt;
==== Codeword encoding scheme ====&lt;br /&gt;
&lt;br /&gt;
Every codeword is encoded as Rice code with three parameters defining coding parameters: maximum prefix length for Rice codes (&amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt;), Rice code parameter (&amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;) and Elias gamma (aka exp-Golomb) code parameter (&amp;lt;code&amp;gt;G&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Decoding process is the following: read unary prefix, if its value more than &amp;lt;code&amp;gt;MP&amp;lt;/code&amp;gt; then treat code as Elias gamma, otherwise treat it as Rice code (or pure unary for &amp;lt;code&amp;gt;R&amp;lt;/code&amp;gt;=0).&lt;br /&gt;
&lt;br /&gt;
  n = get_unary();&lt;br /&gt;
  if (n &amp;gt; MP) {&lt;br /&gt;
    val = get_bits(G + (n - MP - 1)) + ((MP + 1) &amp;lt;&amp;lt; R);&lt;br /&gt;
  } else if (R) {&lt;br /&gt;
    val = (1 &amp;lt;&amp;lt; n) | get_bits(R);&lt;br /&gt;
  } else {&lt;br /&gt;
    val = n;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
Coding parameters are packed into one byte:&lt;br /&gt;
&lt;br /&gt;
  bits 0-1 MP&lt;br /&gt;
  bits 2-4 G&lt;br /&gt;
  bits 5-7 R&lt;br /&gt;
&lt;br /&gt;
So further this byte value will be used to denote parameters.&lt;br /&gt;
&lt;br /&gt;
==== Overall slice coding ====&lt;br /&gt;
&lt;br /&gt;
Add data in slices is stored grouped: data for luma blocks is stored first, for chroma blocks last.&lt;br /&gt;
Inside blocks DC coefficients are stored first, then AC coefficients.&lt;br /&gt;
&lt;br /&gt;
==== DC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
DC values are delta-coded. First value and the first difference value are coded with fixed parameters, others depend on previous raw code:&lt;br /&gt;
&lt;br /&gt;
  dc_code_params[] = {0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70 };&lt;br /&gt;
  &lt;br /&gt;
  code = get_code(0xB8);&lt;br /&gt;
  dc[0] = (code &amp;gt;&amp;gt; 1) ^ -(code &amp;amp; 1);&lt;br /&gt;
  &lt;br /&gt;
  code = 5;&lt;br /&gt;
  sign = 0;&lt;br /&gt;
  for (i = 1; i &amp;lt; num_dcs; i++) {&lt;br /&gt;
    code = get_code(dc_code_params[min(code, 6)]);&lt;br /&gt;
    sign ^= -(code &amp;amp; 1);&lt;br /&gt;
    dc[i] = dc[i - 1] + (((code + 1) &amp;gt;&amp;gt; 1) ^ sign) - sign; &lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== AC coding scheme ====&lt;br /&gt;
&lt;br /&gt;
AC coefficients from all blocks are coded together as single &amp;lt;code&amp;gt;(skip, val, sign)&amp;lt;/code&amp;gt; stream interleaved (i.e. all coefficients at position 1 first, then all coefficients at position 2, etc.).&lt;br /&gt;
And again parameters for coding next value are selected depending on previous decoded value:&lt;br /&gt;
&lt;br /&gt;
  skip_code_params[] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  level_code_params[] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C };&lt;br /&gt;
  &lt;br /&gt;
  pos   = num_blocks;&lt;br /&gt;
  skip  = 4;&lt;br /&gt;
  level = 2;&lt;br /&gt;
  while (pos &amp;lt; 64 * num_blocks &amp;amp;&amp;amp; has_bits_left()) {&lt;br /&gt;
    skip = get_code(skip_code_params[min(skip, 15)]);&lt;br /&gt;
    level = get_code(level_code_params[min(level, 9)]) + 1;&lt;br /&gt;
    sign = get_bit();&lt;br /&gt;
    &lt;br /&gt;
    pos += skip + 1;&lt;br /&gt;
    block[pos % num_blocks][scan[pos / num_blocks]] = sign ? -val : val;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==== Unquantising ====&lt;br /&gt;
&lt;br /&gt;
  DC = 4096 + ((dc_val * quant_matrix[0] * quant_mul) &amp;gt;&amp;gt; 2);&lt;br /&gt;
&lt;br /&gt;
  AC = (ac_val * quant_matrix[i] * quant_mul) &amp;gt;&amp;gt; 2;&lt;br /&gt;
&lt;br /&gt;
Base quantising matrices are given in frame header, quantising multiplier is given in each slice header.&lt;br /&gt;
&lt;br /&gt;
==== Scan order ====&lt;br /&gt;
&lt;br /&gt;
Progressive:&lt;br /&gt;
&lt;br /&gt;
     0,  1,  8,  9,  2,  3, 10, 11,&lt;br /&gt;
    16, 17, 24, 25, 18, 19, 26, 27,&lt;br /&gt;
     4,  5, 12, 20, 13,  6,  7, 14,&lt;br /&gt;
    21, 28, 29, 22, 15, 23, 30, 31,&lt;br /&gt;
    32, 33, 40, 48, 41, 34, 35, 42,&lt;br /&gt;
    49, 56, 57, 50, 43, 36, 37, 44,&lt;br /&gt;
    51, 58, 59, 52, 45, 38, 39, 46,&lt;br /&gt;
    53, 60, 61, 54, 47, 55, 62, 63&lt;br /&gt;
&lt;br /&gt;
Interlaced:&lt;br /&gt;
&lt;br /&gt;
     0,  8,  1,  9, 16, 24, 17, 25,&lt;br /&gt;
     2, 10,  3, 11, 18, 26, 19, 27,&lt;br /&gt;
    32, 40, 33, 34, 41, 48, 56, 49,&lt;br /&gt;
    42, 35, 43, 50, 57, 58, 51, 59,&lt;br /&gt;
     4, 12,  5,  6, 13, 20, 28, 21,&lt;br /&gt;
    14,  7, 15, 22, 29, 36, 44, 37,&lt;br /&gt;
    30, 23, 31, 38, 45, 52, 60, 53,&lt;br /&gt;
    46, 39, 47, 54, 61, 62, 55, 63,&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13504</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13504"/>
		<updated>2011-06-17T11:23:58Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame layout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13503</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13503"/>
		<updated>2011-06-17T11:23:17Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Binary packages and compatibility */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.component || align=&amp;quot;center&amp;quot; | 2.0.1 (Build 227) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13179</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13179"/>
		<updated>2010-12-30T22:34:20Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Huffman tables for delta coding */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of ATRAC3 ATRAC3plus represents the next generation of the ATRAC codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filter] before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the QMF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] += [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13178</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13178"/>
		<updated>2010-12-30T22:25:00Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Mode 1 (master) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of ATRAC3 ATRAC3plus represents the next generation of the ATRAC codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filter] before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the QMF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] += [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding based on modular arithmetic|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13138</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13138"/>
		<updated>2010-11-20T10:14:08Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* ProRes Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e. compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13137</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13137"/>
		<updated>2010-11-20T10:13:44Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* ProRes Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* visually lossless compression (i.e.compressed images cannot be distinguished from the original by a human observer)&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Indeo_5&amp;diff=13124</id>
		<title>Indeo 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Indeo_5&amp;diff=13124"/>
		<updated>2010-11-11T11:30:10Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* GOP header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCCs: IV50&lt;br /&gt;
* Company: [[Intel]], then [[Ligos]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/IV50/&lt;br /&gt;
* Samples: http://ligos.com/videoclips/lions/lion_sif_ind5.zip&lt;br /&gt;
* Docs: http://www.ligos.com/pdf_docs/Indeo_doc.pdf&lt;br /&gt;
* Docs: http://www.ligos.com/pdf_docs/Indeo_FAQ.pdf&lt;br /&gt;
* Patent links: http://www.freepatentsonline.com/5532940.pdf&lt;br /&gt;
* Patent links: http://www.patentstorm.us/patents/5532940-description.html&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Indeo5 is the latest version of Indeo Video Interactive(IVI). For an introduction to this compression algorithm see [[Indeo_4#Introduction|Indeo Video Interactive]].&lt;br /&gt;
&lt;br /&gt;
== Indeo Video Interactive Version 5 (Indeo5) ==&lt;br /&gt;
&lt;br /&gt;
For a description of the coding techniques see [[Indeo_4#Brief description of the coding techniques|Brief description of the coding techniques]].&lt;br /&gt;
&lt;br /&gt;
For a description of the interactive features see [[Indeo_4#Brief description of the interactive features|Brief description of the interactive features]].&lt;br /&gt;
&lt;br /&gt;
Indeo5 algorithm is mostly the same as indeo4 with the following differences:&lt;br /&gt;
&lt;br /&gt;
- indeo5 uses a different bitstream format for picture and band headers that allows storing of compressed frames more compactly.&lt;br /&gt;
&lt;br /&gt;
- indeo5 utilizes only the Slant transform. The Haar transform used in indeo4 was dropped due to its low quality.&lt;br /&gt;
&lt;br /&gt;
- indeo5 uses the Daubechies (LeGall) 5/3 wavelet for the subband decomposition/recomposition instead of the Haar wavelet used in indeo4 in order to provide a better quality for the scalability mode.&lt;br /&gt;
&lt;br /&gt;
- bidirectional frames mode seems to be dropped. Actually there is no indeo5 encoder supports its creating. Mac and Xanim decoders contain no code for handling of this kind of frames.&lt;br /&gt;
&lt;br /&gt;
- indeo5 performs a partially encryption of the bitstream if a numeric password (&amp;quot;access key&amp;quot;) was specified during encoding.&lt;br /&gt;
&lt;br /&gt;
== Decoder specification ==&lt;br /&gt;
&lt;br /&gt;
Indeo5 has the same picture layout and bitstream organization as indeo4. For a detailed description see [[Indeo_4#Picture layout|Indeo4 picture layout]] and [[Indeo_4#Bitstream organization|Bitstream organization]].&lt;br /&gt;
&lt;br /&gt;
=== Conventions ===&lt;br /&gt;
&lt;br /&gt;
Headers are described in some tables. Each row of those tables describes a value which may be read from the frame. Those tables and rows are presented in the order of appearance in the frame.&lt;br /&gt;
&lt;br /&gt;
Here are the meaning of each columns:&lt;br /&gt;
* '''size''': The size of this value in bits. Bits are counted in LSB to MSB order. As an example, with the byte 01110000b, reading 3 bits then 5 bits will return 000b then 01110b. Reading more than 8 bits thus reads as a little-endian value. Think of the get_bits function as filling up the return value from its LSB, using the bits from each byte starting from their LSB.&lt;br /&gt;
* '''name''': Kind of variable name, used to reference the value. When a value is named valueX, it generally means we don't know it's purpose. Lines named alignmentX means that bits reader need to skip bits until next byte boundary.&lt;br /&gt;
* '''condition''': The value is present in the frame only if this condition is matched. No condition means that the value is always present.&lt;br /&gt;
* '''value(s)''': Description of constant values and their meaning.&lt;br /&gt;
* '''comments''': Some details about the content of the value.&lt;br /&gt;
&lt;br /&gt;
=== Picture header ===&lt;br /&gt;
&lt;br /&gt;
Picture header of indeo5 consists of three parts:&lt;br /&gt;
&lt;br /&gt;
 Picture_start_code, frame_type, frame_number&lt;br /&gt;
 [GOP header]&lt;br /&gt;
 Frame header&lt;br /&gt;
&lt;br /&gt;
The first two bytes of a frame tell the decoder how the following data should be interpreted. These include three fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || PSC || always = 0x1F || indeo5 picture start code&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3  || frame_type ||&lt;br /&gt;
* 0 =&amp;gt; INTRA (key) frame&lt;br /&gt;
* 1 =&amp;gt; INTER frame&lt;br /&gt;
* 2 =&amp;gt; droppable INTER frame (scalability mode only)&lt;br /&gt;
* 3 =&amp;gt; droppable INTER frame&lt;br /&gt;
* 4 =&amp;gt; NULL frame&lt;br /&gt;
* 5...7 are illegal&lt;br /&gt;
|| frame type&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || frame_number || 0...0xFF || frame number in GOP (0 for I frame)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Null frames don't contain anything else than this header.&lt;br /&gt;
&lt;br /&gt;
==== GOP header ====&lt;br /&gt;
&lt;br /&gt;
This header is present in INTRA (key) frames only. It's used for transfering of some general information (i.e. picture layout) that will be either rarely or never changed during a video sequence.  The values in this header are valid for all frames in the GOP.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  8 || &amp;lt;span id=&amp;quot;gop_flags&amp;quot;&amp;gt;gop_flags&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* bit 0 =&amp;gt; 1 - [[#gop_hdr_size|gop_hdr_size]] field is present&lt;br /&gt;
* bit 1 =&amp;gt; subsampling format: 0 - YVU9, 1 - YV12&lt;br /&gt;
* bit 2 =&amp;gt; unknown meaning&lt;br /&gt;
* bit 3 =&amp;gt; transparency status?&lt;br /&gt;
* bit 4 =&amp;gt;&lt;br /&gt;
* bit 5 =&amp;gt; access key protection: 1 - enabled&lt;br /&gt;
* bit 6 =&amp;gt; local decoding: 1 - enabled&lt;br /&gt;
* bit 7 =&amp;gt;&lt;br /&gt;
|| GOP header flags (bit 0 is the LSB).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 16 || &amp;lt;span id=&amp;quot;gop_hdr_size&amp;quot;&amp;gt;gop_hdr_size&amp;lt;/span&amp;gt; || [[#gop_flags|gop_flags]] &amp;amp; 0x01 || || Size of this header in bytes. Only present in the bitstream if indicated by the [[#gop_flags|gop_flags]] bit 0.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 32 || &amp;lt;span id=&amp;quot;lock_word&amp;quot;&amp;gt;lock_word&amp;lt;/span&amp;gt; || [[#gop_flags|gop_flags]] &amp;amp; 0x20 || ||&lt;br /&gt;
Only present in the bitstream if &amp;quot;access key protection&amp;quot; is active (as indicated by the bit 5 of the [[#gop_flags|gop_flags]]). For a description of how to use this field see [[#Access key protection|Access key protection]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  2 || &amp;lt;span id=&amp;quot;slice_size_id&amp;quot;&amp;gt;slice_size_id&amp;lt;/span&amp;gt; || [[#gop_flags|gop_flags]] &amp;amp; 0x40 ||&lt;br /&gt;
* 0 =&amp;gt;  64 x 64&lt;br /&gt;
* 1 =&amp;gt; 128 x 128&lt;br /&gt;
* 2 =&amp;gt; 256 x 256&lt;br /&gt;
* 3 =&amp;gt; unused&lt;br /&gt;
|| ID of slice size. Only present if &amp;quot;local decoding mode&amp;quot; is enabled (indicated by the bit 6 of the [[#gop_flags|gop_flags]]).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  2 || &amp;lt;span id=&amp;quot;luma_levels&amp;quot;&amp;gt;luma_levels&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; no decomposition&lt;br /&gt;
* 1 =&amp;gt; 1 level&lt;br /&gt;
* 2 =&amp;gt; 2 levels&lt;br /&gt;
* 3 =&amp;gt; forbidden&lt;br /&gt;
|| Number of wavelet decomposition levels for the luma plane. Number of resulting wavelet subbands can be calculated using the following equation: num_bands = [[#luma_levels|luma_levels]] * 3 + 1.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;chroma_levels&amp;quot;&amp;gt;chroma_levels&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; no decomposition&lt;br /&gt;
* 1 =&amp;gt; forbidden&lt;br /&gt;
|| Number of wavelet decomposition levels for the chrominance planes. The value of &amp;quot;1&amp;quot; is forbidden because no knowing indeo5 software performs any decomposition of the chrominance planes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  4 || &amp;lt;span id=&amp;quot;pic_size_id&amp;quot;&amp;gt;pic_size_id&amp;lt;/span&amp;gt; || || || Index into the table of the  [[#Standard_picture_sizes|standard picture sizes]]. If the picture has dimensions not listed in the table then this field contains the value of &amp;quot;15&amp;quot; and the actual picture size will be coded using [[#pic_height|pic_height]] and [[#pic_width|pic_width]] fields.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 13 || &amp;lt;span id=&amp;quot;pic_height&amp;quot;&amp;gt;pic_height&amp;lt;/span&amp;gt; || rowspan=&amp;quot;2&amp;quot; | [[#pic_size_id|pic_size_id]] == 15 || || Non-standard picture height.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 13 || &amp;lt;span id=&amp;quot;pic_width&amp;quot;&amp;gt;pic_width&amp;lt;/span&amp;gt; || || Non-standard picture width.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  variable || &amp;lt;span id=&amp;quot;band_info_luma&amp;quot;&amp;gt;band_info_luma&amp;lt;/span&amp;gt; || || || Array of the [[#Band_info structure|Band_info structures]] describing each luminance band. For a description how to calculate the number of the luminance bands see here: [[#luma_levels|luma_levels]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  6-8 || &amp;lt;span id=&amp;quot;band_info_chroma&amp;quot;&amp;gt;band_info_chroma&amp;lt;/span&amp;gt; || || || Array of the [[#Band_info structure|Band_info structures]] describing each chrominance band. Because the chrominance planes are being NEVER decomposed by the existing indeo5 software there is only one band per chrominance plane and therefore only one descriptor of this type.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  3 || &amp;lt;span id=&amp;quot;alignment1&amp;quot;&amp;gt;alignment1&amp;lt;/span&amp;gt; || rowspan=&amp;quot;3&amp;quot; | [[#gop_flags|gop_flags]] &amp;amp; 0x08 || always == 0 || Alignment bits. Must be zero.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;color_flg&amp;quot;&amp;gt;color_flg&amp;lt;/span&amp;gt; || || This flag indicates if the [[#transp_color|transp_color]] field is present.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 24 || &amp;lt;span id=&amp;quot;transp_color&amp;quot;&amp;gt;transp_color&amp;lt;/span&amp;gt; || || Transparency fill color.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment2&amp;quot;&amp;gt;alignment2&amp;lt;/span&amp;gt; || || || Align the bitreader on the next byte.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || &amp;lt;span id=&amp;quot;value1&amp;quot;&amp;gt;value1&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || &amp;lt;span id=&amp;quot;value2&amp;quot;&amp;gt;value2&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || &amp;lt;span id=&amp;quot;value3&amp;quot;&amp;gt;value3&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || &amp;lt;span id=&amp;quot;value4&amp;quot;&amp;gt;value4&amp;lt;/span&amp;gt; || || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;gop_ext_flg&amp;quot;&amp;gt;gop_ext_flg&amp;lt;/span&amp;gt; || || || This flag indicates if the [[#gop_ext|gop_ext]] field is present.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;gop_ext&amp;quot;&amp;gt;gop_ext&amp;lt;/span&amp;gt; || [[#gop_ext_flg|gop_ext_flg]] == 1 ||&lt;br /&gt;
do { val = getbits(16);&lt;br /&gt;
} while(val &amp;amp;0x8000);&lt;br /&gt;
|| GOP header extension.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment3&amp;quot;&amp;gt;alignment3&amp;lt;/span&amp;gt; || || || Align the bitreader on the next byte.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Frame header ====&lt;br /&gt;
&lt;br /&gt;
This header is present in all kinds of frame except NULL. It's used mainly to transfer a huffman codebook for the macroblock signals and provide checksum information for debugging purposes.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  8 || &amp;lt;span id=&amp;quot;frame_flags&amp;quot;&amp;gt;frame_flags&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* bit 0 =&amp;gt; 1 - [[#pic_hdr_size|pic_hdr_size]] field is present&lt;br /&gt;
* bit 1 =&amp;gt;&lt;br /&gt;
* bit 2 =&amp;gt;&lt;br /&gt;
* bit 3 =&amp;gt;&lt;br /&gt;
* bit 4 =&amp;gt; 1 - [[#frm_checksum|frm_checksum]] field is present.&lt;br /&gt;
* bit 5 =&amp;gt; 1 - [[#frm_hdr_ext|frm_hdr_ext]] field is present.&lt;br /&gt;
* bit 6 =&amp;gt; 1 - [[#mb_huff_desc|mb_huff_desc]] field is present. Otherwise select the default macroblock huffman codebook.&lt;br /&gt;
* bit 7 =&amp;gt; 1 - [[#band_data_size|band_data_size]] field is present.&lt;br /&gt;
|| Frame flags (bit 0 is the LSB).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 24 || &amp;lt;span id=&amp;quot;pic_hdr_size&amp;quot;&amp;gt;pic_hdr_size&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x01 || || Size of the entire picture header in bytes. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 0.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 16 || &amp;lt;span id=&amp;quot;frm_checksum&amp;quot;&amp;gt;frm_checksum&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x10 || || Frame checksum for debugging purposes. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 4.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;frm_hdr_ext&amp;quot;&amp;gt;frm_hdr_ext&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x20 ||&lt;br /&gt;
To skip it, do the following:&lt;br /&gt;
 do {&lt;br /&gt;
    len = getbits(8);&lt;br /&gt;
    for (i=0; i &amp;lt; len; i++) skipbits(8);&lt;br /&gt;
 } while(len);&lt;br /&gt;
|| Unknown frame header extension. Its content will be ignored by the known indeo5 decoders. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 5.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;mb_huff_desc&amp;quot;&amp;gt;mb_huff_desc&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x40 || || Macroblock huffman codebook descriptor. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 6. For a description of the format of the huffman codebook descriptors see [[Indeo_4#Codebook descriptors in the bitstream|Codebook descriptors in the bitstream]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || &amp;lt;span id=&amp;quot;value5&amp;quot;&amp;gt;value5&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment4&amp;quot;&amp;gt;alignment4&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Band header ===&lt;br /&gt;
&lt;br /&gt;
This header describes a wavelet band.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  8 || &amp;lt;span id=&amp;quot;gop_flags&amp;quot;&amp;gt;band_flags&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* bit 0 =&amp;gt; 1 - this band is empty (doesn't contain any coded data).&lt;br /&gt;
* bit 1 =&amp;gt; 1 - motion vector inheritance mode is enabled.&lt;br /&gt;
* bit 2 =&amp;gt; 1 - qdelta parameter is present.&lt;br /&gt;
* bit 3 =&amp;gt; 1 - qdelta inheritance mode is enabled.&lt;br /&gt;
* bit 4 =&amp;gt; 1 - [[#rv_tab_corr|rv_tab_corr]] array is present.&lt;br /&gt;
* bit 5 =&amp;gt; 1 - [[#band_hdr_ext|band_hdr_ext]] field is present.&lt;br /&gt;
* bit 6 =&amp;gt; 1 - [[#rv_tab_sel|rv_tab_sel]] field is present. Otherwise use the default rv_table.&lt;br /&gt;
* bit 7 =&amp;gt; 1 - [[#blk_huff_desc|blk_huff_desc]] field is present. Otherwise use the default block huffman codebook.&lt;br /&gt;
|| Band flags (bit 0 is the LSB).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 24 || &amp;lt;span id=&amp;quot;band_data_size&amp;quot;&amp;gt;band_data_size&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x80 || || Size of the band data in bytes. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 7.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || &amp;lt;span id=&amp;quot;num_rv_corr&amp;quot;&amp;gt;num_rv_corr&amp;lt;/span&amp;gt; || rowspan=&amp;quot;2&amp;quot; | [[#band_flags|band_flags]] &amp;amp; 0x10 || || Number of rv_table correction pairs. Must be &amp;lt;= 61. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 4.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;rv_tab_corr&amp;quot;&amp;gt;rv_tab_corr&amp;lt;/span&amp;gt; || || Array of rv_table correction pairs. Its size is [[#num_rv_corr|num_rv_corr]] * 2 bytes. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 4.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || &amp;lt;span id=&amp;quot;rv_tab_sel&amp;quot;&amp;gt;rv_tab_sel&amp;lt;/span&amp;gt; || [[#band_flags|band_flags]] &amp;amp; 0x40 || || Indicates which run-value table should be used for decoding. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 6.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;blk_huff_desc&amp;quot;&amp;gt;blk_huff_desc&amp;lt;/span&amp;gt; || [[#band_flags|band_flags]] &amp;amp; 0x80 || || Block huffman codebook descriptor. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 7. For a description of the format of the huffman codebook descriptors see [[Indeo_4#Codebook descriptors in the bitstream|Codebook descriptors in the bitstream]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || &amp;lt;span id=&amp;quot;checksum_flag&amp;quot;&amp;gt;checksum_flag&amp;lt;/span&amp;gt; || || || If set [[#band_checksum|band_checksum]] field is present in the bitstream.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 16 || &amp;lt;span id=&amp;quot;band_checksum&amp;quot;&amp;gt;band_checksum&amp;lt;/span&amp;gt; || [[#checksum_flag|checksum_flag]] || || Band checksum for debugging purposes. Only present in the bitstream if indicated by the [[#checksum_flag|checksum_flag]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;band_glob_quant&amp;quot;&amp;gt;band_glob_quant&amp;lt;/span&amp;gt; || || || Global quantization level for this band.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment5&amp;quot;&amp;gt;alignment5&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;band_hdr_ext&amp;quot;&amp;gt;band_hdr_ext&amp;lt;/span&amp;gt; || [[#band_flags|band_flags]] &amp;amp; 0x20 ||&lt;br /&gt;
To skip it, do the following:&lt;br /&gt;
 do {&lt;br /&gt;
    len = getbits(8);&lt;br /&gt;
    for (i=0; i &amp;lt; len; i++) skipbits(8);&lt;br /&gt;
 } while(getbits(1));&lt;br /&gt;
|| Unknown band header extension. Its content will be ignored by the known indeo5 decoders. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 5.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment6&amp;quot;&amp;gt;alignment6&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Scalability mode ==&lt;br /&gt;
&lt;br /&gt;
This special feature of Indeo5 allows the decoder to adapt playback to the processor power of the particular machine being used for playback. Indeo5 offers both spatial and temporal scalability. Read more about that technique here: [[Scalable Video Coding]].&lt;br /&gt;
&lt;br /&gt;
=== Spatial scalability ===&lt;br /&gt;
&lt;br /&gt;
Spatial scalability works by dividing the image into a number of frequency bands using wavelet decomposition. These bands represent the image at a different level of sharpness. All bands are necessary to perfectly recreate the original image. But if there is not enough processor power available, the decoder can decompress fewer bands of each frame, rather than simply dropping frames. This produces blurry images, but preserves the motion.&lt;br /&gt;
&lt;br /&gt;
The scalability mode is controlled by the user during encoding. If this mode is disabled the encoder acts like an usual block-based transform compression algorithm: each  of the three color planes will be processed using the Slant transform, quantization and Huffman coding.&lt;br /&gt;
If the scalability mode is enabled the encoder first performs subband decomposition using the [[Discrete Wavelet Transform]] (DWT). Although each color plane could be theoretically decomposed Indeo5 performs that only on the luminance plane data. This decomposition results in four wavelet bands, each of them is one-fourth of the original picture size. Further those band will be compressed using the Slant transform, quantization and Huffman coding.&lt;br /&gt;
&lt;br /&gt;
==== Wavelet transform ====&lt;br /&gt;
&lt;br /&gt;
The wavelet used in Indeo5 for decomposition/recomposition purposes is referred as CDF 5/3 or LeGall wavelet. It uses in a slightly different form in many other compression algorithms like [[JPEG 2000]] or [[Snow]]. The coefficients for the analysis filters (encoder) are:&lt;br /&gt;
&lt;br /&gt;
  h0 = {-1, 2, 6, 2, -1} * 1/8&lt;br /&gt;
  h1 = {1, -2, 1} * 1/4&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;h0&amp;quot; is the low-pass filter and &amp;quot;h1&amp;quot; is the high-pass filter.&lt;br /&gt;
&lt;br /&gt;
The coefficients for the synthesis filters (decoder) are:&lt;br /&gt;
&lt;br /&gt;
  h0 = {1, 2, 1} * 1/2&lt;br /&gt;
  h1 = {1, 2, -6, 2, 1} * 1/4&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;h0&amp;quot; is the low-pass filter and &amp;quot;h1&amp;quot; is the high-pass filter.&lt;br /&gt;
&lt;br /&gt;
This wavelet transform has the following advantages:&lt;br /&gt;
&lt;br /&gt;
- it allows an integer implementation&lt;br /&gt;
&lt;br /&gt;
- a fast algorithm (lifting) exists&lt;br /&gt;
&lt;br /&gt;
- it produces better quality images than the Haar wavelet used in [[Indeo 4]] for the same purpose&lt;br /&gt;
&lt;br /&gt;
- it allows the perfect reconstruction of the input signal&lt;br /&gt;
&lt;br /&gt;
==== Wavelet bands ====&lt;br /&gt;
&lt;br /&gt;
The [[#Wavelet transform|Wavelet transform]] produces four wavelet bands whose properties are summarized in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! band !! name !! dimensions !! frequency components !! transform&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  0 || align=&amp;quot;center&amp;quot; | LL ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
|| Low freqs in both horizontal and vertical directions || 2D Slant 8x8&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || align=&amp;quot;center&amp;quot; | HL ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
||&lt;br /&gt;
* Low freqs in the horizontal direction&lt;br /&gt;
* High freqs in the vertical direction&lt;br /&gt;
|| 1D Row Slant&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  2 || align=&amp;quot;center&amp;quot; | LH ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
||&lt;br /&gt;
* High freqs in the horizontal direction&lt;br /&gt;
* Low freqs in the vertical direction&lt;br /&gt;
|| 1D Column Slant&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  3 || align=&amp;quot;center&amp;quot; | HH ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
|| High freqs in both horizontal and vertical directions || No transform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The type of the transform used to process a particular band is chosen according to its frequency content. The low frequency image components are the most important components for visual sensitivity. Therefore the transform is selected so that it can process the low frequency components more efficiently than the high frequency ones. For example, the two-dimensional slant transform is used to process the band 0 because it contains the low frequency components in both horizontal and vertical directions. But the band 1 contains low frequency components only in the horizontal direction that's why the one-dimensional slant transform applied to each of the 8 rows in a 8x8 block is used. Similar to it, the band 2 uses the one-dimensional slant transform applied to each of the 8 columns in a 8x8 block. The band 3 contains only high frequency components in both directions therefore no transform is applied to its data. This band will be coded using quantization and entropy coding only.&lt;br /&gt;
&lt;br /&gt;
==== Wavelet recomposition ====&lt;br /&gt;
&lt;br /&gt;
The following section describes the wavelet recomposition - the last stage of the indeo5 decoder reconstructing an image from a plurality of [[#Wavelet bands|wavelet bands]]. It receives up to four separate bands (labeled b0-b3) and generates recomposed plane data by performing two-dimensional wavelet synthesis.&lt;br /&gt;
&lt;br /&gt;
=== Temporal scalability ===&lt;br /&gt;
&lt;br /&gt;
In order to achieve the temporal scalability Indeo5 introduces special droppable frames. The main advantage of such frames is that those can be skipped without damaging the whole video sequence. If there is not enough processor power available, the decoder can decompress fewer frames and thus display the video at reduced frame rate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Planes ==&lt;br /&gt;
=== Plane data ===&lt;br /&gt;
&lt;br /&gt;
Needs more analysis. Follows plane header.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! nb times !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value24&amp;quot;&amp;gt;value24&amp;lt;/span&amp;gt; || || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value25&amp;quot;&amp;gt;value25&amp;lt;/span&amp;gt; || ! [[#value24|value24]] || || plan_data_size = value25&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  8 || &amp;lt;span id=&amp;quot;value26&amp;quot;&amp;gt;value26&amp;lt;/span&amp;gt; || [[#value25|value25]] == 1 || || plan_data_size = value26&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; | 24 || &amp;lt;span id=&amp;quot;value27&amp;quot;&amp;gt;value27&amp;lt;/span&amp;gt; || [[#value26|value26]] == 0xFF || || plan_data_size = value27&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Block header ===&lt;br /&gt;
&lt;br /&gt;
Each plane is split into a number of blocks in the x and y directions. There is one of these headers one after another for each block in the plane.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! nb times !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value28&amp;quot;&amp;gt;value28&amp;lt;/span&amp;gt; || || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value29&amp;quot;&amp;gt;value29&amp;lt;/span&amp;gt; || value28 &amp;amp;&amp;amp; plane_state17 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value30&amp;quot;&amp;gt;value30&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; plane_state12 &amp;amp;&amp;amp; plane_state1 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  4 || &amp;lt;span id=&amp;quot;value31&amp;quot;&amp;gt;value31&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; four_blocks || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value32&amp;quot;&amp;gt;value32&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; !four_blocks || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value33&amp;quot;&amp;gt;value33&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; plane_state14 &amp;amp;&amp;amp; !plane_state13 &amp;amp;&amp;amp; (plane_state17 &amp;lt;nowiki&amp;gt;||&amp;lt;/nowiki&amp;gt; value31/2) || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value34&amp;quot;&amp;gt;value34&amp;lt;/span&amp;gt; || rowspan=2 | !value28 &amp;amp;&amp;amp; !(block_state4 &amp;amp; 2) &amp;amp;&amp;amp; !plane_state12 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value35&amp;quot;&amp;gt;value35&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'plane_state' states come from plane parsing; they are yet to be connected to the previous data.&lt;br /&gt;
&lt;br /&gt;
block_state4 is too complicated to explain here, sorry!&lt;br /&gt;
&lt;br /&gt;
=== Block data ===&lt;br /&gt;
&lt;br /&gt;
Follows block header. One of these for each plane that has 'plane_flags&amp;amp;1'. The variable 'run' starts at -1 and carries over from one coded plane to the next. I don't really know what I'm doing with vlc's so the names might not be correct... but their functional description is.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! nb times !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;vlc&amp;quot;&amp;gt;vlc&amp;lt;/span&amp;gt; || || rowspan=4 valign=top | while (vlc != vlcEnd) ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;run_add&amp;quot;&amp;gt;run_add&amp;lt;/span&amp;gt; || rowspan=3 | vlc == vlcEsc || run += run_add + 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;lindex_lo&amp;quot;&amp;gt;lindex_lo&amp;lt;/span&amp;gt; || rowspan=2 | lindex = lindex_lo &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt; (lindex_hi&amp;lt;&amp;lt;6)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;lindex_hi&amp;quot;&amp;gt;lindex_hi&amp;lt;/span&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If vlc != vlcEsc then run_add is run_table[vlc], lindex is lindex_table[vlc].&lt;br /&gt;
&lt;br /&gt;
After each loop, stored coefficient is: block[ scan_table[run] ] = level_tables[run][lindex-1].&lt;br /&gt;
&lt;br /&gt;
The values of vlcEnd and vlcEsc are variable, as is the vlc table itself. However, they are all fixed for all the planes in the same block. run_table, lindex_table, scan_table are also fixed-per-block. level_tables is per-plane.&lt;br /&gt;
&lt;br /&gt;
== Annexes ==&lt;br /&gt;
&lt;br /&gt;
=== Standard picture sizes ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | pic_size_id&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | width&lt;br /&gt;
| 640 || 320 || 160 || 704 || 352 || 352 || 176 || 240 || 640 || 704 || 80 || 88 || 0 || 0 || 0 || custom&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | height&lt;br /&gt;
| 480 || 240 || 120 || 224 || 240 || 288 || 144 || 180 || 240 || 240 || 60 || 72 || 0 || 0 || 0 || custom&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Band_info structure ===&lt;br /&gt;
&lt;br /&gt;
This structure is a part of the [[#GOP header|GOP header]] and describes a wavelet band. Its size is usually 6 bits but can be extended up to 8 bits if the [[#ext_trans|ext_trans]] field is present. The same structure is used to describe both luminance and chrominance bands.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;mv_res&amp;quot;&amp;gt;mv_res&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 - fullpel&lt;br /&gt;
* 1 - halfpel&lt;br /&gt;
|| Motion vector resolution.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;mb_size_id&amp;quot;&amp;gt;mb_size_id&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; double&lt;br /&gt;
* 1 =&amp;gt; single&lt;br /&gt;
|| Macroblock size factor. The real size of the macroblock should be calculated as follows: mb_size = [[#blk_size_id|blk_size_id]] &amp;lt;&amp;lt; ![[#mb_size_id|mb_size_id]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;blk_size_id&amp;quot;&amp;gt;blk_size_id&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; 8x8&lt;br /&gt;
* 1 =&amp;gt; 4x4&lt;br /&gt;
|| Block size id.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || &amp;lt;span id=&amp;quot;trans_flg&amp;quot;&amp;gt;trans_flg&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; standard&lt;br /&gt;
* 1 =&amp;gt; non-standard&lt;br /&gt;
|| If this flag is set the field [[#ext_trans|ext_trans]] specifies a transform used to code this band explicitely. Otherwise the default transform is used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;ext_trans&amp;quot;&amp;gt;ext_trans&amp;lt;/span&amp;gt; || [[#trans_flg|trans_flg]] != 0 ||&lt;br /&gt;
* 0 =&amp;gt; 2D Slant&lt;br /&gt;
* 1 =&amp;gt; Row Slant&lt;br /&gt;
* 2 =&amp;gt; Column Slant&lt;br /&gt;
* 3 =&amp;gt; No transform&lt;br /&gt;
|| Specifies a transform that should be used instead of the default transform for this band.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;end_marker&amp;quot;&amp;gt;end_marker&amp;lt;/span&amp;gt; || || always == 0 || End marker terminating this structure.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Table 1 ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | table1_id&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || default&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | counter4&lt;br /&gt;
| 10 || 11 || 12 || 13 || 11 || 13 || 13 || 9&lt;br /&gt;
|-&lt;br /&gt;
! valign=&amp;quot;top&amp;quot; bgcolor=&amp;quot;#f0f0f0&amp;quot; | value19&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
default is used when !([[#ph_flags|ph_flags]] &amp;amp; 0x80)&lt;br /&gt;
&lt;br /&gt;
== Games using indeo5 cutscenes ==&lt;br /&gt;
&lt;br /&gt;
* Dino Crisis I: [http://en.wikipedia.org/wiki/Dino_Crisis]&lt;br /&gt;
* Lemmings Revolution: [http://en.wikipedia.org/wiki/Lemmings_Revolution]&lt;br /&gt;
* Mafia: The City of Lost Heaven [http://en.wikipedia.org/wiki/Mafia:_The_City_of_Lost_Heaven]&lt;br /&gt;
* Thief, Parts 1 &amp;amp; 2 : [http://en.wikipedia.org/wiki/Thief_(series)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Indeo_5&amp;diff=13123</id>
		<title>Indeo 5</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Indeo_5&amp;diff=13123"/>
		<updated>2010-11-11T11:29:21Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Picture header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FOURCCs: IV50&lt;br /&gt;
* Company: [[Intel]], then [[Ligos]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/IV50/&lt;br /&gt;
* Samples: http://ligos.com/videoclips/lions/lion_sif_ind5.zip&lt;br /&gt;
* Docs: http://www.ligos.com/pdf_docs/Indeo_doc.pdf&lt;br /&gt;
* Docs: http://www.ligos.com/pdf_docs/Indeo_FAQ.pdf&lt;br /&gt;
* Patent links: http://www.freepatentsonline.com/5532940.pdf&lt;br /&gt;
* Patent links: http://www.patentstorm.us/patents/5532940-description.html&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Indeo5 is the latest version of Indeo Video Interactive(IVI). For an introduction to this compression algorithm see [[Indeo_4#Introduction|Indeo Video Interactive]].&lt;br /&gt;
&lt;br /&gt;
== Indeo Video Interactive Version 5 (Indeo5) ==&lt;br /&gt;
&lt;br /&gt;
For a description of the coding techniques see [[Indeo_4#Brief description of the coding techniques|Brief description of the coding techniques]].&lt;br /&gt;
&lt;br /&gt;
For a description of the interactive features see [[Indeo_4#Brief description of the interactive features|Brief description of the interactive features]].&lt;br /&gt;
&lt;br /&gt;
Indeo5 algorithm is mostly the same as indeo4 with the following differences:&lt;br /&gt;
&lt;br /&gt;
- indeo5 uses a different bitstream format for picture and band headers that allows storing of compressed frames more compactly.&lt;br /&gt;
&lt;br /&gt;
- indeo5 utilizes only the Slant transform. The Haar transform used in indeo4 was dropped due to its low quality.&lt;br /&gt;
&lt;br /&gt;
- indeo5 uses the Daubechies (LeGall) 5/3 wavelet for the subband decomposition/recomposition instead of the Haar wavelet used in indeo4 in order to provide a better quality for the scalability mode.&lt;br /&gt;
&lt;br /&gt;
- bidirectional frames mode seems to be dropped. Actually there is no indeo5 encoder supports its creating. Mac and Xanim decoders contain no code for handling of this kind of frames.&lt;br /&gt;
&lt;br /&gt;
- indeo5 performs a partially encryption of the bitstream if a numeric password (&amp;quot;access key&amp;quot;) was specified during encoding.&lt;br /&gt;
&lt;br /&gt;
== Decoder specification ==&lt;br /&gt;
&lt;br /&gt;
Indeo5 has the same picture layout and bitstream organization as indeo4. For a detailed description see [[Indeo_4#Picture layout|Indeo4 picture layout]] and [[Indeo_4#Bitstream organization|Bitstream organization]].&lt;br /&gt;
&lt;br /&gt;
=== Conventions ===&lt;br /&gt;
&lt;br /&gt;
Headers are described in some tables. Each row of those tables describes a value which may be read from the frame. Those tables and rows are presented in the order of appearance in the frame.&lt;br /&gt;
&lt;br /&gt;
Here are the meaning of each columns:&lt;br /&gt;
* '''size''': The size of this value in bits. Bits are counted in LSB to MSB order. As an example, with the byte 01110000b, reading 3 bits then 5 bits will return 000b then 01110b. Reading more than 8 bits thus reads as a little-endian value. Think of the get_bits function as filling up the return value from its LSB, using the bits from each byte starting from their LSB.&lt;br /&gt;
* '''name''': Kind of variable name, used to reference the value. When a value is named valueX, it generally means we don't know it's purpose. Lines named alignmentX means that bits reader need to skip bits until next byte boundary.&lt;br /&gt;
* '''condition''': The value is present in the frame only if this condition is matched. No condition means that the value is always present.&lt;br /&gt;
* '''value(s)''': Description of constant values and their meaning.&lt;br /&gt;
* '''comments''': Some details about the content of the value.&lt;br /&gt;
&lt;br /&gt;
=== Picture header ===&lt;br /&gt;
&lt;br /&gt;
Picture header of indeo5 consists of three parts:&lt;br /&gt;
&lt;br /&gt;
 Picture_start_code, frame_type, frame_number&lt;br /&gt;
 [GOP header]&lt;br /&gt;
 Frame header&lt;br /&gt;
&lt;br /&gt;
The first two bytes of a frame tell the decoder how the following data should be interpreted. These include three fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || PSC || always = 0x1F || indeo5 picture start code&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3  || frame_type ||&lt;br /&gt;
* 0 =&amp;gt; INTRA (key) frame&lt;br /&gt;
* 1 =&amp;gt; INTER frame&lt;br /&gt;
* 2 =&amp;gt; droppable INTER frame (scalability mode only)&lt;br /&gt;
* 3 =&amp;gt; droppable INTER frame&lt;br /&gt;
* 4 =&amp;gt; NULL frame&lt;br /&gt;
* 5...7 are illegal&lt;br /&gt;
|| frame type&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || frame_number || 0...0xFF || frame number in GOP (0 for I frame)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Null frames don't contain anything else than this header.&lt;br /&gt;
&lt;br /&gt;
==== GOP header ====&lt;br /&gt;
&lt;br /&gt;
This header is present in INTRA (key) frames only. It's used for transfering of some general information (i.e. picture layout) that will be either rarely or never changed during a video sequence.  The values in this header are valid for all frames in the GOP.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  8 || &amp;lt;span id=&amp;quot;gop_flags&amp;quot;&amp;gt;gop_flags&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* bit 0 =&amp;gt; 1 - [[#gop_hdr_size|gop_hdr_size]] field is present&lt;br /&gt;
* bit 1 =&amp;gt; subsampling format: 0 - YVU9, 1 - YV12&lt;br /&gt;
* bit 2 =&amp;gt; unknown meaning&lt;br /&gt;
* bit 3 =&amp;gt; transparency status?&lt;br /&gt;
* bit 4 =&amp;gt;&lt;br /&gt;
* bit 5 =&amp;gt; access key protection: 1 - enabled&lt;br /&gt;
* bit 6 =&amp;gt; local decoding: 1 - enabled&lt;br /&gt;
* bit 7 =&amp;gt;&lt;br /&gt;
|| GOP header flags (bit 0 is the LSB).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 16 || &amp;lt;span id=&amp;quot;gop_hdr_size&amp;quot;&amp;gt;gop_hdr_size&amp;lt;/span&amp;gt; || [[#gop_flags|gop_flags]] &amp;amp; 0x01 || || Size of this header in bytes. Only present in the bitstream if indicated by the [[#gop_flags|gop_flags]] bit 0.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 32 || &amp;lt;span id=&amp;quot;lock_word&amp;quot;&amp;gt;lock_word&amp;lt;/span&amp;gt; || [[#gop_flags|gop_flags]] &amp;amp; 0x20 || ||&lt;br /&gt;
Only present in the bitstream if &amp;quot;access key protection&amp;quot; is active (as indicated by the bit 5 of the [[#gop_flags|gop_flags]]). For a description of how to use this field see [[#Access key protection|Access key protection]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  2 || &amp;lt;span id=&amp;quot;slice_size_id&amp;quot;&amp;gt;slice_size_id&amp;lt;/span&amp;gt; || [[#gop_flags|gop_flags]] &amp;amp; 0x40 ||&lt;br /&gt;
* 0 =&amp;gt;  64 x 64&lt;br /&gt;
* 1 =&amp;gt; 128 x 128&lt;br /&gt;
* 2 =&amp;gt; 256 x 256&lt;br /&gt;
* 3 =&amp;gt; unused&lt;br /&gt;
|| ID of slice size. Only present if &amp;quot;local decoding mode&amp;quot; is enabled (indicated by the bit 6 of the [[#gop_flags|gop_flags]]).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  2 || &amp;lt;span id=&amp;quot;luma_levels&amp;quot;&amp;gt;luma_levels&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; no decomposition&lt;br /&gt;
* 1 =&amp;gt; 1 level&lt;br /&gt;
* 2 =&amp;gt; 2 levels&lt;br /&gt;
* 3 =&amp;gt; forbidden&lt;br /&gt;
|| Number of wavelet decomposition levels for the luma plane. Number of resulting wavelet subbands can be calculated using the following equation: num_bands = [[#luma_levels|luma_levels]] * 3 + 1.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;chroma_levels&amp;quot;&amp;gt;chroma_levels&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; no decomposition&lt;br /&gt;
* 1 =&amp;gt; forbidden&lt;br /&gt;
|| Number of wavelet decomposition levels for the chrominance planes. The value of &amp;quot;1&amp;quot; is forbidden because no knowing indeo5 software performs any decomposition of the chrominance planes.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  4 || &amp;lt;span id=&amp;quot;pic_size_id&amp;quot;&amp;gt;pic_size_id&amp;lt;/span&amp;gt; || || || Index into the table of the  [[#Standard_picture_sizes|standard picture sizes]]. If the picture has dimensions not listed in the table then this field contains the value of &amp;quot;15&amp;quot; and the actual picture size will be coded using [[#pic_height|pic_height]] and [[#pic_width|pic_width]] fields.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 13 || &amp;lt;span id=&amp;quot;pic_height&amp;quot;&amp;gt;pic_height&amp;lt;/span&amp;gt; || rowspan=&amp;quot;2&amp;quot; | [[#pic_size_id|pic_size_id]] == 15 || || Non-standard picture height.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 13 || &amp;lt;span id=&amp;quot;pic_width&amp;quot;&amp;gt;pic_width&amp;lt;/span&amp;gt; || || Non-standard picture width.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  variable || &amp;lt;span id=&amp;quot;band_info_luma&amp;quot;&amp;gt;band_info_luma&amp;lt;/span&amp;gt; || || || Array of the [[#Band_info structure|Band_info structures]] describing each luminance band. For a description how to calculate the number of the luminance bands see here: [[#luma_levels|luma_levels]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  6-8 || &amp;lt;span id=&amp;quot;band_info_chroma&amp;quot;&amp;gt;band_info_chroma&amp;lt;/span&amp;gt; || || || Array of the [[#Band_info structure|Band_info structures]] describing each chrominance band. Because the chrominance planes are being NEVER decomposed by the existing indeo5 software there is only one band per chrominance plane and therefore only one descriptor of this type.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  3 || &amp;lt;span id=&amp;quot;alignment1&amp;quot;&amp;gt;alignment1&amp;lt;/span&amp;gt; || rowspan=&amp;quot;3&amp;quot; | [[#gop_flags|gop_flags]] &amp;amp; 0x08 || always == 0 || Alignment bits. Must be zero.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;color_flg&amp;quot;&amp;gt;color_flg&amp;lt;/span&amp;gt; || || This flag indicates if the [[#transp_color|transp_color]] field is present.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 24 || &amp;lt;span id=&amp;quot;transp_color&amp;quot;&amp;gt;transp_color&amp;lt;/span&amp;gt; || || Transparency fill color.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment2&amp;quot;&amp;gt;alignment2&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || &amp;lt;span id=&amp;quot;value1&amp;quot;&amp;gt;value1&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || &amp;lt;span id=&amp;quot;value2&amp;quot;&amp;gt;value2&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || &amp;lt;span id=&amp;quot;value3&amp;quot;&amp;gt;value3&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || &amp;lt;span id=&amp;quot;value4&amp;quot;&amp;gt;value4&amp;lt;/span&amp;gt; || || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;gop_ext_flg&amp;quot;&amp;gt;gop_ext_flg&amp;lt;/span&amp;gt; || || || This flag indicates if the [[#gop_ext|gop_ext]] field is present.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;gop_ext&amp;quot;&amp;gt;gop_ext&amp;lt;/span&amp;gt; || [[#gop_ext_flg|gop_ext_flg]] == 1 ||&lt;br /&gt;
do { val = getbits(16);&lt;br /&gt;
} while(val &amp;amp;0x8000);&lt;br /&gt;
|| GOP header extension.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment3&amp;quot;&amp;gt;alignment3&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Frame header ====&lt;br /&gt;
&lt;br /&gt;
This header is present in all kinds of frame except NULL. It's used mainly to transfer a huffman codebook for the macroblock signals and provide checksum information for debugging purposes.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  8 || &amp;lt;span id=&amp;quot;frame_flags&amp;quot;&amp;gt;frame_flags&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* bit 0 =&amp;gt; 1 - [[#pic_hdr_size|pic_hdr_size]] field is present&lt;br /&gt;
* bit 1 =&amp;gt;&lt;br /&gt;
* bit 2 =&amp;gt;&lt;br /&gt;
* bit 3 =&amp;gt;&lt;br /&gt;
* bit 4 =&amp;gt; 1 - [[#frm_checksum|frm_checksum]] field is present.&lt;br /&gt;
* bit 5 =&amp;gt; 1 - [[#frm_hdr_ext|frm_hdr_ext]] field is present.&lt;br /&gt;
* bit 6 =&amp;gt; 1 - [[#mb_huff_desc|mb_huff_desc]] field is present. Otherwise select the default macroblock huffman codebook.&lt;br /&gt;
* bit 7 =&amp;gt; 1 - [[#band_data_size|band_data_size]] field is present.&lt;br /&gt;
|| Frame flags (bit 0 is the LSB).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 24 || &amp;lt;span id=&amp;quot;pic_hdr_size&amp;quot;&amp;gt;pic_hdr_size&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x01 || || Size of the entire picture header in bytes. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 0.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 16 || &amp;lt;span id=&amp;quot;frm_checksum&amp;quot;&amp;gt;frm_checksum&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x10 || || Frame checksum for debugging purposes. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 4.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;frm_hdr_ext&amp;quot;&amp;gt;frm_hdr_ext&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x20 ||&lt;br /&gt;
To skip it, do the following:&lt;br /&gt;
 do {&lt;br /&gt;
    len = getbits(8);&lt;br /&gt;
    for (i=0; i &amp;lt; len; i++) skipbits(8);&lt;br /&gt;
 } while(len);&lt;br /&gt;
|| Unknown frame header extension. Its content will be ignored by the known indeo5 decoders. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 5.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;mb_huff_desc&amp;quot;&amp;gt;mb_huff_desc&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x40 || || Macroblock huffman codebook descriptor. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 6. For a description of the format of the huffman codebook descriptors see [[Indeo_4#Codebook descriptors in the bitstream|Codebook descriptors in the bitstream]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || &amp;lt;span id=&amp;quot;value5&amp;quot;&amp;gt;value5&amp;lt;/span&amp;gt; || || || Unused.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment4&amp;quot;&amp;gt;alignment4&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Band header ===&lt;br /&gt;
&lt;br /&gt;
This header describes a wavelet band.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  8 || &amp;lt;span id=&amp;quot;gop_flags&amp;quot;&amp;gt;band_flags&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* bit 0 =&amp;gt; 1 - this band is empty (doesn't contain any coded data).&lt;br /&gt;
* bit 1 =&amp;gt; 1 - motion vector inheritance mode is enabled.&lt;br /&gt;
* bit 2 =&amp;gt; 1 - qdelta parameter is present.&lt;br /&gt;
* bit 3 =&amp;gt; 1 - qdelta inheritance mode is enabled.&lt;br /&gt;
* bit 4 =&amp;gt; 1 - [[#rv_tab_corr|rv_tab_corr]] array is present.&lt;br /&gt;
* bit 5 =&amp;gt; 1 - [[#band_hdr_ext|band_hdr_ext]] field is present.&lt;br /&gt;
* bit 6 =&amp;gt; 1 - [[#rv_tab_sel|rv_tab_sel]] field is present. Otherwise use the default rv_table.&lt;br /&gt;
* bit 7 =&amp;gt; 1 - [[#blk_huff_desc|blk_huff_desc]] field is present. Otherwise use the default block huffman codebook.&lt;br /&gt;
|| Band flags (bit 0 is the LSB).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 24 || &amp;lt;span id=&amp;quot;band_data_size&amp;quot;&amp;gt;band_data_size&amp;lt;/span&amp;gt; || [[#frame_flags|frame_flags]] &amp;amp; 0x80 || || Size of the band data in bytes. Only present in the bitstream if indicated by the [[#frame_flags|frame_flags]] bit 7.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 8 || &amp;lt;span id=&amp;quot;num_rv_corr&amp;quot;&amp;gt;num_rv_corr&amp;lt;/span&amp;gt; || rowspan=&amp;quot;2&amp;quot; | [[#band_flags|band_flags]] &amp;amp; 0x10 || || Number of rv_table correction pairs. Must be &amp;lt;= 61. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 4.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;rv_tab_corr&amp;quot;&amp;gt;rv_tab_corr&amp;lt;/span&amp;gt; || || Array of rv_table correction pairs. Its size is [[#num_rv_corr|num_rv_corr]] * 2 bytes. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 4.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || &amp;lt;span id=&amp;quot;rv_tab_sel&amp;quot;&amp;gt;rv_tab_sel&amp;lt;/span&amp;gt; || [[#band_flags|band_flags]] &amp;amp; 0x40 || || Indicates which run-value table should be used for decoding. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 6.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;blk_huff_desc&amp;quot;&amp;gt;blk_huff_desc&amp;lt;/span&amp;gt; || [[#band_flags|band_flags]] &amp;amp; 0x80 || || Block huffman codebook descriptor. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 7. For a description of the format of the huffman codebook descriptors see [[Indeo_4#Codebook descriptors in the bitstream|Codebook descriptors in the bitstream]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || &amp;lt;span id=&amp;quot;checksum_flag&amp;quot;&amp;gt;checksum_flag&amp;lt;/span&amp;gt; || || || If set [[#band_checksum|band_checksum]] field is present in the bitstream.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 16 || &amp;lt;span id=&amp;quot;band_checksum&amp;quot;&amp;gt;band_checksum&amp;lt;/span&amp;gt; || [[#checksum_flag|checksum_flag]] || || Band checksum for debugging purposes. Only present in the bitstream if indicated by the [[#checksum_flag|checksum_flag]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;band_glob_quant&amp;quot;&amp;gt;band_glob_quant&amp;lt;/span&amp;gt; || || || Global quantization level for this band.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment5&amp;quot;&amp;gt;alignment5&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || &amp;lt;span id=&amp;quot;band_hdr_ext&amp;quot;&amp;gt;band_hdr_ext&amp;lt;/span&amp;gt; || [[#band_flags|band_flags]] &amp;amp; 0x20 ||&lt;br /&gt;
To skip it, do the following:&lt;br /&gt;
 do {&lt;br /&gt;
    len = getbits(8);&lt;br /&gt;
    for (i=0; i &amp;lt; len; i++) skipbits(8);&lt;br /&gt;
 } while(getbits(1));&lt;br /&gt;
|| Unknown band header extension. Its content will be ignored by the known indeo5 decoders. Only present in the bitstream if indicated by the [[#band_flags|band_flags]] bit 5.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | ?? || &amp;lt;span id=&amp;quot;alignment6&amp;quot;&amp;gt;alignment6&amp;lt;/span&amp;gt; || || || Align the biteader on the next byte.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Scalability mode ==&lt;br /&gt;
&lt;br /&gt;
This special feature of Indeo5 allows the decoder to adapt playback to the processor power of the particular machine being used for playback. Indeo5 offers both spatial and temporal scalability. Read more about that technique here: [[Scalable Video Coding]].&lt;br /&gt;
&lt;br /&gt;
=== Spatial scalability ===&lt;br /&gt;
&lt;br /&gt;
Spatial scalability works by dividing the image into a number of frequency bands using wavelet decomposition. These bands represent the image at a different level of sharpness. All bands are necessary to perfectly recreate the original image. But if there is not enough processor power available, the decoder can decompress fewer bands of each frame, rather than simply dropping frames. This produces blurry images, but preserves the motion.&lt;br /&gt;
&lt;br /&gt;
The scalability mode is controlled by the user during encoding. If this mode is disabled the encoder acts like an usual block-based transform compression algorithm: each  of the three color planes will be processed using the Slant transform, quantization and Huffman coding.&lt;br /&gt;
If the scalability mode is enabled the encoder first performs subband decomposition using the [[Discrete Wavelet Transform]] (DWT). Although each color plane could be theoretically decomposed Indeo5 performs that only on the luminance plane data. This decomposition results in four wavelet bands, each of them is one-fourth of the original picture size. Further those band will be compressed using the Slant transform, quantization and Huffman coding.&lt;br /&gt;
&lt;br /&gt;
==== Wavelet transform ====&lt;br /&gt;
&lt;br /&gt;
The wavelet used in Indeo5 for decomposition/recomposition purposes is referred as CDF 5/3 or LeGall wavelet. It uses in a slightly different form in many other compression algorithms like [[JPEG 2000]] or [[Snow]]. The coefficients for the analysis filters (encoder) are:&lt;br /&gt;
&lt;br /&gt;
  h0 = {-1, 2, 6, 2, -1} * 1/8&lt;br /&gt;
  h1 = {1, -2, 1} * 1/4&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;h0&amp;quot; is the low-pass filter and &amp;quot;h1&amp;quot; is the high-pass filter.&lt;br /&gt;
&lt;br /&gt;
The coefficients for the synthesis filters (decoder) are:&lt;br /&gt;
&lt;br /&gt;
  h0 = {1, 2, 1} * 1/2&lt;br /&gt;
  h1 = {1, 2, -6, 2, 1} * 1/4&lt;br /&gt;
&lt;br /&gt;
where &amp;quot;h0&amp;quot; is the low-pass filter and &amp;quot;h1&amp;quot; is the high-pass filter.&lt;br /&gt;
&lt;br /&gt;
This wavelet transform has the following advantages:&lt;br /&gt;
&lt;br /&gt;
- it allows an integer implementation&lt;br /&gt;
&lt;br /&gt;
- a fast algorithm (lifting) exists&lt;br /&gt;
&lt;br /&gt;
- it produces better quality images than the Haar wavelet used in [[Indeo 4]] for the same purpose&lt;br /&gt;
&lt;br /&gt;
- it allows the perfect reconstruction of the input signal&lt;br /&gt;
&lt;br /&gt;
==== Wavelet bands ====&lt;br /&gt;
&lt;br /&gt;
The [[#Wavelet transform|Wavelet transform]] produces four wavelet bands whose properties are summarized in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! band !! name !! dimensions !! frequency components !! transform&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  0 || align=&amp;quot;center&amp;quot; | LL ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
|| Low freqs in both horizontal and vertical directions || 2D Slant 8x8&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || align=&amp;quot;center&amp;quot; | HL ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
||&lt;br /&gt;
* Low freqs in the horizontal direction&lt;br /&gt;
* High freqs in the vertical direction&lt;br /&gt;
|| 1D Row Slant&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  2 || align=&amp;quot;center&amp;quot; | LH ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
||&lt;br /&gt;
* High freqs in the horizontal direction&lt;br /&gt;
* Low freqs in the vertical direction&lt;br /&gt;
|| 1D Column Slant&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  3 || align=&amp;quot;center&amp;quot; | HH ||&lt;br /&gt;
* width = pic_width/2&lt;br /&gt;
* height = pic_height/2&lt;br /&gt;
|| High freqs in both horizontal and vertical directions || No transform&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The type of the transform used to process a particular band is chosen according to its frequency content. The low frequency image components are the most important components for visual sensitivity. Therefore the transform is selected so that it can process the low frequency components more efficiently than the high frequency ones. For example, the two-dimensional slant transform is used to process the band 0 because it contains the low frequency components in both horizontal and vertical directions. But the band 1 contains low frequency components only in the horizontal direction that's why the one-dimensional slant transform applied to each of the 8 rows in a 8x8 block is used. Similar to it, the band 2 uses the one-dimensional slant transform applied to each of the 8 columns in a 8x8 block. The band 3 contains only high frequency components in both directions therefore no transform is applied to its data. This band will be coded using quantization and entropy coding only.&lt;br /&gt;
&lt;br /&gt;
==== Wavelet recomposition ====&lt;br /&gt;
&lt;br /&gt;
The following section describes the wavelet recomposition - the last stage of the indeo5 decoder reconstructing an image from a plurality of [[#Wavelet bands|wavelet bands]]. It receives up to four separate bands (labeled b0-b3) and generates recomposed plane data by performing two-dimensional wavelet synthesis.&lt;br /&gt;
&lt;br /&gt;
=== Temporal scalability ===&lt;br /&gt;
&lt;br /&gt;
In order to achieve the temporal scalability Indeo5 introduces special droppable frames. The main advantage of such frames is that those can be skipped without damaging the whole video sequence. If there is not enough processor power available, the decoder can decompress fewer frames and thus display the video at reduced frame rate.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Planes ==&lt;br /&gt;
=== Plane data ===&lt;br /&gt;
&lt;br /&gt;
Needs more analysis. Follows plane header.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! nb times !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value24&amp;quot;&amp;gt;value24&amp;lt;/span&amp;gt; || || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value25&amp;quot;&amp;gt;value25&amp;lt;/span&amp;gt; || ! [[#value24|value24]] || || plan_data_size = value25&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  8 || &amp;lt;span id=&amp;quot;value26&amp;quot;&amp;gt;value26&amp;lt;/span&amp;gt; || [[#value25|value25]] == 1 || || plan_data_size = value26&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; | 24 || &amp;lt;span id=&amp;quot;value27&amp;quot;&amp;gt;value27&amp;lt;/span&amp;gt; || [[#value26|value26]] == 0xFF || || plan_data_size = value27&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Block header ===&lt;br /&gt;
&lt;br /&gt;
Each plane is split into a number of blocks in the x and y directions. There is one of these headers one after another for each block in the plane.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! nb times !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value28&amp;quot;&amp;gt;value28&amp;lt;/span&amp;gt; || || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value29&amp;quot;&amp;gt;value29&amp;lt;/span&amp;gt; || value28 &amp;amp;&amp;amp; plane_state17 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value30&amp;quot;&amp;gt;value30&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; plane_state12 &amp;amp;&amp;amp; plane_state1 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  4 || &amp;lt;span id=&amp;quot;value31&amp;quot;&amp;gt;value31&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; four_blocks || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  1 || &amp;lt;span id=&amp;quot;value32&amp;quot;&amp;gt;value32&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; !four_blocks || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value33&amp;quot;&amp;gt;value33&amp;lt;/span&amp;gt; || !value28 &amp;amp;&amp;amp; plane_state14 &amp;amp;&amp;amp; !plane_state13 &amp;amp;&amp;amp; (plane_state17 &amp;lt;nowiki&amp;gt;||&amp;lt;/nowiki&amp;gt; value31/2) || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value34&amp;quot;&amp;gt;value34&amp;lt;/span&amp;gt; || rowspan=2 | !value28 &amp;amp;&amp;amp; !(block_state4 &amp;amp; 2) &amp;amp;&amp;amp; !plane_state12 || ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;value35&amp;quot;&amp;gt;value35&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 'plane_state' states come from plane parsing; they are yet to be connected to the previous data.&lt;br /&gt;
&lt;br /&gt;
block_state4 is too complicated to explain here, sorry!&lt;br /&gt;
&lt;br /&gt;
=== Block data ===&lt;br /&gt;
&lt;br /&gt;
Follows block header. One of these for each plane that has 'plane_flags&amp;amp;1'. The variable 'run' starts at -1 and carries over from one coded plane to the next. I don't really know what I'm doing with vlc's so the names might not be correct... but their functional description is.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! nb times !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;vlc&amp;quot;&amp;gt;vlc&amp;lt;/span&amp;gt; || || rowspan=4 valign=top | while (vlc != vlcEnd) ||&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;run_add&amp;quot;&amp;gt;run_add&amp;lt;/span&amp;gt; || rowspan=3 | vlc == vlcEsc || run += run_add + 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;lindex_lo&amp;quot;&amp;gt;lindex_lo&amp;lt;/span&amp;gt; || rowspan=2 | lindex = lindex_lo &amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt; (lindex_hi&amp;lt;&amp;lt;6)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;right&amp;quot; |  vlc || &amp;lt;span id=&amp;quot;lindex_hi&amp;quot;&amp;gt;lindex_hi&amp;lt;/span&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If vlc != vlcEsc then run_add is run_table[vlc], lindex is lindex_table[vlc].&lt;br /&gt;
&lt;br /&gt;
After each loop, stored coefficient is: block[ scan_table[run] ] = level_tables[run][lindex-1].&lt;br /&gt;
&lt;br /&gt;
The values of vlcEnd and vlcEsc are variable, as is the vlc table itself. However, they are all fixed for all the planes in the same block. run_table, lindex_table, scan_table are also fixed-per-block. level_tables is per-plane.&lt;br /&gt;
&lt;br /&gt;
== Annexes ==&lt;br /&gt;
&lt;br /&gt;
=== Standard picture sizes ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | pic_size_id&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | width&lt;br /&gt;
| 640 || 320 || 160 || 704 || 352 || 352 || 176 || 240 || 640 || 704 || 80 || 88 || 0 || 0 || 0 || custom&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | height&lt;br /&gt;
| 480 || 240 || 120 || 224 || 240 || 288 || 144 || 180 || 240 || 240 || 60 || 72 || 0 || 0 || 0 || custom&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Band_info structure ===&lt;br /&gt;
&lt;br /&gt;
This structure is a part of the [[#GOP header|GOP header]] and describes a wavelet band. Its size is usually 6 bits but can be extended up to 8 bits if the [[#ext_trans|ext_trans]] field is present. The same structure is used to describe both luminance and chrominance bands.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size !! name !! condition !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;mv_res&amp;quot;&amp;gt;mv_res&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 - fullpel&lt;br /&gt;
* 1 - halfpel&lt;br /&gt;
|| Motion vector resolution.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;mb_size_id&amp;quot;&amp;gt;mb_size_id&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; double&lt;br /&gt;
* 1 =&amp;gt; single&lt;br /&gt;
|| Macroblock size factor. The real size of the macroblock should be calculated as follows: mb_size = [[#blk_size_id|blk_size_id]] &amp;lt;&amp;lt; ![[#mb_size_id|mb_size_id]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; |  1 || &amp;lt;span id=&amp;quot;blk_size_id&amp;quot;&amp;gt;blk_size_id&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; 8x8&lt;br /&gt;
* 1 =&amp;gt; 4x4&lt;br /&gt;
|| Block size id.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || &amp;lt;span id=&amp;quot;trans_flg&amp;quot;&amp;gt;trans_flg&amp;lt;/span&amp;gt; || ||&lt;br /&gt;
* 0 =&amp;gt; standard&lt;br /&gt;
* 1 =&amp;gt; non-standard&lt;br /&gt;
|| If this flag is set the field [[#ext_trans|ext_trans]] specifies a transform used to code this band explicitely. Otherwise the default transform is used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;ext_trans&amp;quot;&amp;gt;ext_trans&amp;lt;/span&amp;gt; || [[#trans_flg|trans_flg]] != 0 ||&lt;br /&gt;
* 0 =&amp;gt; 2D Slant&lt;br /&gt;
* 1 =&amp;gt; Row Slant&lt;br /&gt;
* 2 =&amp;gt; Column Slant&lt;br /&gt;
* 3 =&amp;gt; No transform&lt;br /&gt;
|| Specifies a transform that should be used instead of the default transform for this band.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;end_marker&amp;quot;&amp;gt;end_marker&amp;lt;/span&amp;gt; || || always == 0 || End marker terminating this structure.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Table 1 ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | table1_id&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || default&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | counter4&lt;br /&gt;
| 10 || 11 || 12 || 13 || 11 || 13 || 13 || 9&lt;br /&gt;
|-&lt;br /&gt;
! valign=&amp;quot;top&amp;quot; bgcolor=&amp;quot;#f0f0f0&amp;quot; | value19&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 7&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 2&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|-&lt;br /&gt;
| 1&lt;br /&gt;
|}&lt;br /&gt;
| valign=&amp;quot;top&amp;quot; |&lt;br /&gt;
{| border=&amp;quot;0&amp;quot;&lt;br /&gt;
| 3&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 4&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 6&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|-&lt;br /&gt;
| 5&lt;br /&gt;
|}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
default is used when !([[#ph_flags|ph_flags]] &amp;amp; 0x80)&lt;br /&gt;
&lt;br /&gt;
== Games using indeo5 cutscenes ==&lt;br /&gt;
&lt;br /&gt;
* Dino Crisis I: [http://en.wikipedia.org/wiki/Dino_Crisis]&lt;br /&gt;
* Lemmings Revolution: [http://en.wikipedia.org/wiki/Lemmings_Revolution]&lt;br /&gt;
* Mafia: The City of Lost Heaven [http://en.wikipedia.org/wiki/Mafia:_The_City_of_Lost_Heaven]&lt;br /&gt;
* Thief, Parts 1 &amp;amp; 2 : [http://en.wikipedia.org/wiki/Thief_(series)]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13122</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13122"/>
		<updated>2010-11-11T11:20:39Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; ||  || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13121</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13121"/>
		<updated>2010-11-11T09:50:42Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | reserved1 || align=&amp;quot;center&amp;quot; | 0 || Ignored in the decoder v1. It has some meaning in the version 2.0 that need to be clarified.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | reserved2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatFlags&amp;quot;&amp;gt;QMatFlags&amp;lt;/span&amp;gt; ||&lt;br /&gt;
layout: xxxxxxCD where&lt;br /&gt;
* bit C = 1 -&amp;gt; custom [[#QMatLuma|luma quant matrix]] present&lt;br /&gt;
* bit D = 1 -&amp;gt; custom [[#QMatChroma|chroma quant matrix]] present&lt;br /&gt;
|| Custom quantization matrices presence indicators.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatLuma&amp;quot;&amp;gt;QMatLuma&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 0 || Custom quantization matrix for luminance. Only present if indicated by the bit &amp;quot;C&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 64 bytes || align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;QMatChroma&amp;quot;&amp;gt;QMatChroma&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 0 || Custom quantization matrix for chrominance. Only present if indicated by the bit &amp;quot;D&amp;quot; of the [[#QMatFlags|QMatFlags]].&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13103</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13103"/>
		<updated>2010-11-01T12:00:03Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame layout */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | padding2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding3 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13102</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13102"/>
		<updated>2010-11-01T11:59:35Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Binary packages and compatibility */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architecture !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | padding2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding3 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13101</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13101"/>
		<updated>2010-11-01T11:56:20Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Frame header */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architectur !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | version ||&lt;br /&gt;
* &amp;quot;0&amp;quot; - supported in all known decoders&lt;br /&gt;
* &amp;quot;1&amp;quot; - supported in the version 2.0 only&lt;br /&gt;
|| header version.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | padding2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding3 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13100</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13100"/>
		<updated>2010-11-01T11:52:18Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* ProRes 422 Standard Definition / High Quality codec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Binary packages and compatibility ==&lt;br /&gt;
&lt;br /&gt;
ProRes codec is currently available as the following binary libraries:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Lib Name !! Version !! Supported OS !! Supported Architectur !! Encoding !! Decoding&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProRes422.component || align=&amp;quot;center&amp;quot; | 1.0.2 (Build 46) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResDecoder.qtx || align=&amp;quot;center&amp;quot; | 1.0.0.1 || align=&amp;quot;center&amp;quot; | Windows || align=&amp;quot;center&amp;quot; | x86 || align=&amp;quot;center&amp;quot; | No || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | AppleProResCodec.component || align=&amp;quot;center&amp;quot; | 2.0 (Build 224) || align=&amp;quot;center&amp;quot; | Mac OS X || align=&amp;quot;center&amp;quot; | PowerPC/x86 || align=&amp;quot;center&amp;quot; | Yes || align=&amp;quot;center&amp;quot; | Yes&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding1 || align=&amp;quot;center&amp;quot; | 0 || reserved and set to &amp;quot;0&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | padding2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding3 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13046</id>
		<title>Apple ProRes</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=Apple_ProRes&amp;diff=13046"/>
		<updated>2010-10-17T21:41:26Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* ProRes Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* FourCCs used to indicate different ProRes flavours in the [[QuickTime_container|QuickTime]] container:&lt;br /&gt;
** Apple ProRes 422 High Quality: 'apch' ('hcpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Standard Definition: 'apcn' ('ncpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 LT: 'apcs' ('scpa' in little-endian)&lt;br /&gt;
** Apple ProRes 422 Proxy: 'apco' ('ocpa' in little-endian)&lt;br /&gt;
** Apple ProRes 4444: 'ap4h' ('h4pa' in little-endian)&lt;br /&gt;
* Company: [[Apple]]&lt;br /&gt;
* Whitepaper: http://images.apple.com/finalcutstudio/resources/white_papers/L342568A_ProRes_WP.pdf&lt;br /&gt;
* New Whitepaper introducing ProRes LT/Proxy/4444: http://images.apple.com/finalcutstudio/docs/Apple_ProRes_White_Paper_July_2009.pdf&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/V-codecs/HCPA/&lt;br /&gt;
&lt;br /&gt;
= ProRes Introduction =&lt;br /&gt;
&lt;br /&gt;
Apple ProRes is a family of proprietary video codecs used for storing and editing high definition video data in Apple's Final Cut Pro. Apple's official whitepaper lists the codec's key features as being:&lt;br /&gt;
&lt;br /&gt;
* intra-only codecs&lt;br /&gt;
* 4:2:2 / 4:4:4:4 source material&lt;br /&gt;
* 10-bit (12-bit for ProRes 4444) sample depth&lt;br /&gt;
* variable bitrate&lt;br /&gt;
&lt;br /&gt;
[[Category:Video Codecs]]&lt;br /&gt;
[[Category:Undiscovered Video Codecs]]&lt;br /&gt;
&lt;br /&gt;
= ProRes 422 Standard Definition / High Quality codec =&lt;br /&gt;
&lt;br /&gt;
ProRes 422 SD/HQ is the same codec operating on two different bitrates (flavours). Two different FOURCCs are used in order to indicate each flavour:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Flavour name !! FOURCC !! Bitrate&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | Standard Definition (SD) || align=&amp;quot;center&amp;quot; | 'apcn' || align=&amp;quot;center&amp;quot; | 145 Mbps&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | High Quality (HQ) || align=&amp;quot;center&amp;quot; | 'apch' || align=&amp;quot;center&amp;quot; | 220 Mbps&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
ProRes algorithm is based on the [[Discrete_Cosine_Transform | Discrete cosine transform]] (further DCT) and utilizes the following compression techniques:&lt;br /&gt;
&lt;br /&gt;
* custom hybrid [[Golomb|Golomb-Rice]] / [http://en.wikipedia.org/wiki/Exponential-Golomb_coding Exponential Golomb] coding for DCT coefficients&lt;br /&gt;
* [[Run_Length_Encoding|run-lenght coding]]&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
* [[Scalar_Quantization|scalar quantization]]&lt;br /&gt;
&lt;br /&gt;
The bitstream of the ProRes 422 has been designed to provide the following additional features:&lt;br /&gt;
&lt;br /&gt;
* frame-level multi-threaded encoding/decoding depending on available CPU cores&lt;br /&gt;
* spatial scalability providing the possibility to decode a video at different partial resolutions (1/2, 1/4, 1/8 of the full size and so on). ProRes is capable of saving CPU cycles while decoding at smaller resolutions due to a special bitstream layout enabling partial bitstream access and parsing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Frame layout ==&lt;br /&gt;
&lt;br /&gt;
A typical ProRes 422 frame has the following layout:&lt;br /&gt;
&lt;br /&gt;
        Frame container atom&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
            Frame header&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
             Picture 1&lt;br /&gt;
 ------------------------------------&lt;br /&gt;
  Picture 2 (interlaced frames only)&lt;br /&gt;
&lt;br /&gt;
=== Frame container atom ===&lt;br /&gt;
&lt;br /&gt;
At the beginning of each frame the frame container atom is located. It has the classical QuickTime atom structure with the ID set to the undocumented ProRes frame type ID:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | size || align=&amp;quot;center&amp;quot; | frame size in bytes&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | type || align=&amp;quot;center&amp;quot; | 'icpf' (&amp;quot;image codec prores frame&amp;quot;?)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
All data is stored in the big-endian format. The value of the field &amp;quot;size&amp;quot; must match frame size from the movie container.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Frame header ===&lt;br /&gt;
&lt;br /&gt;
A frame header stores description information, such as frame dimension, frame structure (progressive/interlaced), color information and the like.&lt;br /&gt;
All data is stored in the big-endian format.&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Field size !! Field name !! Value !! Description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | hdrSize || || size of this header in bytes. Must be at least 28 bytes long.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding1 || align=&amp;quot;center&amp;quot; | 0 || reserved and set to &amp;quot;0&amp;quot;.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 bytes || align=&amp;quot;center&amp;quot; | vendorID? || align=&amp;quot;center&amp;quot; | 'apl0' || Ignored in all known decoders.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameWidth || || Width of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | frameHeight || || Height of encoded frame.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | frameFlags ||&lt;br /&gt;
layout: AAxxBBxx where&lt;br /&gt;
* bits AA = sample depth?&lt;br /&gt;
* bits BB = frame type:&lt;br /&gt;
** &amp;quot;0&amp;quot; - progressive&lt;br /&gt;
** &amp;quot;1&amp;quot; - interlaced (top-field first)&lt;br /&gt;
** &amp;quot;2&amp;quot; - interlaced (bottom-field first)&lt;br /&gt;
|| Frame structure flags.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 bytes || align=&amp;quot;center&amp;quot; | padding2 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 byte || align=&amp;quot;center&amp;quot; | colorMatrix ||&lt;br /&gt;
* &amp;quot;1&amp;quot; = ITU-R BT.709-2 / SMPTE 274M-1995 / SMPTE 296M-1997&lt;br /&gt;
* &amp;quot;6&amp;quot; = ITU-R BT.601-4 / SMPTE 170M-1994 / SMPTE 293M-1996&lt;br /&gt;
|| Color matrix ID for color conversion between YUV and RGB (see below).&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 bytes || align=&amp;quot;center&amp;quot; | padding3 || align=&amp;quot;center&amp;quot; | 0 || Ignored.&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13033</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13033"/>
		<updated>2010-10-03T17:03:28Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Method D: sequence of numbers in ascending order */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of ATRAC3 ATRAC3plus represents the next generation of the ATRAC codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filter] before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the QMF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding based on modular arithmetic|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
	<entry>
		<id>https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13029</id>
		<title>ATRAC3plus</title>
		<link rel="alternate" type="text/html" href="https://wiki.multimedia.cx/index.php?title=ATRAC3plus&amp;diff=13029"/>
		<updated>2010-10-01T11:50:21Z</updated>

		<summary type="html">&lt;p&gt;Maxpol: /* Value grouping with &amp;quot;group coded&amp;quot; flag */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* Format tag: uses WAVE_FORMAT_EXTENSIBLE with the &amp;quot;SubFormat&amp;quot; field set to the following [[GUID]]: E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
* Company: [[Sony]]&lt;br /&gt;
* Samples: http://samples.mplayerhq.hu/A-codecs/ATRAC3+/&lt;br /&gt;
* Stored in: [[Microsoft_Wave|WAV]] and [[Oma|Oma/Omg]] containers.&lt;br /&gt;
* Official information: http://www.sony.net/Products/ATRAC3/tech/atrac3plus.html&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus introduction =&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a proprietary audio compression algorithm developed by [[Sony]]. As in the case of ATRAC3 ATRAC3plus represents the next generation of the ATRAC codec introduced in 1992 with the MiniDisc. Common use of that codec is in nowel Minidisc players and Portable Playstations made by [[Sony]].&lt;br /&gt;
&lt;br /&gt;
Streams coded with ATRAC3plus are usually stored either in the [[Microsoft_Wave|WAV]] container (those files have the &amp;quot;.at3&amp;quot; extension though) or in the Sony's proprietary [[Oma|Oma/Omg]] container. In the case of the [[Microsoft_Wave|WAV]] container the undocumented [[GUID]]:&lt;br /&gt;
 E923AABF-CB58-4471-A119-FFFA01E4CE62&lt;br /&gt;
is used in order to indicate the ATRAC3plus codec.&lt;br /&gt;
&lt;br /&gt;
There is very limited number of software products supporting encoding/decoding of the ATRAC3plus streams; most of them are unfortunately available for [[Microsoft]] Windows only. Those are:&lt;br /&gt;
&lt;br /&gt;
* Sony's own SonicStage software (Windows only)&lt;br /&gt;
* ATRAC Codec Plugin for Sony Media Software (Windows only)&lt;br /&gt;
* Sonic Studio's expensive N-code plugin for professionals (available for Windows and Mac OS X)&lt;br /&gt;
&lt;br /&gt;
There is a multi-channel version of ATRAC3plus called &amp;quot;ATRAC-X&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
= ATRAC3plus technical documentation =&lt;br /&gt;
&lt;br /&gt;
=== Available bitrates ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus operates on fixed bitrates only. The following bitrates are offered by the Sony Encoding software:&lt;br /&gt;
&lt;br /&gt;
    bitrate      frame size (stereo)&lt;br /&gt;
 -------------   -------------------&lt;br /&gt;
    48 Kbps           280 bytes&lt;br /&gt;
    64 Kbps           376 bytes&lt;br /&gt;
    96 Kbps           560 bytes&lt;br /&gt;
   128 Kbps           744 bytes&lt;br /&gt;
   160 Kbps           936 bytes&lt;br /&gt;
   192 Kbps          1120 bytes&lt;br /&gt;
   256 Kbps          1488 bytes&lt;br /&gt;
   320 Kbps          1864 bytes&lt;br /&gt;
   352 Kbps          2048 bytes&lt;br /&gt;
&lt;br /&gt;
=== Coding techniques ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus is a hybrid subband/MDCT codec like [[MP3]]. The signal is split into 16 subbands using [http://en.wikipedia.org/wiki/Quadrature_mirror_filter Quadrature Mirror Filter] before MDCT and bit allocation. The sample-frame size is 2048 samples per channel.&lt;br /&gt;
&lt;br /&gt;
After the subband splitting ATRAC3plus tries to extract sine waves from each subband using Generalized Harmonic Analysis (further GHA). GHA encodes parameters of extracted sine waves such as frequency, amplitude and phase into final bitstream. &lt;br /&gt;
&lt;br /&gt;
After the sine waves extraction the remained signal (residual) will be transformed into frequency domain by a 128-point [http://en.wikipedia.org/wiki/Modified_discrete_cosine_transform Modified discrete cosine transform]. The resultet MDCT spectrum will be devided into 32 quantization units of unequal width (higher frequencies - wider units). The relationship between QMF bands and quantization units (QU) is shown in the table below:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | QMF subband&lt;br /&gt;
| colspan=&amp;quot;8&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 0&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 1&lt;br /&gt;
| colspan=&amp;quot;4&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 2&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 3&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Quant unit&lt;br /&gt;
| 0 || 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15&lt;br /&gt;
| 16 || 17 || 18 || 19 || 20 || 21 || 22 || 23 || 24 || 25 || 26 || 27 || 28 || 29 || 30 || 31&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The flowchart of the ATRAC3plus decoding process is shown below:&lt;br /&gt;
&lt;br /&gt;
[[image:Atrac3plus_decoder_flow.png]]&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Bitstream decoder&amp;quot; decodes various sound parameters from supplied frame data. First the residual signal will be decoded by applying inverse quantization, power compensation, inverse MDCT and gain compensation. Then the sine waves will be synthesized according with their parameters such as frequency, amplitude and phase. Then the residual and the synthesized sine waves will be added together. Optionally, some white noise can be added if specified in the bitstream.&lt;br /&gt;
&lt;br /&gt;
This processing will be repeated for each of 16 subbands. Finally the QMF synthesis filter will be applied in order to sum all subbands together and reconstruct the encoded audio signal.&lt;br /&gt;
&lt;br /&gt;
Various algorithms are used to improve compression results:&lt;br /&gt;
&lt;br /&gt;
* gain control for reducing pre-echo artifacts&lt;br /&gt;
* power compensation for better quality at low bitrates&lt;br /&gt;
&lt;br /&gt;
The following techniques are used in order to make the compressed data smaller:&lt;br /&gt;
&lt;br /&gt;
* variable-lenght ([[Huffman]]) coding&lt;br /&gt;
* [[Vector_Quantization|vector quantization]] based on trained tables&lt;br /&gt;
* [[Differential_Coding|differential coding]]&lt;br /&gt;
&lt;br /&gt;
Probably the most interesting part of the ATRAC3plus codec is the Generalized Harmonic Analysis (GHA) - an inharmonic frequency analysis proposed by Norbert Wiener in 1930. The main advantage of that is an excellent frequency resolution that surpasses the short-time Discrete Furier transformation. However it requires huge amount of calculations. Several algorithms to work around that problem were introduced during last 20 years, for example the one proposed by Dr.Hirata.&lt;br /&gt;
&lt;br /&gt;
==== Coding methods for compressing bitstream parameters ====&lt;br /&gt;
&lt;br /&gt;
Coding methods described in this section serve the purpose of representing different bitstream parameters like word-length, scale factor etc. using a smaller number of bits. It will be achieved by exploring and removing redundancy from the signals being encoded. The coding techniques described here are [[Lossless_compression|lossless]].&lt;br /&gt;
&lt;br /&gt;
===== Huffman coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus uses this coding technique widely. There are more than 130 different huffman tables in total for coding bitstream signals. Usually more frequently occuring values will have shorter codes.&lt;br /&gt;
ATRAC3plus huffman trees are [http://en.wikipedia.org/wiki/Canonical_Huffman_code canonical ones]. That means those can be stored very compactly by specifying the following parameters:&lt;br /&gt;
&lt;br /&gt;
* number of bits of the shortest codeword&lt;br /&gt;
* number of bits of the longest codeword&lt;br /&gt;
* number of items for every bit length&lt;br /&gt;
* order of items&lt;br /&gt;
&lt;br /&gt;
In my code I'm using the following descriptor in order to specify a canonical huffman table:&lt;br /&gt;
&lt;br /&gt;
 uint8_t min; /* shortest codeword length */&lt;br /&gt;
 uint8_t max; /* longest  codeword length */&lt;br /&gt;
 uint8_t num_items[max - min + 1]; /* number of items for every bit length */&lt;br /&gt;
&lt;br /&gt;
For example, the huffman table vlc_tab_index = 3 [[#Huffman tables for delta coding|here]] will be described as follows:&lt;br /&gt;
&lt;br /&gt;
 min = 1&lt;br /&gt;
 max = 5&lt;br /&gt;
 num_items[1, 0, 2, 3, 2]&lt;br /&gt;
&lt;br /&gt;
The 2nd element of the array &amp;quot;num_items&amp;quot; is set to &amp;quot;0&amp;quot; because there is no codeword with the length of 2 bits.&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode can be used for generating huffman tables from the descriptor described above during decoder initialization:&lt;br /&gt;
&lt;br /&gt;
 code = 0;&lt;br /&gt;
 index = 0;&lt;br /&gt;
 &lt;br /&gt;
 for (num_bits = min; num_bits &amp;lt;= max; num_bits++) {&lt;br /&gt;
     for (i = num_items[num_bits]; i &amp;gt; 0; i--) {&lt;br /&gt;
         bits [index] = num_bits;&lt;br /&gt;
         codes[index] = code++;&lt;br /&gt;
         index++;&lt;br /&gt;
     }&lt;br /&gt;
     code &amp;lt;&amp;lt;= 1;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The array &amp;quot;bits&amp;quot; receives length in bits for each codeword, &amp;quot;codes&amp;quot; receives codeword itself.&lt;br /&gt;
&lt;br /&gt;
Finally, the order of codes need to be specified. A simple remapping table will be used to translate the code index into final code. For the table described above the translation table will look as follows:&lt;br /&gt;
&lt;br /&gt;
 0, 1, 7, 2, 3, 6, 4, 5&lt;br /&gt;
&lt;br /&gt;
===== Delta coding =====&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus utilizes various delta-coding schemes in order to remove linear correlation from the signal. It often uses the [http://en.wikipedia.org/wiki/Modular_arithmetic modular arithmetic] as well. The main advantage of this coding is that only the half of the range of the difference values is required. An example: word-length information coefficients in the range 0...7 need to be transmitted compactly. Using delta coding this would require to code difference values in the range -7...+7, also 15 values.&lt;br /&gt;
&lt;br /&gt;
In the case of modular arithmetic the range of the difference values can be reduced to 0...7 by introducing a &amp;quot;wrap-around&amp;quot; so that the final equation looks like this:&lt;br /&gt;
&lt;br /&gt;
 B = (A + delta) &amp;amp; 7;&lt;br /&gt;
&lt;br /&gt;
Below an example with &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;1&amp;quot; and the reference value A = &amp;quot;6&amp;quot;. Then the difference value (delta) will be = &amp;quot;-5&amp;quot;. According with equation above the delta value of &amp;quot;3&amp;quot; can be used instead of &amp;quot;-5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (6 + 3) &amp;amp; 7 = 1;&lt;br /&gt;
&lt;br /&gt;
Another example without &amp;quot;wrap around&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
Consider we need to code the value B = &amp;quot;7&amp;quot; and the reference value A = &amp;quot;2&amp;quot;. Then the difference value (delta) will be = &amp;quot;5&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
 (2 + 5) &amp;amp; 7 = 7;&lt;br /&gt;
&lt;br /&gt;
Further variable-length codes will be used to reduce amount of bits of difference values in accordance with their probability.&lt;br /&gt;
&lt;br /&gt;
The following is a description of the delta-coding methods used in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
====== Method A: huffman-coded modulo difference to previous ======&lt;br /&gt;
&lt;br /&gt;
Consider the following signal:&lt;br /&gt;
&lt;br /&gt;
 3, 6, 6, 3, 3, 3, 4, 2, 2, 1, 1, 1, 3&lt;br /&gt;
&lt;br /&gt;
Now code it using delta coding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Coefficient !! Modulo delta value !! Huffman code !! Number of bits&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | - || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The 1st coefficient has no delta value associated with it because there is no previous value. It will be coded &amp;quot;as is&amp;quot; using fixed length of 3 bits. The following delta values get a variable-length code from the table val_tab_index = 2 [[#Huffman tables for delta coding|here]] so the final number of bits to be transmitted will be = 32.&lt;br /&gt;
Compared to the unpacked version (13 x 3 bits = 39 bits) the coding method described above will yield a bit-reduction of 7 bits (18% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method B: huffman-coded modulo difference to master ======&lt;br /&gt;
&lt;br /&gt;
In a stereo mix the signal of the left channel is often very similar to the signal of the right channel (i.e. there is a high cross-correlation between the channels). In this case the estimated sound parameters like word-length or scale factor will have a high similarity as well. Then coding the differential signal between the channels can lead to a significant bit reduction.&lt;br /&gt;
Surely at least the one of the channels must be coded independently. Such a channel will be called &amp;quot;master&amp;quot; (it's usually the left channel but ATRAC3plus has the possibility to make the right channel act like a master as well). For the 2nd channel only the difference to master will be coded. The 2nd channel will be called &amp;quot;slave&amp;quot; in this case.&lt;br /&gt;
&lt;br /&gt;
Below an example of such a high-correlated signal:&lt;br /&gt;
&lt;br /&gt;
 Left : 6, 5, 6, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1&lt;br /&gt;
 Right: 6, 5, 6, 2, 2, 2, 3, 1, 1, 1, 2, 1, 1&lt;br /&gt;
 Diff : 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0&lt;br /&gt;
&lt;br /&gt;
Coding the difference signal using the table val_tab_index = 0 [[#Huffman tables for delta coding|here]] will result in another signal 15 bits long. Compared to the unpacked version (13 x 3 bits = 39 bits) that coding method will yield a bit-reduction of 24 bits (62% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method C: shorter delta to min ======&lt;br /&gt;
&lt;br /&gt;
Sometimes coefficients in a signal are very close to each other, so subtracting the minimum value from each coefficient will result in smaller deltas whose can be coded using fewer bits.&lt;br /&gt;
&lt;br /&gt;
An example:&lt;br /&gt;
&lt;br /&gt;
 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1&lt;br /&gt;
&lt;br /&gt;
As one can see the values in the sequence above are very similar to each other. Let us find minimum and maximum values and then determine the number of delta bits:&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 2; num_delta_bits = ilog2(max - min + 1) = 1 bit&lt;br /&gt;
&lt;br /&gt;
Now let us encode the sequence above using shorter deltas:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 1 will be coded as a 2-bit value&lt;br /&gt;
 min = 1 will be coded as a 3-bit value&lt;br /&gt;
 deltas: 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 1 x 15 = 20 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 25 bits (55% smaller).&lt;br /&gt;
&lt;br /&gt;
Another example:&lt;br /&gt;
&lt;br /&gt;
 1, 2, 3, 2, 4, 2, 1, 2, 3, 3, 1, 4, 4, 1, 1&lt;br /&gt;
&lt;br /&gt;
 min = 1; max = 4; num_delta_bits = ilog2(max - min + 1) = 2 bits&lt;br /&gt;
&lt;br /&gt;
Now the encoded signal:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = 2 (will be coded as a 2-bit value)&lt;br /&gt;
 min = 1 (will be coded as a 3-bit value)&lt;br /&gt;
 deltas: 0, 1, 2, 1, 3, 1, 0, 1, 2, 2, 0, 3, 3, 0, 0&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 5 + 2 x 15 = 35 bits long while the unpacked one is 15 x 3 = 45 bits long. The bit-reduction is thereafter 10 bits (22% smaller).&lt;br /&gt;
&lt;br /&gt;
====== Method D: sequence of numbers in ascending order ======&lt;br /&gt;
&lt;br /&gt;
Sometimes ATRAC3plus have to deal with sequences of numbers (i.e. gain control position information) where all items are known to be in ascending order (i.e. satisfy the following equation: ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;''). Such sequences can be packed without any additional bitstream information by examining previous value (predecessor), calculating magnitude between it and the maximum value and making the decision about number of bits of the next delta value.&lt;br /&gt;
&lt;br /&gt;
Consider the following sequence:&lt;br /&gt;
&lt;br /&gt;
 Position index: 0,  1,  2,  3,  4,  5,  6,  7&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Position info : 5,  7, 14, 15, 18, 25, 29, 30&lt;br /&gt;
 ---------------------------------------------&lt;br /&gt;
 Num delta bits: 5,  5,  5,  4,  4,  3,  1,  0&lt;br /&gt;
&lt;br /&gt;
1st coefficient (position index = 0) will be coded directly using 5 bits because the sequence should start somewhere.&lt;br /&gt;
The following coefficients (except one with the value of &amp;quot;30&amp;quot;) will be coded according to the following pseudocode:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog2(31 - prev_val);&lt;br /&gt;
 if (num_delta_bits == 5)&lt;br /&gt;
     new_val = get_bits(5);&lt;br /&gt;
 else&lt;br /&gt;
     new_val = prev_val + get_bits(num_delta_bits) + 1;&lt;br /&gt;
&lt;br /&gt;
Let us return to our sequence. The 2nd value will be coded directly as well using 5 bits because ilog2(31 - 5) = 5. Similar for the 3rd one. No delta coding is applied in that case. The 4th value will be delta-coded using 4 bits:&lt;br /&gt;
&lt;br /&gt;
 num_delta_bits = ilog(31 - 15) = 4 bits;&lt;br /&gt;
 delta = 18 - 15 - 1 = 2&lt;br /&gt;
&lt;br /&gt;
And so on until we reach the last value = 30. In this case there is only one value that meets our condition ''V&amp;lt;sub&amp;gt;n+1&amp;lt;/sub&amp;gt; &amp;gt; V&amp;lt;sub&amp;gt;n&amp;lt;/sub&amp;gt;'': the value of &amp;quot;31&amp;quot;. In this case no delta will be transmitted and the coming value will be calculated just as:&lt;br /&gt;
&lt;br /&gt;
 new_val = prev_val + 1;&lt;br /&gt;
&lt;br /&gt;
Therefore the resulting sequence will be 27 bits long. Compared to the unpacked version (8 x 5 bits = 40 bits) this packing method will yield a bit-reduction of 13 bits (32% smaller).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Vector quantization with residual encoding =====&lt;br /&gt;
&lt;br /&gt;
One further packing technique used in ATRAC3plus is based on so-called &amp;quot;shape prediction vectors&amp;quot;. Encoder decomposes a signal (word-length or scale factor info) into &amp;quot;shape prediction&amp;quot; + residual. Then only the index of the &amp;quot;shape prediction vector&amp;quot; and the huffman-coded residual will be transmitted. The main advantage of this method is when the shape matches the coded signal closely, the residual can be represented very compactly (usually 1-2 bits per value). Moreover, the majority of values of the residual will turn into zeroes, which can be further packed.&lt;br /&gt;
&lt;br /&gt;
Each entry of the &amp;quot;shape prediction tables&amp;quot; contain an average value over 3 coefficients. This helps to keep those tables comparable small. For example, for a signal of 32 values each &amp;quot;shape table&amp;quot; will have 10 entries (last entry contains usually an average value over 5 coefficients).&lt;br /&gt;
&lt;br /&gt;
Consider the following signal to be encoded:&lt;br /&gt;
&lt;br /&gt;
 7, 7, 6, 5, 4, 4, 3, 2, 2, 2, 1, 1&lt;br /&gt;
&lt;br /&gt;
Let us &amp;quot;quantize&amp;quot; that signal by diving it into 4 * 3 groups and find the averaged value in each group:&lt;br /&gt;
&lt;br /&gt;
 floor((7 + 7 + 6) / 3 + 0.5) = 7,&lt;br /&gt;
 floor((5 + 4 + 4) / 3 + 0.5) = 4,&lt;br /&gt;
 floor((3 + 2 + 2) / 3 + 0.5) = 2,&lt;br /&gt;
 floor((2 + 1 + 1) / 3 + 0.5) = 1&lt;br /&gt;
&lt;br /&gt;
Find a &amp;quot;shape table&amp;quot; in the trained set that closely matches our &amp;quot;quantized&amp;quot; version. It will be (for example):&lt;br /&gt;
 7, 5, 2, 1&lt;br /&gt;
&lt;br /&gt;
Now compute the residual:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Original signal&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 7&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 6&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 5&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| style=&amp;quot;text-align:center;&amp;quot;| 4&lt;br /&gt;
| 3 || 2 || 2 || 2 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Unpacked shape table&lt;br /&gt;
| 7 || 7 || 7 || 5 || 5 || 5 || 2 || 2 || 2 || 1 || 1 || 1&lt;br /&gt;
|-&lt;br /&gt;
! bgcolor=&amp;quot;#f0f0f0&amp;quot; | Residual&lt;br /&gt;
| 0 || 0 || -1 || 0 || -1 || -1 || 1 || 0 || 0 || 1 || 0 || 0&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Now select a huffman table that represents the residual above as small as possible. The following huffman tree assigns the shortest code (1 bit) to the most frequently occuring symbol = &amp;quot;0&amp;quot; and 2-bit codes to the others: &amp;quot;1&amp;quot; and &amp;quot;-1&amp;quot;:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | -1&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The packed signal will occupy 21 bits: 4 bits &amp;quot;shape table&amp;quot; index + 17 bits residual(7 bits for &amp;quot;zeroes&amp;quot; + 10 bits for &amp;quot;non-zeroes&amp;quot;). Compared to the unpacked version (12 x 3 bits = 36 bits) this packing method will yield a bit-reduction of 15 bits (42% smaller).&lt;br /&gt;
&lt;br /&gt;
===== Value grouping with &amp;quot;group coded&amp;quot; flag =====&lt;br /&gt;
&lt;br /&gt;
If a signal contains lots of zeroes, grouping several values together and assigning the &amp;quot;group coded&amp;quot; flag to each group will achieve a significant bit-reduction. Consider the following sequence of numbers to be encoded:&lt;br /&gt;
&lt;br /&gt;
 0, 0, 1, 2, 0, 0, 3, 3, 0, 0, 0, 7, 0, 6, 0, 0&lt;br /&gt;
&lt;br /&gt;
Let us cluster each two values together and assign the &amp;quot;coded&amp;quot; flag (1 bit) to each group:&lt;br /&gt;
&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (1, 2); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (3, 3); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
 (0, 7); flag = 1 (group coded)&lt;br /&gt;
 (0, 6); flag = 1 (group coded)&lt;br /&gt;
 (0, 0); flag = 0 (group not coded)&lt;br /&gt;
&lt;br /&gt;
Thereafter, each &amp;quot;not coded&amp;quot; group requires only one bit to be transmitted indicating that all values in that group are zero. On the other hand, each &amp;quot;coded&amp;quot; group requires one extra bit to be transmitted indicating that at least one value in that group is non-zero. In the case above that overhead is worthwhile because the half of the signal contains zeroes.&lt;br /&gt;
&lt;br /&gt;
The encoded signal is 4 x 1 + 4 x 7 = 32 bits long while the unpacked one is 16 x 3 = 48 bits long. The bit-reduction is thereafter 16 bits (33% smaller).&lt;br /&gt;
&lt;br /&gt;
== Multichannel ATRAC3plus (ATRAC-X) ==&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus supports multichannel streams (up to 8 channels). Such streams are encoded in units customary called &amp;quot;channel block&amp;quot;; each block contains max. 2 channels (ie can be MONO or STEREO). For example, taking the channel_id = 3 and looking at the table below we have a stream containing 2 channel blocks: 1 stereo + 1 mono and thus 3 channels.&lt;br /&gt;
The base codec operates on either MONO or STEREO channel blocks only.&lt;br /&gt;
&lt;br /&gt;
=== ATRAC-X channel configurations ===&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! channel_id !! total channels !! number of channel blocks !! speaker mapping&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | undefined ||&lt;br /&gt;
* undefined&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: center (MONO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1 ||&lt;br /&gt;
* front: L, R (STEREO)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: surround&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5+1 || align=&amp;quot;center&amp;quot; | 4 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 6 || align=&amp;quot;center&amp;quot; | 6+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* rear: center&lt;br /&gt;
* LFE&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 7 || align=&amp;quot;center&amp;quot; | 7+1 || align=&amp;quot;center&amp;quot; | 5 ||&lt;br /&gt;
* front: L, R&lt;br /&gt;
* front: center&lt;br /&gt;
* rear: L, R&lt;br /&gt;
* side: L, R&lt;br /&gt;
* LFE&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Bitstream overview ==&lt;br /&gt;
&lt;br /&gt;
The table below shows the bitstream organization of ATRAC3plus at the top-level. Depends on [[#ATRAC-X channel configurations|channel configuration]] a typical frame may contain more than one channel block. In this case the additional fields [[#channel_block_type|channel_block_type]] and [[#channel_block_data|channel_block_data]] will be included for each block.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! number of bits !! value !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | start_marker || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0 ||&lt;br /&gt;
marks the start of the ATRAC3plus bitstream&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_type&amp;quot;&amp;gt;channel_block_type&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | 2 ||&lt;br /&gt;
* 00b - MONO block&lt;br /&gt;
* 01b - STEREO block&lt;br /&gt;
* 10b - EXTENSION block&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | type of the channel block&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | &amp;lt;span id=&amp;quot;channel_block_data&amp;quot;&amp;gt;channel_block_data&amp;lt;/span&amp;gt; || align=&amp;quot;center&amp;quot; | variable || || align=&amp;quot;center&amp;quot; | contains encoded sound information&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | terminator || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 11b || align=&amp;quot;center&amp;quot; | indicates the end of the bitstream&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Channel block types ===&lt;br /&gt;
&lt;br /&gt;
There are following channel block types in ATRAC3plus:&lt;br /&gt;
&lt;br /&gt;
* '''Mono channel block''': contains monaural sound data.&lt;br /&gt;
* '''Stereo channel block''': contains stereophonic sound data.&lt;br /&gt;
* '''Extension block''': as indicated by its name it's intended to carry some extension information. Its purpose is unknown though due to the lack of an official description. All existing decoder implementations are programmed to ignore blocks of that type.&lt;br /&gt;
&lt;br /&gt;
=== Channel block layout ===&lt;br /&gt;
&lt;br /&gt;
ATRAC3plus was designed to provide a high-quality sound compression. Therefore it tries to save as much bits as possible. It uses a new coding scheme for channel blocks compared to ATRAC3: channels in a stereo sound are no more coded separately but rather in one stereo channel block. The bitstream for such a block provides the possibility for both channels to share several sound parameters so that there is no need to transmit the same things twice. Depends on correlation between the channels this can lead to a significant bit reduction and thus improve coding quality.&lt;br /&gt;
&lt;br /&gt;
A mono/stereo channel block contains the following pieces of sound information:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! name !! size in bits !! description&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Sound header|sound_header]] || align=&amp;quot;center&amp;quot; | 6 || width=&amp;quot;700&amp;quot; | defines some global sound parameters&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | [[#Word-length information|wordlength_info]] || align=&amp;quot;center&amp;quot; | variable || quantization word length information for each quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | scalefactor_info || align=&amp;quot;center&amp;quot; | variable || quantization scale factor indexes for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | codetable_info || align=&amp;quot;center&amp;quot; | variable || code table table information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | spectra || align=&amp;quot;center&amp;quot; | variable || huffman-coded spectral information for each coded quant unit&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | window_info || align=&amp;quot;center&amp;quot; | variable || tells which IMDCT window shape should be used during the sound reconstruction&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gain_info || align=&amp;quot;center&amp;quot; | variable || gain envelope used by the gain compensation&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | gha_info || align=&amp;quot;center&amp;quot; | variable || information about sine-like waves in the compressed sound obtained by the GHA. It contains quantized frequency, amplitude and phase for each wave to be synthesized in the decoder.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | noise_info || align=&amp;quot;center&amp;quot; | 1/9 || contains noise flag, level index and table selector for the white noise to be added during decoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Sound header ====&lt;br /&gt;
&lt;br /&gt;
At the start of each channel block the sound header is located. It contains the following fields:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! value(s) !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 5 || &amp;lt;span id=&amp;quot;num_quant_units&amp;quot;&amp;gt;num_quant_units&amp;lt;/span&amp;gt; || valid values: 0...27,31 || width=&amp;quot;500&amp;quot; | number of coded quantization units - 1. The value of &amp;quot;0&amp;quot; indicates one coded unit, the value of &amp;quot;31&amp;quot; - 32 ones. The values 28, 29 and 30 are invalid.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | x_flag ||  || to be figured out&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Word-length information ====&lt;br /&gt;
&lt;br /&gt;
===== Coding summary =====&lt;br /&gt;
&lt;br /&gt;
Word-length (or quantization precision) information follows the sound header. It defines the word-length parameter for each [[#num_quant_units|coded quantization unit]]. This parameter is in the range 0...7, where the value of &amp;quot;7&amp;quot; indicates the highest quantization precision and the value of &amp;quot;1&amp;quot; - the lowest one. The value of &amp;quot;0&amp;quot; means no data, i.e. the corresponding quantization unit was not coded.&lt;br /&gt;
&lt;br /&gt;
In the case of the stereo channel block the word-length parameters for the channel 1(L) will be transmitted first followed by the the word-length parameters for the channel 2(R). The word-lengths for the channel 1 are always coded independently. The word-lengths for the channel 2 can be coded either independently or relative to the channel 1. In this case the 1st channel is called &amp;quot;master&amp;quot; and the 2nd one - &amp;quot;slave&amp;quot;.&lt;br /&gt;
The word-lengths for the mono block will be coded just like the channel 1 in the stereo block.&lt;br /&gt;
&lt;br /&gt;
In order to keep the word-length data as small as possible ATRAC3plus uses several coefficient packing techniques achieving different amount of bits needed for transmission:&lt;br /&gt;
&lt;br /&gt;
* the coefficients are coded directly (3 bits value). This means no packing and used at high bitrates because the frame size is big enough to keep the infomation unpacked.&lt;br /&gt;
&lt;br /&gt;
* differential coding + huffman-coded delta: the first coefficient is coded directly; all others are huffman-coded deltas to the previous coefficient.&lt;br /&gt;
&lt;br /&gt;
* prediction + huffman-coded residual: this techniques offers the best packing and used at low bitrates. It's analogous to the lossless coding and based on trained shape tables serving as prediction. Later the huffman-coded residual will be added to the prediction prefectly reconstructing the coefficients.&lt;br /&gt;
&lt;br /&gt;
===== Reconstruction of trimmed word-length coefficients =====&lt;br /&gt;
&lt;br /&gt;
Word-length coefficient of the trailing quantization units corresponding to the high spectral bands tend to be either 1 (low-precision) or 0 (not coded). Such coefficients will be ommited and one the following modes will be used in order to reconstruct their values during decoding:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! mode code(2 bits) !! &amp;lt;span id=&amp;quot;num_coded_vals&amp;quot;&amp;gt;num_coded_vals&amp;lt;/span&amp;gt; !! &amp;lt;span id=&amp;quot;split_point_delta&amp;quot;&amp;gt;split_point_delta&amp;lt;/span&amp;gt; !! Action(master) !! Action(slave)&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | not present&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | not present&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | no trimmed coefficients&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|rowspan=&amp;quot;3&amp;quot; style=&amp;quot;text-align:center;&amp;quot; | 5 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients to &amp;quot;0&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || width=&amp;quot;220&amp;quot; | set all trimmed coefficients to &amp;quot;1&amp;quot; || width=&amp;quot;220&amp;quot; | for each trimmed coefficient read one bit of its direct value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2 bits&lt;br /&gt;
|colspan=&amp;quot;2&amp;quot; style=&amp;quot;text-align:center;&amp;quot;| set all trimmed coefficients up to split point to &amp;quot;1&amp;quot; and after split point - to &amp;quot;0&amp;quot;. The split point is calculated differently for master and slave channels (see below)&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
To calculate the split point from [[#split_point_delta|split_point_delta]] do the following:&lt;br /&gt;
&lt;br /&gt;
* for the master channel: number of zeroes = split_point_delta + 1&lt;br /&gt;
* for the slave  channel: number of ones   = split_point_delta + 3&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to parse a bitstream according with the table above:&lt;br /&gt;
&lt;br /&gt;
 mode = get_bits(2);&lt;br /&gt;
 if (mode) {&lt;br /&gt;
     num_coded_vals = get_bits(5);&lt;br /&gt;
     if (mode == 3)&lt;br /&gt;
         split_point_delta = get_bits(2);&lt;br /&gt;
 } else {&lt;br /&gt;
     num_coded_vals = [[#num_quant_units|num_quant_units]];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode shows how to reconstruct trimmed word-length coefficients according with the table above:&lt;br /&gt;
&lt;br /&gt;
 switch (mode) {&lt;br /&gt;
 case 0: /* no further action */&lt;br /&gt;
     break;&lt;br /&gt;
 case 1:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
     break;&lt;br /&gt;
 case 2:&lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++) {&lt;br /&gt;
         if (channel == master)&lt;br /&gt;
             wl_coeffs[pos] = 1;&lt;br /&gt;
         else&lt;br /&gt;
             wl_coeffs[pos] = get_bits(1);&lt;br /&gt;
     }&lt;br /&gt;
     break;&lt;br /&gt;
 case 3:&lt;br /&gt;
     if (channel == master)&lt;br /&gt;
         split_point = [[#num_quant_units|num_quant_units]] - split_point_delta - 1;&lt;br /&gt;
     else&lt;br /&gt;
         split_point = num_coded_vals + split_point_delta + 3;&lt;br /&gt;
 &lt;br /&gt;
     for (pos = num_coded_vals; pos &amp;lt; split_point; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 1;&lt;br /&gt;
 &lt;br /&gt;
     for (; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===== Word-length coding in detail =====&lt;br /&gt;
&lt;br /&gt;
The word-length information for each channel will be coded as follows:&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! size in bits !! name !! comments&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 2 || &amp;lt;span id=&amp;quot;coding_mode&amp;quot;&amp;gt;coding_mode&amp;lt;/span&amp;gt; || width=&amp;quot;500&amp;quot; | indicates the coding mode used.&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | variable || align=&amp;quot;center&amp;quot; | coeff_info || word-length coefficients coded according with the [[#coding_mode|coding_mode]].&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The [[#coding_mode|coding_mode]] parameter may be interpreted differently depends on the channel number. The following pseudocode examples explain the coding modes in detail:&lt;br /&gt;
&lt;br /&gt;
===== Mode 0 (master and slave) =====&lt;br /&gt;
&lt;br /&gt;
All coefficients will be directly coded as follows:&lt;br /&gt;
&lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_quant_units|num_quant_units]]; i++)&lt;br /&gt;
      wl_coeffs[i] = get_bits(3);&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (master) =====&lt;br /&gt;
&lt;br /&gt;
Leading &amp;quot;n&amp;quot; values are stored directly while trailing ones are packed using [[#Method C: shorter delta to min|Method C: shorter delta to min]] method.&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2 bits: index of the table of weigths, &amp;quot;0&amp;quot; - indicates &amp;quot;no table used&amp;quot;&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 5 bits: number of directly coded coefficients ('''num_direct_coeffs'''). This value must be &amp;lt; [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
* 2 bits: size of deltas in bits ('''delta_bits''')&lt;br /&gt;
* 3 bits: minimum value ('''min_value''')&lt;br /&gt;
* for each '''num_direct_coeffs'''&lt;br /&gt;
** 3 bits: coefficient value&lt;br /&gt;
* if '''delta_bits''' &amp;gt; 0: for each ([[#num_coded_vals|num_coded_vals]] - '''num_direct_coeffs''')&lt;br /&gt;
** '''delta_bits''': delta value to be added to the '''min_value'''&lt;br /&gt;
&lt;br /&gt;
The following C-pseudocode summarizes all above:&lt;br /&gt;
&lt;br /&gt;
 weigths_tab_indx = get_bits(2); /* get index of weights table to be added after decoding */&lt;br /&gt;
 &lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 num_direct_coeffs = get_bits(5);&lt;br /&gt;
 if (num_direct_coeffs &amp;gt; [[#num_coded_vals|num_coded_vals]])&lt;br /&gt;
     ABORT(&amp;quot;Invalid number of directly coded coefficients&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 delta_bits = get_bits(2);&lt;br /&gt;
 min_value  = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (pos = 0; pos &amp;lt; num_direct_coeffs; pos++)&lt;br /&gt;
     wl_coeffs[pos] = get_bits(3);&lt;br /&gt;
 &lt;br /&gt;
 for (; pos &amp;lt; num_coded_vals; pos++) {&lt;br /&gt;
     if (delta_bits)&lt;br /&gt;
         wl_coeffs[pos] = min_value + get_bits(delta_bits);&lt;br /&gt;
     else&lt;br /&gt;
         wl_coeffs[pos] = min_value;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 /* reconstruct trimmed coefficients as described [[#Reconstruction of trimmed word-length coefficients|here]] */&lt;br /&gt;
 &lt;br /&gt;
 /* add weighting coefficients if requested */&lt;br /&gt;
 if (weigths_tab_indx) {&lt;br /&gt;
     for (pos = 0; pos &amp;lt; [[#num_quant_units|num_quant_units]]; pos++)&lt;br /&gt;
         wl_coeffs[pos] = [[#Tables of weights|wl_weights]][channel_num][weights_tab_indx - 1][pos];&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 1 (slave) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Method B: huffman-coded modulo difference to master|Huffman-coded modulo difference to master]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]]&lt;br /&gt;
* 2 bits: indicates which huffman table from [[#Huffman tables for delta coding|this set]] should be used for decoding&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** huffman-coded delta value to be added to the corresponding value of the master channel&lt;br /&gt;
&lt;br /&gt;
 /* parse mode/num_coded_vals/split_point_delta parameters for [[#Reconstruction of trimmed word-length coefficients|trimmed coefficients]] */&lt;br /&gt;
 &lt;br /&gt;
 vlc_sel = get_bits(2); /* selects a huffman table from [[#Huffman tables for delta coding|this set]] */&lt;br /&gt;
 &lt;br /&gt;
 for (i = 0; i &amp;lt; [[#num_coded_vals|num_coded_vals]]; i++) {&lt;br /&gt;
     delta = get_vlc(vlc_sel);&lt;br /&gt;
     wl_coeffs[i] = (master_ch-&amp;gt;wl_coeffs[i] + delta) &amp;amp; 7;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
===== Mode 2 (master) =====&lt;br /&gt;
&lt;br /&gt;
Coding method: [[#Vector quantization with residual encoding|Vector quantization with residual encoding]] and [[#Value grouping with &amp;quot;group coded&amp;quot; flag|Value grouping with &amp;quot;group coded&amp;quot; flag]].&lt;br /&gt;
&lt;br /&gt;
Data stored in the bitstream:&lt;br /&gt;
&lt;br /&gt;
* 2/7/9 or more bits (depending on mode): info for the [[#Reconstruction of trimmed word-length coefficients|reconstruction of trimmed coefficients]].&lt;br /&gt;
* 1 bit: '''enable_grouping''' flag. &amp;quot;1&amp;quot; indicates that residual values were coded pairwise (in groups of two).&lt;br /&gt;
* 1 bit: selects one of the first two huffman tables from [[#Huffman tables for delta coding|this set]].&lt;br /&gt;
* 3 bits: '''start_value''' selecting a subset of &amp;quot;shape tables&amp;quot; from the trained set.&lt;br /&gt;
* 4 bits: '''shape_index''' selecting a &amp;quot;shape table&amp;quot; within the subset indicated by '''start_value'''.&lt;br /&gt;
* for each [[#num_coded_vals|num_coded_vals]]&lt;br /&gt;
** if '''enable_grouping''' == 1:&lt;br /&gt;
*** 1 bit: '''group_coded''' flag&lt;br /&gt;
*** if '''group_coded''' == 1:&lt;br /&gt;
**** 2 huffman-coded residual values to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
** if '''enable_grouping''' == 0:&lt;br /&gt;
*** one huffman-coded residual value to be added to the unpacked &amp;quot;shape table&amp;quot; using modular arithmetic&lt;br /&gt;
&lt;br /&gt;
== Annex A: Decoding tables  ==&lt;br /&gt;
&lt;br /&gt;
=== Word-length related tables ===&lt;br /&gt;
&lt;br /&gt;
==== Tables of weights ====&lt;br /&gt;
&lt;br /&gt;
The weights below will be added to the decoded word-length coefficients. The tables are organized as follows:&lt;br /&gt;
* [channel_number: 0 or 1][index: 0...2][coeff_indx: 0...31]&lt;br /&gt;
&lt;br /&gt;
 wl_weights[2][3][32] = {&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0},&lt;br /&gt;
     },&lt;br /&gt;
     {&lt;br /&gt;
         {5, 5, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},&lt;br /&gt;
         {6, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== Huffman tables for delta coding ====&lt;br /&gt;
&lt;br /&gt;
PLEASE NOTE: delta values indicated in the tables below will be added using modular arithmetic as described [[#Delta coding based on modular arithmetic|here]], so in the case of &amp;quot;wrap around&amp;quot; the value of &amp;quot;7&amp;quot; will be treated as &amp;quot;-1&amp;quot;, the value of &amp;quot;6&amp;quot; = &amp;quot;-2&amp;quot; and so on.&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 0''', delta range -1...1&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 10 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11 || align=&amp;quot;center&amp;quot; | 2 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 1''', delta range -2...2&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 110 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 111 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 2''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* '''vlc_tab_index = 3''', delta range 0...7 (-4...3)&lt;br /&gt;
&lt;br /&gt;
{| border=&amp;quot;1&amp;quot; cellpadding=&amp;quot;5&amp;quot; style=&amp;quot;border-collapse: collapse; border-style: dashed; border-color: #2f6fab;&amp;quot;&lt;br /&gt;
|- bgcolor=&amp;quot;#f0f0f0&amp;quot; |&lt;br /&gt;
! Huffman code !! Number of bits !! Delta value&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 0 || align=&amp;quot;center&amp;quot; | 1 || align=&amp;quot;center&amp;quot; | 0&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 100 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 1&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 101 || align=&amp;quot;center&amp;quot; | 3 || align=&amp;quot;center&amp;quot; | 7&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1100 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 2&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1101 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 3&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 1110 || align=&amp;quot;center&amp;quot; | 4 || align=&amp;quot;center&amp;quot; | 6&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11110 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 4&lt;br /&gt;
|-&lt;br /&gt;
| align=&amp;quot;center&amp;quot; | 11111 || align=&amp;quot;center&amp;quot; | 5 || align=&amp;quot;center&amp;quot; | 5&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Audio Codecs]]&lt;br /&gt;
[[Category: Multichannel Audio Codecs]]&lt;br /&gt;
[[Category: QMF Audio Codecs]]&lt;br /&gt;
[[Category: MDCT Audio Codecs]]&lt;/div&gt;</summary>
		<author><name>Maxpol</name></author>
	</entry>
</feed>