|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Real-time audio clipper with analog modeling and anti-aliasing features. More...
#include <Clipper.h>

Public Types | |
| enum class | Mode { Hard , Soft , Analog , GoldenRatio } |
| Defines the harmonic waveshaping algorithm used for clipping. More... | |
Public Member Functions | |
| void | prepare (const AudioSpec &spec) |
| Prepares the clipper for processing, allocating any necessary internal buffers. | |
| void | reset () noexcept |
| Resets the internal state of the clipper. | |
| void | processBlock (AudioBufferView< T > buffer) noexcept |
| Processes an audio buffer in-place through the clipping algorithm. | |
| void | setMode (Mode mode) noexcept |
| Sets the clipping algorithm. | |
| void | setCeiling (T dB) noexcept |
| Sets the absolute maximum output level. | |
| void | setInputGain (T dB) noexcept |
| Sets the input drive/gain before clipping. | |
| void | setStages (int count) noexcept |
| Sets the number of cascaded clipping stages. | |
| void | setMix (T amount) noexcept |
| Sets the dry/wet ratio of the processor. | |
| void | setSlewLimit (T ms) noexcept |
| Enables slew limiting to soften clipping edges. | |
| void | setOversampling (int factor) noexcept |
| Sets the oversampling multiplier to mitigate aliasing. | |
| Mode | getMode () const noexcept |
| T | getCeiling () const noexcept |
| T | getInputGain () const noexcept |
| int | getStages () const noexcept |
| T | getMix () const noexcept |
| T | getSlewLimit () const noexcept |
| int | getOversampling () const noexcept |
| Returns the published oversampling factor (applied on the next prepare()). | |
| int | getLatency () const noexcept |
| Returns latency in samples introduced by oversampling filters. | |
| T | getGainReductionDb () const noexcept |
| Retrieves the maximum gain reduction applied during the last block (for UI 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. Oversampling factor applies on the next prepare() as usual. | |
Protected Member Functions | |
| void | processInternal (AudioBufferView< T > &buffer, double currentSampleRate) noexcept |
| Core DSP routing. Resolves atomics and branches to the per-mode template. | |
| template<Mode M> | |
| void | dispatchClipping (AudioBufferView< T > &buffer, T totalGainLin, T stageGain, int numStages, T ceiling, T maxSlewDelta) noexcept |
| Per-mode processing loop (waveshaper inlined at compile time; the slew state and peak metering keep the loop serial per channel). | |
Static Protected Member Functions | |
| template<Mode M> | |
| static T | processSample (T sample, T ceiling) noexcept |
| Compile-time resolution of the waveshaping math. | |
| static T | dbToLinear (T dB) noexcept |
| static T | gainToDecibels (T linear, T minusInfinityDb) noexcept |
Protected Attributes | |
| AudioSpec | spec_ {} |
| std::atomic< bool > | prepared_ { false } |
| DryWetMixer< T > | mixer_ |
| std::unique_ptr< Oversampling< T > > | oversampler_ |
| std::atomic< Mode > | mode_ { Mode::Hard } |
| std::atomic< T > | ceilingDb_ { T(0) } |
| std::atomic< T > | inputGainDb_ { T(0) } |
| std::atomic< int > | stages_ { 1 } |
| std::atomic< T > | mix_ { T(1) } |
| std::atomic< T > | slewLimitMs_ { T(0) } |
| std::atomic< int > | osFactor_ { 1 } |
| T | slewPrev_ [kMaxChannels] {} |
| std::atomic< T > | gainReductionDb_ { T(0) } |
Static Protected Attributes | |
| static constexpr int | kMaxStages = 4 |
| static constexpr int | kMaxChannels = 16 |
| static constexpr T | kPhi = static_cast<T>(1.6180339887498948482) |
| Mathematical Golden Ratio used for the GoldenRatio soft-knee transition. | |
Real-time audio clipper with analog modeling and anti-aliasing features.
| T | Sample type (must satisfy dspark::FloatType, typically float or double). |
|
strong |
Defines the harmonic waveshaping algorithm used for clipping.
|
inlinestaticprotectednoexcept |
|
inlineprotectednoexcept |
|
inlinestaticprotectednoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inline |
|
inline |
Prepares the clipper for processing, allocating any necessary internal buffers.
If oversampling is configured > 1x, this method allocates the oversampling filters. Call it from the main/setup thread before playback begins (never concurrently with processBlock), and again whenever the sample rate changes.
Invalid specs (non-positive/non-finite rate, block size or channel count) are ignored: the previous state is kept and an unprepared instance stays pass-through.
| spec | The current audio environment specifications (sample rate, max block size). |
|
inlinenoexcept |
|
inlineprotectednoexcept |
|
inlinestaticprotectednoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
|
inlinenoexcept |
Sets the oversampling multiplier to mitigate aliasing.
Values are rounded UP to the next power of two and capped at 16.
prepare() to allocate filters.| factor | Oversampling ratio (1 = off, 2, 4, 8, 16). |
|
inlinenoexcept |
Enables slew limiting to soften clipping edges.
Limits how fast the output can change over time. Defined in milliseconds, so the effect stays consistent regardless of the sample rate or oversampling factor. Note that a slew limiter is itself nonlinear: it darkens the transient edges and top octave rather than strictly removing aliasing (use oversampling for that).
| ms | Rise time in milliseconds to reach the ceiling from zero. 0 = off; non-finite values are ignored. |
|
inlinenoexcept |
Sets the number of cascaded clipping stages.
Multi-stage clipping distributes the input gain logarithmically across multiple clipping algorithms. This alters the harmonic profile, making heavy distortion sound smoother compared to a single aggressive stage.
| count | Number of stages. Clamped between 1 and 4. |
|
inline |
Restores parameters from a blob. Oversampling factor applies on the next prepare() as usual.
|
protected |
|
protected |
|
protected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
staticconstexprprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |