Sound
A small class to represent a sound. Has useful API to handle the sound.
Constructor Summary
Public Constructor | ||
public |
constructor(pSoundPath: number, pVolume: number, pStartTime: number, pEndTime: number, pSave: boolean, pPlayUnfocused: boolean, pPlaybackRate: number, pLoop: boolean): Sound |
Member Summary
Public Members | ||
public set |
Set the info of this sound The new value is not used, as this is a "read-only" variable. |
|
public get |
Get the info object of this sound |
|
public get |
Get the loop status of this sound |
|
public set |
Set the loop status of this sound |
|
public |
onEnded: * |
|
public |
onResumed: * |
|
public |
onStarted: * |
|
public |
onStopped: * |
|
public |
onSuspended: * |
|
public get |
playbackRate: number: * Get the playback status of this sound |
|
public set |
playbackRate(pNewPlaybackRate: number) Set the playback status of this sound |
|
public get |
Gets the current volume of this sound |
|
public set |
Sets the volume of this sound |
Private Members | ||
private |
Array of filters that are currently applied on this sound. |
|
private |
Info tied to this sound. |
|
private |
If this sound is to loop. |
|
private |
The playback rate of this sound. |
|
private |
The volume of this sound. |
|
private |
The duration of this sound. |
|
private |
The end time of ththise sound. |
|
private |
Events tied to this sound. |
|
private |
Object holding the fading information for this sound. |
|
private |
The gain node of this sound. |
|
private |
Whether this sound is loaded. |
|
private |
If this sound is muted. |
|
private |
The timestamp of this sound when it was paused so it can be resumed at the same timestamp. |
|
private |
If this sound is to play after it is loaded. |
|
private |
If this sound plays without window focus. |
|
private |
Whether to save this sound or not. |
|
private |
The path of the sound. |
|
private |
The source of this sound. |
|
private |
The start time of this sound. |
|
private |
The start timestamp of this sound. |
|
private |
The state of this sound. |
|
private |
Whether this sound was sent a stop signal. |
Method Summary
Public Methods | ||
public |
Adds a filter to be applied to this sound. |
|
public |
build(pSoundPath: number, pVolume: number, pStartTime: number, pEndTime: number, pSave: boolean, pPlayUnfocused: boolean, pPlaybackRate: number, pLoop: boolean): Sound |
|
public |
Fades this sound to the specified volume in the specified duration via the specified ease |
|
public |
Get the current timestamp of the sound playing |
|
public |
Attaches a callback to the specified event. |
|
public |
pause(): this Pauses this sound |
|
public |
Plays this sound |
|
public |
Start the queued fade |
|
public |
Removes all filters from this sound. |
|
public |
removeFilter(pFilter: Object) Removes a filter from being applied to this sound. |
|
public |
resume(): this Resumes playing this sound |
|
public |
Stops this sound from playing. |
|
public |
toggleLoop(): this Toggleable loop feature for this sound. |
|
public |
toggleMute(): this Toggleable mute feature for this sound. |
Private Methods | ||
private |
Get whether this sound will play when the window is unfocused |
|
private |
kill() Kills this sound. |
|
private |
load() Loads this sound and stores its data so future sounds can use the same buffer |
|
private |
restart(): this Restarts this sound |
|
private |
wipe() Resets this sound to default state |
Public Constructors
public constructor(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 playUnfocused then it will not be played 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 Members
public set info(pNewInfo: Object) source
Set the info of this sound The new value is not used, as this is a "read-only" variable. So any attempts to set it will not work
public get info: Objecct: {...undefined: Object} source
Get the info object of this sound
Return:
Objecct | The info object of this sound |
public onEnded: * source
public onResumed: * source
public onStarted: * source
public onStopped: * source
public onSuspended: * source
Private Members
Public Methods
public addFilter(pFilter: Object) source
Adds a filter to be applied to this sound.
Params:
Name | Type | Attribute | Description |
pFilter | Object | The filter to add. |
TODO:
- Allow more than one filter. Loop through the filters array and connect all filters after disconnecting.
public build(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 fade(pVolume: number, pDuration: number, pEase: function, pCallback: function): this source
Fades this sound to the specified volume in the specified duration via the specified ease
Return:
this | This sound instance |
public on(pEvent: Object, pCallback: Function): this source
Attaches a callback to the specified event.
Return:
this | The Sound instance |
public play(pResume: boolean): this source
Plays this sound
Params:
Name | Type | Attribute | Description |
pResume | boolean | If this is being played from a paused state |
Return:
this | This sound instance |
public removeFilter(pFilter: Object) source
Removes a filter from being applied to this sound.
Params:
Name | Type | Attribute | Description |
pFilter | Object | The filter to remove. |
public stop(pState: string): this source
Stops this sound from playing. If any filters are utilized on this sound they are removed.
Params:
Name | Type | Attribute | Description |
pState | string | The current state of this sound. It's used to figure out if a callback should be dispatched |
Return:
this | This sound instance |
public toggleLoop(): this source
Toggleable loop feature for this sound. Flips between loop and unlooped
Return:
this | This sound instance |
public toggleMute(): this source
Toggleable mute feature for this sound. Flips between muted and unmuted
Return:
this | This sound instance |
Private Methods
private canPlayUnfocused(): boolean source
Get whether this sound will play when the window is unfocused
private kill() source
Kills this sound. Wipes it, and recycles it if the recycle manager isn't full. If the recycle manager is full, this sound will become an empty class instance.