ComputePan bug
HSNB opened this issue · comments
I'm pretty sure this line of code:
float right = (pan <= 0) ? (-pan - 1.f) : 1.f;
Should be this:
float right = (pan <= 0) ? (pan + 1.f) : 1.f;
Because if pan == 0, then right will be -1 in the wrong line.
On top of that, the value clamping on left and right variables are between -1 and 1, but I'm pretty sure it's supposed to be between 0 and 1.
Finally I'd like to ask why values in the matrix resulting from X3DAudioCalculate are always with 0.5 values as "max volume" and not "1" (when the DstChannels == 2, so two speakers).
This means the sound is played at 6 dB less. From looking at the FAudio source code (which reverse engineered XAudio2) the function there computes the "energy per channel" by dividing by the amount of channels. So 1 / 2 = 0.5.
However isn't it strange that the same same sound played in a non-3D environment is louder than in this 3D environment? On the same two-speaker system.
Of course I mean here in the situation where the distance between listener and emitter == 0 (at the same location), so at max volume.
Just hoping for a minor comment on this, not really expecting a solution. I'm multiplying the resulting matrix values x2 so I get the original volume again as a "hack", since there's no way to pass parameters to X3DAudioCalculate to do it for me (except passing X3DAUDIO_CALCULATE_ZEROCENTER flag, but then the resulting matrix is no longer in 3D so that doesn't work for me either, since I still want that to work).
Thanks for your time.
The stereo pan computation is based on this Microsoft Docs article. I believe the reason you use 0.5 for each channel instead of 1.0 for each channel is to maintain energy conservation.
I'll have to look at the mono-pan more. I can't really figure out what I was thinking :)
I adapted the code from the XNA Game Studio audio framework, but I completely hosed up mono panning.
Fixed in this commit