reset
Stop everything and put the hub back to a clean state. Reach for it when a level restarts or a user presses a "reset audio" button. Pass SoundResetOptions to keep some settings.
reset(options?: SoundResetOptions): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
options | SoundResetOptions | {} | What to keep. With {} everything is reset. |
What each part of a reset does, and the option that skips it:
| Step | Skipped by |
|---|---|
| Stop all sounds and streams | Always runs |
| Set the global volume to 1 and unmute a global mute | keepVolumes: true |
Set the global pan to 0 | keepPanning: true |
| Take the master spatial panner out of the chain | keepSpatial: true |
Run resetSound on every buffered sound, with the same options | Always runs |
| Remove every buffered sound from the hub | Runs only with unloadSounds: true |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true, volume: 0.3, pan: -0.8, playbackRate: 1.5 });
soundHub.setGlobalVolume(0.5);
// Level restart: stop everything, but keep the volumes the player chose
soundHub.reset({ keepVolumes: true });
// Leaving the game: also drop every loaded sound
soundHub.reset({ unloadSounds: true });
Try it
Change a sound, then reset it
IdleMove the sliders while it plays, then reset. To keep some settings, pass options such as resetSound(id, { keepVolumes: true }).
Code
Your clicks show up here as soundhub calls
Good to know
- A
resetevent (SoundEventsEnum.RESET) is dispatched once for every sound, fromresetSound, and once more for the hub as a whole. The hub event has nosoundIdand carries the options inresetOptions. - The global volume goes to
1and the global pan to0: the config defaults are for each sound, not for the master. - Streams are stopped but not otherwise reset.
resetSoundskips them. - With
unloadSounds: truethe buffered sounds are removed and their nodes disconnected, but the master chain stays, so the hub is usable and you can load sounds again. Streams are not unloaded and nounloadedevents are dispatched. To shut the hub down for good, usedestroy. - See
resetSoundfor what happens to each sound, including a volume reset that often leaves the level where it was.
See also
resetSound: reset one sound instead of the whole hub.SoundResetOptions: every option and what it keeps.stopAllSounds: only stop playback, change nothing else.destroy: tear the hub down and close the audio context.