MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Nodes::Generator::Phasor Class Reference

Phase ramp generator node. More...

#include <Phasor.hpp>

+ Inheritance diagram for MayaFlux::Nodes::Generator::Phasor:
+ Collaboration diagram for MayaFlux::Nodes::Generator::Phasor:

Public Member Functions

 Phasor (float frequency=1, double amplitude=1, float offset=0)
 Basic constructor with fixed parameters.
 
 Phasor (const std::shared_ptr< Node > &frequency_modulator, float frequency=1, double amplitude=1, float offset=0)
 Constructor with frequency modulation.
 
 Phasor (float frequency, const std::shared_ptr< Node > &amplitude_modulator, double amplitude=1, float offset=0)
 Constructor with amplitude modulation.
 
 Phasor (const std::shared_ptr< Node > &frequency_modulator, const std::shared_ptr< Node > &amplitude_modulator, float frequency=1, double amplitude=1, float offset=0)
 Constructor with both frequency and amplitude modulation.
 
 ~Phasor () override=default
 Virtual destructor.
 
double process_sample (double input=0.) override
 Processes a single input sample and generates a phasor sample.
 
std::vector< double > process_batch (unsigned int num_samples) override
 Processes multiple samples at once.
 
void printGraph () override
 Prints a visual representation of the phasor waveform.
 
void printCurrent () override
 Prints the current parameters of the phasor generator.
 
void set_frequency (float frequency) override
 Sets the generator's frequency.
 
float get_frequency () const
 Gets the current base frequency.
 
void set_params (float frequency, double amplitude, float offset)
 Sets all basic parameters at once.
 
void set_frequency_modulator (const std::shared_ptr< Node > &modulator)
 Sets a node to modulate the generator's frequency.
 
void set_amplitude_modulator (const std::shared_ptr< Node > &modulator)
 Sets a node to modulate the generator's amplitude.
 
void clear_modulators ()
 Removes all modulation connections.
 
void reset (float frequency=1, float amplitude=1.0, float offset=0, double phase=0.0)
 Resets the generator's phase and parameters.
 
void set_phase (double phase)
 Sets the current phase of the phasor.
 
double get_phase () const
 Gets the current phase of the phasor.
 
void on_phase_wrap (const NodeHook &callback)
 Registers a callback for every phase wrap.
 
void on_threshold (const NodeHook &callback, double threshold, bool rising=true)
 Registers a callback for every time the phasor crosses a threshold.
 
bool remove_hook (const NodeHook &callback) override
 Removes a previously registered callback.
 
void remove_all_hooks () override
 Removes all registered callbacks.
 
void save_state () override
 Saves the node's current state for later restoration Recursively cascades through all connected modulator nodes Protected - only NodeSourceProcessor and NodeBuffer can call.
 
void restore_state () override
 Restores the node's state from the last save Recursively cascades through all connected modulator nodes Protected - only NodeSourceProcessor and NodeBuffer can call.
 
- Public Member Functions inherited from MayaFlux::Nodes::Generator::Generator
virtual ~Generator ()=default
 Virtual destructor for proper cleanup.
 
virtual void set_amplitude (double amplitude)
 Sets the generator's amplitude.
 
virtual double get_amplitude () const
 Gets the current base amplitude.
 
virtual void enable_mock_process (bool mock_process)
 Allows RootNode to process the Generator without using the processed sample.
 
virtual bool should_mock_process () const
 Checks if the generator should mock process.
 
virtual std::unique_ptr< NodeContextcreate_context (double value) override
 Creates a context object for callbacks.
 
- Public Member Functions inherited from MayaFlux::Nodes::Node
virtual ~Node ()=default
 Virtual destructor for proper cleanup of derived classes.
 
virtual void on_tick (const NodeHook &callback)
 Registers a callback to be called on each tick.
 
virtual void on_tick_if (const NodeHook &callback, const NodeCondition &condition)
 Registers a conditional callback.
 
virtual bool remove_conditional_hook (const NodeCondition &callback)
 Removes a previously registered conditional callback.
 
virtual void reset_processed_state ()
 Resets the processed state of the node and any attached input nodes.
 
virtual double get_last_output ()
 Retrieves the most recent output value produced by the node.
 
void register_channel_usage (uint32_t channel_id)
 Mark the specificed channel as a processor/user.
 
void unregister_channel_usage (uint32_t channel_id)
 Removes the specified channel from the usage tracking.
 
bool is_used_by_channel (uint32_t channel_id) const
 Checks if the node is currently used by a specific channel.
 
void request_reset_from_channel (uint32_t channel_id)
 Requests a reset of the processed state from a specific channel.
 
const std::atomic< uint32_t > & get_channel_mask () const
 Retrieves the current bitmask of active channels using this node.
 
NodeContextget_last_context ()
 Retrieves the last created context object.
 
void set_gpu_compatible (bool compatible)
 Sets whether the node is compatible with GPU processing.
 
bool is_gpu_compatible () const
 Checks if the node supports GPU processing.
 
std::span< const float > get_gpu_data_buffer () const
 Provides access to the GPU data buffer.
 

Protected Member Functions

void notify_tick (double value) override
 Notifies all registered callbacks about a new sample.
 
bool remove_threshold_callback (const NodeHook &callback)
 Removes a previously registered phase wrap callback.
 
- Protected Member Functions inherited from MayaFlux::Nodes::Node
virtual void reset_processed_state_internal ()
 Resets the processed state of the node directly.
 

Private Member Functions

void update_phase_increment (double frequency)
 Updates the phase increment based on a new frequency.
 

Private Attributes

double m_phase_inc {}
 Phase increment per sample.
 
float m_offset
 DC offset added to the output.
 
std::shared_ptr< Nodem_frequency_modulator
 Node that modulates the frequency.
 
std::shared_ptr< Nodem_amplitude_modulator
 Node that modulates the amplitude.
 
std::vector< NodeHookm_phase_wrap_callbacks
 Collection of phase wrap-specific callback functions.
 
std::vector< std::pair< NodeHook, double > > m_threshold_callbacks
 Collection of threshold-specific callback functions with their thresholds.
 
bool m_phase_wrapped
 Flag indicating whether the phase has wrapped in the current sample.
 
bool m_threshold_crossed
 Flag indicating whether the threshold has been crossed in the current sample.
 
double m_saved_phase {}
 
float m_saved_frequency {}
 
float m_saved_offset {}
 
double m_saved_phase_inc {}
 
double m_saved_last_output {}
 
bool m_state_saved {}
 

Additional Inherited Members

- Public Attributes inherited from MayaFlux::Nodes::Node
bool m_fire_events_during_snapshot = false
 Internal flag controlling whether notify_tick fires during state snapshots Default: false (events don't fire during isolated buffer processing) Can be exposed in future if needed via concrete implementation in parent.
 
std::atomic< Utils::NodeStatem_state { Utils::NodeState::INACTIVE }
 Atomic state flag tracking the node's processing status.
 
std::atomic< uint32_t > m_modulator_count { 0 }
 Counter tracking how many other nodes are using this node as a modulator.
 
- Protected Attributes inherited from MayaFlux::Nodes::Generator::Generator
double m_amplitude { 1.0 }
 Base amplitude of the generator.
 
float m_frequency { 440.0F }
 Base frequency of the generator.
 
double m_phase {}
 Current phase of the generator.
 
- Protected Attributes inherited from MayaFlux::Nodes::Node
double m_last_output { 0 }
 The most recent sample value generated by this oscillator.
 
bool m_gpu_compatible {}
 Flag indicating if the node supports GPU processing This flag is set by derived classes to indicate whether the node can be processed on the GPU.
 
std::unique_ptr< NodeContextm_last_context
 The last context object created for callbacks.
 
std::vector< float > m_gpu_data_buffer
 GPU data buffer for context objects.
 
std::vector< NodeHookm_callbacks
 Collection of standard callback functions.
 
std::vector< std::pair< NodeHook, NodeCondition > > m_conditional_callbacks
 Collection of conditional callback functions with their predicates.
 

Detailed Description

Phase ramp generator node.

The Phasor class generates a linearly increasing ramp from 0 to 1 that wraps around, creating a sawtooth-like waveform. This is a fundamental building block for many synthesis techniques and can be used to derive other waveforms.

Key features:

  • Configurable frequency, amplitude, and DC offset
  • Support for frequency modulation (changing ramp rate)
  • Support for amplitude modulation (changing ramp height)
  • Automatic registration with the node graph manager (optional)
  • Precise phase control for synchronization with other generators

Phasor generators are used extensively in audio and signal processing for:

  • Creating time-based effects and modulations
  • Serving as the basis for other waveforms (triangle, pulse, etc.)
  • Synchronizing multiple oscillators
  • Driving sample playback positions

The implementation uses a simple phase accumulation approach that ensures sample-accurate timing and smooth transitions.

Definition at line 31 of file Phasor.hpp.


The documentation for this class was generated from the following files: