examples/SFExamples/oggvorbiscodec/src/libvorbis/doc/xml/09-helper.xml

00001 <?xml version="1.0" standalone="no"?>
00002 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
00003                 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
00004 
00005 ]>
00006 
00007 <section id="vorbis-spec-helper">
00008 <sectioninfo>
00009 <releaseinfo>
00010  $Id: 09-helper.xml 7186 2004-07-20 07:19:25Z xiphmont $
00011 </releaseinfo>
00012 </sectioninfo>
00013 <title>Helper equations</title>
00014 
00015 <section>
00016 <title>Overview</title>
00017 
00018 <para>
00019 The equations below are used in multiple places by the Vorbis codec
00020 specification.  Rather than cluttering up the main specification
00021 documents, they are defined here and referenced where appropriate.
00022 </para>
00023 
00024 </section>
00025 
00026 <section>
00027 <title>Functions</title>
00028 
00029 <section id="vorbis-spec-ilog">
00030 <title>ilog</title>
00031 
00032 <para>
00033 The "ilog(x)" function returns the position number (1 through n) of the highest set bit in the two's complement integer value
00034 <varname>[x]</varname>.  Values of <varname>[x]</varname> less than zero are defined to return zero.</para>
00035 
00036 <programlisting>
00037   1) [return_value] = 0;
00038   2) if ( [x] is greater than zero ){
00039       
00040        3) increment [return_value];
00041        4) logical shift [x] one bit to the right, padding the MSb with zero
00042        5) repeat at step 2)
00043 
00044      }
00045 
00046    6) done
00047 </programlisting>
00048 
00049 <para>
00050 Examples:
00051 
00052 <itemizedlist>
00053  <listitem><simpara>ilog(0) = 0;</simpara></listitem>
00054  <listitem><simpara>ilog(1) = 1;</simpara></listitem>
00055  <listitem><simpara>ilog(2) = 2;</simpara></listitem>
00056  <listitem><simpara>ilog(3) = 2;</simpara></listitem>
00057  <listitem><simpara>ilog(4) = 3;</simpara></listitem>
00058  <listitem><simpara>ilog(7) = 3;</simpara></listitem>
00059  <listitem><simpara>ilog(negative number) = 0;</simpara></listitem>
00060 </itemizedlist>
00061 </para>
00062 
00063 </section>
00064 
00065 <section id="vorbis-spec-float32_unpack">
00066 <title>float32_unpack</title>
00067 
00068 <para>
00069 "float32_unpack(x)" is intended to translate the packed binary
00070 representation of a Vorbis codebook float value into the
00071 representation used by the decoder for floating point numbers.  For
00072 purposes of this example, we will unpack a Vorbis float32 into a
00073 host-native floating point number.</para>
00074 
00075 <programlisting>
00076   1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
00077   2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
00078   3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
00079   4) if ( [sign] is nonzero ) then negate [mantissa]
00080   5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
00081 </programlisting>
00082 
00083 </section>
00084 
00085 <section id="vorbis-spec-lookup1_values">
00086 <title>lookup1_values</title>
00087 
00088 <para>
00089 "lookup1_values(codebook_entries,codebook_dimensions)" is used to
00090 compute the correct length of the value index for a codebook VQ lookup
00091 table of lookup type 1.  The values on this list are permuted to
00092 construct the VQ vector lookup table of size
00093 <varname>[codebook_entries]</varname>.</para>
00094 
00095 <para>
00096 The return value for this function is defined to be 'the greatest
00097 integer value for which <varname>[return_value] to the power of
00098 [codebook_dimensions] is less than or equal to
00099 [codebook_entries]</varname>'.</para>
00100 
00101 </section>
00102 
00103 <section id="vorbis-spec-low_neighbor">
00104 <title>low_neighbor</title>
00105 
00106 <para>
00107 "low_neighbor(v,x)" finds the position <varname>n</varname> in vector <varname>[v]</varname> of
00108 the greatest value scalar element for which <varname>n</varname> is less than
00109 <varname>[x]</varname> and vector <varname>[v]</varname> element <varname>n</varname> is less
00110 than vector <varname>[v]</varname> element <varname>[x]</varname>.</para>
00111 
00112 <section id="vorbis-spec-high_neighbor">
00113 <title>high_neighbor</title>
00114 
00115 <para>
00116 "high_neighbor(v,x)" finds the position <varname>n</varname> in vector [v] of
00117 the lowest value scalar element for which <varname>n</varname> is less than
00118 <varname>[x]</varname> and vector <varname>[v]</varname> element <varname>n</varname> is greater
00119 than vector <varname>[v]</varname> element <varname>[x]</varname>.</para>
00120 
00121 </section>
00122 
00123 <section id="vorbis-spec-render_point">
00124 <title>render_point</title>
00125 
00126 <para>
00127 "render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
00128 along the line specified by x0, x1, y0 and y1.  This function uses an
00129 integer algorithm to solve for the point directly without calculating
00130 intervening values along the line.</para>
00131 
00132 <programlisting>
00133   1)  [dy] = [y1] - [y0]
00134   2) [adx] = [x1] - [x0]
00135   3) [ady] = absolute value of [dy]
00136   4) [err] = [ady] * ([X] - [x0])
00137   5) [off] = [err] / [adx] using integer division
00138   6) if ( [dy] is less than zero ) {
00139 
00140        7) [Y] = [y0] - [off]
00141 
00142      } else {
00143 
00144        8) [Y] = [y0] + [off]
00145   
00146      }
00147 
00148   9) done
00149 </programlisting>
00150 
00151 </section>
00152 
00153 <section id="vorbis-spec-render_line">
00154 <title>render_line</title>
00155 
00156 <para>
00157 Floor decode type one uses the integer line drawing algorithm of
00158 "render_line(x0, y0, x1, y1, v)" to construct an integer floor
00159 curve for contiguous piecewise line segments. Note that it has not
00160 been relevant elsewhere, but here we must define integer division as
00161 rounding division of both positive and negative numbers toward zero.
00162 </para>
00163 
00164 <programlisting>
00165   1)   [dy] = [y1] - [y0]
00166   2)  [adx] = [x1] - [x0]
00167   3)  [ady] = absolute value of [dy]
00168   4) [base] = [dy] / [adx] using integer division
00169   5)    [x] = [x0]
00170   6)    [y] = [y0]
00171   7)  [err] = 0
00172 
00173   8) if ( [dy] is less than 0 ) {
00174 
00175         9) [sy] = [base] - 1
00176 
00177      } else {
00178 
00179        10) [sy] = [base] + 1
00180 
00181      }
00182 
00183  11) [ady] = [ady] - (absolute value of [base]) * [adx]
00184  12) vector [v] element [x] = [y]
00185 
00186  13) iterate [x] over the range [x0]+1 ... [x1]-1 {
00187 
00188        14) [err] = [err] + [ady];
00189        15) if ( [err] >= [adx] ) {
00190 
00191              16) [err] = [err] - [adx]
00192              17)   [y] = [y] + [sy]
00193 
00194            } else {
00195 
00196              18) [y] = [y] + [base]
00197    
00198            }
00199 
00200        19) vector [v] element [x] = [y]
00201 
00202      }
00203 </programlisting>
00204 
00205 </section>
00206 
00207 </section>
00208 
00209 </section>
00210 
00211 </section>

Generated by  doxygen 1.6.2