|
DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
|
DC blocking filter with configurable Butterworth order (1-10). More...
#include <DCBlocker.h>
Classes | |
| 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 Types | |
| using | OnePoleState = detail::DcBlockState |
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 file-level documentation for the measurements behind that decision. Rejection is therefore rate-independent
| T | Sample type (float or double). |
Definition at line 87 of file DCBlocker.h.
|
protected |
Definition at line 366 of file DCBlocker.h.
|
inlinenoexcept |
Builds a filter coherent with the documented defaults (5 Hz @ 48 kHz).
Definition at line 94 of file DCBlocker.h.
|
default |
|
inlinestaticprotectednoexcept |
Definition at line 407 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Definition at line 413 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 319 of file DCBlocker.h.
|
inlinenoexcept |
Returns the requested cutoff frequency in Hz.
Definition at line 174 of file DCBlocker.h.
|
inlinenoexcept |
Returns the current filter order.
Definition at line 151 of file DCBlocker.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 285 of file DCBlocker.h.
|
inline |
Prepares from AudioSpec (unified API); keeps the configured cutoff.
Definition at line 125 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 110 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 187 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 221 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 253 of file DCBlocker.h.
|
inlinenoexcept |
Clears the internal history states to zero.
Definition at line 276 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 429 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 419 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 167 of file DCBlocker.h.
|
inlinenoexcept |
Sets the filter order (1-10). Thread-safe.
| order | Filter order (1-10). |
Definition at line 145 of file DCBlocker.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition at line 294 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
y[n] = (x[n] - x[n-1]) + R*y[n-1]; the difference zeroes DC exactly.
Definition at line 377 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Direct Form I with the numerator applied as a second difference.
Definition at line 383 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 304 of file DCBlocker.h.
|
protected |
Definition at line 465 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 405 of file DCBlocker.h.
|
staticconstexpr |
Definition at line 90 of file DCBlocker.h.
|
staticconstexpr |
Definition at line 91 of file DCBlocker.h.
|
protected |
Definition at line 466 of file DCBlocker.h.
|
protected |
Definition at line 467 of file DCBlocker.h.
|
protected |
Definition at line 461 of file DCBlocker.h.
|
protected |
Definition at line 470 of file DCBlocker.h.
|
protected |
Derived from the documented defaults in the constructor.
Definition at line 462 of file DCBlocker.h.
|
protected |
Definition at line 464 of file DCBlocker.h.
|
protected |
Definition at line 460 of file DCBlocker.h.
|
protected |
Definition at line 471 of file DCBlocker.h.