ResonanceSingleton
Class for managing sounds
Static Member Summary
Static Public Members | ||
public static |
The frame rate at which to fade the sounds |
|
public static |
The max speed this sound can be played at |
|
public static |
The max number of sounds that can be recycled |
|
public static |
The max volume to be used |
|
public static |
The min volume to be used |
|
public static |
|
|
public static |
|
Constructor Summary
Public Constructor | ||
public |
|
Member Summary
Public Members | ||
public |
The checker function to resolve to true or false denoting if a sound can be played Master control over which sounds can play |
|
public |
audioCtx: AudioContext The audio context all audio will dervie from |
|
public |
An object that stores fade information |
|
public |
|
|
public |
gainNode: GainNode Gain node |
|
public |
An object that stores the buffer data of a sound so it does not have to be loaded each time |
|
public |
Mute status |
|
public |
Array of sounds that are currently paused |
|
public |
Array of sounds that are queued for fading |
|
public |
Array of sounds that are queued for playing |
|
public |
|
|
public |
|
|
public |
Array of sounds that can be resused |
|
public |
Array of sounds that are currently playing |
|
public |
Current state of the library |
|
public |
version: * The version of the module. |
|
public |
The master volume |
Private Members | ||
private |
|
|
private |
The logger module this module uses to log errors / logs. |
Method Summary
Public Methods | ||
public |
Adds a filter to be applied to sounds. |
|
public |
adjustVolume(pVolume: number): ResonanceSingleton Function to adjust master volume |
|
public |
Function to check whether this library can play a sound at a given moment. |
|
public |
createSound(pSoundPath: number, pVolume: number, pStartTime: number, pEndTime: number, pSave: boolean, pPlayUnfocused: boolean, pPlaybackRate: number, pLoop: boolean): Sound |
|
public |
emit(pSoundPath: string, pVolume: number, pStartTime: number, pEndTime: number, pPlaybackRate: number, -: Function): SoundSource Plays a sound that is not stored. |
|
public |
enableChecker(pCheckerFunction: Function): ResonanceSingleton API for the developer to define when a sound can and cannot be played. |
|
public |
Fades this sound to the specified volume in the specified duration via the specified ease |
|
public |
Checks if the sound manager is currently muted |
|
public |
This effectively kills all sounds in the game and subjects them to be recycled |
|
public |
pauseAllSounds(pFocus: boolean): ResonanceSingleton Pauses all sounds in the game |
|
public |
removeFilter(pSound: Sound, pFilter: Object) Removes a filter from being applied to sounds. |
|
public |
resumeAllSounds(pFocus: boolean): ResonanceSingleton Resumes all sounds in games |
|
public |
stopAllSounds(pException: Array): ResonanceSingleton This effectively stops all sounds in the game except those specified in the pException array |
|
public |
Master mute |
|
public |
unloadSound(pSoundPath: string): ResonanceSingleton Removes the loaded audio buffer data for this sound |
Private Methods | ||
private |
|
|
private |
recycleSound(pSound: Sound): ResonanceSingleton Recycles the sound for reuse later instead of deleting it. |
|
private |
This will start playing sounds that were initially blocked by not having a user gesture. |
Static Public Members
Public Constructors
public constructor() source
Public Members
public abilityToPlaySound: Function source
The checker function to resolve to true or false denoting if a sound can be played Master control over which sounds can play
public loadedBuffers: Object source
An object that stores the buffer data of a sound so it does not have to be loaded each time
Private Members
private _previousGainNodeValue: * source
Public Methods
public adjustVolume(pVolume: number): ResonanceSingleton source
Function to adjust master volume
Params:
Name | Type | Attribute | Description |
pVolume | number | The number to change the volume to |
public canPlaySound(): boolean source
Function to check whether this library can play a sound at a given moment.
public createSound(pSoundPath: number, pVolume: number, pStartTime: number, pEndTime: number, pSave: boolean, pPlayUnfocused: boolean, pPlaybackRate: number, pLoop: boolean): Sound source
Params:
Name | Type | Attribute | Description |
pSoundPath | number | The path of the sound file |
|
pVolume | number |
|
The volume of the sound |
pStartTime | number |
|
The start time of this sound (to play a clipped version) |
pEndTime | number |
|
The end time of this sound (to play a clipped version) |
pSave | boolean |
|
Whether to save this sound, or recycle it when it's completed |
pPlayUnfocused | boolean |
|
If this sound is set to true then it will not be paused automatically when the game screen is not focused |
pPlaybackRate | number |
|
The rate at which the sound is played, Higher numbers for faster playback (MAX 10) |
pLoop | boolean |
|
Whether this sound should loop or not |
Return:
Sound | A sound object that has vast API on controlling it |
public emit(pSoundPath: string, pVolume: number, pStartTime: number, pEndTime: number, pPlaybackRate: number, -: Function): SoundSource source
Plays a sound that is not stored. Plays the sound only. You can only kill this sound, no repeat, no changing volume, etc
Params:
Name | Type | Attribute | Description |
pSoundPath | string | The path to the file |
|
pVolume | number |
|
The volume to play the sound |
pStartTime | number |
|
The start time of this sound (to play a clipped version) |
pEndTime | number |
|
The end time of this sound (to play a clipped version) |
pPlaybackRate | number |
|
The rate at which the sound is played, Higher numbers for faster playback (MAX 10) |
- | Function | A callback to call when this sound has finished playing. |
Return:
SoundSource | The source to this emitted sound. Call source.kill() to stop this sound while its playing. This is the only API this sound has |
public enableChecker(pCheckerFunction: Function): ResonanceSingleton source
API for the developer to define when a sound can and cannot be played. Any sound that tries to play while this returns false will not play Enables a checker to become the master checker over whether a sound can play If their defined conditions return false, then the sound cannot be played
Params:
Name | Type | Attribute | Description |
pCheckerFunction | Function | The function that will resolve to true or false denoting if a sound can be played |
public fade(pVolume: number, pDuration: number, pEase: function, pCallback: function): ResonanceSingleton source
Fades this sound to the specified volume in the specified duration via the specified ease
public killAllSounds(): ResonanceSingleton source
This effectively kills all sounds in the game and subjects them to be recycled
public pauseAllSounds(pFocus: boolean): ResonanceSingleton source
Pauses all sounds in the game
Params:
Name | Type | Attribute | Description |
pFocus | boolean | If this function was called automatically by the game being unfocused |
public removeFilter(pSound: Sound, pFilter: Object) source
Removes a filter from being applied to sounds.
public resumeAllSounds(pFocus: boolean): ResonanceSingleton source
Resumes all sounds in games
Params:
Name | Type | Attribute | Description |
pFocus | boolean | If this function was called automatically by the game being focused |
public stopAllSounds(pException: Array): ResonanceSingleton source
This effectively stops all sounds in the game except those specified in the pException array
Params:
Name | Type | Attribute | Description |
pException | Array | an array of sounds that should not stop |
public unloadSound(pSoundPath: string): ResonanceSingleton source
Removes the loaded audio buffer data for this sound
Params:
Name | Type | Attribute | Description |
pSoundPath | string | The path of the sound file |
Private Methods
private playQueuedSounds() source
private recycleSound(pSound: Sound): ResonanceSingleton source
Recycles the sound for reuse later instead of deleting it. All binding info on the sound is removed
Params:
Name | Type | Attribute | Description |
pSound | Sound | The sound to recycle |
private resumeAudioCtx() source
This will start playing sounds that were initially blocked by not having a user gesture. This will also restart sounds when a mobile device backs out of an app, and then rejoins the app