The primary Audio Context used to play client-facing sounds. The context is undefined until the user's first gesture is observed.
The set of singleton Sound instances which are shared across multiple uses of the same sound path.
Get a map of the Sound objects which are currently playing.
A user gesture must be registered before audio can be played. This Array contains the Sound instances which are requested for playback prior to a gesture. Once a gesture is observed, we begin playing all elements of this Array.
Sound
A flag for whether video playback is currently locked by awaiting a user gesture
A Promise which resolves once the game audio API is unlocked and ready to use.
A singleton cache used for audio buffers.
Private
#analyserInterval ID as returned by setInterval for analysing the volume of streams When set to 0, means no timer is set.
Static
levelThe Native interval for the AudioHelper to analyse audio levels from streams Any interval passed to startLevelReports() would need to be a multiple of this value.
Static
THRESHOLD_The cache size threshold after which audio buffers will be expired from the cache to make more room. 1 gigabyte, by default.
Create a Sound instance for a given audio source URL
Sound creation options
Registers a stream for periodic reports of audio levels. Once added, the callback will be called with the maximum decibel level of the audio tracks in that stream since the last time the event was fired. The interval needs to be a multiple of AudioHelper.levelAnalyserNativeInterval which defaults at 50ms
An id to assign to this report. Can be used to stop reports
The MediaStream instance to report activity on.
The callback function to call with the decibel level. callback(dbLevel)
(optional) The interval at which to produce reports.
(optional) The smoothingTimeConstant to set on the audio analyser. Refer to AudioAnalyser API docs.
Returns whether or not listening to the stream was successful
Private
#ensureEnsures the global analyser timer is started
We create only one timer that runs every 50ms and only create it if needed, this is meant to optimize things and avoid having multiple timers running if we want to analyse multiple streams at the same time. I don't know if it actually helps much with performance but it's expected that limiting the number of timers running at the same time is good practice and with JS itself, there's a potential for a timer congestion phenomenon if too many are created.
Private
#cancelPrivate
#emitPrivate
_onPrivate
_onStatic
registerStatic
hasStatic
getStatic
_activateStatic
playPlay a one-off sound effect which is not part of a Playlist
An object configuring the audio data to play
The audio source file path, either a public URL or a local path relative to the public directory
The volume level at which to play the audio, between 0 and 1.
Begin playback of the audio effect immediately once it is loaded.
Loop the audio effect and continue playing it until it is manually stopped.
Options which only apply when emitting playback over websocket. As a boolean, emits (true) or does not emit (false) playback to all other clients As an object, can configure which recipients should receive the event.
A Sound instance which controls audio playback.
AudioHelper.play({src: "sounds/lock.wav", volume: 0.8, loop: false}, true);
Static
preloadStatic
inputReturns the volume value based on a range input volume control's position. This is using an exponential approximation of the logarithmic nature of audio level perception
Value between [0, 1] of the range input
Optional
order: number = 1.5The exponent of the curve
Static
volume
A helper class to provide common functionality for working with the Web Audio API. https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API A singleton instance of this class is available as game#audio.
See
Game#audio
Alias
game.audio