2#include <ossia/dataflow/graph_node.hpp>
3#include <ossia/dataflow/nodes/sound.hpp>
4#include <ossia/dataflow/nodes/sound_utils.hpp>
11 void set_start(std::size_t v) { start = v; }
13 void set_upmix(std::size_t v) { upmix = v; }
15 [[nodiscard]] std::size_t channels()
const {
return m_data.size(); }
17 [[nodiscard]] std::size_t duration()
const
19 return m_data.empty() ? 0 : m_data[0].size();
22 void transport(time_value date)
24 info->m_resampler.transport(to_sample(date, m_dataSampleRate));
28 void set_sound(audio_array data)
30 m_handle = std::make_shared<audio_data>();
31 m_handle->data = std::move(data);
34 m_dataSampleRate = 44100;
35 m_data.assign(m_handle->data.begin(), m_handle->data.end());
36 info->m_resampler.reset(
37 0, audio_stretch_mode::None, m_handle->data.size(), m_dataSampleRate);
41 void set_sound(
const audio_handle& hdl,
int channels,
int sampleRate)
47 m_dataSampleRate = sampleRate;
48 m_data.assign(m_handle->data.begin(), m_handle->data.end());
54 const int64_t start,
const int64_t samples_to_write,
55 T**
const audio_array)
const noexcept
57 read_audio_from_buffer(
58 m_data, start, samples_to_write, info->m_start_offset_samples,
59 info->m_loop_duration_samples, info->m_loops, audio_array);
62 void run(
const ossia::token_request& t, ossia::exec_state_facade e)
noexcept
71 const std::size_t chan = m_data.size();
72 const std::size_t len = m_data[0].size();
73 ossia::audio_port& ap = *audio_out;
74 ap.set_channels(std::max(this->upmix, chan));
76 const auto [samples_to_read, samples_to_write]
77 = snd::sample_info(e.bufferSize(), e.modelToSamples(), t);
78 if(samples_to_read == 0)
80 if(samples_to_write <= 0)
83 assert(samples_to_write > 0);
85 const auto samples_offset = t.physical_start(e.modelToSamples());
88 if(t.prev_date < info->m_prev_date)
93 if(t.prev_date != 0_tv)
95 transport(t.prev_date);
100 info->m_prev_date = 0_tv;
105 transport(t.prev_date);
109 for(std::size_t i = 0; i < chan; ++i)
111 ap.channel(i).resize(e.bufferSize());
114 double stretch_ratio = info->update_stretch(t, e);
117 info->m_resampler.run(
118 *
this, t, e, stretch_ratio, chan, len, samples_to_read, samples_to_write,
121 for(std::size_t i = 0; i < chan; i++)
124 t.start_discontinuous, t.end_discontinuous, ap.channel(i), samples_offset,
128 ossia::snd::perform_upmix(this->upmix, chan, ap);
129 ossia::snd::perform_start_offset(this->start, ap);
131 info->m_prev_date = t.date;
135 sound_processing_info* info{};
136 ossia::audio_port* audio_out{};
138 audio_span<float> m_data{};
143 std::size_t m_dataSampleRate{};
144 audio_handle m_handle{};
The time_value class.
Definition ossia/editor/scenario/time_value.hpp:30