MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ process_sample()

double MayaFlux::Nodes::Generator::Impulse::process_sample ( double  input = 0.)
overridevirtual

Processes a single input sample and generates an impulse sample.

Parameters
inputInput sample (used for modulation when modulators are connected)
Returns
Generated impulse sample (1.0 at the start of each cycle, 0.0 elsewhere)

This method advances the generator's phase and computes the next sample of the impulse train, applying any modulation from connected nodes.

Implements MayaFlux::Nodes::Node.

Definition at line 77 of file Impulse.cpp.

78{
79 double output = 0.0;
80 m_impulse_occurred = false;
81
82 double effective_freq = m_frequency;
85 uint32_t state = m_frequency_modulator->m_state.load();
86 if (state & Nodes::NodeState::PROCESSED) {
87 effective_freq += m_frequency_modulator->get_last_output();
88 } else {
89 effective_freq = m_frequency_modulator->process_sample(0.F);
91 }
92
93 if (effective_freq <= 0) {
94 effective_freq = 0.001;
95 }
96 update_phase_increment(effective_freq);
97 }
98
99 if (m_phase < m_phase_inc) {
100 output = m_amplitude;
101 m_impulse_occurred = true;
102 } else {
103 output = 0.0;
104 }
105
106 double current_amplitude = m_amplitude;
109 uint32_t state = m_amplitude_modulator->m_state.load();
110
111 if (state & NodeState::PROCESSED) {
112 current_amplitude += m_amplitude_modulator->get_last_output();
113 } else {
114 current_amplitude += m_amplitude_modulator->process_sample(0.F);
116 }
117 }
118
119 output *= current_amplitude;
120 m_amplitude = current_amplitude;
121 output += m_offset;
122
124 if (m_phase >= 1.0) {
125 m_phase -= 1.0;
126 }
127
128 m_last_output = output;
129
131 && !m_networked_node) {
132 notify_tick(output);
133 }
134
138 }
142 }
143
144 return output;
145}
float m_frequency
Base frequency of the generator.
double m_amplitude
Base amplitude of the generator.
double m_phase
Current phase of the generator.
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
Definition Impulse.hpp:262
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
Definition Impulse.cpp:179
double m_phase_inc
Phase increment per sample.
Definition Impulse.hpp:247
float m_offset
DC offset added to the output.
Definition Impulse.hpp:252
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
Definition Impulse.cpp:56
std::shared_ptr< Node > m_frequency_modulator
Node that modulates the frequency.
Definition Impulse.hpp:257
bool m_state_saved
tracks if the node's state has been saved by a snapshot operation
Definition Node.hpp:429
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:424
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:377
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:455
@ 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:94
void try_reset_processed_state(std::shared_ptr< Node > node)
Attempts to reset the processed state of a node.
void atomic_inc_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically increments the modulator count by a specified amount.
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.

References MayaFlux::Nodes::atomic_add_flag(), MayaFlux::Nodes::atomic_dec_modulator_count(), MayaFlux::Nodes::atomic_inc_modulator_count(), MayaFlux::Nodes::Generator::Generator::m_amplitude, m_amplitude_modulator, MayaFlux::Nodes::Node::m_fire_events_during_snapshot, MayaFlux::Nodes::Generator::Generator::m_frequency, m_frequency_modulator, m_impulse_occurred, MayaFlux::Nodes::Node::m_last_output, MayaFlux::Nodes::Node::m_networked_node, m_offset, MayaFlux::Nodes::Generator::Generator::m_phase, m_phase_inc, MayaFlux::Nodes::Node::m_state_saved, notify_tick(), MayaFlux::Nodes::PROCESSED, MayaFlux::Nodes::try_reset_processed_state(), and update_phase_increment().

Referenced by process_batch().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: