Oscillators
Oscillators are the primary 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.
| Param | Type | Description |
|---|---|---|
| type | string | Waveform type (see below) |
| freq | signal | Frequency in Hz (not required for "noise") |
Waveform types
| Type | Description |
|---|---|
"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)
sine(440) |> out(@) // Sawtooth wave
saw(220) |> out(@) // Triangle wave
tri(110) |> out(@) // Square wave
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
phasor(2) |> out(@) // Create a sine from phasor using math sin()
sin(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
noise() * 0.3 |> out(@) // Filtered noise for hi-hats
noise() |> hp(@, 8000) * ar(trigger(8), 0.001, 0.05) |> out(@) // Noise sweep
noise() |> lp(@, 200 + sine(0.5) * 1000) |> out(@) FM synthesis
FM synthesis modulates the carrier’s frequency input with another oscillator. See fm-synthesis for the full treatment.
// Simple FM
sine(440 + sine(5) * 10) |> out(@) Related: fm-synthesis, Math Functions, Filters