Skip to content

EZ Web Audio / LFO

Class: LFO

Defined in: packages/core/src/lfo.ts:115

Low Frequency Oscillator (LFO) for modulating audio parameters.

An LFO produces a slow oscillation that can be connected to any audio parameter (gain, pan, frequency, filter cutoff, etc.) to create effects like tremolo, vibrato, auto-pan, and auto-filter.

Example

typescript
import { createLFO, createOscillator } from 'ez-web-audio'

// Tremolo
const synth = await createOscillator({ frequency: 440 })
const tremolo = createLFO({ frequency: 5, depth: 0.3, type: 'sine' })
tremolo.connect(synth, 'gain').start()
synth.play()

// Vibrato
const vibrato = createLFO({ frequency: 6, depth: 50 })
vibrato.connect(synth, 'frequency').start()

Constructors

Constructor

new LFO(options?): LFO

Defined in: packages/core/src/lfo.ts:126

Parameters

options?

LFOOptions

Returns

LFO

Accessors

depth

Get Signature

get depth(): number

Defined in: packages/core/src/lfo.ts:161

Current modulation depth

Returns

number

Set Signature

set depth(value): void

Defined in: packages/core/src/lfo.ts:165

Parameters
value

number

Returns

void


frequency

Get Signature

get frequency(): number

Defined in: packages/core/src/lfo.ts:135

Current oscillation frequency in Hz

Returns

number

Set Signature

set frequency(value): void

Defined in: packages/core/src/lfo.ts:139

Parameters
value

number

Returns

void


isRunning

Get Signature

get isRunning(): boolean

Defined in: packages/core/src/lfo.ts:201

Whether the LFO oscillator is currently running

Returns

boolean


type

Get Signature

get type(): LFOWaveform | PeriodicWave

Defined in: packages/core/src/lfo.ts:174

Current waveform type

Returns

LFOWaveform | PeriodicWave

Set Signature

set type(value): void

Defined in: packages/core/src/lfo.ts:178

Parameters
value

LFOWaveform | PeriodicWave

Returns

void

Methods

connect()

connect(target, paramName, options?): this

Defined in: packages/core/src/lfo.ts:215

Connect the LFO to a target's audio parameter.

Parameters

target

LFOTarget

BaseSound or BaseEffect instance to modulate

paramName

string

Parameter name: 'gain', 'pan', 'frequency', 'detune', or effect-specific

options?

LFOConnectOptions

Connection options (syncLifecycle, retrigger, depthUnit, depth)

Returns

this

this for chaining


disconnect()

disconnect(target?, paramName?): void

Defined in: packages/core/src/lfo.ts:346

Disconnect from target(s).

Parameters

target?

LFOTarget

If provided, disconnect all connections to this target

paramName?

string

If provided with target, disconnect only the specific param

Returns

void


dispose()

dispose(): void

Defined in: packages/core/src/lfo.ts:447

Dispose the LFO, releasing all resources.

Stops the oscillator, disconnects all connections, and restores patched dispose methods. Idempotent — safe to call multiple times.

Returns

void


rampDepth()

rampDepth(value, duration): void

Defined in: packages/core/src/lfo.ts:519

Smoothly ramp the modulation depth.

Parameters

value

number

Target depth

duration

number

Ramp duration in seconds

Returns

void


rampFrequency()

rampFrequency(value, duration): void

Defined in: packages/core/src/lfo.ts:501

Smoothly ramp the oscillation frequency.

Parameters

value

number

Target frequency in Hz

duration

number

Ramp duration in seconds

Returns

void


start()

start(): this

Defined in: packages/core/src/lfo.ts:376

Start the LFO oscillator.

Returns

this

this for chaining

Throws

If no AudioContext available (call connect() first)


stop()

stop(): this

Defined in: packages/core/src/lfo.ts:419

Stop the LFO oscillator. Can be restarted with start().

Returns

this

this for chaining


syncToBPM()

syncToBPM(bpm, noteLength): this

Defined in: packages/core/src/lfo.ts:474

Set LFO frequency to match a musical note length at a given BPM.

Parameters

bpm

number

Beats per minute

noteLength

string

Note length string (e.g., '1/4', '1/8', '1/16')

Returns

this

this for chaining