Build with this node

Start with a prompt in Studio, or copy it into your own coding agent.

Ask Studio

@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 side

For 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 after gain × cos, as the sampler stores Math.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.

Algorithm properties and proofs

No Lean 4 proof is mapped to this node.

Explore proofs alongside performance

Dependencies

None: this node imports no other node.

Dependents

Used by