在Juce中延迟播放AudioSampleBuffer

时间:2016-03-17 14:20:11

标签: c++ audio buffer convolution juce

我正在编写一个卷积混响插件,并希望添加一个预延迟滑块。我在两个独立的缓冲区中有“干”信号和“湿”信号进行播放,如下面的代码所示:

 // 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是干燥的AudioSampleBuffer,缓冲区是湿信号,应用了卷积。如何延迟湿缓冲区的播放?

1 个答案:

答案 0 :(得分:2)

您可以通过移动样品来延迟湿缓冲液。例如,如果您希望延迟2秒,则需要将湿缓冲区增加2*sample_rate,并将所有样本移动sample_rate*2*delay_amt个样本。您必须在convolvers->process方法

中应用这些更改