MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
FIR.cpp
Go to the documentation of this file.
1#include "FIR.hpp"
2
4
5FIR::FIR(const std::shared_ptr<Node>& input, const std::vector<double>& coeffs)
6 : Filter(input, std::vector<double> { 1.0F }, coeffs)
7{
8}
9
10FIR::FIR(const std::vector<double>& coeffs)
11 : FIR(nullptr, coeffs)
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.0;
41 const size_t num_taps = std::min(m_coef_b.size(), m_input_history.size());
42
43 for (size_t i = 0; i < num_taps; ++i) {
45 }
46
48
50 && !m_networked_node) {
52 }
53
54 if (m_input_node) {
55 atomic_dec_modulator_count(m_input_node->m_modulator_count, 1);
57 }
58
60 return m_last_output;
61}
62
64{
66
67 if (m_input_node)
68 m_input_node->save_state();
69
70 m_state_saved = true;
71}
72
74{
76
77 if (m_input_node)
78 m_input_node->restore_state();
79
80 m_state_saved = false;
81}
82
83}
Core::GlobalInputConfig input
Definition Config.cpp:38
std::shared_ptr< Core::VKImage > output
double process_sample(double input=0.) override
Processes a single sample through the FIR filter.
Definition FIR.cpp:15
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
Definition FIR.cpp:63
FIR(const std::shared_ptr< Node > &input, const std::vector< double > &coeffs)
Creates an FIR filter with specified coefficients.
Definition FIR.cpp:5
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
Definition FIR.cpp:73
Finite Impulse Response filter implementation.
Definition FIR.hpp:34
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
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
Base class for computational signal transformers implementing difference equations.
Definition Filter.hpp:148
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