I'm currently coding, and I'm trying to figure out this panning law thing.

As far as I understood, linear panning is bad, because in the end you don't hear the same volume out of your speakers, right ?

I read that you have to use "constant power panning". After some maths and reading I came out with this piece of code :

Let's say that _crossValue is something between 0 (panned hard left) and 1 (panned hard right), and HALF_PI is ... PI/2

Code: Select all

```
switch(_xLaw)
{
case LINEAR:
_gainChanel1 = 1 - _crossValue;
_gainChanel2 = _crossValue;
break;
case SIN_COS:
_gainChanel1 = sin((1 - _crossValue)*HALF_PI);
_gainChanel2 = sin(_crossValue*HALF_PI);
break;
}
```

However, with this code, in the SIN_COS statement, the sum of both chanels is > 1 when panned full center. I have 0.707 of gain per chanel, so in total it's approx 1.414

I read somewhere that using this SIN_COS law, makes the center being amplified by 3dB, and when I calculate 20*log(1.414), I also find 3

Makes sense so far !

My question, is : how should avoid this ?

I was thinking in simply multiplying each channel by 0,707, this way, when panned in full center, the sum of chanels is 1, so 20*log(1)=0 => no amplification !

But I wonder if there's any hidden trick ?

P.S. : I hope this post makes sense. I'm not sure !