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
}
| Field | Type | Default | With reset() | With resetSound() |
|---|---|---|---|---|
keepVolumes | boolean | false | Keeps the global volume and a global mute. | Keeps the sound's volume. |
keepPanning | boolean | false | Keeps the global pan. | Keeps the sound's stereo panner. |
keepSpatial | boolean | false | Keeps the master spatial panner. | Keeps a 3D sound's panner and pan type. |
keepPlaybackRate | boolean | false | Passed on to every sound. | Keeps the sound's playback rate instead of setting it to 1. |
unloadSounds | boolean | false | Removes 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.
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 reset always stops the sound. None of the options keep it playing.
keepVolumes: falseon a sound sets it back to the volume stored in its play options.play()with avolumeandsetSoundVolumeboth write that value, so the level often stays the same; a mute or a running fade is what gets undone.keepPanning: falseremoves the stereo panner, but thepanstored in the play options stays, so the nextplay()pans the sound again.keepSpatial: truekeeps a 3D sound's panner, but its position still goes back to0, 0, 0.- The options arrive in the
resetOptionsfield of theresetevent.
See also
reset: reset the whole hub.resetSound: reset one sound.destroy: tear the hub down completely.