|
MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
|
Finite Impulse Response filter implementation. More...
#include <FIR.hpp>
Inheritance diagram for MayaFlux::Nodes::Filters::FIR:
Collaboration diagram for MayaFlux::Nodes::Filters::FIR:Public Member Functions | |
| FIR (const std::shared_ptr< Node > &input, const std::string &zindex_shifts) | |
| Creates an FIR filter with specified order. | |
| FIR (const std::shared_ptr< Node > &input, const std::vector< double > &coeffs) | |
| Creates an FIR filter with specified coefficients. | |
| FIR (const std::vector< double > &coeffs) | |
| Creates an FIR filter with specified coefficients (no input node) | |
| double | process_sample (double input=0.) override |
| Processes a single sample through the FIR filter. | |
| void | save_state () override |
| Saves the node's current state for later restoration Recursively cascades through all connected modulator nodes Protected - only NodeSourceProcessor and NodeBuffer can call. | |
| void | restore_state () override |
| Restores the node's state from the last save Recursively cascades through all connected modulator nodes Protected - only NodeSourceProcessor and NodeBuffer can call. | |
Public Member Functions inherited from MayaFlux::Nodes::Filters::Filter | |
| Filter (const std::shared_ptr< Node > &input, const std::string &zindex_shifts) | |
| Constructor using string-based filter configuration. | |
| Filter (const std::shared_ptr< Node > &input, const std::vector< double > &a_coef, const std::vector< double > &b_coef) | |
| Constructor using explicit coefficient vectors. | |
| Filter (const std::vector< double > &a_coef, const std::vector< double > &b_coef) | |
| Constructor using explicit coefficient vectors (no input node) | |
| ~Filter () override=default | |
| Virtual destructor. | |
| int | get_current_latency () const |
| Gets the current processing latency of the filter. | |
| std::pair< int, int > | get_current_shift () const |
| Gets the current shift configuration. | |
| void | set_shift (std::string &zindex_shifts) |
| Updates the filter's shift configuration. | |
| void | set_coefs (const std::vector< double > &new_coefs, coefficients type=coefficients::ALL) |
| Updates filter coefficients. | |
| 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 | update_coef_from_input (int length, coefficients type=coefficients::ALL) |
| Updates coefficients from the filter's own input. | |
| void | add_coef (int index, double value, coefficients type=coefficients::ALL) |
| Modifies a specific coefficient. | |
| virtual void | reset () |
| Resets the filter's internal state. | |
| void | set_gain (double new_gain) |
| Sets the filter's output gain. | |
| double | get_gain () const |
| Gets the current gain value. | |
| void | set_bypass (bool enable) |
| Enables or disables filter bypass. | |
| bool | is_bypass_enabled () const |
| Checks if bypass is currently enabled. | |
| int | get_order () const |
| Gets the filter's order. | |
| const std::vector< double > & | get_input_history () const |
| Gets the input history buffer. | |
| const std::vector< double > & | get_output_history () const |
| Gets the output history buffer. | |
| void | normalize_coefficients (coefficients type=coefficients::ALL) |
| Normalizes filter coefficients. | |
| std::complex< double > | get_frequency_response (double frequency, double sample_rate) const |
| Calculates the complex frequency response at a specific frequency. | |
| double | get_magnitude_response (double frequency, double sample_rate) const |
| Calculates the magnitude response at a specific frequency. | |
| double | get_phase_response (double frequency, double sample_rate) const |
| Calculates the phase response at a specific frequency. | |
| std::vector< double > | process_batch (unsigned int num_samples) override |
| Calculates the phase response at a specific frequency. | |
| void | set_input_node (const std::shared_ptr< Node > &input_node) |
| Sets the input node for the filter. | |
| std::shared_ptr< Node > | get_input_node () |
| Gets the input node for the filter. | |
| void | setACoefficients (const std::vector< double > &new_coefs) |
| Updates the feedback (denominator) coefficients. | |
| void | setBCoefficients (const std::vector< double > &new_coefs) |
| Updates the feedforward (numerator) coefficients. | |
| const std::vector< double > & | getACoefficients () const |
| Gets the feedback (denominator) coefficients. | |
| const std::vector< double > & | getBCoefficients () const |
| Gets the feedforward (numerator) coefficients. | |
| void | set_input_context (std::span< double > context) |
| Provide external buffer context for input history. | |
| void | clear_input_context () |
| Clear external input context, resume internal accumulation. | |
| bool | using_external_input_context () const |
Public Member Functions inherited from MayaFlux::Nodes::Node | |
| virtual | ~Node ()=default |
| Virtual destructor for proper cleanup of derived classes. | |
| virtual void | on_tick (const NodeHook &callback) |
| Registers a callback to be called on each tick. | |
| virtual void | on_tick_if (const NodeHook &callback, const NodeCondition &condition) |
| Registers a conditional callback. | |
| virtual bool | remove_hook (const NodeHook &callback) |
| Removes a previously registered callback. | |
| virtual bool | remove_conditional_hook (const NodeCondition &callback) |
| Removes a previously registered conditional callback. | |
| virtual void | remove_all_hooks () |
| Removes all registered callbacks. | |
| virtual void | reset_processed_state () |
| Resets the processed state of the node and any attached input nodes. | |
| virtual double | get_last_output () |
| Retrieves the most recent output value produced by the node. | |
| void | register_channel_usage (uint32_t channel_id) |
| Mark the specificed channel as a processor/user. | |
| void | unregister_channel_usage (uint32_t channel_id) |
| Removes the specified channel from the usage tracking. | |
| bool | is_used_by_channel (uint32_t channel_id) const |
| Checks if the node is currently used by a specific channel. | |
| void | request_reset_from_channel (uint32_t channel_id) |
| Requests a reset of the processed state from a specific channel. | |
| const std::atomic< uint32_t > & | get_channel_mask () const |
| Retrieves the current bitmask of active channels using this node. | |
| NodeContext & | get_last_context () |
| Retrieves the last created context object. | |
| void | set_gpu_compatible (bool compatible) |
| Sets whether the node is compatible with GPU processing. | |
| bool | is_gpu_compatible () const |
| Checks if the node supports GPU processing. | |
| std::span< const float > | get_gpu_data_buffer () const |
| Provides access to the GPU data buffer. | |
Additional Inherited Members | |
Public Attributes inherited from MayaFlux::Nodes::Node | |
| bool | m_fire_events_during_snapshot = false |
| Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don't fire during isolated buffer processing) Can be exposed in future if needed via concrete implementation in parent. | |
| std::atomic< Utils::NodeState > | m_state { Utils::NodeState::INACTIVE } |
| Atomic state flag tracking the node's processing status. | |
| std::atomic< uint32_t > | m_modulator_count { 0 } |
| Counter tracking how many other nodes are using this node as a modulator. | |
Protected Member Functions inherited from MayaFlux::Nodes::Filters::Filter | |
| void | add_coef_internal (uint64_t index, double value, std::vector< double > &buffer) |
| Modifies a specific coefficient in a coefficient buffer. | |
| virtual void | initialize_shift_buffers () |
| Initializes the input and output history buffers. | |
| virtual void | update_inputs (double current_sample) |
| Updates the input history buffer with a new sample. | |
| virtual void | update_outputs (double current_sample) |
| Updates the output history buffer with a new sample. | |
| std::unique_ptr< NodeContext > | create_context (double value) override |
| Creates a filter-specific context object. | |
| void | notify_tick (double value) override |
| Notifies all registered callbacks with the current filter context. | |
| void | build_input_history (double current_sample) |
| Builds input history from external context or internal accumulation. | |
Protected Member Functions inherited from MayaFlux::Nodes::Node | |
| virtual void | reset_processed_state_internal () |
| Resets the processed state of the node directly. | |
Protected Attributes inherited from MayaFlux::Nodes::Filters::Filter | |
| std::shared_ptr< Node > | m_input_node |
| The most recent sample value generated by this oscillator. | |
| std::pair< int, int > | m_shift_config |
| Configuration for input and output buffer sizes. | |
| std::vector< double > | m_input_history |
| Buffer storing previous input samples. | |
| std::vector< double > | m_output_history |
| Buffer storing previous output samples. | |
| std::span< double > | m_external_input_context |
| External input context for input history. | |
| std::vector< double > | m_coef_a |
| Feedback (denominator) coefficients. | |
| std::vector< double > | m_coef_b |
| Feedforward (numerator) coefficients. | |
| double | m_gain = 1.0 |
| Overall gain factor applied to the filter output. | |
| bool | m_bypass_enabled {} |
| Flag to bypass filter processing. | |
| std::vector< double > | m_saved_input_history |
| std::vector< double > | m_saved_output_history |
| bool | m_state_saved {} |
| bool | m_use_external_input_context {} |
Protected Attributes inherited from MayaFlux::Nodes::Node | |
| double | m_last_output { 0 } |
| The most recent sample value generated by this oscillator. | |
| bool | m_gpu_compatible {} |
| Flag indicating if the node supports GPU processing This flag is set by derived classes to indicate whether the node can be processed on the GPU. | |
| std::unique_ptr< NodeContext > | m_last_context |
| The last context object created for callbacks. | |
| std::vector< float > | m_gpu_data_buffer |
| GPU data buffer for context objects. | |
| 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. | |
Finite Impulse Response filter implementation.
The FIR filter implements a non-recursive digital filter where the output depends only on the current and past input values, with no feedback path. This creates a filter with guaranteed stability and linear phase response when coefficients are symmetric.
FIR filters are characterized by the difference equation: y[n] = b₀x[n] + b₁x[n-1] + ... + bₘx[n-m]
Key properties of FIR filters:
Common applications include: