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) array [floor0_book_list] = read a list of [floor0_number_of_books] unsigned integers of eight bits each;
56 An end-of-packet condition during any of these bitstream reads renders
57 this stream undecodable. In addition, any element of the array
58 <varname>[floor0_book_list]</varname> that is greater than the maximum codebook
59 number for this bitstream is an error condition that also renders the
60 stream undecodable.</para>
64 <section id="vorbis-spec-floor0-decode">
65 <title>packet decode</title>
68 Extracting a floor0 curve from an audio packet consists of first
69 decoding the curve amplitude and <varname>[floor0_order]</varname> LSP
70 coefficient values from the bitstream, and then computing the floor
71 curve, which is defined as the frequency response of the decoded LSP
75 Packet decode proceeds as follows:</para>
77 1) [amplitude] = read an unsigned integer of [floor0_amplitude_bits] bits
78 2) if ( [amplitude] is greater than zero ) {
79 3) [coefficients] is an empty, zero length vector
80 4) [booknumber] = read an unsigned integer of <link linkend="vorbis-spec-ilog">ilog</link>( [floor0_number_of_books] ) bits
81 5) if ( [booknumber] is greater than the highest number decode codebook ) then packet is undecodable
83 7) vector [temp_vector] = read vector from bitstream using codebook number [floor0_book_list] element [booknumber] in VQ context.
84 8) add the scalar value [last] to each scalar in vector [temp_vector]
85 9) [last] = the value of the last scalar in vector [temp_vector]
86 10) concatenate [temp_vector] onto the end of the [coefficients] vector
87 11) if (length of vector [coefficients] is less than [floor0_order], continue at step 6
96 Take note of the following properties of decode:
98 <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>
99 <listitem><simpara>An end-of-packet condition during decode should be considered a
100 nominal occruence; if end-of-packet is reached during any read
101 operation above, floor decode is to return 'unused' status as if the
102 <varname>[amplitude]</varname> value had read zero at the beginning of decode.</simpara></listitem>
104 <listitem><simpara>The book number used for decode
105 can, in fact, be stored in the bitstream in <link linkend="vorbis-spec-ilog">ilog</link>( <varname>[floor0_number_of_books]</varname> -
106 1 ) bits. Nevertheless, the above specification is correct and values
107 greater than the maximum possible book value are reserved.</simpara></listitem>
109 <listitem><simpara>The number of scalars read into the vector <varname>[coefficients]</varname>
110 may be greater than <varname>[floor0_order]</varname>, the number actually
111 required for curve computation. For example, if the VQ codebook used
112 for the floor currently being decoded has a
113 <varname>[codebook_dimensions]</varname> value of three and
114 <varname>[floor0_order]</varname> is ten, the only way to fill all the needed
115 scalars in <varname>[coefficients]</varname> is to to read a total of twelve
116 scalars as four vectors of three scalars each. This is not an error
117 condition, and care must be taken not to allow a buffer overflow in
118 decode. The extra values are not used and may be ignored or discarded.</simpara></listitem>
124 <section id="vorbis-spec-floor0-synth">
125 <title>curve computation</title>
128 Given an <varname>[amplitude]</varname> integer and <varname>[coefficients]</varname>
129 vector from packet decode as well as the [floor0_order],
130 [floor0_rate], [floor0_bark_map_size], [floor0_amplitude_bits] and
131 [floor0_amplitude_offset] values from floor setup, and an output
132 vector size <varname>[n]</varname> specified by the decode process, we compute a
133 floor output vector.</para>
136 If the value <varname>[amplitude]</varname> is zero, the return value is a
137 length <varname>[n]</varname> vector with all-zero scalars. Otherwise, begin by
138 assuming the following definitions for the given vector to be
143 <textobject><phrase>[lsp map equation]</phrase></textobject>
144 <textobject role="tex"><phrase>
147 \mathrm{map}_i = \left\{
150 \mathtt{floor0\_bark\_map\_size} - 1,
152 ) & \textrm{for } i \in [0,n-1] \\
153 -1 & \textrm{for } i = n
163 \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})}
170 \mathrm{bark}(x) = 13.1 \arctan (.00074x) + 2.24 \arctan (.0000000185x^2 + .0001x)
173 </phrase></textobject>
174 <imageobject><imagedata fileref="lspmap.png"/></imageobject>
179 The above is used to synthesize the LSP curve on a Bark-scale frequency
180 axis, then map the result to a linear-scale frequency axis.
181 Similarly, the below calculation synthesizes the output LSP curve <varname>[output]</varname> on a log
182 (dB) amplitude scale, mapping it to linear amplitude in the last step:</para>
185 <listitem><simpara> <varname>[i]</varname> = 0 </simpara></listitem>
186 <listitem><para>if ( <varname>[floor0_order]</varname> is odd ) {
188 <listitem><para>calculate <varname>[p]</varname> and <varname>[q]</varname> according to:
191 <textobject><phrase>[equation for odd lsp]</phrase></textobject>
192 <textobject role="tex"><phrase>
195 p & = & (1 - \cos^2\omega)\prod_{j=0}^{(\mathtt{order}-3)/2} 4 (\cos c_{2j+1} - \cos \omega)^2 \\
196 q & = & \frac{1}{4} \prod_{j=0}^{(\mathtt{order}-1)/2} 4 (\cos c_{2j+1} - \cos \omega)^2
199 </phrase></textobject>
200 <imageobject><imagedata fileref="oddlsp.png"/></imageobject>
205 } else <varname>[floor0_order]</varname> is even {
207 <listitem><para>calculate <varname>[p]</varname> and <varname>[q]</varname> according to:
210 <textobject><phrase>[equation for even lsp]</phrase></textobject>
211 <textobject role="tex"><phrase>
214 p & = & \frac{(1 - \cos^2\omega)}{2} \prod_{j=0}^{(\mathtt{order}-2)/2} 4 (\cos c_{2j} - \cos \omega)^2 \\
215 q & = & \frac{(1 + \cos^2\omega)}{2} \prod_{j=0}^{(\mathtt{order}-2)/2} 4 (\cos c_{2j} - \cos \omega)^2
218 </phrase></textobject>
219 <imageobject><imagedata fileref="evenlsp.png"/></imageobject>
226 <listitem><para>calculate <varname>[linear_floor_value]</varname> according to:
229 <textobject><phrase>[expression for floorval]</phrase></textobject>
230 <textobject role="tex"><phrase>
233 \exp \left( .11512925 \left(\frac{\mathtt{amplitude} \cdot \mathtt{floor0\_amplitute\_offset}}{(2^{\mathtt{floor0\_amplitude\_bits}}-1)\sqrt{p+q}}
234 - \mathtt{floor0\_amplitude\_offset} \right) \right)
237 </phrase></textobject>
238 <imageobject><imagedata fileref="floorval.png"/></imageobject>
242 <listitem><simpara><varname>[iteration_condition]</varname> = map element <varname>[i]</varname></simpara></listitem>
243 <listitem><simpara><varname>[output]</varname> element <varname>[i]</varname> = <varname>[linear_floor_value]</varname></simpara></listitem>
244 <listitem><simpara>increment <varname>[i]</varname></simpara></listitem>
245 <listitem><simpara>if ( map element <varname>[i]</varname> is equal to <varname>[iteration_condition]</varname> ) continue at step 5</simpara></listitem>
246 <listitem><simpara>if ( <varname>[i]</varname> is less than <varname>[n]</varname> ) continue at step 2</simpara></listitem>
247 <listitem><simpara>done</simpara></listitem>