[Flac-dev] Feed decoder from c++ std::stream

Bastiaan Timmer basjetimmer at yahoo.com
Tue Aug 9 05:52:12 PDT 2011


Hi! I am working on an application that reads audio data from files, and runs it through some user defined filters. The filters basically all derive from some base filter and have methods start(), update() and finish(). The start routine performs any initialization required by the filter, and finish() does the clean up. In between, I simply read the file piece by piece into a buffer using std::ifstream.read(buffer, bufsize), and then call the filters update function with the buffer and the number of bytes read.

In this fashion I have implemented a WAV reader, WAV writer, MD5 summer, AccurateRip checker and a FLAC encoder and hope to implement MP3 and Vorbis encoders and any number of audio filters (gain/compression/etc). However, at the moment I'm stuck trying to write a FLAC decoder. It seems that the FLAC::Decoder module is incompatible with this approach as it insists on taking control of the data it receives through its read callback. Is this correct? Does anyone see any obvious way to do this?

I have only come up with one (slightly hacky) way to do this, but it requires to know the maximum frame size of the input file, which as I understand it, need not be set in the STREAMINFO, and has no theoretical maximum. So it works now, because I read the input file in 1MB chunks, and I have not come across a file with larger frames, but it is not guaranteed. Any ideas?

I hope that was somewhat clear, I'm finding it difficult to explain. Let me know if you need more clarification or some example code.

thanks,
Bas Timmer


More information about the Flac-dev mailing list