Skip to main content

resetPan

Put a sound back in the centre of the stereo field. Called without an id, it centres the master pan instead.

resetPan(id?: string): void;

Parameters​

ParameterTypeDefaultDescription
idstringoptionalID of a loaded sound. Leave it out to reset the master pan.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

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

soundHub.play('rain', { pan: -0.7 });

soundHub.resetPan('rain'); // this sound back in the centre
soundHub.resetPan(); // the master pan back in the centre

Good to know​

  • With an id, this is setPan with 0, without the pan_changed event. It dispatches SoundEventsEnum.PAN_RESET ('pan_reset') with isMaster: false instead.
  • The stereo panner stays on the sound, set to 0, so isStereoPanActive still returns true. Use removePan to take it off.
  • Like setPan, it removes a 3D panner if the sound had one.
  • Without an id it calls resetGlobalPan, which also removes the 3D panner from every sound.
  • Only buffered sounds are handled by id. For a stream or an id that is not loaded, the error is logged and dispatched as an error event.

See also​