@maruaudio/dsp/oscillators/polyblep is a sine, saw, square or triangle oscillator with an f32 phase accumulator and octave, semitone and cent offsets. Saw and square subtract the two-sample polynomial BLEP residual at each edge; the triangle is a leaky integrator (×0.999 per sample) of the blepped square. The per-waveform math is the shared voice stage code in voices/stages, the functions the subtractive voice's oscillator calls, so the two cannot diverge. Pitch is frequency × 2^(octave + semitone/12 + cents/1200).
Parameters
| Path | Setter | Range as coded | Default | Unit |
|---|---|---|---|---|
waveform | setOscillatorNodeWaveform | Rounded, then 0..3: sine, saw, square, triangle | 1 (saw) | index |
frequency | setOscillatorNodeFrequency | 0 to 20000 | 440 | Hz |
gain | setOscillatorNodeGain | 0 to 1 | 1 | linear |
octave | setOscillatorNodeOctave | −3 to +3 | 0 | octaves |
semitone | setOscillatorNodeSemitone | −12 to +12 | 0 | semitones |
cents | setOscillatorNodeCents | −100 to +100 | 0 | cents |
Lifecycle
initOscillatorNode(sampleRate) → setters → oscillatorNodeTick(state) per sample → resetOscillatorNode, which zeroes the phase and triangle state and keeps the settings. For note starts, resetOscillatorNodePhase(state, phase) wraps a phase in cycles and seeds the triangle integrator to match it, so a triangle started at phase 0 begins at its trough. There is no sample-rate prepare; build a new state for a new rate.
When to use it
A plain oscillator for a synth voice, a test tone or a modulation source that must match the subtractive voice's oscillator sample for sample.
Limits
- Mono sample tick. The tick returns the sample before gain; the caller multiplies by
gain, as the Graph node does. - The pitch
Math.powruns every tick. Changes apply on the next sample with no smoothing. - The clamps are conditional, so a NaN setting passes through.
resetOscillatorNodeat phase 0 leaves the triangle integrator at 0, which the source notes gives a unipolar startup transient.