Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Additional bit for 2nd channel's warm-up samples (Read 672 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Additional bit for 2nd channel's warm-up samples

Hi!
(FLAC newby here)
I'm working on my own FLAC decoder, and ran into something I can't quite understand. I'm trying to understand the following section (src/libFLAC/stream_decoder.c#L2057) of libFLAC:
Code: [Select]
case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
                FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
                if(channel == 1)
                    bps++;
I'm wondering why the warm-up samples for the 2nd channel are stored with an additional bit per sample compared to the 1st channel? I don't find any mention of this in the format spec - am I missing something?

Thanks :)

Re: Additional bit for 2nd channel's warm-up samples

Reply #1
See here: https://github.com/ietf-wg-cellar/flac-specification/blob/master/flac.md#interchannel-decorrelation

Quote
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.

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.
Music: sounds arranged such that they construct feelings.

Re: Additional bit for 2nd channel's warm-up samples

Reply #2
Ah, I see. Thanks a lot for the quick response :)

Re: Additional bit for 2nd channel's warm-up samples

Reply #3
If you find something else that isn't quite clear in the FLAC specification, please let me know, either through this topic or at github. An IETF working group intends to improve the FLAC spec (in wording, not by changing the FLAC format or anything), and they'd like as much input as they can get.

For example, perhaps you can look at these examples to see whether they are clear? https://github.com/ietf-wg-cellar/flac-specification/blob/27e4418776177df638125cccb585b473edebb091/rfc_backmatter.md There's no example yet about a side channel needing an extra bit, but it might still be a good read?
Music: sounds arranged such that they construct feelings.

 

Re: Additional bit for 2nd channel's warm-up samples

Reply #4
I'll have a look, and keep it mind going forward.