Wayverb
frequency_domain_envelope.h
1 #pragma once
2 
3 #include "utilities/mapping_iterator_adapter.h"
4 #include "utilities/range.h"
5 
6 #include <vector>
7 
8 namespace wayverb {
9 namespace waveguide {
10 
13 public:
14  struct point final {
15  double frequency;
16  double amplitude;
17  };
18 
19  using const_iterator = std::vector<point>::const_iterator;
20 
21  const_iterator cbegin() const;
22  const_iterator cend() const;
23 
24  void insert(point p);
25  const_iterator erase(const_iterator b, const_iterator e);
26 
27  void enforce_minimum_spacing(double spacing);
28 
29 private:
30  bool check_invariant() const;
31  void throw_if_invariant_violated() const;
32 
33  std::vector<point> points;
34 };
35 
36 template <typename It>
37 void add_points(frequency_domain_envelope& env, It b, It e) {
38  for (; b != e; ++b) {
39  env.insert(*b);
40  }
41 }
42 
43 constexpr double get_frequency(const frequency_domain_envelope::point& t) {
44  return t.frequency;
45 }
46 
47 constexpr double get_amplitude(const frequency_domain_envelope::point& t) {
48  return t.amplitude;
49 }
50 
51 constexpr bool compare_points(const frequency_domain_envelope::point& a,
53  return get_frequency(a) < get_frequency(b);
54 }
55 
56 template <typename It>
57 constexpr auto make_frequency_iterator(It it) {
58  return util::make_mapping_iterator_adapter(std::move(it), get_frequency);
59 }
60 
61 template <typename It>
62 constexpr auto make_amplitude_iterator(It it) {
63  return util::make_mapping_iterator_adapter(std::move(it), get_amplitude);
64 }
65 
66 void remove_outside_frequency_range(frequency_domain_envelope& env,
68 
69 template <size_t N>
70 auto make_frequency_domain_envelope(const std::array<double, N>& frequency,
71  const std::array<double, N>& amplitude) {
73 
74  for (auto i = 0; i != N; ++i) {
75  ret.insert(
76  frequency_domain_envelope::point{frequency[i], amplitude[i]});
77  }
78 
79  return ret;
80 }
81 
82 } // namespace waveguide
83 } // namespace wayverb
Invariant: points are in ascending frequency order.
Definition: frequency_domain_envelope.h:12
Definition: capsule_base.h:9
Definition: frequency_domain_envelope.h:14