Skip to main content

Class: SpatialAudio

Defined in: src/audio/SpatialAudio.ts:118

A sound positioned in 3D that can follow a mobject and pan to the camera.

Constructors​

Constructor​

new SpatialAudio(options): SpatialAudio

Defined in: src/audio/SpatialAudio.ts:125

Parameters​

options​

SpatialAudioOptions = {}

Returns​

SpatialAudio

Accessors​

connected​

Get Signature​

get connected(): boolean

Defined in: src/audio/SpatialAudio.ts:385

Whether an audio graph exists (a panner was created).

Returns​

boolean


panner​

Get Signature​

get panner(): SpatialPanner

Defined in: src/audio/SpatialAudio.ts:390

The panner node, or null when Web Audio is unavailable.

Returns​

SpatialPanner

Methods​

attachTo()​

attachTo(mobject): this

Defined in: src/audio/SpatialAudio.ts:226

Follow a mobject: each update moves the sound to its center. Snaps to the current center immediately.

Parameters​

mobject​

Mobject

Returns​

this

this for chaining


createUpdater()​

createUpdater(): UpdaterFunction

Defined in: src/audio/SpatialAudio.ts:255

Build an updater that calls update each frame. Add it with mobject.addUpdater(audio.createUpdater()).

Returns​

UpdaterFunction


detach()​

detach(): this

Defined in: src/audio/SpatialAudio.ts:236

Stop following a mobject. The sound stays at its last position.

Returns​

this

this for chaining


dispose()​

dispose(): void

Defined in: src/audio/SpatialAudio.ts:395

Release the panner connection. Does not close an injected context.

Returns​

void


getPosition()​

getPosition(): Vector3Tuple

Defined in: src/audio/SpatialAudio.ts:217

The current sound position in scene coordinates.

Returns​

Vector3Tuple


pause()​

pause(): this

Defined in: src/audio/SpatialAudio.ts:329

Pause playback. No-op with no source.

Returns​

this


play()​

play(): this

Defined in: src/audio/SpatialAudio.ts:323

Start (or resume) playback. No-op with no source.

Returns​

this


setDistanceModel()​

setDistanceModel(model): this

Defined in: src/audio/SpatialAudio.ts:375

Set the distance-attenuation algorithm.

Parameters​

model​

DistanceModelType

Returns​

this

this for chaining


setListenerFromCamera()​

setListenerFromCamera(camera): this

Defined in: src/audio/SpatialAudio.ts:308

Place the listener from a camera: position from the camera, forward from the look-at target (or the default forward), up from the camera up vector.

Parameters​

camera​

ListenerCameraView

Returns​

this

this for chaining


setListenerOrientation()​

setListenerOrientation(forward, up): this

Defined in: src/audio/SpatialAudio.ts:278

Set the listener forward and up orientation (normalized internally).

Parameters​

forward​

Vector3Tuple

up​

Vector3Tuple = DEFAULT_UP

Returns​

this

this for chaining


setListenerPosition()​

setListenerPosition(position): this

Defined in: src/audio/SpatialAudio.ts:267

Set the listener position in scene coordinates.

Parameters​

position​

Vector3Tuple

Returns​

this

this for chaining


setMaxDistance()​

setMaxDistance(value): this

Defined in: src/audio/SpatialAudio.ts:363

Set the maximum attenuation distance.

Parameters​

value​

number

Returns​

this

this for chaining


setPanningModel()​

setPanningModel(model): this

Defined in: src/audio/SpatialAudio.ts:369

Set the spatialization algorithm.

Parameters​

model​

PanningModelType

Returns​

this

this for chaining


setPosition()​

setPosition(position): this

Defined in: src/audio/SpatialAudio.ts:208

Set the sound position in scene coordinates. The position is tracked even when no audio graph exists.

Parameters​

position​

Vector3Tuple

Returns​

this

this for chaining


setRefDistance()​

setRefDistance(value): this

Defined in: src/audio/SpatialAudio.ts:351

Set the reference distance for attenuation.

Parameters​

value​

number

Returns​

this

this for chaining


setRolloffFactor()​

setRolloffFactor(value): this

Defined in: src/audio/SpatialAudio.ts:357

Set the rolloff factor for attenuation.

Parameters​

value​

number

Returns​

this

this for chaining


setVolume()​

setVolume(value): this

Defined in: src/audio/SpatialAudio.ts:341

Set the source volume [0, 1]. No-op with no source.

Parameters​

value​

number

Returns​

this


stop()​

stop(): this

Defined in: src/audio/SpatialAudio.ts:335

Stop playback and reset to the start. No-op with no source.

Returns​

this


update()​

update(_dt): void

Defined in: src/audio/SpatialAudio.ts:245

Advance the driver by dt seconds. When attached, moves the sound to the mobject center. The dt argument keeps the updater signature uniform.

Parameters​

_dt​

number

Returns​

void


fromBuffer()​

static fromBuffer(buffer, options): SpatialAudio

Defined in: src/audio/SpatialAudio.ts:179

Create a positional sound from a decoded AudioBuffer. No-op (disconnected) when Web Audio is unavailable.

Parameters​

buffer​

AudioBuffer

options​

SpatialAudioOptions & object = {}

Returns​

SpatialAudio


fromMediaElement()​

static fromMediaElement(element, options): SpatialAudio

Defined in: src/audio/SpatialAudio.ts:155

Create a positional sound from an <audio> / <video> element. No-op (disconnected) when Web Audio is unavailable.

Parameters​

element​

HTMLMediaElement

options​

SpatialAudioOptions = {}

Returns​

SpatialAudio