Sound

Sound

A representation of a sound in the engine.

Constructor

new Sound()

Members

(readonly) autoPlay :boolean

If true, it will start playing when the SoundSystem runs play().

id :string

name :string

publicAsset

Gets the public api Sound object for this internal api Sound object.

(readonly) spatialize :boolean

Methods

(static) forPublicAsset(publicAsset) → {Sound}

Gets the internal api Asset object for a specified public api Sound object.

Parameters:
Name Type Description
publicAsset Asset

The public api Sound object.

connectTo(nodes)

Connect output of sound to audionodes

Parameters:
Name Type Description
nodes Array.<AudioNode> | AudioNode

disconnectFrom(nodes)

Disconnect output of sound from audionodes

Parameters:
Name Type Description
nodes Array.<AudioNode> | AudioNode

fade(volume, time)

Linearly changes the volume from current over a period of time to a new level

Parameters:
Name Type Description
volume number

Final volume level

time number

Length of the fade, in seconds

fadeIn(time)

Ramps up the volume over a period of time

Parameters:
Name Type Description
time number

Length of the fade in, in seconds

fadeOut(time)

Ramps down the volume over a period of time

Parameters:
Name Type Description
time number

Length of the fade out, in seconds

isPaused() → {boolean}

Gets the pause status of the sound

isPlaying() → {boolean}

Gets the playing status of the sound

pause()

Pauses the sound if it's playing

play(when) → {Promise}

Plays the sound if it's not playing

Parameters:
Name Type Description
when number

Time in seconds according to AudioContext.currentTime when sound should start to play.

process()

Processes sound playback state in case autoplay is disabled.
Called on each render frame.

setAudioBuffer(buffer)

Sets the audio buffer which will be the sound source

Parameters:
Name Type Description
buffer AudioBuffer

setAudioStream(stream)

Sets the audio stream which will be the sound source

Parameters:
Name Type Description
stream mediaStream

stop(when)

Stops the sound if it's playing

Parameters:
Name Type Description
when number

Time in seconds according to AudioContext.currentTime when sound should stop.

update(configopt)

Updates the sound according to config

Parameters:
Name Type Attributes Description
config Object <optional>
Properties
Name Type Attributes Description
loop boolean <optional>
volume number <optional>
name number <optional>

The sound name

start number <optional>

Start offset in seconds.
Will be clamped to be in actual soundclip duration

duration number <optional>

Duration of the sound.
Will be clamped to be in actual soundclip duration

timeScale number <optional>

Playback rate of the sound