Fix shift by negative value when reading blocksize.
[platform/upstream/libvorbis.git] / doc / helper.html
index 5ad551a..a16df28 100644 (file)
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html>\r
-<head>\r
-\r
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>\r
-<title>Ogg Vorbis Documentation</title>\r
-\r
-<style type="text/css">\r
-body {\r
-  margin: 0 18px 0 18px;\r
-  padding-bottom: 30px;\r
-  font-family: Verdana, Arial, Helvetica, sans-serif;\r
-  color: #333333;\r
-  font-size: .8em;\r
-}\r
-\r
-a {\r
-  color: #3366cc;\r
-}\r
-\r
-img {\r
-  border: 0;\r
-}\r
-\r
-#xiphlogo {\r
-  margin: 30px 0 16px 0;\r
-}\r
-\r
-#content p {\r
-  line-height: 1.4;\r
-}\r
-\r
-h1, h1 a, h2, h2 a, h3, h3 a {\r
-  font-weight: bold;\r
-  color: #ff9900;\r
-  margin: 1.3em 0 8px 0;\r
-}\r
-\r
-h1 {\r
-  font-size: 1.3em;\r
-}\r
-\r
-h2 {\r
-  font-size: 1.2em;\r
-}\r
-\r
-h3 {\r
-  font-size: 1.1em;\r
-}\r
-\r
-li {\r
-  line-height: 1.4;\r
-}\r
-\r
-#copyright {\r
-  margin-top: 30px;\r
-  line-height: 1.5em;\r
-  text-align: center;\r
-  font-size: .8em;\r
-  color: #888888;\r
-  clear: both;\r
-}\r
-</style>\r
-\r
-</head>\r
-\r
-<body>\r
-\r
-<div id="xiphlogo">\r
-  <a href="http://www.xiph.org/"><img src="fish_xiph_org.png" alt="Fish Logo and Xiph.org"/></a>\r
-</div>\r
-\r
-<h1>Ogg Vorbis I format specification: helper equations</h1>\r
-\r
-<h1>Overview</h1>\r
-\r
-<p>The equations below are used in multiple places by the Vorbis codec\r
-specification. Rather than cluttering up the main specification\r
-documents, they are defined here and linked in the main documents\r
-where appropriate.</p>\r
-\r
-<h2><a name="log">ilog</a></h2>\r
-\r
-<p>The "ilog(x)" function returns the position number (1 through n) of the\r
-highest set bit in the two's complement integer value\r
-<tt>[x]</tt>. Values of <tt>[x]</tt> less than zero are defined to return zero.</p>\r
-\r
-<pre>\r
-  1) [return_value] = 0;\r
-  2) if ( [x] is greater than zero ){\r
-      \r
-       3) increment [return_value];\r
-       4) logical shift [x] one bit to the right, padding the MSb with zero\r
-       5) repeat at step 2)\r
-\r
-     }\r
-\r
-   6) done\r
-</pre>\r
-\r
-<p>Examples:</p>\r
-\r
-<ul>\r
-<li>ilog(0) = 0;</li>\r
-<li>ilog(1) = 1;</li>\r
-<li>ilog(2) = 2;</li>\r
-<li>ilog(3) = 2;</li>\r
-<li>ilog(4) = 3;</li>\r
-<li>ilog(7) = 3;</li>\r
-<li>ilog(negative number) = 0;</li>\r
-</ul>\r
-\r
-<h2><a name="float32_unpack">float32_unpack</a></h2>\r
-\r
-<p>"float32_unpack(x)" is intended to translate the packed binary\r
-representation of a Vorbis codebook float value into the\r
-representation used by the decoder for floating point numbers. For\r
-purposes of this example, we will unpack a Vorbis float32 into a\r
-host-native floating point number.</p>\r
-\r
-<pre>\r
-  1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)\r
-  2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)\r
-  3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)\r
-  4) if ( [sign] is nonzero ) then negate [mantissa]\r
-  5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )\r
-</pre>\r
-\r
-<h2><a name="lookup1_values">lookup1_values</a></h2>\r
-\r
-<p>"lookup1_values(codebook_entries,codebook_dimensions)" is used to\r
-compute the correct length of the value index for a codebook VQ lookup\r
-table of lookup type 1. The values on this list are permuted to\r
-construct the VQ vector lookup table of size\r
-<tt>[codebook_entries]</tt>.</p>\r
-\r
-<p>The return value for this function is defined to be 'the greatest\r
-integer value for which <tt>[return_value] to the power of\r
-[codebook_dimensions] is less than or equal to\r
-[codebook_entries]</tt>'.</p>\r
-\r
-<h2><a name="low_neighbor">low_neighbor</a></h2>\r
-\r
-<p>"low_neighbor(v,x)" finds the position <i>n</i> in vector [v] of\r
-the greatest value scalar element for which <i>n</i> is less than\r
-<tt>[x]</tt> and <tt>vector [v] element <i>n</i> is less\r
-than vector [v] element [x]</tt>.</p>\r
-\r
-<h2><a name="high_neighbor">high_neighbor</a></h2>\r
-\r
-<p>"high_neighbor(v,x)" finds the position <i>n</i> in vector [v] of\r
-the lowest value scalar element for which <i>n</i> is less than\r
-<tt>[x]</tt> and <tt>vector [v] element <i>n</i> is greater\r
-than vector [v] element [x]</tt>.</p>\r
-\r
-<h2><a name="render_point">render_point</a></h2>\r
-\r
-<p>"render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X\r
-along the line specified by x0, x1, y0 and y1. This function uses an\r
-integer algorithm to solve for the point directly without calculating\r
-intervening values along the line.</p>\r
-\r
-<pre>\r
-  1)  [dy] = [y1] - [y0]\r
-  2) [adx] = [x1] - [x0]\r
-  3) [ady] = absolute value of [dy]\r
-  4) [err] = [ady] * ([X] - [x0])\r
-  5) [off] = [err] / [adx] using integer division\r
-  6) if ( [dy] is less than zero ) {\r
-\r
-       7) [Y] = [y0] - [off]\r
-\r
-     } else {\r
-\r
-       8) [Y] = [y0] + [off]\r
-  \r
-     }\r
-\r
-  9) done\r
-</pre>\r
-\r
-<h2><a name="render_line">render_line</a></h2>\r
-\r
-<p>Floor decode type one uses the integer line drawing algorithm of\r
-"render_line(x0, y0, x1, y1, v)" to construct an integer floor\r
-curve for contiguous piecewise line segments. Note that it has not\r
-been relevant elsewhere, but here we must define integer division as\r
-rounding division of both positive and negative numbers toward zero.</p>\r
-\r
-<pre>\r
-  1)   [dy] = [y1] - [y0]\r
-  2)  [adx] = [x1] - [x0]\r
-  3)  [ady] = absolute value of [dy]\r
-  4) [base] = [dy] / [adx] using integer division\r
-  5)    [x] = [x0]\r
-  6)    [y] = [y0]\r
-  7)  [err] = 0\r
-\r
-  8) if ( [dy] is less than 0 ) {\r
-\r
-        9) [sy] = [base] - 1\r
-\r
-     } else {\r
-\r
-       10) [sy] = [base] + 1\r
-\r
-     }\r
-\r
- 11) [ady] = [ady] - (absolute value of [base]) * [adx]\r
- 12) vector [v] element [x] = [y]\r
-\r
- 13) iterate [x] over the range [x0]+1 ... [x1]-1 {\r
-\r
-       14) [err] = [err] + [ady];\r
-       15) if ( [err] >= [adx] ) {\r
-\r
-             15) [err] = [err] - [adx]\r
-             16)   [y] = [y] + [sy]\r
-\r
-           } else {\r
-\r
-             17) [y] = [y] + [base]\r
-   \r
-           }\r
-\r
-       18) vector [v] element [x] = [y]\r
-\r
-     }\r
-</pre>\r
-\r
-<div id="copyright">\r
-  The Xiph Fish Logo is a\r
-  trademark (&trade;) of Xiph.Org.<br/>\r
-\r
-  These pages &copy; 1994 - 2005 Xiph.Org. All rights reserved.\r
-</div>\r
-\r
-</body>\r
-</html>\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+<head>
+
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>
+<title>Ogg Vorbis Documentation</title>
+
+<style type="text/css">
+body {
+  margin: 0 18px 0 18px;
+  padding-bottom: 30px;
+  font-family: Verdana, Arial, Helvetica, sans-serif;
+  color: #333333;
+  font-size: .8em;
+}
+
+a {
+  color: #3366cc;
+}
+
+img {
+  border: 0;
+}
+
+#xiphlogo {
+  margin: 30px 0 16px 0;
+}
+
+#content p {
+  line-height: 1.4;
+}
+
+h1, h1 a, h2, h2 a, h3, h3 a {
+  font-weight: bold;
+  color: #ff9900;
+  margin: 1.3em 0 8px 0;
+}
+
+h1 {
+  font-size: 1.3em;
+}
+
+h2 {
+  font-size: 1.2em;
+}
+
+h3 {
+  font-size: 1.1em;
+}
+
+li {
+  line-height: 1.4;
+}
+
+#copyright {
+  margin-top: 30px;
+  line-height: 1.5em;
+  text-align: center;
+  font-size: .8em;
+  color: #888888;
+  clear: both;
+}
+</style>
+
+</head>
+
+<body>
+
+<div id="xiphlogo">
+  <a href="http://www.xiph.org/"><img src="fish_xiph_org.png" alt="Fish Logo and Xiph.Org"/></a>
+</div>
+
+<h1>Ogg Vorbis I format specification: helper equations</h1>
+
+<h1>Overview</h1>
+
+<p>The equations below are used in multiple places by the Vorbis codec
+specification. Rather than cluttering up the main specification
+documents, they are defined here and linked in the main documents
+where appropriate.</p>
+
+<h2><a name="log">ilog</a></h2>
+
+<p>The "ilog(x)" function returns the position number (1 through n) of the
+highest set bit in the two's complement integer value
+<tt>[x]</tt>. Values of <tt>[x]</tt> less than zero are defined to return zero.</p>
+
+<pre>
+  1) [return_value] = 0;
+  2) if ( [x] is greater than zero ){
+      
+       3) increment [return_value];
+       4) logical shift [x] one bit to the right, padding the MSb with zero
+       5) repeat at step 2)
+
+     }
+
+   6) done
+</pre>
+
+<p>Examples:</p>
+
+<ul>
+<li>ilog(0) = 0;</li>
+<li>ilog(1) = 1;</li>
+<li>ilog(2) = 2;</li>
+<li>ilog(3) = 2;</li>
+<li>ilog(4) = 3;</li>
+<li>ilog(7) = 3;</li>
+<li>ilog(negative number) = 0;</li>
+</ul>
+
+<h2><a name="float32_unpack">float32_unpack</a></h2>
+
+<p>"float32_unpack(x)" is intended to translate the packed binary
+representation of a Vorbis codebook float value into the
+representation used by the decoder for floating point numbers. For
+purposes of this example, we will unpack a Vorbis float32 into a
+host-native floating point number.</p>
+
+<pre>
+  1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
+  2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
+  3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
+  4) if ( [sign] is nonzero ) then negate [mantissa]
+  5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
+</pre>
+
+<h2><a name="lookup1_values">lookup1_values</a></h2>
+
+<p>"lookup1_values(codebook_entries,codebook_dimensions)" is used to
+compute the correct length of the value index for a codebook VQ lookup
+table of lookup type 1. The values on this list are permuted to
+construct the VQ vector lookup table of size
+<tt>[codebook_entries]</tt>.</p>
+
+<p>The return value for this function is defined to be 'the greatest
+integer value for which <tt>[return_value] to the power of
+[codebook_dimensions] is less than or equal to
+[codebook_entries]</tt>'.</p>
+
+<h2><a name="low_neighbor">low_neighbor</a></h2>
+
+<p>"low_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
+the greatest value scalar element for which <i>n</i> is less than
+<tt>[x]</tt> and <tt>vector [v] element <i>n</i> is less
+than vector [v] element [x]</tt>.</p>
+
+<h2><a name="high_neighbor">high_neighbor</a></h2>
+
+<p>"high_neighbor(v,x)" finds the position <i>n</i> in vector [v] of
+the lowest value scalar element for which <i>n</i> is less than
+<tt>[x]</tt> and <tt>vector [v] element <i>n</i> is greater
+than vector [v] element [x]</tt>.</p>
+
+<h2><a name="render_point">render_point</a></h2>
+
+<p>"render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
+along the line specified by x0, x1, y0 and y1. This function uses an
+integer algorithm to solve for the point directly without calculating
+intervening values along the line.</p>
+
+<pre>
+  1)  [dy] = [y1] - [y0]
+  2) [adx] = [x1] - [x0]
+  3) [ady] = absolute value of [dy]
+  4) [err] = [ady] * ([X] - [x0])
+  5) [off] = [err] / [adx] using integer division
+  6) if ( [dy] is less than zero ) {
+
+       7) [Y] = [y0] - [off]
+
+     } else {
+
+       8) [Y] = [y0] + [off]
+  
+     }
+
+  9) done
+</pre>
+
+<h2><a name="render_line">render_line</a></h2>
+
+<p>Floor decode type one uses the integer line drawing algorithm of
+"render_line(x0, y0, x1, y1, v)" to construct an integer floor
+curve for contiguous piecewise line segments. Note that it has not
+been relevant elsewhere, but here we must define integer division as
+rounding division of both positive and negative numbers toward zero.</p>
+
+<pre>
+  1)   [dy] = [y1] - [y0]
+  2)  [adx] = [x1] - [x0]
+  3)  [ady] = absolute value of [dy]
+  4) [base] = [dy] / [adx] using integer division
+  5)    [x] = [x0]
+  6)    [y] = [y0]
+  7)  [err] = 0
+
+  8) if ( [dy] is less than 0 ) {
+
+        9) [sy] = [base] - 1
+
+     } else {
+
+       10) [sy] = [base] + 1
+
+     }
+
+ 11) [ady] = [ady] - (absolute value of [base]) * [adx]
+ 12) vector [v] element [x] = [y]
+
+ 13) iterate [x] over the range [x0]+1 ... [x1]-1 {
+
+       14) [err] = [err] + [ady];
+       15) if ( [err] >= [adx] ) {
+
+             15) [err] = [err] - [adx]
+             16)   [y] = [y] + [sy]
+
+           } else {
+
+             17) [y] = [y] + [base]
+   
+           }
+
+       18) vector [v] element [x] = [y]
+
+     }
+</pre>
+
+<div id="copyright">
+  The Xiph Fish Logo is a
+  trademark (&trade;) of Xiph.Org.<br/>
+
+  These pages &copy; 1994 - 2005 Xiph.Org. All rights reserved.
+</div>
+
+</body>
+</html>