many doc cleanups
[platform/upstream/libvorbis.git] / doc / helper.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
2 <html>\r
3 <head>\r
4 \r
5 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>\r
6 <title>Ogg Vorbis Documentation</title>\r
7 \r
8 <style type="text/css">\r
9 body {\r
10   margin: 0 18px 0 18px;\r
11   padding-bottom: 30px;\r
12   font-family: Verdana, Arial, Helvetica, sans-serif;\r
13   color: #333333;\r
14   font-size: .8em;\r
15 }\r
16 \r
17 a {\r
18   color: #3366cc;\r
19 }\r
20 \r
21 img {\r
22   border: 0;\r
23 }\r
24 \r
25 #xiphlogo {\r
26   margin: 30px 0 16px 0;\r
27 }\r
28 \r
29 #content p {\r
30   line-height: 1.4;\r
31 }\r
32 \r
33 h1, h1 a, h2, h2 a, h3, h3 a {\r
34   font-weight: bold;\r
35   color: #ff9900;\r
36   margin: 1.3em 0 8px 0;\r
37 }\r
38 \r
39 h1 {\r
40   font-size: 1.3em;\r
41 }\r
42 \r
43 h2 {\r
44   font-size: 1.2em;\r
45 }\r
46 \r
47 h3 {\r
48   font-size: 1.1em;\r
49 }\r
50 \r
51 li {\r
52   line-height: 1.4;\r
53 }\r
54 \r
55 #copyright {\r
56   margin-top: 30px;\r
57   line-height: 1.5em;\r
58   text-align: center;\r
59   font-size: .8em;\r
60   color: #888888;\r
61   clear: both;\r
62 }\r
63 </style>\r
64 \r
65 </head>\r
66 \r
67 <body>\r
68 \r
69 <div id="xiphlogo">\r
70   <a href="http://www.xiph.org/"><img src="fish_xiph_org.png" alt="Fish Logo and Xiph.org"/></a>\r
71 </div>\r
72 \r
73 <h1>Ogg Vorbis I format specification: helper equations</h1>\r
74 \r
75 <h1>Overview</h1>\r
76 \r
77 <p>The equations below are used in multiple places by the Vorbis codec\r
78 specification. Rather than cluttering up the main specification\r
79 documents, they are defined here and linked in the main documents\r
80 where appropriate.</p>\r
81 \r
82 <h2><a name="log">ilog</a></h2>\r
83 \r
84 <p>The "ilog(x)" function returns the position number (1 through n) of the\r
85 highest set bit in the two's complement integer value\r
86 <tt>[x]</tt>. Values of <tt>[x]</tt> less than zero are defined to return zero.</p>\r
87 \r
88 <pre>\r
89   1) [return_value] = 0;\r
90   2) if ( [x] is greater than zero ){\r
91       \r
92        3) increment [return_value];\r
93        4) logical shift [x] one bit to the right, padding the MSb with zero\r
94        5) repeat at step 2)\r
95 \r
96      }\r
97 \r
98    6) done\r
99 </pre>\r
100 \r
101 <p>Examples:</p>\r
102 \r
103 <ul>\r
104 <li>ilog(0) = 0;</li>\r
105 <li>ilog(1) = 1;</li>\r
106 <li>ilog(2) = 2;</li>\r
107 <li>ilog(3) = 2;</li>\r
108 <li>ilog(4) = 3;</li>\r
109 <li>ilog(7) = 3;</li>\r
110 <li>ilog(negative number) = 0;</li>\r
111 </ul>\r
112 \r
113 <h2><a name="float32_unpack">float32_unpack</a></h2>\r
114 \r
115 <p>"float32_unpack(x)" is intended to translate the packed binary\r
116 representation of a Vorbis codebook float value into the\r
117 representation used by the decoder for floating point numbers. For\r
118 purposes of this example, we will unpack a Vorbis float32 into a\r
119 host-native floating point number.</p>\r
120 \r
121 <pre>\r
122   1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)\r
123   2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)\r
124   3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)\r
125   4) if ( [sign] is nonzero ) then negate [mantissa]\r
126   5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )\r
127 </pre>\r
128 \r
129 <h2><a name="lookup1_values">lookup1_values</a></h2>\r
130 \r
131 <p>"lookup1_values(codebook_entries,codebook_dimensions)" is used to\r
132 compute the correct length of the value index for a codebook VQ lookup\r
133 table of lookup type 1. The values on this list are permuted to\r
134 construct the VQ vector lookup table of size\r
135 <tt>[codebook_entries]</tt>.</p>\r
136 \r
137 <p>The return value for this function is defined to be 'the greatest\r
138 integer value for which <tt>[return_value] to the power of\r
139 [codebook_dimensions] is less than or equal to\r
140 [codebook_entries]</tt>'.</p>\r
141 \r
142 <h2><a name="low_neighbor">low_neighbor</a></h2>\r
143 \r
144 <p>"low_neighbor(v,x)" finds the position <i>n</i> in vector [v] of\r
145 the greatest value scalar element for which <i>n</i> is less than\r
146 <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is less\r
147 than vector [v] element [x]</tt>.</p>\r
148 \r
149 <h2><a name="high_neighbor">high_neighbor</a></h2>\r
150 \r
151 <p>"high_neighbor(v,x)" finds the position <i>n</i> in vector [v] of\r
152 the lowest value scalar element for which <i>n</i> is less than\r
153 <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is greater\r
154 than vector [v] element [x]</tt>.</p>\r
155 \r
156 <h2><a name="render_point">render_point</a></h2>\r
157 \r
158 <p>"render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X\r
159 along the line specified by x0, x1, y0 and y1. This function uses an\r
160 integer algorithm to solve for the point directly without calculating\r
161 intervening values along the line.</p>\r
162 \r
163 <pre>\r
164   1)  [dy] = [y1] - [y0]\r
165   2) [adx] = [x1] - [x0]\r
166   3) [ady] = absolute value of [dy]\r
167   4) [err] = [ady] * ([X] - [x0])\r
168   5) [off] = [err] / [adx] using integer division\r
169   6) if ( [dy] is less than zero ) {\r
170 \r
171        7) [Y] = [y0] - [off]\r
172 \r
173      } else {\r
174 \r
175        8) [Y] = [y0] + [off]\r
176   \r
177      }\r
178 \r
179   9) done\r
180 </pre>\r
181 \r
182 <h2><a name="render_line">render_line</a></h2>\r
183 \r
184 <p>Floor decode type one uses the integer line drawing algorithm of\r
185 "render_line(x0, y0, x1, y1, v)" to construct an integer floor\r
186 curve for contiguous piecewise line segments. Note that it has not\r
187 been relevant elsewhere, but here we must define integer division as\r
188 rounding division of both positive and negative numbers toward zero.</p>\r
189 \r
190 <pre>\r
191   1)   [dy] = [y1] - [y0]\r
192   2)  [adx] = [x1] - [x0]\r
193   3)  [ady] = absolute value of [dy]\r
194   4) [base] = [dy] / [adx] using integer division\r
195   5)    [x] = [x0]\r
196   6)    [y] = [y0]\r
197   7)  [err] = 0\r
198 \r
199   8) if ( [dy] is less than 0 ) {\r
200 \r
201         9) [sy] = [base] - 1\r
202 \r
203      } else {\r
204 \r
205        10) [sy] = [base] + 1\r
206 \r
207      }\r
208 \r
209  11) [ady] = [ady] - (absolute value of [base]) * [adx]\r
210  12) vector [v] element [x] = [y]\r
211 \r
212  13) iterate [x] over the range [x0]+1 ... [x1]-1 {\r
213 \r
214        14) [err] = [err] + [ady];\r
215        15) if ( [err] >= [adx] ) {\r
216 \r
217              15) [err] = [err] - [adx]\r
218              16)   [y] = [y] + [sy]\r
219 \r
220            } else {\r
221 \r
222              17) [y] = [y] + [base]\r
223    \r
224            }\r
225 \r
226        18) vector [v] element [x] = [y]\r
227 \r
228      }\r
229 </pre>\r
230 \r
231 <div id="copyright">\r
232   The Xiph Fish Logo is a\r
233   trademark (&trade;) of Xiph.Org.<br/>\r
234 \r
235   These pages &copy; 1994 - 2005 Xiph.Org. All rights reserved.\r
236 </div>\r
237 \r
238 </body>\r
239 </html>\r