The main data is the bulk of a Layer III frame, and it is what the sound is decoded
from. For each granule and channel it holds scalefactors (part 2) and Huffman-coded
spectral values (part 3), part2_3_length bits in all. Any bytes left over
at the end are padding or ancillary data, which are not part of the audio.
The bit reservoir
Main data is one continuous stream of bytes running through the frames, skipping the
frame headers and side information. A frame’s main data does not have to start in its
own bytes: the side information’s main_data_begin says it starts that
many bytes before the frame’s data, in the unused end of earlier frames. So a frame
that needs few bits leaves room that a later, more demanding frame can use, while the
bit rate stays constant. The reach is 511 bytes in MPEG-1 and 255 in LSF.
The consequence is that a frame cannot be decoded alone: a decoder needs the preceding frames’ data. If the reservoir does not reach back far enough, for instance just after a seek, the frame cannot be decoded and is treated as silence. The explorer’s tree shows which granules have bits in each frame’s bytes, whether they began in an earlier frame or carry on into a later one.
Scalefactors
Scalefactors adjust the quantiser step in each scalefactor band of the spectrum. In
MPEG-1 scalefac_compress indexes two tables giving the bits each takes:
scalefac_compress | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
slen1 | 0 | 0 | 0 | 0 | 3 | 1 | 1 | 1 | 2 | 2 | 2 | 3 | 3 | 3 | 4 | 4 |
slen2 | 0 | 1 | 2 | 3 | 0 | 1 | 2 | 3 | 1 | 2 | 3 | 1 | 2 | 3 | 2 | 3 |
Long blocks store bands 0–10 with slen1 and 11–20 with slen2.
Short blocks store, for each of the three windows, bands 0–5 with slen1 and
6–11 with slen2. In a mixed block, long bands 0–7 use
slen1, then short bands 3–5 use slen1 and 6–11
slen2. In the second granule of a frame, scfsi can say a band
group’s values are the same as the first granule’s, and are not stored again.
In LSF (MPEG-2 and 2.5), scalefac_compress is 9 bits and is
decoded into four lengths for up to four partitions of the bands. Below, c is
scalefac_compress; in intensity stereo, the right channel uses the second
set with c divided by two.
| Range of c | slen1 | slen2 | slen3 | slen4 | Preflag | Partition table |
|---|---|---|---|---|---|---|
| 0–399 | (c>>4)/5 | (c>>4)%5 | (c%16)>>2 | c%4 | 0 | 0 |
| 400–499 | ((c−400)>>2)/5 | ((c−400)>>2)%5 | (c−400)%4 | 0 | 0 | 1 |
| 500–511 | (c−500)/3 | (c−500)%3 | 0 | 0 | 1 | 2 |
| right channel, c/2: 0–179 | c/36 | (c%36)/6 | (c%36)%6 | 0 | 0 | 3 |
| 180–243 | ((c−180)%64)>>4 | ((c−180)%16)>>2 | (c−180)%4 | 0 | 0 | 4 |
| 244–255 | (c−244)/3 | (c−244)%3 | 0 | 0 | 0 | 5 |
The partition tables give how many scalefactors each of the four lengths covers:
| Table | Long blocks | Short blocks | Mixed blocks |
|---|---|---|---|
| 0 | 6, 5, 5, 5 | 9, 9, 9, 9 | 6, 9, 9, 9 |
| 1 | 6, 5, 7, 3 | 9, 9, 12, 6 | 6, 9, 12, 6 |
| 2 | 11, 10, 0, 0 | 18, 18, 0, 0 | 15, 18, 0, 0 |
| 3 | 7, 7, 7, 0 | 12, 12, 12, 0 | 6, 15, 12, 0 |
| 4 | 6, 6, 6, 3 | 12, 9, 9, 6 | 6, 12, 9, 6 |
| 5 | 8, 8, 5, 0 | 15, 12, 9, 0 | 6, 18, 9, 0 |
The preflag, for long blocks, adds this fixed table to the
scalefactors of bands 0 to 21: 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3, 3, 2, 0.
Scalefactor bands
Bands get wider with frequency, in line with the ear. The start of each band, in spectral lines, depends on the sample rate. Widths for long blocks (22 bands, 576 lines):
| Sample rate | Widths of bands 0 to 21 |
|---|---|
| 44,100 | 4 4 4 4 4 4 6 6 8 8 10 12 16 20 24 28 34 42 50 54 76 158 |
| 48,000 | 4 4 4 4 4 4 6 6 6 8 10 12 16 18 22 28 34 40 46 54 54 192 |
| 32,000 | 4 4 4 4 4 4 6 6 8 10 12 16 20 24 30 38 46 56 68 84 102 26 |
| 22,050 | 6 6 6 6 6 6 8 10 12 14 16 20 24 28 32 38 46 52 60 68 58 54 |
| 24,000 | 6 6 6 6 6 6 8 10 12 14 16 18 22 26 32 38 46 54 62 70 76 36 |
| 16,000 | 6 6 6 6 6 6 8 10 12 14 16 20 24 28 32 38 46 52 60 68 58 54 |
| 11,025 and 12,000 | 6 6 6 6 6 6 8 10 12 14 16 20 24 28 32 38 46 52 60 68 58 54 |
| 8,000 | 12 12 12 12 12 12 16 20 24 28 32 40 48 56 64 76 90 2 2 2 2 2 |
Widths for short blocks (13 bands, 192 lines, one set for each window):
| Sample rate | Widths of bands 0 to 12 |
|---|---|
| 44,100 | 4 4 4 4 6 8 10 12 14 18 22 30 56 |
| 48,000 | 4 4 4 4 6 6 10 12 14 16 20 26 66 |
| 32,000 | 4 4 4 4 6 8 12 16 20 26 34 42 12 |
| 22,050 | 4 4 4 6 6 8 10 14 18 26 32 42 18 |
| 24,000 | 4 4 4 6 8 10 12 14 18 24 32 44 12 |
| 16,000 | 4 4 4 6 8 10 12 14 18 24 30 40 18 |
| 11,025 and 12,000 | 4 4 4 6 8 10 12 14 18 24 30 40 18 |
| 8,000 | 8 8 8 12 16 20 24 28 36 2 2 2 26 |
Huffman coding
The 576 spectral lines are split into three regions. The lowest lines, the
big values, are coded in pairs: big_values × 2 lines, using up
to three tables from table_select, with region boundaries from
region0_count and region1_count. Above them, the
count1 region holds quadruples of values that are all −1, 0 or +1, each coded
by one of two fixed tables; everything above that is zero.
| Table | Largest value | Linbits | Table | Largest value | Linbits | |
|---|---|---|---|---|---|---|
| 0 | all zero; no bits | 16 | 15 | 1 | ||
| 1 | 1 | 17 | 15 | 2 | ||
| 2, 3 | 2 | 18 | 15 | 3 | ||
| 4 | not used | 19 | 15 | 4 | ||
| 5, 6 | 3 | 20 | 15 | 6 | ||
| 7, 8, 9 | 5 | 21 | 15 | 8 | ||
| 10, 11, 12 | 7 | 22 | 15 | 10 | ||
| 13, 15 | 15 | 23 | 15 | 13 | ||
| 14 | not used | 24–31 | 15 | 4, 5, 6, 7, 8, 9, 11, 13 |
Tables 16 to 23 share one code tree and tables 24 to 31 another; they differ only in how many extra linbits follow the code. A value of 15 in those tables is followed by that many bits holding the excess, then a sign bit for each nonzero value. The two count1 tables each code the sixteen patterns of four values:
Table A, code lengths 1 to 6 bits, with shorter codes for the commonest patterns. Table B, every pattern 4 bits. The value is the four values v, w, x, y as bits, and a sign bit follows each that is 1.
Requantisation
A coded value is becomes a frequency line:
xr = sign(is) × |is|4/3 × 2(global_gain − 210) / 4 × 2−(scalefac_multiplier × (scalefac + preflag × pretab))
where scalefac_multiplier is 0.5 or 1 from scalefac_scale.
Short windows also subtract 8 × subblock_gain from
global_gain before the division by 4. The decoder then applies stereo
processing, reordering and alias reduction before the transform.
Stereo
In joint stereo, the mode extension turns on two tools. MS stereo codes sum and difference: L = (M + S) / √2, R = (M − S) / √2. Intensity stereo applies above the highest band of the right channel that contains any value. In that region the right channel’s scalefactors hold not a scale but a position, and both channels are derived from the left.
MPEG-1 positions 0 to 6 give a ratio tan(position × π / 12): L = ratio / (1 + ratio) of the left signal, R = 1 / (1 + ratio) of it; 7 is illegal, meaning intensity stereo does not apply there, and MS is used if it is on. Position 6 means L = 1 and R = 0.
In LSF, the step is 2−1/4 or 2−1/2 (from the low bit of the right
channel’s scalefac_compress). Position 0 gives L = R; an odd position p
scales L by the step raised to (p+1)/2; an even position scales R by the step raised to
p/2. The illegal position is the largest value the band’s scalefactor bits can hold.
The top band (long band 21, short band 12) has no scalefactor of its own and uses the
one below it.
From lines to samples
- Reordering. Short blocks are stored band by band, window after window; before the transform they are put back in increasing frequency, with the three windows interleaved.
- Alias reduction. For long blocks, butterflies across each subband boundary (eight lines) use c = −0.6, −0.535, −0.33, −0.185, −0.095, −0.041, −0.0142, −0.0037, with cs = 1/√(1+c²) and ca = c/√(1+c²). Short blocks have none; a mixed block reduces only the boundary between subbands 0 and 1.
- IMDCT. Each of the 32 subbands holds 18 lines: a 36-point transform for long blocks, or three 12-point transforms for short ones, with sine windows per the block type, overlapped with the previous granule (overlap and add).
- Frequency inversion. Odd time samples of odd subbands are negated.
- Synthesis. The same 32-band polyphase filterbank as Layers I and II: a 32-point DCT into a 1024-sample FIFO, a 512-tap window D[], giving 32 samples per slot, 18 slots a granule.
The result is 576 samples for each channel and granule, in the range −1 to 1, which is what the explorer’s waveform and Play button use.