AudioFormatWriter ->write or ->writeFromAudioSampleBuffer


Hi, I taking inspiration from the JUCE recording tutorial I wrote this function for my class

void AudioRecorder::Record(const AudioSourceChannelInfo& bufferToFill, const File& file)
auto fileStream = std::unique_ptr (file.createOutputStream());
WavAudioFormat wavFormat;
auto writer = wavFormat.createWriterFor (fileStream.get(), sampleRate, 1, 16, {}, 0);

const auto numSamples = bufferToFill.buffer->getNumSamples();

AudioBuffer<float> toRecord;

toRecord.copyFrom(0, 0, *bufferToFill.buffer, 0, 0, numSamples);

if (writer)
    writer->writeFromAudioSampleBuffer(toRecord, bufferToFill.startSample, bufferToFill.numSamples);


However in the JUCE Demo it uses AudioFormatWriter::ThreadedWriter* in order to keep it Thread’Safe

My Question :

Is there a way to use “->writeFromAudioSampleBuffer” on a “AudioFormatWriter::ThreadedWriter*” (threadSafe pointer as the DEMOs show ), or

Is there a way to convert a buffer into InputChannelData so i can use activeWriter.load()->write (inputChannelData, numSamples); ?