memlnaut-nisps/nisps/dsp/dc_blocker.hpp
w1n5t0n 973455b158 feat(nisps/dsp): lean DSP primitives ported from maximilian (meml-1v6)
Header-only, heap-free, sample-rate-aware DSP primitives for stream 3:
- Biquad (LPF/HPF/BPF/Notch/Peak/LowShelf/HighShelf, denormal flush)
- Delay<N> + DynamicDelay<N> (fixed-length feedback + power-of-two
  ring with fractional read & smoothed offset)
- AllPass / Comb / LpComb (Schroeder-Moorer reverb sections, split per
  role rather than maximilian's one-class-many-roles maxiReverbFilters)
- DCBlocker (one-pole HPF)
- ChamberlinSVF + OnePoleSmoother<NCh> + EnvelopeFollower
- ADSR envelope generator
- SineOsc/SawOsc/SquareOsc, PAFOperator (port of maxiPAFOperator with
  static gauss/cauchy tables), FMOp single-operator FM building block
- PitchShifter<N> granular two-head crossfade (replaces daisysp PitchShifter)

Tests: biquad freq-domain attenuation, delay tap timing, reverb
boundedness, pitch-shifter ratio + finite output. All pass under
-Wall -Wextra -Werror -Wpedantic, C++20.
2026-04-29 16:08:49 +03:00

34 lines
691 B
C++

// nisps/dsp/dc_blocker.hpp — first-order high-pass to remove DC.
//
// y[n] = x[n] - x[n-1] + R * y[n-1]
//
// `R` close to 1 (typical 0.99) gives a very low-frequency cut. This is the
// straight port of maximilian's `maxiDCBlocker`.
#pragma once
#include "../core/perf.hpp"
namespace nisps {
class DCBlocker {
public:
DCBlocker() noexcept = default;
NISPS_HOT NISPS_FORCE_INLINE float play(float input, float r) noexcept {
ym1_ = input - xm1_ + r * ym1_;
xm1_ = input;
return ym1_;
}
void reset() noexcept {
xm1_ = 0.f;
ym1_ = 0.f;
}
private:
float xm1_ = 0.f;
float ym1_ = 0.f;
};
} // namespace nisps