IOscillator
Base template class for all oscillators. Provides common phase and frequency management.Template Parameters
Sample type (typically
double or float)Constructor
Initial phase value (0.0 to 1.0)
Initial frequency in Hz
Methods
Process
Frequency in Hz for this sample
SetFreqCPS
Frequency in cycles per second (Hz)
SetSampleRate
Sample rate in samples per second
Reset
SetPhase
Phase value (0.0 to 1.0)
Protected Members
Current phase (0.0 to 1.0)
Phase increment per sample
Current sample rate
Initial phase for reset
SinOscillator
Standard sine wave oscillator usingstd::sin(). Suitable for general-purpose use where performance is not critical.
Template Parameters
Sample type (typically
double or float)Constructor
Initial phase value (0.0 to 1.0)
Initial frequency in Hz
Methods
Process (no arguments)
Process (with frequency)
Frequency in Hz for this sample
Usage Example
FastSinOscillator
High-performance sine wave oscillator using table lookup with linear interpolation. Based on Miller Puckette’s Pure Data implementation.This oscillator uses a clever floating-point bit manipulation technique to extract table indices and fractional parts efficiently. It’s significantly faster than
SinOscillator for CPU-intensive applications.Template Parameters
Sample type (typically
double or float)Constructor
Initial phase value (0.0 to 1.0)
Initial frequency in Hz
Methods
Process (no arguments)
Process (with frequency)
Frequency in Hz for this sample
Lookup (static)
Phase in radians
ProcessBlock
Output buffer to fill with generated samples
Number of samples to generate
Public Members
Last generated output value
Usage Example
Performance Considerations
Table Size
Uses a 512-sample lookup table with linear interpolation
Bit Manipulation
Leverages IEEE 754 double precision format for fast indexing
Block Processing
ProcessBlock() is more efficient than calling Process() in a loopCache Friendly
Small table size fits in CPU cache
Implementation Details
Phase Representation
All oscillators use normalized phase values:- Range: 0.0 to 1.0
- Wrapping: Automatic wrapping when phase exceeds 1.0
- Precision: Double precision floating point
Frequency Calculation
Phase increment is calculated as:FastSinOscillator Algorithm
The fast oscillator uses a technique originally by Robert Höldrich:- Add a magic constant (UNITBIT32 = 1572864) to the phase
- Use a union to extract integer and fractional parts
- Use integer part as table index
- Use fractional part for linear interpolation
- Achieve sub-sample accuracy without expensive conversions
This technique only works with double precision floating point values in the range [-524288, +524288]. The oscillator phase is carefully managed to stay within this range.
Code Location
Source:IPlug/Extras/Oscillator.h:1