8 : m_is_processing(false)
10 , m_skip_state_management(false)
18 bool expected =
false;
20 std::memory_order_acquire, std::memory_order_relaxed)) {
25 std::this_thread::yield();
56 bool expected =
false;
62 std::memory_order_acquire, std::memory_order_relaxed)) {
84 uint32_t state = node->m_state.load();
85 double node_output = 0.0;
88 node_output = node->process_sample();
91 node_output = node->get_last_output();
94 if (node->is_output_excluded_from_graph()) {
98 if (node->needs_channel_routing()) {
99 node_output *= node->get_routing_state().amount[
m_channel];
102 sample += node_output;
116 uint32_t state = node->m_state.load();
118 node->process_sample();
132 node->request_reset_from_channel(
m_channel);
149 std::vector<double> output(num_samples);
151 for (
unsigned int i = 0; i < num_samples; i++) {
159 for (uint32_t i = 0; i < num_frames; i++) {
167 if (op.is_addition) {
168 if (m_Nodes.end() == std::ranges::find(m_Nodes, op.node)) {
169 m_Nodes.push_back(op.node);
170 uint32_t state = op.node->m_state.load();
171 state &= ~static_cast<uint32_t>(NodeState::INACTIVE);
172 state |= static_cast<uint32_t>(NodeState::ACTIVE);
173 atomic_set_flag_strong(op.node->m_state, static_cast<NodeState>(state));
176 auto it = std::ranges::find(
m_Nodes, op.node);
180 op.node->reset_processed_state();
181 uint32_t state = op.node->m_state.load();
190void RootNode::terminate_all_nodes()
192 m_request_terminate.store(
true, std::memory_order_release);
194 m_is_processing.store(
false, std::memory_order_release);
196 const auto nodes = m_Nodes;
197 for (
const auto& node : nodes) {
201 process_pending_operations();
void process_pending_operations()
Processes any pending node registration/unregistration operations.
Memory::PendingQueue< PendingOp, 2048 > m_pending_ops
Operations queued by any thread and applied in arrival order by the processing thread.
std::vector< std::shared_ptr< Node > > m_Nodes
Collection of nodes registered with this root node.
void enqueue_operation(PendingOp &&op)
Queues an operation, draining on the caller's behalf when the queue is full.
uint32_t m_channel
The processing channel index for this root node.
RootNode(ProcessingToken token=ProcessingToken::AUDIO_RATE, uint32_t channel=0)
Constructs a RootNode for a specific processing token and channel.
void unregister_node(const std::shared_ptr< Node > &node)
Removes a node from this root node.
void process_frame()
Processes a single frame from all registered nodes.
bool preprocess()
Checks if the root node can process pending operations.
void register_node(const std::shared_ptr< Node > &node)
Adds a node to this root node.
std::atomic< bool > m_is_processing
Flag indicating if the root node is currently processing nodes.
double process_sample()
Processes a single sample from all registered nodes.
bool m_skip_state_management
Flag indicating whether to skip preprocessing and post processing.
void process_batch_frame(uint32_t num_frames)
Processes multiple frames from all registered nodes.
std::atomic< bool > m_request_terminate
Flag to request termination of processing.
void postprocess()
Performs post-processing after all nodes have been processed.
std::vector< double > process_batch(uint32_t num_samples)
Processes all registered nodes and combines their outputs.
NodeState
Represents the processing state of a node in the audio graph.
@ PROCESSED
Node has been processed this cycle.
@ ACTIVE
Engine is processing this node.
@ INACTIVE
Engine is not processing this node.
@ PENDING_REMOVAL
Node is marked for removal.
ProcessingToken
Enumerates the different processing domains for nodes.
void atomic_remove_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically removes a flag from a node state.
void atomic_set_flag_strong(std::atomic< NodeState > &flag, const NodeState &desired)
Atomically sets a node state flag to a specific value.
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.
Contains the node-based computational processing system components.
void unregister_node(const std::shared_ptr< Nodes::Node > &node, const Nodes::ProcessingToken &token, uint32_t channel)
Removes a node from the root node of specified channels.
Structure for storing pending node registration/unregistration operations.