06-floor0.tex 8.3 KB

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