Class: AudioManager

hcje/audio~AudioManager()

Class which provides a connection for all outputs and controls for all music and sound effects. The class is not exported by the module and can only be instantiated by calling the module's getAudioManager method.

Constructor

new AudioManager()

Construct the AudioManager

Source:

Members

context :AudioContext

The underlying AudioContext.

Type:
  • AudioContext
Source:

gain :AudioParam

The gain value. When changed, this is almost instantaneous but a small time constant is applied to minimise clicks.

Type:
  • AudioParam
Source:
See:

(readonly) inputNode

The input for the audio manager. This is where all nodes should connect if they want to connect to the destination of the underlying destination.

Source:

Methods

addAudioSfx(definition) → {Promise}

Create an AudioSfxPlayer. It is stored in a map of sound effects. It is only stored once ready to play, so it may not be available in the map immediately. If the definition includes a loop property, it is set to false as sound effects are not allowed to loop.

Parameters:
Name Type Description
definition module:hcje/audio~AudioDefinition | module:hcje/audio~SynthAudioDefinition

Details of the sound to add.

Source:
Returns:

Fulfils to true on success.

Type
Promise

playAudioSfx(title)

Play audio effect. The title is used as a lookup into the map of existing sound effects.

Parameters:
Name Type Description
title string

Title of the sound effect.

Source:

setMusic(definition) → {Promise}

Set the background music. The background music will automatically start. Any stop or start commands to the player are cached, so that if it takes a long time to load, the final playing state will still reflect the last command received.

Parameters:
Name Type Description
definition module:hcje/audio~AudioDefinition | module:hcje/audio~SynthAudioDefinition

Details of the music to add.

Source:
Returns:

Fulfils to true on success.

Type
Promise

startMusic()

Start playing the background music.

Source:

stopMusic()

Stop background music.

Source: