1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
5 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>
6 <title>Ogg Vorbis Documentation</title>
8 <style type="text/css">
10 margin: 0 18px 0 18px;
12 font-family: Verdana, Arial, Helvetica, sans-serif;
26 margin: 30px 0 16px 0;
33 h1, h1 a, h2, h2 a, h3, h3 a {
36 margin: 1.3em 0 8px 0;
70 <a href="http://www.xiph.org/"><img src="fish_xiph_org.png" alt="Fish Logo and Xiph.Org"/></a>
73 <h1>Ogg Vorbis I format specification: helper equations</h1>
77 <p>The equations below are used in multiple places by the Vorbis codec
78 specification. Rather than cluttering up the main specification
79 documents, they are defined here and linked in the main documents
80 where appropriate.</p>
82 <h2><a name="log">ilog</a></h2>
84 <p>The "ilog(x)" function returns the position number (1 through n) of the
85 highest set bit in the two's complement integer value
86 <tt>[x]</tt>. Values of <tt>[x]</tt> less than zero are defined to return zero.</p>
89 1) [return_value] = 0;
90 2) if ( [x] is greater than zero ){
92 3) increment [return_value];
93 4) logical shift [x] one bit to the right, padding the MSb with zero
104 <li>ilog(0) = 0;</li>
105 <li>ilog(1) = 1;</li>
106 <li>ilog(2) = 2;</li>
107 <li>ilog(3) = 2;</li>
108 <li>ilog(4) = 3;</li>
109 <li>ilog(7) = 3;</li>
110 <li>ilog(negative number) = 0;</li>
113 <h2><a name="float32_unpack">float32_unpack</a></h2>
115 <p>"float32_unpack(x)" is intended to translate the packed binary
116 representation of a Vorbis codebook float value into the
117 representation used by the decoder for floating point numbers. For
118 purposes of this example, we will unpack a Vorbis float32 into a
119 host-native floating point number.</p>
122 1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
123 2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
124 3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
125 4) if ( [sign] is nonzero ) then negate [mantissa]
126 5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
129 <h2><a name="lookup1_values">lookup1_values</a></h2>
131 <p>"lookup1_values(codebook_entries,codebook_dimensions)" is used to
132 compute the correct length of the value index for a codebook VQ lookup
133 table of lookup type 1. The values on this list are permuted to
134 construct the VQ vector lookup table of size
135 <tt>[codebook_entries]</tt>.</p>
137 <p>The return value for this function is defined to be 'the greatest
138 integer value for which <tt>[return_value] to the power of
139 [codebook_dimensions] is less than or equal to
140 [codebook_entries]</tt>'.</p>
142 <h2><a name="low_neighbor">low_neighbor</a></h2>
144 <p>"low_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
145 the greatest value scalar element for which <i>n</i> is less than
146 <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is less
147 than vector [v] element [x]</tt>.</p>
149 <h2><a name="high_neighbor">high_neighbor</a></h2>
151 <p>"high_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
152 the lowest value scalar element for which <i>n</i> is less than
153 <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is greater
154 than vector [v] element [x]</tt>.</p>
156 <h2><a name="render_point">render_point</a></h2>
158 <p>"render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
159 along the line specified by x0, x1, y0 and y1. This function uses an
160 integer algorithm to solve for the point directly without calculating
161 intervening values along the line.</p>
164 1) [dy] = [y1] - [y0]
165 2) [adx] = [x1] - [x0]
166 3) [ady] = absolute value of [dy]
167 4) [err] = [ady] * ([X] - [x0])
168 5) [off] = [err] / [adx] using integer division
169 6) if ( [dy] is less than zero ) {
171 7) [Y] = [y0] - [off]
175 8) [Y] = [y0] + [off]
182 <h2><a name="render_line">render_line</a></h2>
184 <p>Floor decode type one uses the integer line drawing algorithm of
185 "render_line(x0, y0, x1, y1, v)" to construct an integer floor
186 curve for contiguous piecewise line segments. Note that it has not
187 been relevant elsewhere, but here we must define integer division as
188 rounding division of both positive and negative numbers toward zero.</p>
191 1) [dy] = [y1] - [y0]
192 2) [adx] = [x1] - [x0]
193 3) [ady] = absolute value of [dy]
194 4) [base] = [dy] / [adx] using integer division
199 8) if ( [dy] is less than 0 ) {
205 10) [sy] = [base] + 1
209 11) [ady] = [ady] - (absolute value of [base]) * [adx]
210 12) vector [v] element [x] = [y]
212 13) iterate [x] over the range [x0]+1 ... [x1]-1 {
214 14) [err] = [err] + [ady];
215 15) if ( [err] >= [adx] ) {
217 15) [err] = [err] - [adx]
222 17) [y] = [y] + [base]
226 18) vector [v] element [x] = [y]
232 The Xiph Fish Logo is a
233 trademark (™) of Xiph.Org.<br/>
235 These pages © 1994 - 2005 Xiph.Org. All rights reserved.