8 , m_frequency_modulator(nullptr)
9 , m_amplitude_modulator(nullptr)
10 , m_phase_wrapped(false)
11 , m_threshold_crossed(false)
18Phasor::Phasor(
const std::shared_ptr<Node>& frequency_modulator,
float frequency,
double amplitude,
float offset)
20 , m_frequency_modulator(frequency_modulator)
21 , m_amplitude_modulator(nullptr)
22 , m_phase_wrapped(false)
23 , m_threshold_crossed(false)
30Phasor::Phasor(
float frequency,
const std::shared_ptr<Node>& amplitude_modulator,
double amplitude,
float offset)
32 , m_frequency_modulator(nullptr)
33 , m_amplitude_modulator(amplitude_modulator)
34 , m_phase_wrapped(false)
35 , m_threshold_crossed(false)
41Phasor::Phasor(
const std::shared_ptr<Node>& frequency_modulator,
const std::shared_ptr<Node>& amplitude_modulator,
42 float frequency,
double amplitude,
float offset)
44 , m_frequency_modulator(frequency_modulator)
45 , m_amplitude_modulator(amplitude_modulator)
46 , m_phase_wrapped(false)
47 , m_threshold_crossed(false)
62 uint64_t s_rate = 48000U;
144 std::vector<double> output(num_samples, 0.0);
146 for (
unsigned int i = 0; i < num_samples; ++i) {
153void Phasor::reset(
float frequency,
float amplitude,
float offset,
double phase)
176 std::pair<NodeHook, double> entry = std::make_pair(callback, threshold);
178 if (pair.first.target_type() == callback.target_type() && pair.second == threshold) {
188 if (it->first.target_type() == callback.target_type()) {
201 return removed_from_tick || removed_from_phase_wrap || removed_from_threshold;
228 }
else if (value < threshold) {
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.
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.
bool remove_threshold_callback(const NodeHook &callback)
Removes a previously registered phase wrap callback.
bool m_threshold_crossed
Flag indicating whether the threshold has been crossed in the current sample.
void restore_state() override
Restores the node's state from the last save Recursively cascades through all connected modulator nod...
bool m_phase_wrapped
Flag indicating whether the phase has wrapped in the current sample.
double m_saved_last_output
void set_frequency(float frequency) override
Sets the generator's frequency.
bool remove_hook(const NodeHook &callback) override
Removes a previously registered callback.
std::shared_ptr< Node > m_amplitude_modulator
Node that modulates the amplitude.
std::vector< NodeHook > m_phase_wrap_callbacks
Collection of phase wrap-specific callback functions.
std::vector< double > process_batch(unsigned int num_samples) override
Processes multiple samples at once.
void update_phase_increment(double frequency)
Updates the phase increment based on a new frequency.
double m_phase_inc
Phase increment per sample.
std::vector< std::pair< NodeHook, double > > m_threshold_callbacks
Collection of threshold-specific callback functions with their thresholds.
void notify_tick(double value) override
Notifies all registered callbacks about a new sample.
void reset(float frequency=1, float amplitude=1.0, float offset=0, double phase=0.0)
Resets the generator's phase and parameters.
void on_threshold(const NodeHook &callback, double threshold, bool rising=true)
Registers a callback for every time the phasor crosses a threshold.
void set_frequency_modulator(const std::shared_ptr< Node > &modulator)
Sets a node to modulate the generator's frequency.
void save_state() override
Saves the node's current state for later restoration Recursively cascades through all connected modul...
Phasor(float frequency=1, double amplitude=1, float offset=0)
Basic constructor with fixed parameters.
double process_sample(double input=0.) override
Processes a single input sample and generates a phasor sample.
void clear_modulators()
Removes all modulation connections.
void on_phase_wrap(const NodeHook &callback)
Registers a callback for every phase wrap.
float m_offset
DC offset added to the output.
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.