00001 <?xml version="1.0" standalone="no"?>
00002 <!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
00003 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
00004 <!ENTITY pi "π"> <!-- GREEK SMALL LETTER PI -->
00005 ]>
00006
00007 <section id="vorbis-spec-codec">
00008 <sectioninfo>
00009 <releaseinfo>
00010 $Id: 04-codec.xml 10466 2005-11-28 00:34:44Z giles $
00011 </releaseinfo>
00012 </sectioninfo>
00013 <title>Codec Setup and Packet Decode</title>
00014
00015 <section>
00016 <title>Overview</title>
00017
00018 <para>
00019 This document serves as the top-level reference document for the
00020 bit-by-bit decode specification of Vorbis I. This document assumes a
00021 high-level understanding of the Vorbis decode process, which is
00022 provided in <xref linkend="vorbis-spec-intro"/>. <xref
00023 linkend="vorbis-spec-bitpacking"/> covers reading and writing bit fields from
00024 and to bitstream packets.</para>
00025
00026 </section>
00027
00028 <section>
00029 <title>Header decode and decode setup</title>
00030
00031 <para>
00032 A Vorbis bitstream begins with three header packets. The header
00033 packets are, in order, the identification header, the comments header,
00034 and the setup header. All are required for decode compliance. An
00035 end-of-packet condition during decoding the first or third header
00036 packet renders the stream undecodable. End-of-packet decoding the
00037 comment header is a non-fatal error condition.</para>
00038
00039 <section><title>Common header decode</title>
00040
00041 <para>
00042 Each header packet begins with the same header fields.
00043 </para>
00044
00045 <screen>
00046 1) [packet_type] : 8 bit value
00047 2) 0x76, 0x6f, 0x72, 0x62, 0x69, 0x73: the characters 'v','o','r','b','i','s' as six octets
00048 </screen>
00049
00050 <para>
00051 Decode continues according to packet type; the identification header
00052 is type 1, the comment header type 3 and the setup header type 5
00053 (these types are all odd as a packet with a leading single bit of '0'
00054 is an audio packet). The packets must occur in the order of
00055 identification, comment, setup.</para>
00056
00057 </section>
00058
00059 <section><title>Identification header</title>
00060
00061 <para>
00062 The identification header is a short header of only a few fields used
00063 to declare the stream definitively as Vorbis, and provide a few externally
00064 relevant pieces of information about the audio stream. The
00065 identification header is coded as follows:</para>
00066
00067 <screen>
00068 1) [vorbis_version] = read 32 bits as unsigned integer
00069 2) [audio_channels] = read 8 bit integer as unsigned
00070 3) [audio_sample_rate] = read 32 bits as unsigned integer
00071 4) [bitrate_maximum] = read 32 bits as signed integer
00072 5) [bitrate_nominal] = read 32 bits as signed integer
00073 6) [bitrate_minimum] = read 32 bits as signed integer
00074 7) [blocksize_0] = 2 exponent (read 4 bits as unsigned integer)
00075 8) [blocksize_1] = 2 exponent (read 4 bits as unsigned integer)
00076 9) [framing_flag] = read one bit
00077 </screen>
00078
00079 <para>
00080 <varname>[vorbis_version]</varname> is to read '0' in order to be compatible
00081 with this document. Both <varname>[audio_channels]</varname> and
00082 <varname>[audio_sample_rate]</varname> must read greater than zero. Allowed final
00083 blocksize values are 64, 128, 256, 512, 1024, 2048, 4096 and 8192 in
00084 Vorbis I. <varname>[blocksize_0]</varname> must be less than or equal to
00085 <varname>[blocksize_1]</varname>. The framing bit must be nonzero. Failure to
00086 meet any of these conditions renders a stream undecodable.</para>
00087
00088 <para>
00089 The bitrate fields above are used only as hints. The nominal bitrate
00090 field especially may be considerably off in purely VBR streams. The
00091 fields are meaningful only when greater than zero.</para>
00092
00093 <para>
00094 <itemizedlist>
00095 <listitem><simpara>All three fields set to the same value implies a fixed rate, or tightly bounded, nearly fixed-rate bitstream</simpara></listitem>
00096 <listitem><simpara>Only nominal set implies a VBR or ABR stream that averages the nominal bitrate</simpara></listitem>
00097 <listitem><simpara>Maximum and or minimum set implies a VBR bitstream that obeys the bitrate limits</simpara></listitem>
00098 <listitem><simpara>None set indicates the encoder does not care to speculate.</simpara></listitem>
00099 </itemizedlist>
00100 </para>
00101
00102 </section>
00103
00104 <section><title>Comment header</title>
00105 <para>
00106 Comment header decode and data specification is covered in
00107 <xref linkend="vorbis-spec-comment"/>.</para>
00108 </section>
00109
00110 <section><title>Setup header</title>
00111
00112 <para>
00113 Vorbis codec setup is configurable to an extreme degree:
00114
00115 <mediaobject>
00116 <imageobject>
00117 <imagedata fileref="components.png" format="PNG"/>
00118 </imageobject>
00119 <textobject>
00120 <phrase>[decoder pipeline configuration]</phrase>
00121 </textobject>
00122 </mediaobject>
00123 </para>
00124
00125 <para>
00126 The setup header contains the bulk of the codec setup information
00127 needed for decode. The setup header contains, in order, the lists of
00128 codebook configurations, time-domain transform configurations
00129 (placeholders in Vorbis I), floor configurations, residue
00130 configurations, channel mapping configurations and mode
00131 configurations. It finishes with a framing bit of '1'. Header decode
00132 proceeds in the following order:</para>
00133
00134 <section><title>Codebooks</title>
00135
00136 <orderedlist>
00137 <listitem><simpara><varname>[vorbis_codebook_count]</varname> = read eight bits as unsigned integer and add one</simpara></listitem>
00138 <listitem><simpara>Decode <varname>[vorbis_codebook_count]</varname> codebooks in order as defined
00139 in <xref linkend="vorbis-spec-codebook"/>. Save each configuration, in
00140 order, in an array of
00141 codebook configurations <varname>[vorbis_codebook_configurations]</varname>.</simpara></listitem>
00142 </orderedlist>
00143
00144 </section>
00145
00146 <section><title>Time domain transforms</title>
00147
00148 <para>
00149 These hooks are placeholders in Vorbis I. Nevertheless, the
00150 configuration placeholder values must be read to maintain bitstream
00151 sync.</para>
00152
00153 <orderedlist>
00154 <listitem><simpara><varname>[vorbis_time_count]</varname> = read 6 bits as unsigned integer and add one</simpara></listitem>
00155 <listitem><simpara>read <varname>[vorbis_time_count]</varname> 16 bit values; each value should be zero. If any value is nonzero, this is an error condition and the stream is undecodable.</simpara></listitem>
00156 </orderedlist>
00157
00158 </section>
00159
00160 <section><title>Floors</title>
00161
00162 <para>
00163 Vorbis uses two floor types; header decode is handed to the decode
00164 abstraction of the appropriate type.</para>
00165
00166 <orderedlist>
00167 <listitem><simpara><varname>[vorbis_floor_count]</varname> = read 6 bits as unsigned integer and add one</simpara></listitem>
00168 <listitem><para>For each <varname>[i]</varname> of <varname>[vorbis_floor_count]</varname> floor numbers:
00169 <orderedlist>
00170 <listitem><simpara>read the floor type: vector <varname>[vorbis_floor_types]</varname> element <varname>[i]</varname> =
00171 read 16 bits as unsigned integer</simpara></listitem>
00172 <listitem><simpara>If the floor type is zero, decode the floor
00173 configuration as defined in <xref linkend="vorbis-spec-floor0"/>; save
00174 this
00175 configuration in slot <varname>[i]</varname> of the floor configuration array <varname>[vorbis_floor_configurations]</varname>.</simpara></listitem>
00176 <listitem><simpara>If the floor type is one,
00177 decode the floor configuration as defined in <xref
00178 linkend="vorbis-spec-floor1"/>; save this configuration in slot <varname>[i]</varname> of the floor configuration array <varname>[vorbis_floor_configurations]</varname>.</simpara></listitem>
00179 <listitem><simpara>If the the floor type is greater than one, this stream is undecodable; ERROR CONDITION</simpara></listitem>
00180 </orderedlist>
00181 </para></listitem>
00182 </orderedlist>
00183
00184 </section>
00185
00186 <section><title>Residues</title>
00187
00188 <para>
00189 Vorbis uses three residue types; header decode of each type is identical.
00190 </para>
00191
00192 <orderedlist>
00193 <listitem><simpara><varname>[vorbis_residue_count]</varname> = read 6 bits as unsigned integer and add one
00194 </simpara></listitem>
00195 <listitem><para>For each of <varname>[vorbis_residue_count]</varname> residue numbers:
00196 <orderedlist>
00197 <listitem><simpara>read the residue type; vector <varname>[vorbis_residue_types]</varname> element <varname>[i]</varname> = read 16 bits as unsigned integer</simpara></listitem>
00198 <listitem><simpara>If the residue type is zero,
00199 one or two, decode the residue configuration as defined in <xref
00200 linkend="vorbis-spec-residue"/>; save this configuration in slot <varname>[i]</varname> of the residue configuration array <varname>[vorbis_residue_configurations]</varname>.</simpara></listitem>
00201 <listitem><simpara>If the the residue type is greater than two, this stream is undecodable; ERROR CONDITION</simpara></listitem>
00202 </orderedlist>
00203 </para></listitem>
00204 </orderedlist>
00205
00206 </section>
00207
00208 <section><title>Mappings</title>
00209
00210 <para>
00211 Mappings are used to set up specific pipelines for encoding
00212 multichannel audio with varying channel mapping applications. Vorbis I
00213 uses a single mapping type (0), with implicit PCM channel mappings.</para>
00214
00215 <orderedlist>
00216 <listitem><simpara><varname>[vorbis_mapping_count]</varname> = read 6 bits as unsigned integer and add one</simpara></listitem>
00217 <listitem><para>For each <varname>[i]</varname> of <varname>[vorbis_mapping_count]</varname> mapping numbers:
00218 <orderedlist>
00219 <listitem><simpara>read the mapping type: 16 bits as unsigned integer. There's no reason to save the mapping type in Vorbis I.</simpara></listitem>
00220 <listitem><simpara>If the mapping type is nonzero, the stream is undecodable</simpara></listitem>
00221 <listitem><para>If the mapping type is zero:
00222 <orderedlist>
00223 <listitem><para>read 1 bit as a boolean flag
00224 <orderedlist>
00225 <listitem><simpara>if set, <varname>[vorbis_mapping_submaps]</varname> = read 4 bits as unsigned integer and add one</simpara></listitem>
00226 <listitem><simpara>if unset, <varname>[vorbis_mapping_submaps]</varname> = 1</simpara></listitem>
00227 </orderedlist>
00228 </para>
00229 </listitem>
00230 <listitem><para>read 1 bit as a boolean flag
00231 <orderedlist>
00232 <listitem><para>if set, square polar channel mapping is in use:
00233 <orderedlist>
00234 <listitem><simpara><varname>[vorbis_mapping_coupling_steps]</varname> = read 8 bits as unsigned integer and add one</simpara></listitem>
00235 <listitem><para>for <varname>[j]</varname> each of <varname>[vorbis_mapping_coupling_steps]</varname> steps:
00236 <orderedlist>
00237 <listitem><simpara>vector <varname>[vorbis_mapping_magnitude]</varname> element <varname>[j]</varname>= read <link linkend="vorbis-spec-ilog">ilog</link>(<varname>[audio_channels]</varname> - 1) bits as unsigned integer</simpara></listitem>
00238 <listitem><simpara>vector <varname>[vorbis_mapping_angle]</varname> element <varname>[j]</varname>= read <link linkend="vorbis-spec-ilog">ilog</link>(<varname>[audio_channels]</varname> - 1) bits as unsigned integer</simpara></listitem>
00239 <listitem><simpara>the numbers read in the above two steps are channel numbers representing the channel to treat as magnitude and the channel to treat as angle, respectively. If for any coupling step the angle channel number equals the magnitude channel number, the magnitude channel number is greater than <varname>[audio_channels]</varname>-1, or the angle channel is greater than <varname>[audio_channels]</varname>-1, the stream is undecodable.</simpara></listitem>
00240 </orderedlist>
00241 </para>
00242 </listitem>
00243 </orderedlist>
00244 </para>
00245 </listitem>
00246 <listitem><simpara>if unset, <varname>[vorbis_mapping_coupling_steps]</varname> = 0</simpara></listitem>
00247 </orderedlist>
00248 </para>
00249 </listitem>
00250 <listitem><simpara>read 2 bits (reserved field); if the value is nonzero, the stream is undecodable</simpara></listitem>
00251 <listitem><simpara>if <varname>[vorbis_mapping_submaps]</varname> is greater than one, we read channel multiplex settings. For each <varname>[j]</varname> of <varname>[audio_channels]</varname> channels:</simpara>
00252 <orderedlist>
00253 <listitem><simpara>vector <varname>[vorbis_mapping_mux]</varname> element <varname>[j]</varname> = read 4 bits as unsigned integer</simpara></listitem>
00254 <listitem><simpara>if the value is greater than the highest numbered submap (<varname>[vorbis_mapping_submaps]</varname> - 1), this in an error condition rendering the stream undecodable</simpara></listitem>
00255 </orderedlist>
00256 </listitem>
00257 <listitem><simpara>for each submap <varname>[j]</varname> of <varname>[vorbis_mapping_submaps]</varname> submaps, read the floor and residue numbers for use in decoding that submap:</simpara>
00258 <orderedlist>
00259 <listitem><simpara>read and discard 8 bits (the unused time configuration placeholder)</simpara></listitem>
00260 <listitem><simpara>read 8 bits as unsigned integer for the floor number; save in vector <varname>[vorbis_mapping_submap_floor]</varname> element <varname>[j]</varname></simpara></listitem>
00261 <listitem><simpara>verify the floor number is not greater than the highest number floor configured for the bitstream. If it is, the bitstream is undecodable</simpara></listitem>
00262 <listitem><simpara>read 8 bits as unsigned integer for the residue number; save in vector <varname>[vorbis_mapping_submap_residue]</varname> element <varname>[j]</varname></simpara></listitem>
00263 <listitem><simpara>verify the residue number is not greater than the highest number residue configured for the bitstream. If it is, the bitstream is undecodable</simpara></listitem>
00264 </orderedlist>
00265 </listitem>
00266 <listitem><simpara>save this mapping configuration in slot <varname>[i]</varname> of the mapping configuration array <varname>[vorbis_mapping_configurations]</varname>.</simpara></listitem>
00267 </orderedlist></para>
00268 </listitem>
00269 </orderedlist>
00270 </para></listitem>
00271 </orderedlist>
00272
00273 </section>
00274
00275 <section><title>Modes</title>
00276
00277 <orderedlist>
00278 <listitem><simpara><varname>[vorbis_mode_count]</varname> = read 6 bits as unsigned integer and add one</simpara></listitem>
00279 <listitem><simpara>For each of <varname>[vorbis_mode_count]</varname> mode numbers:</simpara>
00280 <orderedlist>
00281 <listitem><simpara><varname>[vorbis_mode_blockflag]</varname> = read 1 bit</simpara></listitem>
00282 <listitem><simpara><varname>[vorbis_mode_windowtype]</varname> = read 16 bits as unsigned integer</simpara></listitem>
00283 <listitem><simpara><varname>[vorbis_mode_transformtype]</varname> = read 16 bits as unsigned integer</simpara></listitem>
00284 <listitem><simpara><varname>[vorbis_mode_mapping]</varname> = read 8 bits as unsigned integer</simpara></listitem>
00285 <listitem><simpara>verify ranges; zero is the only legal value in Vorbis I for
00286 <varname>[vorbis_mode_windowtype]</varname>
00287 and <varname>[vorbis_mode_transformtype]</varname>. <varname>[vorbis_mode_mapping]</varname> must not be greater than the highest number mapping in use. Any illegal values render the stream undecodable.</simpara></listitem>
00288 <listitem><simpara>save this mode configuration in slot <varname>[i]</varname> of the mode configuration array
00289 <varname>[vorbis_mode_configurations]</varname>.</simpara></listitem>
00290 </orderedlist>
00291 </listitem>
00292 <listitem><simpara>read 1 bit as a framing flag. If unset, a framing error occurred and the stream is not
00293 decodable.</simpara></listitem>
00294 </orderedlist>
00295
00296 <para>
00297 After reading mode descriptions, setup header decode is complete.
00298 </para>
00299
00300 </section>
00301
00302 </section>
00303
00304 </section>
00305
00306 <section>
00307 <title>Audio packet decode and synthesis</title>
00308
00309 <para>
00310 Following the three header packets, all packets in a Vorbis I stream
00311 are audio. The first step of audio packet decode is to read and
00312 verify the packet type. <emphasis>A non-audio packet when audio is expected
00313 indicates stream corruption or a non-compliant stream. The decoder
00314 must ignore the packet and not attempt decoding it to audio</emphasis>.
00315 </para>
00316
00317 <section><title>packet type, mode and window decode</title>
00318
00319 <orderedlist>
00320 <listitem><simpara>read 1 bit <varname>[packet_type]</varname>; check that packet type is 0 (audio)</simpara></listitem>
00321 <listitem><simpara>read <link linkend="vorbis-spec-ilog">ilog</link>([vorbis_mode_count]-1) bits
00322 <varname>[mode_number]</varname></simpara></listitem>
00323 <listitem><simpara>decode blocksize <varname>[n]</varname> is equal to <varname>[blocksize_0]</varname> if
00324 <varname>[vorbis_mode_blockflag]</varname> is 0, else <varname>[n]</varname> is equal to <varname>[blocksize_1]</varname>.</simpara></listitem>
00325 <listitem><simpara>perform window selection and setup; this window is used later by the inverse MDCT:</simpara>
00326 <orderedlist>
00327 <listitem><simpara>if this is a long window (the <varname>[vorbis_mode_blockflag]</varname> flag of this mode is
00328 set):</simpara>
00329 <orderedlist>
00330 <listitem><simpara>read 1 bit for <varname>[previous_window_flag]</varname></simpara></listitem>
00331 <listitem><simpara>read 1 bit for <varname>[next_window_flag]</varname></simpara></listitem>
00332 <listitem><simpara>if <varname>[previous_window_flag]</varname> is not set, the left half
00333 of the window will be a hybrid window for lapping with a
00334 short block. See <xref
00335 linkend="vorbis-spec-window"/> for an illustration of overlapping
00336 dissimilar
00337 windows. Else, the left half window will have normal long
00338 shape.</simpara></listitem>
00339 <listitem><simpara>if <varname>[next_window_flag]</varname> is not set, the right half of
00340 the window will be a hybrid window for lapping with a short
00341 block. See <xref linkend="vorbis-spec-window"/> for an
00342 illustration of overlapping dissimilar
00343 windows. Else, the left right window will have normal long
00344 shape.</simpara></listitem>
00345 </orderedlist>
00346 </listitem>
00347 <listitem><simpara> if this is a short window, the window is always the same
00348 short-window shape.</simpara></listitem>
00349 </orderedlist>
00350 </listitem>
00351 </orderedlist>
00352
00353 <para>
00354 Vorbis windows all use the slope function y=sin(0.5 * π * sin^2((x+.5)/n * π)),
00355 where n is window size and x ranges 0...n-1, but dissimilar
00356 lapping requirements can affect overall shape. Window generation
00357 proceeds as follows:</para>
00358
00359 <orderedlist>
00360 <listitem><simpara> <varname>[window_center]</varname> = <varname>[n]</varname> / 2</simpara></listitem>
00361 <listitem><para> if (<varname>[vorbis_mode_blockflag]</varname> is set and <varname>[previous_window_flag]</varname> is
00362 not set) then
00363 <orderedlist>
00364 <listitem><simpara><varname>[left_window_start]</varname> = <varname>[n]</varname>/4 -
00365 <varname>[blocksize_0]</varname>/4</simpara></listitem>
00366 <listitem><simpara><varname>[left_window_end]</varname> = <varname>[n]</varname>/4 + <varname>[blocksize_0]</varname>/4</simpara></listitem>
00367 <listitem><simpara><varname>[left_n]</varname> = <varname>[blocksize_0]</varname>/2</simpara></listitem>
00368 </orderedlist>
00369 else
00370 <orderedlist>
00371 <listitem><simpara><varname>[left_window_start]</varname> = 0</simpara></listitem>
00372 <listitem><simpara><varname>[left_window_end]</varname> = <varname>[window_center]</varname></simpara></listitem>
00373 <listitem><simpara><varname>[left_n]</varname> = <varname>[n]</varname>/2</simpara></listitem>
00374 </orderedlist></para>
00375 </listitem>
00376 <listitem><para> if (<varname>[vorbis_mode_blockflag]</varname> is set and <varname>[next_window_flag]</varname> is not
00377 set) then
00378 <orderedlist>
00379 <listitem><simpara><varname>[right_window_start]</varname> = <varname>[n]*3</varname>/4 -
00380 <varname>[blocksize_0]</varname>/4</simpara></listitem>
00381 <listitem><simpara><varname>[right_window_end]</varname> = <varname>[n]*3</varname>/4 +
00382 <varname>[blocksize_0]</varname>/4</simpara></listitem>
00383 <listitem><simpara><varname>[right_n]</varname> = <varname>[blocksize_0]</varname>/2</simpara></listitem>
00384 </orderedlist>
00385 else
00386 <orderedlist>
00387 <listitem><simpara><varname>[right_window_start]</varname> = <varname>[window_center]</varname></simpara></listitem>
00388 <listitem><simpara><varname>[right_window_end]</varname> = <varname>[n]</varname></simpara></listitem>
00389 <listitem><simpara><varname>[right_n]</varname> = <varname>[n]</varname>/2</simpara></listitem>
00390 </orderedlist></para>
00391 </listitem>
00392 <listitem><simpara> window from range 0 ... <varname>[left_window_start]</varname>-1 inclusive is zero</simpara></listitem>
00393 <listitem><simpara> for <varname>[i]</varname> in range <varname>[left_window_start]</varname> ...
00394 <varname>[left_window_end]</varname>-1, window(<varname>[i]</varname>) = sin(.5 * π * sin^2( (<varname>[i]</varname>-<varname>[left_window_start]</varname>+.5) / <varname>[left_n]</varname> * .5 * π) )</simpara></listitem>
00395 <listitem><simpara> window from range <varname>[left_window_end]</varname> ... <varname>[right_window_start]</varname>-1
00396 inclusive is one</simpara></listitem><listitem><simpara> for <varname>[i]</varname> in range <varname>[right_window_start]</varname> ... <varname>[right_window_end]</varname>-1, window(<varname>[i]</varname>) = sin(.5 * π * sin^2( (<varname>[i]</varname>-<varname>[right_window_start]</varname>+.5) / <varname>[right_n]</varname> * .5 * π + .5 * π) )</simpara></listitem>
00397 <listitem><simpara> window from range <varname>[right_window_start]</varname> ... <varname>[n]</varname>-1 is
00398 zero</simpara></listitem>
00399 </orderedlist>
00400
00401 <para>
00402 An end-of-packet condition up to this point should be considered an
00403 error that discards this packet from the stream. An end of packet
00404 condition past this point is to be considered a possible nominal
00405 occurrence.</para>
00406
00407 </section>
00408
00409 <section><title>floor curve decode</title>
00410
00411 <para>
00412 From this point on, we assume out decode context is using mode number
00413 <varname>[mode_number]</varname> from configuration array
00414 <varname>[vorbis_mode_configurations]</varname> and the map number
00415 <varname>[vorbis_mode_mapping]</varname> (specified by the current mode) taken
00416 from the mapping configuration array
00417 <varname>[vorbis_mapping_configurations]</varname>.</para>
00418
00419 <para>
00420 Floor curves are decoded one-by-one in channel order.</para>
00421
00422 <para>
00423 For each floor <varname>[i]</varname> of <varname>[audio_channels]</varname>
00424 <orderedlist>
00425 <listitem><simpara><varname>[submap_number]</varname> = element <varname>[i]</varname> of vector [vorbis_mapping_mux]</simpara></listitem>
00426 <listitem><simpara><varname>[floor_number]</varname> = element <varname>[submap_number]</varname> of vector
00427 [vorbis_submap_floor]</simpara></listitem>
00428 <listitem><simpara>if the floor type of this
00429 floor (vector <varname>[vorbis_floor_types]</varname> element
00430 <varname>[floor_number]</varname>) is zero then decode the floor for
00431 channel <varname>[i]</varname> according to the
00432 <xref linkend="vorbis-spec-floor0-decode"/></simpara></listitem>
00433 <listitem><simpara>if the type of this floor
00434 is one then decode the floor for channel <varname>[i]</varname> according
00435 to the <xref linkend="vorbis-spec-floor1-decode"/></simpara></listitem>
00436 <listitem><simpara>save the needed decoded floor information for channel for later synthesis</simpara></listitem>
00437 <listitem><simpara>if the decoded floor returned 'unused', set vector <varname>[no_residue]</varname> element
00438 <varname>[i]</varname> to true, else set vector <varname>[no_residue]</varname> element <varname>[i]</varname> to
00439 false</simpara></listitem>
00440 </orderedlist>
00441 </para>
00442
00443 <para>
00444 An end-of-packet condition during floor decode shall result in packet
00445 decode zeroing all channel output vectors and skipping to the
00446 add/overlap output stage.</para>
00447
00448 </section>
00449
00450 <section><title>nonzero vector propagate</title>
00451
00452 <para>
00453 A possible result of floor decode is that a specific vector is marked
00454 'unused' which indicates that that final output vector is all-zero
00455 values (and the floor is zero). The residue for that vector is not
00456 coded in the stream, save for one complication. If some vectors are
00457 used and some are not, channel coupling could result in mixing a
00458 zeroed and nonzeroed vector to produce two nonzeroed vectors.</para>
00459
00460 <para>
00461 for each <varname>[i]</varname> from 0 ... <varname>[vorbis_mapping_coupling_steps]</varname>-1
00462
00463 <orderedlist>
00464 <listitem><simpara>if either <varname>[no_residue]</varname> entry for channel
00465 (<varname>[vorbis_mapping_magnitude]</varname> element <varname>[i]</varname>)
00466 or channel
00467 (<varname>[vorbis_mapping_angle]</varname> element <varname>[i]</varname>)
00468 are set to false, then both must be set to false. Note that an 'unused'
00469 floor has no decoded floor information; it is important that this is
00470 remembered at floor curve synthesis time.</simpara></listitem>
00471 </orderedlist>
00472 </para>
00473
00474 </section>
00475
00476 <section><title>residue decode</title>
00477
00478 <para>
00479 Unlike floors, which are decoded in channel order, the residue vectors
00480 are decoded in submap order.</para>
00481
00482 <para>
00483 for each submap <varname>[i]</varname> in order from 0 ... <varname>[vorbis_mapping_submaps]</varname>-1</para>
00484
00485 <orderedlist>
00486 <listitem><simpara><varname>[ch]</varname> = 0</simpara></listitem>
00487 <listitem><simpara>for each channel <varname>[j]</varname> in order from 0 ... <varname>[audio_channels]</varname> - 1</simpara>
00488 <orderedlist>
00489 <listitem><simpara>if channel <varname>[j]</varname> in submap <varname>[i]</varname> (vector <varname>[vorbis_mapping_mux]</varname> element <varname>[j]</varname> is equal to <varname>[i]</varname>)</simpara>
00490 <orderedlist>
00491 <listitem><para>if vector <varname>[no_residue]</varname> element <varname>[j]</varname> is true
00492 <orderedlist>
00493 <listitem><simpara>vector <varname>[do_not_decode_flag]</varname> element <varname>[ch]</varname> is set</simpara></listitem>
00494 </orderedlist>
00495 else
00496 <orderedlist>
00497 <listitem><simpara>vector <varname>[do_not_decode_flag]</varname> element <varname>[ch]</varname> is unset</simpara></listitem>
00498 </orderedlist></para>
00499 </listitem>
00500 <listitem><simpara>increment <varname>[ch]</varname></simpara></listitem>
00501 </orderedlist>
00502 </listitem>
00503 </orderedlist>
00504 </listitem><listitem><simpara><varname>[residue_number]</varname> = vector <varname>[vorbis_mapping_submap_residue]</varname> element <varname>[i]</varname></simpara></listitem>
00505 <listitem><simpara><varname>[residue_type]</varname> = vector <varname>[vorbis_residue_types]</varname> element <varname>[residue_number]</varname></simpara></listitem>
00506 <listitem><simpara>decode <varname>[ch]</varname> vectors using residue <varname>[residue_number]</varname>, according to type <varname>[residue_type]</varname>, also passing vector <varname>[do_not_decode_flag]</varname> to indicate which vectors in the bundle should not be decoded. Correct per-vector decode length is <varname>[n]</varname>/2.</simpara></listitem>
00507 <listitem><simpara><varname>[ch]</varname> = 0</simpara></listitem>
00508 <listitem><simpara>for each channel <varname>[j]</varname> in order from 0 ... <varname>[audio_channels]</varname></simpara>
00509 <orderedlist>
00510 <listitem><simpara>if channel <varname>[j]</varname> is in submap <varname>[i]</varname> (vector <varname>[vorbis_mapping_mux]</varname> element <varname>[j]</varname> is equal to <varname>[i]</varname>)</simpara>
00511 <orderedlist>
00512 <listitem><simpara>residue vector for channel <varname>[j]</varname> is set to decoded residue vector <varname>[ch]</varname></simpara></listitem>
00513 <listitem><simpara>increment <varname>[ch]</varname></simpara></listitem>
00514 </orderedlist>
00515 </listitem>
00516 </orderedlist>
00517 </listitem>
00518 </orderedlist>
00519
00520 </section>
00521
00522 <section><title>inverse coupling</title>
00523
00524 <para>
00525 for each <varname>[i]</varname> from <varname>[vorbis_mapping_coupling_steps]</varname>-1 descending to 0
00526
00527 <orderedlist>
00528 <listitem><simpara><varname>[magnitude_vector]</varname> = the residue vector for channel
00529 (vector <varname>[vorbis_mapping_magnitude]</varname> element <varname>[i]</varname>)</simpara></listitem>
00530 <listitem><simpara><varname>[angle_vector]</varname> = the residue vector for channel (vector
00531 <varname>[vorbis_mapping_angle]</varname> element <varname>[i]</varname>)</simpara></listitem>
00532 <listitem><simpara>for each scalar value <varname>[M]</varname> in vector <varname>[magnitude_vector]</varname> and the corresponding scalar value <varname>[A]</varname> in vector <varname>[angle_vector]</varname>:</simpara>
00533 <orderedlist>
00534 <listitem><para>if (<varname>[M]</varname> is greater than zero)
00535 <orderedlist>
00536 <listitem><para>if (<varname>[A]</varname> is greater than zero)
00537 <orderedlist>
00538 <listitem><simpara><varname>[new_M]</varname> = <varname>[M]</varname></simpara></listitem>
00539 <listitem><simpara><varname>[new_A]</varname> = <varname>[M]</varname>-<varname>[A]</varname></simpara></listitem>
00540 </orderedlist>
00541 else
00542 <orderedlist>
00543 <listitem><simpara><varname>[new_A]</varname> = <varname>[M]</varname></simpara></listitem>
00544 <listitem><simpara><varname>[new_M]</varname> = <varname>[M]</varname>+<varname>[A]</varname></simpara></listitem>
00545 </orderedlist>
00546 </para></listitem>
00547 </orderedlist>
00548 else
00549 <orderedlist>
00550 <listitem><para>if (<varname>[A]</varname> is greater than zero)
00551 <orderedlist>
00552 <listitem><simpara><varname>[new_M]</varname> = <varname>[M]</varname></simpara></listitem>
00553 <listitem><simpara><varname>[new_A]</varname> = <varname>[M]</varname>+<varname>[A]</varname></simpara></listitem>
00554 </orderedlist>
00555 else
00556 <orderedlist>
00557 <listitem><simpara><varname>[new_A]</varname> = <varname>[M]</varname></simpara></listitem>
00558 <listitem><simpara><varname>[new_M]</varname> = <varname>[M]</varname>-<varname>[A]</varname></simpara></listitem>
00559 </orderedlist>
00560 </para></listitem>
00561 </orderedlist>
00562 </para></listitem>
00563 <listitem><simpara>set scalar value <varname>[M]</varname> in vector <varname>[magnitude_vector]</varname> to <varname>[new_M]</varname></simpara></listitem>
00564 <listitem><simpara>set scalar value <varname>[A]</varname> in vector <varname>[angle_vector]</varname> to <varname>[new_A]</varname></simpara></listitem>
00565 </orderedlist>
00566 </listitem>
00567 </orderedlist>
00568 </para>
00569
00570 </section>
00571
00572 <section><title>dot product</title>
00573
00574 <para>
00575 For each channel, synthesize the floor curve from the decoded floor
00576 information, according to packet type. Note that the vector synthesis
00577 length for floor computation is <varname>[n]</varname>/2.</para>
00578
00579 <para>
00580 For each channel, multiply each element of the floor curve by each
00581 element of that channel's residue vector. The result is the dot
00582 product of the floor and residue vectors for each channel; the produced
00583 vectors are the length <varname>[n]</varname>/2 audio spectrum for each
00584 channel.</para>
00585
00586 <para>
00587 One point is worth mentioning about this dot product; a common mistake
00588 in a fixed point implementation might be to assume that a 32 bit
00589 fixed-point representation for floor and residue and direct
00590 multiplication of the vectors is sufficient for acceptable spectral
00591 depth in all cases because it happens to mostly work with the current
00592 Xiph.Org reference encoder. </para>
00593
00594 <para>
00595 However, floor vector values can span ~140dB (~24 bits unsigned), and
00596 the audio spectrum vector should represent a minimum of 120dB (~21
00597 bits with sign), even when output is to a 16 bit PCM device. For the
00598 residue vector to represent full scale if the floor is nailed to
00599 -140dB, it must be able to span 0 to +140dB. For the residue vector
00600 to reach full scale if the floor is nailed at 0dB, it must be able to
00601 represent -140dB to +0dB. Thus, in order to handle full range
00602 dynamics, a residue vector may span -140dB to +140dB entirely within
00603 spec. A 280dB range is approximately 48 bits with sign; thus the
00604 residue vector must be able to represent a 48 bit range and the dot
00605 product must be able to handle an effective 48 bit times 24 bit
00606 multiplication. This range may be achieved using large (64 bit or
00607 larger) integers, or implementing a movable binary point
00608 representation.</para>
00609
00610 </section>
00611
00612 <section><title>inverse MDCT</title>
00613
00614 <para>
00615 Convert the audio spectrum vector of each channel back into time
00616 domain PCM audio via an inverse Modified Discrete Cosine Transform
00617 (MDCT). A detailed description of the MDCT is available in the paper
00618 <ulink url="http://www.iocon.com/resource/docs/ps/eusipco_corrected.ps"><citetitle pubwork="article">The
00619 use of multirate filter banks for coding of high quality digital
00620 audio</citetitle></ulink>, by T. Sporer, K. Brandenburg and B. Edler. The window
00621 function used for the MDCT is the function described earlier.</para>
00622
00623 </section>
00624
00625 <section><title>overlap_add</title>
00626
00627 <para>
00628 Windowed MDCT output is overlapped and added with the right hand data
00629 of the previous window such that the 3/4 point of the previous window
00630 is aligned with the 1/4 point of the current window (as illustrated in
00631 <xref linkend="vorbis-spec-window"/>). The overlapped portion
00632 produced from overlapping the previous and current frame data is
00633 finished data to be returned by the decoder. This data spans from the
00634 center of the previous window to the center of the current window. In
00635 the case of same-sized windows, the amount of data to return is
00636 one-half block consisting of and only of the overlapped portions. When
00637 overlapping a short and long window, much of the returned range does not
00638 actually overlap. This does not damage transform orthogonality. Pay
00639 attention however to returning the correct data range; the amount of
00640 data to be returned is:
00641
00642 <programlisting>
00643 window_blocksize(previous_window)/4+window_blocksize(current_window)/4
00644 </programlisting>
00645
00646 from the center (element windowsize/2) of the previous window to the
00647 center (element windowsize/2-1, inclusive) of the current window.</para>
00648
00649 <para>
00650 Data is not returned from the first frame; it must be used to 'prime'
00651 the decode engine. The encoder accounts for this priming when
00652 calculating PCM offsets; after the first frame, the proper PCM output
00653 offset is '0' (as no data has been returned yet).</para>
00654
00655 </section>
00656
00657 <section><title>output channel order</title>
00658
00659 <para>
00660 Vorbis I specifies only a channel mapping type 0. In mapping type 0,
00661 channel mapping is implicitly defined as follows for standard audio
00662 applications:</para>
00663
00664 <variablelist>
00665 <varlistentry>
00666 <term>one channel</term>
00667 <listitem>
00668 <simpara>the stream is monophonic</simpara>
00669 </listitem>
00670 </varlistentry><varlistentry>
00671 <term>two channels</term><listitem>
00672 <simpara>the stream is stereo. channel order: left, right</simpara>
00673 </listitem>
00674 </varlistentry><varlistentry>
00675 <term>three channels</term><listitem>
00676 <simpara>the stream is a 1d-surround encoding. channel order: left,
00677 center, right</simpara>
00678 </listitem>
00679 </varlistentry><varlistentry>
00680 <term>four channels</term><listitem>
00681 <simpara>the stream is quadraphonic surround. channel order: front left,
00682 front right, rear left, rear right</simpara>
00683 </listitem>
00684 </varlistentry><varlistentry>
00685 <term>five channels</term><listitem>
00686 <simpara>the stream is five-channel surround. channel order: front left,
00687 front center, front right, rear left, rear right</simpara>
00688 </listitem>
00689 </varlistentry><varlistentry>
00690 <term>six channels</term><listitem>
00691 <simpara>the stream is 5.1 surround. channel order: front left, front
00692 center, front right, rear left, rear right, LFE</simpara>
00693 </listitem>
00694 </varlistentry><varlistentry>
00695 <term>greater than six channels</term><listitem>
00696 <simpara>channel use and order is defined by the application</simpara>
00697 </listitem>
00698 </varlistentry>
00699 </variablelist>
00700
00701 <para>
00702 Applications using Vorbis for dedicated purposes may define channel
00703 mapping as seen fit. Future channel mappings (such as three and four
00704 channel <ulink url="http:
00705 make use of channel mappings other than mapping 0.</para>
00706
00707 </section>
00708
00709 </section>
00710
00711 </section>