Chris@1: % -*- mode: latex; TeX-master: "Vorbis_I_spec"; -*- Chris@1: %!TEX root = Vorbis_I_spec.tex Chris@1: % $Id$ Chris@1: \section{Floor type 0 setup and decode} \label{vorbis:spec:floor0} Chris@1: Chris@1: \subsection{Overview} Chris@1: Chris@1: Vorbis floor type zero uses Line Spectral Pair (LSP, also alternately Chris@1: known as Line Spectral Frequency or LSF) representation to encode a Chris@1: smooth spectral envelope curve as the frequency response of the LSP Chris@1: filter. This representation is equivalent to a traditional all-pole Chris@1: infinite impulse response filter as would be used in linear predictive Chris@1: coding; LSP representation may be converted to LPC representation and Chris@1: vice-versa. Chris@1: Chris@1: Chris@1: Chris@1: \subsection{Floor 0 format} Chris@1: Chris@1: Floor zero configuration consists of six integer fields and a list of Chris@1: VQ codebooks for use in coding/decoding the LSP filter coefficient Chris@1: values used by each frame. Chris@1: Chris@1: \subsubsection{header decode} Chris@1: Chris@1: Configuration information for instances of floor zero decodes from the Chris@1: codec setup header (third packet). configuration decode proceeds as Chris@1: follows: Chris@1: Chris@1: \begin{Verbatim}[commandchars=\\\{\}] Chris@1: 1) [floor0\_order] = read an unsigned integer of 8 bits Chris@1: 2) [floor0\_rate] = read an unsigned integer of 16 bits Chris@1: 3) [floor0\_bark\_map\_size] = read an unsigned integer of 16 bits Chris@1: 4) [floor0\_amplitude\_bits] = read an unsigned integer of six bits Chris@1: 5) [floor0\_amplitude\_offset] = read an unsigned integer of eight bits Chris@1: 6) [floor0\_number\_of\_books] = read an unsigned integer of four bits and add 1 Chris@1: 7) array [floor0\_book\_list] = read a list of [floor0\_number\_of\_books] unsigned integers of eight bits each; Chris@1: \end{Verbatim} Chris@1: Chris@1: An end-of-packet condition during any of these bitstream reads renders Chris@1: this stream undecodable. In addition, any element of the array Chris@1: \varname{[floor0\_book\_list]} that is greater than the maximum codebook Chris@1: number for this bitstream is an error condition that also renders the Chris@1: stream undecodable. Chris@1: Chris@1: Chris@1: Chris@1: \subsubsection{packet decode} \label{vorbis:spec:floor0-decode} Chris@1: Chris@1: Extracting a floor0 curve from an audio packet consists of first Chris@1: decoding the curve amplitude and \varname{[floor0\_order]} LSP Chris@1: coefficient values from the bitstream, and then computing the floor Chris@1: curve, which is defined as the frequency response of the decoded LSP Chris@1: filter. Chris@1: Chris@1: Packet decode proceeds as follows: Chris@1: \begin{Verbatim}[commandchars=\\\{\}] Chris@1: 1) [amplitude] = read an unsigned integer of [floor0\_amplitude\_bits] bits Chris@1: 2) if ( [amplitude] is greater than zero ) \{ Chris@1: 3) [coefficients] is an empty, zero length vector Chris@1: 4) [booknumber] = read an unsigned integer of \link{vorbis:spec:ilog}{ilog}( [floor0\_number\_of\_books] ) bits Chris@1: 5) if ( [booknumber] is greater than the highest number decode codebook ) then packet is undecodable Chris@1: 6) [last] = zero; Chris@1: 7) vector [temp\_vector] = read vector from bitstream using codebook number [floor0\_book\_list] element [booknumber] in VQ context. Chris@1: 8) add the scalar value [last] to each scalar in vector [temp\_vector] Chris@1: 9) [last] = the value of the last scalar in vector [temp\_vector] Chris@1: 10) concatenate [temp\_vector] onto the end of the [coefficients] vector Chris@1: 11) if (length of vector [coefficients] is less than [floor0\_order], continue at step 6 Chris@1: Chris@1: \} Chris@1: Chris@1: 12) done. Chris@1: Chris@1: \end{Verbatim} Chris@1: Chris@1: Take note of the following properties of decode: Chris@1: \begin{itemize} Chris@1: \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: \item An end-of-packet condition during decode should be considered a Chris@1: nominal occruence; if end-of-packet is reached during any read Chris@1: operation above, floor decode is to return 'unused' status as if the Chris@1: \varname{[amplitude]} value had read zero at the beginning of decode. Chris@1: Chris@1: \item The book number used for decode Chris@1: can, in fact, be stored in the bitstream in \link{vorbis:spec:ilog}{ilog}( \varname{[floor0\_number\_of\_books]} - Chris@1: 1 ) bits. Nevertheless, the above specification is correct and values Chris@1: greater than the maximum possible book value are reserved. Chris@1: Chris@1: \item The number of scalars read into the vector \varname{[coefficients]} Chris@1: may be greater than \varname{[floor0\_order]}, the number actually Chris@1: required for curve computation. For example, if the VQ codebook used Chris@1: for the floor currently being decoded has a Chris@1: \varname{[codebook\_dimensions]} value of three and Chris@1: \varname{[floor0\_order]} is ten, the only way to fill all the needed Chris@1: scalars in \varname{[coefficients]} is to to read a total of twelve Chris@1: scalars as four vectors of three scalars each. This is not an error Chris@1: condition, and care must be taken not to allow a buffer overflow in Chris@1: decode. The extra values are not used and may be ignored or discarded. Chris@1: \end{itemize} Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: \subsubsection{curve computation} \label{vorbis:spec:floor0-synth} Chris@1: Chris@1: Given an \varname{[amplitude]} integer and \varname{[coefficients]} Chris@1: vector from packet decode as well as the [floor0\_order], Chris@1: [floor0\_rate], [floor0\_bark\_map\_size], [floor0\_amplitude\_bits] and Chris@1: [floor0\_amplitude\_offset] values from floor setup, and an output Chris@1: vector size \varname{[n]} specified by the decode process, we compute a Chris@1: floor output vector. Chris@1: Chris@1: If the value \varname{[amplitude]} is zero, the return value is a Chris@1: length \varname{[n]} vector with all-zero scalars. Otherwise, begin by Chris@1: assuming the following definitions for the given vector to be Chris@1: synthesized: Chris@1: Chris@1: \begin{displaymath} Chris@1: \mathrm{map}_i = \left\{ Chris@1: \begin{array}{ll} Chris@1: \min ( Chris@1: \mathtt{floor0\texttt{\_}bark\texttt{\_}map\texttt{\_}size} - 1, Chris@1: foobar Chris@1: ) & \textrm{for } i \in [0,n-1] \\ Chris@1: -1 & \textrm{for } i = n Chris@1: \end{array} Chris@1: \right. Chris@1: \end{displaymath} Chris@1: Chris@1: where Chris@1: Chris@1: \begin{displaymath} Chris@1: foobar = Chris@1: \left\lfloor Chris@1: \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: \right\rfloor Chris@1: \end{displaymath} Chris@1: Chris@1: and Chris@1: Chris@1: \begin{displaymath} Chris@1: \mathrm{bark}(x) = 13.1 \arctan (.00074x) + 2.24 \arctan (.0000000185x^2 + .0001x) Chris@1: \end{displaymath} Chris@1: Chris@1: The above is used to synthesize the LSP curve on a Bark-scale frequency Chris@1: axis, then map the result to a linear-scale frequency axis. Chris@1: Similarly, the below calculation synthesizes the output LSP curve \varname{[output]} on a log Chris@1: (dB) amplitude scale, mapping it to linear amplitude in the last step: Chris@1: Chris@1: \begin{enumerate} Chris@1: \item \varname{[i]} = 0 Chris@1: \item \varname{[$\omega$]} = $\pi$ * map element \varname{[i]} / \varname{[floor0\_bark\_map\_size]} Chris@1: \item if ( \varname{[floor0\_order]} is odd ) { Chris@1: \begin{enumerate} Chris@1: \item calculate \varname{[p]} and \varname{[q]} according to: Chris@1: \begin{eqnarray*} Chris@1: 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: q & = & \frac{1}{4} \prod_{j=0}^{\frac{\mathtt{floor0\texttt{\_}order}-1}{2}} 4 (\cos([\mathtt{coefficients}]_{2j}) - \cos \omega)^2 Chris@1: \end{eqnarray*} Chris@1: Chris@1: \end{enumerate} Chris@1: } else \varname{[floor0\_order]} is even { Chris@1: \begin{enumerate}[resume] Chris@1: \item calculate \varname{[p]} and \varname{[q]} according to: Chris@1: \begin{eqnarray*} Chris@1: 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: 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: \end{eqnarray*} Chris@1: Chris@1: \end{enumerate} Chris@1: } Chris@1: Chris@1: \item calculate \varname{[linear\_floor\_value]} according to: Chris@1: \begin{displaymath} Chris@1: \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: - \mathtt{floor0\texttt{\_}amplitude\texttt{\_}offset} \right) \right) Chris@1: \end{displaymath} Chris@1: Chris@1: \item \varname{[iteration\_condition]} = map element \varname{[i]} Chris@1: \item \varname{[output]} element \varname{[i]} = \varname{[linear\_floor\_value]} Chris@1: \item increment \varname{[i]} Chris@1: \item if ( map element \varname{[i]} is equal to \varname{[iteration\_condition]} ) continue at step 5 Chris@1: \item if ( \varname{[i]} is less than \varname{[n]} ) continue at step 2 Chris@1: \item done Chris@1: \end{enumerate} Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: Chris@1: