7 , m_coefficients(coefficients)
9 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
10 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
12 m_direct_function = create_polynomial_function(coefficients);
17 , m_direct_function(
std::move(function))
19 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
20 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
26 , m_buffer_function(
std::move(function))
27 , m_ring_count(buffer_size)
28 , m_buffer_size(buffer_size)
29 , m_ring_data(buffer_size, 0.0)
30 , m_linear_view(buffer_size, 0.0)
32 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
33 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
59 std::span<double> view;
76 std::span<double> view;
109 std::vector<double> buffer(num_samples);
113 for (
size_t i = 0; i < num_samples; ++i) {
157 size_t count = std::min(initial_values.size(),
m_buffer_size);
158 for (
size_t i = 0; i < count; ++i) {
191 for (
size_t i = 1; i < view_size && i <= lookback; ++i) {
201 return [coefficients](
double x) {
203 double x_power = 1.0;
205 for (
double coefficient : std::ranges::reverse_view(coefficients)) {
206 result += coefficient * x_power;
242 if (condition(ctx)) {
size_t m_buffer_size
Size of the buffers.
std::span< double > m_output_buffer
Copy of output buffer.
PolynomialMode m_mode
Current processing mode.
std::span< double > m_input_buffer
Copy of input buffer.
std::function< double(std::span< double >)> BufferFunction
Function type for recursive/feedforward polynomial evaluation.
PolynomialMode m_mode
Converts coefficient vector to a polynomial function.
DirectFunction create_polynomial_function(const std::vector< double > &coefficients)
Creates a polynomial function from coefficients.
size_t m_saved_ring_count
std::vector< double > m_ring_data
void update_context(double value) override
Updates the context object with the current node state.
void set_direct_function(DirectFunction function)
Sets a custom direct function.
void set_initial_conditions(const std::vector< double > &initial_values)
Sets initial conditions for recursive mode.
size_t m_current_buffer_position
double process_sample(double input=0.) override
Processes a single sample.
double m_saved_last_output
PolynomialContextGpu m_context_gpu
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
std::vector< double > m_saved_ring_data
void set_buffer_function(BufferFunction function, PolynomialMode mode, size_t buffer_size)
Sets a custom buffer function.
double m_scale_factor
Scaling factor for output.
Polynomial(const std::vector< double > &coefficients)
Constructs a Polynomial generator in direct mode with coefficient-based definition.
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.
void ring_push(double val)
void set_coefficients(const std::vector< double > &coefficients)
Sets the polynomial coefficients (for direct mode)
void reset()
Resets the generator to its initial state.
std::vector< double > m_linear_view
BufferFunction m_buffer_function
Function for recursive/feedforward mode.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
std::shared_ptr< Node > m_input_node
Input node for processing.
std::span< double > linearized_view()
std::function< double(double)> DirectFunction
Function type for direct polynomial evaluation.
NodeContext & get_last_context() override
Retrieves the last created context object.
DirectFunction m_direct_function
Function for direct mode.
bool m_use_external_context
PolynomialContext m_context
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
std::vector< double > m_coefficients
Polynomial coefficients (if using coefficient-based definition)
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
double value
Current sample value.
Base context class for node callbacks.
std::vector< NodeHook > m_callbacks
Collection of standard callback functions.
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
bool m_networked_node
Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when t...
double m_last_output
The most recent sample value generated by this oscillator.
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
Collection of conditional callback functions with their predicates.
bool m_gpu_compatible
Flag indicating if the node supports GPU processing This flag is set by derived classes to indicate w...
@ DIRECT
Stateless evaluation of current input only (combinational logic)
PolynomialMode
Defines how the polynomial function processes input values.
@ 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.
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.