Blame doc/06-floor0.tex

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