MayaFlux 0.3.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 38 of file Polynomial.cpp.

39{
40 double result = 0.0;
41
42 if (m_input_node) {
43 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
44 uint32_t state = m_input_node->m_state.load();
45 if (state & NodeState::PROCESSED) {
46 input += m_input_node->get_last_output();
47 } else {
48 input = m_input_node->process_sample(input);
50 }
51 }
52
53 switch (m_mode) {
55 result = m_direct_function(input);
56 break;
57
59 if (m_buffer_size > 0) {
60 std::span<double> view;
61
63 view = external_context_view(input);
64 } else {
65 m_history.push(input);
67 }
68
69 result = m_buffer_function(view);
70
72 }
73 break;
74
76 if (m_buffer_size > 0) {
77 std::span<double> view;
78
80 view = external_context_view(input);
81 } else {
82 m_history.push(input);
84 }
85
86 result = m_buffer_function(view);
87 }
88 break;
89 }
90
91 result *= m_scale_factor;
92
93 m_last_output = result;
94
96 && !m_networked_node) {
97 notify_tick(result);
98 }
99
100 if (m_input_node) {
101 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
103 }
104
105 return result;
106}
std::span< T > linearized_view()
Get mutable linearized view of entire history.
void overwrite_newest(const T &value)
Overwrite the newest element without advancing position.
void push(const T &value)
Push new value to front of history.
PolynomialMode m_mode
Converts coefficient vector to a polynomial function.
Memory::HistoryBuffer< double > m_history
Ring buffer for input/output history.
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
View into external buffer.
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: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
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
@ 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], ...)
@ 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 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, MayaFlux::Memory::HistoryBuffer< T >::linearized_view(), m_buffer_function, m_buffer_size, m_direct_function, m_external_buffer_context, MayaFlux::Nodes::Node::m_fire_events_during_snapshot, m_history, m_input_node, MayaFlux::Nodes::Node::m_last_output, m_mode, MayaFlux::Nodes::Node::m_networked_node, m_scale_factor, MayaFlux::Nodes::Node::m_state_saved, m_use_external_context, notify_tick(), MayaFlux::Memory::HistoryBuffer< T >::overwrite_newest(), MayaFlux::Nodes::PROCESSED, MayaFlux::Memory::HistoryBuffer< T >::push(), MayaFlux::Nodes::Generator::RECURSIVE, 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: