34 } state_left_, state_right_;
37 apply_biquad1p (
float in, BiquadState& state)
39 float out = in - state.x1 - a1_ * state.y1;
46 apply_biquad2p (
float in, BiquadState& state)
48 float out = in - 2 * state.x1 + state.x2 - a1_ * state.y1 - a2_ * state.y2;
56 template<
int CHANNELS>
void
57 process_impl (uint n_samples,
float *left,
float *right)
61 BiquadState sl = state_left_, sr = state_right_;
65 for (uint i = 0; i < n_samples; i++)
67 left[i] = apply_biquad1p (left[i], sl);
68 if constexpr (CHANNELS == 2)
69 right[i] = apply_biquad1p (right[i], sr);
74 for (uint i = 0; i < n_samples; i++)
76 left[i] = apply_biquad2p (left[i], sl);
77 if constexpr (CHANNELS == 2)
78 right[i] = apply_biquad2p (right[i], sr);
88 reset (
float freq,
float rate,
int order)
90 assert (order == 1 || order == 2);
92 const double k = M_PI * freq / rate;
96 a1_ = (k - 1) / (k + 1);
101 const double kk = k * k;
102 const double div_factor = 1 / (1 + (k + M_SQRT2) * k);
104 a1_ = 2 * (kk - 1) * div_factor;
105 a2_ = (1 - k * M_SQRT2 + kk) * div_factor;
108 state_right_.reset();
112 process (uint n_samples,
float *left,
float *right =
nullptr)
115 process_impl<2> (n_samples, left, right);
117 process_impl<1> (n_samples, left,
nullptr);
Definition: smdcblocker.hh:15