44 const std::vector<double>& input_history,
45 const std::vector<double>& output_history,
46 const std::vector<double>& coefs_a,
47 const std::vector<double>& coefs_b)
49 , input_history(input_history)
50 , output_history(output_history)
96 const std::vector<double>& input_history,
97 const std::vector<double>& output_history,
98 const std::vector<double>& coefs_a,
99 const std::vector<double>& coefs_b,
100 std::span<const float> gpu_data)
101 :
FilterContext(value, input_history, output_history, coefs_a, coefs_b)
151 Filter(
const std::shared_ptr<Node>&
input,
const std::vector<double>& a_coef,
const std::vector<double>& b_coef);
162 Filter(
const std::vector<double>& a_coef,
const std::vector<double>& b_coef);
178 return static_cast<int>(std::max(m_coef_b.size(), m_coef_a.size())) - 1;
189 void set_coefs(
const std::vector<double>& new_coefs,
coefficients type = coefficients::ALL);
203 void update_coefs_from_node(
int length,
const std::shared_ptr<Node>& source,
coefficients type = coefficients::ALL);
215 void update_coef_from_input(
int length,
coefficients type = coefficients::ALL);
226 void add_coef(
int index,
double value,
coefficients type = coefficients::ALL);
235 virtual void reset();
244 inline void set_gain(
double new_gain) { m_gain = new_gain; }
250 [[nodiscard]]
inline double get_gain()
const {
return m_gain; }
260 inline void set_bypass(
bool enable) { m_bypass_enabled = enable; }
276 [[nodiscard]]
inline int get_order()
const {
return std::max(m_coef_a.size() - 1, m_coef_b.size() - 1); }
285 [[nodiscard]]
inline const std::vector<double>&
get_input_history()
const {
return m_input_history; }
294 [[nodiscard]]
inline const std::vector<double>&
get_output_history()
const {
return m_output_history; }
303 void normalize_coefficients(
coefficients type = coefficients::ALL);
316 [[nodiscard]] std::complex<double> get_frequency_response(
double frequency,
double sample_rate)
const;
327 [[nodiscard]]
double get_magnitude_response(
double frequency,
double sample_rate)
const;
338 [[nodiscard]]
double get_phase_response(
double frequency,
double sample_rate)
const;
360 std::vector<double> process_batch(
unsigned int num_samples)
override;
369 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
385 void setACoefficients(
const std::vector<double>& new_coefs);
395 void setBCoefficients(
const std::vector<double>& new_coefs);
404 [[nodiscard]]
inline const std::vector<double>&
getACoefficients()
const {
return m_coef_a; }
413 [[nodiscard]]
inline const std::vector<double>&
getBCoefficients()
const {
return m_coef_b; }
421 m_external_input_context = context;
422 m_use_external_input_context =
true;
430 m_use_external_input_context =
false;
431 m_external_input_context = {};
436 return m_use_external_input_context;
447 Node::set_gpu_compatible(compatible);
449 m_node_capability |= NodeCapability::VECTOR;
472 [[nodiscard]] std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>> get_modulators()
const override;
484 void add_coef_internal(uint64_t index,
double value, std::vector<double>& buffer);
494 virtual void update_inputs(
double current_sample);
504 virtual void update_outputs(
double current_sample);
519 void update_context(
double value)
override;
536 void notify_tick(
double value)
override;
542 void build_input_history(
double current_sample);
617 bool m_bypass_enabled {};
622 bool m_use_external_input_context {};
Core::GlobalInputConfig input
std::vector< float > gpu_float_buffer
FilterContextGpu(double value, const std::vector< double > &input_history, const std::vector< double > &output_history, const std::vector< double > &coefs_a, const std::vector< double > &coefs_b, std::span< const float > gpu_data)
GPU-augmented filter context for callbacks.
const std::vector< double > & coefs_b
Current coefficients for output.
const std::vector< double > & input_history
Current input history buffer.
const std::vector< double > & coefs_a
Current coefficients for input.
FilterContext(double value, const std::vector< double > &input_history, const std::vector< double > &output_history, const std::vector< double > &coefs_a, const std::vector< double > &coefs_b)
Constructs a FilterContext with the current filter state.
const std::vector< double > & output_history
Current output history buffer.
Specialized context for filter node callbacks.
void set_gain(double new_gain)
Sets the filter's output gain.
std::vector< double > m_saved_output_history
void set_gpu_compatible(bool compatible) override
Sets whether the node is compatible with GPU processing.
void set_input_context(std::span< double > context)
Provide external buffer context for input history.
std::vector< double > m_coef_b
Feedforward (numerator) coefficients.
std::vector< double > m_output_history
Buffer storing previous output samples.
const std::vector< double > & get_input_history() const
Gets the input history buffer.
const std::vector< double > & getBCoefficients() const
Gets the feedforward (numerator) coefficients.
int get_order() const
Gets the filter's order.
bool is_bypass_enabled() const
Checks if bypass is currently enabled.
std::shared_ptr< Node > m_input_node
The most recent sample value generated by this oscillator.
std::vector< double > m_saved_input_history
const std::vector< double > & getACoefficients() const
Gets the feedback (denominator) coefficients.
~Filter() override=default
Virtual destructor.
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node for the filter.
int get_current_latency() const
Gets the current processing latency of the filter.
double get_gain() const
Gets the current gain value.
std::vector< double > m_input_history
Buffer storing previous input samples.
void clear_input_context()
Clear external input context, resume internal accumulation.
FilterContextGpu m_context_gpu
std::span< double > m_external_input_context
External input context for input history.
const std::vector< double > & get_output_history() const
Gets the output history buffer.
std::vector< double > m_coef_a
Feedback (denominator) coefficients.
double process_sample(double input=0.) override=0
Processes a single sample through the filter.
void set_bypass(bool enable)
Enables or disables filter bypass.
std::shared_ptr< Node > get_input_node()
Gets the input node for the filter.
bool using_external_input_context() const
Base class for computational signal transformers implementing difference equations.
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
Base interface for all computational processing nodes.
NodeCapability
Bitmask flags declaring what data shapes a node's context can produce.
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
std::function< bool(NodeContext &)> NodeCondition
Predicate function type for conditional callbacks.