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" [
7 <section id="vorbis-spec-helper">
13 <title>Helper equations</title>
16 <title>Overview</title>
19 The equations below are used in multiple places by the Vorbis codec
20 specification. Rather than cluttering up the main specification
21 documents, they are defined here and referenced where appropriate.
27 <title>Functions</title>
29 <section id="vorbis-spec-ilog">
33 The "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>
37 1) [return_value] = 0;
38 2) if ( [x] is greater than zero ){
40 3) increment [return_value];
41 4) logical shift [x] one bit to the right, padding the MSb with zero
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>
65 <section id="vorbis-spec-float32_unpack">
66 <title>float32_unpack</title>
69 "float32_unpack(x)" is intended to translate the packed binary
70 representation of a Vorbis codebook float value into the
71 representation used by the decoder for floating point numbers. For
72 purposes of this example, we will unpack a Vorbis float32 into a
73 host-native floating point number.</para>
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 ) )
85 <section id="vorbis-spec-lookup1_values">
86 <title>lookup1_values</title>
89 "lookup1_values(codebook_entries,codebook_dimensions)" is used to
90 compute the correct length of the value index for a codebook VQ lookup
91 table of lookup type 1. The values on this list are permuted to
92 construct the VQ vector lookup table of size
93 <varname>[codebook_entries]</varname>.</para>
96 The return value for this function is defined to be 'the greatest
97 integer value for which <varname>[return_value] to the power of
98 [codebook_dimensions] is less than or equal to
99 [codebook_entries]</varname>'.</para>
103 <section id="vorbis-spec-low_neighbor">
104 <title>low_neighbor</title>
107 "low_neighbor(v,x)" finds the position <varname>n</varname> in vector <varname>[v]</varname> of
108 the 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
110 than vector <varname>[v]</varname> element <varname>[x]</varname>.</para>
112 <section id="vorbis-spec-high_neighbor">
113 <title>high_neighbor</title>
116 "high_neighbor(v,x)" finds the position <varname>n</varname> in vector [v] of
117 the 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
119 than vector <varname>[v]</varname> element <varname>[x]</varname>.</para>
123 <section id="vorbis-spec-render_point">
124 <title>render_point</title>
127 "render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
128 along the line specified by x0, x1, y0 and y1. This function uses an
129 integer algorithm to solve for the point directly without calculating
130 intervening values along the line.</para>
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 ) {
140 7) [Y] = [y0] - [off]
144 8) [Y] = [y0] + [off]
153 <section id="vorbis-spec-render_line">
154 <title>render_line</title>
157 Floor decode type one uses the integer line drawing algorithm of
158 "render_line(x0, y0, x1, y1, v)" to construct an integer floor
159 curve for contiguous piecewise line segments. Note that it has not
160 been relevant elsewhere, but here we must define integer division as
161 rounding division of both positive and negative numbers toward zero.
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
173 8) if ( [dy] is less than 0 ) {
179 10) [sy] = [base] + 1
183 11) [ady] = [ady] - (absolute value of [base]) * [adx]
184 12) vector [v] element [x] = [y]
186 13) iterate [x] over the range [x0]+1 ... [x1]-1 {
188 14) [err] = [err] + [ady];
189 15) if ( [err] >= [adx] ) {
191 16) [err] = [err] - [adx]
196 18) [y] = [y] + [base]
200 19) vector [v] element [x] = [y]