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

    • context: IAudioContext
    • globalGainNode: GainNode
    • soundType: SoundType = SoundType.Oscillator
    • panType: PanType = "HRTF"
    • oscillatorOptions: Partial<OscillatorOptions> = {}

    Returns Synth

Properties

_filters: BiquadFilterNode[] = []
_oscillatorOptions: Partial<OscillatorOptions>
_position: Position = ...
_stereoPan: number = 0
_threeDOptions: PannerOptions = ...
_volume: number = 1
context: IAudioContext
eventEmitter: TypedEventEmitter<SynthEvents> = ...
globalGainNode: GainNode
panType: PanType = "HRTF"
playbacks: SynthPlayback[] = []
soundType: SoundType = SoundType.Oscillator

Accessors

  • get detune(): number
  • Returns number

  • set detune(detune): void
  • Parameters

    • detune: number

    Returns void

  • get filters(): BiquadFilterNode[]
  • Returns BiquadFilterNode[]

  • 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

    True if the object is playing, false otherwise.

  • 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

    The current position of the sound.

  • 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

    • position: Position

      The new position of the sound.

    Returns void

  • get stereoPan(): null | number
  • Returns null | number

  • set stereoPan(value): void
  • Parameters

    • value: number

    Returns void

  • get threeDOptions(): PannerOptions
  • Returns PannerOptions

  • set threeDOptions(options): void
  • Parameters

    • options: Partial<PannerOptions>

    Returns void

  • get type(): OscillatorType
  • Returns OscillatorType

  • set type(type): void
  • Parameters

    • type: OscillatorType

    Returns void

  • get volume(): number
  • Gets the volume of the sound. This volume level affects all current and future playbacks of this sound instance. The volume is specified as a linear value between 0 (silent) and 1 (full volume).

    Returns number

    The current volume of the sound.

  • set volume(volume): void
  • Sets the volume of the sound. This volume level affects all current and future playbacks of this sound instance. The volume is specified as a linear value between 0 (silent) and 1 (full volume).

    Parameters

    • volume: number

      The new volume level for the sound.

    Returns void

Methods

  • Adds a BiquadFilterNode to the container's filter chain. Filters are applied in the order they are added.

    Parameters

    • filter: BiquadFilterNode

      The filter to add to the chain.

    Returns void

  • Parameters

    • filters: BiquadFilterNode[]

    Returns void

  • Parameters

    • connection: any

    Returns any

  • 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

    A new Sound instance that is a clone of the current sound.

  • Parameters

    • oscillator: OscillatorNode

    Returns SynthPlayback[]

  • Type Parameters

    • K extends keyof SynthEvents

    Parameters

    • event: K
    • data: SynthEvents[K]

    Returns void

  • Type Parameters

    • K extends keyof SynthEvents

    Parameters

    • event: K
    • data: SynthEvents[K]

    Returns Promise<void>

  • Remove event listener.

    Type Parameters

    • K extends keyof SynthEvents

    Parameters

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

          • data: SynthEvents[K]

          Returns void

    Returns void

  • Register event listener.

    Type Parameters

    • K extends keyof SynthEvents

    Parameters

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

          • data: SynthEvents[K]

          Returns void

    Returns void

    Cleanup function

  • 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[]

    An array of SynthPlayback instances that are ready to be played.

  • Removes a BiquadFilterNode from the container's filter chain. If the filter is not part of the chain, the method has no effect.

    Parameters

    • filter: BiquadFilterNode

      The filter to remove from the chain.

    Returns void

  • Parameters

    • filters: BiquadFilterNode[]

    Returns void

  • Returns void