Skip to main content

setMasterSpatialOrientation

Point the master panner in a direction. Like setSpatialOrientation for one sound, it is only audible when the master panner has a cone set.

setMasterSpatialOrientation(x: number, y: number, z: number, skipDispatchEvent?: boolean): void;

Parameters​

ParameterTypeDefaultDescription
xnumberrequiredx part of the direction vector.
ynumberrequiredy part of the direction vector.
znumberrequiredz part of the direction vector.
skipDispatchEventbooleanfalseSet to true to leave out the spatial_orientation_changed event.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

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

soundHub.play('music', { loop: true });

// A speaker in front of you, with a cone
soundHub.setMasterSpatialPosition(0, 0, -3, {
coneInnerAngle: 90,
coneOuterAngle: 180,
coneOuterGain: 0.3,
});

// Facing you: full volume
soundHub.setMasterSpatialOrientation(0, 0, 1);

// Turned away: quieter
soundHub.setMasterSpatialOrientation(0, 0, -1);

Good to know​

  • When there is no master panner yet, one is added at the current master position, without a global_spatial_position_changed event.
  • The default direction is 1, 0, 0, along positive x.
  • The values are rounded to 2 decimals. It does not check whether spatial audio is enabled.
  • Every call dispatches SoundEventsEnum.SPATIAL_ORIENTATION_CHANGED ('spatial_orientation_changed') with isMaster: true and orientation, and no soundId.

See also​