7Filter::Filter(
const std::shared_ptr<Node>&
input,
const std::vector<double>& a_coef,
const std::vector<double>& b_coef)
11 , m_context(0.0, m_input_history, m_output_history, m_coef_a, m_coef_b)
12 , m_context_gpu(0.0, m_input_history, m_output_history, m_coef_a, m_coef_b, get_gpu_data_buffer())
16 "IIR coefficients cannot be empty. Received a_coef size: {}, b_coef size: {}",
m_coef_a.size(),
m_coef_b.size());
20 "First denominator coefficient (a[0]) cannot be zero. Received a[0]: {}",
m_coef_a[0]);
26Filter::Filter(
const std::vector<double>& a_coef,
const std::vector<double>& b_coef)
27 :
Filter(nullptr, a_coef, b_coef)
51 for (
size_t i = 0; i < lookback; ++i) {
77 if (new_coefs.empty()) {
79 "Denominator coefficients cannot be empty. Received size: {}", new_coefs.size());
81 if (new_coefs[0] == 0.0F) {
83 "First denominator coefficient (a[0]) cannot be zero. Received a[0]: {}", new_coefs[0]);
92 if (new_coefs.empty()) {
94 "Numerator coefficients cannot be empty. Received size: {}", new_coefs.size());
103 std::vector<double> samples = source->process_batch(length);
110 std::vector<double> samples =
m_input_node->process_batch(length);
119 if (index > buffer.size()) {
120 buffer.resize(index + 1, 1.F);
122 buffer.at(index) = value;
160 double max_coef = 0.0;
162 max_coef = std::max(max_coef, std::abs(coef));
165 if (max_coef > 0.0) {
176 double omega = 2.0 * M_PI *
frequency / sample_rate;
177 std::complex<double> z = std::exp(std::complex<double>(0, omega));
179 std::complex<double> numerator = 0.0;
180 for (
size_t i = 0; i <
m_coef_b.size(); ++i) {
181 numerator +=
m_coef_b[i] * std::pow(z, -
static_cast<int>(i));
184 std::complex<double> denominator = 0.0;
185 for (
size_t i = 0; i <
m_coef_a.size(); ++i) {
186 denominator +=
m_coef_a[i] * std::pow(z, -
static_cast<int>(i));
189 return numerator / denominator;
204 std::vector<double> output(num_samples);
205 for (
unsigned int i = 0; i < num_samples; ++i) {
218 for (
size_t i = 0; i < src.size(); ++i)
236 if (condition(ctx)) {
267std::vector<std::pair<ModulatorRole, std::shared_ptr<Node>>>
#define MF_WARN(comp, ctx,...)
Core::GlobalInputConfig input
std::vector< float > gpu_float_buffer
const std::vector< double > & input_history
Current input history buffer.
Specialized context for filter node callbacks.
void add_coef_internal(uint64_t index, double value, std::vector< double > &buffer)
Modifies a specific coefficient in a coefficient buffer.
Filter(const std::shared_ptr< Node > &input, const std::vector< double > &a_coef, const std::vector< double > &b_coef)
Constructor using explicit coefficient vectors.
void add_coef(int index, double value, coefficients type=coefficients::ALL)
Modifies a specific coefficient.
void on_tick(const TypedHook< FilterContext > &callback)
Registers a callback to be called on each tick with the filter context.
std::vector< double > process_batch(unsigned int num_samples) override
Calculates the phase response at a specific frequency.
virtual void reset()
Resets the filter's internal state.
void build_input_history(double current_sample)
Builds input history from external context or internal accumulation.
std::vector< double > m_coef_b
Feedforward (numerator) coefficients.
std::vector< double > m_output_history
Buffer storing previous output samples.
virtual void update_outputs(double current_sample)
Updates the output history buffer with a new sample.
std::vector< std::pair< ModulatorRole, std::shared_ptr< Node > > > get_modulators() const override
Retrieves the current modulators connected to this node.
std::shared_ptr< Node > m_input_node
The most recent sample value generated by this oscillator.
void update_coef_from_input(int length, coefficients type=coefficients::ALL)
Updates coefficients from the filter's own input.
std::complex< double > get_frequency_response(double frequency, double sample_rate) const
Calculates the complex frequency response at a specific frequency.
void set_coefs(const std::vector< double > &new_coefs, coefficients type=coefficients::ALL)
Updates filter coefficients.
bool m_use_external_input_context
void normalize_coefficients(coefficients type=coefficients::ALL)
Normalizes filter coefficients.
void setACoefficients(const std::vector< double > &new_coefs)
Updates the feedback (denominator) coefficients.
std::vector< double > m_input_history
Buffer storing previous input samples.
void setBCoefficients(const std::vector< double > &new_coefs)
Updates the feedforward (numerator) coefficients.
virtual void update_inputs(double current_sample)
Updates the input history buffer with a new sample.
void update_coefs_from_node(int length, const std::shared_ptr< Node > &source, coefficients type=coefficients::ALL)
Updates coefficients from another node's output.
void notify_tick(double value) override
Notifies all registered callbacks with the current filter context.
FilterContextGpu m_context_gpu
std::span< double > m_external_input_context
External input context for input history.
void on_tick_if(const NodeCondition &condition, const TypedHook< FilterContext > &callback)
Registers a conditional callback to be called on each tick if the condition is met.
double get_phase_response(double frequency, double sample_rate) const
Calculates the phase response at a specific frequency.
void update_context(double value) override
Updates filter-specific context object.
std::vector< double > m_coef_a
Feedback (denominator) coefficients.
double get_magnitude_response(double frequency, double sample_rate) const
Calculates the magnitude response at a specific frequency.
double process_sample(double input=0.) override=0
Processes a single sample through the filter.
NodeContext & get_last_context() override
Gets the last created context object.
Base class for computational signal transformers implementing difference equations.
std::span< const float > m_gpu_data
double value
Current sample value.
Base context class for node callbacks.
std::vector< NodeHook > m_callbacks
Collection of standard callback functions.
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...
@ Configuration
Configuration and parameter updates.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
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.