DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
Clipper.h File Reference

Multi-mode clipping processor with oversampling, multi-stage architecture, and time-aware slew limiting. More...

#include "../Core/AudioBuffer.h"
#include "../Core/AudioSpec.h"
#include "../Core/DspMath.h"
#include "../Core/DryWetMixer.h"
#include "../Core/Oversampling.h"
#include "../Core/StateBlob.h"
#include <algorithm>
#include <atomic>
#include <bit>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <numbers>
#include <vector>
Include dependency graph for Clipper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::Clipper< T >
 Real-time audio clipper with analog modeling and anti-aliasing features. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

Multi-mode clipping processor with oversampling, multi-stage architecture, and time-aware slew limiting.

Zero-allocation in the audio thread and entirely lock-free. Four clipping modes are supported:

  • Hard: Digital clamp. Transparent until the ceiling is hit, then applies a brickwall limit.
  • Soft: Hyperbolic tangent (tanh). Smooth mathematical saturation with no hard discontinuities.
  • Analog: Sine-based waveshaping. Models the soft clipping characteristics of magnetic/transformer saturation.
  • GoldenRatio: True soft-knee using golden ratio thresholds. Operates linearly up to ceiling/phi, then transitions using a smooth rational asymptotic curve to the ceiling.

Threading model:

  • prepare(): setup thread only (allocates when oversampling is enabled); never concurrently with processBlock(). Invalid specs are ignored and an unprepared instance passes audio through untouched.
  • Parameter setters/getters (setMode, setCeiling, ...): std::atomic based, safe from any thread during playback. Non-finite values are ignored.
  • getState()/setState(): setup/UI threads (getState allocates).
  • getGainReductionDb(): metering-style read, safe from any thread.

Channel handling: without oversampling up to 16 channels are clipped; the dry/wet blend and the oversampled path cover only the prepared channel count, so keep the view within the prepared spec for consistent behaviour.

Note
The ceiling is enforced sample-exactly in the processing (high) rate. With oversampling, the downsampling filter can reconstruct small inter-sample overshoots above the ceiling; follow with a true-peak limiter when broadcast compliance is required.

Dependencies: Core/AudioBuffer.h, Core/AudioSpec.h, Core/DspMath.h, Core/DryWetMixer.h, Core/Oversampling.h, Core/StateBlob.h.

Definition in file Clipper.h.