texdr.aft
texdr.aft

Reputation: 274

What is the purpose of the “wasted bits-per-sample” in the FLAC audio format?

I am looking into implementing a FLAC decoder. One part of the specification of the SUBFRAME_HEADER is unclear to me.

<1+k> 'Wasted bits-per-sample flag':

  • 0 : no wasted bits-per-sample in source subblock, k=0
  • 1 : k wasted bits-per-sample in source subblock, k-1 follows, unary coded; e.g. k=3 => 001 follows, k=7 => 0000001 follows.

(Here the “<1+k>” designates the size of the field/block.)

This is the only place in the specification that the value k is mentioned. What is its purpose, and how should it be interpreted? I don't find the term “wasted bits-per-sample” to be very meaningful. The hyphenation implies to me that it is not referring to “wasted bits”, but rather referring to “wasted values of bits-per-sample”; however, I don't understand why such a quantity is useful information.

Upvotes: 0

Views: 312

Answers (1)

ktmf
ktmf

Reputation: 423

Certain file formats, like AIFF, store 14-bit audio as left-justified 16-bit audio padded with zeros. The FLAC format compressed this by setting the sample size in bits to 16, but setting wasted bits to 2. When a subframe has bits per sample set to 16 but has wasted bits set to 2, the rest of the subframe is to be decoded as 14 bit, and has to be padded back to 16 bits.

In other words the flag says: this audio stream says it has a bitdepth of 16, but the least significant k bits are 0 everywhere, in other words, they are not used/wasted. So, this subframe is coded as (16-k) bits and you have to add k bits of padding to get the original back.

Besides its use to efficiently compress audio that has samples with a bitdepth other than 8, 16 or 24 bits padded to whole byte samplesizes, some tools use it to do some form of lossy compression, by selectively decreasing the bitdepth of audio. This has also been done with some DVD-Audio. See this forum thread for more information

Upvotes: 1

Related Questions