JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::dsp::Oversampling< SampleType > Class Template Reference

A processing class performing multi-channel oversampling. More...

#include <juce_Oversampling.h>

Collaboration diagram for juce::dsp::Oversampling< SampleType >:

Public Types

enum  FilterType {
  filterHalfBandFIREquiripple = 0,
  filterHalfBandPolyphaseIIR,
  numFilterTypes
}
 The type of filter that can be used for the oversampling processing. More...
 

Public Member Functions

 Oversampling (size_t numChannels, size_t factor, FilterType type, bool isMaxQuality=true)
 Constructor of the oversampling class. More...
 
 Oversampling (size_t numChannels=1)
 Default constructor of the oversampling class, which can be used to create an empty object and then add the appropriate stages. More...
 
 ~Oversampling ()
 Destructor. More...
 
void addDummyOversamplingStage ()
 
void addOversamplingStage (FilterType, float normalizedTransitionWidthUp, float stopbandAttenuationdBUp, float normalizedTransitionWidthDown, float stopbandAttenuationdBDown)
 
void clearOversamplingStages ()
 
SampleType getLatencyInSamples () noexcept
 Returns the latency in samples of the whole processing. More...
 
size_t getOversamplingFactor () noexcept
 Returns the current oversampling factor. More...
 
void initProcessing (size_t maximumNumberOfSamplesBeforeOversampling)
 Must be called before any processing, to set the buffer sizes of the internal buffers of the oversampling processing. More...
 
void processSamplesDown (dsp::AudioBlock< SampleType > &outputBlock) noexcept
 Must be called to perform the downsampling, after the upsampling and the non-linear processing. More...
 
dsp::AudioBlock< SampleType > processSamplesUp (const dsp::AudioBlock< SampleType > &inputBlock) noexcept
 Must be called to perform the upsampling, prior to any oversampled processing. More...
 
void reset () noexcept
 Resets the processing pipeline, ready to oversample a new stream of data. More...
 

Public Attributes

size_t factorOversampling = 1
 
size_t numChannels = 1
 

Private Attributes

bool isReady = false
 
OwnedArray< OversamplingStage > stages
 

Detailed Description

template<typename SampleType>
class juce::dsp::Oversampling< SampleType >

A processing class performing multi-channel oversampling.

It can be configured to do 2 times, 4 times, 8 times or 16 times oversampling using a multi-stage approach, either polyphase allpass IIR filters or FIR filters for the filtering, and reports successfully the latency added by the filter stages.

The principle of oversampling is to increase the sample rate of a given non-linear process, to prevent it from creating aliasing. Oversampling works by upsampling N times the input signal, processing the upsampling signal with the increased internal sample rate, and downsample the result to get back the original processing sample rate.

Choose between FIR or IIR filtering depending on your needs in term of latency and phase distortion. With FIR filters, the phase is linear but the latency is maximum. With IIR filtering, the phase is compromised around the Nyquist frequency but the latency is minimum.

See also
FilterDesign.

{DSP}

Member Enumeration Documentation

◆ FilterType

template<typename SampleType >
enum juce::dsp::Oversampling::FilterType

The type of filter that can be used for the oversampling processing.

Enumerator
filterHalfBandFIREquiripple 
filterHalfBandPolyphaseIIR 
numFilterTypes 

Constructor & Destructor Documentation

◆ Oversampling() [1/2]

template<typename SampleType >
juce::dsp::Oversampling< SampleType >::Oversampling ( size_t  numChannels,
size_t  factor,
FilterType  type,
bool  isMaxQuality = true 
)

Constructor of the oversampling class.

All the processing parameters must be provided at the creation of the oversampling object.

Note: You might want to create a class inheriting from Oversampling with a different constructor if you need more control on what happens in the process.

Parameters
numChannelsthe number of channels to process with this object
factorthe processing will perform 2 ^ factor times oversampling
typethe type of filter design employed for filtering during oversampling
isMaxQualityif the oversampling is done using the maximum quality, the filters will be more efficient, but the CPU load will increase as well

◆ Oversampling() [2/2]

template<typename SampleType >
juce::dsp::Oversampling< SampleType >::Oversampling ( size_t  numChannels = 1)
explicit

Default constructor of the oversampling class, which can be used to create an empty object and then add the appropriate stages.

◆ ~Oversampling()

template<typename SampleType >
juce::dsp::Oversampling< SampleType >::~Oversampling ( )

Destructor.

Member Function Documentation

◆ addDummyOversamplingStage()

template<typename SampleType >
void juce::dsp::Oversampling< SampleType >::addDummyOversamplingStage ( )

◆ addOversamplingStage()

template<typename SampleType >
void juce::dsp::Oversampling< SampleType >::addOversamplingStage ( FilterType  ,
float  normalizedTransitionWidthUp,
float  stopbandAttenuationdBUp,
float  normalizedTransitionWidthDown,
float  stopbandAttenuationdBDown 
)

◆ clearOversamplingStages()

template<typename SampleType >
void juce::dsp::Oversampling< SampleType >::clearOversamplingStages ( )

◆ getLatencyInSamples()

template<typename SampleType >
SampleType juce::dsp::Oversampling< SampleType >::getLatencyInSamples ( )
noexcept

Returns the latency in samples of the whole processing.

Use this information in your main processor to compensate the additional latency involved with the oversampling, for example with a dry / wet functionality, and to report the latency to the DAW.

Note: The latency might not be integer, so you might need to round its value or to compensate it properly in your processing code.

◆ getOversamplingFactor()

template<typename SampleType >
size_t juce::dsp::Oversampling< SampleType >::getOversamplingFactor ( )
noexcept

Returns the current oversampling factor.

◆ initProcessing()

template<typename SampleType >
void juce::dsp::Oversampling< SampleType >::initProcessing ( size_t  maximumNumberOfSamplesBeforeOversampling)

Must be called before any processing, to set the buffer sizes of the internal buffers of the oversampling processing.

◆ processSamplesDown()

template<typename SampleType >
void juce::dsp::Oversampling< SampleType >::processSamplesDown ( dsp::AudioBlock< SampleType > &  outputBlock)
noexcept

Must be called to perform the downsampling, after the upsampling and the non-linear processing.

The output signal is probably delayed by the internal latency of the whole oversampling behaviour, so don't forget to take this into account.

◆ processSamplesUp()

template<typename SampleType >
dsp::AudioBlock<SampleType> juce::dsp::Oversampling< SampleType >::processSamplesUp ( const dsp::AudioBlock< SampleType > &  inputBlock)
noexcept

Must be called to perform the upsampling, prior to any oversampled processing.

Returns an AudioBlock referencing the oversampled input signal, which must be used to perform the non-linear processing which needs the higher sample rate. Don't forget to set the sample rate of that processing to N times the original sample rate.

◆ reset()

template<typename SampleType >
void juce::dsp::Oversampling< SampleType >::reset ( )
noexcept

Resets the processing pipeline, ready to oversample a new stream of data.

Member Data Documentation

◆ factorOversampling

template<typename SampleType >
size_t juce::dsp::Oversampling< SampleType >::factorOversampling = 1

◆ isReady

template<typename SampleType >
bool juce::dsp::Oversampling< SampleType >::isReady = false
private

◆ numChannels

template<typename SampleType >
size_t juce::dsp::Oversampling< SampleType >::numChannels = 1

◆ stages

template<typename SampleType >
OwnedArray<OversamplingStage> juce::dsp::Oversampling< SampleType >::stages
private

The documentation for this class was generated from the following file: