annotate src/libvorbis-1.3.3/doc/09-helper.tex @ 83:ae30d91d2ffe

Replace these with versions built using an older toolset (so as to avoid ABI compatibilities when linking on Ubuntu 14.04 for packaging purposes)
author Chris Cannam
date Fri, 07 Feb 2020 11:51:13 +0000
parents 05aa0afa9217
children
rev   line source
Chris@1 1 % -*- mode: latex; TeX-master: "Vorbis_I_spec"; -*-
Chris@1 2 %!TEX root = Vorbis_I_spec.tex
Chris@1 3 % $Id$
Chris@1 4 \section{Helper equations} \label{vorbis:spec:helper}
Chris@1 5
Chris@1 6 \subsection{Overview}
Chris@1 7
Chris@1 8 The equations below are used in multiple places by the Vorbis codec
Chris@1 9 specification. Rather than cluttering up the main specification
Chris@1 10 documents, they are defined here and referenced where appropriate.
Chris@1 11
Chris@1 12
Chris@1 13 \subsection{Functions}
Chris@1 14
Chris@1 15 \subsubsection{ilog} \label{vorbis:spec:ilog}
Chris@1 16
Chris@1 17 The "ilog(x)" function returns the position number (1 through n) of the highest set bit in the two's complement integer value
Chris@1 18 \varname{[x]}. Values of \varname{[x]} less than zero are defined to return zero.
Chris@1 19
Chris@1 20 \begin{programlisting}
Chris@1 21 1) [return\_value] = 0;
Chris@1 22 2) if ( [x] is greater than zero ) {
Chris@1 23
Chris@1 24 3) increment [return\_value];
Chris@1 25 4) logical shift [x] one bit to the right, padding the MSb with zero
Chris@1 26 5) repeat at step 2)
Chris@1 27
Chris@1 28 }
Chris@1 29
Chris@1 30 6) done
Chris@1 31 \end{programlisting}
Chris@1 32
Chris@1 33 Examples:
Chris@1 34
Chris@1 35 \begin{itemize}
Chris@1 36 \item ilog(0) = 0;
Chris@1 37 \item ilog(1) = 1;
Chris@1 38 \item ilog(2) = 2;
Chris@1 39 \item ilog(3) = 2;
Chris@1 40 \item ilog(4) = 3;
Chris@1 41 \item ilog(7) = 3;
Chris@1 42 \item ilog(negative number) = 0;
Chris@1 43 \end{itemize}
Chris@1 44
Chris@1 45
Chris@1 46
Chris@1 47
Chris@1 48 \subsubsection{float32\_unpack} \label{vorbis:spec:float32:unpack}
Chris@1 49
Chris@1 50 "float32\_unpack(x)" is intended to translate the packed binary
Chris@1 51 representation of a Vorbis codebook float value into the
Chris@1 52 representation used by the decoder for floating point numbers. For
Chris@1 53 purposes of this example, we will unpack a Vorbis float32 into a
Chris@1 54 host-native floating point number.
Chris@1 55
Chris@1 56 \begin{programlisting}
Chris@1 57 1) [mantissa] = [x] bitwise AND 0x1fffff (unsigned result)
Chris@1 58 2) [sign] = [x] bitwise AND 0x80000000 (unsigned result)
Chris@1 59 3) [exponent] = ( [x] bitwise AND 0x7fe00000) shifted right 21 bits (unsigned result)
Chris@1 60 4) if ( [sign] is nonzero ) then negate [mantissa]
Chris@1 61 5) return [mantissa] * ( 2 ^ ( [exponent] - 788 ) )
Chris@1 62 \end{programlisting}
Chris@1 63
Chris@1 64
Chris@1 65
Chris@1 66 \subsubsection{lookup1\_values} \label{vorbis:spec:lookup1:values}
Chris@1 67
Chris@1 68 "lookup1\_values(codebook\_entries,codebook\_dimensions)" is used to
Chris@1 69 compute the correct length of the value index for a codebook VQ lookup
Chris@1 70 table of lookup type 1. The values on this list are permuted to
Chris@1 71 construct the VQ vector lookup table of size
Chris@1 72 \varname{[codebook\_entries]}.
Chris@1 73
Chris@1 74 The return value for this function is defined to be 'the greatest
Chris@1 75 integer value for which \varname{[return\_value]} to the power of
Chris@1 76 \varname{[codebook\_dimensions]} is less than or equal to
Chris@1 77 \varname{[codebook\_entries]}'.
Chris@1 78
Chris@1 79
Chris@1 80
Chris@1 81 \subsubsection{low\_neighbor} \label{vorbis:spec:low:neighbor}
Chris@1 82
Chris@1 83 "low\_neighbor(v,x)" finds the position \varname{n} in vector \varname{[v]} of
Chris@1 84 the greatest value scalar element for which \varname{n} is less than
Chris@1 85 \varname{[x]} and vector \varname{[v]} element \varname{n} is less
Chris@1 86 than vector \varname{[v]} element \varname{[x]}.
Chris@1 87
Chris@1 88 \subsubsection{high\_neighbor} \label{vorbis:spec:high:neighbor}
Chris@1 89
Chris@1 90 "high\_neighbor(v,x)" finds the position \varname{n} in vector [v] of
Chris@1 91 the lowest value scalar element for which \varname{n} is less than
Chris@1 92 \varname{[x]} and vector \varname{[v]} element \varname{n} is greater
Chris@1 93 than vector \varname{[v]} element \varname{[x]}.
Chris@1 94
Chris@1 95
Chris@1 96
Chris@1 97 \subsubsection{render\_point} \label{vorbis:spec:render:point}
Chris@1 98
Chris@1 99 "render\_point(x0,y0,x1,y1,X)" is used to find the Y value at point X
Chris@1 100 along the line specified by x0, x1, y0 and y1. This function uses an
Chris@1 101 integer algorithm to solve for the point directly without calculating
Chris@1 102 intervening values along the line.
Chris@1 103
Chris@1 104 \begin{programlisting}
Chris@1 105 1) [dy] = [y1] - [y0]
Chris@1 106 2) [adx] = [x1] - [x0]
Chris@1 107 3) [ady] = absolute value of [dy]
Chris@1 108 4) [err] = [ady] * ([X] - [x0])
Chris@1 109 5) [off] = [err] / [adx] using integer division
Chris@1 110 6) if ( [dy] is less than zero ) {
Chris@1 111
Chris@1 112 7) [Y] = [y0] - [off]
Chris@1 113
Chris@1 114 } else {
Chris@1 115
Chris@1 116 8) [Y] = [y0] + [off]
Chris@1 117
Chris@1 118 }
Chris@1 119
Chris@1 120 9) done
Chris@1 121 \end{programlisting}
Chris@1 122
Chris@1 123
Chris@1 124
Chris@1 125 \subsubsection{render\_line} \label{vorbis:spec:render:line}
Chris@1 126
Chris@1 127 Floor decode type one uses the integer line drawing algorithm of
Chris@1 128 "render\_line(x0, y0, x1, y1, v)" to construct an integer floor
Chris@1 129 curve for contiguous piecewise line segments. Note that it has not
Chris@1 130 been relevant elsewhere, but here we must define integer division as
Chris@1 131 rounding division of both positive and negative numbers toward zero.
Chris@1 132
Chris@1 133
Chris@1 134 \begin{programlisting}
Chris@1 135 1) [dy] = [y1] - [y0]
Chris@1 136 2) [adx] = [x1] - [x0]
Chris@1 137 3) [ady] = absolute value of [dy]
Chris@1 138 4) [base] = [dy] / [adx] using integer division
Chris@1 139 5) [x] = [x0]
Chris@1 140 6) [y] = [y0]
Chris@1 141 7) [err] = 0
Chris@1 142
Chris@1 143 8) if ( [dy] is less than 0 ) {
Chris@1 144
Chris@1 145 9) [sy] = [base] - 1
Chris@1 146
Chris@1 147 } else {
Chris@1 148
Chris@1 149 10) [sy] = [base] + 1
Chris@1 150
Chris@1 151 }
Chris@1 152
Chris@1 153 11) [ady] = [ady] - (absolute value of [base]) * [adx]
Chris@1 154 12) vector [v] element [x] = [y]
Chris@1 155
Chris@1 156 13) iterate [x] over the range [x0]+1 ... [x1]-1 {
Chris@1 157
Chris@1 158 14) [err] = [err] + [ady];
Chris@1 159 15) if ( [err] >= [adx] ) {
Chris@1 160
Chris@1 161 16) [err] = [err] - [adx]
Chris@1 162 17) [y] = [y] + [sy]
Chris@1 163
Chris@1 164 } else {
Chris@1 165
Chris@1 166 18) [y] = [y] + [base]
Chris@1 167
Chris@1 168 }
Chris@1 169
Chris@1 170 19) vector [v] element [x] = [y]
Chris@1 171
Chris@1 172 }
Chris@1 173 \end{programlisting}
Chris@1 174
Chris@1 175
Chris@1 176
Chris@1 177
Chris@1 178
Chris@1 179
Chris@1 180
Chris@1 181