setMasterSpatialPosition
Position the whole mix in 3D at once. The first call adds a panner to the master output chain, so every sound goes through it, on top of any position a sound has of its own.
setMasterSpatialPosition(x: number, y: number, z: number, config?: SoundPannerConfig, skipDispatchEvent?: boolean): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
x | number | required | Position of the master panner on the x axis. |
y | number | required | Position on the y axis. |
z | number | required | Position on the z axis. |
config | SoundPannerConfig | {} | Panner settings to change. Only the keys you pass are applied. See Spatial audio. |
skipDispatchEvent | boolean | false | Set to true to leave out the global_spatial_position_changed event. |
Returns
Nothing.
Example
import { SoundHub, PanningModel, DistanceModel } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true });
// The whole mix comes from behind a wall to the right
soundHub.setMasterSpatialPosition(4, 0, 0, {
panningModel: PanningModel.HRTF,
distanceModel: DistanceModel.Linear,
maxDistance: 100,
});
soundHub.getMasterSpatialPosition(); // { x: 4, y: 0, z: 0 }
Good to know
- The master chain becomes master gain, then this panner, then the master stereo panner, then the limiter when it is on.
setGlobalPankeeps working. - Since 6.3.2, splicing the panner in no longer disconnects nodes your app connected to
getMasterOutput. - A new master panner starts with the browser's
PannerNodedefaults, not withpannerNodeConfigfrom the hub config. Passconfigif you want other settings. - Unlike
setSpatialPosition, it does not check whether spatial audio is enabled and does not round the coordinates. - Every call dispatches
SoundEventsEnum.GLOBAL_SPATIAL_POSITION_CHANGED('global_spatial_position_changed') withposition.
See also
getMasterSpatialPosition: read the position back.setMasterSpatialOrientation: point the master panner.resetMasterSpatialPosition: reset and remove the master panner.cleanupGlobalPan: remove the master panner without an event.