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
| Parameter | Type | Default | Description |
|---|---|---|---|
x | number | required | x part of the direction vector. |
y | number | required | y part of the direction vector. |
z | number | required | z part of the direction vector. |
skipDispatchEvent | boolean | false | Set 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_changedevent. - 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') withisMaster: trueandorientation, and nosoundId.
See also
getMasterSpatialOrientation: read the direction back.setMasterSpatialPosition: position the master panner and set its cone.setSpatialOrientation: point one sound.