MayaFlux 0.4.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()) {
18 return input;
19 }
20
21 double processed_input = input;
22 if (m_input_node) {
23 atomic_inc_modulator_count(m_input_node->m_modulator_count, 1);
24 uint32_t state = m_input_node->m_state.load();
25 if (state & NodeState::PROCESSED) {
26 processed_input += m_input_node->get_last_output();
27 } else {
28 processed_input += m_input_node->process_sample(input);
30 }
31 }
32
34 build_input_history(processed_input);
35 } else {
36 update_inputs(processed_input);
37 }
38
39 double output = 0.;
40 const size_t num_feedforward = std::min(m_coef_b.size(), m_input_history.size());
41 for (size_t i = 0; i < num_feedforward; ++i) {
42 output += m_coef_b[i] * m_input_history[i];
43 }
44
45 const size_t num_feedback = std::min(m_coef_a.size(), m_output_history.size());
46 for (size_t i = 1; i < num_feedback; ++i) {
47 output -= m_coef_a[i] * m_output_history[i];
48 }
49
50 // output /= m_coef_a[0];
51
52 update_outputs(output);
53
55 && !m_networked_node) {
56 notify_tick(output);
57 }
58
59 if (m_input_node) {
60 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
62 }
63
64 return output * get_gain();
65}
66
77
88
89}
Core::GlobalInputConfig input
Definition Config.cpp:36
std::vector< double > m_saved_output_history
Definition Filter.hpp:620
void build_input_history(double current_sample)
Builds input history from external context or internal accumulation.
Definition Filter.cpp:43
std::vector< double > m_coef_b
Feedforward (numerator) coefficients.
Definition Filter.hpp:601
std::vector< double > m_output_history
Buffer storing previous output samples.
Definition Filter.hpp:576
virtual void update_outputs(double current_sample)
Updates the output history buffer with a new sample.
Definition Filter.cpp:67
bool is_bypass_enabled() const
Checks if bypass is currently enabled.
Definition Filter.hpp:266
std::shared_ptr< Node > m_input_node
The most recent sample value generated by this oscillator.
Definition Filter.hpp:560
std::vector< double > m_saved_input_history
Definition Filter.hpp:619
double get_gain() const
Gets the current gain value.
Definition Filter.hpp:250
std::vector< double > m_input_history
Buffer storing previous input samples.
Definition Filter.hpp:568
virtual void update_inputs(double current_sample)
Updates the input history buffer with a new sample.
Definition Filter.cpp:59
void notify_tick(double value) override
Notifies all registered callbacks with the current filter context.
Definition Filter.cpp:227
std::vector< double > m_coef_a
Feedback (denominator) coefficients.
Definition Filter.hpp:593
Base class for computational signal transformers implementing difference equations.
Definition Filter.hpp:139
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:457
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:452
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:487
@ 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