OSSIA
Open Scenario System for Interactive Application
audio_port.hpp
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
4 #include <ossia/dataflow/nodes/media.hpp>
5 #include <ossia/detail/buffer_pool.hpp>
6 #include <ossia/detail/math.hpp>
7 #include <ossia/detail/small_vector.hpp>
8 
9 #include <vector>
10 namespace ossia
11 {
12 
13 OSSIA_EXPORT
14 void ensure_vector_sizes(const audio_vector& src_vec, audio_vector& sink_vec);
15 
16 OSSIA_EXPORT
17 void mix(const audio_vector& src_vec, audio_vector& sink_vec);
18 
19 struct OSSIA_EXPORT audio_buffer_pool : object_pool<audio_channel>
20 {
21  audio_buffer_pool();
22  ~audio_buffer_pool();
23  static audio_buffer_pool& instance() noexcept;
24 
25  static void set_channels(audio_vector& samples, std::size_t channels);
26 };
27 
28 using pan_weight = ossia::small_vector<double, 2>;
29 struct inlet;
30 struct audio_port
31 {
32  static const constexpr int which = 0;
33 
34  audio_port() noexcept { set_channels(2); }
35 
36  audio_port(const audio_port& other) noexcept { *this = other; }
37 
38  audio_port(audio_port&& other) noexcept
39  : m_samples{std::move(other.m_samples)}
40  {
41  }
42 
43  audio_port& operator=(const audio_port& other) noexcept
44  {
45  audio_buffer_pool::set_channels(m_samples, other.channels());
46  for(std::size_t c = 0; c < other.channels(); c++)
47  {
48  channel(c) = other.channel(c);
49  }
50  return *this;
51  }
52 
53  audio_port& operator=(audio_port&& other) noexcept
54  {
55  m_samples = std::move(other.m_samples);
56  other.set_channels(2);
57 
58  return *this;
59  }
60 
61  audio_channel& channel(std::size_t i) noexcept { return m_samples[i]; }
62 
63  [[nodiscard]] const audio_channel& channel(std::size_t i) const noexcept
64  {
65  return m_samples[i];
66  }
67 
68  [[nodiscard]] std::size_t channels() const noexcept { return m_samples.size(); }
69 
70  [[nodiscard]] bool empty() const noexcept { return m_samples.empty(); }
71 
72  void set_channels(std::size_t channels)
73  {
74  return audio_buffer_pool::set_channels(m_samples, channels);
75  }
76 
77  operator ossia::mutable_audio_span<double>() noexcept
78  {
79  return {m_samples.begin(), m_samples.end()};
80  }
81 
82  operator ossia::audio_span<double>() const noexcept
83  {
84  return {m_samples.begin(), m_samples.end()};
85  }
86 
87  audio_vector& get() noexcept { return m_samples; }
88  [[nodiscard]] const audio_vector& get() const noexcept { return m_samples; }
89 
90  [[nodiscard]] auto begin() const noexcept { return m_samples.begin(); }
91  [[nodiscard]] auto end() const noexcept { return m_samples.end(); }
92  [[nodiscard]] auto cbegin() const noexcept { return m_samples.cbegin(); }
93  [[nodiscard]] auto cend() const noexcept { return m_samples.cend(); }
94  [[nodiscard]] auto rbegin() const noexcept { return m_samples.rbegin(); }
95  [[nodiscard]] auto rend() const noexcept { return m_samples.rend(); }
96  [[nodiscard]] auto crbegin() const noexcept { return m_samples.crbegin(); }
97  [[nodiscard]] auto crend() const noexcept { return m_samples.crend(); }
98  auto begin() noexcept { return m_samples.begin(); }
99  auto end() noexcept { return m_samples.end(); }
100  auto cbegin() noexcept { return m_samples.cbegin(); }
101  auto cend() noexcept { return m_samples.cend(); }
102  auto rbegin() noexcept { return m_samples.rbegin(); }
103  auto rend() noexcept { return m_samples.rend(); }
104  auto crbegin() noexcept { return m_samples.crbegin(); }
105  auto crend() noexcept { return m_samples.crend(); }
106 
107 private:
108  friend void ensure_vector_sizes(const audio_vector& src_vec, audio_vector& sink_vec);
109  audio_vector m_samples;
110 };
111 
112 #if BOOST_VERSION >= 107200
113 static_assert(noexcept(audio_port{}));
114 #endif
115 
116 struct audio_delay_line
117 {
118  std::vector<audio_vector> samples;
119 };
120 
121 }
Definition: git_info.h:7