Skip to main content

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​

ParameterTypeDefaultDescription
valuenumberrequiredPan 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​

Try it

Pan the whole mix

Idle
centre
LR

setPan 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 setPan and a global pan to the right add up.
  • It does remove the 3D panner from every sound that has one, as removeSpatialEffect would. Those sounds lose their spatial position until you set it again.
  • The value it replaces is kept, and getPreviousMasterPan returns it.
  • Dispatches SoundEventsEnum.MASTER_PAN_CHANGED ('master_pan_changed') with pan and previousPan. There is no argument to skip it.
  • The starting value comes from defaultPan in the hub config, 0 when not set.

See also​