Class Sound

A small class to represent a sound. Has useful API to handle the sound.

Sound

Constructors

  • Parameters

    • Optional pSoundPath: string

      The path of the sound file

    • Optional pVolume: number

      The volume of the sound

    • Optional pStartTime: number

      The start time of this sound (to play a clipped version)

    • Optional pEndTime: number

      The end time of this sound (to play a clipped version)

    • Optional pSave: boolean

      Whether to save this sound, or recycle it when it's completed

    • Optional pPlayUnfocused: boolean

      If this sound is set to playUnfocused then it will not be played automatically when the game screen is not focused

    • Optional pPlaybackRate: number

      The rate at which the sound is played, Higher numbers for faster playback (MAX 10)

    • Optional pLoop: boolean

      Whether this sound should loop or not

    Returns Sound

    • A sound object that has vast API on controlling it

Properties

soundPath: null | string = null

The path of the sound.

startTime: null | number = null

The start time of this sound.

endTime: null | number = null

The end time of ththise sound.

save: null | boolean = null

Whether to save this sound or not.

duration: null | number = null

The duration of this sound.

source: any = null

The source of this sound.

gainNode: any = null

The gain node of this sound.

loaded: boolean = false

Whether this sound is loaded.

playAfterLoad: null | boolean = null

If this sound is to play after it is loaded.

muted: boolean = false

If this sound is muted.

state: null | string = null

The state of this sound.

startedTimeStamp: null | number = null

The start timestamp of this sound.

pausedTimeStamp: number = 0

The timestamp of this sound when it was paused so it can be resumed at the same timestamp.

playUnfocused: null | boolean = null

If this sound plays without window focus.

fader: any = {}

Object holding the fading information for this sound.

events: any = {}

Events tied to this sound. start | end | pause | resume

_filters: any[] = []

Array of filters that are currently applied on this sound.

stopSignal: boolean = false

Whether this sound was sent a stop signal.

_loop: boolean = false

If this sound is to loop.

_playbackRate: number = 1

The playback rate of this sound.

_volume: number = 100

The volume of this sound.

_info: {
    soundPath: null | string;
    duration: null | number;
} = ...

Info tied to this sound.

Type declaration

  • soundPath: null | string
  • duration: null | number

Accessors

  • get volume(): number
  • Gets the current volume of this sound

    Returns number

    The current volume of this sound

  • set volume(pNewVolume): void
  • Sets the volume of this sound

    Parameters

    • pNewVolume: number

      The volume to set

    Returns void

  • get loop(): boolean
  • Get the loop status of this sound

    Returns boolean

    Whether this sound is set to loop or not

  • set loop(pLoopValue): void
  • Set the loop status of this sound

    Parameters

    • pLoopValue: boolean

      The value which to set the loop status to. Truthy values resolve to true, and falsely values resovle to false

    Returns void

  • get playbackRate(): number
  • Get the playback status of this sound

    Returns number

    The playback rate of this sound

  • set playbackRate(pNewPlaybackRate): void
  • Set the playback status of this sound

    Parameters

    • pNewPlaybackRate: number

      The value which to set the playback status to. Clamped to 10

    Returns void

  • get info(): {
        soundPath: null | string;
        duration: null | number;
    }
  • Get the info object of this sound

    Returns {
        soundPath: null | string;
        duration: null | number;
    }

    The info object of this sound

    • soundPath: null | string
    • duration: null | number
  • set info(pNewInfo): void
  • 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

    Parameters

    • pNewInfo: any

      The new value

    Returns void

Methods

  • Attaches a callback to the specified event.

    Parameters

    • pEvent: string

      The event to attach the callback to

    • pCallback: (() => void)

      The function to be called when the event is triggered

        • (): void
        • Returns void

    Returns Sound

    The Sound instance

  • Toggleable mute feature for this sound. Flips between muted and unmuted

    Returns Sound

    This sound instance

  • Toggleable loop feature for this sound. Flips between loop and unlooped

    Returns Sound

    This sound instance

  • Parameters

    • Optional pSoundPath: string

      The path of the sound file

    • pVolume: number = 100

      The volume of the sound

    • pStartTime: number = 0

      The start time of this sound (to play a clipped version)

    • pEndTime: number = 0

      The end time of this sound (to play a clipped version)

    • pSave: boolean = false

      Whether to save this sound, or recycle it when it's completed

    • pPlayUnfocused: boolean = false

      If this sound is set to true then it will not be paused automatically when the game screen is not focused

    • pPlaybackRate: number = 1

      The rate at which the sound is played, Higher numbers for faster playback (MAX 10)

    • pLoop: boolean = false

      Whether this sound should loop or not

    Returns Sound

    • A sound object that has vast API on controlling it
  • Loads this sound and stores its data so future sounds can use the same buffer

    Returns void

  • Pauses this sound

    Returns Sound

    This sound instance

  • Resumes playing this sound

    Returns Sound

    This sound instance

  • Stops this sound from playing. If any filters are utilized on this sound they are removed.

    Parameters

    • Optional pState: string

      The current state of this sound. It's used to figure out if a callback should be dispatched

    Returns Sound

    This sound instance

  • Plays this sound

    Parameters

    • Optional pResume: boolean

      If this is being played from a paused state

    Returns Sound

    This sound instance

  • Restarts this sound

    Returns Sound

    This sound instance

  • Get whether this sound will play when the window is unfocused

    Returns boolean

    Whether or not this sound will play when the window is unfocused

  • 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.

    Returns void

  • Adds a filter to be applied to this sound. *

    Parameters

    • pFilter: any

      The filter to add.

    Returns void

    Todo

    Allow more than one filter. Loop through the filters array and connect all filters after disconnecting.

  • Removes a filter from being applied to this sound.

    Parameters

    • pFilter: any

      The filter to remove.

    Returns void

  • Removes all filters from this sound.

    Returns void

  • Resets this sound to default state

    Returns void

  • Get the current timestamp of the sound playing

    Returns number

    The current timestamp into the sound

  • Fades this sound to the specified volume in the specified duration via the specified ease

    Parameters

    • Optional pVolume: number = 100

      The volume to fade to

    • Optional pDuration: number = 5000

      The duration of the fade in ms

    • Optional pEase: string = 'easeOutCubic'

      Easing function

    • Optional pCallback: (() => void)

      Callback to be called when the fade is over

        • (): void
        • Returns void

    Returns Sound

    This sound instance

  • Start the queued fade

    Returns void