Hello! I am running into an issue where using oversampling seems to introduce random spikes in amplitude for single samples (this does not happen when not using oversampling). I tried upgrading to Juce 7 and have created a simple test file to demonstrate. I am guessing that I am using the oversampler incorrectly?
I would upload the example file, but I am not allowed to attach yet in the forum. Thanks!
That’s not required with the oversampler, it can deal with stereo and more channels internally. But it of course needs to be initialized to use the needed number of channels.
From the docs :
A processor that performs multi-channel oversampling.
That’s what I use on all of our products, without suffering these spikes.
In PluginProcessor.h, we have the oversampler as a private member:
std::unique_ptr<dsp::Oversampling> oversampling;
Then, PluginProcessor.cpp:
In the constructor:
oversampling.reset (new dsp::Oversampling (2, log2(2), dsp::Oversampling::filterHalfBandPolyphaseIIR, false)); //change log2(2) with your oversampling factor
In prepareToPlay:
oversampling->initProcessing(static_cast<size_t> (samplesPerBlock));
In process(dsp::ProcessContextReplacing context):
ScopedNoDenormals noDenormals;
auto&& inBlock = context.getInputBlock();
auto&& outBlock = context.getOutputBlock();
jassert (inBlock.getNumChannels() == outBlock.getNumChannels());
jassert (inBlock.getNumSamples() == outBlock.getNumSamples());
auto numSamples = inBlock.getNumSamples();
auto numChannels = inBlock.getNumChannels();
// Upsampling
dsp::AudioBlock<float> oversampledBlock;
setLatencySamples (audioCurrentlyOversampled ? roundToInt (oversampling->getLatencyInSamples()) : 0);
// Upsampling
if (audioCurrentlyOversampled)
{
oversampledBlock = oversampling->processSamplesUp (context.getInputBlock());
}
auto pluginContext = audioCurrentlyOversampled ? dsp::ProcessContextReplacing<float> (oversampledBlock)
: context;
auto&& plugInBlock = pluginContext.getInputBlock();
auto&& plugOutBlock = pluginContext.getOutputBlock();
jassert (plugInBlock.getNumChannels() == plugOutBlock.getNumChannels());
jassert (plugInBlock.getNumSamples() == plugOutBlock.getNumSamples());
numSamples = plugInBlock.getNumSamples();
numChannels = plugInBlock.getNumChannels();
const bool isMono = numChannels == 1;
const bool isStereo = numChannels > 1;
//Plugin Processing
for (size_t chan = 0; chan < numChannels; ++chan)
{
for (size_t i = 0; i < numSamples; ++i)
{
const float nrDry = plugInBlock.getChannelPointer(chan)[i];
//my dsp process goes here
plugOutBlock.getChannelPointer(chan)[i] = blabla; //my dsp process output goes in the out block here
}
}
// Downsampling
if (audioCurrentlyOversampled)
oversampling->processSamplesDown (context.getOutputBlock());
}
Just out of the blue, the signal after oversampling, especially after using IIR filters (which also move the phase) might look ripply, but could be correct. In the values you provided in the first post I can’t see a spike (did not check the file which you have provided)