Hi all,
I’m encountering what seems to be a fairly common issue, though I’m at a loss as to how to solve it. I’ve already followed threads such as this to try to fix the problem, but no dice.
Here’s the high level flow of what I’m doing:
-
I have a
wetBufferthat I initialize inprepareToPlayto the size ofsamplesPerBlock. That means it’s possible for this to eclipse the size of the incomingbufferinprocessBlock. -
I have some DSP objects (namely some filters and a gain) in a
ProcessorChain, which processes thewetBufferexclusively. InprepareToPlayand everyprocessBlock, Ipreparethat DSPProcessorChainwith the incoming number of samples. -
I fill the
wetBufferwith the current number of incoming samples, create anAudioBlockof the proper size from it (usinggetSubBlock), and attempt to process the samples. In highly variable hosts like FL Studio, I’m getting a ton of noise here.
Here are some condensed code snippets:
void MyProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
bufferSampleNum = buffer.getNumSamples();
juce::dsp::ProcessSpec processSpec;
processSpec.maximumBlockSize = bufferSampleNum;
processSpec.sampleRate = sampleRate;
processSpec.numChannels = wetBuffer.getNumChannels();
wetProcessorChain.prepare(processSpec);
wetBuffer.clear();
... (fill wetBuffer with bufferSampleNum samples)
auto wetBlock = juce::dsp::AudioBlock<float> (wetBuffer).getSubBlock (0, bufferSampleNum);
juce::dsp::ProcessContextReplacing<float> wetContext (wetBlock);
wetProcessorChain.process(wetContext);
// Sum dry and wet buffers.
for (auto channel = 0; channel < wetBuffer.getNumChannels(); channel++)
buffer.addFrom(channel, 0, wetBuffer, channel, 0, bufferSampleNum);
}
Am I missing anything super obvious here? I’ve added some logs throughout processBlock and verified that the number of incoming samples == the maximumBlockSize of the DSP chain == the size of the wetBlock before processing == the size of the wetBlock after processing. I’ve also verified that the number of samples in wetBuffer is always >= the number of incoming samples.
If it’s relevant at all, my ProcessorChain is defined as this:
juce::dsp::ProcessorChain<juce::dsp::StateVariableTPTFilter<float>, juce::dsp::StateVariableTPTFilter<float>, juce::dsp::Gain<float>> wetProcessorChain;
