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

◆ process_sample()

double MayaFlux::Nodes::Generator::Logic::process_sample ( double  input = 0.)
overridevirtual

Processes a single input sample through the logic function.

Parameters
inputInput value to evaluate
Returns
1.0 for true result, 0.0 for false result

Evaluates the input according to the configured logic operation and computational model, producing a binary output (0.0 or 1.0).

Implements MayaFlux::Nodes::Node.

Definition at line 108 of file Logic.cpp.

109{
110 bool result = false;
111 m_edge_detected = false;
112
113 if (m_input_node) {
114 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
115 uint32_t state = m_input_node->m_state.load();
116 if (state & NodeState::PROCESSED) {
117 input += m_input_node->get_last_output();
118 } else {
119 input = m_input_node->process_sample(input);
121 }
122 }
123
124 bool current_bool = input > m_threshold;
125 bool previous_bool = m_last_output > 0.5;
126
127 switch (m_mode) {
129 switch (m_operator) {
131 result = current_bool;
132 break;
133
135 if (input > m_high_threshold) {
136 m_hysteresis_state = true;
137 } else if (input < m_low_threshold) {
138 m_hysteresis_state = false;
139 }
140 result = m_hysteresis_state;
141 break;
142
143 case LogicOperator::EDGE: {
144 bool previous_bool_input = m_input > m_threshold;
145 if (current_bool != previous_bool_input) {
146 switch (m_edge_type) {
147 case EdgeType::RISING:
148 m_edge_detected = current_bool && !previous_bool_input;
149 break;
151 m_edge_detected = !current_bool && previous_bool_input;
152 break;
153 case EdgeType::BOTH:
154 m_edge_detected = true;
155 break;
156 }
157 }
158 result = m_edge_detected;
159 break;
160 }
161
163 result = current_bool && previous_bool;
164 break;
165
167 result = current_bool || previous_bool;
168 break;
169
171 result = current_bool != previous_bool;
172 break;
173
175 result = !current_bool;
176 break;
177
179 result = !(current_bool && previous_bool);
180 break;
181
183 result = !(current_bool || previous_bool);
184 break;
185
187 result = m_direct_function(input);
188 break;
189
190 default:
191 result = current_bool;
192 }
193 break;
194
196 bool current_bool = input > m_threshold;
197 history_push(current_bool);
198 auto view = history_linearized_view();
199 result = m_sequential_function(view);
200 break;
201 }
202
203 case LogicMode::TEMPORAL: {
205 result = m_temporal_function(input, m_temporal_time);
206 break;
207 }
208
210 add_input(input, 0);
212 break;
213 }
214 }
215
216 m_input = input;
217 auto current = result ? 1.0 : 0.0;
218
220 && !m_networked_node) {
221 notify_tick(current);
222 }
223
224 if (m_input_node) {
225 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
227 }
228
229 m_last_output = current;
230 return m_last_output;
231}
SequentialFunction m_sequential_function
Function for sequential mode.
Definition Logic.hpp:584
TemporalFunction m_temporal_function
Function for temporal mode.
Definition Logic.hpp:585
DirectFunction m_direct_function
Function for direct mode.
Definition Logic.hpp:582
EdgeType m_edge_type
Type of edge to detect.
Definition Logic.hpp:593
double m_threshold
Threshold for boolean conversion.
Definition Logic.hpp:590
double m_temporal_time
Time tracking for temporal mode.
Definition Logic.hpp:596
double m_high_threshold
High threshold for hysteresis.
Definition Logic.hpp:592
double m_input
Current input value for multi-input mode.
Definition Logic.hpp:597
std::vector< double > m_input_buffer
Definition Logic.hpp:598
std::shared_ptr< Node > m_input_node
Input node for processing.
Definition Logic.hpp:599
LogicOperator m_operator
Current logic operator.
Definition Logic.hpp:581
double m_low_threshold
Low threshold for hysteresis.
Definition Logic.hpp:591
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
Definition Logic.hpp:583
bool m_edge_detected
Whether an edge was detected in the last processing.
Definition Logic.hpp:594
bool m_hysteresis_state
State for hysteresis operator.
Definition Logic.hpp:595
LogicMode m_mode
Current processing mode.
Definition Logic.hpp:580
std::span< bool > history_linearized_view()
Definition Logic.cpp:638
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
Definition Logic.cpp:503
void add_input(double input, size_t index)
Definition Logic.cpp:281
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:429
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:424
uint32_t m_sample_rate
Sample rate for audio processing, used for normalization.
Definition Node.hpp:431
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:377
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:455
@ FALLING
High-to-low transition (1→0)
@ RISING
Low-to-high transition (0→1)
@ SEQUENTIAL
State-based evaluation using history of inputs (sequential logic)
@ DIRECT
Stateless evaluation of current input only (combinational logic)
@ TEMPORAL
Time-dependent evaluation with timing constraints.
@ MULTI_INPUT
Parallel evaluation of multiple input signals.
@ NOT
Logical NOT - inverts the input.
@ NOR
Logical NOR - inverted OR operation.
@ OR
Logical OR - true when any input is true.
@ NAND
Logical NAND - inverted AND operation.
@ THRESHOLD
Binary quantization - true when input exceeds threshold.
@ AND
Logical AND - true only when all inputs are true.
@ EDGE
Transition detector - identifies state changes.
@ HYSTERESIS
Threshold with memory - prevents rapid oscillation at boundary.
@ CUSTOM
User-defined boolean function.
@ XOR
Logical XOR - true when odd number of inputs are true.
@ 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:94
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
void atomic_inc_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically increments the modulator count by a specified amount.
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.

References add_input(), MayaFlux::Nodes::Generator::AND, MayaFlux::Nodes::atomic_add_flag(), MayaFlux::Nodes::atomic_dec_modulator_count(), MayaFlux::Nodes::atomic_inc_modulator_count(), MayaFlux::Nodes::Generator::BOTH, MayaFlux::Nodes::Generator::CUSTOM, MayaFlux::Nodes::Generator::DIRECT, MayaFlux::Nodes::Generator::EDGE, MayaFlux::Nodes::Generator::FALLING, history_linearized_view(), history_push(), MayaFlux::Nodes::Generator::HYSTERESIS, m_direct_function, m_edge_detected, m_edge_type, MayaFlux::Nodes::Node::m_fire_events_during_snapshot, m_high_threshold, m_hysteresis_state, m_input, m_input_buffer, m_input_node, MayaFlux::Nodes::Node::m_last_output, m_low_threshold, m_mode, m_multi_input_function, MayaFlux::Nodes::Node::m_networked_node, m_operator, MayaFlux::Nodes::Node::m_sample_rate, m_sequential_function, MayaFlux::Nodes::Node::m_state_saved, m_temporal_function, m_temporal_time, m_threshold, MayaFlux::Nodes::Generator::MULTI_INPUT, MayaFlux::Nodes::Generator::NAND, MayaFlux::Nodes::Generator::NOR, MayaFlux::Nodes::Generator::NOT, notify_tick(), MayaFlux::Nodes::Generator::OR, MayaFlux::Nodes::PROCESSED, MayaFlux::Nodes::Generator::RISING, MayaFlux::Nodes::Generator::SEQUENTIAL, MayaFlux::Nodes::Generator::TEMPORAL, MayaFlux::Nodes::Generator::THRESHOLD, MayaFlux::Nodes::try_reset_processed_state(), and MayaFlux::Nodes::Generator::XOR.

Referenced by process_batch().

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