willfo
willfo

Reputation: 249

Delay playback of AudioSampleBuffer in Juce

I am writing a convolution reverb plugin and want to add a pre delay slider. I have the "Dry" signal and "Wet" signal in two separate buffers for playback as shown in the code below:

 // copy the original signal into a "dry signal" buffer that we'll use later
AudioSampleBuffer dryBuffer(buffer.getNumChannels(), buffer.getNumSamples());

// now apply convolution to the buffer
for (int i = 0; i < buffer.getNumChannels(); ++i)
{
    float* writePointer = buffer.getWritePointer (i % getNumOutputChannels());
    const float* readPointer = buffer.getReadPointer (i % getNumInputChannels());

    dryBuffer.copyFrom(
                       i, // destChannel
                       0, //destStartSample
                       buffer, // sourceBuffer
                       i, // sourceChannel
                       0, // sourceStartSample,
                       buffer.getNumSamples()
   );

    convolvers.getUnchecked(i % convolvers.size())->process (readPointer, writePointer, buffer.getNumSamples());

    //WET MIX
    buffer.applyGain(i, // channel
                     0, // startSample
                     buffer.getNumSamples(),
                     wetLevel->getValue() // gain
                     );

    //DRY MIX
    dryBuffer.applyGain(i,
                        0,
                        dryBuffer.getNumSamples(),
                        dryLevel->getValue()
                        );

    buffer.addFrom(
                   i, // destChannel
                   0, // destStartSample
                   dryBuffer, // sourceBuffer
                   i, // sourceChannel
                   0, // soucreStartSample,
                   buffer.getNumSamples(),
                   1.0 // gain
                   );


}

dryBuffer is the dry AudioSampleBuffer, and buffer is the wet signal with the convolution applied. How can I delay the playback of the wet buffer?

Upvotes: 0

Views: 1062

Answers (1)

yun
yun

Reputation: 1283

You could delay the wet buffer by moving its samples. For example if you want a 2 second delay you would want to increase the wet buffer by 2*sample_rate and move all the samples by sample_rate*2*delay_amt samples. You'll have to apply these changes in your convolvers->process method

Upvotes: 2

Related Questions