Skip to main content

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​

ParameterTypeDefaultDescription
xnumberrequiredPosition of the master panner on the x axis.
ynumberrequiredPosition on the y axis.
znumberrequiredPosition on the z axis.
configSoundPannerConfig{}Panner settings to change. Only the keys you pass are applied. See Spatial audio.
skipDispatchEventbooleanfalseSet 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. setGlobalPan keeps 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 PannerNode defaults, not with pannerNodeConfig from the hub config. Pass config if 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') with position.

See also​