Introduction
Decoding a Layer I frame has two steps: turn each sample code into a subband sample (requantisation and scaling), then turn 32 subband samples at a time into 32 output samples with the polyphase synthesis filter. The filter is shared with Layer II and Layer III.
Requantisation
For a subband with nb bits a sample and a sample code c (an integer from 0 to 2nb − 1), the requantised value is
fraction = (c + 1 − 2^(nb−1)) × 2 / (2^nb − 1)
sample = fraction × 2 × 2^(−index/3)
where index is the subband’s scalefactor index. This is the draft standard’s rule (invert the first bit of the code, read the result as a two’s complement fraction, add 2−(nb−1), and scale by 2nb/(2nb − 1)) written in one line, and it gives the same numbers as the reference decoder’s dequantiser. A code of 0 gives the most negative value, the middle code 2nb−1 − 1 gives 0.
Synthesis filter
Each channel keeps a 1,024-value vector V. For each slot (one sample from each of the 32 subbands, S[0] to S[31]):
- Shift V up by 64 places, so V[i] becomes V[i − 64] for i from 1,023 down to 64.
- For i from 0 to 63: V[i] = Σk=0..31 cos((16 + i) × (2k + 1) × π / 64) × S[k].
- Build the 512-value vector U: for i from 0 to 7 and j from 0 to 31, U[i × 64 + j] = V[i × 128 + j] and U[i × 64 + 32 + j] = V[i × 128 + 96 + j].
- Multiply by the window: W[i] = U[i] × D[i], for i from 0 to 511.
- The 32 output samples are out[j] = Σi=0..15 W[j + 32i], for j from 0 to 31.
A full-scale sine gives output values of about ±1, which a player scales to 16 bits by 32,768 and clips.
Window coefficients
The 512 coefficients D[0] to D[511] are all whole numbers divided by 65,536. The table lists the numbers, 16 to a row, row 0 first, so D[256] is 75038 / 65536 = 1.144989014.
0, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -3, -3, -4, -4, -5,
-5, -6, -7, -7, -8, -9, -10, -11, -13, -14, -16, -17, -19, -21, -24, -26,
-29, -31, -35, -38, -41, -45, -49, -53, -58, -63, -68, -73, -79, -85, -91, -97,
-104, -111, -117, -125, -132, -139, -147, -154, -161, -169, -176, -183, -190, -196, -202, -208,
213, 218, 222, 225, 227, 228, 228, 227, 224, 221, 215, 208, 200, 189, 177, 163,
146, 127, 106, 83, 57, 29, -2, -36, -72, -111, -153, -197, -244, -294, -347, -401,
-459, -519, -581, -645, -711, -779, -848, -919, -991, -1064, -1137, -1210, -1283, -1356, -1428, -1498,
-1567, -1634, -1698, -1759, -1817, -1870, -1919, -1962, -2001, -2032, -2057, -2075, -2085, -2087, -2080, -2063,
2037, 2000, 1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970, 794, 605, 402, 185,
-45, -288, -545, -814, -1095, -1388, -1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788,
-5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209, -8491, -8755, -8998, -9219, -9416, -9585,
-9727, -9838, -9916, -9959, -9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092, -7640, -7134,
6574, 5959, 5288, 4561, 3776, 2935, 2037, 1082, 70, -998, -2122, -3300, -4533, -5818, -7154, -8540,
-9975, -11455, -12980, -14548, -16155, -17799, -19478, -21189, -22929, -24694, -26482, -28289, -30112, -31947, -33791, -35640,
-37489, -39336, -41176, -43006, -44821, -46617, -48390, -50137, -51853, -53534, -55178, -56778, -58333, -59838, -61289, -62684,
-64019, -65290, -66494, -67629, -68692, -69679, -70590, -71420, -72169, -72835, -73415, -73908, -74313, -74630, -74856, -74992,
75038, 74992, 74856, 74630, 74313, 73908, 73415, 72835, 72169, 71420, 70590, 69679, 68692, 67629, 66494, 65290,
64019, 62684, 61289, 59838, 58333, 56778, 55178, 53534, 51853, 50137, 48390, 46617, 44821, 43006, 41176, 39336,
37489, 35640, 33791, 31947, 30112, 28289, 26482, 24694, 22929, 21189, 19478, 17799, 16155, 14548, 12980, 11455,
9975, 8540, 7154, 5818, 4533, 3300, 2122, 998, -70, -1082, -2037, -2935, -3776, -4561, -5288, -5959,
6574, 7134, 7640, 8092, 8492, 8840, 9139, 9389, 9592, 9750, 9863, 9935, 9966, 9959, 9916, 9838,
9727, 9585, 9416, 9219, 8998, 8755, 8491, 8209, 7910, 7597, 7271, 6935, 6589, 6237, 5879, 5517,
5153, 4788, 4425, 4063, 3705, 3351, 3004, 2663, 2330, 2006, 1692, 1388, 1095, 814, 545, 288,
45, -185, -402, -605, -794, -970, -1131, -1280, -1414, -1535, -1644, -1739, -1822, -1893, -1952, -2000,
2037, 2063, 2080, 2087, 2085, 2075, 2057, 2032, 2001, 1962, 1919, 1870, 1817, 1759, 1698, 1634,
1567, 1498, 1428, 1356, 1283, 1210, 1137, 1064, 991, 919, 848, 779, 711, 645, 581, 519,
459, 401, 347, 294, 244, 197, 153, 111, 72, 36, 2, -29, -57, -83, -106, -127,
-146, -163, -177, -189, -200, -208, -215, -221, -224, -227, -228, -228, -227, -225, -222, -218,
213, 208, 202, 196, 190, 183, 176, 169, 161, 154, 147, 139, 132, 125, 117, 111,
104, 97, 91, 85, 79, 73, 68, 63, 58, 53, 49, 45, 41, 38, 35, 31,
29, 26, 24, 21, 19, 17, 16, 14, 13, 11, 10, 9, 8, 7, 7, 6,
5, 5, 4, 4, 3, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1
Accuracy
The standard defines a decoder’s accuracy by a comparison with the reference decoder on test streams (ISO/IEC 11172-4). Written to the specification above, in floating point, a decoder stays within a fraction of the last bit of a 16-bit sample of other floating point decoders, and within one last bit of decoders that work at 16 bits. The explorer’s decoder, mpg123, FFmpeg and the ISO reference decoder agree to that precision on generated streams that cover all three MPEG-1 and all three MPEG-2 sample rates, single channel, stereo, dual channel and joint stereo with each bound, CRC, padding, ancillary data and extreme sample codes, and on a free-format stream for the decoders that read free format (FFmpeg does not).
The same holds for streams made by the ISO reference encoder at every bit rate index of 32 to 448 kbit/s, at 32, 44.1 and 48 kHz and (with the half-rate bit rate table) at the MPEG-2 sample rates, and for a Layer I recording made by another encoder. Against mpg123 the largest difference is under a quarter of a 16-bit step; against the two 16-bit decoders it is one step. In a few joint stereo streams whose mode changes from frame to frame, FFmpeg’s demuxer skips some whole frames; the frames it does decode agree with the others.