DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::Oversampling< T, MaxChannels > Class Template Reference

Power-of-two oversampling processor with polyphase anti-aliasing. More...

#include <Oversampling.h>

Public Types

enum class  Quality { Low , Medium , High , Maximum }
 Quality presets defining the steepness and rejection of the anti-aliasing filter. More...
 

Public Member Functions

 Oversampling (int factor=2, Quality quality=Quality::High)
 Constructs the oversampling engine.
 
void prepare (const AudioSpec &spec)
 Pre-allocates buffers and computes FIR filter coefficients.
 
void reset () noexcept
 Flushes all internal delay lines and history buffers. Call this when resetting the transport or to clear audio tails.
 
int getFactor () const noexcept
 Returns the current oversampling factor.
 
Quality getQuality () const noexcept
 Returns the current quality preset.
 
int getLatency () const noexcept
 Calculates the exact group delay latency of the oversampling chain.
 
AudioBufferView< T > upsample (AudioBufferView< const T > input) noexcept
 Upsamples the input base-rate signal into the internal high-rate buffer.
 
void downsample (AudioBufferView< T > output) noexcept
 Downsamples the internal high-rate buffer back to base-rate.
 

Detailed Description

template<typename T, int MaxChannels = 16>
class dspark::Oversampling< T, MaxChannels >

Power-of-two oversampling processor with polyphase anti-aliasing.

Usage is a paired streaming operation per audio callback:

auto up = os.upsample(block); // 1. base rate -> high rate
process(up); // 2. nonlinear processing at the high rate
os.downsample(block); // 3. high rate -> base rate, in place
Note
upsample() and downsample() form a pair: downsample() consumes the high-rate samples the most recent upsample() left in the internal buffer, so call them once each per block, with the same block length.

Threading: prepare() and reset() belong to the setup thread (prepare allocates). upsample() and downsample() belong to the audio thread and are noexcept and allocation-free. There are no runtime setters – factor and quality are fixed at construction and all filter state is only touched by the audio thread – so no cross-thread synchronisation is needed.

Template Parameters
TSample type (float or double).
MaxChannelsMaximum number of channels supported.

Definition at line 67 of file Oversampling.h.

Member Enumeration Documentation

◆ Quality

template<typename T , int MaxChannels = 16>
enum class dspark::Oversampling::Quality
strong

Quality presets defining the steepness and rejection of the anti-aliasing filter.

Enumerator
Low 

31 taps/stage, ~-40 dB stopband. For fast previewing.

Medium 

63 taps/stage, ~-60 dB stopband. General purpose.

High 

127 taps/stage, ~-80 dB stopband. Professional standard.

Maximum 

255 taps/stage, ~-100 dB stopband. Mastering grade.

Definition at line 73 of file Oversampling.h.

Constructor & Destructor Documentation

◆ Oversampling()

template<typename T , int MaxChannels = 16>
dspark::Oversampling< T, MaxChannels >::Oversampling ( int  factor = 2,
Quality  quality = Quality::High 
)
inlineexplicit

Constructs the oversampling engine.

Parameters
factorOversampling factor. Must be a power of two (1, 2, 4, 8, 16).
qualityFilter quality preset. Default is High (-80 dB).
Precondition
factor >= 1 and is a power of 2.
Note
Release builds normalise an invalid factor into range and round it down to a power of two (debug builds assert).

Definition at line 89 of file Oversampling.h.

Member Function Documentation

◆ downsample()

template<typename T , int MaxChannels = 16>
void dspark::Oversampling< T, MaxChannels >::downsample ( AudioBufferView< T >  output)
inlinenoexcept

Downsamples the internal high-rate buffer back to base-rate.

Consumes the high-rate samples written by the most recent upsample() (and modified in place by the caller in between).

Parameters
outputBuffer view where the base-rate samples will be written. Use the same block length as the paired upsample() input.
Note
Real-time safe.

Definition at line 212 of file Oversampling.h.

◆ getFactor()

template<typename T , int MaxChannels = 16>
int dspark::Oversampling< T, MaxChannels >::getFactor ( ) const
inlinenoexcept

Returns the current oversampling factor.

Definition at line 142 of file Oversampling.h.

◆ getLatency()

template<typename T , int MaxChannels = 16>
int dspark::Oversampling< T, MaxChannels >::getLatency ( ) const
inlinenoexcept

Calculates the exact group delay latency of the oversampling chain.

Returns
Latency in samples at the BASE (1x) sample rate.

Definition at line 151 of file Oversampling.h.

◆ getQuality()

template<typename T , int MaxChannels = 16>
Quality dspark::Oversampling< T, MaxChannels >::getQuality ( ) const
inlinenoexcept

Returns the current quality preset.

Definition at line 145 of file Oversampling.h.

◆ prepare()

template<typename T , int MaxChannels = 16>
void dspark::Oversampling< T, MaxChannels >::prepare ( const AudioSpec spec)
inline

Pre-allocates buffers and computes FIR filter coefficients.

Parameters
specThe audio specification at the base (1x) sample rate.
Postcondition
The processor is ready to handle up to spec.maxBlockSize base samples.

Definition at line 112 of file Oversampling.h.

◆ reset()

template<typename T , int MaxChannels = 16>
void dspark::Oversampling< T, MaxChannels >::reset ( )
inlinenoexcept

Flushes all internal delay lines and history buffers. Call this when resetting the transport or to clear audio tails.

Definition at line 134 of file Oversampling.h.

◆ upsample()

template<typename T , int MaxChannels = 16>
AudioBufferView< T > dspark::Oversampling< T, MaxChannels >::upsample ( AudioBufferView< const T >  input)
inlinenoexcept

Upsamples the input base-rate signal into the internal high-rate buffer.

Parameters
inputView of the base-rate audio buffer. Blocks longer than prepare()'s maxBlockSize are truncated (release-safe); channels beyond the prepared channel count are ignored.
Returns
A view of the internal oversampled buffer (length = input samples * factor).
Note
Real-time safe. Pair every call with one downsample() of the same block length before the next upsample().

Definition at line 174 of file Oversampling.h.


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