The filter bank
The sound is rebuilt by the polyphase synthesis filter bank of MPEG audio
(as in Layer I and II): 32 subband samples go in for each
time slot and 32 output samples come out. Musepack differs from MPEG audio in its window,
which is its own 512-tap table (the DI_OPT table of the decoder, divided by
65,536) and in the order in which it groups the work, but the structure is the same.
The output scale is plus or minus 1.0 for full scale, so a 16-bit sample is the value times 32,768.
One frame
Each channel keeps a buffer V of 3,264 values (2,304 plus 960). At the start of a frame the first 960 values are copied to the end of the buffer (from position 2,304), which is the history of the 15 previous slots. Then for each of the 36 slots n:
- The write position moves down by 64, from 2,304 for the first slot.
- Matrixing. The 32 subband samples of the slot become 64 values stored at the write position. This is the cosine transform of MPEG audio, computed with the fast method of the decoder: sums and differences of mirrored pairs of samples (the differences scaled by 16 constants), a cascade of three more butterfly stages with the constants 0.5024 to 5.1011, 0.5098 to 2.5629, 0.5412, 1.3066 and 0.7071, and a final combination of the 16 + 16 results into the 64 values, with the symmetry V[32 − k] = −V[k] and V[63 − k] = V[33 + k].
- Windowing. Each of the 32 output samples k is the sum of 16 products of V at the position k plus the offset and the window value in row k, column i of the table. The offsets are 0, 96, 128, 224, 256, 352, 384, 480, 512, 608, 640, 736, 768, 864, 896 and 992.
The 32 outputs of slot n are output samples 32n to 32n + 31 of the frame, so a frame yields 1,152 samples a channel. Channels are interleaved in the output.
Delay and length
The filter bank delays the sound by 481 samples a channel. A decoder therefore discards the first 481 samples it produces (and, in SV8, the beginning silence of the stream header on top of them) and keeps running one frame past the last frame of the stream to flush the rest. The decoder stops when the samples still to play plus 481 are zero or less; the stream’s length is given in the SV8 stream header or the SV7 header.
Accuracy
The viewer’s decoder is a port of the floating-point decoder of libmpcdec, and it rounds its intermediate values to 32-bit floats as that decoder does. Against the output of libmpcdec for the same files, every sample agrees to within one step of a 16-bit sample.
Divergence from the specification
- The archived specifications describe the stream only; the filter bank is described in the decoder source. The window table is the table
Di_optof libmpcdec; its 512 values and the transform constants are listed on the Tables page.
Sources
- libmpcdec 1.2.6 and revision 475 of the Musepack source: the synthesis, the window table and the delay.