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
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | required | ID 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: 0in its play options when it loads, so after the firstplay()of a stereo sound this returnstrueeven if you never panned it. removePanandsetSpatialPositiontake the stereo panner away, so this returnsfalseafter either.- Streams from
loadStreamare not looked up, so the result for a stream id is alwaysfalse.
See also
isSpatialAudioActive: the same check for the 3D panner.setPan: pan a sound left or right.removePan: take the stereo panner off a sound.