Skip to main content

getSpatialOrientation

Get the direction a sound points in.

getSpatialOrientation(soundId: string): { x: number; y: number; z: number } | null;

Parameters​

ParameterTypeDefaultDescription
soundIdstringrequiredID 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 through panSpatialOrientation in the play options, are returned. A panner that was never pointed returns null, even though the browser gives it a default direction.
  • The values are the rounded ones (2 decimals).

See also​