Layers I and II are the simpler MPEG audio layers. They have no Huffman coding and no bit reservoir: each frame is self-contained, holding 32 subbands of samples, an allocation that says how many bits each subband uses, and scalefactors that restore its level. The frame header and everything before the audio data are the same as for Layer III; see the frame header.
Layer I
A frame holds 384 samples per channel: 12 consecutive samples of each of 32 subbands. After the header and any CRC come, in order:
- Allocation: 4 bits for each subband and channel, giving the bits per sample as the value plus one. 0 means the subband is silent; 15 is not allowed. From the bound up, in joint stereo, one allocation serves both channels.
- Scalefactors: 6 bits for each subband and channel that has anything allocated.
- Samples: for each of 12 time slots, for each subband, for each channel, one code of the allocated width. Above the bound, one code serves both channels, each scaled by its own scalefactor.
Layer II
A frame holds 1152 samples per channel: 36 consecutive samples of each subband, arranged as 12 groups of three, and shares its scalefactors across three parts of 12 samples each. After the header and any CRC:
- Bit allocation: one field per subband and channel, of a width set by the allocation table; above the bound, one field for both channels.
- Scalefactor selection (scfsi): 2 bits per subband and channel with an allocation.
- Scalefactors: for each subband with an allocation, one to three 6-bit values, as the scfsi says.
- Samples: 12 groups; in each, for each subband, for each channel, three samples, as a single grouped code or three separate codes.
| scfsi | Scalefactors stored | Applied to parts 1, 2, 3 |
|---|---|---|
| 0 | three | first, second, third |
| 1 | two | first, first, second |
| 2 | one | first, first, first |
| 3 | two | first, second, second |
Layer II allocation tables
Which subbands exist and how they may be coded depends on the sample rate and the bit rate per channel. Four tables serve MPEG-1 (ISO/IEC 11172-3, tables B.2a to B.2d); MPEG-2’s lower rates use their own (13818-3). For each subband, the table gives the allocation field’s width, then the quantisation classes the values 1, 2, … select.
| Table | Used when | Subbands |
|---|---|---|
| a (B.2a) | sample rate is 48 kHz and bit rate per channel at least 56, or per channel 56 to 80; free format at 48 kHz | 0–26 |
| b (B.2b) | sample rate is not 48 kHz and bit rate per channel at least 96; free format at 44.1 and 32 kHz | 0–29 |
| c (B.2c) | sample rate is not 32 kHz and bit rate per channel at most 48 | 0–7 |
| d (B.2d) | otherwise | 0–11 |
| LSF (13818-3) | MPEG-2 and 2.5 | 0–29 |
Free format follows the highest rates, as libmad does. mpg123 uses table a for free format at every sample rate, so the two decode a free-format Layer II stream at 44.1 or 32 kHz differently; such streams are very rare.
Rows of allocation-field width and classes (allocation value 0 is silent):
| Tables | Subbands | Width | Classes (levels) for allocation 1, 2, 3 … |
|---|---|---|---|
| a, b | 0–2 | 4 | 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535 |
| a, b | 3–10 | 4 | 3, 5, 7, 9, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 65535 |
| a, b | 11–22 | 3 | 3, 5, 7, 9, 15, 31, 65535 |
| a, b | 23–29 | 2 | 3, 5, 65535 |
| c, d | 0–1 | 4 | 3, 5, 9, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767 |
| c, d | 2–11 | 3 | 3, 5, 9, 15, 31, 63, 127 |
| LSF | 0–3 | 4 | 3, 5, 7, 9, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383 |
| LSF | 4–10 | 3 | 3, 5, 9, 15, 31, 63, 127 |
| LSF | 11–29 | 2 | 3, 5, 9 |
Samples
Every level count is 3, 5, 9, or 2n − 1. A value v from 0 to levels − 1 is a sample s = (2v + 1 − levels) / levels, in the range −1 to 1, then multiplied by the scalefactor.
| Levels | Bits a sample | Coding |
|---|---|---|
| 3 | 5, for three samples together | grouped: v₀ + 3 v₁ + 9 v₂ in 5 bits |
| 5 | 7, for three together | grouped: v₀ + 5 v₁ + 25 v₂ in 7 bits |
| 7 | 3 each | one code a sample |
| 9 | 10, for three together | grouped: v₀ + 9 v₁ + 81 v₂ in 10 bits |
| 15, 31, … 65535 | log₂(levels + 1) each | one code a sample |
In Layer I every subband uses a level count of 2n − 1 with n from the allocation; there is no grouping.
Scalefactors
A 6-bit index selects a multiplier: 2 × 2−index / 3, so 0 is 2.0, 1 is about 1.587, 2 about 1.26, and each three steps halves the value. Index 63 is not used.
Intensity stereo
In joint stereo, subbands from the bound up ( the mode extension sets it to 4, 8, 12 or 16) share one allocation and one set of samples between the two channels; each channel has its own scalefactors, which set its share of the signal.
Synthesis
The decoded subband samples go through the polyphase synthesis filterbank, 32 samples at a time: a 32-point DCT feeding a 1024-sample buffer, windowed by the standard’s 512 coefficients D[0..511], which produces the time samples. Layer III ends with the same filterbank. The steps and all 512 coefficients are on Decoding tables.
Ancillary data
Any bits after the samples are ancillary data, ignored by a decoder. The explorer shows where the samples end and the ancillary data begins in each frame.
The MPEG-2 multichannel extension
ISO/IEC 13818-3 extends MPEG-1 audio backwards-compatibly to up to five full-range channels and a low-frequency channel (3/2 + LFE), and to up to seven multilingual commentary channels, at the MPEG-1 sample rates. It is defined for all three layers and used almost only with Layer II, in DVB and DVD-Video. This is what is publicly known of it:
- The frames are ordinary MPEG-1 frames. Their two channels carry a compatible stereo mix of all the channels (often called L0 and R0), so an MPEG-1 decoder plays them unchanged.
- The multichannel data sits in the ancillary data of each frame: a header saying which channels are present and how the stereo mix was made (the matrixing, or dematrixing, procedure), then scalefactors and samples for the extra channels. A decoder subtracts the extra channels from the stereo mix to recover left and right.
- When a frame cannot hold it all, the rest goes in a separate extension stream with its own sync word, which a file may carry beside the main one.
The standard text, ISO/IEC 13818-3, is sold by ISO and was not available here. What
the explorer shows comes instead from the source of the ISO reference decoder
(dist10, mc_header() and its extension sync search), so it is inferred,
not read from the specification:
- The MC header, in the first ancillary bits after the samples of a Layer II frame: extension-frame-present (1 bit), the number of ancillary bytes (8 bits, only when an extension frame is present), centre (2), surround (2), LFE (1), audio mix (1), dematrix procedure (2), multilingual channels (3), multilingual sampling rate (1), multilingual layer (1), copyright identifier bit (1) and start (1).
- An extension frame, placed after the Layer II frame in the file: the 12-bit sync word 0x7FF, a 16-bit CRC, an 11-bit length in bytes and a reserved bit, then the extension data.
The explorer shows the MC header only for a Layer II frame that an extension frame follows, because a plain stereo frame's ancillary bits may be anything. The extension data (bit allocation, scalefactors and samples of the extra channels) is shown as bytes and not decoded; the meaning of the audio mix bit and the CRC coverage are not known. The viewer plays the compatible stereo mix.