Skip to main content

removeSpatialEffect

Remove the 3D panner from a sound. The audio goes straight from the source to the sound's gain node again, with no position or distance applied.

removeSpatialEffect(id: string): void;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of a loaded sound or of one of its instances.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

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

soundHub.play('rain', { loop: true });
soundHub.setSpatialPosition(5, 0, -5, 'rain');

// Back to plain playback
soundHub.removeSpatialEffect('rain');
soundHub.isSpatialAudioActive('rain'); // false

Good to know​

  • No event is dispatched.
  • The sound goes back to stereo for good: its position returns to 0, 0, 0 and its pan type to SoundPanType.Stereo, in its play options as well, so the next play() does not build a new panner. Before 6.4.0 it did, and the effect came back.
  • The sound's gain node is disconnected and connected to the master again, even when there was no panner.
  • setPan and setGlobalPan call this for you on spatial sounds.
  • Only buffered sounds are handled. For a stream or an id that is not loaded, the error is logged and dispatched as an error event.

See also​