2#include <ossia/detail/config.hpp>
4#include <ossia/dataflow/nodes/media.hpp>
5#include <ossia/detail/buffer_pool.hpp>
7#include <ossia/detail/small_vector.hpp>
14void ensure_vector_sizes(
const audio_vector& src_vec, audio_vector& sink_vec);
17void mix(
const audio_vector& src_vec, audio_vector& sink_vec);
19struct OSSIA_EXPORT audio_buffer_pool :
private object_pool<audio_channel>
24 using object_pool::acquire;
26 void release(audio_channel&& b)
29 buffers.enqueue(std::move(b));
32 static audio_buffer_pool& instance() noexcept;
34 static
void set_channels(audio_vector& samples, std::
size_t channels);
37using pan_weight =
ossia::small_vector<
double, 2>;
41 static const constexpr int which = 0;
43 audio_port() noexcept { set_channels(2); }
45 audio_port(
const audio_port& other)
noexcept { *
this = other; }
47 audio_port(audio_port&& other) noexcept
48 : m_samples{std::move(other.m_samples)}
52 audio_port& operator=(
const audio_port& other)
noexcept
54 audio_buffer_pool::set_channels(m_samples, other.channels());
55 for(std::size_t c = 0; c < other.channels(); c++)
57 const auto& src = other.channel(c);
58 channel(c).assign(src.begin(), src.end());
63 audio_port& operator=(audio_port&& other)
noexcept
65 m_samples = std::move(other.m_samples);
66 other.set_channels(2);
71 audio_channel& channel(std::size_t i)
noexcept {
return m_samples[i]; }
73 [[nodiscard]]
const audio_channel& channel(std::size_t i)
const noexcept
78 [[nodiscard]] std::size_t channels() const noexcept {
return m_samples.size(); }
80 [[nodiscard]]
bool empty() const noexcept {
return m_samples.empty(); }
82 void set_channels(std::size_t channels)
84 return audio_buffer_pool::set_channels(m_samples, channels);
87 operator ossia::mutable_audio_span<double>() noexcept
89 return {m_samples.begin(), m_samples.end()};
92 operator ossia::audio_span<double>() const noexcept
94 return {m_samples.begin(), m_samples.end()};
97 audio_vector& get() noexcept {
return m_samples; }
98 [[nodiscard]]
const audio_vector& get() const noexcept {
return m_samples; }
100 [[nodiscard]]
auto begin() const noexcept {
return m_samples.begin(); }
101 [[nodiscard]]
auto end() const noexcept {
return m_samples.end(); }
102 [[nodiscard]]
auto cbegin() const noexcept {
return m_samples.cbegin(); }
103 [[nodiscard]]
auto cend() const noexcept {
return m_samples.cend(); }
104 [[nodiscard]]
auto rbegin() const noexcept {
return m_samples.rbegin(); }
105 [[nodiscard]]
auto rend() const noexcept {
return m_samples.rend(); }
106 [[nodiscard]]
auto crbegin() const noexcept {
return m_samples.crbegin(); }
107 [[nodiscard]]
auto crend() const noexcept {
return m_samples.crend(); }
108 auto begin() noexcept {
return m_samples.begin(); }
109 auto end() noexcept {
return m_samples.end(); }
110 auto cbegin() noexcept {
return m_samples.cbegin(); }
111 auto cend() noexcept {
return m_samples.cend(); }
112 auto rbegin() noexcept {
return m_samples.rbegin(); }
113 auto rend() noexcept {
return m_samples.rend(); }
114 auto crbegin() noexcept {
return m_samples.crbegin(); }
115 auto crend() noexcept {
return m_samples.crend(); }
118 friend void ensure_vector_sizes(
const audio_vector& src_vec, audio_vector& sink_vec);
119 audio_vector m_samples;
122#if BOOST_VERSION >= 107200
123static_assert(
noexcept(audio_port{}));
126struct audio_delay_line
128 std::vector<audio_vector> samples;