Audio · class

SpatialSource

Explained in Your first game.

class SpatialSource
import { SpatialSource } from '@driftengine/audio';

Constructor

new

constructor(listener: AudioListenerGraph, buffer: AudioBuffer, options?: SpatialOptions)
ParameterTypeDescription
listenerAudioListenerGraph
bufferAudioBuffer
options?SpatialOptions

Accessors

NameTypeDescription
detuneCentsgetnumberThe pitch shift currently applied, in cents. Zero with doppler off.
occlusiongetnumberHow blocked this source is right now, after smoothing.

Methods

attachZone

attachZone(zone: ReverbZone): void

Carry the tail of a space this source is in, rather than one the listener is in.

ParameterTypeDescription
zoneReverbZone
More

The case zones.ts names as the one its own model cannot serve: a sound inside a cave heard from outside carries whatever space the listener stands in, which is wrong exactly when somebody is listening into a space. A source-attached zone is a second routing into a return that already carries a convolver, so it costs one GainNode rather than one convolution.

MAX_OPEN_ZONES still binds, and it binds per source. The budget is not about the sends, which are nearly free; it is about how many convolvers are audible at once, and a source driving four returns makes four of them audible. Two is the space being left and the space being entered, here as for the listener.

The send is taken from the occluded, unpanned signal: a reverb send comes off the channel on any console, and the return is itself a stereo space, so a point-panned tail would arrive from the source's direction rather than from the room. Occlusion is upstream because a sound behind a wall has a muffled tail too.

zoneSend

zoneSend(zone: ReverbZone): number

What this source is currently sending into that zone's return.

ParameterTypeDescription
zoneReverbZone

place

place(x: number, y: number, z: number, dtSec: number): void

Where this source is, this frame.

ParameterTypeDescription
xnumber
ynumber
znumber
dtSecnumber
More

Velocity is derived here exactly as the listener derives its own, and for the same reason. A source that teleports should be moved with warp.

warp

warp(x: number, y: number, z: number): void

Move without having travelled: a respawn, a cut, an object put back at the start.

ParameterTypeDescription
xnumber
ynumber
znumber

setOcclusion

setOcclusion(amount: number): void

Say how blocked this source is, 0 clear to 1 solid.

ParameterTypeDescription
amountnumber
More

For a consumer that already knows — a door with a state, a sound that is definitionally indoors — and for anyone who would rather not hand the listener a probe. Overrides whatever the probe last answered until the probe answers again.

start

start(when?: number): void
ParameterTypeDescription
when?number

stop

stop(): void

dispose

dispose(): void