Re: [LAD] (libsndfile) FLAC format question

From: Erik de Castro Lopo <mle+la@email-addr-hidden-nerd.com>
Date: Wed Nov 06 2013 - 00:18:55 EET

hermann meyer wrote:

> I would save a internal audio buffer to file on exit, to reuse it after
> e new start.
> Currently I use stdio fopen/fwrite/fread and save the binary data from
> the array.
> That works well.
>
> Now I've started to play with libsndfile, first I use SF_FORMAT_WAV |
> SF_FORMAT_FLOAT which work as nice as stdio. The file size is the same
> then with plain binary data.
>
> To save some bytes on the disk I tried SF_FORMAT_FLAC | SF_FORMAT_PCM_24
> which reduce the size nearly to the half. The drawback is that the
> floats in the internal buffer could go out of the range from -1.0 <->
> 1.0 which leads to crackles when the buffer get refiled. As long the
> values are in range, flac works very well.

Yes, and so it should.

> I tried it with the sf_command (sndfile, SFC_SET_NORM_FLOAT, NULL, SF_TRUE)
> for write and read, but that didn't help.

No, it won't.

What you need to do is scale your data to the range [-1.0, 1.0] before
you write it to the file.

> Yes, I use sf_write_float to write/read the flac file, even if flac
> didn't support floats. When I understand the libsndfile api right,
> libsndfile will handle that.

Yes, that is correct.

> So my quetion will be, which is the common format to write flac file
> with libsndfile,

Writing float is fine, you just need to ensure that the data is in
range [-1.0, 1.0] first.

> and is there a way to write values out of range into a
> flac file?

No, there isn't.

Erik

-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Wed Nov 6 04:15:01 2013

This archive was generated by hypermail 2.1.8 : Wed Nov 06 2013 - 04:15:01 EET