Audio · class
SpatialSource
Explained in Your first game.
class SpatialSourceimport { SpatialSource } from '@driftengine/audio';Constructor
new
constructor(listener: AudioListenerGraph, buffer: AudioBuffer, options?: SpatialOptions)| Parameter | Type | Description |
|---|---|---|
listener | AudioListenerGraph | |
buffer | AudioBuffer | |
options? | SpatialOptions |
Accessors
| Name | Type | Description |
|---|---|---|
detuneCentsget | number | The pitch shift currently applied, in cents. Zero with doppler off. |
occlusionget | number | How blocked this source is right now, after smoothing. |
Methods
attachZone
attachZone(zone: ReverbZone): voidCarry the tail of a space this source is in, rather than one the listener is in.
| Parameter | Type | Description |
|---|---|---|
zone | ReverbZone |
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): numberWhat this source is currently sending into that zone's return.
| Parameter | Type | Description |
|---|---|---|
zone | ReverbZone |
place
place(x: number, y: number, z: number, dtSec: number): voidWhere this source is, this frame.
| Parameter | Type | Description |
|---|---|---|
x | number | |
y | number | |
z | number | |
dtSec | number |
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): voidMove without having travelled: a respawn, a cut, an object put back at the start.
| Parameter | Type | Description |
|---|---|---|
x | number | |
y | number | |
z | number |
setOcclusion
setOcclusion(amount: number): voidSay how blocked this source is, 0 clear to 1 solid.
| Parameter | Type | Description |
|---|---|---|
amount | number |
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| Parameter | Type | Description |
|---|---|---|
when? | number |
stop
stop(): voiddispose
dispose(): void