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

◆ process_sample()

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

Processes a single input sample and generates a phasor sample.

Parameters
inputInput sample (used for modulation when modulators are connected)
Returns
Generated phasor sample (ramp from 0 to amplitude)

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

Implements MayaFlux::Nodes::Node.

Definition at line 85 of file Phasor.cpp.

86{
87 double output = 0.0;
88
89 double effective_freq = m_frequency;
90
93 uint32_t state = m_frequency_modulator->m_state.load();
94 if (state & Utils::NodeState::PROCESSED) {
95 effective_freq += m_frequency_modulator->get_last_output();
96 } else {
97 effective_freq = m_frequency_modulator->process_sample(0.F);
99 }
100
101 update_phase_increment(effective_freq);
102 }
103
104 output = m_phase * m_amplitude;
105
108 uint32_t state = m_amplitude_modulator->m_state.load();
109 if (state & Utils::NodeState::PROCESSED) {
110 output *= m_amplitude_modulator->get_last_output();
111 } else {
112 output *= m_amplitude_modulator->process_sample(0.F);
114 }
115 }
116
117 output += m_offset;
118
120 if (m_phase >= 1.0) {
121 m_phase -= 1.0;
122 m_phase_wrapped = true;
123 }
124
125 m_last_output = output;
126
128 notify_tick(output);
129
133 }
137 }
138
139 return output;
140}
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_frequency_modulator
Node that modulates the frequency.
Definition Phasor.hpp:304
bool m_phase_wrapped
Flag indicating whether the phase has wrapped in the current sample.
Definition Phasor.hpp:333
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
Definition Phasor.hpp:309
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
Definition Phasor.cpp:60
double m_phase_inc
Phase increment per sample.
Definition Phasor.hpp:294
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
Definition Phasor.cpp:204
float m_offset
DC offset added to the output.
Definition Phasor.hpp:299
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:378
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
Definition Node.hpp:448
void atomic_add_flag(std::atomic< Utils::NodeState > &state, Utils::NodeState flag)
Atomically adds a flag to a node state.
Definition NodeUtils.cpp:96
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.
@ PROCESSED
Node has been processed this cycle.
Definition Utils.hpp:34

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, MayaFlux::Nodes::Node::m_last_output, m_offset, MayaFlux::Nodes::Generator::Generator::m_phase, m_phase_inc, m_phase_wrapped, m_state_saved, notify_tick(), MayaFlux::Utils::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: