Hi There,
I’m having trouble using the juce::dsp::Convolution class, hopefully, someone here could help me.
The project is a plugin, and I encountered a problem when the host sample rate is changed. I created a test project to see if I still had the problem and yes.
The test project only has a convolver, I load a neutral (it doesn’t do anything) impulse response and process the buffer with it.
The impulse response is 44.1 kHz, and when I use the plugin using that sample rate, everything works perfectly. I have no gain either attenuation.
The problem starts when I change the sample rate from the host, then I have more gain as the sample rate increases: 44.1 kHz doesn’t add any gain, 48 kHz adds 0.7 dBs, 88.2 kHz adds 4 dBs, 96k kHz adds 4.7 dBs, 176.4 kHz adds 8.9 dBs, and 192 kHz adds 9.6 dBs.
As long as I understand the problem is in the resampling function that loadImpulseResponse uses. It calls resampleImpulseResponse that uses a ResamplingAudioSource to resample the impulse response.
The discrete-time signal theory says that the resampling process does change the amplitude of our signal, but the factor can be calculated and compensated to have the same signal. Maybe that step is missing in the JUCE implementation? I wasn’t able to see that. But probably I’m missing something or doing something wrong.
The test project I did is:
in the pluginProcessor.h
private:
juce::dsp::Convolution convolver;
in the pluginProcessor.cpp
void test::prepareToPlay (double sampleRate, int samplesPerBlock){
DBG(“---------- prepare to play --------------\n”);juce::dsp::ProcessSpec spec; spec.sampleRate = sampleRate; spec.maximumBlockSize = (juce::uint32)samplesPerBlock; spec.numChannels = (juce::uint32) juce::jmax (getTotalNumInputChannels(), getTotalNumOutputChannels()); convolver.reset(); convolver.prepare(spec); convolver.loadImpulseResponse(BinaryData::neutral_wav, BinaryData::neutral_wavSize, juce::dsp::Convolution::Stereo::no, juce::dsp::Convolution::Trim::no,0, juce::dsp::Convolution::Normalise::no);
}
void test::processBlock (juce::AudioBuffer& buffer, juce::MidiBuffer& midiMessages)
{
juce::ScopedNoDenormals noDenormals;
auto totalNumInputChannels = getTotalNumInputChannels();
auto totalNumOutputChannels = getTotalNumOutputChannels();for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i) buffer.clear (i, 0, buffer.getNumSamples()); const auto numChannels = juce::jmax (totalNumInputChannels, totalNumOutputChannels); auto inoutBlock = juce::dsp::AudioBlock<float> (buffer).getSubsetChannelBlock (0, (size_t) numChannels); convolver.process(juce::dsp::ProcessContextReplacing<float> (inoutBlock));
}
Thanks for your time! And sorry in advance If my English is not the clearest one