annotate src/libvorbis-1.3.3/doc/06-floor0.tex @ 1:05aa0afa9217

Bring in flac, ogg, vorbis
author Chris Cannam
date Tue, 19 Mar 2013 17:37:49 +0000
parents
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{Floor type 0 setup and decode} \label{vorbis:spec:floor0}
Chris@1 5
Chris@1 6 \subsection{Overview}
Chris@1 7
Chris@1 8 Vorbis floor type zero uses Line Spectral Pair (LSP, also alternately
Chris@1 9 known as Line Spectral Frequency or LSF) representation to encode a
Chris@1 10 smooth spectral envelope curve as the frequency response of the LSP
Chris@1 11 filter. This representation is equivalent to a traditional all-pole
Chris@1 12 infinite impulse response filter as would be used in linear predictive
Chris@1 13 coding; LSP representation may be converted to LPC representation and
Chris@1 14 vice-versa.
Chris@1 15
Chris@1 16
Chris@1 17
Chris@1 18 \subsection{Floor 0 format}
Chris@1 19
Chris@1 20 Floor zero configuration consists of six integer fields and a list of
Chris@1 21 VQ codebooks for use in coding/decoding the LSP filter coefficient
Chris@1 22 values used by each frame.
Chris@1 23
Chris@1 24 \subsubsection{header decode}
Chris@1 25
Chris@1 26 Configuration information for instances of floor zero decodes from the
Chris@1 27 codec setup header (third packet). configuration decode proceeds as
Chris@1 28 follows:
Chris@1 29
Chris@1 30 \begin{Verbatim}[commandchars=\\\{\}]
Chris@1 31 1) [floor0\_order] = read an unsigned integer of 8 bits
Chris@1 32 2) [floor0\_rate] = read an unsigned integer of 16 bits
Chris@1 33 3) [floor0\_bark\_map\_size] = read an unsigned integer of 16 bits
Chris@1 34 4) [floor0\_amplitude\_bits] = read an unsigned integer of six bits
Chris@1 35 5) [floor0\_amplitude\_offset] = read an unsigned integer of eight bits
Chris@1 36 6) [floor0\_number\_of\_books] = read an unsigned integer of four bits and add 1
Chris@1 37 7) array [floor0\_book\_list] = read a list of [floor0\_number\_of\_books] unsigned integers of eight bits each;
Chris@1 38 \end{Verbatim}
Chris@1 39
Chris@1 40 An end-of-packet condition during any of these bitstream reads renders
Chris@1 41 this stream undecodable. In addition, any element of the array
Chris@1 42 \varname{[floor0\_book\_list]} that is greater than the maximum codebook
Chris@1 43 number for this bitstream is an error condition that also renders the
Chris@1 44 stream undecodable.
Chris@1 45
Chris@1 46
Chris@1 47
Chris@1 48 \subsubsection{packet decode} \label{vorbis:spec:floor0-decode}
Chris@1 49
Chris@1 50 Extracting a floor0 curve from an audio packet consists of first
Chris@1 51 decoding the curve amplitude and \varname{[floor0\_order]} LSP
Chris@1 52 coefficient values from the bitstream, and then computing the floor
Chris@1 53 curve, which is defined as the frequency response of the decoded LSP
Chris@1 54 filter.
Chris@1 55
Chris@1 56 Packet decode proceeds as follows:
Chris@1 57 \begin{Verbatim}[commandchars=\\\{\}]
Chris@1 58 1) [amplitude] = read an unsigned integer of [floor0\_amplitude\_bits] bits
Chris@1 59 2) if ( [amplitude] is greater than zero ) \{
Chris@1 60 3) [coefficients] is an empty, zero length vector
Chris@1 61 4) [booknumber] = read an unsigned integer of \link{vorbis:spec:ilog}{ilog}( [floor0\_number\_of\_books] ) bits
Chris@1 62 5) if ( [booknumber] is greater than the highest number decode codebook ) then packet is undecodable
Chris@1 63 6) [last] = zero;
Chris@1 64 7) vector [temp\_vector] = read vector from bitstream using codebook number [floor0\_book\_list] element [booknumber] in VQ context.
Chris@1 65 8) add the scalar value [last] to each scalar in vector [temp\_vector]
Chris@1 66 9) [last] = the value of the last scalar in vector [temp\_vector]
Chris@1 67 10) concatenate [temp\_vector] onto the end of the [coefficients] vector
Chris@1 68 11) if (length of vector [coefficients] is less than [floor0\_order], continue at step 6
Chris@1 69
Chris@1 70 \}
Chris@1 71
Chris@1 72 12) done.
Chris@1 73
Chris@1 74 \end{Verbatim}
Chris@1 75
Chris@1 76 Take note of the following properties of decode:
Chris@1 77 \begin{itemize}
Chris@1 78 \item An \varname{[amplitude]} value of zero must result in a return code that indicates this channel is unused in this frame (the output of the channel will be all-zeroes in synthesis). Several later stages of decode don't occur for an unused channel.
Chris@1 79 \item An end-of-packet condition during decode should be considered a
Chris@1 80 nominal occruence; if end-of-packet is reached during any read
Chris@1 81 operation above, floor decode is to return 'unused' status as if the
Chris@1 82 \varname{[amplitude]} value had read zero at the beginning of decode.
Chris@1 83
Chris@1 84 \item The book number used for decode
Chris@1 85 can, in fact, be stored in the bitstream in \link{vorbis:spec:ilog}{ilog}( \varname{[floor0\_number\_of\_books]} -
Chris@1 86 1 ) bits. Nevertheless, the above specification is correct and values
Chris@1 87 greater than the maximum possible book value are reserved.
Chris@1 88
Chris@1 89 \item The number of scalars read into the vector \varname{[coefficients]}
Chris@1 90 may be greater than \varname{[floor0\_order]}, the number actually
Chris@1 91 required for curve computation. For example, if the VQ codebook used
Chris@1 92 for the floor currently being decoded has a
Chris@1 93 \varname{[codebook\_dimensions]} value of three and
Chris@1 94 \varname{[floor0\_order]} is ten, the only way to fill all the needed
Chris@1 95 scalars in \varname{[coefficients]} is to to read a total of twelve
Chris@1 96 scalars as four vectors of three scalars each. This is not an error
Chris@1 97 condition, and care must be taken not to allow a buffer overflow in
Chris@1 98 decode. The extra values are not used and may be ignored or discarded.
Chris@1 99 \end{itemize}
Chris@1 100
Chris@1 101
Chris@1 102
Chris@1 103
Chris@1 104 \subsubsection{curve computation} \label{vorbis:spec:floor0-synth}
Chris@1 105
Chris@1 106 Given an \varname{[amplitude]} integer and \varname{[coefficients]}
Chris@1 107 vector from packet decode as well as the [floor0\_order],
Chris@1 108 [floor0\_rate], [floor0\_bark\_map\_size], [floor0\_amplitude\_bits] and
Chris@1 109 [floor0\_amplitude\_offset] values from floor setup, and an output
Chris@1 110 vector size \varname{[n]} specified by the decode process, we compute a
Chris@1 111 floor output vector.
Chris@1 112
Chris@1 113 If the value \varname{[amplitude]} is zero, the return value is a
Chris@1 114 length \varname{[n]} vector with all-zero scalars. Otherwise, begin by
Chris@1 115 assuming the following definitions for the given vector to be
Chris@1 116 synthesized:
Chris@1 117
Chris@1 118 \begin{displaymath}
Chris@1 119 \mathrm{map}_i = \left\{
Chris@1 120 \begin{array}{ll}
Chris@1 121 \min (
Chris@1 122 \mathtt{floor0\texttt{\_}bark\texttt{\_}map\texttt{\_}size} - 1,
Chris@1 123 foobar
Chris@1 124 ) & \textrm{for } i \in [0,n-1] \\
Chris@1 125 -1 & \textrm{for } i = n
Chris@1 126 \end{array}
Chris@1 127 \right.
Chris@1 128 \end{displaymath}
Chris@1 129
Chris@1 130 where
Chris@1 131
Chris@1 132 \begin{displaymath}
Chris@1 133 foobar =
Chris@1 134 \left\lfloor
Chris@1 135 \mathrm{bark}\left(\frac{\mathtt{floor0\texttt{\_}rate} \cdot i}{2n}\right) \cdot \frac{\mathtt{floor0\texttt{\_}bark\texttt{\_}map\texttt{\_}size}} {\mathrm{bark}(.5 \cdot \mathtt{floor0\texttt{\_}rate})}
Chris@1 136 \right\rfloor
Chris@1 137 \end{displaymath}
Chris@1 138
Chris@1 139 and
Chris@1 140
Chris@1 141 \begin{displaymath}
Chris@1 142 \mathrm{bark}(x) = 13.1 \arctan (.00074x) + 2.24 \arctan (.0000000185x^2 + .0001x)
Chris@1 143 \end{displaymath}
Chris@1 144
Chris@1 145 The above is used to synthesize the LSP curve on a Bark-scale frequency
Chris@1 146 axis, then map the result to a linear-scale frequency axis.
Chris@1 147 Similarly, the below calculation synthesizes the output LSP curve \varname{[output]} on a log
Chris@1 148 (dB) amplitude scale, mapping it to linear amplitude in the last step:
Chris@1 149
Chris@1 150 \begin{enumerate}
Chris@1 151 \item \varname{[i]} = 0
Chris@1 152 \item \varname{[$\omega$]} = $\pi$ * map element \varname{[i]} / \varname{[floor0\_bark\_map\_size]}
Chris@1 153 \item if ( \varname{[floor0\_order]} is odd ) {
Chris@1 154 \begin{enumerate}
Chris@1 155 \item calculate \varname{[p]} and \varname{[q]} according to:
Chris@1 156 \begin{eqnarray*}
Chris@1 157 p & = & (1 - \cos^2\omega)\prod_{j=0}^{\frac{\mathtt{floor0\texttt{\_}order}-3}{2}} 4 (\cos([\mathtt{coefficients}]_{2j+1}) - \cos \omega)^2 \\
Chris@1 158 q & = & \frac{1}{4} \prod_{j=0}^{\frac{\mathtt{floor0\texttt{\_}order}-1}{2}} 4 (\cos([\mathtt{coefficients}]_{2j}) - \cos \omega)^2
Chris@1 159 \end{eqnarray*}
Chris@1 160
Chris@1 161 \end{enumerate}
Chris@1 162 } else \varname{[floor0\_order]} is even {
Chris@1 163 \begin{enumerate}[resume]
Chris@1 164 \item calculate \varname{[p]} and \varname{[q]} according to:
Chris@1 165 \begin{eqnarray*}
Chris@1 166 p & = & \frac{(1 - \cos\omega)}{2} \prod_{j=0}^{\frac{\mathtt{floor0\texttt{\_}order}-2}{2}} 4 (\cos([\mathtt{coefficients}]_{2j+1}) - \cos \omega)^2 \\
Chris@1 167 q & = & \frac{(1 + \cos\omega)}{2} \prod_{j=0}^{\frac{\mathtt{floor0\texttt{\_}order}-2}{2}} 4 (\cos([\mathtt{coefficients}]_{2j}) - \cos \omega)^2
Chris@1 168 \end{eqnarray*}
Chris@1 169
Chris@1 170 \end{enumerate}
Chris@1 171 }
Chris@1 172
Chris@1 173 \item calculate \varname{[linear\_floor\_value]} according to:
Chris@1 174 \begin{displaymath}
Chris@1 175 \exp \left( .11512925 \left(\frac{\mathtt{amplitude} \cdot \mathtt{floor0\texttt{\_}amplitute\texttt{\_}offset}}{(2^{\mathtt{floor0\texttt{\_}amplitude\texttt{\_}bits}}-1)\sqrt{p+q}}
Chris@1 176 - \mathtt{floor0\texttt{\_}amplitude\texttt{\_}offset} \right) \right)
Chris@1 177 \end{displaymath}
Chris@1 178
Chris@1 179 \item \varname{[iteration\_condition]} = map element \varname{[i]}
Chris@1 180 \item \varname{[output]} element \varname{[i]} = \varname{[linear\_floor\_value]}
Chris@1 181 \item increment \varname{[i]}
Chris@1 182 \item if ( map element \varname{[i]} is equal to \varname{[iteration\_condition]} ) continue at step 5
Chris@1 183 \item if ( \varname{[i]} is less than \varname{[n]} ) continue at step 2
Chris@1 184 \item done
Chris@1 185 \end{enumerate}
Chris@1 186
Chris@1 187
Chris@1 188
Chris@1 189
Chris@1 190
Chris@1 191
Chris@1 192