8 , m_frequency_modulator(nullptr)
9 , m_amplitude_modulator(nullptr)
10 , m_impulse_occurred(false)
17Impulse::Impulse(
const std::shared_ptr<Node>& frequency_modulator,
float frequency,
double amplitude,
float offset)
19 , m_frequency_modulator(frequency_modulator)
20 , m_amplitude_modulator(nullptr)
21 , m_impulse_occurred(false)
28Impulse::Impulse(
float frequency,
const std::shared_ptr<Node>& amplitude_modulator,
double amplitude,
float offset)
30 , m_frequency_modulator(nullptr)
31 , m_amplitude_modulator(amplitude_modulator)
32 , m_impulse_occurred(false)
39Impulse::Impulse(
const std::shared_ptr<Node>& frequency_modulator,
const std::shared_ptr<Node>& amplitude_modulator,
40 float frequency,
double amplitude,
float offset)
42 , m_frequency_modulator(frequency_modulator)
43 , m_amplitude_modulator(amplitude_modulator)
44 , m_impulse_occurred(false)
59 uint64_t s_rate = 48000U;
98 if (effective_freq <= 0) {
99 effective_freq = 0.001;
124 output *= current_amplitude;
152 std::vector<double> output(num_samples, 0.0);
154 for (
unsigned int i = 0; i < num_samples; ++i) {
179 return removed_from_tick || removed_from_impulse;
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.
bool remove_hook(const NodeHook &callback) override
Removes a previously registered callback.
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
std::vector< NodeHook > m_impulse_callbacks
Collection of impulse-specific callback functions.
double m_phase_inc
Phase increment per sample.
Impulse(float frequency=1, double amplitude=1, float offset=0)
Basic constructor with fixed parameters.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
double process_sample(double input=0.) override
Processes a single input sample and generates an impulse sample.
void reset(float frequency=1, float amplitude=1.0F, float offset=0)
Resets the generator's phase and parameters.
void clear_modulators()
Removes all modulation connections.
float m_offset
DC offset added to the output.
double m_saved_last_output
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
void set_frequency_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the generator's frequency.
void on_impulse(const NodeHook &callback)
Registers a callback for every impulse.
void set_frequency(float frequency) override
Sets the generator's frequency.
std::shared_ptr< Node > m_frequency_modulator
Node that modulates the frequency.
void set_amplitude_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the generator's amplitude.
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.
std::function< void(NodeContext &)> NodeHook
Callback function type for node processing events.
void atomic_add_flag(std::atomic< Utils::NodeState > &state, Utils::NodeState flag)
Atomically adds a flag to a node state.
bool safe_add_callback(std::vector< NodeHook > &callbacks, const NodeHook &callback)
Safely adds a callback to a collection if it doesn't already exist.
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.
bool safe_remove_callback(std::vector< NodeHook > &callbacks, const NodeHook &callback)
Safely removes a callback from a collection.
@ PROCESSED
Node has been processed this cycle.
bool is_engine_initialized()
Checks if the default audio engine is initialized.