Analyzers for each context, plus an internal ticker. Each context key holds data about its AnalyserNode, a Float32Array for FFT data, and so on.
A singleton cache used for audio buffers.
A singleton audio context used for playback of environmental audio.
A singleton audio context used for playback of interface sounds and effects.
A flag for whether video playback is currently locked by awaiting a user gesture
A singleton audio context used for playback of music.
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.
Get a map of the Sound objects which are currently playing.
The set of singleton Sound instances which are shared across multiple uses of the same sound path.
A Promise which resolves once the game audio API is unlocked and ready to use.
Static
ANALYSIS_A static inactivity threshold for audio analysis, in milliseconds.
If no band value is requested for a channel within this duration,
the analyzer is disabled to conserve resources (unless the analyzer is enabled with the keepAlive=true
option)
Static
AUDIO_An array containing all possible audio context names.
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.
For backwards compatibility, AudioHelper#context refers to the context used for music playback.
A global mute which suppresses all 3 audio channels.
Register an event listener to await the first mousemove gesture and begin playback once observed.
The unlocked audio context
Create a Sound instance for a given audio source URL
Sound creation options
Log a debugging message if the audio debugging flag is enabled.
The message to log
Disable the analyzer for a given context, disconnecting the AnalyserNode.
Enable the analyzer for a given context (music, environment, interface), attaching an AnalyserNode to its gain node if not already active.
Optional
options: { keepAlive?: boolean } = {}Optional
keepAlive?: booleanIf true, this analyzer will not auto-disable after inactivity.
Returns a singleton AudioContext if one can be created. An audio context may not be available due to limited resources or browser compatibility in which case null will be returned
A singleton AudioContext or null if one is not available
Returns a normalized band value in [0,1]. Optionally, we can subtract the actual gainNode (global) volume from the measurement.
Optional
options: { ignoreVolume?: boolean } = {}Optional
ignoreVolume?: booleanIf true, remove the real-time channel volume from the measurement.
The normalized band value in [0,1].
Retrieve a single "peak" analyzer value across the three main audio contexts (music, environment, interface). This takes the maximum of the three normalized [0,1] values for a given frequency band.
Optional
band: BandName = "all"The frequency band for which to retrieve an analyzer value.
Optional
options: { ignoreVolume?: boolean } = {}Optional
ignoreVolume?: booleanIf true, remove the real-time channel volume from the measurement.
A number in the [0,1] range representing the loudest band value among the three contexts.
Play a single Sound by providing its source.
The file path to the audio source being played
Optional
options: { context?: AudioContext } = {}Additional options which configure playback
Optional
context?: AudioContextA specific AudioContext within which to play
The created Sound which is now playing
Request that other connected clients begin preloading a certain sound path.
The source file path requested for preload
A Promise which resolves once the preload is complete
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
Stop sending audio level reports This stops listening to a stream and stops sending reports. If we aren't listening to any more streams, cancel the global analyser timer.
The id of the reports that passed to startLevelReports.
Static
_activateOpen socket listeners which transact ChatMessage data
Static
getGiven an input file path, determine a default name for the sound based on the filename
An input file path
A default sound name for the path
Static
hasTest whether a source file has a supported audio extension type
A requested audio source path
Does the filename end with a valid audio extension?
Static
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
playPlay a one-off sound effect which is not part of a Playlist
An object configuring the audio data to play.
Optional
autoplay?: booleanBegin playback of the audio effect immediately once it is loaded.
Default: false
.
Optional
channel?: stringAn audio channel in CONST.AUDIO_CHANNELS where the sound should play.
Default: "interface"
.
Optional
loop?: booleanLoop the audio effect and continue playing it until it is manually stopped.
Default: false
.
The audio source file path, either a public URL or a local path relative to the public directory.
Optional
volume?: numberThe volume level at which to play the audio, between 0 and 1. Default: 1
.
Optional
socketOptions: boolean | { recipients: string[] }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 (an array of User IDs) should receive the event
(all clients by default). Default: false
.
A Sound instance which controls audio playback, or nothing if data.autoplay
is false.
Static
preloadBegin loading the sound for a provided source URL adding its
The audio source path to preload
The created and loaded Sound ready for playback
Static
registerRegister client-level settings for global volume controls.
Static
volumeCounterpart to inputToVolume() Returns the input range value based on a volume
Value between [0, 1] of the volume level
Optional
order: number = 1.5The exponent of the curve
Static
volumeConverts a volume level to a human-readable percentage value.
Value in the interval [0, 1] of the volume level.
Optional
options: { decimalPlaces?: number; label?: boolean } = {}Optional
decimalPlaces?: numberThe number of decimal places to round the percentage to.
Optional
label?: booleanPrefix the returned tooltip with a localized 'Volume: ' label. This should be used if the returned string is intended for assistive technologies, such as the aria-valuetext attribute.
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
foundry.Game#audio