Multiple processors in one plugin, swap by choice


#1

If there can only be one plugin processor, If I wanted to implement an audio plugin which had an editor where you could select an effect(e.g distortion, tremolo…) and its processor would run what is the correct way to go about this?


#2

processblock(buffer, midimessages)
{
if (distortionOn)
distortionBox.processBlock(buffer);

if (tremoloOn)
tremoloBox.processBlock(buffer);

}

then just make a distortionBox class with a processBlock method and do your number crunching there, no need for multiple processors unless you need the fanciness it offers.


#3

But keep in mind that if you classes have any state (i.e. require memory allocation) then you should do this for both classes before you reach processBlock(). You can do it in the AudioProcessor constructor unless you need to know details like samplerate or expected blocks per sample, in which case you should do it in prepareToPlay().


#4

Yeah thats important

2 approaches:

prepareToPlay(sampleRate, samplesPerBlock)
{

ProcessorDetails::set(sampleRate, samplesPerBlock); //this should be a static thing

tremoloBox.prepareToPlay(sampleRate, samplesPerBlock); //direct set up

}

DistortionBox::processBlock()
{
const double sampleRate = ProcessorDetails::getSampleRate();
}

But your code must also handle changes inside its main process block, so make sure to check details and if necessary re-set the proper values.


#5

Yep, the blocklength may vary in processBlock(), but the sample rate will be fixed.

Also, the number of channels are available in prepareToPlay() by calling getTotalNumImputChannels() or getTotal NumOutputChannels() and that shouldn’t change in processBlock().