Porting the AudioRecordingDemo to a Plugin


#1

Hi,

I"m currently learning how to use JUCE and I wanted to use the audio recording functionality found in AudioRecordingDemo.cpp in a plugin environment, however I’m struggling to figure out how I would port this over.

When creating a new plugin project with Projucer, in the processBlock() there is the main for loop:

    // This is the place where you'd normally do the guts of your plugin's
    // audio processing...
    for (int channel = 0; channel < totalNumInputChannels; ++channel)
    {
        float* channelData = buffer.getWritePointer (channel);

        // ..do something to the data...
    }

Within the example, the closest thing I can find is:

    void audioDeviceIOCallback (const float** inputChannelData, int /*numInputChannels*/,
                                float** outputChannelData, int numOutputChannels,
                                int numSamples) override
    {
        const ScopedLock sl (writerLock);

        if (activeWriter != nullptr)
        {
            activeWriter->write (inputChannelData, numSamples);

            // Create an AudioSampleBuffer to wrap our incoming data, note that this does no allocations or copies, it simply references our input data
            const AudioSampleBuffer buffer (const_cast<float**> (inputChannelData), thumbnail.getNumChannels(), numSamples);
            thumbnail.addBlock (nextSampleNum, buffer, 0, numSamples);
            nextSampleNum += numSamples;
        }

        // We need to clear the output buffers, in case they're full of junk..
        for (int i = 0; i < numOutputChannels; ++i)
            if (outputChannelData[i] != nullptr)
                FloatVectorOperations::clear (outputChannelData[i], numSamples);
    }

It looks like in the AudioRecordingDemo, the activeWriter->write (inputChannelData, numSamples); bit is used to write the audio to the file. There is a numSamples parameter that I don’t think I see exposed in the Plugin interface.

Any pointers in the right direction would be really appreciated. Ultimately I just want to take the audio coming into the plugin and write it to a file (i.e. bounce the audio).

Thanks!
Tomek


#2

Many come here and ask this, because it seems to be the first thing to learn. But actually, a plugin is not meant to write or read audio files. The host does this.
The plugin receives audio, modifies it and sends it back into the track’s processing chain.

You can do that, but it is actually relatively hard to do, because you have to synchronise non-realtime processes like reading from or writing to disk to the realtime audio thread. It’s not the first thing worth learning…

If you still want to do that, for writing have a look at ThreadedWriter and BufferingAudioReader


#3

Thanks for the info, I’ll look into these two classes.

Yea as I’ve been digging more into plugins, I’ve been realizing how limited the capabilities are. Unfortunately, the use case I’m trying to develop requires bouncing a track into the plugin and sending it off to an external web service/API.