A Promise which resolves once the game audio API is unlocked and ready to use.
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 singleton audio context used for playback of music.
A singleton audio context used for playback of environmental audio.
A singleton audio context used for playback of interface sounds and effects.
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.
Private
#analyserMap of all streams that we listen to for determining the decibel levels. Used for analyzing audio levels of each stream.
Private
#fftFast Fourier Transform Array. Used for analysing the decibel level of streams. The array is allocated only once then filled by the analyser repeatedly. We only generate it when we need to listen to a stream's level, so we initialize it to null.
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.
Static
Private
#analyzerAudio Context singleton used for analysing audio levels of each stream Only created if necessary to listen to audio streams.
For backwards compatibility, AudioHelper#context refers to the context used for music playback.
Create a Sound instance for a given audio source URL
Sound creation options
Play a single Sound by providing its source.
The file path to the audio source being played
Optional
options: { Additional options which configure playback
A specific AudioContext within which to play
The created Sound which is now playing
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
interval: number = 50The interval at which to produce reports.
Optional
smoothing: number = 0.1The smoothingTimeConstant to set on the audio analyser.
Returns whether 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
_onStatic
hasStatic
getStatic
registerStatic
_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
An audio channel in CONST.AUDIO_CHANNELS where the sound should play
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
volumeStatic
Private
#onStatic
Private
#onStatic
Private
#onStatic
Private
#create
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