@relu-interactives/spatial-ecs
@relu-interactives/spatial-ecs / index / AudioSystem
Class: AudioSystem ​
Defined in: systems/AudioSystem.ts:102
Reconciles AudioComponent state with the underlying THREE.js audio objects each frame.
Playback — drives play(), pause(), and stop() on the THREE.js audio node based on the isPlaying / isPaused flags set by AudioComponent.play(), .pause(), and .stop().
Option sync — detects changes to loop, pitch, volume, refDistance, distanceModel, and rolloffFactor and applies them live. Changes take effect on the next frame, so scripts and inspector edits during runtime are reflected without reloading the scene.
Mixing — every sound plays through a bus (sfx, voice, music) with its own volume, and music dips while a voice plays.
Sound banks — loadSoundBank and playSlot play named sounds from a .soundbank.json asset, as a random take.
Pausing — world.pause() holds what is playing and world.resume() continues it from the same point, leaving anything already stopped alone. Sounds started during the pause play normally, and the ui bus is never held, so a menu keeps its clicks. This system keeps ticking for them.
Only active in preview mode (isEditor: true makes every update a no-op so the editor is unaffected).
Implements ​
Constructors ​
Constructor ​
new AudioSystem(__namedParameters?): AudioSystem;Defined in: systems/AudioSystem.ts:125
Parameters ​
| Parameter | Type |
|---|---|
__namedParameters | { isEditor?: boolean; } |
__namedParameters.isEditor? | boolean |
Returns ​
AudioSystem
Properties ​
| Property | Modifier | Type | Default value | Description | Defined in |
|---|---|---|---|---|---|
runsWhilePaused | readonly | true | true | Keep ticking while the world is paused. Leave it unset for anything that moves the game on: such a system stops at world.pause() and picks up where it was at world.resume(). | systems/AudioSystem.ts:103 |
Methods ​
attachWorld() ​
attachWorld(world): void;Defined in: systems/AudioSystem.ts:130
Scripts can load a bank in init, before this system's first update.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
Returns ​
void
getMixer() ​
getMixer(): AudioMixer | null;Defined in: systems/AudioSystem.ts:135
The mixer, made with the listener on first use.
Returns ​
AudioMixer | null
setMasterVolume() ​
setMasterVolume(volume): void;Defined in: systems/AudioSystem.ts:184
The player's overall volume, 0..1, saved in settings.
Parameters ​
| Parameter | Type |
|---|---|
volume | number |
Returns ​
void
setMuted() ​
setMuted(muted): void;Defined in: systems/AudioSystem.ts:190
Mute or unmute everything, saved in settings.
Parameters ​
| Parameter | Type |
|---|---|
muted | boolean |
Returns ​
void
setBusVolume() ​
setBusVolume(bus, volume): void;Defined in: systems/AudioSystem.ts:196
Set a bus's volume (0 silent, 1 as mixed).
Parameters ​
| Parameter | Type |
|---|---|
bus | AudioBus |
volume | number |
Returns ​
void
getBusVolume() ​
getBusVolume(bus): number;Defined in: systems/AudioSystem.ts:200
Parameters ​
| Parameter | Type |
|---|---|
bus | AudioBus |
Returns ​
number
loadSoundBank() ​
loadSoundBank(source): Promise<void>;Defined in: systems/AudioSystem.ts:209
Fetch a .soundbank.json and decode its recordings. Its slots add to any loaded before, and a slot id used twice takes the later one.
Parameters ​
| Parameter | Type | Description |
|---|---|---|
source | | string | { path: string; } | an asset path, or a script's AssetInput field |
Returns ​
Promise<void>
releaseSoundBank() ​
releaseSoundBank(source): boolean;Defined in: systems/AudioSystem.ts:235
Let go of a loaded bank: its slots stop playing and its decoded recordings are freed, keeping those another loaded bank still uses. A sound already playing finishes. Returns whether that bank was loaded.
Parameters ​
| Parameter | Type |
|---|---|
source | | string | { path: string; } |
Returns ​
boolean
playSlot() ​
playSlot(id, options?): boolean;Defined in: systems/AudioSystem.ts:254
Play a named sound from a loaded bank. Returns whether it sounded: a slot's chance, cooldown and priority can each keep it quiet, and that's normal.
Parameters ​
| Parameter | Type |
|---|---|
id | string |
options | PlaySlotOptions |
Returns ​
boolean
onWorldPause() ​
onWorldPause(world, options): void;Defined in: systems/AudioSystem.ts:329
Hold what is playing. A sound that is wanted but not sounding yet counts: one still loading would otherwise start up behind the menu.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
options | PauseOptions |
Returns ​
void
Implementation of ​
onWorldResume() ​
onWorldResume(world): void;Defined in: systems/AudioSystem.ts:355
Continue what the pause held, and only that.
Parameters ​
| Parameter | Type |
|---|---|
world | World |
Returns ​
void
Implementation of ​
update() ​
update(world, _deltaTime): void;Defined in: systems/AudioSystem.ts:406
Parameters ​
| Parameter | Type |
|---|---|
world | World |
_deltaTime | number |
Returns ​
void
Implementation of ​
dispose() ​
dispose(_world): void;Defined in: systems/AudioSystem.ts:542
Parameters ​
| Parameter | Type |
|---|---|
_world | World |
Returns ​
void

