getSpatialOrientation
Get the direction a sound points in.
getSpatialOrientation(soundId: string): { x: number; y: number; z: number } | null;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
soundId | string | required | ID of a loaded sound or of one of its instances. |
Returns
{ x: number; y: number; z: number } | null: the direction last set for the sound. null when the sound was never given a direction, or when the id is unknown.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('television', '/audio/television.mp3');
soundHub.getSpatialOrientation('television'); // null, no direction yet
soundHub.setSpatialOrientation('television', 0, 0, -1);
soundHub.getSpatialOrientation('television'); // { x: 0, y: 0, z: -1 }
Good to know
- Only directions set through
setSpatialOrientation, or throughpanSpatialOrientationin the play options, are returned. A panner that was never pointed returnsnull, even though the browser gives it a default direction. - The values are the rounded ones (2 decimals).
See also
setSpatialOrientation: point a sound.getSpatialPosition: where the sound is.getMasterSpatialOrientation: the direction of the master panner.