Sound

Defines a sound that can be played in the application. The sound can either be an ambient track or a simple sound played in reaction to a user action.

see

http://doc.babylonjs.com/how_to/playing_sounds_and_music

Hierarchy

  • Sound

Index

Constructors

constructor

Find examples in Playground
  • new Sound(name: string, urlOrArrayBuffer: any, scene: Scene, readyToPlayCallback?: Nullable<function>, options?: any): Sound
  • Create a sound and attach it to a scene

    Parameters

    • name: string

      Name of your sound

    • urlOrArrayBuffer: any

      Url to the sound to load async or ArrayBuffer, it also works with MediaStreams

    • scene: Scene
    • Optional readyToPlayCallback: Nullable<function>

      Provide a callback function if you'd like to load your code once the sound is ready to be played

    • Optional options: any

      Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming

    Returns Sound

Properties

autoplay

Find examples in Playground
autoplay: boolean

Does the sound autoplay once loaded.

directionalConeInnerAngle

Find examples in Playground
directionalConeInnerAngle: number

Gets or sets the inner angle for the directional cone.

directionalConeOuterAngle

Find examples in Playground
directionalConeOuterAngle: number

Gets or sets the outer angle for the directional cone.

distanceModel

Find examples in Playground
distanceModel: string

Define the distance attenuation model the sound will follow.

see

http://doc.babylonjs.com/how_to/playing_sounds_and_music#creating-a-spatial-3d-sound

isPaused

Find examples in Playground
isPaused: boolean

Is this sound currently paused.

isPlaying

Find examples in Playground
isPlaying: boolean

Is this sound currently played.

loop

Find examples in Playground
loop: boolean

Does the sound loop after it finishes playing once.

maxDistance

Find examples in Playground
maxDistance: number

Define the max distance the sound should be heard (intensity just became 0 at this point).

see

http://doc.babylonjs.com/how_to/playing_sounds_and_music#creating-a-spatial-3d-sound

name

Find examples in Playground
name: string

The name of the sound in the scene.

onEndedObservable

Find examples in Playground
onEndedObservable: Observable<Sound>

Observable event when the current playing sound finishes.

refDistance

Find examples in Playground
refDistance: number

Define the reference distance the sound should be heard perfectly.

see

http://doc.babylonjs.com/how_to/playing_sounds_and_music#creating-a-spatial-3d-sound

rolloffFactor

Find examples in Playground
rolloffFactor: number

soundTrackId

Find examples in Playground
soundTrackId: number

The sound track id this sound belongs to.

spatialSound

Find examples in Playground
spatialSound: boolean

useCustomAttenuation

Find examples in Playground
useCustomAttenuation: boolean

Does the sound use a custom attenuation curve to simulate the falloff happening when the source gets further away from the camera.

see

http://doc.babylonjs.com/how_to/playing_sounds_and_music#creating-your-own-custom-attenuation-function

Methods

attachToMesh

Find examples in Playground

clone

Find examples in Playground
  • Clone the current sound in the scene.

    Returns Nullable<Sound>

    the new sound clone

connectToSoundTrackAudioNode

Find examples in Playground
  • connectToSoundTrackAudioNode(soundTrackAudioNode: AudioNode): void
  • Connect this sound to a sound track audio node like gain...

    Parameters

    • soundTrackAudioNode: AudioNode

      the sound track audio node to connect to

    Returns void

detachFromMesh

Find examples in Playground
  • detachFromMesh(): void

dispose

Find examples in Playground
  • dispose(): void
  • Release the sound and its associated resources

    Returns void

getAudioBuffer

Find examples in Playground
  • getAudioBuffer(): Nullable<AudioBuffer>
  • Gets the current underlying audio buffer containing the data

    Returns Nullable<AudioBuffer>

    the audio buffer

getVolume

Find examples in Playground
  • getVolume(): number
  • Gets the volume of the sound.

    Returns number

    the volume of the sound

isReady

Find examples in Playground
  • isReady(): boolean
  • Gets if the sounds is ready to be played or not.

    Returns boolean

    true if ready, otherwise false

pause

Find examples in Playground
  • pause(): void
  • Put the sound in pause

    Returns void

play

Find examples in Playground
  • play(time?: number, offset?: number): void
  • Play the sound

    Parameters

    • 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

    Returns void

serialize

Find examples in Playground
  • serialize(): any
  • Serializes the Sound in a JSON representation

    Returns any

    the JSON representation of the sound

setAttenuationFunction

Find examples in Playground
  • setAttenuationFunction(callback: function): void

setAudioBuffer

Find examples in Playground
  • setAudioBuffer(audioBuffer: AudioBuffer): void
  • Sets the data of the sound from an audiobuffer

    Parameters

    • audioBuffer: AudioBuffer

      The audioBuffer containing the data

    Returns void

setDirectionalCone

Find examples in Playground
  • setDirectionalCone(coneInnerAngle: number, coneOuterAngle: number, coneOuterGain: number): void
  • Transform this sound into a directional source

    Parameters

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

    Returns void

setLocalDirectionToMesh

Find examples in Playground
  • setLocalDirectionToMesh(newLocalDirection: Vector3): void
  • Sets the local direction of the emitter if spatial sound is enabled

    Parameters

    • newLocalDirection: Vector3

      Defines the new local direction

    Returns void

setPlaybackRate

Find examples in Playground
  • setPlaybackRate(newPlaybackRate: number): void
  • Set the sound play back rate

    Parameters

    • newPlaybackRate: number

      Define the playback rate the sound should be played at

    Returns void

setPosition

Find examples in Playground
  • setPosition(newPosition: Vector3): void
  • Sets the position of the emitter if spatial sound is enabled

    Parameters

    • newPosition: Vector3

      Defines the new posisiton

    Returns void

setVolume

Find examples in Playground
  • setVolume(newVolume: number, time?: number): void
  • Sets a dedicated volume for this sounds

    Parameters

    • newVolume: number

      Define the new volume of the sound

    • Optional time: number

      Define in how long the sound should be at this value

    Returns void

stop

Find examples in Playground
  • stop(time?: number): void
  • Stop the sound

    Parameters

    • Optional time: number

      (optional) Stop the sound after X seconds. Stop immediately (0) by default.

    Returns void

switchPanningModelToEqualPower

Find examples in Playground
  • switchPanningModelToEqualPower(): void

switchPanningModelToHRTF

Find examples in Playground
  • switchPanningModelToHRTF(): void

updateOptions

Find examples in Playground
  • updateOptions(options: any): void
  • Updates the current sounds options such as maxdistance, loop...

    Parameters

    • options: any

      A JSON object containing values named as the object properties

    Returns void

Static Parse

Find examples in Playground
  • Parse(parsedSound: any, scene: Scene, rootUrl: string, sourceSound?: Sound): Sound
  • Parse a JSON representation of a sound to innstantiate in a given scene

    Parameters

    • parsedSound: any

      Define the JSON representation of the sound (usually coming from the serialize method)

    • scene: Scene

      Define the scene the new parsed sound should be created in

    • rootUrl: string

      Define the rooturl of the load in case we need to fetch relative dependencies

    • Optional sourceSound: Sound

      Define a cound place holder if do not need to instantiate a new one

    Returns Sound

    the newly parsed sound

Generated using TypeDoc