EZ Web Audio / createOscillator
Function: createOscillator()
Call Signature
createOscillator(
options?):Promise<Oscillator>
Defined in: packages/core/src/index.ts:756
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?
Optional oscillator configuration (frequency, type, filters, envelope)
Returns
Promise<Oscillator>
Promise resolving to an Oscillator instance
Example
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()
// Using note name instead of frequency
const a4 = await createOscillator({ note: 'A4', type: 'sine' })
a4.play()Call Signature
createOscillator(
audioContext,options?):Promise<Oscillator>
Defined in: packages/core/src/index.ts:757
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
audioContext
BaseAudioContext
options?
Optional oscillator configuration (frequency, type, filters, envelope)
Returns
Promise<Oscillator>
Promise resolving to an Oscillator instance
Example
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()
// Using note name instead of frequency
const a4 = await createOscillator({ note: 'A4', type: 'sine' })
a4.play()