Skip to main content

resetSpatialPosition

Put a positioned sound back at 0, 0, 0, where the listener stands by default. Without an id it resets the master panner instead.

resetSpatialPosition(id?: string): void;

Parameters​

ParameterTypeDefaultDescription
idstringundefinedID of the sound to reset. Leave it out to reset the master spatial position.

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(8, 0, -3, 'rain');

// Back to the centre of the scene
soundHub.resetSpatialPosition('rain');
soundHub.getSpatialPosition('rain'); // { x: 0, y: 0, z: 0 }

Good to know​

  • Without an id it does not reset every sound. It calls setMasterSpatialPosition with 0, 0, 0, which adds a master panner if there was none. To take the master panner out again, use resetMasterSpatialPosition.
  • With an id it only acts when the sound has a 3D panner. A stereo sound, an unknown id or a stream is left alone without an error.
  • The sound keeps its panner and stays spatial. Use removeSpatialEffect to drop the panner.
  • Does nothing when spatialAudio is off in the hub config.
  • A sound reset dispatches spatial_position_changed followed by spatial_position_reset. A master reset dispatches global_spatial_position_changed followed by spatial_position_reset with isMaster: true.

See also​