Skip to content

EZ Web Audio / OscillatorOptions

Interface: OscillatorOptions

Defined in: packages/core/src/oscillator.ts:46

Configuration options for creating an Oscillator.

Example

typescript
const opts: OscillatorOptions = {
  frequency: 440,      // A4
  type: 'sawtooth',    // Rich harmonic content
  gain: 0.5,           // Half volume
  lowpass: {           // Filter out harsh highs
    frequency: 2000,
    q: 1
  },
  envelope: {          // ADSR for note shaping
    attack: 0.01,
    decay: 0.2,
    sustain: 0.5,
    release: 0.3
  }
}

Extends

  • BaseSoundOptions

Properties

allpass?

optional allpass: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:84

Allpass filter - shifts phase without changing amplitude.


bandpass?

optional bandpass: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:72

Bandpass filter - allows frequencies near cutoff, attenuates others.


clearTimeout()?

optional clearTimeout: (id) => void

Defined in: packages/core/src/base-sound.ts:45

Custom clearTimeout implementation.

Must match the setTimeout implementation. By default, the AudioContext-aware clearTimeout is used.

Parameters

id

number

Timeout ID returned by setTimeout

Returns

void

Inherited from

BaseSoundOptions.clearTimeout


detune?

optional detune: number

Defined in: packages/core/src/oscillator.ts:64

Detune in cents (100 cents = 1 semitone).


envelope?

optional envelope: EnvelopeOptions

Defined in: packages/core/src/oscillator.ts:86

ADSR envelope for amplitude shaping.


frequency?

optional frequency: number

Defined in: packages/core/src/oscillator.ts:62

Base frequency in Hz (default: 440).


gain?

optional gain: number

Defined in: packages/core/src/oscillator.ts:66

Initial gain/volume (0-1).


highpass?

optional highpass: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:70

Highpass filter - removes frequencies below cutoff.


highshelf?

optional highshelf: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:78

Highshelf filter - boosts/cuts frequencies above cutoff.


lowpass?

optional lowpass: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:74

Lowpass filter - removes frequencies above cutoff.


lowshelf?

optional lowshelf: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:76

Lowshelf filter - boosts/cuts frequencies below cutoff.


name?

optional name: string

Defined in: packages/core/src/base-sound.ts:23

Optional name for identifying this sound instance. Useful for debugging and when managing multiple sounds.

Inherited from

BaseSoundOptions.name


notch?

optional notch: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:82

Notch filter - attenuates frequencies at cutoff.


note?

optional note: string

Defined in: packages/core/src/oscillator.ts:60

Note name (e.g., 'A4', 'C3', 'Eb5'). Looked up in the frequency map. Takes precedence over frequency if both provided. Both flat (Db, Eb, Gb, Ab, Bb) and sharp (C#, D#, F#, G#, A#) notation are supported as enharmonic equivalents.

Example

typescript
// Play middle C
const osc = await createOscillator({ note: 'C4', type: 'sine' })

peaking?

optional peaking: OscillatorFilterOptions

Defined in: packages/core/src/oscillator.ts:80

Peaking filter - boosts/cuts frequencies around cutoff.


setTimeout()?

optional setTimeout: (fn, delayMillis) => number

Defined in: packages/core/src/base-sound.ts:35

Custom setTimeout implementation.

By default, an AudioContext-aware setTimeout is used that compensates for browser throttling. Override this if you need different timing behavior.

Parameters

fn

() => void

Function to call after delay

delayMillis

number

Delay in milliseconds

Returns

number

Timeout ID for cancellation

Inherited from

BaseSoundOptions.setTimeout


startOffset?

optional startOffset: number

Defined in: packages/core/src/oscillator.ts:48

Starting offset in seconds (rarely used for oscillators).


type?

optional type: OscillatorType

Defined in: packages/core/src/oscillator.ts:68

Waveform type: 'sine', 'square', 'sawtooth', or 'triangle'.