I’m working on a system that requires realtime encoding / decoding of compressed audio formats. This is to perform some analysis on the artefacts introduced by the encoding process.
My approach so far is to create an AudioFormatWriter and AudioFormatReader and to get the process up and running I’m using a WavAudioFormat reader and writer (to avoid any potential complications with compressed formats).
The wave file has a size of zero samples until the writer is flushed or destroyed.
This is, because the number of samples is written in the header at the end of writing, when the size is known.
But if you want it to run continuously, you need a format that allows streaming. Not sure, if there is any in JUCE…
Like I tried to explain before, the mOutputStream has the length of zero samples. You can verify that by stepping into the mReader.
Also, there is no need to call setPosition on the InputStream, once you handed it over to the AudioFormatReader. On the contrary, I guess it could blow the whole thing up.
You might be able to circumvent the problem by calling
mWriter->flush();
before creating the reader. Then it will see at least the already written few samples.
But the JUCE AudioFormatReaders will read the header only once, so even if you append samples later, the reader will see the input as exceeded and stop reading, producing silence.
That is what I tried to explain, when I said you would need a format, that allows streaming, i.e. not knowing what the size will be.
It has nothing to do with the encoding/compression of your data, it is usually a trait of the container.
This is for a system that compares the original uncompressed audio against various compressed formats like MP3, AAC, Ogg etc in real time.
I was looking for a way to encode to a compressed format and decode back to floating point in real-time so the WAV example was just to illustrate the write / reader approach I had in mind for a memory based real time process.
Sounds like I’ll need to use the encoder libraries directly.
Right, yes, for that you probably would need to go down to the underlying libraries. Although you might be able to bodge something by periodically calling flush() on the writer, and then creating a new reader to read from it. (IIRC the tracktion engine will call flush() every second or so, which means that even if something goes wrong, the file up to that point will be readable)