Wayverb
kernel.h
1 #pragma once
2 
3 #include "utilities/aligned/vector.h"
4 
5 #include <cmath>
6 #include <stdexcept>
7 #include <vector>
8 
9 namespace wayverb {
10 namespace core {
11 namespace kernels {
12 
13 double gaussian(double t, double o);
14 double sin_modulated_gaussian(double t, double o);
15 double gaussian_dash(double t, double o);
16 
17 template <typename T, typename Func>
18 util::aligned::vector<T> gauss_like_kernel(double fc, const Func& func) {
19  const auto o = 1.0 / (2.0 * M_PI * fc);
20  const ptrdiff_t delay = std::ceil(8.0 * o);
21  const auto l = delay * 2 + 1;
22  util::aligned::vector<T> ret;
23  ret.reserve(l);
24  for (ptrdiff_t i = 0; i != l; ++i) {
25  ret.emplace_back(func(i - delay, o));
26  }
27  return ret;
28 }
29 
30 template <typename T = float>
31 auto gen_gaussian(double fc) {
32  return gauss_like_kernel<T>(fc, gaussian);
33 }
34 
35 template <typename T = float>
36 auto gen_sin_modulated_gaussian(double fc) {
37  return gauss_like_kernel<T>(fc, sin_modulated_gaussian);
38 }
39 
40 template <typename T = float>
41 auto gen_gaussian_dash(double fc) {
42  return gauss_like_kernel<T>(fc, gaussian_dash);
43 }
44 
47 double ricker(double t, double f);
48 
49 template <typename T = float>
50 util::aligned::vector<T> gen_ricker(double fc) {
51  const ptrdiff_t delay = std::ceil(1.0 / fc);
52  const auto l = delay * 2 + 1;
53  util::aligned::vector<T> ret;
54  ret.reserve(l);
55  for (ptrdiff_t i = 0; i != l; ++i) {
56  ret.emplace_back(ricker(i - delay, fc));
57  }
58  return ret;
59 }
60 
61 } // namespace kernels
62 } // namespace core
63 } // namespace wayverb
Definition: traits.cpp:2
Definition: capsule_base.h:9