Class PositionalSound

A class for sounds that have a position in space. Uses PannerNode for spatial audio and distance-based volume.

PositionalSound

Hierarchy (view full)

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 true then it will not be paused 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

    • Optional pRefDistance: number = 1

      The reference distance for the sound

    • Optional pRolloffFactor: number = 1

      The rolloff factor for the sound

    • Optional pMaxDistance: number = 10000

      The maximum distance for the sound

    Returns PositionalSound

    • A positional sound object

Properties

panner: PannerNode
_x: number = 0
_y: number = 0
_z: number = 0
_refDistance: number = 1
_rolloffFactor: number = 1
_maxDistance: number = 10000
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 refDistance(): number
  • The reference distance for the sound. Within this distance, the sound is at its maximum volume.

    Returns number

  • set refDistance(val): void
  • Parameters

    • val: number

    Returns void

  • get rolloffFactor(): number
  • The rolloff factor for the sound. Higher values cause the volume to drop off more rapidly with distance.

    Returns number

  • set rolloffFactor(val): void
  • Parameters

    • val: number

    Returns void

  • get maxDistance(): number
  • The maximum distance for the sound. Beyond this distance, the sound will be silent.

    Returns number

  • set maxDistance(val): void
  • Parameters

    • val: number

    Returns void

  • 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

  • Sets the position of the sound in 3D space.

    Parameters

    • x: number

      The x position

    • y: number

      The y position

    • Optional z: number = 0

      The z position

    Returns this

    This sound instance

  • Resets this sound to default state or builds it with new parameters.

    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

    • Optional pRefDistance: number = 1

      The reference distance for the sound

    • Optional pRolloffFactor: number = 1

      The rolloff factor for the sound

    • Optional pMaxDistance: number = 10000

      The maximum distance for the sound

    Returns this

    This sound instance

  • Stops the sound and disconnects the panner.

    Parameters

    • Optional pState: string

      Current state of the sound

    Returns this

    This sound instance

  • Updates the PannerNode with the current position.

    Returns void

  • Overrides base connection to include the PannerNode. Chain: source -> gainNode -> panner -> Resonance.gainNode

    Returns void

  • 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

  • Loads this sound and stores its data so future sounds can use the same buffer

    Returns void

  • Plays this sound

    Parameters

    • Optional pResume: boolean

      If this is being played from a paused state

    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

  • 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

  • Unloads this sound's buffer data and stops it.

    Returns void