MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
IIR.cpp
Go to the documentation of this file.
1#include "IIR.hpp"
2
4
5IIR::IIR(const std::shared_ptr<Node>& input, const std::vector<double>& a_coef, const std::vector<double>& b_coef)
6 : Filter(input, a_coef, b_coef)
7{
8}
9
10IIR::IIR(const std::vector<double>& a_coef, const std::vector<double>& b_coef)
11 : Filter(a_coef, b_coef)
12{
13}
14
16{
17 if (is_bypass_enabled()) {
19 return m_last_output;
20 }
21
22 double processed_input = input;
23 if (m_input_node) {
24 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
25 uint32_t state = m_input_node->m_state.load();
26 if (state & NodeState::PROCESSED) {
27 processed_input += m_input_node->get_last_output();
28 } else {
29 processed_input += m_input_node->process_sample(input);
31 }
32 }
33
35 build_input_history(processed_input);
36 } else {
37 update_inputs(processed_input);
38 }
39
40 double output = 0.;
41 const size_t num_feedforward = std::min(m_coef_b.size(), m_input_history.size());
42 for (size_t i = 0; i < num_feedforward; ++i) {
44 }
45
46 const size_t num_feedback = std::min(m_coef_a.size(), m_output_history.size());
47 for (size_t i = 1; i < num_feedback; ++i) {
49 }
50
52
54 && !m_networked_node) {
56 }
57
58 if (m_input_node) {
59 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
61 }
62
64 return m_last_output;
65}
66
77
88
89}
Core::GlobalInputConfig input
Definition Config.cpp:38
std::shared_ptr< Core::VKImage > output
std::vector< double > m_saved_output_history
Definition Filter.hpp:671
void build_input_history(double current_sample)
Builds input history from external context or internal accumulation.
Definition Filter.cpp:35
std::vector< double > m_coef_b
Feedforward (numerator) coefficients.
Definition Filter.hpp:652
std::vector< double > m_output_history
Buffer storing previous output samples.
Definition Filter.hpp:627
virtual void update_outputs(double current_sample)
Updates the output history buffer with a new sample.
Definition Filter.cpp:59
bool is_bypass_enabled() const
Checks if bypass is currently enabled.
Definition Filter.hpp:315
std::shared_ptr< Node > m_input_node
The most recent sample value generated by this oscillator.
Definition Filter.hpp:611
std::vector< double > m_saved_input_history
Definition Filter.hpp:670
double get_gain() const
Gets the current gain value.
Definition Filter.hpp:299
std::vector< double > m_input_history
Buffer storing previous input samples.
Definition Filter.hpp:619
virtual void update_inputs(double current_sample)
Updates the input history buffer with a new sample.
Definition Filter.cpp:51
void notify_tick(double value) override
Notifies all registered callbacks with the current filter context.
Definition Filter.cpp:245
std::vector< double > m_coef_a
Feedback (denominator) coefficients.
Definition Filter.hpp:644
Base class for computational signal transformers implementing difference equations.
Definition Filter.hpp:148
IIR(const std::shared_ptr< Node > &input, const std::vector< double > &a_coef, const std::vector< double > &b_coef)
Creates an IIR filter with specified coefficients.
Definition IIR.cpp:5
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
Definition IIR.cpp:67
double process_sample(double input=0.) override
Processes a single sample through the IIR filter.
Definition IIR.cpp:15
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
Definition IIR.cpp:78
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:477
bool m_networked_node
Flag indicating if the node is part of a NodeNetwork This flag is used to disable event firing when t...
Definition Node.hpp:472
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:425
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:507
@ PROCESSED
Node has been processed this cycle.
Definition NodeSpec.hpp:49
void atomic_add_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically adds a flag to a node state.
Definition NodeUtils.cpp:60
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
Definition NodeUtils.cpp:97
void atomic_inc_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically increments the modulator count by a specified amount.
Definition NodeUtils.cpp:87
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.
Definition NodeUtils.cpp:92