From 2172f974e70d12ee70d088620a49fd2614668f8a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 17 May 2016 14:28:30 -0700 Subject: [PATCH] Improve reverb panning gains for "3D" output. --- Alc/effects/reverb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 916469a8..f9c19325 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -826,11 +826,11 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection ALfloat length; ALuint i; - /* 0.5 would be the gain scaling when the panning vector is 0. This also - * equals sqrt(1/4), a nice gain scaling for the four virtual points + /* sqrt(0.5) would be the gain scaling when the panning vector is 0. This + * also equals sqrt(2/4), a nice gain scaling for the four virtual points * producing an "ambient" response. */ - gain[0] = gain[1] = gain[2] = gain[3] = 0.5f; + gain[0] = gain[1] = gain[2] = gain[3] = 0.707106781f; length = sqrtf(ReflectionsPan[0]*ReflectionsPan[0] + ReflectionsPan[1]*ReflectionsPan[1] + ReflectionsPan[2]*ReflectionsPan[2]); if(length > 1.0f) { @@ -842,7 +842,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection for(i = 0;i < 4;i++) { ALfloat dotp = pan[0]*PanDirs[i][0] + pan[1]*PanDirs[i][1] + pan[2]*PanDirs[i][2]; - gain[i] = dotp*0.5f + 0.5f; + gain[i] = sqrtf(clampf(dotp*0.5f + 0.5f, 0.0f, 1.0f)); } } else if(length > FLT_EPSILON) @@ -851,7 +851,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection { ALfloat dotp = ReflectionsPan[0]*PanDirs[i][0] + ReflectionsPan[1]*PanDirs[i][1] + -ReflectionsPan[2]*PanDirs[i][2]; - gain[i] = dotp*0.5f + 0.5f; + gain[i] = sqrtf(clampf(dotp*0.5f + 0.5f, 0.0f, 1.0f)); } } for(i = 0;i < 4;i++) @@ -861,7 +861,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection State->Early.PanGain[i]); } - gain[0] = gain[1] = gain[2] = gain[3] = 0.5f; + gain[0] = gain[1] = gain[2] = gain[3] = 0.707106781f; length = sqrtf(LateReverbPan[0]*LateReverbPan[0] + LateReverbPan[1]*LateReverbPan[1] + LateReverbPan[2]*LateReverbPan[2]); if(length > 1.0f) { @@ -873,7 +873,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection for(i = 0;i < 4;i++) { ALfloat dotp = pan[0]*PanDirs[i][0] + pan[1]*PanDirs[i][1] + pan[2]*PanDirs[i][2]; - gain[i] = dotp*0.5f + 0.5f; + gain[i] = sqrtf(clampf(dotp*0.5f + 0.5f, 0.0f, 1.0f)); } } else if(length > FLT_EPSILON) @@ -882,7 +882,7 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection { ALfloat dotp = LateReverbPan[0]*PanDirs[i][0] + LateReverbPan[1]*PanDirs[i][1] + -LateReverbPan[2]*PanDirs[i][2]; - gain[i] = dotp*0.5f + 0.5f; + gain[i] = sqrtf(clampf(dotp*0.5f + 0.5f, 0.0f, 1.0f)); } } for(i = 0;i < 4;i++)