6Sine::Sine(
float frequency,
double amplitude,
float offset)
8 , m_frequency_modulator(nullptr)
9 , m_amplitude_modulator(nullptr)
18Sine::Sine(
const std::shared_ptr<Node>& frequency_modulator,
float frequency,
double amplitude,
float offset)
20 , m_frequency_modulator(frequency_modulator)
21 , m_amplitude_modulator(nullptr)
28Sine::Sine(
float frequency,
const std::shared_ptr<Node>& amplitude_modulator,
double amplitude,
float offset)
30 , m_frequency_modulator(nullptr)
31 , m_amplitude_modulator(amplitude_modulator)
38Sine::Sine(
const std::shared_ptr<Node>& frequency_modulator,
const std::shared_ptr<Node>& amplitude_modulator,
float frequency,
double amplitude,
float offset)
40 , m_frequency_modulator(frequency_modulator)
41 , m_amplitude_modulator(amplitude_modulator)
56 uint64_t s_rate = 48000U;
60 m_phase_inc = (2 * M_PI * frequency) / (
double)s_rate;
101 }
else if (
m_phase < -2 * M_PI) {
120 current_sample *= current_amplitude;
123 current_sample += input;
124 current_sample *= 0.5F;
140 return current_sample;
145 std::vector<double> output(num_samples);
146 for (
unsigned int i = 0; i < num_samples; i++) {
virtual std::unique_ptr< NodeContext > create_context(double value) override
Creates a context object for callbacks.
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.
double m_phase_inc
Phase increment per sample.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
void set_frequency_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the oscillator's frequency.
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
void clear_modulators()
Removes all modulation connections.
std::shared_ptr< Node > m_frequency_modulator
Node that modulates the frequency.
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
void set_frequency(float frequency) override
Sets the oscillator's frequency.
void printGraph() override
Prints a visual representation of the sine wave.
void printCurrent() override
Prints the current parameters of the sine oscillator.
void reset(float frequency=440, double amplitude=0.5, float offset=0)
Resets the oscillator's phase and parameters.
double m_saved_last_output
Sine(float frequency=440, double amplitude=1, float offset=0)
Basic constructor with fixed parameters.
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
void set_amplitude_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the oscillator's amplitude.
double process_sample(double input=0.) override
Processes a single input sample and generates a sine wave sample.
std::vector< NodeHook > m_callbacks
Collection of standard callback functions.
double m_last_output
The most recent sample value generated by this oscillator.
bool m_fire_events_during_snapshot
Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don...
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
Collection of conditional callback functions with their predicates.
std::unique_ptr< NodeContext > m_last_context
The last context object created for callbacks.
uint32_t get_sample_rate()
Gets the sample rate from the default engine.
void atomic_add_flag(std::atomic< Utils::NodeState > &state, Utils::NodeState flag)
Atomically adds a flag to a node state.
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.
void atomic_remove_flag(std::atomic< Utils::NodeState > &state, Utils::NodeState flag)
Atomically removes a flag from a node state.
@ ACTIVE
Engine is processing this node.
@ PROCESSED
Node has been processed this cycle.
bool is_engine_initialized()
Checks if the default audio engine is initialized.