Skip to main content

isSpatialAudioActive

Check whether a sound is positioned in 3D, that is, whether it has a panner node.

isSpatialAudioActive(id: string): boolean;

Parameters​

ParameterTypeDefaultDescription
idstringrequiredID of a loaded sound or of one of its instances.

Returns​

boolean: true when the sound has a 3D panner node. false when it has none or when the id is unknown.

Example​

import { SoundHub } from 'soundhub';

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

soundHub.play('rain', { loop: true });
soundHub.isSpatialAudioActive('rain'); // false

soundHub.setSpatialPosition(2, 0, -3, 'rain');
soundHub.isSpatialAudioActive('rain'); // true

soundHub.setPan('rain', 0.5);
soundHub.isSpatialAudioActive('rain'); // false, setPan replaced the 3D panner

Good to know​

  • It checks for the node, not the sound's panType. After removeSpatialEffect this is false, although the sound still has SoundPanType.Spatial.
  • setPan and setGlobalPan remove the 3D panner, so this returns false after either.
  • Streams are not looked up, so a stream id returns false.

See also​