43 FilterContext(
double value,
const std::vector<double>& input_history,
const std::vector<double>& output_history,
44 const std::vector<double>& coefs_a,
const std::vector<double>& coefs_b)
46 , input_history(input_history)
47 , output_history(output_history)
92 FilterContextGpu(
double value,
const std::vector<double>& input_history,
const std::vector<double>& output_history,
93 const std::vector<double>& coefs_a,
const std::vector<double>& coefs_b, std::span<const float> gpu_data)
94 :
FilterContext(value, input_history, output_history, coefs_a, coefs_b)
108std::pair<int, int>
shift_parser(
const std::string& str);
149 Filter(
const std::shared_ptr<Node>& input,
const std::string& zindex_shifts);
161 Filter(
const std::shared_ptr<Node>& input,
const std::vector<double>& a_coef,
const std::vector<double>& b_coef);
172 Filter(
const std::vector<double>& a_coef,
const std::vector<double>& b_coef);
188 return std::max(m_shift_config.first, m_shift_config.second);
199 return m_shift_config;
212 initialize_shift_buffers();
223 void set_coefs(
const std::vector<double>& new_coefs,
coefficients type = coefficients::ALL);
237 void update_coefs_from_node(
int length,
const std::shared_ptr<Node>& source,
coefficients type = coefficients::ALL);
249 void update_coef_from_input(
int length,
coefficients type = coefficients::ALL);
260 void add_coef(
int index,
double value,
coefficients type = coefficients::ALL);
269 virtual void reset();
278 inline void set_gain(
double new_gain) { m_gain = new_gain; }
284 [[nodiscard]]
inline double get_gain()
const {
return m_gain; }
294 inline void set_bypass(
bool enable) { m_bypass_enabled = enable; }
310 [[nodiscard]]
inline int get_order()
const {
return std::max(m_coef_a.size() - 1, m_coef_b.size() - 1); }
319 [[nodiscard]]
inline const std::vector<double>&
get_input_history()
const {
return m_input_history; }
328 [[nodiscard]]
inline const std::vector<double>&
get_output_history()
const {
return m_output_history; }
337 void normalize_coefficients(
coefficients type = coefficients::ALL);
350 [[nodiscard]] std::complex<double> get_frequency_response(
double frequency,
double sample_rate)
const;
361 [[nodiscard]]
double get_magnitude_response(
double frequency,
double sample_rate)
const;
372 [[nodiscard]]
double get_phase_response(
double frequency,
double sample_rate)
const;
394 std::vector<double> process_batch(
unsigned int num_samples)
override;
403 inline void set_input_node(
const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
419 void setACoefficients(
const std::vector<double>& new_coefs);
429 void setBCoefficients(
const std::vector<double>& new_coefs);
438 [[nodiscard]]
inline const std::vector<double>&
getACoefficients()
const {
return m_coef_a; }
447 [[nodiscard]]
inline const std::vector<double>&
getBCoefficients()
const {
return m_coef_b; }
455 m_external_input_context = context;
456 m_use_external_input_context =
true;
464 m_use_external_input_context =
false;
465 m_external_input_context = {};
470 return m_use_external_input_context;
483 void add_coef_internal(uint64_t index,
double value, std::vector<double>& buffer);
492 virtual void initialize_shift_buffers();
502 virtual void update_inputs(
double current_sample);
512 virtual void update_outputs(
double current_sample);
528 std::unique_ptr<NodeContext> create_context(
double value)
override;
545 void notify_tick(
double value)
override;
551 void build_input_history(
double current_sample);
634 bool m_bypass_enabled {};
639 bool m_state_saved {};
641 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.
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.