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)
115std::pair<int, int>
shift_parser(
const std::string& str);
156 Filter(
const std::shared_ptr<Node>& input,
const std::string& zindex_shifts);
168 Filter(
const std::shared_ptr<Node>& input,
const std::vector<double>& a_coef,
const std::vector<double>& b_coef);
179 Filter(
const std::vector<double>& a_coef,
const std::vector<double>& b_coef);
195 return std::max(m_shift_config.first, m_shift_config.second);
206 return m_shift_config;
219 initialize_shift_buffers();
230 void set_coefs(
const std::vector<double>& new_coefs,
coefficients type = coefficients::ALL);
244 void update_coefs_from_node(
int length,
const std::shared_ptr<Node>& source,
coefficients type = coefficients::ALL);
256 void update_coef_from_input(
int length,
coefficients type = coefficients::ALL);
267 void add_coef(
int index,
double value,
coefficients type = coefficients::ALL);
276 virtual void reset();
285 inline void set_gain(
double new_gain) { m_gain = new_gain; }
291 [[nodiscard]]
inline double get_gain()
const {
return m_gain; }
301 inline void set_bypass(
bool enable) { m_bypass_enabled = enable; }
317 [[nodiscard]]
inline int get_order()
const {
return std::max(m_coef_a.size() - 1, m_coef_b.size() - 1); }
326 [[nodiscard]]
inline const std::vector<double>&
get_input_history()
const {
return m_input_history; }
335 [[nodiscard]]
inline const std::vector<double>&
get_output_history()
const {
return m_output_history; }
344 void normalize_coefficients(
coefficients type = coefficients::ALL);
357 [[nodiscard]] std::complex<double> get_frequency_response(
double frequency,
double sample_rate)
const;
368 [[nodiscard]]
double get_magnitude_response(
double frequency,
double sample_rate)
const;
379 [[nodiscard]]
double get_phase_response(
double frequency,
double sample_rate)
const;
401 std::vector<double> process_batch(
unsigned int num_samples)
override;
410 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
426 void setACoefficients(
const std::vector<double>& new_coefs);
436 void setBCoefficients(
const std::vector<double>& new_coefs);
445 [[nodiscard]]
inline const std::vector<double>&
getACoefficients()
const {
return m_coef_a; }
454 [[nodiscard]]
inline const std::vector<double>&
getBCoefficients()
const {
return m_coef_b; }
462 m_external_input_context = context;
463 m_use_external_input_context =
true;
471 m_use_external_input_context =
false;
472 m_external_input_context = {};
477 return m_use_external_input_context;
496 void add_coef_internal(uint64_t index,
double value, std::vector<double>& buffer);
505 virtual void initialize_shift_buffers();
515 virtual void update_inputs(
double current_sample);
525 virtual void update_outputs(
double current_sample);
540 void update_context(
double value)
override;
557 void notify_tick(
double value)
override;
563 void build_input_history(
double current_sample);
646 bool m_bypass_enabled {};
651 bool m_use_external_input_context {};
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_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.
std::pair< int, int > get_current_shift() const
Gets the current shift configuration.
bool is_bypass_enabled() const
Checks if bypass is currently enabled.
void set_shift(std::string &zindex_shifts)
Updates the filter's shift configuration.
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::pair< int, int > m_shift_config
Configuration for input and output buffer sizes.
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.
std::pair< int, int > shift_parser(const std::string &str)
Parses a string representation of filter order into input/output shift configuration.