Skip to main content

resetSound

Stop one sound and put its settings back. Use it when one sound has been bent out of shape (sped up, panned, moved in 3D) and you want it clean again without resetting the whole hub.

resetSound(id: string, options?: SoundResetOptions): void;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of a loaded buffered sound, or an instance id like 'click:2'.
optionsSoundResetOptions{}What to keep. With {} everything below is reset.

What happens to the sound:

StepSkipped by
Stop it if it is playing, and set its position back to 0Always runs
Take the stereo panner offkeepPanning: true
Take the 3D panner off and switch the sound back to stereokeepSpatial: true
Set the playback rate to 1keepPlaybackRate: true
Set the volume to the volume stored in its play optionskeepVolumes: true

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');

soundHub.play('rain', { loop: true, pan: -0.8, playbackRate: 1.5 });

// Put the rate and pan back, keep the volume
soundHub.resetSound('rain', { keepVolumes: true });

soundHub.getPlaybackRate('rain'); // 1
soundHub.isPlaying('rain'); // false, a reset always stops

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​

  • The volume goes back to playOptions.volume, falling back to the config's defaultVolume. Both play() with a volume and setSoundVolume write that value, so in practice the level usually stays the same. What the step does undo is a mute or a fade in progress.
  • Removing the stereo panner does not clear the pan stored in the play options, so the next play() pans the sound again. Play with pan: 0 or call resetPan if it should stay centred.
  • A sound positioned in 3D always gets its spatial position reset to 0, 0, 0, even with keepSpatial: true. The option only keeps the 3D panner in place.
  • The playback rate goes to 1, not to the config's defaultPlaybackRate, and that value is written to the play options.
  • Dispatches a reset event (SoundEventsEnum.RESET) with soundId and resetOptions. The steps above can dispatch their own events too, such as stopped and volume_changed.
  • Streams from loadStream and unknown ids are ignored. In debug mode a line is logged, nothing else happens.

See also​