MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ extract_multiple_samples()

std::vector< double > MayaFlux::Buffers::extract_multiple_samples ( const std::shared_ptr< Nodes::Node > &  node,
size_t  num_samples 
)

Extract multiple samples from a node into a vector.

Definition at line 184 of file BufferUtils.cpp.

187{
188 std::vector<double> output(num_samples);
189
190 if (!node) {
191 MF_RT_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
192 "extract_multiple_samples: null node");
193 return output;
194 }
195
196 static std::atomic<uint64_t> s_context_counter { 1 };
197 uint64_t my_context_id = s_context_counter.fetch_add(1, std::memory_order_relaxed);
198
199 const auto state = node->m_state.load(std::memory_order_acquire);
200
201 // Fast path: inactive node
202 if (state == Utils::NodeState::INACTIVE && !node->is_buffer_processed()) {
203 for (size_t i = 0; i < num_samples; i++) {
204 output[i] = node->process_sample(0.F);
205 }
206 node->mark_buffer_processed();
207 return output;
208 }
209
210 bool claimed = node->try_claim_snapshot_context(my_context_id);
211
212 if (claimed) {
213 try {
214 node->save_state();
215
216 for (size_t i = 0; i < num_samples; i++) {
217 output[i] = node->process_sample(0.F);
218 }
219
220 node->restore_state();
221
222 if (node->is_buffer_processed()) {
223 node->request_buffer_reset();
224 }
225
226 node->release_snapshot_context(my_context_id);
227
228 } catch (const std::exception& e) {
229 node->release_snapshot_context(my_context_id);
230 MF_RT_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
231 "Error processing node: {}", e.what());
232 output.clear();
233 }
234 } else {
235 uint64_t active_context = node->get_active_snapshot_context();
236
237 if (!wait_for_snapshot_completion(node, active_context)) {
238 output.clear();
239 return output;
240 }
241
242 node->save_state();
243 for (size_t i = 0; i < num_samples; i++) {
244 output[i] = node->process_sample(0.F);
245 }
246 node->restore_state();
247
248 if (node->is_buffer_processed()) {
249 node->request_buffer_reset();
250 }
251 }
252
253 return output;
254}
#define MF_RT_ERROR(comp, ctx,...)
bool wait_for_snapshot_completion(const std::shared_ptr< Nodes::Node > &node, uint64_t active_context_id, int max_spins)
Wait for an active snapshot context to complete using exponential backoff.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Utils::INACTIVE, MF_RT_ERROR, and wait_for_snapshot_completion().

Referenced by MayaFlux::Buffers::NodeSourceProcessor::get_node_data().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: