DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::detail::SaturationAlgorithm< T > Class Template Referenceabstract

#include <Saturation.h>

Inheritance diagram for dspark::detail::SaturationAlgorithm< T >:

Public Member Functions

virtual ~SaturationAlgorithm ()=default
 
virtual void prepare (const AudioSpec &spec) noexcept=0
 Prepares the algorithm with the current audio specification.
 
virtual void reset () noexcept=0
 Resets internal states (filters, phase, memory).
 
virtual void update (T, T, const AudioSpec &) noexcept
 Updates internal coefficients dependent on block-rate parameters.
 
virtual Saturation< T >::Algorithm getType () const noexcept=0
 Identifies the exact algorithm type for CRTP static dispatch.
 
void setAntialias (int order) noexcept
 Antiderivative antialiasing order on the memoryless curves: 0 off, 1 first order (SoftClip/Tube/HardClip), 2 second order (SoftClip/Tube/HardClip/Wavefolder/Transformer/Exciter/Tape and every MultiStage stage from 2x, Bilbao et al. 2017). Order 2 delays every algorithm by the same number of processing samples (latchOrder()): the kernels delay by one and are padded to it, the others are delayed by all of it, so a crossfade between any two stays aligned. Default 0.
 
void latchOrder (int commonDelay=1) noexcept
 Latches the order for the coming block (audio thread, before update()) and the common second-order delay in processing samples (1 to kMaxDelay; Saturation passes 1 at 1x, 4 at 2x and 3 from 4x). Entering order 2 arms every channel: its first sample seeds the kernel history and the delay line with the current input, so the delay is inserted as held samples instead of a step from stale history. The off and first-order paths keep no second-order history at all.
 
int order () const noexcept
 The latched order (audio thread).
 
int commonDelay () const noexcept
 The latched common second-order delay (processing samples).
 
T align (T y, int ch) noexcept
 
T padKernel (T y, int ch) noexcept
 

Static Public Attributes

static constexpr int kAaCh = 16
 
static constexpr int kMaxDelay = 4
 

Protected Member Functions

bool takeArm (int c) noexcept
 
T delayBy (T y, int ch, int n) noexcept
 
T delayHalfSample (T y, int ch) noexcept
 
void resetAlign () noexcept
 

Protected Attributes

std::atomic< int > antialias_ { 0 }
 
int order_ = 0
 Latched order (audio thread).
 
int delay_ = 1
 Latched common second-order delay.
 
unsigned armMask_ = ~0u
 Channels whose order-2 history must be seeded.
 
unsigned delayArm_ = ~0u
 Channels whose delay line must be seeded.
 
unsigned halfArm_ = ~0u
 Channels whose interpolator must be seeded.
 
std::array< std::array< T, kMaxDelay >, kAaCh > alignHold_ {}
 
std::array< std::array< T, 3 >, kAaCh > halfHold_ {}
 

Detailed Description

template<typename T>
class dspark::detail::SaturationAlgorithm< T >

Definition at line 82 of file Saturation.h.

Constructor & Destructor Documentation

◆ ~SaturationAlgorithm()

template<typename T >
virtual dspark::detail::SaturationAlgorithm< T >::~SaturationAlgorithm ( )
virtualdefault

Member Function Documentation

◆ align()

template<typename T >
T dspark::detail::SaturationAlgorithm< T >::align ( T  y,
int  ch 
)
inlinenoexcept

Full common delay, for algorithms without a second-order kernel.

Definition at line 137 of file Saturation.h.

◆ commonDelay()

template<typename T >
int dspark::detail::SaturationAlgorithm< T >::commonDelay ( ) const
inlinenoexcept

The latched common second-order delay (processing samples).

Definition at line 134 of file Saturation.h.

◆ delayBy()

template<typename T >
T dspark::detail::SaturationAlgorithm< T >::delayBy ( T  y,
int  ch,
int  n 
)
inlineprotectednoexcept

Delays y by n (1 to kMaxDelay) samples on channel ch.

Definition at line 162 of file Saturation.h.

◆ delayHalfSample()

template<typename T >
T dspark::detail::SaturationAlgorithm< T >::delayHalfSample ( T  y,
int  ch 
)
inlineprotectednoexcept

Delays y by 1.5 samples on channel ch with a linear-phase 4-tap interpolator (its own history, seeded like the delay line). Coefficients -a, 0.5 + a, 0.5 + a, -a with a = 0.0824, the minimax choice for a flat response to 20 kHz at 96 kHz: within +0.10/-0.11 dB there, -0.54 dB at 24 kHz, a zero at half the rate.

Definition at line 185 of file Saturation.h.

◆ getType()

◆ latchOrder()

template<typename T >
void dspark::detail::SaturationAlgorithm< T >::latchOrder ( int  commonDelay = 1)
inlinenoexcept

Latches the order for the coming block (audio thread, before update()) and the common second-order delay in processing samples (1 to kMaxDelay; Saturation passes 1 at 1x, 4 at 2x and 3 from 4x). Entering order 2 arms every channel: its first sample seeds the kernel history and the delay line with the current input, so the delay is inserted as held samples instead of a step from stale history. The off and first-order paths keep no second-order history at all.

Definition at line 122 of file Saturation.h.

◆ order()

template<typename T >
int dspark::detail::SaturationAlgorithm< T >::order ( ) const
inlinenoexcept

The latched order (audio thread).

Definition at line 131 of file Saturation.h.

◆ padKernel()

template<typename T >
T dspark::detail::SaturationAlgorithm< T >::padKernel ( T  y,
int  ch 
)
inlinenoexcept

The common delay less the one sample of a second-order kernel.

Definition at line 140 of file Saturation.h.

◆ prepare()

◆ reset()

◆ resetAlign()

template<typename T >
void dspark::detail::SaturationAlgorithm< T >::resetAlign ( )
inlineprotectednoexcept

Definition at line 203 of file Saturation.h.

◆ setAntialias()

template<typename T >
void dspark::detail::SaturationAlgorithm< T >::setAntialias ( int  order)
inlinenoexcept

Antiderivative antialiasing order on the memoryless curves: 0 off, 1 first order (SoftClip/Tube/HardClip), 2 second order (SoftClip/Tube/HardClip/Wavefolder/Transformer/Exciter/Tape and every MultiStage stage from 2x, Bilbao et al. 2017). Order 2 delays every algorithm by the same number of processing samples (latchOrder()): the kernels delay by one and are padded to it, the others are delayed by all of it, so a crossfade between any two stays aligned. Default 0.

Definition at line 110 of file Saturation.h.

◆ takeArm()

template<typename T >
bool dspark::detail::SaturationAlgorithm< T >::takeArm ( int  c)
inlineprotectednoexcept

True once per channel after entering order 2 (or a reset).

Definition at line 153 of file Saturation.h.

◆ update()

template<typename T >
virtual void dspark::detail::SaturationAlgorithm< T >::update ( T  ,
T  ,
const AudioSpec &   
)
inlinevirtualnoexcept

Member Data Documentation

◆ alignHold_

template<typename T >
std::array<std::array<T, kMaxDelay>, kAaCh> dspark::detail::SaturationAlgorithm< T >::alignHold_ {}
protected

Definition at line 211 of file Saturation.h.

◆ antialias_

template<typename T >
std::atomic<int> dspark::detail::SaturationAlgorithm< T >::antialias_ { 0 }
protected

Definition at line 145 of file Saturation.h.

◆ armMask_

template<typename T >
unsigned dspark::detail::SaturationAlgorithm< T >::armMask_ = ~0u
protected

Channels whose order-2 history must be seeded.

Definition at line 148 of file Saturation.h.

◆ delay_

template<typename T >
int dspark::detail::SaturationAlgorithm< T >::delay_ = 1
protected

Latched common second-order delay.

Definition at line 147 of file Saturation.h.

◆ delayArm_

template<typename T >
unsigned dspark::detail::SaturationAlgorithm< T >::delayArm_ = ~0u
protected

Channels whose delay line must be seeded.

Definition at line 149 of file Saturation.h.

◆ halfArm_

template<typename T >
unsigned dspark::detail::SaturationAlgorithm< T >::halfArm_ = ~0u
protected

Channels whose interpolator must be seeded.

Definition at line 150 of file Saturation.h.

◆ halfHold_

template<typename T >
std::array<std::array<T, 3>, kAaCh> dspark::detail::SaturationAlgorithm< T >::halfHold_ {}
protected

Definition at line 212 of file Saturation.h.

◆ kAaCh

template<typename T >
constexpr int dspark::detail::SaturationAlgorithm< T >::kAaCh = 16
staticconstexpr

Definition at line 85 of file Saturation.h.

◆ kMaxDelay

template<typename T >
constexpr int dspark::detail::SaturationAlgorithm< T >::kMaxDelay = 4
staticconstexpr

Definition at line 142 of file Saturation.h.

◆ order_

template<typename T >
int dspark::detail::SaturationAlgorithm< T >::order_ = 0
protected

Latched order (audio thread).

Definition at line 146 of file Saturation.h.


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