Wayverb
filters.h
1 #pragma once
2 
3 #include "waveguide/cl/filter_structs.h"
4 
5 #include "utilities/decibels.h"
6 
7 #include <cmath>
8 #include <functional>
9 
10 namespace wayverb {
11 namespace waveguide {
12 
16 struct filter_descriptor final {
17  double gain{0};
18  double centre{0};
19  double Q{0};
20 };
21 
22 template <typename Callback, size_t... Ix>
23 inline biquad_coefficients_array get_biquads_array(
24  const Callback& callback,
25  const std::array<filter_descriptor, biquad_sections>& n,
26  std::index_sequence<Ix...>) {
27  return biquad_coefficients_array{{callback(std::get<Ix>(n))...}};
28 }
29 
30 template <typename Callback>
31 inline biquad_coefficients_array get_biquads_array(
32  const Callback& callback,
33  const std::array<filter_descriptor, biquad_sections>& n) {
34  return get_biquads_array(
35  callback, n, std::make_index_sequence<biquad_sections>{});
36 }
37 
38 coefficients_biquad get_peak_coefficients(const filter_descriptor& n);
39 
40 biquad_coefficients_array get_peak_biquads_array(
41  const std::array<filter_descriptor, biquad_sections>& n);
42 
43 template <size_t A, size_t B>
44 constexpr coefficients<A + B> convolve(const coefficients<A>& a,
45  const coefficients<B>& b) {
46  auto ret = coefficients<A + B>{};
47  for (auto i = 0; i != A + 1; ++i) {
48  for (auto j = 0; j != B + 1; ++j) {
49  ret.b[i + j] += a.b[i] * b.b[j];
50  ret.a[i + j] += a.a[i] * b.a[j];
51  }
52  }
53  return ret;
54 }
55 
57 
58 } // namespace waveguide
59 } // namespace wayverb
Several sets of biquad parameters.
Definition: filter_structs.h:78
Definition: capsule_base.h:9