1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
7 <section id="vorbis-spec-floor0">
13 <title>Floor type 0 setup and decode</title>
17 <title>Overview</title>
20 Vorbis floor type zero uses Line Spectral Pair (LSP, also alternately
21 known as Line Spectral Frequency or LSF) representation to encode a
22 smooth spectral envelope curve as the frequency response of the LSP
23 filter. This representation is equivalent to a traditional all-pole
24 infinite impulse response filter as would be used in linear predictive
25 coding; LSP representation may be converted to LPC representation and
31 <title>Floor 0 format</title>
34 Floor zero configuration consists of six integer fields and a list of
35 VQ codebooks for use in coding/decoding the LSP filter coefficient
36 values used by each frame. </para>
38 <section><title>header decode</title>
41 Configuration information for instances of floor zero decodes from the
42 codec setup header (third packet). configuration decode proceeds as
46 1) [floor0_order] = read an unsigned integer of 8 bits
47 2) [floor0_rate] = read an unsigned integer of 16 bits
48 3) [floor0_bark_map_size] = read an unsigned integer of 16 bits
49 4) [floor0_amplitude_bits] = read an unsigned integer of six bits
50 5) [floor0_amplitude_offset] = read an unsigned integer of eight bits
51 6) [floor0_number_of_books] = read an unsigned integer of four bits and add 1
52 7) if any of [floor0_order], [floor0_rate], [floor0_bark_map_size], [floor0_amplitude_bits],
53 [floor0_amplitude_offset] or [floor0_number_of_books] are less than zero, the stream is not decodable
54 8) array [floor0_book_list] = read a list of [floor0_number_of_books] unsigned integers of eight bits each;
58 An end-of-packet condition during any of these bitstream reads renders
59 this stream undecodable. In addition, any element of the array
60 <varname>[floor0_book_list]</varname> that is greater than the maximum codebook
61 number for this bitstream is an error condition that also renders the
62 stream undecodable.</para>
66 <section id="vorbis-spec-floor0-decode">
67 <title>packet decode</title>
70 Extracting a floor0 curve from an audio packet consists of first
71 decoding the curve amplitude and <varname>[floor0_order]</varname> LSP
72 coefficient values from the bitstream, and then computing the floor
73 curve, which is defined as the frequency response of the decoded LSP
77 Packet decode proceeds as follows:</para>
79 1) [amplitude] = read an unsigned integer of [floor0_amplitude_bits] bits
80 2) if ( [amplitude] is greater than zero ) {
81 3) [coefficients] is an empty, zero length vector
83 4) [booknumber] = read an unsigned integer of <link linkend="vorbis-spec-ilog">ilog</link>( [floor0_number_of_books] ) bits
84 5) if ( [booknumber] is greater than the highest number decode codebook ) then packet is undecodable
86 7) vector [temp_vector] = read vector from bitstream using codebook number [booknumber] in VQ context.
87 8) add the scalar value [last] to each scalar in vector [temp_vector]
88 9) [last] = the value of the last scalar in vector [temp_vector]
89 10) concatenate [temp_vector] onto the end of the [coefficients] vector
90 11) if (length of vector [coefficients] is less than [floor0_order], continue at step 6
99 Take note of the following properties of decode:
101 <listitem><simpara>An <varname>[amplitude]</varname> 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.</simpara></listitem>
102 <listitem><simpara>An end-of-packet condition during decode should be considered a
103 nominal occruence; if end-of-packet is reached during any read
104 operation above, floor decode is to return 'unused' status as if the
105 <varname>[amplitude]</varname> value had read zero at the beginning of decode.</simpara></listitem>
107 <listitem><simpara>The book number used for decode
108 can, in fact, be stored in the bitstream in <link linkend="vorbis-spec-ilog">ilog</link>( <varname>[floor0_number_of_books]</varname> -
109 1 ) bits. Nevertheless, the above specification is correct and values
110 greater than the maximum possible book value are reserved.</simpara></listitem>
112 <listitem><simpara>The number of scalars read into the vector <varname>[coefficients]</varname>
113 may be greater than <varname>[floor0_order]</varname>, the number actually
114 required for curve computation. For example, if the VQ codebook used
115 for the floor currently being decoded has a
116 <varname>[codebook_dimensions]</varname> value of three and
117 <varname>[floor0_order]</varname> is ten, the only way to fill all the needed
118 scalars in <varname>[coefficients]</varname> is to to read a total of twelve
119 scalars as four vectors of three scalars each. This is not an error
120 condition, and care must be taken not to allow a buffer overflow in
121 decode. The extra values are not used and may be ignored or discarded.</simpara></listitem>
127 <section id="vorbis-spec-floor0-synth">
128 <title>curve computation</title>
131 Given an <varname>[amplitude]</varname> integer and <varname>[coefficients]</varname>
132 vector from packet decode as well as the [floor0_order],
133 [floor0_rate], [floor0_bark_map_size], [floor0_amplitude_bits] and
134 [floor0_amplitude_offset] values from floor setup, and an output
135 vector size <varname>[n]</varname> specified by the decode process, we compute a
136 floor output vector.</para>
139 If the value <varname>[amplitude]</varname> is zero, the return value is a
140 length <varname>[n]</varname> vector with all-zero scalars. Otherwise, begin by
141 assuming the following definitions for the given vector to be
146 <textobject><phrase>[lsp map equation]</phrase></textobject>
147 <textobject role="tex"><phrase>
150 \mathrm{map}_i = \left\{
153 \mathtt{floor0\_bark\_map\_size} - 1,
155 ) & \textrm{for } i \in [0,n-1] \\
156 -1 & \textrm{for } i = n
166 \mathrm{bark}\left(\frac{\mathtt{floor0\_rate} \cdot i}{2n}\right) \cdot \frac{\mathtt{floor0\_bark\_map\_size}} {\mathrm{bark}(.5 \cdot \mathtt{floor0\_rate})}
173 \mathrm{bark}(x) = 13.1 \arctan (.00074x) + 2.24 \arctan (.0000000158x^2)+.0001x
176 </phrase></textobject>
177 <imageobject><imagedata fileref="lspmap.png"/></imageobject>
182 The above is used to synthesize the LSP curve on a Bark-scale frequency
183 axis, then map the result to a linear-scale frequency axis.
184 Similarly, the below calculation synthesizes the output LSP curve <varname>[output]</varname> on a log
185 (dB) amplitude scale, mapping it to linear amplitude in the last step:</para>
188 <listitem><simpara> <varname>[i]</varname> = 0 </simpara></listitem>
189 <listitem><para>if ( <varname>[floor0_order]</varname> is odd ) {
191 <listitem><para>calculate <varname>[p]</varname> and <varname>[q]</varname> according to:
194 <textobject><phrase>[equation for odd lsp]</phrase></textobject>
195 <textobject role="tex"><phrase>
198 p & = & (1 - \cos^2\omega)\prod_{j=0}^{(\mathtt{order}-3)/2} 4 (\cos c_{2j+1} - \cos \omega)^2 \\
199 q & = & \frac{1}{4} \prod_{j=0}^{(\mathtt{order}-1)/2} 4 (\cos c_{2j+1} - \cos \omega)^2
202 </phrase></textobject>
203 <imageobject><imagedata fileref="oddlsp.png"/></imageobject>
208 } else <varname>[floor0_order]</varname> is even {
210 <listitem><para>calculate <varname>[p]</varname> and <varname>[q]</varname> according to:
213 <textobject><phrase>[equation for even lsp]</phrase></textobject>
214 <textobject role="tex"><phrase>
217 p & = & \frac{(1 - \cos^2\omega)}{2} \prod_{j=0}^{(\mathtt{order}-2)/2} 4 (\cos c_{2j} - \cos \omega)^2 \\
218 q & = & \frac{(1 + \cos^2\omega)}{2} \prod_{j=0}^{(\mathtt{order}-2)/2} 4 (\cos c_{2j} - \cos \omega)^2
221 </phrase></textobject>
222 <imageobject><imagedata fileref="evenlsp.png"/></imageobject>
229 <listitem><para>calculate <varname>[linear_floor_value]</varname> according to:
232 <textobject><phrase>[expression for floorval]</phrase></textobject>
233 <textobject role="tex"><phrase>
236 \exp \left( .11512925 \left(\frac{\mathtt{amplitude} \cdot \mathtt{floor0\_amplitute\_offset}}{(2^{\mathtt{floor0\_amplitude\_bits}}-1)\sqrt{p+q}}
237 - \mathtt{floor0\_amplitude\_offset} \right) \right)
240 </phrase></textobject>
241 <imageobject><imagedata fileref="floorval.png"/></imageobject>
245 <listitem><simpara><varname>[iteration_condition]</varname> = map element <varname>[i]</varname></simpara></listitem>
246 <listitem><simpara><varname>[output]</varname> element <varname>[i]</varname> = <varname>[linear_floor_value]</varname></simpara></listitem>
247 <listitem><simpara>increment <varname>[i]</varname></simpara></listitem>
248 <listitem><simpara>if ( map element <varname>[i]</varname> is equal to <varname>[iteration_condition]</varname> ) continue at step 5</simpara></listitem>
249 <listitem><simpara>if ( <varname>[i]</varname> is less than <varname>[n]</varname> ) continue at step 2</simpara></listitem>
250 <listitem><simpara>done</simpara></listitem>