builtins

Oscillators

Oscillators are the fundamental sound sources in synthesis. The osc() function is the unified interface for all oscillator types.

Oscillators are the fundamental sound sources in synthesis. The osc() function is the unified interface for all oscillator types.

osc

Generic Oscillator - Generates a waveform of the specified type.

ParamTypeDescription
typestringWaveform type (see below)
freqsignalFrequency in Hz (not required for "noise")

Waveform Types

TypeDescription
"sin"Sine wave - pure tone, no harmonics
"saw"Sawtooth wave - all harmonics, bright and buzzy
"tri"Triangle wave - odd harmonics, softer than saw
"sqr"Square wave - odd harmonics, hollow and punchy
"phasor"0-1 ramp, useful for modulation and wavetables
"ramp"Alias for phasor
"noise"White noise (freq parameter ignored)

Pitched Waveforms

// Sine wave (440 Hz)
osc("sin", 440) |> out(%, %)
// Sawtooth wave
osc("saw", 220) |> out(%, %)
// Triangle wave
osc("tri", 110) |> out(%, %)
// Square wave
osc("sqr", 110) * 0.3 |> out(%, %)

Phasor / Ramp

A phasor outputs a value that ramps from 0 to 1 over each cycle. Useful for driving wavetables, custom waveshaping, or as a modulation source.

// Use phasor for wavetable position
osc("phasor", 2) |> out(%, %)
// Create a sine from phasor using math sin()
sin(osc("phasor", 440) * 2 * 3.14159) |> out(%, %)

Noise

White noise contains equal energy at all frequencies. Useful for percussion, wind sounds, and as a modulation source. The frequency parameter is ignored.

// Raw noise
osc("noise") * 0.3 |> out(%, %)
// Filtered noise for hi-hats
osc("noise") |> hp(%, 8000) * ar(trigger(8), 0.001, 0.05) |> out(%, %)
// Noise sweep
osc("noise") |> lp(%, 200 + osc("sin", 0.5) * 1000) |> out(%, %)

FM Synthesis

// Simple FM
osc("sin", 440 + osc("sin", 5) * 10) |> out(%, %)
// FM using phasor as modulator
osc("sin", 440 + osc("phasor", 5) * 100) |> out(%, %)

Related: Math Functions, Filters