33 std::span<double> input_buffer,
34 std::span<double> output_buffer,
35 const std::vector<double>& coefficients)
38 , m_buffer_size(buffer_size)
39 , m_input_buffer(input_buffer)
40 , m_output_buffer(output_buffer)
41 , m_coefficients(coefficients)
73 [[nodiscard]]
const std::vector<double>&
get_coefficients()
const {
return m_coefficients; }
93 std::span<double> input_buffer,
94 std::span<double> output_buffer,
95 const std::vector<double>& coefficients,
96 std::span<const float> gpu_data)
97 :
PolynomialContext(value, mode, buffer_size, input_buffer, output_buffer, coefficients)
156 explicit Polynomial(
const std::vector<double>& coefficients);
165 explicit Polynomial(DirectFunction function);
177 Polynomial(BufferFunction function, PolynomialMode mode,
size_t buffer_size);
188 double process_sample(
double input = 0.)
override;
198 std::vector<double> process_batch(
unsigned int num_samples)
override;
214 void set_coefficients(
const std::vector<double>& coefficients);
241 void set_initial_conditions(
const std::vector<double>& initial_values);
252 DirectFunction create_polynomial_function(
const std::vector<double>& coefficients);
260 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
278 [[nodiscard]]
const std::vector<double>&
get_coefficients()
const {
return m_coefficients; }
309 inline void set_amplitude(
double amplitude)
override { m_scale_factor = amplitude; }
318 [[nodiscard]]
inline double get_amplitude()
const override {
return m_scale_factor; }
320 void save_state()
override;
321 void restore_state()
override;
333 m_external_buffer_context = buffer_view;
334 m_use_external_context =
true;
342 m_use_external_context =
false;
343 m_external_buffer_context = {};
348 return m_use_external_context;
363 m_gpu_compatible = compatible;
365 m_node_capability |= NodeCapability::VECTOR;
376 void update_context(
double value)
override;
386 void notify_tick(
double value)
override;
410 size_t m_buffer_size {};
413 size_t m_current_buffer_position {};
415 double m_saved_last_output {};
416 bool m_use_external_context {};
421 std::span<double> external_context_view(
double input);
History buffer for difference equations and recursive relations.
Base class for all signal and pattern generators in Maya Flux.
PolynomialContextGpu(double value, PolynomialMode mode, size_t buffer_size, std::span< double > input_buffer, std::span< double > output_buffer, const std::vector< double > &coefficients, std::span< const float > gpu_data)
std::vector< float > gpu_float_buffer
std::span< double > get_output_buffer() const
Gets the output buffer.
size_t m_buffer_size
Size of the buffers.
const std::vector< double > & m_coefficients
Copy of polynomial coefficients.
const std::vector< double > & get_coefficients() const
Gets the polynomial coefficients.
std::span< double > m_output_buffer
Copy of output buffer.
PolynomialMode m_mode
Current processing mode.
PolynomialContext(double value, PolynomialMode mode, size_t buffer_size, std::span< double > input_buffer, std::span< double > output_buffer, const std::vector< double > &coefficients)
Constructs a PolynomialContext.
std::span< double > m_input_buffer
Copy of input buffer.
std::span< double > get_input_buffer() const
Gets the input buffer.
size_t get_buffer_size() const
Gets the buffer size.
PolynomialMode get_mode() const
Gets the current polynomial mode.
std::function< double(std::span< double >)> BufferFunction
Function type for recursive/feedforward polynomial evaluation.
void set_gpu_compatible(bool compatible) override
Sets whether the node is compatible with GPU processing.
PolynomialMode m_mode
Converts coefficient vector to a polynomial function.
std::vector< double > m_saved_history_state
Saved state of the history buffer.
void set_amplitude(double amplitude) override
Sets the scaling factor for the output values.
Memory::HistoryBuffer< double > m_history
Ring buffer for input/output history.
PolynomialMode get_mode() const
Gets the current polynomial mode.
bool using_external_context() const
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node to generate polynomial values from.
~Polynomial() override=default
void set_buffer_context(std::span< double > buffer_view)
Uses an external buffer context for processing.
void printCurrent() override
Prints the current state and parameters.
PolynomialContextGpu m_context_gpu
const std::vector< double > & get_coefficients() const
Gets the polynomial coefficients.
double get_amplitude() const override
Gets the current amplitude scaling factor.
double m_scale_factor
Scaling factor for output.
std::span< double > m_external_buffer_context
View into external buffer.
size_t get_buffer_size() const
Gets the buffer size.
void clear_buffer_context()
Clear external buffer context, resume internal accumulation.
std::vector< double > m_linear_view
Linearized view of history for easy access.
BufferFunction m_buffer_function
Function for recursive/feedforward mode.
std::shared_ptr< Node > m_input_node
Input node for processing.
std::span< double > get_output_buffer()
Gets the output buffer.
std::function< double(double)> DirectFunction
Function type for direct polynomial evaluation.
DirectFunction m_direct_function
Function for direct mode.
PolynomialContext m_context
void printGraph() override
Prints a visual representation of the polynomial function.
std::span< double > get_input_buffer()
Gets the input buffer.
std::vector< double > m_coefficients
Polynomial coefficients (if using coefficient-based definition)
Generator that produces values based on polynomial functions.
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
@ 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], ...)
@ FEEDFORWARD
Evaluates using current and previous inputs: y[n] = f(x[n], x[n-1], ...)
NodeCapability
Bitmask flags declaring what data shapes a node's context can produce.