]> git.jsancho.org Git - lugaru.git/blob - libvorbis-1.0.1/doc/helper.html
Use const char * for string arguments to avoid deprecated conversion warnings.
[lugaru.git] / libvorbis-1.0.1 / doc / helper.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: helper equations
7 </font></h1>
8
9 <em>Last update to this document: October 15, 2002</em><p>
10
11 <h1>Overview</h1>
12
13 The equations below are used in multiple places by the Vorbis codec
14 specification.  Rather than cluttering up the main specification
15 documents, they are defined here and linked in the main documents
16 where appropriate.<p>
17
18 <a name=log><h2>ilog</h2></a>
19
20
21 The "ilog(x)" function returns the position number (1 through n) of the highest set bit in the two's complement integer value
22 <tt>[x]</tt>.  Values of <tt>[x]</tt> less than zero are defined to return zero.
23
24 <pre>
25   1) [return_value] = 0;
26   2) if ( [x] is greater than zero ){
27       
28        3) increment [return_value];
29        4) logical shift [x] one bit to the right, padding the MSb with zero
30        5) repeat at step 2)
31
32      }
33
34    6) done
35 </pre>
36
37 Examples:
38
39 <ul><li> ilog(0) = 0;
40     <li> ilog(1) = 1;
41     <li> ilog(2) = 2;
42     <li> ilog(3) = 2;
43     <li> ilog(4) = 3;
44     <li> ilog(7) = 3;
45     <li> ilog(negative number) = 0;
46 </uL>
47
48 <a name=float32_unpack><h2>float32_unpack</h2></a>
49
50 "float32_unpack(x)" is intended to translate the packed binary
51 representation of a Vorbis codebook float value into the
52 representation used by the decoder for floating point numbers.  For
53 purposes of this example, we will unpack a Vorbis float32 into a
54 host-native floating point number.<p>
55
56 <pre>
57   1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
58   2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
59   3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
60   4) if ( [sign] is nonzero ) then negate [mantissa]
61   5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
62 </pre>
63
64 <a name=lookup1_values><h2>lookup1_values</h2></a>
65
66 "lookup1_values(codebook_entries,codebook_dimensions)" is used to
67 compute the correct length of the value index for a codebook VQ lookup
68 table of lookup type 1.  The values on this list are permuted to
69 construct the VQ vector lookup table of size
70 <tt>[codebook_entries]</tt>.<p>
71
72 The return value for this function is defined to be 'the greatest
73 integer value for which <tt>[return_value] to the power of
74 [codebook_dimensions] is less than or equal to
75 [codebook_entries]</tt>'.
76
77 <a name=low_neighbor><h2>low_neighbor</h2></a>
78
79 "low_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
80 the greatest value scalar element for which <i>n</i> is less than
81 <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is less
82 than vector [v] element [x]</tt>.
83
84 <a name=high_neighbor><h2>high_neighbor</h2></a>
85
86 "high_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
87 the lowest value scalar element for which <i>n</i> is less than
88 <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is greater
89 than vector [v] element [x]</tt>.
90
91 <a name=render_point><h2>render_point</h2></a>
92
93 "render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
94 along the line specified by x0, x1, y0 and y1.  This function uses an
95 integer algorithm to solve for the point directly without calculating
96 intervening values along the line.<p>
97
98 <pre>
99   1)  [dy] = [y1] - [y0]
100   2) [adx] = [x1] - [x0]
101   3) [ady] = absolute value of [dy]
102   4) [err] = [ady] * ([X] - [x0])
103   5) [off] = [err] / [adx] using integer division
104   6) if ( [dy] is less than zero ) {
105
106        7) [Y] = [y0] - [off]
107
108      } else {
109
110        8) [Y] = [y0] + [off]
111   
112      }
113
114   9) done
115 </pre>
116
117 <a name=render_line><h2>render_line</h2></a>
118
119 Floor decode type one uses the integer line drawing algorithm of
120 "render_line(x0, y0, x1, y1, v)" to construct an integer floor
121 curve for contiguous piecewise line segments. Note that it has not
122 been relevant elsewhere, but here we must define integer division as
123 rounding division of both positive and negative numbers toward zero.
124
125 <pre>
126   1)   [dy] = [y1] - [y0]
127   2)  [adx] = [x1] - [x0]
128   3)  [ady] = absolute value of [dy]
129   4) [base] = [dy] / [adx] using integer division
130   5)    [x] = [x0]
131   6)    [y] = [y0]
132   7)  [err] = 0
133
134   8) if ( [dy] is less than 0 ) {
135
136         9) [sy] = [base] - 1
137
138      } else {
139
140        10) [sy] = [base] + 1
141
142      }
143
144  11) [ady] = [ady] - (absolute value of [base]) * [adx]
145  12) vector [v] element [x] = [y]
146
147  13) iterate [x] over the range [x0]+1 ... [x1]-1 {
148
149        14) [err] = [err] + [ady];
150        15) if ( [err] >= [adx] ) {
151
152              15) [err] = [err] - [adx]
153              16)   [y] = [y] + [sy]
154
155            } else {
156
157              17) [y] = [y] + [base]
158    
159            }
160
161        18) vector [v] element [x] = [y]
162
163      }
164 </pre>
165
166 <hr>
167 <a href="http://www.xiph.org/">
168 <img src="white-xifish.png" align=left border=0>
169 </a>
170 <font size=-2 color=#505050>
171
172 Ogg is a <a href="http://www.xiph.org">Xiph.org Foundation</a> effort
173 to protect essential tenets of Internet multimedia from corporate
174 hostage-taking; Open Source is the net's greatest tool to keep
175 everyone honest. See <a href="http://www.xiph.org/about.html">About
176 the Xiph.org Foundation</a> for details.
177 <p>
178
179 Ogg Vorbis is the first Ogg audio CODEC.  Anyone may freely use and
180 distribute the Ogg and Vorbis specification, whether in a private,
181 public or corporate capacity.  However, the Xiph.org Foundation and
182 the Ogg project (xiph.org) reserve the right to set the Ogg Vorbis
183 specification and certify specification compliance.<p>
184
185 Xiph.org's Vorbis software CODEC implementation is distributed under a
186 BSD-like license.  This does not restrict third parties from
187 distributing independent implementations of Vorbis software under
188 other licenses.<p>
189
190 Ogg, Vorbis, Xiph.org Foundation and their logos are trademarks (tm)
191 of the <a href="http://www.xiph.org/">Xiph.org Foundation</a>.  These
192 pages are copyright (C) 1994-2002 Xiph.org Foundation. All rights
193 reserved.<p>
194
195 </body>
196