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

◆ update_buffer_with_node_data()

void MayaFlux::Buffers::update_buffer_with_node_data ( const std::shared_ptr< Nodes::Node > &  node,
std::span< double >  buffer,
double  mix 
)

Apply node output to an existing buffer with mixing.

Definition at line 257 of file BufferUtils.cpp.

261{
262 if (!node) {
263 MF_RT_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
264 "apply_to_buffer: null node");
265 return;
266 }
267
268 static std::atomic<uint64_t> s_context_counter { 1 };
269 uint64_t my_context_id = s_context_counter.fetch_add(1, std::memory_order_relaxed);
270
271 const auto state = node->m_state.load(std::memory_order_acquire);
272
273 if (state == Nodes::NodeState::INACTIVE && !node->is_buffer_processed()) {
274 for (double& sample : buffer) {
275 sample += node->process_sample(0.F) * mix;
276 }
277 node->mark_buffer_processed();
278 return;
279 }
280
281 bool claimed = node->try_claim_snapshot_context(my_context_id);
282
283 if (claimed) {
284 try {
285 node->save_state();
286
287 for (double& sample : buffer) {
288 sample += node->process_sample(0.F) * mix;
289 }
290
291 node->restore_state();
292
293 if (node->is_buffer_processed()) {
294 node->request_buffer_reset();
295 }
296
297 node->release_snapshot_context(my_context_id);
298
299 } catch (const std::exception& e) {
300 node->release_snapshot_context(my_context_id);
301 MF_RT_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
302 "Error processing node: {}", e.what());
303 }
304 } else {
305 uint64_t active_context = node->get_active_snapshot_context();
306
307 if (!wait_for_snapshot_completion(node, active_context)) {
308 return;
309 }
310
311 node->save_state();
312 for (double& sample : buffer) {
313 sample += node->process_sample(0.F) * mix;
314 }
315 node->restore_state();
316
317 if (node->is_buffer_processed()) {
318 node->request_buffer_reset();
319 }
320 }
321}
#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.
std::vector< double > mix(const std::vector< std::vector< double > > &streams)
Mix multiple data streams with equal weighting.
Definition Yantra.cpp:1021

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

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

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