Wayverb
dc_blocker.h
1 #pragma once
2 
3 #include "core/filters_common.h"
4 #include "core/schroeder.h"
5 
6 #include "utilities/aligned/vector.h"
7 
8 namespace wayverb {
9 namespace core {
10 namespace filter {
11 
12 class delay_line final {
13 public:
14  delay_line() = default;
15  delay_line(int length);
16 
17  double& operator[](size_t i);
18  const double& operator[](size_t i) const;
19  void push(double x);
20 
21  void clear();
22 
23 private:
24  util::aligned::vector<double> data;
25  size_t index;
26 };
27 
29 
30 class moving_average final {
31 public:
32  moving_average() = default;
33  moving_average(int d);
34 
35  double filter(double x);
36  void clear();
37 
38  double get_index(size_t i) const;
39 
40 private:
41  int d;
43  double single_delay;
44 };
45 
47 
48 template <int modules>
49 class n_moving_averages final {
50 public:
51  n_moving_averages() = default;
52  n_moving_averages(int d) {
53  std::fill(averages.begin(), averages.end(), moving_average(d));
54  }
55 
56  double filter(double x) {
57  for (auto& i : averages) {
58  x = i.filter(x);
59  }
60  return x;
61  }
62 
63  void clear() {
64  for (auto& i : averages) {
65  i.clear();
66  }
67  }
68 
69  const moving_average& get_averager() const { return averages.front(); }
70 
71 private:
72  std::array<moving_average, modules> averages;
73 };
74 
76 
77 class linear_dc_blocker final {
78 public:
79  explicit linear_dc_blocker(int d = 128);
80 
81  double filter(double x);
82 
83  template <typename It>
84  util::aligned::vector<float> filter(It begin, It end) {
85  util::aligned::vector<float> ret(begin, end);
86  std::for_each(std::begin(ret), std::end(ret), [this](auto& i) {
87  i = this->filter(i);
88  });
89  return ret;
90  }
91 
92  void clear();
93 
94 private:
95  int d;
96  n_moving_averages<2> moving_averages;
97 };
98 
100 
102 public:
103  explicit extra_linear_dc_blocker(int d = 128);
104 
105  double filter(double x);
106 
107  template <typename It>
108  util::aligned::vector<float> filter(It begin, It end) {
109  util::aligned::vector<float> ret(begin, end);
110  std::for_each(std::begin(ret), std::end(ret), [this](auto& i) {
111  i = this->filter(i);
112  });
113  return ret;
114  }
115 
116  void clear();
117 
118 private:
119  int d;
121  n_moving_averages<4> moving_averages;
122 };
123 
125 
132 template <typename It>
133 void block_dc(It begin, It end, double sr) {
134  auto hipass = make_series_biquads(
135  compute_hipass_butterworth_coefficients<1>(10, sr));
136  run_two_pass(hipass, begin, end);
137 }
138 
139 } // namespace filter
140 } // namespace core
141 } // namespace wayverb
Definition: dc_blocker.h:77
Definition: traits.cpp:2
Definition: capsule_base.h:9
Definition: dc_blocker.h:30
Definition: dc_blocker.h:49
Definition: dc_blocker.h:12