|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Professional multi-algorithm saturation processor with analog simulation. More...
#include <Saturation.h>

Classes | |
| struct | Params |
Public Types | |
| enum class | Algorithm { Tube , Tape , Transformer , SoftClip , HardClip , Exciter , Wavefolder , Bitcrusher , Downsample , MultiStage } |
| Defines the harmonic generation topology. More... | |
| enum class | ProcessingMode { Stereo , MidOnly , SideOnly , MidSide } |
| Determines how the stereo field is processed. More... | |
| enum class | OutputMode { Normal , WetOnly , Delta } |
| Determines the final output signal routing. More... | |
Public Member Functions | |
| Saturation () | |
| ~Saturation ()=default | |
| Saturation (const Saturation &)=delete | |
| Saturation & | operator= (const Saturation &)=delete |
| void | prepare (const AudioSpec &spec) |
| Prepares all internal resources, filters, and buffers. | |
| void | reset () noexcept |
| Clears all internal states, phase memory, and history buffers. | |
| void | processBlock (AudioBufferView< SampleType > buffer) noexcept |
| Processes an audio block in-place (AudioProcessor standard contract). | |
| void | process (AudioBufferView< SampleType > buffer) noexcept |
| The core audio processing pipeline. | |
| void | setAlgorithm (Algorithm algo) |
| Sets the saturation algorithm topology. | |
| void | setDrive (SampleType dB) |
| Sets the input drive gain. | |
| void | setMix (SampleType mix01) |
| Sets the global Dry/Wet blend. | |
| void | setCharacter (SampleType c) |
| Adjusts the specific character/bias of the selected algorithm. | |
| void | setProcessingMode (ProcessingMode m) |
| Sets the routing configuration for multi-channel processing. | |
| void | setOutputMode (OutputMode m) |
| Sets the output signal path. | |
| void | setAnalogDrift (SampleType i) |
| Injects true-stereo pseudo-random low-frequency modulation (drift) into the saturation drive. | |
| void | setPreFilterHpFrequency (SampleType hz) |
| Configures a pre-saturation high-pass filter. | |
| void | setOutputGain (SampleType dB) |
| Sets the post-saturation make-up or trim gain. | |
| void | setDcBlocking (bool on) |
| Enables or disables the fixed 10Hz DC Blocker. | |
| void | setAdaptiveBlend (bool on) noexcept |
| Enables program-dependent saturation density. | |
| void | setAntialiasing (bool on) noexcept |
| Enables antiderivative anti-aliasing (ADAA) on the memoryless curves (SoftClip / Tube / HardClip), which suppresses the aliasing the nonlinearity generates. Best combined with oversampling (ADAA + OS is the cleanest, per Parker/Zavalishin DAFx-16 and Bilbao et al. 2017). Off by default. | |
| void | setSlewSensitivity (SampleType amount) noexcept |
| Sets a derivative-based (slew rate) saturation multiplier. | |
| void | setPostFilterTilt (SampleType centerHz, SampleType amountDb) |
| Configures a post-saturation first-order tilt EQ. | |
| void | setOversampling (int factor) |
| Configures internal polyphase oversampling to reduce aliasing. | |
| int | getOversamplingFactor () const noexcept |
| Retrieves the current oversampling factor. | |
| int | getLatencySamples () const noexcept |
| Reports the processor's algorithmic latency in samples. | |
| int | getLatency () const noexcept |
| Alias of getLatencySamples() following the framework-wide latency reporting name, so ProcessorChain::getLatency() includes this stage. | |
| Algorithm | getCurrentAlgorithm () const noexcept |
| Retrieves the currently active underlying algorithm. | |
| SampleType | getGainReductionDb () const noexcept |
| Calculates the peak gain reduction (clipping amount) for metering. | |
| std::vector< uint8_t > | getState () const |
| Serializes the parameter state (setup/UI threads; allocates). | |
| bool | setState (const uint8_t *data, size_t size) |
| Restores parameters from a blob (setup/UI threads: it forwards the stored oversampling factor to setOversampling, which may allocate). Out-of-range enum values from foreign or corrupt blobs are clamped. | |
Protected Member Functions | |
| template<typename Fn > | |
| void | pushParam (Fn &&mutate) |
| void | handleParameterChanges () |
| void | applyParamSnapshot (const Params &p) |
| void | processSaturationPipeline (AudioBufferView< SampleType > buffer) noexcept |
| void | applyAdaptiveBlend (AudioBufferView< SampleType > buffer) noexcept |
| Program-dependent dry/wet density blend (base rate, L/R domain). The dry reference is the DryWetMixer capture, which carries the same latency compensation as the wet path - no comb filtering. | |
| void | dispatchSaturator (detail::SaturationAlgorithm< SampleType > *baseAlgo, AudioBufferView< SampleType > buffer, bool useDrift) noexcept |
| template<typename ExactAlgo > | |
| void | processCore (ExactAlgo *algo, AudioBufferView< SampleType > buffer, bool useDrift) noexcept |
| void | applyOutputGain (AudioBufferView< SampleType > buffer) noexcept |
Static Protected Member Functions | |
| static void | sanitizeParams (Params &p, const Params &prev) noexcept |
Static Protected Attributes | |
| static constexpr int | kNumAlgorithms = 10 |
| static constexpr int | kMaxCh = 16 |
Professional multi-algorithm saturation processor with analog simulation.
This class provides a high-quality saturation pipeline featuring 10 distinct algorithms ranging from soft clipping to complex magnetic tape and transformer modeling. Zero latency at 1x; with oversampling enabled the latency equals the oversampler group delay (see getLatency()).
Channel handling: the saturation stage processes up to 16 channels and no more than the prepared spec's channel count; any further channels in the incoming view pass through the linear stages (filters, gain, mix) only.
| SampleType | The floating-point precision to use (must be float or double). |
Definition at line 611 of file Saturation.h.
|
strong |
Defines the harmonic generation topology.
Definition at line 622 of file Saturation.h.
|
strong |
Determines the final output signal routing.
| Enumerator | |
|---|---|
| Normal | |
| WetOnly | |
| Delta | |
Definition at line 640 of file Saturation.h.
|
strong |
Determines how the stereo field is processed.
| Enumerator | |
|---|---|
| Stereo | |
| MidOnly | |
| SideOnly | |
| MidSide | |
Definition at line 637 of file Saturation.h.
|
inline |
Definition at line 644 of file Saturation.h.
|
default |
|
delete |
|
inlineprotectednoexcept |
Program-dependent dry/wet density blend (base rate, L/R domain). The dry reference is the DryWetMixer capture, which carries the same latency compensation as the wet path - no comb filtering.
Definition at line 1464 of file Saturation.h.
|
inlineprotectednoexcept |
Definition at line 1529 of file Saturation.h.
|
inlineprotected |
Definition at line 1270 of file Saturation.h.
|
inlineprotectednoexcept |
Definition at line 1488 of file Saturation.h.
|
inlinenoexcept |
Retrieves the currently active underlying algorithm.
Definition at line 1123 of file Saturation.h.
|
inlinenoexcept |
Calculates the peak gain reduction (clipping amount) for metering.
Definition at line 1130 of file Saturation.h.
|
inlinenoexcept |
Alias of getLatencySamples() following the framework-wide latency reporting name, so ProcessorChain::getLatency() includes this stage.
Definition at line 1116 of file Saturation.h.
|
inlinenoexcept |
Reports the processor's algorithmic latency in samples.
Definition at line 1109 of file Saturation.h.
|
inlinenoexcept |
Retrieves the current oversampling factor.
Definition at line 1102 of file Saturation.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 1134 of file Saturation.h.
|
inlineprotected |
Definition at line 1252 of file Saturation.h.
|
delete |
|
inline |
Prepares all internal resources, filters, and buffers.
std::vector::resize) and filter coefficient calculations. It must be called from the main/setup thread before audio processing begins.| spec | The audio environment specifications (sample rate, max block size, channels). An invalid spec (non-positive or NaN fields) is ignored and the previous state is kept. |
Definition at line 676 of file Saturation.h.
|
inlinenoexcept |
The core audio processing pipeline.
Executes the following sequence: parameter updates (lock-free) -> Mid/Side Encoding -> Pre-filtering -> Slew detection -> Drift generation -> Saturation -> Adaptive Blend -> Mid/Side Decoding -> Post-filtering -> DC Blocking -> Dry/Wet Mix.
prepare() must have been called successfully prior to execution.| buffer | Mutable view of the audio data. Will be modified in-place. |
Definition at line 794 of file Saturation.h.
|
inlinenoexcept |
Processes an audio block in-place (AudioProcessor standard contract).
| buffer | Mutable view of the audio data. |
Definition at line 780 of file Saturation.h.
|
inlineprotectednoexcept |
Definition at line 1507 of file Saturation.h.
|
inlineprotectednoexcept |
Definition at line 1335 of file Saturation.h.
|
inlineprotected |
Definition at line 1236 of file Saturation.h.
|
inlinenoexcept |
Clears all internal states, phase memory, and history buffers.
Definition at line 739 of file Saturation.h.
|
inlinestaticprotectednoexcept |
Keeps every snapshot the audio thread can ever see well-formed: NaN/Inf from the GUI reverts to the previous value (setter-with-NaN == ignored, the framework-wide policy - without this the smoothers and filter designs are poisoned permanently), and enum fields are clamped so a cast-from-int caller or a corrupt state blob can never index outside pool_. Also keeps lastParams_ finite for getState().
Definition at line 1210 of file Saturation.h.
|
inlinenoexcept |
Enables program-dependent saturation density.
| on | True to enable adaptive dynamic blending. |
Definition at line 1012 of file Saturation.h.
|
inline |
Sets the saturation algorithm topology.
| algo | The desired algorithm (e.g., Algorithm::Tube). |
Definition at line 935 of file Saturation.h.
|
inline |
Injects true-stereo pseudo-random low-frequency modulation (drift) into the saturation drive.
| i | Intensity of the drift. Range: [0.0, 1.0]. |
Definition at line 984 of file Saturation.h.
|
inlinenoexcept |
Enables antiderivative anti-aliasing (ADAA) on the memoryless curves (SoftClip / Tube / HardClip), which suppresses the aliasing the nonlinearity generates. Best combined with oversampling (ADAA + OS is the cleanest, per Parker/Zavalishin DAFx-16 and Bilbao et al. 2017). Off by default.
Definition at line 1025 of file Saturation.h.
|
inline |
Adjusts the specific character/bias of the selected algorithm.
Behavior varies per algorithm:
| c | Character amount. Range: [-1.0, 1.0]. 0.0 represents the neutral state. |
Definition at line 963 of file Saturation.h.
|
inline |
Enables or disables the fixed 10Hz DC Blocker.
| on | True to enable DC blocking (default). |
Definition at line 1005 of file Saturation.h.
|
inline |
Sets the input drive gain.
| dB | Drive level in decibels. Range: [-24.0, +48.0]. 0 dB = unity gain. |
Definition at line 942 of file Saturation.h.
|
inline |
Sets the global Dry/Wet blend.
| mix01 | Mix ratio. Range: [0.0 (fully dry), 1.0 (fully wet)]. |
Definition at line 949 of file Saturation.h.
|
inline |
Sets the post-saturation make-up or trim gain.
| dB | Gain in decibels. |
Definition at line 998 of file Saturation.h.
|
inline |
Sets the output signal path.
| m | The output mode (Normal, WetOnly, Delta). Delta mode outputs ONLY the generated harmonics. |
Definition at line 977 of file Saturation.h.
|
inline |
Configures internal polyphase oversampling to reduce aliasing.
prepare(), or prepare() must be called immediately after.| factor | The oversampling multiplier. Must be a power of 2 (1, 2, 4, 8, 16). 1 = Off. |
Definition at line 1067 of file Saturation.h.
|
inline |
Configures a post-saturation first-order tilt EQ.
Tilts the spectrum around the pivot: -amountDb/2 at DC, unity at the pivot, +amountDb/2 at Nyquist (total span = amountDb). Positive values brighten the signal; negative values darken it.
| centerHz | Pivot frequency in Hertz. Range: [100.0, Nyquist]. |
| amountDb | Total tilt span in decibels. Range: [-12.0, 12.0]. |
Definition at line 1054 of file Saturation.h.
|
inline |
Configures a pre-saturation high-pass filter.
| hz | Cutoff frequency in Hertz. Range: [10.0, Nyquist]. |
Definition at line 991 of file Saturation.h.
|
inline |
Sets the routing configuration for multi-channel processing.
| m | The processing mode (Stereo, MidOnly, SideOnly, MidSide). |
Definition at line 970 of file Saturation.h.
|
inlinenoexcept |
Sets a derivative-based (slew rate) saturation multiplier.
| amount | Sensitivity multiplier. Range: [0.0 (off), 1.0 (max)]. |
Definition at line 1037 of file Saturation.h.
|
inline |
Restores parameters from a blob (setup/UI threads: it forwards the stored oversampling factor to setOversampling, which may allocate). Out-of-range enum values from foreign or corrupt blobs are clamped.
Definition at line 1164 of file Saturation.h.
|
protected |
Definition at line 1553 of file Saturation.h.
|
protected |
Definition at line 1591 of file Saturation.h.
|
protected |
Mirror for getState.
Definition at line 1560 of file Saturation.h.
|
protected |
Definition at line 1568 of file Saturation.h.
|
protected |
Definition at line 1570 of file Saturation.h.
|
protected |
Definition at line 1565 of file Saturation.h.
|
protected |
Definition at line 1577 of file Saturation.h.
|
protected |
Definition at line 1564 of file Saturation.h.
|
protected |
Definition at line 1583 of file Saturation.h.
|
protected |
Definition at line 1568 of file Saturation.h.
|
protected |
Definition at line 1567 of file Saturation.h.
|
protected |
Definition at line 1578 of file Saturation.h.
|
protected |
Definition at line 1589 of file Saturation.h.
|
staticconstexprprotected |
Definition at line 1592 of file Saturation.h.
|
staticconstexprprotected |
Definition at line 1551 of file Saturation.h.
|
protected |
Definition at line 1557 of file Saturation.h.
|
protected |
Definition at line 1599 of file Saturation.h.
|
protected |
Definition at line 1600 of file Saturation.h.
|
protected |
Definition at line 1598 of file Saturation.h.
|
protected |
Definition at line 1580 of file Saturation.h.
|
protected |
Definition at line 1568 of file Saturation.h.
|
protected |
MidOnly/SideOnly channel snapshot.
Definition at line 1584 of file Saturation.h.
|
protected |
Definition at line 1554 of file Saturation.h.
|
protected |
Definition at line 1569 of file Saturation.h.
|
protected |
Definition at line 1563 of file Saturation.h.
|
protected |
Definition at line 1586 of file Saturation.h.
|
protected |
Definition at line 1587 of file Saturation.h.
|
protected |
Definition at line 1556 of file Saturation.h.
|
mutableprotected |
Definition at line 1558 of file Saturation.h.
|
protected |
Definition at line 1559 of file Saturation.h.
|
protected |
Definition at line 1552 of file Saturation.h.
|
protected |
Definition at line 1572 of file Saturation.h.
|
protected |
Definition at line 1567 of file Saturation.h.
|
protected |
Definition at line 1569 of file Saturation.h.
|
protected |
Definition at line 1572 of file Saturation.h.
|
protected |
Definition at line 1567 of file Saturation.h.
|
protected |
Definition at line 1549 of file Saturation.h.
|
protected |
Definition at line 1593 of file Saturation.h.
|
protected |
Definition at line 1596 of file Saturation.h.
|
protected |
Definition at line 1562 of file Saturation.h.
|
protected |
Definition at line 1580 of file Saturation.h.
|
protected |
Definition at line 1595 of file Saturation.h.
|
protected |
Definition at line 1548 of file Saturation.h.
|
protected |
Definition at line 1582 of file Saturation.h.