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

#include <Saturation.h>

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

Public Member Functions

void prepare (const AudioSpec &spec) 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 update (T drive, T character, const AudioSpec &spec) noexcept override
 Updates internal coefficients dependent on block-rate parameters.
 
T processSample (T sample, T drive, T character, int ch) noexcept
 
T processSecond (T sample, T drive, T character, int ch) 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
 

Static Public Attributes

static constexpr bool kSelfAligned = true
 processSecond() delays by exactly the common delay (no padding).
 
- Static Public Attributes inherited from dspark::detail::SaturationAlgorithm< T >
static constexpr int kAaCh = 16
 
static constexpr int kMaxDelay = 4
 

Additional Inherited Members

- 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::MultiStageAlgorithm< T >

Definition at line 1508 of file Saturation.h.

Member Function Documentation

◆ getType()

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

Identifies the exact algorithm type for CRTP static dispatch.

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

Definition at line 1522 of file Saturation.h.

◆ prepare()

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

Prepares the algorithm with the current audio specification.

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

Definition at line 1515 of file Saturation.h.

◆ processSample()

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

Definition at line 1544 of file Saturation.h.

◆ processSecond()

template<typename T >
T dspark::detail::MultiStageAlgorithm< T >::processSecond ( T  sample,
T  drive,
T  character,
int  ch 
)
inlinenoexcept

Second order. Each stage regenerates the harmonics the previous one's kernel removed, and the transformer's low band amplifies whatever aliasing reaches it (a stage's fold-back lands near DC), so every stage needs a kernel; the cascade's delay must equal the common delay:

  • 1 (1x): the tube kernel only (one sample);
  • 2: first-order tube, tape kernel, first-order transformer (0.5 + 1 + 0.5 samples; the low-drive chain of delay 4);
  • 4 (2x): two chains on a first-order tube and the tape kernel, blended by drive (smoothstep from +14 to +16 dB): below, the first-order transformer padded by two samples (the cascade of delay 2, alias -83.3/-48.2/-37.1 dBc at 0/+6/+12 dB); above, the transformer kernel (2.5 samples) and a 1.5-sample linear-phase interpolator (delayHalfSample()), -33.1/-36.2/-33.4 dBc at +18/+24/+36 dB where the first chain reaches -31.1/-28.0/-28.4. The kernel chain aliases more below +15 dB (+12 dB: -33.5) because its extra droop lowers high fundamentals. With all three kernels (three samples, padded to four) +24 dB reaches -29.1 dBc, with the tube kernel and a first-order transformer -28.4, and any split of two samples aliases more still (-14.5 with the tape at first order, -1.3 to -19.2 with a plain stage). At +18 dB both chains reach the same limit on a 19.25 kHz tone at -18 dBFS (-33.1 and -33.4 dBc);
  • 3 (4x and above): second-order kernels on all three stages. The delay-4 chains at 4x and 8x alias 0.2-3.2 dB more at every drive from +12 to +36 dB; at 1x each further kernel lowers a 19.25 kHz fundamental by 13.8 dB, and the delay-2 chain aliases 12-25 dB more than the tube kernel alone (+12 dB: -0.7 against -12.9 dBc). Worst alias over 1-19.25 kHz tones at -6/-18 dBFS, +12/+24 dB: -37.1/-36.2 dBc at 2x and -70.6/-49.7 dBc at 4x, against -16.0/-6.8 and -32.4/-6.0 with the tube kernel alone.

Definition at line 1588 of file Saturation.h.

◆ reset()

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

Resets internal states (filters, phase, memory).

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

Definition at line 1521 of file Saturation.h.

◆ update()

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

Updates internal coefficients dependent on block-rate parameters.

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

Definition at line 1527 of file Saturation.h.

Member Data Documentation

◆ kSelfAligned

template<typename T >
constexpr bool dspark::detail::MultiStageAlgorithm< T >::kSelfAligned = true
staticconstexpr

processSecond() delays by exactly the common delay (no padding).

Definition at line 1525 of file Saturation.h.


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