Login / Register 0 items | $0.00 New @ KVR
Ap0C552
KVRist
 
142 posts since 15 Feb, 2012
I am writting some code to take some PCM audio, and a float value that represents pan [-1.0,1.0] where center is 0.

When I pan left, I will decrease the amplitude in the right channel, should I also increase the amplitude in the left channel?

Or should I just decrease in the right, so pan center and full pan left, the left channel amplitude is the same.

Thanks for any insight provided!! :)
User avatar
noizebox
KVRer
 
20 posts since 19 Nov, 2012, from Stockholm, Sweden
You should definitely make the left channel a bit louder when panned hard left if you want the user to percieve the same loudness level as center panned audio. How much is subject to some debate though. See https://en.wikipedia.org/wiki/Pan_law for details.
mystran
KVRAF
 
4979 posts since 11 Feb, 2006, from Helsinki, Finland
Right.. so judging by how your question is worded, perhaps we should start with the concept of pan laws.. you see most of the time you want to follow an "equal power panning law" which means that whatever the position of the pan pot, you always get the same total signal power (at least assuming a mono input). Equal power is almost always preferred, because this way as you adjust the pan-pot the signal (as heard) stays essentially constant level, the position just moves.

Since power is the square of the amplitude, in terms of the linear gain multipliers of the two channels this means that the sum of squares of the gain values stays constant.

Then there's the question of taper, which would be the actual shape of the curve. I'll assume x in [0,1] 'cos that's really easier to work with, but you can obviously remap. Now.. one popular choice is cos(x*pi/2)^2+sin(x*pi/2)^2=1 which is know as "circular panning" or "cosine taper" where cos(x*pi/2) and sin(x*pi/2) are the linear gains.. but similarly sqrt(x)^2+sqrt(1-x)^2=1 and more generally you can take any "cross-fade" curve and take sqrt of both values to turn it into equal power. What's "best" is somewhat of a matter of choice. Personally I like pan-curves with lots of action in the middle and not too much at the end points, so something like sqrt of smoothstep works well for me.. but anything equal power is quite workable.

So.. with that covered.. with equal power laws the center position is down by -3dB, which translates to sqrt(.5)=0.707.. as the linear gain value. Now you have two choices: either you use the values directly and center gets attenuated by 3dB or you boost everything by 3dB (ie. multiply the computed gain values by sqrt(2)) and center stays at 0dB while panning to either side results in a 3dB boost on that channel. If you look around the software world, you'll find both of these approaches. You'll also find some software lets you choose... and some weird software even lets you choose linear panning laws that don't maintain equal power... but you almost certainly never want to use that sort of things for anything. :)

My recommendation for an "unsurprising" panning law would be to just use cosine taper with -3dB center, unless you know you have the headroom (needed when panning to sides) to put the center at 0dB. [edit: for plugins and such it's fine to assume headroom, but if you're writing to integer formats or something then you might need to be more conservative] This should feel close enough to "correct" for most people. If you want to do something else, I'd highly recommend letting some artists test that the result doesn't feel too weird.
Image <- plugins | forum
User avatar
Aleksey Vaneev
KVRAF
 
3501 posts since 7 Sep, 2002
mystran wrote:What's "best" is somewhat of a matter of choice.

Just a note, if you take physics of the sound, when speakers are 60 degrees apart, they do not sum linearly, the sum is -1.3 dB quieter than if they were 0 degrees apart. That's at least applicable to lower frequencies, high frequenies may not interact as much due to narrow directionality.

IMO, the most correct would be 4.7 dB taper if one considers power of sinewave signal sum. I always wondered why 3 dB taper, it's probably a compromise, as 6 dB or even 4.7 dB is a bit steep, or maybe it was due to assumption that everyone positions speakers 90 degrees apart, which is of course not a universal recommendation. Ideally, when doing panning one should also specify speaker positioning.
Image
User avatar
aciddose
KVRAF
 
11941 posts since 7 Dec, 2004
Aleksey Vaneev wrote:or maybe it was due to assumption that everyone positions speakers 90 degrees apart,


Headphones.

The compromise makes a lot more sense if you consider all factors, not just stereo speaker configurations.

Once you include headphones and mono speakers with various mixers, the 3 dB option becomes the best all-around compromise.

Also the circuits used to generate the panning law are of critical importance: other laws are either too application-specific or far more expensive. Printing a potentiometer with a smooth and equal non-linear curve is not easy. Do some research on equal power potentiometers to understand why the 3 dB law is the best option from a hardware manufacturer's point of view.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
User avatar
Aleksey Vaneev
KVRAF
 
3501 posts since 7 Sep, 2002
aciddose wrote:
Aleksey Vaneev wrote:or maybe it was due to assumption that everyone positions speakers 90 degrees apart,


Headphones.

The compromise makes a lot more sense if you consider all factors, not just stereo speaker configurations.

Once you include headphones and mono speakers with various mixers, the 3 dB option becomes the best all-around compromise.

I think when mixing in headphones you do not need compensation at all, may be perceptual compensation is needed, but I'm yet to read a scientific experiment on that - if you have any links that would be great to look at.
Image
User avatar
aciddose
KVRAF
 
11941 posts since 7 Dec, 2004
Yes so you aren't actually shifted toward 6 dB as you thought, the 0 dB case balances out at 3 dB.

Mixing to mono is a very important aspect of this too... but I believe circuit cost is the primary factor.

Good approximations to the 3 dB law are natural in very cheap circuits. In fact the approximation to 3 dB may be the "best fit" solution achievable with the most simple circuit.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
Ap0C552
KVRist
 
142 posts since 15 Feb, 2012
Thank you for the replies!
JCJR
KVRAF
 
2308 posts since 17 Apr, 2005, from S.E. TN
Pan laws as described above seem "the right thing to do" when panning mono-to-stereo. Pick whichever one seems to make the most sense.

I'm out of date, but idly curious about stereo-to-stereo panning. Hardware stereo mixers which have X number of mono channel strips and Y number of stereo channel strips, or software mixers which can accomodate both mono and stereo source tracks--

Knob labels can vary-- I recently bought a smallish analog mixer for live keyboards with several mono channel strips and several stereo channel strips. The control layout for trim, EQ, pan and level is identical between mono and stereo channels, but the stereo channel strip pan knobs are labeled "balance" rather than "pan" though I've seen it labeled both ways. Balance may be a more accurate moniker for stereo-to-stereo pan as usually implemented.

Perhaps because it would take a lot of parts to "do the right thing" in a stereo-to-stereo pan, or perhaps because it is difficult to define an unambiguous "best right thing to do", the implementation is often simple and rather crude--With the pan knob centered, LeftInput is hardwired to LeftOutput at unity gain and RightInput is hardwired to RightOutput at unity gain. As the pan knob is rotated left of center, LeftInput remains unity gain and RightInput gets attenuated. As the pan knob is rotated right of center, RightInput remains unity gain and LeftInput gets attenuated.

Such stereo channel strip behavior is simple to implement and is common enough that users are probably not caught by surprise. And it does generally function as a balance adjustment-- If you have a stereo track and one channel is too hot, then the "pan" or "balance" knob can fix it.

But maybe there are behaviors which would "usually be a better thing to do"? I don't know. It may be that a fancier implementation might improve some situations while worsening other situations.

An advantage of the simple balance control described above, for instance if you are mastering or whatever, have a bunch of finished stereo tracks in a DAW project where each stereo track is a mastered or near-mastered song-- And you un-mute one track at a time when auditioning/tweaking. The simple behavior, at least with unity gain and center-pan, the track goes unmodified from input to output-- The entire song just gets multiplied by 1.0 on the way thru the mixer. Admittedly modern float math gain does not mangle audio to any significant degree, but some folks might like easily getting to a setting of "no modification at all" from intput to output, in some applications.

A problem with the simple way, is all those stereo synth patches so common nowadays. Perhaps of special note fancy stereo acoustic piano patches and fancy stereo drumkit patches.

I've noticed that many modern stereo acoustic piano patches can sound bad if you electronically mix them to mono and squirt them out of a mono speaker. For whatever reason, they sound a lot better if played thru stereo speakers with the channel mixing happening acoustically in the room. So far as that goes, a lot of nice stereo hammond+leslie patches really start to suck if you mix them to mono and squirt them out a mono speaker (or dual-mono out of stereo speakers).

A well-panned drum kit, maybe hats are significantly louder on one side and floor tom significantly louder on the other side or whatever.

Starting with a stereo piano patch, and the "simple" balance/pan control, if you want the piano louder on the left side of the mix, it will basically turn down the right mic on the sample-source grand piano. You don't really want more left-piano mic in yer mix-- You want to wheel the piano over to stage left and pick up both the left and right mics in proper balance.

Same deal with hammond+leslie-- If you want to move the leslie stage-right, you want to move the whole sound over to the right, not just disconnect the left-hand mics!

Same deal with stereo drumkit. Moving the drumkit away from stage center ought not give you too much floor tom and not enough hat or vice-versa.

One solution is to route the stereo synth or DAW track into dual mono channel strips rather than a stereo channel strip. That way you can narrow the stereo image and move the entire image away from center-stage without losing track information.

Am guessing maybe a "constant amplitude" stereo-to-stereo pan might be done somehow-- Maybe if you pan half-left, LeftInput is still hardwired to LeftOutput, but also an attenuated copy of RightInput is mixed into LeftOutput, and of course RightInput is also attenuated in RightOutput. So that the "stereo center" of the track would sound like it is "half left" with the LeftInput still hardpanned to LeftOutput and RightInput maybe center-panned, equal levels of RightInput appearing in both LeftOutput and RightOutput.

At whatever "pan law" would keep the perceptual amplitude mix the same, so that the stereo piano still has equal levels of left and right mic, and the stereo drums still have equal levels of hats vs floor tom.

Hard-Pan-Left would just be a mono mix of LeftInput + RightInput hardwired to LeftOutput, and Hard-Pan-Right would be a mono mix of LeftInput + RightInput hardwired to RightOutput.

Do some mixers do it "fancy" like that? Or are there better ways to do it fancy? The hazard being that perhaps any "fancy" method might work worse than the simple method in some common situations. Hard to say.
User avatar
aciddose
KVRAF
 
11941 posts since 7 Dec, 2004
The 3 dB law is identical whether mono or stereo. It is simply a scaling for two channels.

Whether the two channels are derived from one channel or not is completely irrelevant.

"Balance" is a piecewise linear function identical to that used in 3 dB law approximations except that the mid point is set to 1 or 0 rather than sqrt(1/2). A balance function ensures there is zero level loss in the unfaded channel. During a fade to the left, the left channel remains unity throughout the entire fade.

This is identical to as if you had faded the right channel from 0 dB to -40 dB (or similar depending upon the mixer faders) without ever touching the left channel fader.

In most software you will find this labelled "0 dB law", "balance" or similar.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
User avatar
aciddose
KVRAF
 
11941 posts since 7 Dec, 2004
In each of these graphs there is a cyan trace representing the sum of L+R and a green trace which shows 1/2 dB steps. I didn't want to bother adding more horizontal line functionality to the graph tool since it would take me too long and is only rarely needed. (I may add it at some point, though.) This green trace is mostly useless unless you don't trust my text labels. :)

6 dB "linear" law:
Image

4.5 dB "square root of products" AKA "half and half" law:
Image

3 dB "cosine" law:
Image

0 dB "balance" law:
Image

The OP's question is really just a question of "should I set the gain for my pan laws?"

Well nobody can answer that fully except for you. Ideally the user should be able to both select the pan law and set the gain compensation value. For a 3 dB law the "unity at center" gain would be 3 dB or sqrt(2).
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
JCJR
KVRAF
 
2308 posts since 17 Apr, 2005, from S.E. TN
Thanks aciddose. I suppose the musical implication of Stereo-to-Stereo "balance" algorithm that seems different-- Mono-to-Stereo pan of whatever flavor, the input can appear at either the left or right outputs, and the timbre of the mono input signal will basically be the same regardless where it is panned. Except acoustic and psycho-acoustic effects. The timbre might be different in the left vs right speaker, left vs right room acoustics, or left vs right perceptual differences in the listener's ear and brain.

But with Stereo-to-Stereo "balance" the LeftInput NEVER gets into the RightOutput and the RightInput NEVER gets into the LeftOutput. And if the tone of the source left vs right is different, such as left and right piano sample mics, the setting of "balance" affects both perceived stereo position and also strongly affects timbre.

A fancier Stereo-to-Stereo pan is not likely a timbral panacea. Many good sounding stereo patches sound awful when electronically mixed to mono. So gradually narrowing the stereo spread with a pan knob on such patches would be gradual morph between good and awful as the signal becomes ever-closer to mono, I suppose. Wild guessing. I'm cheep but was forced to bite the bullet and put together a stereo live keyboard stage rig because some of the patches sound so bad mixed to mono, but who knows why a stereo stage monitor rig with the two speakers a few feet apart mix in the air and don't suck so bad.

A "fancier" Stereo-to-Stereo pan-- Assuming the pan knob is -1 hard left, 0 center, +1 hard right--

From -1 to 0, LeftInput is unity gain to LeftOutput and -inf gain to RightOutput (Hard Left). From 0 to +1, LeftInput pans from Hard Left thru the Center and finally to Hard Right.

From -1 to 0, RightInput pans from Hard Left thru the Center and finally to Hard Right. From 0 to +1, RightInput remains Hard Right.

So if we set the pan knob Hard Left we get a mono mix of LeftInput + RightInput on the LeftOutput. If we set the pan knob Hard Right we get a mono mix of both input channels on the RightOutput.

If the stereo track is mono-compatible then the timbre ought to be about the same either Hard Left, Center, or Hard Right. Maybe the timbre at intermediate positions would depend on the speakers + room or the headphones or whatever, so that no theoretical curve would always "psychoacoustically mix equal amounts" regardless of intermediate pan location. Or maybe one of the pan laws would be pretty durable in many situations. Dunno.

Wonder what would make a good test signal to evaluate the fade curves? Maybe a pleasingly interesting harmonically rich test tone-- Put the odd harmonics on one stereo channel and put the even harmonics on the other stereo channel. If a "fancy pan" knob location would mess up the perceived mix of left + right then the ear should easily hear a timbral change. Or maybe something else would be better.
mystran
KVRAF
 
4979 posts since 11 Feb, 2006, from Helsinki, Finland
The nice thing about the -3dB equal power rule is that it also works well for stereo balance when you assume the signals for the two channels are uncorrelated. Since it also happens to be a good "best guess rule" for panning mono signals when you don't try to make too many assumptions about the listening environment, it just ends up being a pretty good rule overall, especially if you don't plan on differentiating between mono panning and stereo balance.

Certainly if you are actually mixing for a specific controlled listening environment then it makes sense to use something that's specifically tuned to give you the correct results in that specific listening environment... but for the rest of us, it's probably not worth the trouble to try to be too clever. What we can probably all agree on though is that both aciddose's "6dB linear" and "0dB balance" usually feel weird in practice and the ideal is going to lie somewhere between these two extremes.
Image <- plugins | forum
User avatar
aciddose
KVRAF
 
11941 posts since 7 Dec, 2004
It's actually trivial to use the same method to create a "half and half" between cosine and the balance law too, yielding a 1.5 dB law:
Image

Your position in the law can also always be skewed/tapered by modifying the input coefficient.

Here for a definition of "taper": http://www.resistorguide.com/potentiometer-taper/
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
mystran
KVRAF
 
4979 posts since 11 Feb, 2006, from Helsinki, Finland
As long as you allow at least a little bit of center attenuation, you can get continuous curves by using different powers between 0 and 1.. something like this: https://www.desmos.com/calculator/zpq6h2mesm

You'll probably want some additional tapering to move the action closer to the middle (eg. put x through a smoothstep first) but.. yeah.. :P
Image <- plugins | forum
Next

Moderator: KVR Moderators (Main)

Return to DSP and Plug-in Development