CopyBuffer doesn't work in a JUCE vst plugin


#1

Hi all!
I’ve learned the way of using more effects in parallel on a copy of the buffer and then turn back the copied buffer to the main buffer in an Audio App, but when I use this technique in an Audio Plugin, it doesn’t work:
here is my code:

class FilterDelay

{
public:

FilterDelay ()
{
    delay = stk::DelayL();
    delay.setMaximumDelay(44100);
}

void clear ()
{
    delay.clear();  
}

void process (AudioSampleBuffer& buffer, AudioSampleBuffer& delayBuffer)
{
    delay.setDelay(time);
    delay.setGain(feedback * mix);
    
    for (int i = 0; i < buffer.getNumSamples(); ++i)
    {
        float* buf = buffer.getWritePointer(0);
        float* delayBuf = delayBuffer.getWritePointer(0);
        
        float inBuf = buf[i];
        buf[i] += delayBuf[i];
        delayBuf[i] = delay.tick(delayBuf[i]) + inBuf;
    }
}

void setDelayTime (float value)
{
    time = value;
}

void setDelayFeedback (float value)
{
    feedback = value;
}

void setDelayMix (float value)
{
    mix = value;    
}

private:

// Delay
stk::DelayL delay;
float time, feedback, mix;

};

This is the effect class…
This is the code used inprepareToPlay:

fxBufferA.setSize(1, samplesPerBlock);
fxBufferA.clear();

delayBufferA.setSize(1, 12000);
delayBufferA.clear();

delayA = FilterDelay();
delayA.setDelayTime(atime);
delayA.setDelayFeedback(afeedback);
delayA.setDelayMix(amix);
delayA.clear();

And this is the code in processBlock:

auto numSamples = buffer.getNumSamples();

delayA.setDelayTime(atime);
delayA.setDelayFeedback(afeedback);
delayA.setDelayMix(amix);

fxBufferA.copyFrom(0, 0, buffer, 0, 0, numSamples);

delayA.process(fxBufferA, delayBufferA);

auto anglea = jmap(apan * 1.0, -1.0, 1.0, 0.0, float_Pi * 0.5);

buffer.copyFrom(0, 0, fxBufferA.getReadPointer(0), numSamples, std::cos(anglea));
buffer.copyFrom(1, 0, fxBufferA.getReadPointer(0), numSamples, std::sin(anglea));

This configuration produces a short noise and then silence…
Any idea?