Skip to content

EZ Web Audio / createOscillator

Function: createOscillator()

createOscillator(options?): Promise<Oscillator>

Defined in: index.ts:351

Create an Oscillator for synthesizing audio from waveforms.

Oscillators generate sound from sine, square, sawtooth, or triangle waves. They support filters for tone shaping and ADSR envelopes for professional-quality synthesis.

Parameters

options?

OscillatorOptions

Optional oscillator configuration (frequency, type, filters, envelope)

Returns

Promise<Oscillator>

Promise resolving to an Oscillator instance

Example

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

// Simple sine wave at 440Hz (A4)
const synth = await createOscillator({ frequency: 440, type: 'sine' })
synth.play()
setTimeout(() => synth.stop(), 500)

// With ADSR envelope for piano-like decay
const piano = await createOscillator({
  frequency: 440,
  type: 'triangle',
  envelope: { attack: 0.01, decay: 0.3, sustain: 0.4, release: 0.5 }
})
piano.play()