annotate src/libvorbis-1.3.3/doc/09-helper.tex @ 169:223a55898ab9 tip default

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