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

◆ process_sample()

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

Processes a single sample.

Parameters
inputInput value
Returns
The next sample value from the polynomial function

Computes the next output value based on the polynomial function and current mode.

Implements MayaFlux::Nodes::Node.

Definition at line 37 of file Polynomial.cpp.

38{
39 double result = 0.0;
40
41 if (m_input_node) {
42 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
43 uint32_t state = m_input_node->m_state.load();
44 if (state & Utils::NodeState::PROCESSED) {
45 input += m_input_node->get_last_output();
46 } else {
47 input = m_input_node->process_sample(input);
49 }
50 }
51
52 switch (m_mode) {
54 result = m_direct_function(input);
55 break;
56
58 if (m_buffer_size > 0) {
59 std::span<double> view;
60
62 view = external_context_view(input);
63 } else {
64 ring_push(input);
65 view = linearized_view();
66 }
67
68 result = m_buffer_function(view);
69
70 m_ring_data[m_ring_head] = result;
71 }
72 break;
73
75 if (m_buffer_size > 0) {
76 std::span<double> view;
77
79 view = external_context_view(input);
80 } else {
81 ring_push(input);
82 view = linearized_view();
83 }
84
85 result = m_buffer_function(view);
86 }
87 break;
88 }
89
90 result *= m_scale_factor;
91
92 m_last_output = result;
93
95 && !m_networked_node) {
96 notify_tick(result);
97 }
98
99 if (m_input_node) {
100 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
102 }
103
104 return result;
105}
PolynomialMode m_mode
Converts coefficient vector to a polynomial function.
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
double m_scale_factor
Scaling factor for output.
std::span< double > m_external_buffer_context
std::span< double > external_context_view(double input)
size_t m_buffer_size
Maximum size of the buffers.
BufferFunction m_buffer_function
Function for recursive/feedforward mode.
std::shared_ptr< Node > m_input_node
Input node for processing.
DirectFunction m_direct_function
Function for direct mode.
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:426
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:421
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:374
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:448
@ RECURSIVE
Evaluates using current and previous outputs: y[n] = f(y[n-1], y[n-2], ...)
@ DIRECT
Evaluates f(x) where x is the current phase/input.
@ FEEDFORWARD
Evaluates using current and previous inputs: y[n] = f(x[n], x[n-1], ...)
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 MayaFlux::Nodes::atomic_add_flag(), MayaFlux::Nodes::atomic_dec_modulator_count(), MayaFlux::Nodes::atomic_inc_modulator_count(), MayaFlux::Nodes::Generator::DIRECT, external_context_view(), MayaFlux::Nodes::Generator::FEEDFORWARD, linearized_view(), m_buffer_function, m_buffer_size, m_direct_function, m_external_buffer_context, MayaFlux::Nodes::Node::m_fire_events_during_snapshot, m_input_node, MayaFlux::Nodes::Node::m_last_output, m_mode, MayaFlux::Nodes::Node::m_networked_node, m_ring_data, m_ring_head, m_scale_factor, MayaFlux::Nodes::Node::m_state_saved, m_use_external_context, notify_tick(), MayaFlux::Utils::PROCESSED, MayaFlux::Nodes::Generator::RECURSIVE, ring_push(), 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: