isSpatialAudioActive
Check whether a sound is positioned in 3D, that is, whether it has a panner node.
isSpatialAudioActive(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 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. AfterremoveSpatialEffectthis isfalse, although the sound still hasSoundPanType.Spatial. setPanandsetGlobalPanremove the 3D panner, so this returnsfalseafter either.- Streams are not looked up, so a stream id returns
false.
See also
isStereoPanActive: the same check for the stereo panner.isSpatialAudioEnabled: whether spatial audio is on at all.setSpatialPosition: position a sound in 3D.