Skip to main content

isStereoPanActive

Check whether a sound has a stereo panner. Use it to tell a stereo panned sound from one that is positioned in 3D or not panned at all.

isStereoPanActive(id: string): boolean;

Parameters​

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

Returns​

boolean: true when the sound has a stereo panner node. false when it has none, when it uses a 3D panner instead, 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.setPan('rain', -0.5);
soundHub.isStereoPanActive('rain'); // true

soundHub.setSpatialPosition(3, 0, -2, 'rain');
soundHub.isStereoPanActive('rain'); // false, the stereo panner was replaced

Good to know​

  • It checks for the node, not for a pan value away from centre. Every sound gets pan: 0 in its play options when it loads, so after the first play() of a stereo sound this returns true even if you never panned it.
  • removePan and setSpatialPosition take the stereo panner away, so this returns false after either.
  • Streams from loadStream are not looked up, so the result for a stream id is always false.

See also​