helper.html 5.6 KB

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