Audio · interface
SpatialOptions
A sound placed in the world, heard from where the listener is standing.
Explained in Your first game.
interface SpatialOptionsimport type { SpatialOptions } from '@driftengine/audio';In depth
buffer source ─ detune ─→ occlusion lowpass ─→ occlusion gain ─→ panner (HRTF) ─→ a busA function rather than a method on the console, and that is a size decision rather than a
style one. A method would be a static reference from the mix to the panner, which no bundler
can shake out, so every consumer that imports the mix would carry the HRTF machinery whether or
not it ever places a sound. scripts/size-gate.test.mjs publishes what each package costs and
promises you pay only for what you import; this is what keeps that true.
This is the expensive path and it is meant to be. distanceGain and stereoPan still exist
and are still right for a fire, a shoreline or a storm column — diffuse things where what a
player reads is "how close" and "which way". Reach for a panner when the direction is
information: a footstep behind you, a voice through a doorway, something you are meant to turn
towards.
Properties
| Name | Type | Description |
|---|---|---|
busreadonlyoptional | MixBus | Where this lands in the mix. The console's effects bus when omitted. |
loopreadonlyoptional | boolean | |
dopplerreadonlyoptional | boolean | Shift the pitch with relative motion.MoreOff by default, deliberately. On a looping bed — a fire, a waterfall — a listener walking past makes the bed's pitch wander, which reads as the sound being broken rather than as motion. Turn it on for something that genuinely passes: a vehicle, a projectile, a siren. |
speedOfSoundreadonlyoptional | number | Metres per second. 343 in air; a game whose world is not in metres will want its own. |
maxDopplerCentsreadonlyoptional | number | How far the pitch is allowed to move, in cents. A whole tone each way by default. |
refDistancereadonlyoptional | number | Distance-model parameters, passed to the panner unchanged. |
maxDistancereadonlyoptional | number | |
rolloffreadonlyoptional | number | |
occlusionRatereadonlyoptional | number | How fast occlusion follows the world, per second.MoreSlow enough that a probe landing on a different answer does not click, fast enough that walking through a doorway is heard as walking through a doorway. |