Skip to main content

resetAllCounters

Clear the counters behind instance ids. When a sound plays with overlap, each instance gets an id like 'click:1', 'click:2', and so on. After this call the numbering starts from 1 again.

resetAllCounters(): void;

This method is on the SoundHub class but not on SoundHubInterface.

Parameters​

This method takes no parameters.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

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

soundHub.play('click', { overlap: true }); // instance 'click:1'
soundHub.play('click', { overlap: true }); // instance 'click:2'

// New level: start numbering from scratch
soundHub.resetAllCounters();

Good to know​

  • The counters only decide the number in an instance id. They do not limit how many instances can play; that is maxInstancesPerSound in SoundHubConfig or a group's maxInstances.
  • An id that is still in use is never handed out again. If 'click:1' is still registered after a reset, the next instance becomes 'click:2'.
  • No event is dispatched. In debug mode a line is logged.
  • reset with unloadSounds: true and destroy clear the counters as well.

See also​

  • play: the overlap option that creates instances.
  • getSoundIds: list every sound and instance id in the hub.
  • reset: put the whole hub back to its starting state.