After the three headers, each packet is a block of audio. Decoding a packet reads its mode, recovers a floor curve and a residue spectrum for every channel, multiplies them, and transforms the result into samples. All fields are bit-packed, lowest bits first.
Packet start
| Size | Field | Description |
|---|---|---|
| 1 bit | packet type | 0 for audio; a set bit would be a header |
| ilog(modes − 1) | mode number | the mode used for this block |
| 1 bit each | window flags | on a long block only: the previous and next window flags (0 means that neighbour is short) |
Floor curves
Each channel uses the floor of its submap. Floor 1 starts with a flag:
0 means the channel is unused in this block. Otherwise it reads two amplitudes (each
ilog(range − 1) bits), then partition by partition uses the class books to read
one value per post. The values are predictions from neighbouring posts. Reconstruction
joins the kept posts with straight lines in dB.
Floor 0 reads an amplitude, chooses a book by number, and reads enough vectors to make up the LSP coefficients. The curve is the LSP filter’s response on the Bark scale.
A channel with an unused floor has no residue. A coupled pair is treated as used if either channel in the pair is used.
Residue spectra
Residues are read in eight passes over partitions, using cascaded codebooks by class. A classification word, read through the classbook, gives the class of each partition.
| Type | How the values fall into each partition |
|---|---|
| 0 | one vector spread across the partition, position by position |
| 1 | vectors placed one after another in the partition |
| 2 | like 1, but over one vector interleaving all channels, split back out afterwards |
Reading continues only up to residue_end, and running out of packet ends
the block with zeros for the rest.
Channel coupling
For every coupling step, last to first, the magnitude and angle spectra become two channels again:
| M | A | New M | New A |
|---|---|---|---|
| M > 0 | A > 0 | M | M − A |
| M > 0 | A ≤ 0 | M + A | M |
| M ≤ 0 | A > 0 | M | M + A |
| M ≤ 0 | A ≤ 0 | M − A | M |
Transform and overlap
- Multiply each channel’s residue by its floor curve to give the spectrum.
- Apply the inverse MDCT of the block size, which gives twice as many samples as spectral values.
- Apply the window: a slope of the Vorbis power-complementary sine over the overlap, with a shorter slope next to a short neighbour.
- Overlap-add with the previous block, and output the samples between the centres of the two blocks.
The first block gives no output. Each later block yields a quarter of the previous block plus a quarter of the current block. Granule positions then trim both ends (Vorbis I appendix A.2, and granule positions):
- Start. When the first page that finishes an audio packet has a granule position smaller than the samples its packets give, the difference is dropped from the start of the output: those samples come before time zero. No more may be dropped than the first two packets’ overlap gives. A larger granule position is allowed too: the stream then starts later than 0, and nothing is dropped.
- End. When the last page (the one with the EOS flag) has a granule position smaller than the samples its packets give, the extra samples at the end are dropped.
Links
- Vorbis I specification – the Xiph.Org Foundation’s description of the codec
Source: Xiph.Org, Vorbis I specification, section 4.3.1 (packet type, mode number, window flags), 8.3 to 8.5 (residue types 0 to 2), 4.3.5 (square polar channel decoupling, the four cases above) and 10.1 (the 256-entry floor1_inverse_dB_table, reproduced by the formula the explorer uses to 7 digits).