Audio Loom - v0.3.0
    Preparing search index...

    Class AudioManager

    AudioManager is a framework-agnostic audio management system built on the Web Audio API. It provides centralized control for organizing, playing, and managing audio assets in games and interactive applications.

    const audio = new AudioManager();

    // Initialize on user interaction (required by browsers)
    button.onclick = async () => {
    await audio.resumeAudioContext();
    };

    // Add and play sounds
    audio.addAudioTrack('explosion', 'sfx', '/sounds/explosion.wav');
    await audio.preload(['explosion']);
    audio.playAudioTrack('explosion');

    // Play background music with fade
    audio.addAudioTrack('music', 'music', '/sounds/track.mp3');
    await audio.fadeIn('music', 2000);
    Index

    Constructors

    Properties

    onTrackStart$: Observable<TrackStartEvent>

    Observable that emits when a track starts playing.

    onTrackEnd$: Observable<TrackEndEvent>

    Observable that emits when a track finishes playing.

    onLoadComplete$: Observable<LoadCompleteEvent>

    Observable that emits when a track's metadata is loaded and ready to play.

    onError$: Observable<AudioErrorEvent>

    Observable that emits when an audio error occurs.

    onPositionUpdate$: Observable<PositionUpdateEvent>

    Observable that emits when a 3D sound's position is updated.

    onOrientationUpdate$: Observable<OrientationUpdateEvent>

    Observable that emits when a 3D sound's orientation is updated.

    onDistanceThreshold$: Observable<DistanceThresholdEvent>

    Observable that emits when a 3D sound crosses a distance threshold.

    Accessors

    • get loggingEnabled(): boolean

      Gets or sets whether debug logging is enabled.

      Returns boolean

    • set loggingEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    Methods

    • Initializes the AudioContext and resumes it if suspended.

      Returns Promise<void>

    • Resumes a suspended AudioContext.

      Returns Promise<void>

    • Suspends the AudioContext to save resources.

      Returns Promise<void>

    • Checks if the AudioContext is initialized and running.

      Returns boolean

    • Sets the master volume that affects all audio output.

      Parameters

      • volume: number

      Returns void

    • Gets the current master volume level.

      Returns number

    • Enables or disables audio playback for a specific group.

      Parameters

      • group: string
      • enabled: boolean

      Returns void

    • Sets the volume for a specific audio group.

      Parameters

      • group: string
      • volume: number

      Returns void

    • Sets the maximum number of concurrent sounds for a group.

      Parameters

      • group: string
      • maxConcurrent: number

      Returns void

    • Checks if all tracks for a key are fully loaded and ready to play.

      Parameters

      • key: string

      Returns boolean

    • Preloads audio tracks into memory for low-latency playback.

      Parameters

      • keys: string[]

      Returns Promise<void>

    • Registers an audio track with the manager.

      Parameters

      • key: string
      • group: string
      • path: string

      Returns void

    • Plays a one-shot sound effect.

      Parameters

      • key: string

      Returns void

    • Starts continuous playback on a channel.

      Parameters

      • key: string
      • channelId: string = DEFAULT_CHANNEL

      Returns void

    • Stops continuous playback on a channel.

      Parameters

      • channelId: string = DEFAULT_CHANNEL

      Returns void

    • Pauses continuous playback on a channel.

      Parameters

      • channelId: string = DEFAULT_CHANNEL

      Returns void

    • Resumes paused continuous playback on a channel.

      Parameters

      • channelId: string = DEFAULT_CHANNEL

      Returns void

    • Starts playback with a gradual volume fade-in effect.

      Parameters

      • key: string
      • duration: number
      • channelId: string = DEFAULT_CHANNEL

      Returns Promise<void>

    • Gradually fades out and stops the current playback on a channel.

      Parameters

      • duration: number
      • channelId: string = DEFAULT_CHANNEL

      Returns Promise<void>

    • Cross-fades from the current track to a new track.

      Parameters

      • key: string
      • duration: number
      • channelId: string = DEFAULT_CHANNEL

      Returns Promise<void>

    • Stops all continuous playback on all channels.

      Returns void

    • Pauses all continuous playback on all channels.

      Returns void

    • Resumes all paused continuous playback on all channels.

      Returns void

    • Sets the playback speed/rate for a channel.

      Parameters

      • rate: number
      • channelId: string = DEFAULT_CHANNEL

      Returns void

    • Gets the current playback rate for a channel.

      Parameters

      • channelId: string = DEFAULT_CHANNEL

      Returns number | null

    • Seeks to a specific time position in the current track.

      Parameters

      • time: number
      • channelId: string = DEFAULT_CHANNEL

      Returns void

    • Gets the current playback time in seconds.

      Parameters

      • channelId: string = DEFAULT_CHANNEL

      Returns number | null

    • Gets the total duration of the current track in seconds.

      Parameters

      • channelId: string = DEFAULT_CHANNEL

      Returns number | null

    • Registers an impulse response for use with convolution reverb.

      Parameters

      • key: string
      • path: string

      Returns void

    • Preloads impulse response files into memory.

      Parameters

      • keys: string[]

      Returns Promise<void>

    • Checks if an impulse response is fully loaded and ready for use.

      Parameters

      • key: string

      Returns boolean

    • Sets the wet/dry mix for the effects bus.

      Parameters

      • wet: number

      Returns void

    • Gets the current wet/dry mix for the effects bus.

      Returns number

    • Applies a reverb effect using a loaded impulse response.

      Parameters

      • key: string | null

      Returns Promise<void>

    • Gets the key of the currently active reverb impulse response.

      Returns string | null

    • Sets the low-pass filter parameters for the effects bus.

      Parameters

      • frequency: number
      • Q: number = 1

      Returns void

    • Sets the high-pass filter parameters for the effects bus.

      Parameters

      • frequency: number
      • Q: number = 1

      Returns void

    • Checks if the effects bus has been initialized.

      Returns boolean

    • Gets comprehensive state information about the effects bus.

      Returns {
          initialized: boolean;
          wetMix: number;
          activeReverb: string | null;
          lowPass: FilterConfig | null;
          highPass: FilterConfig | null;
          registeredImpulses: string[];
      }

    • Sets whether a group should bypass the effects bus.

      Parameters

      • group: string
      • bypass: boolean

      Returns void

    • Checks if a group is currently bypassing the effects bus.

      Parameters

      • group: string

      Returns boolean

    • Gets a list of all groups that are currently bypassing effects.

      Returns string[]

    • Plays continuous audio at a specific position in 3D space.

      Parameters

      Returns Promise<void>

    • Updates the position of a playing 3D sound (one-shot).

      Parameters

      • instanceId: string
      • position: Vector3

      Returns boolean

    • Updates the position of a continuous 3D channel.

      Parameters

      Returns boolean

    • Checks if a sound instance is a 3D positioned sound.

      Parameters

      • instanceId: string

      Returns boolean

    • Checks if a channel is a 3D positioned channel.

      Parameters

      • channelId: string

      Returns boolean

    • Gets the current position of a 3D sound.

      Parameters

      • instanceId: string

      Returns Vector3 | null

    • Gets the current position of a 3D channel.

      Parameters

      • channelId: string

      Returns Vector3 | null

    • Sets the orientation of a playing 3D sound (one-shot).

      Parameters

      • instanceId: string
      • orientation: Vector3

      Returns boolean

    • Sets the orientation of a continuous 3D channel.

      Parameters

      • channelId: string
      • orientation: Vector3

      Returns boolean

    • Gets the current orientation of a 3D sound.

      Parameters

      • instanceId: string

      Returns Vector3 | null

    • Gets the current orientation of a 3D channel.

      Parameters

      • channelId: string

      Returns Vector3 | null

    • Updates the stereo pan position of a playing 2D panned sound.

      Parameters

      • instanceId: string
      • pan: number

      Returns boolean

    • Gets the current pan position of a 2D panned sound.

      Parameters

      • instanceId: string

      Returns number | null

    • Checks if a sound instance is a 2D panned sound.

      Parameters

      • instanceId: string

      Returns boolean

    • Unregisters distance callbacks for a sound.

      Parameters

      • instanceId: string

      Returns boolean

    • Stops all active one-shot sounds in a specific group.

      Parameters

      • group: string

      Returns void

    • Destroys the AudioManager and releases all resources.

      Returns void