Wayverb
waveguide.h
1 #pragma once
2 
3 #include "combined/model/member.h"
4 
5 #include "waveguide/simulation_parameters.h"
6 
7 #include "hrtf/multiband.h"
8 
9 #include "cereal/types/base_class.hpp"
10 
11 namespace wayverb {
12 namespace combined {
13 namespace model {
14 
15 class single_band_waveguide final : public basic_member<single_band_waveguide> {
16 public:
17  explicit single_band_waveguide(double cutoff = 500,
18  double usable_portion = 0.6);
19 
20  void set_cutoff(double cutoff);
21  void set_usable_portion(double usable);
22 
24 
25  template <typename Archive>
26  void serialize(Archive& archive) {
27  archive(data_.cutoff, data_.usable_portion);
28  }
29 
30  NOTIFYING_COPY_ASSIGN_DECLARATION(single_band_waveguide)
31 private:
32  inline void swap(single_band_waveguide& other) noexcept {
33  using std::swap;
34  swap(data_, other.data_);
35  };
36 
38 };
39 
40 bool operator==(const single_band_waveguide& a, const single_band_waveguide& b);
41 bool operator!=(const single_band_waveguide& a, const single_band_waveguide& b);
42 
44 
46  : public basic_member<multiple_band_waveguide> {
47 public:
48  explicit multiple_band_waveguide(size_t bands = 2,
49  double cutoff = 500,
50  double usable_portion = 0.6);
51 
52  void set_bands(size_t bands);
53  void set_cutoff(double cutoff);
54  void set_usable_portion(double usable);
55 
57 
58  template <typename Archive>
59  void serialize(Archive& archive) {
60  archive(data_.bands, data_.cutoff, data_.usable_portion);
61  }
62 
63  NOTIFYING_COPY_ASSIGN_DECLARATION(multiple_band_waveguide)
64 private:
65  inline void swap(multiple_band_waveguide& other) noexcept {
66  using std::swap;
67  swap(data_, other.data_);
68  };
69 
70  static const frequency_domain::edges_and_width_factor<9> band_params_;
71 
72  void maintain_valid_cutoff();
73 
75 };
76 
77 bool operator==(const multiple_band_waveguide& a,
78  const multiple_band_waveguide& b);
79 bool operator!=(const multiple_band_waveguide& a,
80  const multiple_band_waveguide& b);
81 
83 
84 class waveguide final : public owning_member<waveguide,
85  single_band_waveguide,
86  multiple_band_waveguide> {
87 public:
88  enum class mode { single, multiple };
89 
90  explicit waveguide(
91  mode mode = mode::single,
94 
97 
98  void set_mode(mode mode);
99  mode get_mode() const;
100 
101  template <typename Archive>
102  void serialize(Archive& archive) {
103  archive(cereal::base_class<base_type>(this), mode_);
104  }
105 
106  using single_band_t = single_band_waveguide;
107  using multiple_band_t = multiple_band_waveguide;
108 
109  const auto& single_band() const { return get<0>(); }
110  auto& single_band() { return get<0>(); }
111 
112  const auto& multiple_band() const { return get<1>(); }
113  auto& multiple_band() { return get<1>(); }
114 
115  NOTIFYING_COPY_ASSIGN_DECLARATION(waveguide)
116 private:
117  inline void swap(waveguide& other) noexcept {
118  using std::swap;
119  swap(mode_, other.mode_);
120  };
121 
122  mode mode_ = mode::single;
123 };
124 
125 bool operator==(const waveguide& a, const waveguide& b);
126 bool operator!=(const waveguide& a, const waveguide& b);
127 
128 double compute_sampling_frequency(const waveguide& waveguide);
129 
130 } // namespace model
131 } // namespace combined
132 } // namespace wayverb
Definition: waveguide.h:84
double usable_portion
Definition: simulation_parameters.h:15
Definition: simulation_parameters.h:9
double cutoff
The actual cutoff of the waveguide mesh in Hz.
Definition: simulation_parameters.h:11
Definition: capsule_base.h:9