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
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | undefined | ID 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
setMasterSpatialPositionwith0, 0, 0, which adds a master panner if there was none. To take the master panner out again, useresetMasterSpatialPosition. - 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
removeSpatialEffectto drop the panner. - Does nothing when
spatialAudiois off in the hub config. - A sound reset dispatches
spatial_position_changedfollowed byspatial_position_reset. A master reset dispatchesglobal_spatial_position_changedfollowed byspatial_position_resetwithisMaster: true.
See also
setSpatialPosition: place a sound in 3D.removeSpatialEffect: remove the 3D panner from a sound.resetMasterSpatialPosition: reset and remove the master panner.