@maruaudio/dsp/oscillators/variable-shape ports DaisySP's VariableShapeOscillator: a waveform that morphs from triangle (shape 0) through saw (0.5) to square (1), with pulse width and optional hard sync to a master frequency. Pulse edge, phase wrap and sync reset are band-limited with BLEP and integrated-BLEP residuals at their sub-sample times. State and arithmetic are f32; the output is one sample late.
Parameters
| Path | Setter | Range as coded | Default | Unit |
|---|---|---|---|---|
frequency | setVariableShapeOscillatorFrequency | frequency / sampleRate clamped to 0..0.25 | 220 | Hz |
syncFrequency | setVariableShapeOscillatorSyncFrequency | Same 0..0.25 normalized clamp | 440 | Hz |
pulseWidth | setVariableShapeOscillatorPulseWidth | 2 × f to 1 − 2 × f (f the normalized frequency); 0.5 at the ceiling | 0.5 | fraction |
shape | setVariableShapeOscillatorShape | 0 to 1 | 0 | morph |
enabled | setVariableShapeOscillatorSync | 0 off, anything else on | 0 | flag |
gain | setVariableShapeOscillatorGain | 0 to 1 | 1 | linear |
Lifecycle
initVariableShapeOscillatorNode(sampleRate) sets the sync frequency, the frequency and then the pulse width (upstream Init sets the width first) → setters → variableShapeOscillatorNodeTick per sample → resetVariableShapeOscillatorNode, which clears phases and residuals only. prepareVariableShapeOscillatorNodeSampleRate re-derives both increments from the stored Hz values.
When to use it
A synth oscillator that morphs between triangle, saw and square, or a hard-sync voice whose sync frequency sets the pitch.
Limits
- Mono sample tick, one sample of latency. The tick does not apply
gain; the Graph node multiplies by it. - Set frequency before pulse width: the width clamp uses the frequency then stored, and only reaching the 0.25 ceiling resets the width (to 0.5).
- At most two transitions (edge and wrap) per sample, as the 0.25 ceiling allows. Widths of exactly 0 and 1 use a finite slope, so 0 Hz stays finite.