Just conditionally call it in your processBlock function (if you started recording via UI request to ‘start Recording’ with file) after generating your audio/after each block where you fill your output fifo if you have one.
I don’t remember if the original demo code was this way, but it may be more convenient to change the buffer format you have to pass in (this is how I have it, but copied that example a long time ago) - for example.
void processAudioInputBuffer (const AudioSourceChannelInfo& souceChannelInfo)
const ScopedLock sl (writerLock);
if (activeWriter != nullptr )
float** inputChannelData = souceChannelInfo.buffer->getArrayOfWritePointers();
activeWriter->write (inputChannelData, souceChannelInfo.numSamples);
nextSampleNum += souceChannelInfo.numSamples;
Make sure to add a prepare to play function that you call from Audio processor prepare to play - so that the sample rate is correct… and you probably need to stop the recording process if sample rate changes during a recording - add an extra stop recording call there maybe:
void prepareToPlay (float sampleRate_)
sampleRate = sampleRate_;
Not sure how safe it is to do the scoped writer lock in the processBlock callback () - maybe there is a cleaner way to manage that.