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

#include <Saturation.h>

Inheritance diagram for dspark::detail::CurveAlgorithm< T >:
Collaboration diagram for dspark::detail::CurveAlgorithm< T >:

Public Member Functions

void prepare (const AudioSpec &) noexcept override
 Prepares the algorithm with the current audio specification.
 
void reset () noexcept override
 Resets internal states (filters, phase, memory).
 
Saturation< T >::Algorithm getType () const noexcept override
 Identifies the exact algorithm type for CRTP static dispatch.
 
void setShape (T hardness, T curvature, T asymmetry) noexcept
 
T getHardness () const noexcept
 
T getCurvature () const noexcept
 
T getAsymmetry () const noexcept
 
void setBase (int base) noexcept
 
int getBase () const noexcept
 
void update (T, T, const AudioSpec &) noexcept override
 Updates internal coefficients dependent on block-rate parameters.
 
T bend (T v, bool negative) const noexcept
 
T shape (T x) const noexcept
 
T processSample (T sample, T drive, T, int) noexcept
 
- Public Member Functions inherited from dspark::detail::SaturationAlgorithm< T >
virtual ~SaturationAlgorithm ()=default
 
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
 

Additional Inherited Members

- Static Public Attributes inherited from dspark::detail::SaturationAlgorithm< T >
static constexpr int kAaCh = 16
 
static constexpr int kMaxDelay = 4
 
- Protected Member Functions inherited from dspark::detail::SaturationAlgorithm< T >
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 inherited from dspark::detail::SaturationAlgorithm< T >
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::CurveAlgorithm< T >

A soft clipper whose curve is shaped by three controls that would work on any curve with unit slope at the origin and a ceiling of 1 (here tanh):

  • hardness (0 to 0.95): the curve is a straight line up to it and the whole tanh, squeezed, between it and the ceiling. 0 is tanh; towards 1 the knee shrinks to a corner.
  • curvature (0.5 to 4): the exponent p of f(u) = tanh(u^p)^(1/p), which keeps the slope at the origin and the ceiling: over 1 the curve stays on the line longer and turns faster, under 1 it leaves it at once.
  • asymmetry (-1 to 1): over 0 the negative half-cycle meets a ceiling of 2^-asymmetry, under 0 the positive one meets 2^asymmetry, with the same slope at the origin: even harmonics, and a DC term the processor's DC blocker removes. Neither half goes past 1.

It has no antiderivative kernel: with antialiasing on it is delayed to the common alignment and relies on the oversampling.

Definition at line 1423 of file Saturation.h.

Member Function Documentation

◆ bend()

template<typename T >
T dspark::detail::CurveAlgorithm< T >::bend ( T  v,
bool  negative 
) const
inlinenoexcept

The base curve beyond the knee, v >= 0, each with a slope of 1 at 0 and heading for 1: tanh; algebraic v / sqrt(1 + v^2); arctangent (2 / pi) atan(pi v / 2); the error function erf(sqrt(pi) v / 2); a cubic that reaches 1 at v = 1.5 and stays (finite support); a valve, 1 - e^-v on the positive half and algebraic on the negative one; and a rectifier, tanh on the positive half and tanh(v) e^-v on the negative one, which turns back toward 0.

Definition at line 1471 of file Saturation.h.

◆ getAsymmetry()

template<typename T >
T dspark::detail::CurveAlgorithm< T >::getAsymmetry ( ) const
inlinenoexcept

Definition at line 1444 of file Saturation.h.

◆ getBase()

template<typename T >
int dspark::detail::CurveAlgorithm< T >::getBase ( ) const
inlinenoexcept

Definition at line 1447 of file Saturation.h.

◆ getCurvature()

template<typename T >
T dspark::detail::CurveAlgorithm< T >::getCurvature ( ) const
inlinenoexcept

Definition at line 1443 of file Saturation.h.

◆ getHardness()

template<typename T >
T dspark::detail::CurveAlgorithm< T >::getHardness ( ) const
inlinenoexcept

Definition at line 1442 of file Saturation.h.

◆ getType()

template<typename T >
Saturation< T >::Algorithm dspark::detail::CurveAlgorithm< T >::getType ( ) const
inlineoverridevirtualnoexcept

Identifies the exact algorithm type for CRTP static dispatch.

Implements dspark::detail::SaturationAlgorithm< T >.

Definition at line 1433 of file Saturation.h.

◆ prepare()

template<typename T >
void dspark::detail::CurveAlgorithm< T >::prepare ( const AudioSpec &  spec)
inlineoverridevirtualnoexcept

Prepares the algorithm with the current audio specification.

Implements dspark::detail::SaturationAlgorithm< T >.

Definition at line 1431 of file Saturation.h.

◆ processSample()

template<typename T >
T dspark::detail::CurveAlgorithm< T >::processSample ( T  sample,
T  drive,
T  ,
int   
)
inlinenoexcept

Definition at line 1503 of file Saturation.h.

◆ reset()

template<typename T >
void dspark::detail::CurveAlgorithm< T >::reset ( )
inlineoverridevirtualnoexcept

Resets internal states (filters, phase, memory).

Implements dspark::detail::SaturationAlgorithm< T >.

Definition at line 1432 of file Saturation.h.

◆ setBase()

template<typename T >
void dspark::detail::CurveAlgorithm< T >::setBase ( int  base)
inlinenoexcept

Publishes the base curve (an index of Saturation::CurveBase).

Definition at line 1446 of file Saturation.h.

◆ setShape()

template<typename T >
void dspark::detail::CurveAlgorithm< T >::setShape ( T  hardness,
T  curvature,
T  asymmetry 
)
inlinenoexcept

Publishes the three controls (any thread; values that are not finite keep what they had).

Definition at line 1436 of file Saturation.h.

◆ shape()

template<typename T >
T dspark::detail::CurveAlgorithm< T >::shape ( T  x) const
inlinenoexcept

The curve on a driven sample.

Definition at line 1486 of file Saturation.h.

◆ update()

template<typename T >
void dspark::detail::CurveAlgorithm< T >::update ( T  ,
T  ,
const AudioSpec &   
)
inlineoverridevirtualnoexcept

Updates internal coefficients dependent on block-rate parameters.

Reimplemented from dspark::detail::SaturationAlgorithm< T >.

Definition at line 1449 of file Saturation.h.


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