Load impulse response from existing audio buffer for dsp::Convolution

Hi,
I’m working on dsp::Convolution and I want to use a pre-defined vector of float for testing. All codes are inside the prepareToPlay function.

convBuffer.setSize(1, 300);
/* assign values to convBuffer... */

conv.reset();
conv.prepare(spec);
conv.loadImpulseResponse(
        &convBuffer,
        spec.sampleRate,
        dsp::Convolution::Stereo::yes,
        dsp::Convolution::Trim::no,
        0,
        dsp::Convolution::Normalise::no);

However, I got the jassert error.

void ResamplingAudioSource::setResamplingRatio (const double             
samplesInPerOutputSample)
{
    jassert (samplesInPerOutputSample > 0); // comes from here...

    const SpinLock::ScopedLockType sl (ratioLock);
    ratio = jmax (0.0, samplesInPerOutputSample);
}

I also read the doc.
https://docs.juce.com/master/classdsp_1_1Convolution.html#add9aaabf3c0211a00f7533dd3951069f
But still have no idea how to use it…

I think I made the wrong function call. But how to fix it?
Thank you!

I think you may be accidentally calling the overload of loadImpulseResponse which takes a const void* parameter instead of an AudioBuffer<float>&&.

You can call the correct overload by moving the buffer:

AudioBuffer<float> convBuffer;
convBuffer.setSize (1, 300);

conv.loadImpulseResponse (std::move (convBuffer),
                          spec.sampleRate,
                          dsp::Convolution::Stereo::yes,
                          dsp::Convolution::Trim::no,
                          0,
                          dsp::Convolution::Normalise::no);
conv.prepare (spec);
1 Like

It works!

Thank you.