Sound

Audio

Description

class Sound

Constructor

new Sound(name, urlOrArrayBuffer, scene, readyToPlayCallback, options)

Create a sound and attach it to a scene

Parameters

Name Type Description
name string Name of your sound
urlOrArrayBuffer any Url to the sound to load async or ArrayBuffer
scene Scene
optional readyToPlayCallback Nullable<() => void> Provide a callback function if you'd like to load your code once the sound is ready to be played

Members

name : string

autoplay : boolean

loop : boolean

useCustomAttenuation : boolean

soundTrackId : number

spatialSound : boolean

refDistance : number

rolloffFactor : number

maxDistance : number

distanceModel : string

onended : () => any

isPlaying : boolean

isPaused : boolean

null : ()

Methods

dispose() void

isReady() boolean

setAudioBuffer(audioBuffer) void

Parameters

Name Type Description
audioBuffer AudioBuffer

updateOptions(options) void

Parameters

Name Type Description
options any

switchPanningModelToHRTF() void

switchPanningModelToEqualPower() void

connectToSoundTrackAudioNode(soundTrackAudioNode) void

Parameters

Name Type Description
soundTrackAudioNode AudioNode

setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) void

Transform this sound into a directional source

Parameters

Name Type Description
coneInnerAngle number Size of the inner cone in degree
coneOuterAngle number Size of the outer cone in degree
coneOuterGain number Volume of the sound outside the outer cone (between 0.0 and 1.0)

setPosition(newPosition) void

Parameters

Name Type Description
newPosition Vector3

setLocalDirectionToMesh(newLocalDirection) void

Parameters

Name Type Description
newLocalDirection Vector3

updateDistanceFromListener() void

setAttenuationFunction(callback) void

Parameters

Name Type Description
callback currentVolume number
currentDistance number
maxDistance number
refDistance number
rolloffFactor number

play(time, offset) void

Play the sound

Parameters

Name Type Description
optional time number (optional) Start the sound after X seconds. Start immediately (0) by default.
optional offset number (optional) Start the sound setting it at a specific time

stop(time) void

Stop the sound

Parameters

Name Type Description
optional time number (optional) Stop the sound after X seconds. Stop immediately (0) by default.

pause() void

setVolume(newVolume, time) void

Parameters

Name Type Description
newVolume number
optional time number

setPlaybackRate(newPlaybackRate) void

Parameters

Name Type Description
newPlaybackRate number

getVolume() number

attachToMesh(meshToConnectTo) void

Parameters

Name Type Description
meshToConnectTo AbstractMesh

detachFromMesh() void

clone() Nullable<Sound>

getAudioBuffer() AudioBuffer

serialize() any

static Parse(parsedSound, scene, rootUrl, sourceSound) Sound

Parameters

Name Type Description
parsedSound any
scene Scene
rootUrl string