From 98d78f7ff9a3636567273e4384731debca2ec79f Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 26 Nov 2010 00:24:54 -0800 Subject: Slightly improve channel gain calculations --- Alc/ALu.c | 4 ++-- Alc/alcReverb.c | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index 78f18782..b7471132 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -620,13 +620,13 @@ ALvoid CalcSourceParams(ALsource *ALSource, const ALCcontext *ALContext) DirGain = aluSqrt(Position[0]*Position[0] + Position[2]*Position[2]); // elevation adjustment for directional gain. this sucks, but // has low complexity - AmbientGain = 1.0/aluSqrt(Device->NumChan) * (1.0-DirGain); + AmbientGain = aluSqrt(1.0/Device->NumChan); for(s = 0;s < OUTPUTCHANNELS;s++) ALSource->Params.DryGains[s] = 0.0f; for(s = 0;s < (ALsizei)Device->NumChan;s++) { Channel chan = Device->Speaker2Chan[s]; - ALfloat gain = SpeakerGain[chan]*DirGain + AmbientGain; + ALfloat gain = AmbientGain + (SpeakerGain[chan]-AmbientGain)*DirGain; ALSource->Params.DryGains[chan] = DryGain * gain; } diff --git a/Alc/alcReverb.c b/Alc/alcReverb.c index e1f6df45..02f07f9a 100644 --- a/Alc/alcReverb.c +++ b/Alc/alcReverb.c @@ -596,7 +596,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection ALfloat latePan[3] = { LateReverbPan[0], LateReverbPan[1], LateReverbPan[2] }; const ALfloat *speakerGain; - ALfloat dirGain, ambientGain; + ALfloat dirGain; ALfloat length; ALuint index; ALint pos; @@ -629,27 +629,26 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection pos = aluCart2LUTpos(earlyPan[2], earlyPan[0]); speakerGain = &Device->PanningLUT[OUTPUTCHANNELS * pos]; dirGain = aluSqrt((earlyPan[0] * earlyPan[0]) + (earlyPan[2] * earlyPan[2])); - ambientGain = (1.0 - dirGain); + for(index = 0;index < OUTPUTCHANNELS;index++) State->Early.PanGain[index] = 0.0f; for(index = 0;index < Device->NumChan;index++) { Channel chan = Device->Speaker2Chan[index]; - State->Early.PanGain[chan] = speakerGain[chan]*dirGain + - ambientGain; + State->Early.PanGain[chan] = 1.0 + (speakerGain[chan]-1.0)*dirGain; } + pos = aluCart2LUTpos(latePan[2], latePan[0]); speakerGain = &Device->PanningLUT[OUTPUTCHANNELS * pos]; dirGain = aluSqrt((latePan[0] * latePan[0]) + (latePan[2] * latePan[2])); - ambientGain = (1.0 - dirGain); + for(index = 0;index < OUTPUTCHANNELS;index++) State->Late.PanGain[index] = 0.0f; for(index = 0;index < Device->NumChan;index++) { Channel chan = Device->Speaker2Chan[index]; - State->Late.PanGain[chan] = speakerGain[chan]*dirGain + - ambientGain; + State->Late.PanGain[chan] = 1.0 + (speakerGain[chan]-1.0)*dirGain; } } -- cgit v1.2.3