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

◆ process_sample()

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

Processes a single input sample and generates a sine wave sample.

Parameters
inputInput sample (used for modulation when modulators are connected)
Returns
Generated sine wave sample

This method advances the oscillator's phase and computes the next sample of the sine wave, applying any modulation from connected nodes.

Implements MayaFlux::Nodes::Node.

Definition at line 73 of file Sine.cpp.

74{
77 uint32_t state = m_frequency_modulator->m_state.load();
78 double current_freq = m_frequency;
79
80 if (state & NodeState::PROCESSED) {
81 current_freq += m_frequency_modulator->get_last_output();
82 } else {
83 current_freq += m_frequency_modulator->process_sample(0.F);
85 }
86 update_phase_increment(current_freq);
87 }
88
89 double current_sample = std::sin(m_phase + m_offset);
91
92 if (m_phase > 2 * M_PI) {
93 m_phase -= 2 * M_PI;
94 } else if (m_phase < -2 * M_PI) {
95 m_phase += 2 * M_PI;
96 }
97
98 double current_amplitude = m_amplitude;
101 uint32_t state = m_amplitude_modulator->m_state.load();
102
103 if (state & NodeState::PROCESSED) {
104 current_amplitude += m_amplitude_modulator->get_last_output();
105 if (!(state & NodeState::ACTIVE)) {
107 }
108 } else {
109 current_amplitude += m_amplitude_modulator->process_sample(0.F);
111 }
112 }
113 current_sample *= current_amplitude;
114
115 if (input != 0.0) {
116 current_sample += input;
117 current_sample *= 0.5F;
118 }
119
120 m_last_output = current_sample;
121
123 && !m_networked_node) {
124 notify_tick(current_sample);
125 }
126
130 }
134 }
135 return current_sample;
136}
float m_frequency
Base frequency of the generator.
double m_amplitude
Base amplitude of the generator.
double m_phase
Current phase of the generator.
float m_offset
DC offset added to the output.
Definition Sine.hpp:217
double m_phase_inc
Phase increment per sample.
Definition Sine.hpp:212
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
Definition Sine.cpp:156
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
Definition Sine.cpp:51
std::shared_ptr< Node > m_frequency_modulator
Node that modulates the frequency.
Definition Sine.hpp:222
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
Definition Sine.hpp:227
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
@ ACTIVE
Engine is processing this node.
Definition NodeSpec.hpp:45
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_remove_flag(std::atomic< NodeState > &state, NodeState flag)
Atomically removes a flag from a node state.
void atomic_dec_modulator_count(std::atomic< uint32_t > &count, int amount)
Atomically decrements the modulator count by a specified amount.

References MayaFlux::Nodes::ACTIVE, MayaFlux::Nodes::atomic_add_flag(), MayaFlux::Nodes::atomic_dec_modulator_count(), MayaFlux::Nodes::atomic_inc_modulator_count(), MayaFlux::Nodes::atomic_remove_flag(), 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, 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: