MayaFlux 0.1.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 115 of file Logic.cpp.

116{
117 bool result = false;
118 m_edge_detected = false;
119
120 if (m_input_node) {
121 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
122 uint32_t state = m_input_node->m_state.load();
123 if (state & Utils::NodeState::PROCESSED) {
124 input += m_input_node->get_last_output();
125 } else {
126 input = m_input_node->process_sample(input);
128 }
129 }
130
131 bool current_bool = input > m_threshold;
132 bool previous_bool = m_last_output > 0.5;
133
134 switch (m_mode) {
136 switch (m_operator) {
138 result = current_bool;
139 break;
140
142 if (input > m_high_threshold) {
143 m_hysteresis_state = true;
144 } else if (input < m_low_threshold) {
145 m_hysteresis_state = false;
146 }
147 result = m_hysteresis_state;
148 break;
149
150 case LogicOperator::EDGE: {
151 bool previous_bool_input = m_input > m_threshold;
152 if (current_bool != previous_bool_input) {
153 switch (m_edge_type) {
154 case EdgeType::RISING:
155 m_edge_detected = current_bool && !previous_bool_input;
156 break;
158 m_edge_detected = !current_bool && previous_bool_input;
159 break;
160 case EdgeType::BOTH:
161 m_edge_detected = true;
162 break;
163 }
164 }
165 result = m_edge_detected;
166 break;
167 }
168
170 result = current_bool && previous_bool;
171 break;
172
174 result = current_bool || previous_bool;
175 break;
176
178 result = current_bool != previous_bool;
179 break;
180
182 result = !current_bool;
183 break;
184
186 result = !(current_bool && previous_bool);
187 break;
188
190 result = !(current_bool || previous_bool);
191 break;
192
194 result = m_direct_function(input);
195 break;
196
197 default:
198 result = current_bool;
199 }
200 break;
201
203 bool current_bool = input > m_threshold;
204 m_history.push_front(current_bool);
205 if (m_history.size() > m_history_size) {
206 m_history.pop_back();
207 }
209 break;
210 }
211
212 case LogicMode::TEMPORAL: {
214 result = m_temporal_function(input, m_temporal_time);
215 break;
216 }
217
219 add_input(input, 0);
221 break;
222 }
223 }
224
225 m_input = input;
226 auto current = result ? 1.0 : 0.0;
227
229 notify_tick(current);
230
231 if (m_input_node) {
232 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
234 }
235
236 m_last_output = current;
237 return m_last_output;
238}
SequentialFunction m_sequential_function
Function for sequential mode.
Definition Logic.hpp:563
TemporalFunction m_temporal_function
Function for temporal mode.
Definition Logic.hpp:564
DirectFunction m_direct_function
Function for direct mode.
Definition Logic.hpp:561
size_t m_history_size
Maximum size of the history buffer.
Definition Logic.hpp:566
EdgeType m_edge_type
Type of edge to detect.
Definition Logic.hpp:571
double m_threshold
Threshold for boolean conversion.
Definition Logic.hpp:568
std::deque< bool > m_history
Buffer of input values for feedforward mode.
Definition Logic.hpp:565
double m_temporal_time
Time tracking for temporal mode.
Definition Logic.hpp:574
double m_high_threshold
High threshold for hysteresis.
Definition Logic.hpp:570
double m_input
Current input value for multi-input mode.
Definition Logic.hpp:576
std::vector< double > m_input_buffer
Definition Logic.hpp:575
std::shared_ptr< Node > m_input_node
Input node for processing.
Definition Logic.hpp:577
LogicOperator m_operator
Current logic operator.
Definition Logic.hpp:560
double m_low_threshold
Low threshold for hysteresis.
Definition Logic.hpp:569
MultiInputFunction m_multi_input_function
Function for recursive/feedforward mode.
Definition Logic.hpp:562
bool m_edge_detected
Whether an edge was detected in the last processing.
Definition Logic.hpp:572
bool m_hysteresis_state
State for hysteresis operator.
Definition Logic.hpp:573
LogicMode m_mode
Current processing mode.
Definition Logic.hpp:559
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
Definition Logic.cpp:512
void add_input(double input, size_t index)
Definition Logic.cpp:288
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:378
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:448
uint32_t get_sample_rate()
Gets the sample rate from the default engine.
Definition Config.cpp:46
@ 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.
void atomic_add_flag(std::atomic< Utils::NodeState > &state, Utils::NodeState flag)
Atomically adds a flag to a node state.
Definition NodeUtils.cpp:96
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.
@ PROCESSED
Node has been processed this cycle.
Definition Utils.hpp:34

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, MayaFlux::Config::get_sample_rate(), 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_history, m_history_size, 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, m_operator, m_sequential_function, 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::Utils::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: