Class Synth

The base interface for any sound-producing entity, including individual sounds, groups, and playbacks. BaseSound

Hierarchy

  • PlaybackContainer<typeof FilterManager, this> & FilterManager<this>
    • Synth

Implements

Constructors

  • Parameters

    Returns Synth

Properties

_filters: BiquadFilterNode[] = []
_oscillatorOptions: Partial<OscillatorOptions>
_position: Position = ...
_routeTarget: null | Bus = null

Primary route target. null means master. See Sound for full notes.

_sends: Map<Bus, number> = ...

Send target → send gain value. See Sound._sends for notes.

_stereoPan: number = 0
_threeDOptions: ThreeDOptions = ...

Canonical 3D-audio configuration storage. Always holds a fully-populated HRTF variant (ThreeDOptions with panType: "HRTF") so callers reading via the getter never see undefined fields. Setting the stereo variant replaces this with the stereo shape (no stale HRTF fields).

_volume: number = 1
cacophony?: Cacophony
context: BaseContext
eventEmitter: TypedEventEmitter<SynthEvents> = ...
globalGainNode: GainNode
panType: PanType = "HRTF"
playbacks: SynthPlayback[] = []
soundType: SoundType = "oscillator"

Accessors

  • get frequency(): number
  • Returns number

  • set frequency(frequency): void
  • Parameters

    • frequency: number

    Returns void

  • get isPlaying(): boolean
  • Returns a boolean indicating whether the object is currently playing. an object is playing if any of its playbacks are currently playing.

    Returns boolean

  • get oscillatorOptions(): Partial<OscillatorOptions>
  • Returns Partial<OscillatorOptions>

  • set oscillatorOptions(options): void
  • Parameters

    • options: Partial<OscillatorOptions>

    Returns void

  • get position(): Position
  • Retrieves the current 3D spatial position of the sound in the audio context. The position is returned as an array of three values[x, y, z].

    Returns Position

  • set position(position): void
  • Sets the 3D spatial position of the sound in the audio context. The position is an array of three values[x, y, z]. This method updates the position of all active playbacks of the sound.

    Parameters

    Returns void

  • get stereoPan(): number
  • Returns number

  • set stereoPan(value): void
  • Parameters

    • value: number

    Returns void

  • get threeDOptions(): ThreeDOptions
  • Returns a fresh copy of the canonical 3D-audio configuration. The clone prevents callers from mutating the container's internal state via the returned reference (previously the raw _threeDOptions object leaked).

    Returns ThreeDOptions

  • set threeDOptions(options): void
  • Accepts either a full canonical ThreeDOptions value, or a partial HRTF-options override (legacy ergonomics). When a partial is provided the existing variant is merged in place — and if the existing variant is stereo, the partial is interpreted as a switch back to HRTF defaults plus the override (no stale stereo fields). When a full variant is provided with a different panType, the storage is replaced wholesale so stale fields from the previous variant cannot be observed via the getter.

    Parameters

    Returns void

  • get type(): OscillatorType
  • Returns OscillatorType

  • set type(type): void
  • Parameters

    • type: OscillatorType

    Returns void

  • get volume(): number
  • Returns number

  • set volume(volume): void
  • Parameters

    • volume: number

    Returns void

Methods

  • Parameters

    • bus: Bus
    • gainValue: number

    Returns void

  • Parameters

    Returns void

  • Adds a BiquadFilterNode to the container's filter chain. Filters are cloned when creating new playbacks - existing playbacks are not affected. Each playback gets independent filter instances for isolated processing.

    Parameters

    Returns void

  • Returns void

  • Clones the current Synth instance, creating a deep copy with the option to override specific properties. This method allows for the creation of a new, independent Synth instance based on the current one, with the flexibility to modify certain attributes through the overrides parameter. This is particularly useful for creating variations of a synth without affecting the original instance. The cloned instance includes all properties, playback settings, and filters of the original, unless explicitly overridden.

    Parameters

    • overrides: Partial<SynthCloneOverrides> = {}

      An object specifying properties to override in the cloned instance. This can include audio settings like volume, playback rate, and spatial positioning, as well as more complex configurations like 3D audio options and filter adjustments.

    Returns Synth

  • Type Parameters

    • K extends "stop" | "play" | "pause" | "resume" | "ended" | "volumeChange" | "error" | "fadeStart" | "fadeEnd" | "fadeCancel" | "frequencyChange" | "typeChange" | "detuneChange"

    Parameters

    Returns void

  • Type Parameters

    • K extends "stop" | "play" | "pause" | "resume" | "ended" | "volumeChange" | "error" | "fadeStart" | "fadeEnd" | "fadeCancel" | "frequencyChange" | "typeChange" | "detuneChange"

    Parameters

    Returns Promise<void>

  • Fades in all playbacks from silence to their current volume.

    Parameters

    • duration: number

      The fade duration in milliseconds.

    • Optional type: FadeType

      The fade curve type. Defaults to "linear".

    Returns Promise<void>

    Resolves when all fades complete.

  • Fades out all playbacks from their current volume to silence.

    Parameters

    • duration: number

      The fade duration in milliseconds.

    • Optional type: FadeType

      The fade curve type. Defaults to "linear".

    Returns Promise<void>

    Resolves when all fades complete.

  • Fades the volume of all playbacks to a target value over a duration.

    Parameters

    • value: number

      The target volume (0 to 1).

    • duration: number

      The fade duration in milliseconds.

    • Optional type: FadeType

      The fade curve type. Defaults to "linear".

    Returns Promise<void>

    Resolves when all fades complete.

  • Remove event listener.

    Type Parameters

    • K extends "stop" | "play" | "pause" | "resume" | "ended" | "volumeChange" | "error" | "fadeStart" | "fadeEnd" | "fadeCancel" | "frequencyChange" | "typeChange" | "detuneChange"

    Parameters

    • event: K
    • listener: ((data) => void)

    Returns void

  • Register event listener.

    Type Parameters

    • K extends "stop" | "play" | "pause" | "resume" | "ended" | "volumeChange" | "error" | "fadeStart" | "fadeEnd" | "fadeCancel" | "frequencyChange" | "typeChange" | "detuneChange"

    Parameters

    • event: K
    • listener: ((data) => void)

    Returns (() => void)

    Cleanup function

      • (): void
      • Returns void

  • Returns SynthPlayback[]

  • Generates a Playback instance for the synth without starting playback. This allows for pre-configuration of playback properties such as volume and position before the synth is actually played.

    Returns SynthPlayback[]

  • Removes a BiquadFilterNode from the container's filter chain. Only affects future playbacks - existing playbacks retain their cloned filters.

    Parameters

    Returns void

    Throws

    If the filter was never added to this container.

  • Parameters

    Returns void

  • Routes this Synth to a Bus (or back to master). See Sound.routeTo for full semantics — Synth mirrors the behavior exactly.

    Parameters

    • target: string | Bus
    • Optional sendGain: number

    Returns void

  • Fades out all playbacks then stops them.

    Parameters

    • duration: number

      The fade-out duration in milliseconds.

    • Optional type: FadeType

      The fade curve type. Defaults to "linear".

    Returns Promise<void>

    Resolves when the fade completes and all playbacks are stopped.