Wayverb
filter.h
1 #pragma once
2 
3 #include "frequency_domain/buffer.h"
4 
5 #include <complex>
6 #include <functional>
7 #include <stdexcept>
8 
9 namespace frequency_domain {
10 
12 class filter final {
13 public:
17  explicit filter(size_t signal_length);
18 
19  filter(const filter&) = delete;
20  filter& operator=(const filter&) = delete;
21  filter(filter&&) = delete;
22  filter& operator=(filter&&) = delete;
23 
24  ~filter() noexcept;
25 
31  using callback =
32  std::function<std::complex<float>(std::complex<float>, float)>;
33 
40  template <typename In, typename Out>
41  void run(In begin, In end, Out output_it, const callback& callback) {
42  const auto dist = std::distance(begin, end);
43 
44  if (dist > 0) {
45  if (dist > rbuf_.size()) {
46  throw std::runtime_error{"Filter input signal is too long."};
47  }
48 
49  rbuf_.zero();
50  std::copy(begin, end, rbuf_.begin());
51  filter_impl(callback);
52  std::copy(rbuf_.begin(), rbuf_.begin() + dist, output_it);
53  }
54  }
55 
56 private:
57  void filter_impl(const callback& callback);
58 
59  rbuf rbuf_;
60 
61  class impl;
62  std::unique_ptr<impl> pimpl_;
63 };
64 
65 } // namespace frequency_domain
std::function< std::complex< float >(std::complex< float >, float)> callback
Definition: filter.h:32
Structured this way so that I can keep all fftw linkage internal.
Definition: filter.h:12
void run(In begin, In end, Out output_it, const callback &callback)
Definition: filter.h:41
Definition: buffer.h:5
Definition: filter.cpp:10
filter(size_t signal_length)
Definition: filter.cpp:57