Skip to main content

SoundResetOptions

The options for reset and resetSound. By default a reset puts everything back. Each keep option leaves one part alone.

export interface SoundResetOptions {
keepVolumes?: boolean; // Keep current volume settings
keepPanning?: boolean; // Keep current panning settings
keepSpatial?: boolean; // Keep spatial audio settings
keepPlaybackRate?: boolean // Keep playback rate
unloadSounds?: boolean; // Unload all sounds
}
FieldTypeDefaultWith reset()With resetSound()
keepVolumesbooleanfalseKeeps the global volume and a global mute.Keeps the sound's volume.
keepPanningbooleanfalseKeeps the global pan.Keeps the sound's stereo panner.
keepSpatialbooleanfalseKeeps the master spatial panner.Keeps a 3D sound's panner and pan type.
keepPlaybackRatebooleanfalsePassed on to every sound.Keeps the sound's playback rate instead of setting it to 1.
unloadSoundsbooleanfalseRemoves every buffered sound after resetting it.Ignored.

SoundResetOptions is exported from soundhub as a type.

Example​

import { SoundHub } from 'soundhub';

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

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

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

// Clear the whole hub and drop the loaded sounds
soundHub.reset({ unloadSounds: true });

Try it​

Change the volume, pan and playback rate, then reset with different options to see which settings survive and which are restored.

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 always stops the sound. None of the options keep it playing.
  • keepVolumes: false on a sound sets it back to the volume stored in its play options. play() with a volume and setSoundVolume both write that value, so the level often stays the same; a mute or a running fade is what gets undone.
  • keepPanning: false removes the stereo panner, but the pan stored in the play options stays, so the next play() pans the sound again.
  • keepSpatial: true keeps a 3D sound's panner, but its position still goes back to 0, 0, 0.
  • The options arrive in the resetOptions field of the reset event.

See also​