I'm trying to understand the following section (link) of libFLAC
case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
if(channel == 1)
bps++;
Why are the warm-up samples for the 2nd channel stored with an additional bit-per-sample compare to the 1st channel? Also, I don't find any mention of this in the format spec - am I missing something?
I also asked on hydrogenaudio, and got an answer there: https://hydrogenaud.io/index.php?topic=121900.0
From the spec (not the one on xiph.org):
The side channel needs one extra bit of bit depth as the subtraction can produce sample values twice as large as the maximum possible in any given bit depth. The mid channel in mid-side stereo does not need one extra bit, as it is shifted left one bit. The left shift of the mid channel does not lead to non-lossless behavior, because an uneven sample in the mid subframe must always be accompanied by a corresponding uneven sample in the side subframe, which means the lost least significant bit can be restored by taking it from the sample in the side subframe.
And from user ktf:
Simply put: if you have 8-bit audio, and the left sample is +127 and the right sample -128, the diff channel becomes 127 - -128 = 255. So, you need 9 bits to code for that number.