|
DSPark 1.9.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 |
| template<int W> | |
| void | runPair (T *left, T *right, int numSamples, int chLeft, int chRight, int order) noexcept |
| Two channels through the filter in the lanes of one register (W = 2). | |
| template<int W> | |
| void | runOnePolePair (T *left, T *right, int numSamples, int chLeft, int chRight) noexcept |
| template<int W, int S> | |
| void | runCascadePair (T *left, T *right, int numSamples, int chLeft, int chRight) 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 |
| static double | finiteOrZero (T x) 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. | |
| static constexpr bool | kPairChannels = simd::kVecDoubleNarrow == 2 && sizeof(void*) == 8 |
DC blocking filter with configurable Butterworth order (1-10).
Designed for strict real-time processing: zero allocations and tight inner loops. The recursion is serial along the samples, so the block path runs pairs of channels in the two lanes of one register (each lane computes the single-channel operations) and an odd last channel on its own.
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 90 of file DCBlocker.h.
|
protected |
Definition at line 375 of file DCBlocker.h.
|
inlinenoexcept |
Builds a filter coherent with the documented defaults (5 Hz @ 48 kHz).
Definition at line 97 of file DCBlocker.h.
|
default |
|
inlinestaticprotectednoexcept |
Definition at line 494 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Definition at line 416 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Definition at line 422 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 328 of file DCBlocker.h.
|
inlinenoexcept |
Returns the requested cutoff frequency in Hz.
Definition at line 177 of file DCBlocker.h.
|
inlinenoexcept |
Returns the current filter order.
Definition at line 154 of file DCBlocker.h.
|
inline |
Serializes the parameter state (setup/UI threads; allocates).
Definition at line 294 of file DCBlocker.h.
|
inline |
Prepares from AudioSpec (unified API); keeps the configured cutoff.
Definition at line 128 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 113 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 190 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 228 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 262 of file DCBlocker.h.
|
inlinenoexcept |
Clears the internal history states to zero.
Definition at line 285 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 440 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 520 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 428 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 497 of file DCBlocker.h.
|
inlineprotectednoexcept |
Two channels through the filter in the lanes of one register (W = 2).
Definition at line 477 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 170 of file DCBlocker.h.
|
inlinenoexcept |
Sets the filter order (1-10). Thread-safe.
| order | Filter order (1-10). |
Definition at line 148 of file DCBlocker.h.
|
inline |
Restores parameters from a blob (tolerant; rejects foreign ids).
Definition at line 303 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
y[n] = (x[n] - x[n-1]) + R*y[n-1]; the difference zeroes DC exactly.
Definition at line 386 of file DCBlocker.h.
|
inlinestaticprotectednoexcept |
Direct Form I with the numerator applied as a second difference.
Definition at line 392 of file DCBlocker.h.
|
inlineprotectednoexcept |
Definition at line 313 of file DCBlocker.h.
|
protected |
Definition at line 565 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 414 of file DCBlocker.h.
|
staticconstexpr |
Definition at line 93 of file DCBlocker.h.
|
staticconstexpr |
Definition at line 94 of file DCBlocker.h.
|
staticconstexprprotected |
Definition at line 473 of file DCBlocker.h.
|
protected |
Definition at line 566 of file DCBlocker.h.
|
protected |
Definition at line 567 of file DCBlocker.h.
|
protected |
Definition at line 561 of file DCBlocker.h.
|
protected |
Definition at line 570 of file DCBlocker.h.
|
protected |
Derived from the documented defaults in the constructor.
Definition at line 562 of file DCBlocker.h.
|
protected |
Definition at line 564 of file DCBlocker.h.
|
protected |
Definition at line 560 of file DCBlocker.h.
|
protected |
Definition at line 571 of file DCBlocker.h.