MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
Filter.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7enum coefficients : uint8_t {
10 ALL
11};
12
13/**
14 * @class FilterContext
15 * @brief Specialized context for filter node callbacks
16 *
17 * FilterContext extends the base NodeContext to provide filter-specific
18 * information to callbacks. It includes references to the filter's internal
19 * state, including input and output history buffers and coefficient vectors.
20 *
21 * This rich context enables callbacks to perform sophisticated analysis and
22 * monitoring of filter behavior, such as:
23 * - Detecting resonance conditions or instability
24 * - Analyzing filter response characteristics in real-time
25 * - Implementing adaptive processing based on filter state
26 * - Visualizing filter behavior through external interfaces
27 * - Recording filter state for later analysis or debugging
28 */
29class MAYAFLUX_API FilterContext : public NodeContext {
30public:
31 /**
32 * @brief Constructs a FilterContext with the current filter state
33 * @param value Current output sample value
34 * @param input_history Reference to the filter's input history buffer
35 * @param output_history Reference to the filter's output history buffer
36 * @param coefs_a Reference to the filter's feedback coefficients
37 * @param coefs_b Reference to the filter's feedforward coefficients
38 *
39 * Creates a context object that provides a complete snapshot of the
40 * filter's current state, including its most recent output value,
41 * history buffers, and coefficient vectors.
42 */
43 FilterContext(double value,
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)
48 : NodeContext(value, typeid(FilterContext).name())
49 , input_history(input_history)
50 , output_history(output_history)
51 , coefs_a(coefs_a)
52 , coefs_b(coefs_b)
53 {
54 }
55
56 /**
57 * @brief Current input history buffer
58 *
59 * Contains the most recent input samples processed by the filter,
60 * with the newest sample at index 0. The size of this buffer depends
61 * on the filter's feedforward path configuration.
62 */
63 const std::vector<double>& input_history;
64
65 /**
66 * @brief Current output history buffer
67 *
68 * Contains the most recent output samples processed by the filter,
69 * with the newest sample at index 0. The size of this buffer depends
70 * on the filter's feedback path configuration.
71 */
72 const std::vector<double>& output_history;
73
74 /**
75 * @brief Current coefficients for input
76 */
77 const std::vector<double>& coefs_a;
78
79 /**
80 * @brief Current coefficients for output
81 */
82 const std::vector<double>& coefs_b;
83};
84
85/**
86 * @class FilterContextGpu
87 * @brief GPU-augmented filter context for callbacks
88 *
89 * Extends FilterContext to include GPU-uploadable data, allowing
90 * callbacks to access both CPU-side filter state and GPU-resident
91 * data for advanced processing and visualization.
92 */
93class MAYAFLUX_API FilterContextGpu : public FilterContext, public GpuVectorData {
94public:
95 FilterContextGpu(double value,
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)
102 , GpuVectorData(gpu_data)
103 {
104 }
105
106 friend class Filter;
107
108 std::vector<float> gpu_float_buffer;
109};
110
111/**
112 * @brief Parses a string representation of filter order into input/output shift configuration
113 * @param str String in format "N_M" where N is input order and M is output order
114 * @return Pair of integers representing input and output shift values
115 *
116 * This utility function converts a simple string representation of filter order
117 * into the corresponding shift configuration for the filter's internal buffers.
118 */
119std::pair<int, int> shift_parser(const std::string& str);
120
121/**
122 * @class Filter
123 * @brief Base class for computational signal transformers implementing difference equations
124 *
125 * The Filter class provides a comprehensive framework for implementing digital
126 * transformations based on difference equations. It transcends traditional audio
127 * filtering concepts, offering a flexible foundation for:
128 *
129 * - Complex resonant systems for generative synthesis
130 * - Computational physical modeling components
131 * - Recursive signal transformation algorithms
132 * - Data-driven transformation design from frequency responses
133 * - Dynamic coefficient modulation for emergent behaviors
134 *
135 * At its core, the Filter implements the general difference equation:
136 * y[n] = (b₀x[n] + b₁x[n-1] + ... + bₘx[n-m]) - (a₁y[n-1] + ... + aₙy[n-n])
137 *
138 * Where:
139 * - x[n] are input values
140 * - y[n] are output values
141 * - b coefficients apply to input values (feedforward)
142 * - a coefficients apply to previous output values (feedback)
143 *
144 * This mathematical structure can represent virtually any linear time-invariant system,
145 * making it a powerful tool for signal transformation across domains. The same
146 * equations can process audio, control data, or even be applied to visual or
147 * physical simulation parameters.
148 */
149class MAYAFLUX_API Filter : public Node {
150public:
151 /**
152 * @brief Constructor using string-based filter configuration
153 * @param input Source node providing input samples
154 * @param zindex_shifts String in format "N_M" specifying filter order
155 *
156 * Creates a filter with the specified input node and order configuration.
157 * The zindex_shifts parameter provides a simple way to define filter order
158 * using a string like "2_2" for a biquad filter.
159 */
160 Filter(const std::shared_ptr<Node>& input, const std::string& zindex_shifts);
161
162 /**
163 * @brief Constructor using explicit coefficient vectors
164 * @param input Source node providing input samples
165 * @param a_coef Feedback (denominator) coefficients
166 * @param b_coef Feedforward (numerator) coefficients
167 *
168 * Creates a filter with the specified input node and coefficient vectors.
169 * This allows direct specification of filter coefficients for precise
170 * control over filter behavior.
171 */
172 Filter(const std::shared_ptr<Node>& input, const std::vector<double>& a_coef, const std::vector<double>& b_coef);
173
174 /**
175 * @brief Constructor using explicit coefficient vectors (no input node)
176 * @param a_coef Feedback (denominator) coefficients
177 * @param b_coef Feedforward (numerator) coefficients
178 *
179 * Creates a filter with the specified coefficient vectors but no input node.
180 * This can be used in scenarios where the filter operates on external data
181 * or is part of a larger processing chain.
182 */
183 Filter(const std::vector<double>& a_coef, const std::vector<double>& b_coef);
184
185 /**
186 * @brief Virtual destructor
187 */
188 ~Filter() override = default;
189
190 /**
191 * @brief Gets the current processing latency of the filter
192 * @return Latency in samples
193 *
194 * The latency is determined by the maximum of the input and output
195 * buffer sizes, representing how many samples of delay the filter introduces.
196 */
197 [[nodiscard]] inline int get_current_latency() const
198 {
199 return std::max(m_shift_config.first, m_shift_config.second);
200 }
201
202 /**
203 * @brief Gets the current shift configuration
204 * @return Pair of integers representing input and output shift values
205 *
206 * Returns the current configuration for input and output buffer sizes.
207 */
208 [[nodiscard]] inline std::pair<int, int> get_current_shift() const
209 {
210 return m_shift_config;
211 }
212
213 /**
214 * @brief Updates the filter's shift configuration
215 * @param zindex_shifts String in format "N_M" specifying new filter order
216 *
217 * Reconfigures the filter with a new order specification, resizing
218 * internal buffers as needed.
219 */
220 inline void set_shift(std::string& zindex_shifts)
221 {
222 m_shift_config = shift_parser(zindex_shifts);
223 initialize_shift_buffers();
224 }
225
226 /**
227 * @brief Updates filter coefficients
228 * @param new_coefs New coefficient values
229 * @param type Which set of coefficients to update (input, output, or both)
230 *
231 * Provides a flexible way to update filter coefficients, allowing
232 * dynamic modification of filter characteristics during processing.
233 */
234 void set_coefs(const std::vector<double>& new_coefs, coefficients type = coefficients::ALL);
235
236 /**
237 * @brief Updates coefficients from another node's output
238 * @param length Number of coefficients to update
239 * @param source Node providing coefficient values
240 * @param type Which set of coefficients to update (input, output, or both)
241 *
242 * Enables cross-domain interaction by deriving transformation coefficients from
243 * another node's output. This creates dynamic relationships between different
244 * parts of the computational graph, allowing one signal path to influence
245 * the behavior of another - perfect for generative systems where parameters
246 * evolve based on the system's own output.
247 */
248 void update_coefs_from_node(int length, const std::shared_ptr<Node>& source, coefficients type = coefficients::ALL);
249
250 /**
251 * @brief Updates coefficients from the filter's own input
252 * @param length Number of coefficients to update
253 * @param type Which set of coefficients to update (input, output, or both)
254 *
255 * Creates a self-modifying transformation where the input signal itself
256 * influences the transformation characteristics. This enables complex
257 * emergent behaviors and feedback systems where the signal's own properties
258 * determine how it will be processed, leading to evolving, non-linear responses.
259 */
260 void update_coef_from_input(int length, coefficients type = coefficients::ALL);
261
262 /**
263 * @brief Modifies a specific coefficient
264 * @param index Index of the coefficient to modify
265 * @param value New value for the coefficient
266 * @param type Which set of coefficients to update (input, output, or both)
267 *
268 * Allows precise control over individual coefficients, useful for
269 * fine-tuning filter behavior or implementing parameter automation.
270 */
271 void add_coef(int index, double value, coefficients type = coefficients::ALL);
272
273 /**
274 * @brief Resets the filter's internal state
275 *
276 * Clears the input and output history buffers, effectively
277 * resetting the filter to its initial state. This is useful
278 * when switching between audio segments to prevent artifacts.
279 */
280 virtual void reset();
281
282 /**
283 * @brief Sets the filter's output gain
284 * @param new_gain New gain value
285 *
286 * Adjusts the overall output level of the filter without
287 * changing its frequency response characteristics.
288 */
289 inline void set_gain(double new_gain) { m_gain = new_gain; }
290
291 /**
292 * @brief Gets the current gain value
293 * @return Current gain value
294 */
295 [[nodiscard]] inline double get_gain() const { return m_gain; }
296
297 /**
298 * @brief Enables or disables filter bypass
299 * @param enable True to enable bypass, false to disable
300 *
301 * When bypass is enabled, the filter passes input directly to output
302 * without applying any filtering, useful for A/B testing or
303 * temporarily disabling filters.
304 */
305 inline void set_bypass(bool enable) { m_bypass_enabled = enable; }
306
307 /**
308 * @brief Checks if bypass is currently enabled
309 * @return True if bypass is enabled, false otherwise
310 */
311 [[nodiscard]] inline bool is_bypass_enabled() const { return m_bypass_enabled; }
312
313 /**
314 * @brief Gets the filter's order
315 * @return Maximum order of the filter
316 *
317 * The filter order is determined by the maximum of the input and output
318 * coefficient counts minus one, representing the highest power of z⁻¹
319 * in the filter's transfer function.
320 */
321 [[nodiscard]] inline int get_order() const { return std::max(m_coef_a.size() - 1, m_coef_b.size() - 1); }
322
323 /**
324 * @brief Gets the input history buffer
325 * @return Constant reference to the input history vector
326 *
327 * Provides access to the filter's internal input history buffer,
328 * useful for analysis and visualization.
329 */
330 [[nodiscard]] inline const std::vector<double>& get_input_history() const { return m_input_history; }
331
332 /**
333 * @brief Gets the output history buffer
334 * @return Constant reference to the output history vector
335 *
336 * Provides access to the filter's internal output history buffer,
337 * useful for analysis and visualization.
338 */
339 [[nodiscard]] inline const std::vector<double>& get_output_history() const { return m_output_history; }
340
341 /**
342 * @brief Normalizes filter coefficients
343 * @param type Which set of coefficients to normalize (input, output, or both)
344 *
345 * Scales coefficients to ensure a[0] = 1.0 and/or maintain consistent
346 * gain at DC or Nyquist, depending on the filter type.
347 */
348 void normalize_coefficients(coefficients type = coefficients::ALL);
349
350 /**
351 * @brief Calculates the complex frequency response at a specific frequency
352 * @param frequency Frequency in Hz to analyze
353 * @param sample_rate Sample rate in Hz
354 * @return Complex frequency response (magnitude and phase)
355 *
356 * Computes the transformation's complex response at the specified frequency.
357 * This mathematical analysis can be used for visualization, further algorithmic
358 * processing, or to inform cross-domain mappings between audio properties
359 * and other computational parameters.
360 */
361 [[nodiscard]] std::complex<double> get_frequency_response(double frequency, double sample_rate) const;
362
363 /**
364 * @brief Calculates the magnitude response at a specific frequency
365 * @param frequency Frequency in Hz to analyze
366 * @param sample_rate Sample rate in Hz
367 * @return Magnitude response in linear scale
368 *
369 * Computes the filter's magnitude response at the specified frequency,
370 * representing how much the filter amplifies or attenuates that frequency.
371 */
372 [[nodiscard]] double get_magnitude_response(double frequency, double sample_rate) const;
373
374 /**
375 * @brief Calculates the phase response at a specific frequency
376 * @param frequency Frequency in Hz to analyze
377 * @param sample_rate Sample rate in Hz
378 * @return Phase response in radians
379 *
380 * Computes the filter's phase response at the specified frequency,
381 * representing the phase shift introduced by the filter at that frequency.
382 */
383 [[nodiscard]] double get_phase_response(double frequency, double sample_rate) const;
384
385 /**
386 * @brief Processes a single sample through the filter
387 * @param input The input sample
388 * @return The filtered output sample
389 *
390 * This is the core processing method that implements the difference
391 * equation for a single sample. It must be implemented by derived
392 * filter classes to define their specific filtering behavior.
393 */
394 double process_sample(double input = 0.) override = 0;
395
396 /**
397 * @brief Calculates the phase response at a specific frequency
398 * @param frequency Frequency in Hz to analyze
399 * @param sample_rate Sample rate in Hz
400 * @return Phase response in radians
401 *
402 * Computes the filter's phase response at the specified frequency,
403 * representing the phase shift introduced by the filter at that frequency.
404 */
405 std::vector<double> process_batch(unsigned int num_samples) override;
406
407 /**
408 * @brief Sets the input node for the filter
409 * @param input_node Node providing input samples
410 *
411 * Connects the filter to a source of input samples, allowing
412 * filters to be chained together or connected to generators.
413 */
414 inline void set_input_node(const std::shared_ptr<Node>& input_node) { m_input_node = input_node; }
415
416 /**
417 * @brief Gets the input node for the filter
418 * @return Node providing input samples
419 */
420 inline std::shared_ptr<Node> get_input_node() { return m_input_node; }
421
422 /**
423 * @brief Updates the feedback (denominator) coefficients
424 * @param new_coefs New coefficient values
425 *
426 * Sets the 'a' coefficients in the difference equation, which
427 * are applied to previous output samples. The method ensures
428 * proper normalization and buffer sizing.
429 */
430 void setACoefficients(const std::vector<double>& new_coefs);
431
432 /**
433 * @brief Updates the feedforward (numerator) coefficients
434 * @param new_coefs New coefficient values
435 *
436 * Sets the 'b' coefficients in the difference equation, which
437 * are applied to current and previous input samples. The method
438 * ensures proper buffer sizing.
439 */
440 void setBCoefficients(const std::vector<double>& new_coefs);
441
442 /**
443 * @brief Gets the feedback (denominator) coefficients
444 * @return Constant reference to the 'a' coefficient vector
445 *
446 * Provides access to the filter's feedback coefficients for
447 * analysis and visualization.
448 */
449 [[nodiscard]] inline const std::vector<double>& getACoefficients() const { return m_coef_a; }
450
451 /**
452 * @brief Gets the feedforward (numerator) coefficients
453 * @return Constant reference to the 'b' coefficient vector
454 *
455 * Provides access to the filter's feedforward coefficients for
456 * analysis and visualization.
457 */
458 [[nodiscard]] inline const std::vector<double>& getBCoefficients() const { return m_coef_b; }
459
460 /**
461 * @brief Provide external buffer context for input history
462 * @param context View into buffer data to use instead of internal input accumulation
463 */
464 inline void set_input_context(std::span<double> context)
465 {
466 m_external_input_context = context;
467 m_use_external_input_context = true;
468 }
469
470 /**
471 * @brief Clear external input context, resume internal accumulation
472 */
474 {
475 m_use_external_input_context = false;
476 m_external_input_context = {};
477 }
478
479 [[nodiscard]] inline bool using_external_input_context() const
480 {
481 return m_use_external_input_context;
482 }
483
484 /**
485 * @brief Gets the last created context object
486 * @return Reference to the last FilterContext object
487 */
488 NodeContext& get_last_context() override;
489
490 void set_gpu_compatible(bool compatible) override
491 {
492 m_gpu_compatible = compatible;
493 if (compatible) {
494 m_node_capability |= NodeCapability::VECTOR;
495 } else {
496 m_node_capability &= ~NodeCapability::VECTOR;
497 }
498 }
499
500protected:
501 /**
502 * @brief Modifies a specific coefficient in a coefficient buffer
503 * @param index Index of the coefficient to modify
504 * @param value New value for the coefficient
505 * @param buffer Reference to the coefficient buffer to modify
506 *
507 * Internal implementation for adding or modifying a coefficient
508 * in either the 'a' or 'b' coefficient vectors.
509 */
510 void add_coef_internal(uint64_t index, double value, std::vector<double>& buffer);
511
512 /**
513 * @brief Initializes the input and output history buffers
514 *
515 * Resizes the history buffers based on the current shift configuration
516 * and initializes them to zero. Called during construction and when
517 * the filter configuration changes.
518 */
519 virtual void initialize_shift_buffers();
520
521 /**
522 * @brief Updates the input history buffer with a new sample
523 * @param current_sample The new input sample
524 *
525 * Shifts the input history buffer and adds the new sample at the
526 * beginning. This maintains the history of input samples needed
527 * for the filter's feedforward path.
528 */
529 virtual void update_inputs(double current_sample);
530
531 /**
532 * @brief Updates the output history buffer with a new sample
533 * @param current_sample The new output sample
534 *
535 * Shifts the output history buffer and adds the new sample at the
536 * beginning. This maintains the history of output samples needed
537 * for the filter's feedback path.
538 */
539 virtual void update_outputs(double current_sample);
540
541 /**
542 * @brief Updates filter-specific context object
543 * @param value The current output sample value
544 *
545 * Updates FilterContext object that contains information about the filter's
546 * current state, including the current sample value, input/output history buffers,
547 * and coefficients. This context is passed to callbacks and conditions to provide
548 * them with the information they need to execute properly.
549 *
550 * The FilterContext allows callbacks to access filter-specific information
551 * beyond just the current sample value, enabling more sophisticated monitoring
552 * and analysis of filter behavior.
553 */
554 void update_context(double value) override;
555
556 /**
557 * @brief Notifies all registered callbacks with the current filter context
558 * @param value The current output sample value
559 *
560 * This method is called by the filter implementation when a new output value
561 * is produced. It creates a FilterContext object using create_context(), then
562 * calls all registered callbacks with that context.
563 *
564 * For unconditional callbacks (registered with on_tick()), the callback
565 * is always called. For conditional callbacks (registered with on_tick_if()),
566 * the callback is called only if its condition returns true.
567 *
568 * Filter implementations should call this method at appropriate points in their
569 * processing flow to trigger callbacks, typically after computing a new output value.
570 */
571 void notify_tick(double value) override;
572
573 /**
574 * @brief Builds input history from external context or internal accumulation
575 * @param current_sample Current input sample being processed
576 */
577 void build_input_history(double current_sample);
578
579 /**
580 * @brief The most recent sample value generated by this oscillator
581 *
582 * This value is updated each time process_sample() is called and can be
583 * accessed via get_last_output() without triggering additional processing.
584 * It's useful for monitoring the oscillator's state and for implementing
585 * feedback loops.
586 */
587 // double m_last_output;
588
589 /**
590 * @brief Input node providing samples to filter
591 *
592 * The filter processes samples from this node, allowing filters
593 * to be chained together or connected to generators.
594 */
595 std::shared_ptr<Node> m_input_node;
596
597 /**
598 * @brief Configuration for input and output buffer sizes
599 *
600 * Defines how many past input and output samples are stored,
601 * based on the filter's order.
602 */
603 std::pair<int, int> m_shift_config;
604
605 /**
606 * @brief Buffer storing previous input samples
607 *
608 * Maintains a history of input samples needed for the filter's
609 * feedforward path (b coefficients).
610 */
611 std::vector<double> m_input_history;
612
613 /**
614 * @brief Buffer storing previous output samples
615 *
616 * Maintains a history of output samples needed for the filter's
617 * feedback path (a coefficients).
618 */
619 std::vector<double> m_output_history;
620
621 /**
622 * @brief External input context for input history
623 *
624 * If set, the filter uses this external context for input history
625 * instead of its internal buffer. This allows sharing input history
626 * across multiple filters or nodes or from AudioBuffer sources.
627 */
628 std::span<double> m_external_input_context;
629
630 /**
631 * @brief Feedback (denominator) coefficients
632 *
633 * The 'a' coefficients in the difference equation, applied to
634 * previous output samples. a[0] is typically normalized to 1.0.
635 */
636 std::vector<double> m_coef_a;
637
638 /**
639 * @brief Feedforward (numerator) coefficients
640 *
641 * The 'b' coefficients in the difference equation, applied to
642 * current and previous input samples.
643 */
644 std::vector<double> m_coef_b;
645
646 /**
647 * @brief Overall gain factor applied to the filter output
648 *
649 * Provides a simple way to adjust the filter's output level
650 * without changing its frequency response characteristics.
651 */
652 double m_gain = 1.0;
653
654 /**
655 * @brief Flag to bypass filter processing
656 *
657 * When enabled, the filter passes input directly to output
658 * without applying any filtering.
659 */
660 bool m_bypass_enabled {};
661
662 std::vector<double> m_saved_input_history;
663 std::vector<double> m_saved_output_history;
664
665 bool m_use_external_input_context {};
666
669};
670}
double frequency
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)
Definition Filter.hpp:95
GPU-augmented filter context for callbacks.
Definition Filter.hpp:93
const std::vector< double > & coefs_b
Current coefficients for output.
Definition Filter.hpp:82
const std::vector< double > & input_history
Current input history buffer.
Definition Filter.hpp:63
const std::vector< double > & coefs_a
Current coefficients for input.
Definition Filter.hpp:77
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.
Definition Filter.hpp:43
const std::vector< double > & output_history
Current output history buffer.
Definition Filter.hpp:72
Specialized context for filter node callbacks.
Definition Filter.hpp:29
void set_gain(double new_gain)
Sets the filter's output gain.
Definition Filter.hpp:289
std::vector< double > m_saved_output_history
Definition Filter.hpp:663
void set_gpu_compatible(bool compatible) override
Sets whether the node is compatible with GPU processing.
Definition Filter.hpp:490
void set_input_context(std::span< double > context)
Provide external buffer context for input history.
Definition Filter.hpp:464
std::vector< double > m_coef_b
Feedforward (numerator) coefficients.
Definition Filter.hpp:644
std::vector< double > m_output_history
Buffer storing previous output samples.
Definition Filter.hpp:619
const std::vector< double > & get_input_history() const
Gets the input history buffer.
Definition Filter.hpp:330
const std::vector< double > & getBCoefficients() const
Gets the feedforward (numerator) coefficients.
Definition Filter.hpp:458
int get_order() const
Gets the filter's order.
Definition Filter.hpp:321
std::pair< int, int > get_current_shift() const
Gets the current shift configuration.
Definition Filter.hpp:208
bool is_bypass_enabled() const
Checks if bypass is currently enabled.
Definition Filter.hpp:311
void set_shift(std::string &zindex_shifts)
Updates the filter's shift configuration.
Definition Filter.hpp:220
std::shared_ptr< Node > m_input_node
The most recent sample value generated by this oscillator.
Definition Filter.hpp:595
std::vector< double > m_saved_input_history
Definition Filter.hpp:662
const std::vector< double > & getACoefficients() const
Gets the feedback (denominator) coefficients.
Definition Filter.hpp:449
~Filter() override=default
Virtual destructor.
void set_input_node(const std::shared_ptr< Node > &input_node)
Sets the input node for the filter.
Definition Filter.hpp:414
int get_current_latency() const
Gets the current processing latency of the filter.
Definition Filter.hpp:197
double get_gain() const
Gets the current gain value.
Definition Filter.hpp:295
std::vector< double > m_input_history
Buffer storing previous input samples.
Definition Filter.hpp:611
void clear_input_context()
Clear external input context, resume internal accumulation.
Definition Filter.hpp:473
FilterContextGpu m_context_gpu
Definition Filter.hpp:668
std::pair< int, int > m_shift_config
Configuration for input and output buffer sizes.
Definition Filter.hpp:603
std::span< double > m_external_input_context
External input context for input history.
Definition Filter.hpp:628
const std::vector< double > & get_output_history() const
Gets the output history buffer.
Definition Filter.hpp:339
std::vector< double > m_coef_a
Feedback (denominator) coefficients.
Definition Filter.hpp:636
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.
Definition Filter.hpp:305
std::shared_ptr< Node > get_input_node()
Gets the input node for the filter.
Definition Filter.hpp:420
bool using_external_input_context() const
Definition Filter.hpp:479
Base class for computational signal transformers implementing difference equations.
Definition Filter.hpp:149
GPU-uploadable 1D array data interface.
Base context class for node callbacks.
Definition Node.hpp:30
Base interface for all computational processing nodes.
Definition Node.hpp:109
std::pair< int, int > shift_parser(const std::string &str)
Parses a string representation of filter order into input/output shift configuration.
Definition Filter.cpp:7
NodeCapability
Bitmask flags declaring what data shapes a node's context can produce.
Definition NodeSpec.hpp:104