From sample codes to subband samples
After a frame is read, each of its sample values q (an integer, 36 for each band and channel) is scaled to a subband sample in three steps. For band b, channel c and group g (0 to 2, covering samples 12g to 12g + 11 of the band):
- The factor is CC[resolution + 1] × SCF[scalefactor of the group], rounded to a 32-bit float.
- The sample is that factor times q, also rounded to a 32-bit float.
- If the band uses mid/side stereo, the two channels are combined (see below).
A channel with resolution 0 in a band contributes zero. The values stay in the order slot 0 to 35 and band 0 to 31, and go to the synthesis one slot at a time. Bands above the stream’s maximum band are silent.
Resolution table
CC is the step size of each resolution; DC is the offset subtracted from the plain or extra-bit values of the high resolutions. Index in the table is the resolution plus one. The Tables page also gives the plain bit counts of each resolution.
| Resolution | CC | DC |
|---|---|---|
| −1 (noise) | 111.285962475327 | 2 |
| 0 | 65536 | 0 |
| 1 | 21845.333333333332 | 1 |
| 2 | 13107.2 | 2 |
| 3 | 9362.285714285714 | 3 |
| 4 | 7281.777777777777 | 4 |
| 5 | 4369.066666666666 | 7 |
| 6 | 2114.064516129032 | 15 |
| 7 | 1040.253968253968 | 31 |
| 8 | 516.031496062992 | 63 |
| 9 | 257.003921568627 | 127 |
| 10 | 128.25048923679 | 255 |
| 11 | 64.062561094819 | 511 |
| 12 | 32.015632633121 | 1,023 |
| 13 | 16.003907203907 | 2,047 |
| 14 | 8.000976681723 | 4,095 |
| 15 | 4.000244155527 | 8,191 |
| 16 | 2.000061037018 | 16,383 |
| 17 | 1.000015259021 | 32,767 |
The offset DC is only used for the plain-bit resolutions: 8 to 17 in SV7 and 9 and above in SV8, where the stored number is an unsigned value with the offset removed to centre it. Resolutions 1 to 7 give signed values directly.
Scalefactors
The stored scalefactor is an index into a table of 256 entries (it is used modulo 256). Index 1 is 1/32768; each step up multiplies by 0.83298066476582673961, and each step down divides by it, so one step is about −1.58 dB. The table entries are rounded to 32-bit floats. In SV8 the stored index runs from −6 (the 7-bit absolute value minus 6). In SV7 the value 0x8080 marks a scalefactor that was above 1,024, which reads as a very quiet entry of the table.
Noise substitution
A resolution of −1 stores no samples. The decoder makes them: for each of the 36 values it steps two 32-bit shift registers (the first right by one bit with feedback from the parity of its bits under the mask 0xF5, the second left by one with feedback from the parity of its bits 25 to 31 under the mask 0x63), starts them both at 1, exclusive-ors the two, adds up the four bytes of the result and subtracts 510. The sum is then scaled like any other sample, with resolution −1 and the band’s scalefactor.
Mid/side stereo
For a band with the mid/side flag set the two channel values are mid a (left channel) and side b (right channel). If both channels are coded, left is a + b and right is a − b. If only the left is coded, both outputs are a. If only the right is coded, left is b and right is −b.
Divergence from the specification
- The archived specifications do not give the tables or the formulas. This page follows the decoder source (libmpcdec 1.2.6 and revision 475).
Sources
- libmpcdec 1.2.6 and revision 475: the requantisation, the scalefactor table, the noise generator and the CC and DC tables.