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

◆ process_sample()

double MayaFlux::Nodes::Generator::Counter::process_sample ( double  input = 0.0)
overridevirtual

Processes a single data sample.

Parameters
inputThe input sample value
Returns
The processed output sample value

This is the core processing method that all nodes must implement. It takes a single input value, applies the node's transformation algorithm, and returns the resulting output value.

For generator nodes that don't require input (like oscillators or stochastic generators), the input parameter may be ignored. Note: This method does NOT mark the node as processed. That responsibility belongs to the caller, typically a chained parent node or the root node.

Implements MayaFlux::Nodes::Node.

Definition at line 59 of file Counter.cpp.

60{
61 if (m_reset_trigger) {
62 atomic_inc_modulator_count(m_reset_trigger->m_modulator_count, 1);
63 uint32_t state = m_reset_trigger->m_state.load();
64
65 double trigger_val = 0.0;
66 if (state & NodeState::PROCESSED) {
67 trigger_val = m_reset_trigger->get_last_output();
68 } else {
69 trigger_val = m_reset_trigger->process_sample(0.0);
71 }
72
73 if (trigger_val != 0.0 && m_last_trigger_value == 0.0) {
74 m_count = 0;
75 }
76 m_last_trigger_value = trigger_val;
77 }
78
79 m_wrapped = false;
80 if (m_modulo > 0) {
81 auto prev = static_cast<int32_t>(m_count);
82 int32_t next = (prev + m_step);
83 int32_t wrapped = ((next % static_cast<int32_t>(m_modulo)) + static_cast<int32_t>(m_modulo)) % static_cast<int32_t>(m_modulo);
84 m_wrapped = (wrapped < prev && m_step > 0) || (wrapped > prev && m_step < 0);
85 m_count = static_cast<uint32_t>(wrapped);
86 } else {
87 m_count += static_cast<uint32_t>(m_step);
88 }
89
90 double output = (m_modulo > 1)
91 ? static_cast<double>(m_count) / static_cast<double>(m_modulo - 1)
92 : static_cast<double>(m_count);
93
94 output *= m_amplitude;
95 m_last_output = output;
96
98 && !m_networked_node) {
99 notify_tick(output);
100 }
101
102 if (m_reset_trigger) {
103 atomic_dec_modulator_count(m_reset_trigger->m_modulator_count, 1);
105 }
106
107 return output;
108}
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
Definition Counter.cpp:119
std::shared_ptr< Node > m_reset_trigger
Definition Counter.hpp:127
double m_amplitude
Base amplitude of the generator.
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:449
bool m_networked_node
Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when t...
Definition Node.hpp:444
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:397
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:479
@ PROCESSED
Node has been processed this cycle.
Definition NodeSpec.hpp:49
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.
Definition NodeUtils.cpp:60
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
Definition NodeUtils.cpp:97
void atomic_inc_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically increments the modulator count by a specified amount.
Definition NodeUtils.cpp:87
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.
Definition NodeUtils.cpp:92

References MayaFlux::Nodes::atomic_add_flag(), MayaFlux::Nodes::atomic_dec_modulator_count(), MayaFlux::Nodes::atomic_inc_modulator_count(), MayaFlux::Nodes::Generator::Generator::m_amplitude, m_count, MayaFlux::Nodes::Node::m_fire_events_during_snapshot, MayaFlux::Nodes::Node::m_last_output, m_last_trigger_value, m_modulo, MayaFlux::Nodes::Node::m_networked_node, m_reset_trigger, MayaFlux::Nodes::Node::m_state_saved, m_step, m_wrapped, notify_tick(), MayaFlux::Nodes::PROCESSED, and MayaFlux::Nodes::try_reset_processed_state().

Referenced by process_batch().

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