Skip to main content

SoundManager <Channel, SoundName>

Manages a set of sounds through a Web Audio mixer graph:

Sound.output → mix gain → SoundChannel (input → output) → SoundManager.output → speakers

Master, channel and per-sound mix volumes and mutes compose in the graph, so muting is silent playback rather than a pause and none of it touches Sound.volume. A SoundManager is Loadable, add it to a Loader to load every sound it manages.

Implements

Index

Constructors

constructor

Properties

publicchannel

channel: ChannelCollection<Channel>

publicdata

data: AudioBuffer[]

Decoded audio of every managed sound once loaded, see Loadable

publicreadonlyinput

input: GainNode

Master bus input every channel (and channel-less sound) is mixed into

publicmaxConcurrentTracks

maxConcurrentTracks: number = Infinity

Maximum number of simultaneously playing tracks across ALL managed sounds. Default is Infinity (unbounded). When the cap is reached, new play() calls are dropped.

publicreadonlyoutput

output: GainNode

Master gain carrying the master volume and mute, connected to the audio context destination

publicvoiceStealing

voiceStealing: boolean = false

Stop the oldest playing track to make room when a cap is reached instead of dropping the new play

Accessors

publicmuted

  • get muted(): boolean
  • Whether the master output is muted


    Returns boolean

publicvolume

  • get volume(): number
  • set volume(volume: number): void
  • Master volume [0-1], default 1


    Returns number

  • Parameters

    • volume: number

    Returns void

Methods

publicgetChannel

publicgetChannels

publicgetSound

publicgetSounds

  • getSounds(): readonly Sound<string>[]
  • Returns readonly Sound<string>[]

publicgetSoundsForChannel

  • getSoundsForChannel(channel: Channel | AnyString): readonly Sound<string>[]
  • Parameters

    Returns readonly Sound<string>[]

publicgetVolume

  • getVolume(name: SoundName): number
  • getVolume(sound: Sound): number
  • Get the mix volume of a tracked sound (or Sound.volume for an untracked one)


    Parameters

    • name: SoundName

    Returns number

publicisLoaded

  • isLoaded(): boolean
  • Returns true if the loadable is loaded


    Returns boolean

publicisMuted

  • isMuted(name: SoundName): boolean
  • isMuted(sound: Sound): boolean
  • Whether a sound is silenced by its own mute, its channel's mute, or the master mute


    Parameters

    • name: SoundName

    Returns boolean

publicload

  • load(): Promise<AudioBuffer[]>
  • Load every managed sound


    Returns Promise<AudioBuffer[]>

publicmute

  • mute(name?: SoundName): void
  • mute(sound: Sound): void
  • Mute a tracked sound, or the master output when no sound is given. Playback continues silently.


    Parameters

    • optionalname: SoundName

    Returns void

publicplay

  • play(name: SoundName, options?: number | PlayOptions): Promise<boolean>
  • play(sound: Sound, options?: number | PlayOptions): Promise<boolean>
  • Play a sound with optional one-off PlayOptions. Resolves to false if the sound is unknown or dropped by a concurrency cap. Muted sounds still play (silently) so they are audible mid-clip when unmuted.


    Parameters

    Returns Promise<boolean>

publicplayingCount

  • playingCount(): number
  • Total number of currently-playing tracks across all managed sounds


    Returns number

publicsetChannel

  • setChannel(name: SoundName, channel: Channel | null): void
  • setChannel(sound: Sound, channel: Channel | null): void
  • Route a tracked sound through a channel, or null for straight to the master output


    Parameters

    • name: SoundName
    • channel: Channel | null

    Returns void

publicsetVolume

  • setVolume(name: SoundName, volume?: number): void
  • setVolume(sound: Sound, volume?: number): void
  • Set the mix volume [0-1] of a tracked sound (or Sound.volume for an untracked one)


    Parameters

    • name: SoundName
    • optionalvolume: number

    Returns void

publicstart

publicstop

  • stop(name?: SoundName): void
  • stop(sound: Sound): void
  • Parameters

    • optionalname: SoundName

    Returns void

publictoggle

  • toggle(name?: SoundName): void
  • toggle(sound: Sound): void
  • Parameters

    • optionalname: SoundName

    Returns void

publictrack

  • Start managing a sound, registered under name, the config's name, or the sound's own name. Its output is re-routed through the manager's mixer graph.


    Parameters

    Returns void

publicunmute

  • unmute(name?: SoundName): void
  • unmute(sound: Sound): void
  • Parameters

    • optionalname: SoundName

    Returns void

publicuntrack

  • untrack(name: SoundName): void
  • untrack(sound: Sound): void
  • Stop managing a sound, restoring its output straight to the speakers


    Parameters

    • name: SoundName

    Returns void

publicwireEngine

  • wireEngine(engine: Engine): void
  • Wire every managed sound (including ones tracked later) to the engine so they pause when hidden and stop with it. Called by the Loader.


    Parameters

    Returns void