Wayverb
convolver.h
1 #pragma once
2 
3 #include "frequency_domain/buffer.h"
4 
5 #include <vector>
6 
7 namespace frequency_domain {
8 
11 class convolver final {
12 public:
13  explicit convolver(size_t fft_length);
14 
15  convolver(const convolver&) = delete;
16  convolver& operator=(const convolver&) = delete;
17  convolver(convolver&&) = delete;
18  convolver& operator=(convolver&&) = delete;
19 
20  ~convolver() noexcept;
21 
22  template <typename T, typename U>
23  auto convolve(const T& a, const U& b) {
24  using std::begin;
25  using std::end;
26  return convolve(begin(a), end(a), begin(b), end(b));
27  }
28 
29  template <typename It, typename Jt>
30  auto convolve(It a_begin, It a_end, Jt b_begin, Jt b_end) {
31  const auto d0 = std::distance(a_begin, a_end);
32  const auto d1 = std::distance(b_begin, b_end);
33  if (d0 + d1 - 1 != get_fft_length()) {
34  throw std::runtime_error{"Inputs must sum to FFT_LENGTH + 1."};
35  }
36 
37  r2c_i_.zero();
38  std::copy(a_begin, a_end, r2c_i_.begin());
39  forward_fft_a();
40 
41  r2c_i_.zero();
42  std::copy(b_begin, b_end, r2c_i_.begin());
43  forward_fft_b();
44 
45  return convolve_impl();
46  }
47 
48  size_t get_fft_length() const;
49 
50 private:
51  void forward_fft_a();
52  void forward_fft_b();
53  std::vector<float> convolve_impl();
54 
55  rbuf r2c_i_;
56 
57  class impl;
58  std::unique_ptr<impl> pimpl_;
59 };
60 
61 } // namespace frequency_domain
Definition: convolver.h:11
Definition: convolver.cpp:7
Definition: buffer.h:5