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

◆ extract_node_samples()

void MayaFlux::Nodes::Network::NodeNetwork::extract_node_samples ( const std::shared_ptr< Nodes::Node > &  node,
std::vector< double > &  buffer,
size_t &  buffer_pos,
size_t  num_samples 
)
staticprotected

Extract num_samples from node into buffer using snapshot guard.

Parameters
nodeSource node to extract from
bufferOutput buffer, resized to num_samples and filled
buffer_posPosition counter, reset to 0 before extraction

Definition at line 41 of file NodeNetwork.cpp.

46{
47 buffer.assign(num_samples, 0.0);
48 buffer_pos = 0;
49
50 if (!node)
51 return;
52
53 static std::atomic<uint64_t> s_ctx { 1 };
54 uint64_t my_ctx = s_ctx.fetch_add(1, std::memory_order_relaxed);
55
56 const auto state = node->m_state.load(std::memory_order_acquire);
57
58 if (state == NodeState::INACTIVE && !node->is_buffer_processed()) {
59 for (size_t i = 0; i < num_samples; ++i)
60 buffer[i] = node->process_sample(0.0);
61 node->mark_buffer_processed();
62 return;
63 }
64
65 bool claimed = node->try_claim_snapshot_context(my_ctx);
66
67 if (claimed) {
68 try {
69 node->save_state();
70 for (size_t i = 0; i < num_samples; ++i)
71 buffer[i] = node->process_sample(0.0);
72 node->restore_state();
73 if (node->is_buffer_processed())
74 node->request_buffer_reset();
75 node->release_snapshot_context(my_ctx);
76 } catch (...) {
77 node->release_snapshot_context(my_ctx);
78 buffer.assign(num_samples, 0.0);
79 }
80 } else {
81 uint64_t active = node->get_active_snapshot_context();
83 return;
84 node->save_state();
85 for (size_t i = 0; i < num_samples; ++i)
86 buffer[i] = node->process_sample(0.0);
87 node->restore_state();
88 if (node->is_buffer_processed())
89 node->request_buffer_reset();
90 }
91}
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.
@ INACTIVE
Engine is not processing this node.
Definition NodeSpec.hpp:44

References MayaFlux::Nodes::INACTIVE, and MayaFlux::Buffers::wait_for_snapshot_completion().

Referenced by MayaFlux::Nodes::Network::ModalNetwork::process_batch(), and MayaFlux::Nodes::Network::WaveguideNetwork::process_batch().

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