Keep piling ongoing work into CVS.
[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 Residue type two can be thought of as a variant of residue type 1.
132 Rather than encoding multiple passed-in vectors as in residue type 1,
133 the <i>ch</i> passed in vectors of length <i>n</i> are first
134 interleaved and flattened into a single vector of length
135 <i>ch</i>*<i>n</i>.  Encoding then proceeds as in type 1. Decoding is
136 as in type 1 with decode interleave reversed. If operating on a single
137 vector to begin with, residue type 1 and type 2 are equivalent.<p>
138
139 <img src="residue2.png"><p>
140
141 <h1>Residue decode</h1>
142
143 <h2>header decode</h2>
144
145 <h2>packet decode, format 0</h2>
146
147 <h2>packet decode, format 1</h2>
148
149 <h2>packet decode, format 2</h2>
150
151
152 <hr>
153 <a href="http://www.xiph.org/">
154 <img src="white-xifish.png" align=left border=0>
155 </a>
156 <font size=-2 color=#505050>
157
158 Ogg is a <a href="http://www.xiph.org">Xiph.org Foundation</a> effort
159 to protect essential tenets of Internet multimedia from corporate
160 hostage-taking; Open Source is the net's greatest tool to keep
161 everyone honest. See <a href="http://www.xiph.org/about.html">About
162 the Xiph.org Foundation</a> for details.
163 <p>
164
165 Ogg Vorbis is the first Ogg audio CODEC.  Anyone may freely use and
166 distribute the Ogg and Vorbis specification, whether in a private,
167 public or corporate capacity.  However, the Xiph.org Foundation and
168 the Ogg project (xiph.org) reserve the right to set the Ogg Vorbis
169 specification and certify specification compliance.<p>
170
171 Xiph.org's Vorbis software CODEC implementation is distributed under a
172 BSD-like license.  This does not restrict third parties from
173 distributing independent implementations of Vorbis software under
174 other licenses.<p>
175
176 Ogg, Vorbis, Xiph.org Foundation and their logos are trademarks (tm)
177 of the <a href="http://www.xiph.org/">Xiph.org Foundation</a>.  These
178 pages are copyright (C) 1994-2002 Xiph.org Foundation. All rights
179 reserved.<p>
180
181 </body>
182