I’m trying to make a plugin which captures audio from the DAW and sends it to another standalone juce application which could capture the audio and then record it/play it in real time.
I have it “almost” working but I’m not sure this is correct. To summarize, I use the InterprocessConnection class to capture the audiobuffer at the end of the plugin processBlock and send it to the standalone which then takes the buffer and plays it in its own processBlock method.
In the plugin I do the following at the end of the processBlock method
WavAudioFormat format;
MemoryBlock memBlock;
{
std::unique_ptr<AudioFormatWriter> writer(format.createWriterFor(new MemoryOutputStream(memBlock, false), 48000, 1, 16, StringPairArray(), 0));
writer->writeFromAudioSampleBuffer(buffer, 0, buffer.getNumSamples());
}
processConnection->sendMessage(memBlock);
In the standalone app, if I receive a message and place it in a vector of memory blocks, and in the next iteration of processBlock I convert the message back into an AudioBuffer and add then add it to the buffer.
Converting memoryblock to audiobuffer
AudioBuffer<float> BcProcessConnection::getNextProcessBuffer()
{
AudioBuffer<float> buffer;
WavAudioFormat format;
if (memoryBlocks.size() > 0)
{
WavAudioFormat wavFormat;
std::unique_ptr<AudioFormatReader> reader(wavFormat.createReaderFor(
new MemoryInputStream(
memoryBlocks[0].getData(),
memoryBlocks[0].getSize(),
false),
true));
if (reader.get() != nullptr)
{
buffer.setSize(reader->numChannels, reader->lengthInSamples);
reader->read(&buffer, 0, reader->lengthInSamples, 0, true, true);
}
memoryBlocks.erase(memoryBlocks.begin());
}
return buffer;
}
Adding the audio data to the main buffer
if (processConnection != nullptr)
{
AudioBuffer<float> buf = processConnection->getNextProcessBuffer();
if (buf.getNumSamples() > 0)
{
buffer.addFromWithRamp(0,
0,
buf.getReadPointer(0, 0),
buf.getNumSamples(),
1,
1);
}
}
I get audio and this works but I can’t seem to process the messages fast, the samples are played out in basically super slow motion and my vector of memoryblocks keeps increasing.
Is there a way to achieve what I’m trying to do, or am I on the wrong path here?
EDIT
I’m close, I can almost smell the finish line… I changed the interprocessconnection to run on the audio thread which greatly reduced delay, there’s still a few milliseconds delay annoyingly but it’s very close. I’m not sure how I could possible sync up the clocks though, I feel like I’ll always be one or two processBlocks behind. The relay plugin would need to wait for the host to process it’s message or something.
