helper.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <HTML><HEAD><TITLE>xiph.org: Ogg Vorbis documentation</TITLE>
  2. <BODY bgcolor="#ffffff" text="#202020" link="#006666" vlink="#000000">
  3. <nobr><img src="white-ogg.png"><img src="vorbisword2.png"></nobr><p>
  4. <h1><font color=#000070>
  5. Ogg Vorbis I format specification: helper equations
  6. </font></h1>
  7. <em>Last update to this document: October 15, 2002</em><p>
  8. <h1>Overview</h1>
  9. The equations below are used in multiple places by the Vorbis codec
  10. specification. Rather than cluttering up the main specification
  11. documents, they are defined here and linked in the main documents
  12. where appropriate.<p>
  13. <a name=log><h2>ilog</h2></a>
  14. The "ilog(x)" function returns the position number (1 through n) of the highest set bit in the two's complement integer value
  15. <tt>[x]</tt>. Values of <tt>[x]</tt> less than zero are defined to return zero.
  16. <pre>
  17. 1) [return_value] = 0;
  18. 2) if ( [x] is greater than zero ){
  19. 3) increment [return_value];
  20. 4) logical shift [x] one bit to the right, padding the MSb with zero
  21. 5) repeat at step 2)
  22. }
  23. 6) done
  24. </pre>
  25. Examples:
  26. <ul><li> ilog(0) = 0;
  27. <li> ilog(1) = 1;
  28. <li> ilog(2) = 2;
  29. <li> ilog(3) = 2;
  30. <li> ilog(4) = 3;
  31. <li> ilog(7) = 3;
  32. <li> ilog(negative number) = 0;
  33. </uL>
  34. <a name=float32_unpack><h2>float32_unpack</h2></a>
  35. "float32_unpack(x)" is intended to translate the packed binary
  36. representation of a Vorbis codebook float value into the
  37. representation used by the decoder for floating point numbers. For
  38. purposes of this example, we will unpack a Vorbis float32 into a
  39. host-native floating point number.<p>
  40. <pre>
  41. 1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
  42. 2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
  43. 3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
  44. 4) if ( [sign] is nonzero ) then negate [mantissa]
  45. 5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
  46. </pre>
  47. <a name=lookup1_values><h2>lookup1_values</h2></a>
  48. "lookup1_values(codebook_entries,codebook_dimensions)" is used to
  49. compute the correct length of the value index for a codebook VQ lookup
  50. table of lookup type 1. The values on this list are permuted to
  51. construct the VQ vector lookup table of size
  52. <tt>[codebook_entries]</tt>.<p>
  53. The return value for this function is defined to be 'the greatest
  54. integer value for which <tt>[return_value] to the power of
  55. [codebook_dimensions] is less than or equal to
  56. [codebook_entries]</tt>'.
  57. <a name=low_neighbor><h2>low_neighbor</h2></a>
  58. "low_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
  59. the greatest value scalar element for which <i>n</i> is less than
  60. <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is less
  61. than vector [v] element [x]</tt>.
  62. <a name=high_neighbor><h2>high_neighbor</h2></a>
  63. "high_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
  64. the lowest value scalar element for which <i>n</i> is less than
  65. <tt>[x]</tt> and <tt>vector [v] element <i>n</i> is greater
  66. than vector [v] element [x]</tt>.
  67. <a name=render_point><h2>render_point</h2></a>
  68. "render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
  69. along the line specified by x0, x1, y0 and y1. This function uses an
  70. integer algorithm to solve for the point directly without calculating
  71. intervening values along the line.<p>
  72. <pre>
  73. 1) [dy] = [y1] - [y0]
  74. 2) [adx] = [x1] - [x0]
  75. 3) [ady] = absolute value of [dy]
  76. 4) [err] = [ady] * ([X] - [x0])
  77. 5) [off] = [err] / [adx] using integer division
  78. 6) if ( [dy] is less than zero ) {
  79. 7) [Y] = [y0] - [off]
  80. } else {
  81. 8) [Y] = [y0] + [off]
  82. }
  83. 9) done
  84. </pre>
  85. <a name=render_line><h2>render_line</h2></a>
  86. Floor decode type one uses the integer line drawing algorithm of
  87. "render_line(x0, y0, x1, y1, v)" to construct an integer floor
  88. curve for contiguous piecewise line segments. Note that it has not
  89. been relevant elsewhere, but here we must define integer division as
  90. rounding division of both positive and negative numbers toward zero.
  91. <pre>
  92. 1) [dy] = [y1] - [y0]
  93. 2) [adx] = [x1] - [x0]
  94. 3) [ady] = absolute value of [dy]
  95. 4) [base] = [dy] / [adx] using integer division
  96. 5) [x] = [x0]
  97. 6) [y] = [y0]
  98. 7) [err] = 0
  99. 8) if ( [dy] is less than 0 ) {
  100. 9) [sy] = [base] - 1
  101. } else {
  102. 10) [sy] = [base] + 1
  103. }
  104. 11) [ady] = [ady] - (absolute value of [base]) * [adx]
  105. 12) vector [v] element [x] = [y]
  106. 13) iterate [x] over the range [x0]+1 ... [x1]-1 {
  107. 14) [err] = [err] + [ady];
  108. 15) if ( [err] >= [adx] ) {
  109. 15) [err] = [err] - [adx]
  110. 16) [y] = [y] + [sy]
  111. } else {
  112. 17) [y] = [y] + [base]
  113. }
  114. 18) vector [v] element [x] = [y]
  115. }
  116. </pre>
  117. <hr>
  118. <a href="http://www.xiph.org/">
  119. <img src="white-xifish.png" align=left border=0>
  120. </a>
  121. <font size=-2 color=#505050>
  122. Ogg is a <a href="http://www.xiph.org">Xiph.org Foundation</a> effort
  123. to protect essential tenets of Internet multimedia from corporate
  124. hostage-taking; Open Source is the net's greatest tool to keep
  125. everyone honest. See <a href="http://www.xiph.org/about.html">About
  126. the Xiph.org Foundation</a> for details.
  127. <p>
  128. Ogg Vorbis is the first Ogg audio CODEC. Anyone may freely use and
  129. distribute the Ogg and Vorbis specification, whether in a private,
  130. public or corporate capacity. However, the Xiph.org Foundation and
  131. the Ogg project (xiph.org) reserve the right to set the Ogg Vorbis
  132. specification and certify specification compliance.<p>
  133. Xiph.org's Vorbis software CODEC implementation is distributed under a
  134. BSD-like license. This does not restrict third parties from
  135. distributing independent implementations of Vorbis software under
  136. other licenses.<p>
  137. Ogg, Vorbis, Xiph.org Foundation and their logos are trademarks (tm)
  138. of the <a href="http://www.xiph.org/">Xiph.org Foundation</a>. These
  139. pages are copyright (C) 1994-2002 Xiph.org Foundation. All rights
  140. reserved.<p>
  141. </body>