[Ffmpeg-devel] Does FLAC decoder support 24-bit files?

Dave Chapman dave
Wed Oct 26 01:14:08 CEST 2005


Mike Melanson wrote:
> Dave Chapman wrote:
> 
>> Just to clarify, my question was about the FLAC decoder itself, rather
>> than ffmpeg.  I've built my own decoder around the flac.c file - using
>> my own FLAC parser and the bare minimum of support functions from ffmpeg
>> (namely the bitreading and golomb routines).
>>
>> So I'm simply asking if flac.c itself (which decodes the data into
>> 32-bit ints) is known to be able to handle 24-bit audio.
> 
> 
>     A quick tour through the flac.c source code indicates that it is
> aware of 20- and 24-bit depths (in addition to 8, 12, and 16); this is
> evidenced by sample_size_table[]. While the data is decoded an array of
> signed 32-bit numbers (int32_t *decoded[MAX_CHANNELS]), the final
> samples are stuffed into signed 16-bit numbers in flac_decode_frame(). I
> imagine that the truncating behavior is not correct in this case.

Yes, that's definitely wrong.  For ffmpeg, the data should be shifted
appropriately.

>     If you are in the hacking mood, you could try modifying the relevant
> code starting around line 722 ("switch(s->decorrelation)"). Find the
> channel case that represents your files and if s->curr_bps is 20 or 24,
> appropriately reduce of the precision of the samples from s->decoded[][].

The first thing I did when extracting flac.c from ffmpeg was to modify
that part of flac_decode_frame so that it keeps the samples as 32-bit
integers (storing the output in the same s->decoded[][] arrays).

But I've now found the problem - it's an overflow in the
decode_subframe_lpc() function.

Fixing that problem (I'll try and post a patch later, but basically, you
need a second version of the main loop in that function - with sum a
64-bit int, and cast the two values in the multiplication to 64-bit as
well).  With that change, I am now getting bit-perfect 24-bit output
from the ffmpeg FLAC decoder.

Thanks,

Dave.





More information about the ffmpeg-devel mailing list