55 , T a1_ = T(), T a2_ = T())
56 : b0(b0_), b1(b1_), b2(b2_)
65 b0 += rhs.b0; b1 += rhs.b1; b2 += rhs.b2;
66 a1 += rhs.a1; a2 += rhs.a2;
78 b0 *= rhs; b1 *= rhs; b2 *= rhs;
91 b0 /= rhs; b1 /= rhs; b2 /= rhs;
111 return {lhs.b0 - rhs.b0, lhs.b1 - rhs.b1, lhs.b2 - rhs.b2
112 , lhs.a1 - rhs.a1, lhs.a2 - rhs.a2};
118 stream <<
"b0: " << c.b0 <<
", b1: " << c.b1 <<
", b2: " << c.b2
119 <<
", a1: " << c.a1 <<
", a2: " << c.a2;
130 , T a1_ = T(), T a2_ = T())
131 : b0(b0_), b1(b1_), b2(b2_)
144template<
typename T,
template<
typename>
class DenormalPrevention = apf::dp::ac>
148 using argument_type = T;
149 using result_type = T;
151 BiQuad() : w0(), w1(), w2() {}
170 w2 = in - this->a1*w1 - this->a2*w0;
172 this->prevent_denormals(w2);
174 in = this->b0*w2 + this->b1*w1 + this->b2*w0;
184template<
typename S,
typename Container = std::vector<S>>
188 using argument_type =
typename S::argument_type;
189 using result_type =
typename S::result_type;
190 using size_type =
typename Container::size_type;
193 explicit Cascade(size_type n) : _sections(n) {}
202 assert(_sections.size() == size_type(std::distance(first, last)));
204 std::copy(first, last, _sections.begin());
212 for (
auto& section: _sections)
225 template<
typename In,
typename Out>
228 using out_t =
typename std::iterator_traits<Out>::value_type;
230 while (first != last)
232 *result++ =
static_cast<out_t
>(this->
operator()(*first));
237 size_type number_of_sections()
const {
return _sections.size(); }
258 std::complex<T> eig[2];
260 T tmp_arg = std::pow((Roots[0][0]+Roots[1][1])/two, two)
261 + Roots[0][1]*Roots[1][0] - Roots[0][0]*Roots[1][1];
265 eig[0] = (Roots[0][0]+Roots[1][1])/two + std::sqrt(tmp_arg);
266 eig[1] = (Roots[0][0]+Roots[1][1])/two - std::sqrt(tmp_arg);
270 eig[0] = std::complex<T>((Roots[0][0]+Roots[1][1])/two, std::sqrt(-tmp_arg));
271 eig[1] = std::complex<T>((Roots[0][0]+Roots[1][1])/two, -std::sqrt(-tmp_arg));
274 poly1 = real(-eig[0] - eig[1]);
275 poly2 = real(-eig[1] * -eig[0]);
297 T fp_temp =
static_cast<T
>(fp) * (two * apf::math::pi<T>());
298 T lambda = fp_temp / std::tan(fp_temp /
static_cast<T
>(fs) / two) / two;
301 T A[2][2] = { { -coeffs_in.a1, -coeffs_in.a2 }, { 1.0, 0.0 } };
302 T B[2] = { 1.0, 0.0 };
303 T C[2] = { coeffs_in.b1-coeffs_in.a1, coeffs_in.b2-coeffs_in.a2 };
309 T T1[2][2] = { { (t/two)*A[0][0] + one, (t/two)*A[0][1] },
310 { (t/two)*A[1][0], (t/two)*A[1][1] + one } };
311 T T2[2][2] = { { -(t/two)*A[0][0] + one, -(t/two)*A[0][1] },
312 { -(t/two)*A[1][0], -(t/two)*A[1][1] + one} };
315 T det = T2[0][0]*T2[1][1] - T2[0][1]*T2[1][0];
316 T Ad[2][2] = { { (T1[0][0]*T2[1][1] - T1[1][0]*T2[0][1]) / det,
317 (T1[0][1]*T2[1][1] - T1[1][1]*T2[0][1]) / det },
318 { (T1[1][0]*T2[0][0] - T1[0][0]*T2[1][0]) / det,
319 (T1[1][1]*T2[0][0] - T1[0][1]*T2[1][0]) / det } };
320 T Bd[2] = { (t/r) * (B[0]*T2[1][1] - B[1]*T2[0][1]) / det,
321 (t/r) * (B[1]*T2[0][0] - B[0]*T2[1][0]) / det };
322 T Cd[2] = { (C[0]*T2[1][1] - C[1]*T2[1][0]) / det,
323 (C[1]*T2[0][0] - C[0]*T2[0][1]) / det };
324 T Dd = (B[0]*Cd[0] + B[1]*Cd[1]) * (t/two) + D;
330 internal::roots2poly(Ad, coeffs_out.a1, coeffs_out.a2);
332 T Tmp[2][2] = { { Ad[0][0]-Bd[0]*Cd[0], Ad[0][1]-Bd[0]*Cd[1] },
333 { Ad[1][0]-Bd[1]*Cd[0], Ad[1][1]-Bd[1]*Cd[1] } };
335 internal::roots2poly(Tmp, coeffs_out.b1, coeffs_out.b2);
338 coeffs_out.b1 += (Dd-one)*coeffs_out.a1;
339 coeffs_out.b2 += (Dd-one)*coeffs_out.a2;
void roots2poly(T Roots[2][2], T &poly1, T &poly2)
Roots-to-polynomial conversion.
Direct Form II recursive filter of second order.
result_type operator()(argument_type in)
Process filter on single sample.
BiQuad & operator=(const SosCoefficients< T > &c)
Assignment operator.
Cascade of filter sections.
void set(I first, I last)
Overwrite sections with new content.
result_type operator()(argument_type in)
Process all sections on single sample.
Cascade(size_type n)
Constructor.
void execute(In first, In last, Out result)
Process all sections on audio block.
Different methods to prevent denormal numbers.
Mathematical constants and helper functions.
Audio Processing Framework.
SosCoefficients< T > bilinear(LaplaceCoefficients< T > coeffs_in, int fs, int fp)
Bilinear transform.
Coefficients of analog recursive filter.
Coefficients of digital recursive filter (second order section).