diff options
author | Chris Robinson <[email protected]> | 2014-09-30 07:33:13 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-09-30 07:33:13 -0700 |
commit | 4d36ef65b2ec1cd3122bf9ee615df452f003d014 (patch) | |
tree | ffd165b5c9f2e263521feaac0b580707e1b40275 /Alc/ALu.c | |
parent | 4955824c2df321755bfc1b1d8142a969ffc61b08 (diff) |
Use an ambisonics-based panning method
For mono sources, third-order ambisonics is utilized to generate panning gains.
The general idea is that a panned mono sound can be encoded into b-format
ambisonics as:
w[i] = sample[i] * 0.7071;
x[i] = sample[i] * dir[0];
y[i] = sample[i] * dir[1];
...
and subsequently rendered using:
output[chan][i] = w[i] * w_coeffs[chan] +
x[i] * x_coeffs[chan] +
y[i] * y_coeffs[chan] +
...;
By reordering the math, channel gains can be generated by doing:
gain[chan] = 0.7071 * w_coeffs[chan] +
dir[0] * x_coeffs[chan] +
dir[1] * y_coeffs[chan] +
...;
which then get applied as normal:
output[chan][i] = sample[i] * gain[chan];
One of the reasons to use ambisonics for panning is that it provides arguably
better reproduction for sounds emanating from between two speakers. As well,
this makes it easier to pan in all 3 dimensions, with for instance a "3D7.1" or
8-channel cube speaker configuration by simply providing the necessary
coefficients (this will need some work since some methods still use angle-based
panpot, particularly multi-channel sources).
Unfortunately, the math to reliably generate the coefficients for a given
speaker configuration is too costly to do at run-time. They have to be pre-
generated based on a pre-specified speaker arangement, which means the config
options for tweaking speaker angles are no longer supportable. Eventually I
hope to provide config options for custom coefficients, which can either be
generated and written in manually, or via alsoft-config from user-specified
speaker positions.
The current default set of coefficients were generated using the MATLAB scripts
(compatible with GNU Octave) from the excellent Ambisonic Decoder Toolbox, at
https://bitbucket.org/ambidecodertoolbox/adt/
Diffstat (limited to 'Alc/ALu.c')
-rw-r--r-- | Alc/ALu.c | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -959,14 +959,21 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte else { MixGains *gains = voice->Direct.Mix.Gains[0]; - ALfloat DirGain = 0.0f; - ALfloat AmbientGain; for(j = 0;j < MaxChannels;j++) gains[j].Target = 0.0f; /* Normalize the length, and compute panned gains. */ - if(Distance > FLT_EPSILON) + if(!(Distance > FLT_EPSILON)) + { + ALfloat gain = 1.0f / sqrtf(Device->NumSpeakers); + for(i = 0;i < (ALint)Device->NumSpeakers;i++) + { + enum Channel chan = Device->Speaker[i].ChanName; + gains[chan].Target = gain; + } + } + else { ALfloat radius = ALSource->Radius; ALfloat Target[MaxChannels]; @@ -975,22 +982,11 @@ ALvoid CalcSourceParams(ALvoice *voice, const ALsource *ALSource, const ALCconte Position[1] *= invlen; Position[2] *= invlen; - DirGain = sqrtf(Position[0]*Position[0] + Position[2]*Position[2]); - ComputeAngleGains(Device, atan2f(Position[0], -Position[2]*ZScale), 0.0f, - DryGain*DirGain, Target); + ComputeDirectionalGains(Device, Position, DryGain, Target); for(j = 0;j < MaxChannels;j++) gains[j].Target = Target[j]; } - /* Adjustment for vertical offsets. Not the greatest, but simple - * enough. */ - AmbientGain = DryGain * sqrtf(1.0f/Device->NumSpeakers) * (1.0f-DirGain); - for(i = 0;i < (ALint)Device->NumSpeakers;i++) - { - enum Channel chan = Device->Speaker[i].ChanName; - gains[chan].Target = maxf(gains[chan].Target, AmbientGain); - } - if(!voice->Direct.Moving) { for(j = 0;j < MaxChannels;j++) |