6fad84b75e8ddfc99a17ad9739e7e42e6b40519c
[platform/upstream/libvorbis.git] / doc / vorbis-spec-res.html
1 <HTML><HEAD><TITLE>xiph.org: Ogg Vorbis documentation</TITLE>
2 <BODY bgcolor="#ffffff" text="#202020" link="#006666" vlink="#000000">
3 <nobr><img src="white-ogg.png"><img src="vorbisword2.png"></nobr><p>
4
5 <h1><font color=#000070>
6 Ogg Vorbis I format specification: residue setup and decode
7 </font></h1>
8
9 <em>Last update to this document: July 18, 2002</em><br>
10
11 <h1>Overview</h1>
12
13 A residue vector represents the fine detail of the audio spectrum of
14 one channel in an audio frame after the encoder subtracts the floor
15 curve and performs any channel coupling.  A residue vector may
16 represent spectral lines, spectral magnitude, spectral phase or
17 hybrids as mixed by channel coupling.  The exact semantic content of
18 the vector does not matter to the residue abstraction.<p>
19
20 Whatever the exact qualities, the Vorbis residue abstraction codes the
21 residue vectors into the bitstream packet, and then reconstructs the
22 vectors during decode.  Vorbis makes use of three different encoding
23 variants (numbered 0, 1 and 2) of the same basic vector encoding
24 abstration.<p>
25
26 <h1>Residue format</h1>
27
28 Reside format takes the bundles of vectors, partitions the vectors
29 into chunks, classifies each chunk, encodes the chunk classifications
30 and finally encodes the chunks using the the specific VQ arrangement
31 defined for each selected selected classification.  The exact
32 interleaving and partitioning vary by residue encoding number, however
33 the high-level process used to classify and encode the residue vector
34 is the same in all three variants.<p>
35
36 A set of coded residue vectors are all of the same length.  High level
37 coding structure, ignoring for the moment exactly how a partition is
38 encoded and simply trusting that it is, is as follows:<p>
39
40 <ul>
41 <li>Each vector is partitioned into multiple equal sized chunks
42 according to configuration specified.  If we have a vector size of
43 <i>n</i>, a partition size <i>residue_partition_size</i>, and a total
44 of <i>ch</i> residue vectors, the total number of paritioned chunks
45 coded is <i>n</i>/<i>residue_partition_size</i>*<i>ch</i>.  It is
46 important to note that the integer division truncates.  In the below
47 example, we assume an example <i>residue_partition_size</i> of 8.<p>
48
49 <li>Each partition in each vector has a classification number that
50 specifies which of multiple configured VQ codebook setups are used to
51 decode that partition.  The classification numbers of each partition
52 can be thought of as forming a vector, as in the illustration below.
53 Just as the residue vectors are coded in grouped partitions to
54 increase encoding efficiency, the classification vector is also
55 partitioned into chunks.  The integer elements of each scalar in a
56 classification chunk are built into a single scalar that represents
57 the classification numbers in that chunk.  In the below example, the
58 classification codeword encodes two classification numbers.<p>
59
60 <li>The values in a residue vector may be encoded monolithically in a
61 single pass through the residue vector, but more often efficient
62 codebook design dictates that each vector is encoded as the additive
63 sum of several passes through the residue vector using more than one
64 VQ codebook.  Thus, each residue value potentially accumulates values
65 from multiple decode passes.  The classification value associated with
66 a partition is the same in each pass, thus the classification codeword
67 is coded only in the first pass.<p>
68
69 </ul>
70
71 <img src="residue-pack.png"><p>
72
73 <h2>residue 0</h2>
74
75 Residue 0 and 1 differ only in the way the values within a residue
76 partition are interleaved during partition encoding (visually treated
77 as a black box- or cyan box or brown box- in the above figure).<p>
78
79 Residue encoding 0 interleaves VQ encoding according to the
80 dimension of the codebook used to encode a partition in a specific
81 pass.  The dimension of the codebook need not be the same in multiple
82 passes, however the partition size must be an even multiple of the
83 codebook dimension.<p>
84
85 As an example, assume a partition vector of size eight, to be encoded
86 by residue 0 using codebook sizes of 8, 4, 2 and 1:<p>
87
88 <pre>
89
90             original residue vector: [ 0 1 2 3 4 5 6 7 ]
91
92 codebook dimensions = 8  encoded as: [ 0 1 2 3 4 5 6 7 ]
93
94 codebook dimensions = 4  encoded as: [ 0 2 4 6 ], [ 1 3 5 7 ]
95
96 codebook dimensions = 2  encoded as: [ 0 4 ], [ 1 5 ], [ 2 6 ], [ 3 7 ]
97
98 codebook dimensions = 1  encoded as: [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ]
99
100 </pre>
101
102 It is worth mentioning at this point that no configurable value in the
103 residue coding setup is restricted to a power of two.<p>
104
105 <h2> residue 1 </h2>
106
107 Residue 1 does not interleave VQ encoding.  It represents partition
108 vector scalars in order.  As with residue 0, however, partition length
109 must be an integer multiple of the codebook dimension, although
110 dimension may vary from pass to pass.
111
112 As an example, assume a partition vector of size eight, to be encoded
113 by residue 0 using codebook sizes of 8, 4, 2 and 1:<p>
114
115 <pre>
116
117             original residue vector: [ 0 1 2 3 4 5 6 7 ]
118
119 codebook dimensions = 8  encoded as: [ 0 1 2 3 4 5 6 7 ]
120
121 codebook dimensions = 4  encoded as: [ 0 1 2 3 ], [ 4 5 6 7 ]
122
123 codebook dimensions = 2  encoded as: [ 0 1 ], [ 2 3 ], [ 4 5 ], [ 6 7 ]
124
125 codebook dimensions = 1  encoded as: [ 0 ], [ 1 ], [ 2 ], [ 3 ], [ 4 ], [ 5 ], [ 6 ], [ 7 ]
126
127 </pre>
128
129 <h2> residue 2 </h2>
130
131
132
133 <h1>Residue decode</h1>
134
135 <h2>header decode</h2>
136
137 <h2>packet decode, format 0</h2>
138
139 <h2>packet decode, format 1</h2>
140
141 <h2>packet decode, format 2</h2>
142
143
144 <hr>
145 <a href="http://www.xiph.org/">
146 <img src="white-xifish.png" align=left border=0>
147 </a>
148 <font size=-2 color=#505050>
149
150 Ogg is a <a href="http://www.xiph.org">Xiph.org Foundation</a> effort
151 to protect essential tenets of Internet multimedia from corporate
152 hostage-taking; Open Source is the net's greatest tool to keep
153 everyone honest. See <a href="http://www.xiph.org/about.html">About
154 the Xiph.org Foundation</a> for details.
155 <p>
156
157 Ogg Vorbis is the first Ogg audio CODEC.  Anyone may freely use and
158 distribute the Ogg and Vorbis specification, whether in a private,
159 public or corporate capacity.  However, the Xiph.org Foundation and
160 the Ogg project (xiph.org) reserve the right to set the Ogg Vorbis
161 specification and certify specification compliance.<p>
162
163 Xiph.org's Vorbis software CODEC implementation is distributed under a
164 BSD-like license.  This does not restrict third parties from
165 distributing independent implementations of Vorbis software under
166 other licenses.<p>
167
168 Ogg, Vorbis, Xiph.org Foundation and their logos are trademarks (tm)
169 of the <a href="http://www.xiph.org/">Xiph.org Foundation</a>.  These
170 pages are copyright (C) 1994-2002 Xiph.org Foundation. All rights
171 reserved.<p>
172
173 </body>
174