setGlobalPan
Set the stereo pan of the master bus, so everything the hub plays moves left or right together. Unlike setPan, which pans a single sound, this acts on the whole mix.
setGlobalPan(value: number): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
value | number | required | Pan position: -1 is full left, 0 is centre, 1 is full right. Values outside that range are clamped. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
await soundHub.loadSound('music', '/audio/theme.mp3');
soundHub.play('music', { loop: true });
soundHub.setGlobalPan(-0.5); // the whole mix leans left
soundHub.setGlobalPan(0); // centre
soundHub.resetGlobalPan(); // same as setGlobalPan(0), plus a pan_reset event
Try it
Pan the whole mix
IdlesetPan moves one sound. setGlobalPan moves everything at once, like a balance knob.
Code
Your clicks show up here as soundhub calls
Good to know
- Per-sound stereo pans are left alone. The master panner comes after them, so a sound panned left with
setPanand a global pan to the right add up. - It does remove the 3D panner from every sound that has one, as
removeSpatialEffectwould. Those sounds lose their spatial position until you set it again. - The value it replaces is kept, and
getPreviousMasterPanreturns it. - Dispatches
SoundEventsEnum.MASTER_PAN_CHANGED('master_pan_changed') withpanandpreviousPan. There is no argument to skip it. - The starting value comes from
defaultPanin the hub config,0when not set.
See also
getGlobalPan: read the master pan back.resetGlobalPan: centre the master pan.setPan: pan one sound.