Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/libvorbis-1.2.0/doc/xml/09-helper.xml @ 16

Last change on this file since 16 was 16, checked in by landauf, 16 years ago

added libvorbis

File size: 5.6 KB
Line 
1<?xml version="1.0" standalone="no"?>
2<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3                "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4
5]>
6
7<section id="vorbis-spec-helper">
8<sectioninfo>
9<releaseinfo>
10 $Id: 09-helper.xml 7186 2004-07-20 07:19:25Z xiphmont $
11</releaseinfo>
12</sectioninfo>
13<title>Helper equations</title>
14
15<section>
16<title>Overview</title>
17
18<para>
19The equations below are used in multiple places by the Vorbis codec
20specification.  Rather than cluttering up the main specification
21documents, they are defined here and referenced where appropriate.
22</para>
23
24</section>
25
26<section>
27<title>Functions</title>
28
29<section id="vorbis-spec-ilog">
30<title>ilog</title>
31
32<para>
33The "ilog(x)" function returns the position number (1 through n) of the highest set bit in the two's complement integer value
34<varname>[x]</varname>.  Values of <varname>[x]</varname> less than zero are defined to return zero.</para>
35
36<programlisting>
37  1) [return_value] = 0;
38  2) if ( [x] is greater than zero ){
39     
40       3) increment [return_value];
41       4) logical shift [x] one bit to the right, padding the MSb with zero
42       5) repeat at step 2)
43
44     }
45
46   6) done
47</programlisting>
48
49<para>
50Examples:
51
52<itemizedlist>
53 <listitem><simpara>ilog(0) = 0;</simpara></listitem>
54 <listitem><simpara>ilog(1) = 1;</simpara></listitem>
55 <listitem><simpara>ilog(2) = 2;</simpara></listitem>
56 <listitem><simpara>ilog(3) = 2;</simpara></listitem>
57 <listitem><simpara>ilog(4) = 3;</simpara></listitem>
58 <listitem><simpara>ilog(7) = 3;</simpara></listitem>
59 <listitem><simpara>ilog(negative number) = 0;</simpara></listitem>
60</itemizedlist>
61</para>
62
63</section>
64
65<section id="vorbis-spec-float32_unpack">
66<title>float32_unpack</title>
67
68<para>
69"float32_unpack(x)" is intended to translate the packed binary
70representation of a Vorbis codebook float value into the
71representation used by the decoder for floating point numbers.  For
72purposes of this example, we will unpack a Vorbis float32 into a
73host-native floating point number.</para>
74
75<programlisting>
76  1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
77  2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
78  3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
79  4) if ( [sign] is nonzero ) then negate [mantissa]
80  5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
81</programlisting>
82
83</section>
84
85<section id="vorbis-spec-lookup1_values">
86<title>lookup1_values</title>
87
88<para>
89"lookup1_values(codebook_entries,codebook_dimensions)" is used to
90compute the correct length of the value index for a codebook VQ lookup
91table of lookup type 1.  The values on this list are permuted to
92construct the VQ vector lookup table of size
93<varname>[codebook_entries]</varname>.</para>
94
95<para>
96The return value for this function is defined to be 'the greatest
97integer value for which <varname>[return_value] to the power of
98[codebook_dimensions] is less than or equal to
99[codebook_entries]</varname>'.</para>
100
101</section>
102
103<section id="vorbis-spec-low_neighbor">
104<title>low_neighbor</title>
105
106<para>
107"low_neighbor(v,x)" finds the position <varname>n</varname> in vector <varname>[v]</varname> of
108the greatest value scalar element for which <varname>n</varname> is less than
109<varname>[x]</varname> and vector <varname>[v]</varname> element <varname>n</varname> is less
110than vector <varname>[v]</varname> element <varname>[x]</varname>.</para>
111
112<section id="vorbis-spec-high_neighbor">
113<title>high_neighbor</title>
114
115<para>
116"high_neighbor(v,x)" finds the position <varname>n</varname> in vector [v] of
117the lowest value scalar element for which <varname>n</varname> is less than
118<varname>[x]</varname> and vector <varname>[v]</varname> element <varname>n</varname> is greater
119than vector <varname>[v]</varname> element <varname>[x]</varname>.</para>
120
121</section>
122
123<section id="vorbis-spec-render_point">
124<title>render_point</title>
125
126<para>
127"render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
128along the line specified by x0, x1, y0 and y1.  This function uses an
129integer algorithm to solve for the point directly without calculating
130intervening values along the line.</para>
131
132<programlisting>
133  1)  [dy] = [y1] - [y0]
134  2) [adx] = [x1] - [x0]
135  3) [ady] = absolute value of [dy]
136  4) [err] = [ady] * ([X] - [x0])
137  5) [off] = [err] / [adx] using integer division
138  6) if ( [dy] is less than zero ) {
139
140       7) [Y] = [y0] - [off]
141
142     } else {
143
144       8) [Y] = [y0] + [off]
145 
146     }
147
148  9) done
149</programlisting>
150
151</section>
152
153<section id="vorbis-spec-render_line">
154<title>render_line</title>
155
156<para>
157Floor decode type one uses the integer line drawing algorithm of
158"render_line(x0, y0, x1, y1, v)" to construct an integer floor
159curve for contiguous piecewise line segments. Note that it has not
160been relevant elsewhere, but here we must define integer division as
161rounding division of both positive and negative numbers toward zero.
162</para>
163
164<programlisting>
165  1)   [dy] = [y1] - [y0]
166  2)  [adx] = [x1] - [x0]
167  3)  [ady] = absolute value of [dy]
168  4) [base] = [dy] / [adx] using integer division
169  5)    [x] = [x0]
170  6)    [y] = [y0]
171  7)  [err] = 0
172
173  8) if ( [dy] is less than 0 ) {
174
175        9) [sy] = [base] - 1
176
177     } else {
178
179       10) [sy] = [base] + 1
180
181     }
182
183 11) [ady] = [ady] - (absolute value of [base]) * [adx]
184 12) vector [v] element [x] = [y]
185
186 13) iterate [x] over the range [x0]+1 ... [x1]-1 {
187
188       14) [err] = [err] + [ady];
189       15) if ( [err] >= [adx] ) {
190
191             16) [err] = [err] - [adx]
192             17)   [y] = [y] + [sy]
193
194           } else {
195
196             18) [y] = [y] + [base]
197   
198           }
199
200       19) vector [v] element [x] = [y]
201
202     }
203</programlisting>
204
205</section>
206
207</section>
208
209</section>
210
211</section>
Note: See TracBrowser for help on using the repository browser.