[LAD] (libsndfile) FLAC format question

Erik de Castro Lopo mle+la at mega-nerd.com
Tue Nov 5 22:18:55 UTC 2013


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/


More information about the Linux-audio-dev mailing list