PositionalAudio Class

Extends AudioEmitter
Module: Audio

PositionalAudio is used to play audio with positional audio effect using a WebAudio panner.

Using the positional audio object the sound is controlled by the camera that renders first in the scene.

Methods

getDistanceModel

() String

Get distance model in use by this audio emitter.

Returns:

String:

Distance model.

getMaxDistance

()

Get maximum distance for this audio emitter.

Returns:

Maximum distance.

getOutput

() Object

Get output audio node.

Returns:

Object:

Output audio node.

getRefDistance

() Number

Get reference distance.

Returns:

Number:

Reference distance.

getRolloffFactor

() Number

Get rolloff factor.

Returns:

Number:

Rolloff factor.

initialize

()

Initialize audio object, loads audio data decodes it and starts playback if autoplay is set to True.

setDistanceModel

(
  • model
)

Set distance model to be used.

Distance model defined how the emitter controls its volume from its position in the world, relative to the camera.

By default the mode used is "inverse", can be also set to:

  • "linear": A linear distance model calculating the gain induced by the distance according to
    • 1 - rolloffFactor * (distance - refDistance) / (maxDistance - refDistance)
  • "inverse": An inverse distance model calculating the gain induced by the distance according to:
    • refDistance / (refDistance + rolloffFactor * (distance - refDistance))
  • "exponential": An exponential distance model calculating the gain induced by the distance according to:
    • pow(distance / refDistance, -rolloffFactor).

Parameters:

  • model String

    Distance Model to be used.

setMaxDistance

(
  • value
)

Set maximum distance for this audio emitter.

Parameters:

  • value Number

    Maximum distance.

setRefDistance

(
  • value
)

Set reference distance.

Parameters:

  • value Number

    Reference distance.

setRolloffFactor

(
  • value
)

Set rolloff factor.

Parameters:

  • value Number

    Rolloff factor.

update

()

Update positional audio panner relative to the camera.

Properties

distanceModel

String

Distance model to be applied to the audio panner.

panner

PannerNode

panningModel

String

Model to be applied to the audio panner.

Attributes

scene

Scene

Runtime pointer to the scene to get the camera list.