@maruaudio/dsp/mixing/constant-power-pan gives the constant-power pan gains for a bipolar position as unrounded doubles, and the Web Audio StereoPannerNode balance law for a stereo input.
angle = (clamp(pan, −1, 1) + 1) × π/4
left = cos(angle) right = sin(angle) // centre: √½ per sideFor a stereo pair, constantPowerStereoPanLeft/Right(left, right, pan) follow the specification's stereo-input branch: panning left adds the right channel into the left through that pair and attenuates what stays right; panning right mirrors it.
Parameters
There are no setters or state. pan is clamped to −1 (hard left) to +1 (hard right) inside every function.
Lifecycle
Pure functions. A voice resolves constantPowerPanLeft(pan) and constantPowerPanRight(pan) once at note start and folds them into its constant gain; the stereo balance functions run per sample on an already-stereo bus. Nothing allocates or does I/O.
When to use it
Placing a mono voice in a stereo field when the pan is folded into a per-voice gain, or balancing a stereo bus the way a browser StereoPannerNode would. For a per-sample crossfade over a 0 to 1 position, use @maru/mixing-levels.
Limits
- The angle equals
@maru/mixing-levels' equal-power pair bit for bit; only the rounding differs. This DSP node returns doubles so the caller rounds once aftergain × cos, as the sampler storesMath.fround(gain × panLeft). - The clamp is a local conditional clamp; a NaN passes through.
- At pan 0 the stereo law passes both channels within 1e-12 of the input.