Skip to main content

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​

ParameterTypeDefaultDescription
optionsSoundResetOptions{}What to keep. With {} everything is reset.

What each part of a reset does, and the option that skips it:

StepSkipped by
Stop all sounds and streamsAlways runs
Set the global volume to 1 and unmute a global mutekeepVolumes: true
Set the global pan to 0keepPanning: true
Take the master spatial panner out of the chainkeepSpatial: true
Run resetSound on every buffered sound, with the same optionsAlways runs
Remove every buffered sound from the hubRuns 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​

Try it

Change a sound, then reset it

Idle
0.70
0.00
LR
1.00×

Move 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 reset event (SoundEventsEnum.RESET) is dispatched once for every sound, from resetSound, and once more for the hub as a whole. The hub event has no soundId and carries the options in resetOptions.
  • The global volume goes to 1 and the global pan to 0: the config defaults are for each sound, not for the master.
  • Streams are stopped but not otherwise reset. resetSound skips them.
  • With unloadSounds: true the 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 no unloaded events are dispatched. To shut the hub down for good, use destroy.
  • See resetSound for what happens to each sound, including a volume reset that often leaves the level where it was.

See also​