Blame doc/helper.html

Packit 06404a
Packit 06404a
<html>
Packit 06404a
<head>
Packit 06404a
Packit 06404a
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-15"/>
Packit 06404a
<title>Ogg Vorbis Documentation</title>
Packit 06404a
Packit 06404a
<style type="text/css">
Packit 06404a
body {
Packit 06404a
  margin: 0 18px 0 18px;
Packit 06404a
  padding-bottom: 30px;
Packit 06404a
  font-family: Verdana, Arial, Helvetica, sans-serif;
Packit 06404a
  color: #333333;
Packit 06404a
  font-size: .8em;
Packit 06404a
}
Packit 06404a
Packit 06404a
a {
Packit 06404a
  color: #3366cc;
Packit 06404a
}
Packit 06404a
Packit 06404a
img {
Packit 06404a
  border: 0;
Packit 06404a
}
Packit 06404a
Packit 06404a
#xiphlogo {
Packit 06404a
  margin: 30px 0 16px 0;
Packit 06404a
}
Packit 06404a
Packit 06404a
#content p {
Packit 06404a
  line-height: 1.4;
Packit 06404a
}
Packit 06404a
Packit 06404a
h1, h1 a, h2, h2 a, h3, h3 a {
Packit 06404a
  font-weight: bold;
Packit 06404a
  color: #ff9900;
Packit 06404a
  margin: 1.3em 0 8px 0;
Packit 06404a
}
Packit 06404a
Packit 06404a
h1 {
Packit 06404a
  font-size: 1.3em;
Packit 06404a
}
Packit 06404a
Packit 06404a
h2 {
Packit 06404a
  font-size: 1.2em;
Packit 06404a
}
Packit 06404a
Packit 06404a
h3 {
Packit 06404a
  font-size: 1.1em;
Packit 06404a
}
Packit 06404a
Packit 06404a
li {
Packit 06404a
  line-height: 1.4;
Packit 06404a
}
Packit 06404a
Packit 06404a
#copyright {
Packit 06404a
  margin-top: 30px;
Packit 06404a
  line-height: 1.5em;
Packit 06404a
  text-align: center;
Packit 06404a
  font-size: .8em;
Packit 06404a
  color: #888888;
Packit 06404a
  clear: both;
Packit 06404a
}
Packit 06404a
</style>
Packit 06404a
Packit 06404a
</head>
Packit 06404a
Packit 06404a
<body>
Packit 06404a
Packit 06404a
Packit 06404a
  Fish Logo and Xiph.Org
Packit 06404a
Packit 06404a
Packit 06404a

Ogg Vorbis I format specification: helper equations

Packit 06404a
Packit 06404a

Overview

Packit 06404a
Packit 06404a

The equations below are used in multiple places by the Vorbis codec

Packit 06404a
specification. Rather than cluttering up the main specification
Packit 06404a
documents, they are defined here and linked in the main documents
Packit 06404a
where appropriate.

Packit 06404a
Packit 06404a

ilog

Packit 06404a
Packit 06404a

The "ilog(x)" function returns the position number (1 through n) of the

Packit 06404a
highest set bit in the two's complement integer value
Packit 06404a
<tt>[x]</tt>. Values of <tt>[x]</tt> less than zero are defined to return zero.

Packit 06404a
Packit 06404a
Packit 06404a
  1) [return_value] = 0;
Packit 06404a
  2) if ( [x] is greater than zero ){
Packit 06404a
      
Packit 06404a
       3) increment [return_value];
Packit 06404a
       4) logical shift [x] one bit to the right, padding the MSb with zero
Packit 06404a
       5) repeat at step 2)
Packit 06404a
Packit 06404a
     }
Packit 06404a
Packit 06404a
   6) done
Packit 06404a
Packit 06404a
Packit 06404a

Examples:

Packit 06404a
Packit 06404a
    Packit 06404a
  • ilog(0) = 0;
  • Packit 06404a
  • ilog(1) = 1;
  • Packit 06404a
  • ilog(2) = 2;
  • Packit 06404a
  • ilog(3) = 2;
  • Packit 06404a
  • ilog(4) = 3;
  • Packit 06404a
  • ilog(7) = 3;
  • Packit 06404a
  • ilog(negative number) = 0;
  • Packit 06404a
    Packit 06404a
    Packit 06404a

    float32_unpack

    Packit 06404a
    Packit 06404a

    "float32_unpack(x)" is intended to translate the packed binary

    Packit 06404a
    representation of a Vorbis codebook float value into the
    Packit 06404a
    representation used by the decoder for floating point numbers. For
    Packit 06404a
    purposes of this example, we will unpack a Vorbis float32 into a
    Packit 06404a
    host-native floating point number.

    Packit 06404a
    Packit 06404a
    Packit 06404a
      1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
    Packit 06404a
      2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
    Packit 06404a
      3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
    Packit 06404a
      4) if ( [sign] is nonzero ) then negate [mantissa]
    Packit 06404a
      5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
    Packit 06404a
    Packit 06404a
    Packit 06404a

    lookup1_values

    Packit 06404a
    Packit 06404a

    "lookup1_values(codebook_entries,codebook_dimensions)" is used to

    Packit 06404a
    compute the correct length of the value index for a codebook VQ lookup
    Packit 06404a
    table of lookup type 1. The values on this list are permuted to
    Packit 06404a
    construct the VQ vector lookup table of size
    Packit 06404a
    <tt>[codebook_entries]</tt>.

    Packit 06404a
    Packit 06404a

    The return value for this function is defined to be 'the greatest

    Packit 06404a
    integer value for which <tt>[return_value] to the power of
    Packit 06404a
    [codebook_dimensions] is less than or equal to
    Packit 06404a
    [codebook_entries]</tt>'.

    Packit 06404a
    Packit 06404a

    low_neighbor

    Packit 06404a
    Packit 06404a

    "low_neighbor(v,x)" finds the position n in vector [v] of

    Packit 06404a
    the greatest value scalar element for which n is less than
    Packit 06404a
    <tt>[x]</tt> and <tt>vector [v] element n is less
    Packit 06404a
    than vector [v] element [x]</tt>.

    Packit 06404a
    Packit 06404a

    high_neighbor

    Packit 06404a
    Packit 06404a

    "high_neighbor(v,x)" finds the position n in vector [v] of

    Packit 06404a
    the lowest value scalar element for which n is less than
    Packit 06404a
    <tt>[x]</tt> and <tt>vector [v] element n is greater
    Packit 06404a
    than vector [v] element [x]</tt>.

    Packit 06404a
    Packit 06404a

    render_point

    Packit 06404a
    Packit 06404a

    "render_point(x0,y0,x1,y1,X)" is used to find the Y value at point X

    Packit 06404a
    along the line specified by x0, x1, y0 and y1. This function uses an
    Packit 06404a
    integer algorithm to solve for the point directly without calculating
    Packit 06404a
    intervening values along the line.

    Packit 06404a
    Packit 06404a
    Packit 06404a
      1)  [dy] = [y1] - [y0]
    Packit 06404a
      2) [adx] = [x1] - [x0]
    Packit 06404a
      3) [ady] = absolute value of [dy]
    Packit 06404a
      4) [err] = [ady] * ([X] - [x0])
    Packit 06404a
      5) [off] = [err] / [adx] using integer division
    Packit 06404a
      6) if ( [dy] is less than zero ) {
    Packit 06404a
    Packit 06404a
           7) [Y] = [y0] - [off]
    Packit 06404a
    Packit 06404a
         } else {
    Packit 06404a
    Packit 06404a
           8) [Y] = [y0] + [off]
    Packit 06404a
      
    Packit 06404a
         }
    Packit 06404a
    Packit 06404a
      9) done
    Packit 06404a
    Packit 06404a
    Packit 06404a

    render_line

    Packit 06404a
    Packit 06404a

    Floor decode type one uses the integer line drawing algorithm of

    Packit 06404a
    "render_line(x0, y0, x1, y1, v)" to construct an integer floor
    Packit 06404a
    curve for contiguous piecewise line segments. Note that it has not
    Packit 06404a
    been relevant elsewhere, but here we must define integer division as
    Packit 06404a
    rounding division of both positive and negative numbers toward zero.

    Packit 06404a
    Packit 06404a
    Packit 06404a
      1)   [dy] = [y1] - [y0]
    Packit 06404a
      2)  [adx] = [x1] - [x0]
    Packit 06404a
      3)  [ady] = absolute value of [dy]
    Packit 06404a
      4) [base] = [dy] / [adx] using integer division
    Packit 06404a
      5)    [x] = [x0]
    Packit 06404a
      6)    [y] = [y0]
    Packit 06404a
      7)  [err] = 0
    Packit 06404a
    Packit 06404a
      8) if ( [dy] is less than 0 ) {
    Packit 06404a
    Packit 06404a
            9) [sy] = [base] - 1
    Packit 06404a
    Packit 06404a
         } else {
    Packit 06404a
    Packit 06404a
           10) [sy] = [base] + 1
    Packit 06404a
    Packit 06404a
         }
    Packit 06404a
    Packit 06404a
     11) [ady] = [ady] - (absolute value of [base]) * [adx]
    Packit 06404a
     12) vector [v] element [x] = [y]
    Packit 06404a
    Packit 06404a
     13) iterate [x] over the range [x0]+1 ... [x1]-1 {
    Packit 06404a
    Packit 06404a
           14) [err] = [err] + [ady];
    Packit 06404a
           15) if ( [err] >= [adx] ) {
    Packit 06404a
    Packit 06404a
                 15) [err] = [err] - [adx]
    Packit 06404a
                 16)   [y] = [y] + [sy]
    Packit 06404a
    Packit 06404a
               } else {
    Packit 06404a
    Packit 06404a
                 17) [y] = [y] + [base]
    Packit 06404a
       
    Packit 06404a
               }
    Packit 06404a
    Packit 06404a
           18) vector [v] element [x] = [y]
    Packit 06404a
    Packit 06404a
         }
    Packit 06404a
    Packit 06404a
    Packit 06404a
    Packit 06404a
      The Xiph Fish Logo is a
    Packit 06404a
      trademark (™) of Xiph.Org.
    Packit 06404a
    Packit 06404a
      These pages © 1994 - 2005 Xiph.Org. All rights reserved.
    Packit 06404a
    Packit 06404a
    Packit 06404a
    </body>
    Packit 06404a
    </html>