hmm, I just took all the file stuff out of AudioRecorder::startRecording method (I pre-create the file which is passed into the AudioRecorders RecOut::startRecording method when the channel you wish to record is selected) and it didn’t seem to get any better. Are you suggesting that I also somehow break out the code in RecOut::startRecording and RecOut::stop? There are maybe certain things I can preallocate, like the WavAudioFormat, but the rest seems that it needs to be created/deleted each time right…? Unless its fine to create the ThreadedWriter and everything (basically everything in RecOut::startRecording) once when the class is instantiated and just have a global bool in my audio callbacks that gets checked if its true or not before calling ThreadedWriter::write?
I’m refering to these methods…
void RecOut::startRecording (const File& file)
{
stop();
if (sampleRate > 0)
{
// Create an OutputStream to write to our destination file...
file.deleteFile();
ScopedPointer<FileOutputStream> fileStream (file.createOutputStream());
if (fileStream != 0)
{
// Now create a WAV writer object that writes to our output stream...
WavAudioFormat wavFormat;
AudioFormatWriter* writer = wavFormat.createWriterFor (fileStream, sampleRate, 1, 16, StringPairArray(), 0);
if (writer != 0)
{
fileStream.release(); // (passes responsibility for deleting the stream to the writer object that is now using it)
// Now we'll create one of these helper objects which will act as a FIFO buffer, and will
// write the data to disk on our background thread.
threadedWriter = new AudioFormatWriter::ThreadedWriter (writer, backgroundThread, 32768);
// And now, swap over our active writer pointer so that the audio callback will start using it..
const ScopedLock sl (writerLock);
activeWriter = threadedWriter;
}
}
}
}
and
[code]void RecOut::stop()
{
// First, clear this pointer to stop the audio callback from using our writer object…
{
const ScopedLock sl (writerLock);
activeWriter = 0;
}
// Now we can delete the writer object. It's done in this order because the deletion could
// take a little time while remaining data gets flushed to disk, so it's best to avoid blocking
// the audio callback while this happens.
threadedWriter = 0;
}[/code]