# How to use dsp::Oversampling?

**URL:** <https://forum.juce.com/t/how-to-use-dsp-oversampling/48317>\
**Category:** Audio Plugins\
**Created:** [October 18, 2021, 5:22pm UTC](https://forum.juce.com/t/how-to-use-dsp-oversampling/48317 "2021-10-18T17:22:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vascofsantos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vascofsantos/32/12013_2.png) [@vascofsantos](https://forum.juce.com/u/vascofsantos)\
**Post date:** [October 18, 2021, 5:22pm UTC](https://forum.juce.com/t/how-to-use-dsp-oversampling/48317/1 "2021-10-18T17:22:38Z")

</div>

Hi!

I’m just starting with JUCE and I wanted to create a basic overdrive/distortion plugin just for learning.  
I got the basic functionality working, but now I’d like to apply the non-linear processing after oversampling the signal in order to attenuate aliasing.

I’m feeling a little confused about AudioBuffer vs AudioBlock and how to manage buffers at the various processing stages.

Are there any good examples and/or sources for information regarding this functionality?

Vasco.

---

<div class="post-metadata">

**Author:** ![SourGummi](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@SourGummi](https://forum.juce.com/u/SourGummi)\
**Post date:** [October 18, 2021, 6:47pm UTC](https://forum.juce.com/t/how-to-use-dsp-oversampling/48317/2 "2021-10-18T18:47:44Z")

</div>

> [@vascofsantos](#):
>
> I’m feeling a little confused about AudioBuffer vs AudioBlock and how to manage buffers at the various processing stages.

i’m also fairly new to juce so take anything i say with the smallest grain of salt.

as far as im aware, AudioBlock is just a light weight AudioBuffer that doesn’t own any memory from the original Buffer. Faster and easier.

again, as far as im aware, oversampling of x4 is just like using 48000 sample rate x4. so the new sample rate would be 192000. it processes the sample at the new rate then reverts back to 48000 and returns that.

[Oversampling](https://docs.juce.com/master/classdsp_1_1Oversampling.html#affb3eb18a1e9e8888338946ab0a98d55)

this is what i just tried, and im pretty sure it works because using a factor of 4 (which equates to 16x oversampling) my CPU usage goes up to about 10%.

**header file**

```auto
    using OS = juce::dsp::Oversampling<float>;
    OS oversample{ getTotalNumOutputChannels(), 4, OS::FilterType::filterHalfBandFIREquiripple };

```

**prepareToPlay**

```auto
    oversample.initProcessing(maximumBlockSize);

```

**process block**

```auto
    juce::dsp::AudioBlock<float> block(buffer);
    juce::dsp::ProcessContextReplacing<float> context(block);

    // before procesing
    oversample.processSamplesUp(context.getInputBlock());
    
    // processing
    //--------------------------------------------------

    // after processing
    oversample.processSamplesDown(context.getOutputBlock());

```

of course, i didnt actually do any processing but what i think needs to be done is _BEFORE_ you process anything you tell the oversampler to increase the rate by **x** then you process at the new rate, then you tell the oversampler to revert back to your original sample rate.

---

<div class="post-metadata">

**Author:** ![PluginPenguin](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/pluginpenguin/32/10203_2.png) [@PluginPenguin](https://forum.juce.com/u/PluginPenguin)\
**Post date:** [October 18, 2021, 9:27pm UTC](https://forum.juce.com/t/how-to-use-dsp-oversampling/48317/3 "2021-10-18T21:27:34Z")

</div>

You can take my open source guitar overdrive as an example. Here is a `dsp::Waveshaper` wrapped into an oversampling instance:

> <https://github.com/JanosGit/Schrammel_OJD/blob/develop/Source/Waveshaper.h>

---

<div class="post-metadata">

**Author:** ![vascofsantos](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/vascofsantos/32/12013_2.png) [@vascofsantos](https://forum.juce.com/u/vascofsantos)\
**Post date:** [October 19, 2021, 8:07am UTC](https://forum.juce.com/t/how-to-use-dsp-oversampling/48317/4 "2021-10-19T08:07:48Z")

</div>

Thank you @SourGummi and @PluginPenguin !  
You have been a great help!
