7 , m_coefficients(coefficients)
10 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
11 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
13 m_direct_function = create_polynomial_function(coefficients);
19 , m_direct_function(
std::move(function))
22 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
23 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
29 , m_buffer_function(
std::move(function))
30 , m_buffer_size(buffer_size)
31 , m_history(buffer_size)
32 , m_linear_view(buffer_size, 0.0)
34 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
35 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
41 , m_coefficients(
std::move(coefficients))
42 , m_history(buffer_size)
43 , m_linear_view(buffer_size, 0.0)
44 , m_buffer_size(buffer_size)
46 , m_context(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients)
47 , m_context_gpu(0.0, m_mode, m_buffer_size, {}, {}, m_coefficients, get_gpu_data_buffer())
49 m_coef_function = function;
50 m_buffer_function = bind_coefficients(std::move(function));
76 std::span<double> view;
93 std::span<double> view;
126 std::vector<double>
buffer(num_samples);
130 for (
size_t i = 0; i < num_samples; ++i) {
178 return [
this, function = std::move(function)](std::span<double>
window) {
185 std::shared_ptr<Polynomial> copy;
215 for (
size_t i = 1; i < view_size && i <= lookback; ++i) {
225 return [coefficients](
double x) {
233 double x_power = 1.0;
235 for (
double coefficient : std::ranges::reverse_view(coefficients)) {
236 result += coefficient * x_power;
255 for (
size_t i = 0; i < view.size(); ++i)
304std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>>
Core::GlobalInputConfig input
std::shared_ptr< NetworkGeometryBuffer > buffer
std::weak_ptr< Core::Window > window
void resize(size_t new_capacity)
Resize buffer capacity.
void restore_state(const std::vector< T > &state)
Restore previously saved state.
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.
void reset()
Reset buffer to initial state (all zeros)
std::vector< T > save_state() const
Save current state for later restoration.
void set_initial_conditions(const std::vector< T > &values)
Set initial conditions.
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
std::vector< float > gpu_float_buffer
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.
BufferFunction bind_coefficients(CoefBufferFunction function)
Converts coefficient vector to a polynomial function.
CoefBufferFunction m_coef_function
The function behind m_buffer_function while a CoefBufferFunction is bound.
std::function< double(std::span< double >)> BufferFunction
Function type for recursive/feedforward polynomial evaluation.
std::vector< double > m_saved_coefficients
Saved coefficient array, used when a CoefBufferFunction is bound.
PolynomialMode m_mode
Current processing mode.
std::shared_ptr< Polynomial > clone() const
An independent node with the same behaviour and fresh history.
std::function< double(std::span< double >, std::span< double >)> CoefBufferFunction
Function type for recursive/feedforward evaluation with access to the coefficient array.
DirectFunction create_polynomial_function(const std::vector< double > &coefficients)
Creates a polynomial function from coefficients.
static double power_sum(const std::vector< double > &coefficients, double x) noexcept
Evaluates the coefficient list at x, highest power first.
std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > get_modulators() const override
Retrieves the current modulators connected to this node.
std::vector< double > m_saved_history_state
Saved state of the history buffer.
Memory::HistoryBuffer< double > m_history
Ring buffer for input/output history.
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 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
View into external buffer.
std::span< double > external_context_view(double input)
size_t m_buffer_size
Maximum size of the buffers.
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
Linearized view of history for easy access.
BufferFunction m_buffer_function
Function for recursive/feedforward mode.
bool m_coef_direct
True while DIRECT output is evaluated from m_coefficients.
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.
bool m_coef_bound
True once a CoefBufferFunction has been bound.
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.
std::span< const float > m_gpu_data
double value
Current sample value.
Base context class for node callbacks.
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...
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], ...)
@ PROCESSED
Node has been processed this cycle.
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.
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.