Default plug-in processBlock comments

Hello,

Incoming noob question!

Starting out a new project and reading the comments in the processBlock method. (processBlock is a method of the PluginProcessor right?) Was wondering if someone could answer some qustions / comment on my thinking!

// Make sure to reset the state if your inner loop is processing
// the samples and the outer loop is handling the channels.
// Alternatively, you can process the samples with the channels
// interleaved by keeping the same state.

What’s the state it refers to?

Am I correct in thinking the alternatively part is saying instead of resetting the state you can do something like this?

for (int sample = 0; sample < buffer.getNumSamples(); sample++)
{
    for (int channel = 0; channel < totalNumInputChannels; ++channel)
    {
        auto* channelData = buffer.getWritePointer (channel);
        
        // ..do something to the data...
    }
}

But then do you want to be getting a new pointer to the sample array every sample? Feels wrong?

Cheers and thanks!

processBlock is a virtual method of AudioProcessor that your processor inherits from.

The “state” is whatever variables need to be retained for the audio channels. (The typical example would be a filter which has a history of the past audio samples and that needs to be independent for each audio channel.)

If you need to write your loop in the “alternative” way where the outer loop iterates the samples, it will maybe be a bit more efficient to do it this way :

auto channelDatas = buffer.getArrayOfWritePointers();
for (int sample = 0; sample < buffer.getNumSamples(); sample++)
{
    for (int channel = 0; channel < totalNumInputChannels; ++channel)
    {
        // ..do something to the data...
        // like : channelDatas[channel][sample] *= 0.5f;
    }
}
1 Like

Cool got it, will read up on virtual methods thanks.

That makes sense, I can see why you’d need to reset those.

Thanks for the suggestion of using .getArrayOfWritePointers()!

I believe the comment is there to warn newbies about the most common bug in developing plugins: #1 most common programming mistake that we see on the forum

1 Like

Gotcha, I’ve read through that post makes sense! I consider myself warned!