LFO
lfo(opts)
Returns an LfoSpec that can be passed to modulatable machine parameters (e.g. cutoff on vasynth).
The LFO runs as a per-note OscillatorNode inside Web Audio API.
lfo(opts: { rate: number; // cycle length in beats (4 = one cycle every 4 beats) min: number; // minimum value (Hz) max: number; // maximum value (Hz) shape?: 'sine' | 'tri' | 'saw' | 'square'; // default: 'sine' offset?: number; // start phase offset: 1=max, -1=min, 0=center (default). sine only.}): LfoSpecThe lfo function is injected by the engine at runtime — it reads the current BPM automatically,
so rate is always expressed in musical beats rather than seconds.
Example
function* song(ctx) { const synth = vasynth({ wave: 'sawtooth', cutoff: lfo({ rate: 4, min: 300, max: 3000, shape: 'sine' }), gain: 0.5, }) const key = scales(4, 'A3:minor') while (true) { yield cast(synth, key, seq(4, '0,2,4,3'), ctx) }}Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
rate | number | — | LFO period in beats. 4 = one full cycle every 4 beats. |
min | number | — | Minimum modulation value. |
max | number | — | Maximum modulation value. |
shape | string | 'sine' | Oscillator shape: sine, tri, saw, square. |
offset | number | 0 | Start phase offset. 1 = start at max, -1 = start at min, 0 = center. Applies to sine only. Range: −1 to 1. |
Modulatable parameters
The following parameters accept an LfoSpec in addition to a plain number:
| Machine | Parameter |
|---|---|
vasynth | cutoff |
Notes
- The LFO oscillator starts fresh on every note trigger (per-note).
- BPM is captured at the moment the machine is created inside the generator loop, so tempo changes take effect from the next cycle.