A way to set balance of stereo track

I'd like an API command to set left/right balance of an audio track (fileplayer) channel.


Sets the balance parameter for the channel. -1.0 is full left, 0.0 is center, and 1.0 is full right. Fractions can be used.

It would work similarly to Pan but instead would modify the balance of left and right making sure that the total volume is always 100%. Like on a hifi. I could set balance to full right and the right channel would play over both left and right outputs.

In Fore! Track I had to do this manually by splitting the stereo pair into two files which I play in lockstep and modify the volume of each during gameplay.


For full flexibility I think go with the 2x2 matrix here: channel:setLevels(l_to_l, l_to_r, r_to_l, r_to_r) which does

out_left = in_left * l_to_l + in_right * r_to_l;
out_right = in_left * l_to_r + in_right * r_to_r;

I'm tempted to add this to individual sources as well, but that increases the complexity considerably--there's not a single point where sources get mixed into the channel buffer, they each do that in their own render function. For now I'll just add the channel output matrix.

One more implementation detail: Do we do this before or after applying effects? It won't make much difference for effects that process left and right independently (which is true for pretty much all of the built ins) but you wouldn't want to pan the output of something like a stereo spatializer effect. In this case applying the matrix before the effect makes more sense, I think.


Happy to leave the decision with you Dave. Cheers!

1 Like

I don't suppose it would be possible to support more than 2 channels?

Happy to file a new issue for this request, if you'd prefer.

Here's why I'm suggesting it, basically Nintendo use the same system I use in Fore! Track and Lucas Pope uses in Mars After Midnight but they do it with 8 tracks: