MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SamplingPipeline.cpp
Go to the documentation of this file.
2
5
8
9namespace MayaFlux::Kriya {
10
12 std::shared_ptr<Kakshya::DynamicSoundStream> stream,
14 Vruta::TaskScheduler& scheduler,
15 uint32_t channel,
16 uint32_t buf_size)
17 : m_stream(std::move(stream))
18 , m_processor(std::make_shared<Buffers::StreamSliceProcessor>())
19 , m_mgr(mgr)
20 , m_capture(nullptr)
21 , m_scheduler(scheduler)
22 , m_channel(channel)
23 , m_buf_size(buf_size)
24{
25 m_buffer = std::make_shared<Buffers::AudioBuffer>(channel, buf_size);
26
27 m_buffer->set_default_processor(m_processor);
28
31
33 m_processor->set_on_end([this](size_t) {
34 if (!any_active())
35 m_pipeline->stop_continuous();
36 });
37}
38
47
52
57
59{
60 if (m_built)
61 return;
62
65
66 m_pipeline >> static_cast<BufferOperation>(m_capture);
67
68 m_pipeline->execute_buffer_rate(0);
69
70 m_built = true;
71}
72
73void SamplingPipeline::build_for(uint64_t milliseconds)
74{
75 if (m_built)
76 return;
77
80
81 m_pipeline >> static_cast<BufferOperation>(m_capture);
82
83 const double seconds = static_cast<double>(milliseconds) / 1000.0;
84 const uint64_t cycles = Vruta::seconds_to_blocks(
86
87 m_pipeline->on_complete([this] {
88 std::ranges::fill(m_buffer->get_data(), 0.0);
89 });
90
91 m_pipeline->execute_buffer_rate(cycles);
92
93 m_built = true;
94}
95
96void SamplingPipeline::rebuild_for(uint64_t milliseconds)
97{
98 if (!m_built) {
100 "SamplingPipeline::rebuild_for called before build. Use build_for instead to avoid redundant setup.");
101 return;
102 }
103 m_pipeline->stop_continuous();
104
105 const double seconds = static_cast<double>(milliseconds) / 1000.0;
106 const uint64_t cycles = Vruta::seconds_to_blocks(
108
109 m_pipeline->on_complete([this] {
110 std::ranges::fill(m_buffer->get_data(), 0.0);
111 });
112
113 m_pipeline->execute_buffer_rate(cycles);
114}
115
116void SamplingPipeline::play(size_t index)
117{
118 if (index >= m_processor->slot_count()) {
120 "SamplingPipeline::play index {} exceeds slot count {}", index, m_processor->slot_count());
121 return;
122 }
123
124 m_processor->load(index, m_processor->slice(index));
125 m_processor->bind(index);
126}
127
129{
130 m_processor->load(index, std::move(slice));
131 if (!m_built) {
132 build();
133 }
134
135 m_processor->bind(index);
136}
137
139{
140 if (index >= m_processor->slot_count()) {
142 "SamplingPipeline::play_continuous index {} exceeds slot count {}", index, m_processor->slot_count());
143 return;
144 }
145
146 auto sl = m_processor->slice(index);
147 sl.looping = true;
148 m_processor->load(index, sl);
149 m_processor->bind(index);
150}
151
153{
154 slice.looping = true;
155 m_processor->load(index, std::move(slice));
156
157 if (!m_built) {
158 build();
159 }
160
161 m_processor->bind(index);
162}
163
164void SamplingPipeline::stop(size_t index)
165{
166 if (index >= m_processor->slot_count()) {
168 "SamplingPipeline::stop index {} exceeds slot count {}", index, m_processor->slot_count());
169 return;
170 }
171 m_processor->unbind(index);
172}
173
175{
176 return m_processor->slice(index);
177}
178
180{
181 return m_processor->any_active();
182}
183
184} // namespace MayaFlux::Kriya
#define MF_RT_ERROR(comp, ctx,...)
#define MF_WARN(comp, ctx,...)
uint32_t channel
uint32_t get_buffer_size(ProcessingToken token) const
Gets the buffer size for a token.
uint64_t get_sample_rate() const
Gets the sample rate for a token (audio-specific)
bool supply_buffer_to(const std::shared_ptr< AudioBuffer > &buffer, ProcessingToken token, uint32_t channel, double mix=1.0, bool force=false)
bool remove_supplied_buffer(const std::shared_ptr< AudioBuffer > &buffer, ProcessingToken token, uint32_t channel)
Token-based multimodal buffer management system for unified data stream processing.
Fundamental unit of operation in buffer processing pipelines.
static std::shared_ptr< BufferPipeline > create(Vruta::TaskScheduler &scheduler, std::shared_ptr< Buffers::BufferManager > buffer_manager=nullptr)
Coroutine-based execution engine for composable, multi-strategy buffer processing.
CaptureBuilder & on_capture_processing()
Set processing control to ON_CAPTURE mode.
Definition Capture.cpp:89
CaptureBuilder & for_cycles(uint32_t count)
Set number of cycles to capture (enables ACCUMULATE mode).
Definition Capture.cpp:107
Fluent builder interface for constructing BufferCapture configurations.
Definition Capture.hpp:231
std::shared_ptr< Buffers::AudioBuffer > m_buffer
Kakshya::StreamSlice & slice(size_t index)
Direct access to a voice's StreamSlice for configuration.
CaptureBuilder & capture()
Access the capture operation builder for fluent configuration.
void build()
Finalize configuration and start processing.
void build_for(uint64_t milliseconds)
Finalize configuration and start processing for a bounded duration.
std::shared_ptr< Buffers::StreamSliceProcessor > m_processor
void play_continuous(size_t index=0)
Activate a voice with looping enabled.
void play(size_t index=0)
Activate a voice, resetting its cursor to loop_start.
void stop(size_t index=0)
Deactivate a voice.
BufferPipeline & pipeline()
Access the internal pipeline for fluent configuration.
std::shared_ptr< BufferPipeline > m_pipeline
void rebuild_for(uint64_t milliseconds)
Stop and restart pipeline execution for a bounded duration.
SamplingPipeline(std::shared_ptr< Kakshya::DynamicSoundStream > stream, Buffers::BufferManager &mgr, Vruta::TaskScheduler &scheduler, uint32_t channel, uint32_t buf_size)
Begin construction with a loaded stream and output channel.
Token-based multimodal task scheduling system for unified coroutine processing.
Definition Scheduler.hpp:51
@ AUDIO_BACKEND
Standard audio processing backend configuration.
@ Configuration
Configuration and parameter updates.
@ Kriya
Automatable tasks and fluent scheduling api for Nodes and Buffers.
uint64_t seconds_to_blocks(double seconds, uint32_t sample_rate, uint32_t block_size)
Convert seconds to number of processing blocks.
A bounded region of a DynamicSoundStream with associated playback parameters.