SoundPanType
SoundPanType says how a sound is panned: stereo, between the left and right channel, or spatial, at a position in a 3D scene. A sound uses one or the other, never both.
export enum SoundPanType {
Stereo = 'stereo',
Spatial = 'spatial'
}
| Value | String | Description |
|---|---|---|
SoundPanType.Stereo | 'stereo' | A stereo panner node, from -1 (full left) to 1 (full right). The default for every sound. |
SoundPanType.Spatial | 'spatial' | A 3D panner node at an x, y, z position, heard from the listener. See Spatial audio. |
Import it from the package:
import { SoundPanType } from 'soundhub';
Where it is used
panTypein the play options, next topanfor stereo andpanSpatialPositionfor spatial.defaultPanTypein the hub config,SoundPanType.Stereoby default.
Example
import { SoundHub, SoundPanType } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('rain', '/audio/rain.mp3');
// Stereo: shifted to the left
soundHub.play('rain', {
loop: true,
panType: SoundPanType.Stereo,
pan: -0.8,
});
// Switch to spatial: ten units to the right, fifteen ahead
soundHub.setSpatialPosition(10, 0, -15, 'rain');
soundHub.isSpatialAudioActive('rain'); // true
soundHub.isStereoPanActive('rain'); // false
// And back to stereo
soundHub.setPan('rain', 0.5);
soundHub.isStereoPanActive('rain'); // true
Try it
Move the sound between the left and right channel to hear stereo panning at work. Use headphones for the clearest effect.
Move a sound left and right
IdlePlay the helicopter and drag the slider. Headphones make the movement easy to follow.
Code
Your clicks show up here as soundhub calls
Good to know
- The methods switch the type for you.
setSpatialPositionremoves the stereo panner and setsSpatial.setPanremoves the 3D panner, setsStereoand puts the spatial position back to0, 0, 0. - For a sound played without
overlap,panType: SoundPanType.Spatialon its own does not make it spatial. A non-zeropanSpatialPositiondoes. For an overlapping instance,panTypeis taken as given. updateSoundOptionsonly stores new options for the nextplay(). It does not rewire a sound that is already playing, so usesetSpatialPositionorsetPanto switch live.- Streams from
loadStreamare always stereo.
See also
setPan: stereo pan a sound.setSpatialPosition: place a sound in 3D.isStereoPanActive: check for a stereo panner.isSpatialAudioActive: check for a 3D panner.removePan: take the stereo panner off.removeSpatialEffect: take the 3D panner off.- Spatial audio: the full picture.