The old stream versions
Musepack streams before version 7 (versions 1 to 6) were produced by early encoders
(MPEGplus). They are 44,100 Hz stereo and are made of the same 1,152-sample frames of 36
time slots as the later versions, with the same filter bank
(Synthesis) and the same requantisation
(Requantisation). What differs is how a
frame is written: the resolutions of all bands come first, then the scalefactor
selectors, the scalefactors and the samples, and every sample is a code of its own.
The decoder source for versions 4 to 6 is libmpcdec 1.2.6, built with its old-version option.
It reads only variable bit rate streams without intensity stereo and with a block size of 1; the rest
(constant bit rate, intensity stereo, larger blocks, versions 1 to 3) is read from the source and the compiled code of the
2000 decoder library for Windows (mppdecoder.cpp, mppdecoder.lib).
This page follows both, and the viewer’s decoder reproduces their output.
There is no replay gain, profile, encoder version or gapless information in the header of these versions. A tag (Tags) may follow the last frame.
Recognising a stream
A stream of these versions has no marker. It starts with the header word below, and the
only way to tell it from other data is its version field (1 to 6) together with a plausible first frame:
from version 4 the 20-bit length of the first frame must fit in the file. Versions 1 to 3 have no length to check,
so the viewer takes a file as one of them only when its name ends in .mpc, .mp+ or .mpp
(and, for version 3, the block size is not 0). An ID3v2 tag in front
of the stream is skipped as for the other versions. libmpcdec itself looks for the
MP+ marker of version 7 first and, finding none, takes the file as an old stream.
The header
Bits of a stream are numbered from the start of the stream (after an ID3v2 tag) and read in 32-bit little-endian words, the most significant bit of each word first (the byte order of the SV7 header). The first word holds these fields, from its most significant bit down:
| Bits | Field | Meaning |
|---|---|---|
| 9 | Bit rate | The bit rate in kilobits a second, 0 when it is not stated. Above 128 the resolutions are plain numbers (constant bit rate, below); up to 128 they are Huffman codes. It also sets the band range (below) |
| 1 | Intensity stereo | 1 when the bands from Min_Band up to Max_Band are intensity stereo (below) |
| 1 | Mid/side stereo | 1 when the frames carry a mid/side flag for each band |
| 10 | Stream version | 1 to 6 |
| 5 | Desired maximum band | From version 2: the highest subband that frames may use (0 to 31); 0 lets the decoder choose from the bit rate. Version 1 has no such field |
| 6 | Block size | From version 3: the number of frames in a block (1 in most streams). 0 is not valid. Versions 1 and 2 have no such field and use 1 |
The frame count follows from version 3: 16 bits in versions 3 and 4 and 32 bits in versions 5 and 6. The header is therefore 21 bits long in version 1, 26 in version 2, 48 in versions 3 and 4 and 64 bits long in versions 5 and 6, and the first frame starts right after it. Versions 4 and 5 count one frame too many (the last frame of those versions is not valid), so the number of frames is the field minus one; version 6 uses the field as it is. Versions 1 and 2 store no frame count; the 2000 library ignores the count of every version and reads frames until the data has no whole 32-bit word left (the file length rounded down to a multiple of 4 bytes), and the viewer counts the frames of versions 1 to 3 the same way.
The sample rate (44,100 Hz) and the channel count (2) are not stored.
Min_Band and Max_Band
The decoder turns the bit rate, the intensity flag and the desired band into two band numbers, Min_Band and Max_Band
(the routine is the header reader of the 2000 library, Headergroesse). Every frame codes the bands 0 up to Max_Band.
- Desired band 0 (versions 1 and above), intensity stereo off (Min_Band, Max_Band): bit rate 0: 32 and 31; up to 64: 21 and 20; up to 160: 27 and 26; up to 384: 30 and 29; above 384: 32 and 31.
- Desired band 0, intensity stereo on (bit rates up to 384): up to 64 (including 0): 4 and 20; up to 112: 8 and 26; up to 160: 12 and 26; up to 384: 16 and 29. Above 384 neither number is set.
- Desired band not 0, intensity stereo off: Max_Band is the desired band and Min_Band is one more.
- Desired band not 0, intensity stereo on: up to a bit rate of 384 Max_Band is the desired band and Min_Band is 4 (up to 64), 8 (up to 112), 12 (up to 160) or 16 (up to 384); above 384 neither is set. Then a Min_Band that is not below Max_Band is set to Max_Band.
Without intensity stereo Min_Band has no use. The library never clears the two numbers: a header that does not set them (above) keeps the values left by the file before it, 0 and 0 in a fresh process, which is what the viewer uses. The viewer’s test runs the library on every bit rate, intensity flag and desired band to check these rules.
Frames
Frames follow each other with no padding, bit after bit. From version 4 a 20-bit length precedes every block of frames (the header’s block size gives the number of frames in a block; it is 1 in most streams, so each frame has its own length). The length is the size of the block in bits without the length field itself, so the next length starts at the bit after them. libmpcdec checks that the fields it reads use exactly that many bits and treats a block where they do not as the end of the stream; the viewer lists the frame as faulty and goes on from the length. Versions 1 to 3 have no lengths: the frames follow the header and each other directly, and version 3 has a block size but nothing that uses it.
The data of a frame, in this order (the tables are on the Tables page):
- Resolutions. For each band n from 0 to the maximum band: the left channel’s resolution index, the mid/side flag of the band (1 bit, only when the header says mid/side), then the right channel’s resolution index. With a bit rate above 128 (constant bit rate) an index is a plain number of 4 bits for bands 0 to 10, 3 bits for bands 11 to 22 and 2 bits for bands 23 to 31, which picks the entry of the band’s row of the resolution map below. With a bit rate up to 128 (including 0) an index is a Huffman code from the region table of the band: A for bands 0 to 10, B for bands 11 to 22 and C for bands 23 to 31. The resolution is the entry of the resolution map at the band’s row and that index. It is 0 (no samples), 1 to 14 or 17. The highest band with a non-zero resolution in either channel is the last used band; the bands after it have no more data in the frame. With intensity stereo, the bands from Min_Band on have only the left index: no mid/side flag and no right index, and the band’s samples serve both channels (below).
- Selectors. For each band from 0 to the last used band, left then right, but only for a channel with a non-zero resolution (in an intensity stereo band the right channel has a selector and scalefactors when the left resolution is non-zero): a Huffman code from the selector table. Its symbol divided by 2 is the scalefactor selector (0 to 3) and its lowest bit says how the scalefactors are written: 1 as differences, 0 as plain 6-bit values.
- Scalefactors. The same loop, one group of up to three scalefactors for each band and channel (one for each group of 12 time slots). The selector says which are written: 0 all three; 1 the first and the second, with the third the same as the second; 2 the first and the third, with the second the same as the first; 3 only the first, used for all three. A written value is either a 6-bit number or, when the delta flag is 1, the previous written value plus a difference (the previous value of the first one is the third scalefactor of the band in the previous frame, so a decoder keeps these from frame to frame). After a run of differences a scalefactor above 1,024 is replaced by 32,896 (hexadecimal 8080), which the requantisation reads as a very quiet entry of its table.
- Samples. For each band from 0 to the last used band, 36 time slots. A resolution from 1 to 7 is coded with the Huffman table of that resolution (resolution 1 to 7); each code gives one sample, unlike version 7, where resolutions 1 and 2 give several samples a code. The codes of the two channels alternate, left then right for each time slot. A resolution of 8 or more is written as plain values of a fixed number of bits (the plain bit count of the resolution on the Tables page) minus an offset, again left and right alternating, after all the Huffman coded samples of the band.
The numbers in the frame (resolutions, scalefactors, samples) then go through the same requantisation, mid/side decoding and synthesis as in the other versions.
Intensity stereo
With the intensity flag set, bands below Min_Band are coded and decoded as above. The bands from Min_Band to Max_Band have one resolution (the left one) and one set of 36 samples; the right resolution and the mid/side flag are not written. A sample is requantised with the left resolution without its scalefactor and divided by the fourth root of 2 (21/4); the left channel’s value is that number times the left scalefactor and the right channel’s value is the same number times the right scalefactor. The two scalefactor sets are written as for any band with a non-zero resolution. No band is mid/side.
Blocks
The length of a block covers its frames up to the next length; a decoder that finds the fields of the block use another number of bits stops (libmpcdec) or goes on from the length (the viewer). The scalefactor differences carry across the frames of a block exactly as across single frames. In version 6 the last block’s length does not count the 11-bit sample count of the end of stream, and the viewer counts the blocks of the chain with the block size as step.
The end of the stream
The decoder discards the first 481 samples of its output, the delay of the filter bank, and stops after the last frame.
- Versions 4 and 5 have no information on the length of the last frame: every frame gives 1,152 samples a channel, so the length is the number of frames times 1,152 less 481.
- Version 6 writes an 11-bit number right after the last frame, which says how many samples of the last frame are used (a 0 is read as 1,152, a fix for an encoder bug). With m that number, the decay of the filter bank is d = (m + 481) modulo 1,152. If m + 481 is 1,152 or more, the decoder runs the filter bank once more on subband samples that are all zero, and the last frame gives 1,152 + d samples; otherwise it gives d samples. The length of the stream is the number of frames less one, times 1,152, plus what the last frame gives, less 481.
Divergence from the specification
- There is no specification of these versions: the archived specifications cover versions 7 and 8. This page is written from the decoder source (libmpcdec 1.2.6 for the ordinary streams;
mppdecoder.cppand the compiledmppdecoder.libof the 2000 library for the rest), and the viewer’s decoder agrees with those decoders: with libmpcdec sample by sample, and with the library (run through an emulator of its machine code) on every generated stream, in the bits of every frame and in the sound to within two steps of 16 bits. - libmpcdec 1.2.6 refuses constant bit rate streams, intensity stereo, block sizes above 1 and versions 1 to 3; the viewer reads them as the 2000 library does. The library ignores the frame count and the end of its file’s last whole 32-bit word decides where the frames stop; a frame that ends exactly on that word cannot be told from the end, and the viewer takes it as the end. It does not know the 11-bit sample count that stream 6 ends with.
- libmpcdec’s own identification of a stream is loose; the viewer’s rule above also checks the first block’s length (versions 4 to 6) or the file name (versions 1 to 3).
Sources
- libmpcdec 1.2.6 (
streaminfo.c, the header reader for versions 4 to 6;mpc_decoder.c, the frame reader, the end of stream and the resolution map;huffsv46.c, the Huffman tables), built with the old-version option. - The 2000 decoder library for Windows (
x-mpplib:mppdecoder.cpp, and the object code ofmppdecoder.lib, whose header routine gives Min_Band, Max_Band and the header layouts of versions 1 to 6, and whose frame reader gives the constant bit rate resolutions, intensity stereo and blocks), run in an emulator of the processor to produce reference output. - The Musepack decoder source revision 475 (
requant.c,synth_filter.c) for the requantisation constants and the filter bank shared by all versions. - Early Musepack encoder and decoder releases for Windows (archived downloads), which contain readme files and no stream files.