Wayverb
envelope.h
1 #pragma once
2 
3 #include "utilities/range.h"
4 
5 #include <array>
6 #include <cmath>
7 
8 namespace frequency_domain {
9 
10 double max_width_factor(util::range<double> r, double step);
11 double width_factor(util::range<double> r, size_t bands, double overlap);
12 
14 
15 double lower_band_edge(double p, double P, size_t l);
16 double upper_band_edge(double p, double P, size_t l);
17 
18 double band_edge_frequency(size_t band, size_t bands, util::range<double> r);
19 double band_centre_frequency(size_t band, size_t bands, util::range<double> r);
20 
22 
23 template <size_t... Ix>
24 auto band_edges(util::range<double> r, std::index_sequence<Ix...>) {
25  return std::array<double, sizeof...(Ix)>{
26  {band_edge_frequency(Ix, sizeof...(Ix) - 1, r)...}};
27 }
28 
29 template <size_t bands>
30 auto band_edges(util::range<double> r) {
31  return band_edges(r, std::make_index_sequence<bands + 1>{});
32 }
33 
35 
36 template <typename T, size_t... Ix>
37 auto bandwidths(const std::array<T, sizeof...(Ix) + 1>& edges,
38  std::index_sequence<Ix...>) {
39  using value_type = decltype(edge(edges[1]) - edge(edges[0]));
40  return std::array<value_type, sizeof...(Ix)>{
41  {edge(edges[Ix + 1]) - edge(edges[Ix])...}};
42 }
43 
44 template <typename T, size_t edges>
45 auto bandwidths(const std::array<T, edges>& e) {
46  return bandwidths(e, std::make_index_sequence<edges - 1>{});
47 }
48 
50 
51 template <size_t... Ix>
52 auto band_centres(util::range<double> r, std::index_sequence<Ix...>) {
53  return std::array<double, sizeof...(Ix)>{
54  {band_centre_frequency(Ix, sizeof...(Ix), r)...}};
55 }
56 
57 template <size_t bands>
58 auto band_centres(util::range<double> r) {
59  return band_centres(r, std::make_index_sequence<bands>{});
60 }
61 
63 
70 double compute_bandpass_magnitude(double frequency,
72  double width_factor,
73  size_t l = 0);
74 
75 double compute_lopass_magnitude(double frequency,
76  double edge,
77  double width_factor,
78  size_t l = 0);
79 
80 double compute_hipass_magnitude(double frequency,
81  double edge,
82  double width_factor,
83  size_t l = 0);
84 
85 } // namespace frequency_domain
Definition: buffer.h:5