Re: Crash when writing 32bit flac files, am I doing something wrong ?

lvqcl <[email protected]>
Newsgroups gmane.comp.audio.compression.flac.devel
Message-ID <CAC1tzki060cFNn239BotL818jEUdUxhOfinSzDn++GGAA2iJ3Q@mail.gmail.com>
On Thu, Mar 22, 2018 at 3:41 AM, Stéphane Damo <[email protected]> wrote:
> Hello,
>
> I manage to successfully write 8, 16 and 24 bit, all stereo, FLAC files. But
> when I try to write 32 bit FLACs my program crashes.
>
> FLAC__stream_encoder_set_bits_per_sample is called to match the desired bit
> depth (8, 16, 24, 32)
>
> It's the same code for all bit depths, i provide a fixed-size signed int
> buffer to the lib (size=16384), with values with appropriate ranges for each
> bit depth (-128...+127 for 8 bit, etc.).
>
> The crash happens in stream_encoder.c line 2263 :
>
> encoder->private_->integer_signal[channel][i] = buffer[k++];
>
> It happens when I call FLAC__stream_encoder_process_interleaved(encoder,
> out, 16384/2) in my code. Its working perfectly for all bit depth except 32
> bit.
>
>
> Output message: Unhandled exception at 0x00F98441 in fmcomposer.exe:
> 0xC0000005: Access violation writing location 0x00000000.
>
>
> I'm using the latest code from the github repository. Reading the docs
> didn't noticed any thing special to do for writing 32 bit FLACs, it seems it
> should be supported. Maybe I am missing something ?

AFAIK: while FLAC format itself supports 32-bit PCM, the official
encoder doesn't support it.

from include/FLAC/format.h:


/** The maximum sample resolution permitted by the format. */
#define FLAC__MAX_BITS_PER_SAMPLE (32u)

/** The maximum sample resolution permitted by libFLAC.
 *
 * \warning
 * FLAC__MAX_BITS_PER_SAMPLE is the limit of the FLAC format.  However,
 * the reference encoder/decoder is currently limited to 24 bits because
 * of prevalent 32-bit math, so make sure and use this value when
 * appropriate.
 */
#define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)

also, init_stream_internal_() function already checks bit depth:

    if(encoder->protected_->bits_per_sample <
FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample >
FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
        return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;


so, maybe you forgot to check return value for errors?
_______________________________________________
flac-dev mailing list
[email protected]
http://lists.xiph.org/mailman/listinfo/flac-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.