# Help with dsp::oversampling

**URL:** <https://forum.juce.com/t/help-with-dsp-oversampling/50163>\
**Category:** Audio Plugins\
**Created:** [February 13, 2022, 7:14pm UTC](https://forum.juce.com/t/help-with-dsp-oversampling/50163 "2022-02-13T19:14:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dylanjrodan](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@dylanjrodan](https://forum.juce.com/u/dylanjrodan)\
**Post date:** [February 13, 2022, 7:14pm UTC](https://forum.juce.com/t/help-with-dsp-oversampling/50163/1 "2022-02-13T19:14:59Z")

</div>

I am making a fairly generic audio plugin, writing some of my own dsp functions as a way of learning them. Having some issues with the oversampling class that must be from a misunderstanding on my end on how data is organized by audioblock.

I construct the oversampler in the header file of the PluginProcessor

```auto
juce::dsp::Oversampling<float> oversampling{ getTotalNumOutputChannels(), 1, juce::dsp::Oversampling<float>::FilterType::filterHalfBandFIREquiripple, false, true};

```

in prepareToPlay

```auto
int numChannels = getNumInputChannels();

    oversampling.numChannels = getTotalNumInputChannels();
    oversampling.initProcessing(samplesPerBlock);
    oversampling.reset();
    float oversampledRate = sampleRate * 2.0;

    setLatencySamples(oversampling.getLatencyInSamples());

```

Finally in processBlock

```auto
juce::dsp::AudioBlock<float> block(buffer);
    auto oversampledBlock = oversampling.processSamplesUp(block);
    int numSamples = oversampledBlock.getNumSamples() / 2;

for (int channel = 0; channel < totalNumInputChannels; ++channel)
    {
        auto* channelData = oversampledBlock.getChannelPointer(channel);

        dspFunction.processBlock(channelData, numSamples, channel);
    }

oversampling.processSamplesDown(block);

```

This results in, I think, every other block being processed? Which sounds like an issue with numSamples but when I get rid of that division, the plugin immediately crashes.

This is my first post so hopefully my formatting is right and I’ve included enough information

---

<div class="post-metadata">

**Author:** ![duvrin](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@duvrin](https://forum.juce.com/u/duvrin)\
**Post date:** [February 13, 2022, 11:00pm UTC](https://forum.juce.com/t/help-with-dsp-oversampling/50163/2 "2022-02-13T23:00:29Z")

</div>

I don’t see why you would need to divide `numSamples`. Perhaps something is wrong with your dspFunction?  
Have a look at DSPModulePluginDemo. Look for the oversampling example in `DistortionProcessor`.

---

<div class="post-metadata">

**Author:** ![dylanjrodan](https://avatars.discourse-cdn.com/v4/letter/d/35a633/32.png) [@dylanjrodan](https://forum.juce.com/u/dylanjrodan)\
**Post date:** [February 14, 2022, 12:26am UTC](https://forum.juce.com/t/help-with-dsp-oversampling/50163/3 "2022-02-14T00:26:18Z")

</div>

Hey thank you for checking out my code and issue. Honestly the confidence boost from nothing immediately visibly being wrong had me go through and comment everything out then slowly add in functions trying to find if there was a specific function causing issue.

My implementation was fine, the issue I was running into was the juce reverb algorithm was after the oversampling, but still being fed an incorrect numSamples. Giving it the regular sampling rate amount of samples per block solved my issue.
