|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
DC blocking filter with configurable Butterworth order (1-10). More...
#include <DCBlocker.h>

Classes | |
| struct | OnePoleState |
| struct | Section |
| Second-order section: b0 * (1 - z^-1)^2 / (1 + a1 z^-1 + a2 z^-2). More... | |
| struct | SectionState |
Public Member Functions | |
| DCBlocker () noexcept | |
| Builds a filter coherent with the documented defaults (5 Hz @ 48 kHz). | |
| ~DCBlocker ()=default | |
| void | prepare (double sampleRate, int numChannels=2, double cutoffHz=-1.0) |
| Prepares the DC blocker, resetting internal states and precalculating coefficients. | |
| void | prepare (const AudioSpec &spec) |
| Prepares from AudioSpec (unified API); keeps the configured cutoff. | |
| void | setOrder (int order) noexcept |
| Sets the filter order (1-10). Thread-safe. | |
| int | getOrder () const noexcept |
| Returns the current filter order. | |
| void | setCutoff (T hz) noexcept |
| Requests a cutoff frequency update. | |
| T | getCutoff () const noexcept |
| Returns the requested cutoff frequency in Hz. | |
| void | processBlock (AudioBufferView< T > buffer) noexcept |
| Processes an AudioBufferView in-place. | |
| void | processBlock (int channel, T *data, int numSamples) noexcept |
| Processes a block of samples for one channel in-place. | |
| T | processSample (int channel, T input) noexcept |
| Processes a single sample for a given channel. | |
| void | reset () noexcept |
| Clears the internal history states to zero. | |
| 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 (tolerant; rejects foreign ids). | |
Static Public Attributes | |
| static constexpr int | kMaxBiquadStages = 5 |
| static constexpr int | kMaxChannels = 16 |
Protected Member Functions | |
| void | updateCoefficientsIfNeeded () noexcept |
| void | forceUpdateCoefficients (T explicitCutoff=T(0)) noexcept |
| void | runOnePole (T *data, int numSamples, int channel) noexcept |
| void | runCascade (T *data, int numSamples, int channel, int numStages) noexcept |
Static Protected Member Functions | |
| static double | stepOnePole (double r, OnePoleState &z, double x) noexcept |
| y[n] = (x[n] - x[n-1]) + R*y[n-1]; the difference zeroes DC exactly. | |
| static double | stepSection (double b0, double a1, double a2, SectionState &z, double x) noexcept |
| Direct Form I with the numerator applied as a second difference. | |
| static void | flushDenormals (OnePoleState &z) noexcept |
| static void | flushDenormals (SectionState &z) noexcept |
Protected Attributes | |
| double | sampleRate_ = 48000.0 |
| int | numChannels_ = 2 |
| double | onePoleR_ = 0.0 |
| Derived from the documented defaults in the constructor. | |
| std::atomic< int > | order_ { 1 } |
| std::atomic< T > | cutoffHz_ { T(5) } |
| T | lastCutoff_ = T(-1) |
| int | lastOrder_ = -1 |
| std::array< OnePoleState, kMaxChannels > | onePole_ {} |
| std::array< Section, kMaxBiquadStages > | sections_ {} |
Static Protected Attributes | |
| static constexpr double | kDenormalFloor = 1e-30 |
| Flushes a fully decayed state to zero at the end of a block. | |
DC blocking filter with configurable Butterworth order (1-10).
Designed for strict real-time processing: zero allocations and tight scalar inner loops (the recursive filter state rules out SIMD vectorization).
The filter core (coefficients, history and recursion) is always double precision, independent of the sample type: see the
Definition at line 86 of file DCBlocker.h.
|
inlinenoexcept |
Builds a filter coherent with the documented defaults (5 Hz @ 48 kHz).
Definition at line 93 of file DCBlocker.h.
|
default |
|
inlinestaticprotectednoexcept |
Definition at line 409 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Definition at line 415 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 318 of file DCBlocker.h.
|
inlinenoexcept |
Returns the requested cutoff frequency in Hz.
Definition at line 173 of file DCBlocker.h.
|
inlinenoexcept |
Returns the current filter order.
Definition at line 150 of file DCBlocker.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 284 of file DCBlocker.h.
|
inline |
Prepares from AudioSpec (unified API); keeps the configured cutoff.
Definition at line 124 of file DCBlocker.h.
|
inline |
Prepares the DC blocker, resetting internal states and precalculating coefficients.
| sampleRate | Sample rate in Hz. Non-positive or NaN rates are ignored. |
| numChannels | Number of audio channels (max 16, default: 2). |
| cutoffHz | Cutoff frequency in Hz (clamped to min 1 Hz). Leave it out (or pass a non-positive value) to KEEP the cutoff currently configured, which is what a host re-activating the plugin wants: re-preparing used to silently drop a setCutoff() back to the 5 Hz default. A freshly built instance still starts at 5 Hz. |
Definition at line 109 of file DCBlocker.h.
|
inlinenoexcept |
Processes an AudioBufferView in-place.
Checks for parameter updates and applies the appropriate filter topology across all channels using tight scalar inner loops.
| buffer | Audio buffer to process. |
Definition at line 186 of file DCBlocker.h.
|
inlinenoexcept |
Processes a block of samples for one channel in-place.
| channel | Channel index. Out-of-range indices leave the data untouched (the per-channel state is bounded to kMaxChannels). |
| data | Audio samples (modified in-place). |
| numSamples | Number of samples to process. |
Definition at line 220 of file DCBlocker.h.
|
inlinenoexcept |
Processes a single sample for a given channel.
| channel | Channel index. Out-of-range indices return the input unprocessed. |
| input | Input sample. |
Definition at line 252 of file DCBlocker.h.
|
inlinenoexcept |
Clears the internal history states to zero.
Definition at line 275 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 431 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 421 of file DCBlocker.h.
|
inlinenoexcept |
Requests a cutoff frequency update.
Coefficients are recomputed lazily on the next processing call to ensure thread safety, but beware that calculating high-order biquads involves trigonometric operations.
| hz | Cutoff frequency in Hz (clamped to min 1.0). Non-finite values are ignored (std::max(NaN, 1) returns the NaN, which would poison every coefficient on the next rebuild). |
Definition at line 166 of file DCBlocker.h.
|
inlinenoexcept |
Sets the filter order (1-10). Thread-safe.
| order | Filter order (1-10). |
Definition at line 144 of file DCBlocker.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition at line 293 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
y[n] = (x[n] - x[n-1]) + R*y[n-1]; the difference zeroes DC exactly.
Definition at line 376 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Direct Form I with the numerator applied as a second difference.
Definition at line 385 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 303 of file DCBlocker.h.
|
protected |
Definition at line 467 of file DCBlocker.h.
|
staticconstexprprotected |
Flushes a fully decayed state to zero at the end of a block.
A 5 Hz pole holds energy for seconds: without this, a silent passage walks the state down through the denormal range and parks both the recursion and the emitted samples on the CPU's slow path (the float cascade this replaced was measured at 1e-42 after four seconds of DC). The floor sits ~600 dB below full scale and above the smallest normal float, and only fires when the input history is negligible too, so it can never truncate a live signal.
Definition at line 407 of file DCBlocker.h.
|
staticconstexpr |
Definition at line 89 of file DCBlocker.h.
|
staticconstexpr |
Definition at line 90 of file DCBlocker.h.
|
protected |
Definition at line 468 of file DCBlocker.h.
|
protected |
Definition at line 469 of file DCBlocker.h.
|
protected |
Definition at line 463 of file DCBlocker.h.
|
protected |
Definition at line 472 of file DCBlocker.h.
|
protected |
Derived from the documented defaults in the constructor.
Definition at line 464 of file DCBlocker.h.
|
protected |
Definition at line 466 of file DCBlocker.h.
|
protected |
Definition at line 462 of file DCBlocker.h.
|
protected |
Definition at line 473 of file DCBlocker.h.