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)
155 explicit Polynomial(
const std::vector<double>& coefficients);
164 explicit Polynomial(DirectFunction function);
176 Polynomial(BufferFunction function, PolynomialMode mode,
size_t buffer_size);
187 double process_sample(
double input = 0.)
override;
197 std::vector<double> process_batch(
unsigned int num_samples)
override;
213 void set_coefficients(
const std::vector<double>& coefficients);
240 void set_initial_conditions(
const std::vector<double>& initial_values);
251 DirectFunction create_polynomial_function(
const std::vector<double>& coefficients);
259 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
277 [[nodiscard]]
const std::vector<double>&
get_coefficients()
const {
return m_coefficients; }
294 inline void set_amplitude(
double amplitude)
override { m_scale_factor = amplitude; }
303 [[nodiscard]]
inline double get_amplitude()
const override {
return m_scale_factor; }
305 void save_state()
override;
306 void restore_state()
override;
318 m_external_buffer_context = buffer_view;
319 m_use_external_context =
true;
327 m_use_external_context =
false;
328 m_external_buffer_context = {};
333 return m_use_external_context;
348 Node::set_gpu_compatible(compatible);
350 m_node_capability |= NodeCapability::VECTOR;
360 [[nodiscard]] std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> get_modulators()
const override;
367 void update_context(
double value)
override;
391 size_t m_buffer_size {};
394 size_t m_current_buffer_position {};
396 double m_saved_last_output {};
397 bool m_use_external_context {};
402 std::span<double> external_context_view(
double input);
Core::GlobalInputConfig 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.
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
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.