diff options
author | Chris Robinson <[email protected]> | 2014-10-02 18:05:42 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-10-02 18:05:42 -0700 |
commit | 95ba18cf4e52c439b85ece2daf0b404fa69c7b70 (patch) | |
tree | 2367b5d69488633fb8d596cf3e3b328d81b2753f /Alc/effects | |
parent | 9377d0f23730ff0d42a870627ea9a75059c481f4 (diff) |
Make ComputeAngleGains use ComputeDirectionalGains
Diffstat (limited to 'Alc/effects')
-rw-r--r-- | Alc/effects/chorus.c | 6 | ||||
-rw-r--r-- | Alc/effects/dedicated.c | 30 | ||||
-rw-r--r-- | Alc/effects/echo.c | 14 | ||||
-rw-r--r-- | Alc/effects/flanger.c | 6 | ||||
-rw-r--r-- | Alc/effects/reverb.c | 62 |
5 files changed, 74 insertions, 44 deletions
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index ad45c785..6e541208 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -93,6 +93,8 @@ static ALboolean ALchorusState_deviceUpdate(ALchorusState *state, ALCdevice *Dev static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, const ALeffectslot *Slot) { + static const ALfloat left_dir[3] = { -1.0f, 0.0f, 0.0f }; + static const ALfloat right_dir[3] = { 1.0f, 0.0f, 0.0f }; ALfloat frequency = (ALfloat)Device->Frequency; ALfloat rate; ALint phase; @@ -111,8 +113,8 @@ static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, cons state->delay = fastf2i(Slot->EffectProps.Chorus.Delay * frequency); /* Gains for left and right sides */ - ComputeAngleGains(Device, atan2f(-1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[0]); - ComputeAngleGains(Device, atan2f(+1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[1]); + ComputeDirectionalGains(Device, left_dir, Slot->Gain, state->Gain[0]); + ComputeDirectionalGains(Device, right_dir, Slot->Gain, state->Gain[1]); phase = Slot->EffectProps.Chorus.Phase; rate = Slot->EffectProps.Chorus.Rate; diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c index 0907d6b0..ea028046 100644 --- a/Alc/effects/dedicated.c +++ b/Alc/effects/dedicated.c @@ -48,16 +48,32 @@ static ALboolean ALdedicatedState_deviceUpdate(ALdedicatedState *UNUSED(state), static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device, const ALeffectslot *Slot) { ALfloat Gain; - ALsizei s; + ALuint i; + + for(i = 0;i < MaxChannels;i++) + state->gains[i] = 0.0f; Gain = Slot->Gain * Slot->EffectProps.Dedicated.Gain; - if(Slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE) - ComputeAngleGains(device, atan2f(0.0f, 1.0f), 0.0f, Gain, state->gains); - else if(Slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) - { - for(s = 0;s < MaxChannels;s++) - state->gains[s] = 0.0f; + if(Slot->EffectType == AL_EFFECT_DEDICATED_LOW_FREQUENCY_EFFECT) state->gains[LFE] = Gain; + else if(Slot->EffectType == AL_EFFECT_DEDICATED_DIALOGUE) + { + ALboolean done = AL_FALSE; + /* Dialog goes to the front-center speaker if it exists, otherwise it + * plays from the front-center location. */ + for(i = 0;i < device->NumSpeakers;i++) + { + if(device->Speaker[i].ChanName == FrontCenter) + { + state->gains[FrontCenter] = Gain; + done = AL_TRUE; + } + } + if(!done) + { + static const ALfloat front_dir[3] = { 0.0f, 0.0f, -1.0f }; + ComputeDirectionalGains(device, front_dir, Gain, state->gains); + } } } diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index 17b7269b..69d9b84f 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -83,9 +83,10 @@ static ALboolean ALechoState_deviceUpdate(ALechoState *state, ALCdevice *Device) static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const ALeffectslot *Slot) { + ALfloat pandir[3] = { 0.0f, 0.0f, 0.0f }; ALuint frequency = Device->Frequency; - ALfloat lrpan, gain; - ALfloat dirGain; + ALfloat gain = Slot->Gain; + ALfloat lrpan; state->Tap[0].delay = fastf2u(Slot->EffectProps.Echo.Delay * frequency) + 1; state->Tap[1].delay = fastf2u(Slot->EffectProps.Echo.LRDelay * frequency); @@ -99,14 +100,13 @@ static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const AL 1.0f - Slot->EffectProps.Echo.Damping, LOWPASSFREQREF/frequency, 0.0f); - gain = Slot->Gain; - dirGain = fabsf(lrpan); - /* First tap panning */ - ComputeAngleGains(Device, atan2f(-lrpan, 0.0f), (1.0f-dirGain)*F_PI, gain, state->Gain[0]); + pandir[0] = -lrpan; + ComputeDirectionalGains(Device, pandir, gain, state->Gain[0]); /* Second tap panning */ - ComputeAngleGains(Device, atan2f(+lrpan, 0.0f), (1.0f-dirGain)*F_PI, gain, state->Gain[1]); + pandir[0] = +lrpan; + ComputeDirectionalGains(Device, pandir, gain, state->Gain[1]); } static ALvoid ALechoState_process(ALechoState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE]) diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c index 6395f4bf..a38b3b13 100644 --- a/Alc/effects/flanger.c +++ b/Alc/effects/flanger.c @@ -93,6 +93,8 @@ static ALboolean ALflangerState_deviceUpdate(ALflangerState *state, ALCdevice *D static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, const ALeffectslot *Slot) { + static const ALfloat left_dir[3] = { -1.0f, 0.0f, 0.0f }; + static const ALfloat right_dir[3] = { 1.0f, 0.0f, 0.0f }; ALfloat frequency = (ALfloat)Device->Frequency; ALfloat rate; ALint phase; @@ -111,8 +113,8 @@ static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, co state->delay = fastf2i(Slot->EffectProps.Flanger.Delay * frequency); /* Gains for left and right sides */ - ComputeAngleGains(Device, atan2f(-1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[0]); - ComputeAngleGains(Device, atan2f(+1.0f, 0.0f), 0.0f, Slot->Gain, state->Gain[1]); + ComputeDirectionalGains(Device, left_dir, Slot->Gain, state->Gain[0]); + ComputeDirectionalGains(Device, right_dir, Slot->Gain, state->Gain[1]); phase = Slot->EffectProps.Flanger.Phase; rate = Slot->EffectProps.Flanger.Rate; diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 1e9cd550..8c17076a 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -1031,44 +1031,54 @@ static ALvoid UpdateEchoLine(ALfloat reverbGain, ALfloat lateGain, ALfloat echoT // Update the early and late 3D panning gains. static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *ReflectionsPan, const ALfloat *LateReverbPan, ALfloat Gain, ALreverbState *State) { - ALfloat earlyPan[3] = { ReflectionsPan[0], ReflectionsPan[1], - ReflectionsPan[2] }; - ALfloat latePan[3] = { LateReverbPan[0], LateReverbPan[1], - LateReverbPan[2] }; + ALfloat earlyPan[3] = { ReflectionsPan[0], ReflectionsPan[1], ReflectionsPan[2] }; + ALfloat latePan[3] = { LateReverbPan[0], LateReverbPan[1], LateReverbPan[2] }; + ALfloat earlyLen = 0.0f; + ALfloat lateLen = 0.0f; + ALfloat length, invlen; ALfloat ambientGain; - ALfloat dirGain; - ALfloat length; + ALuint i; Gain *= ReverbBoost; - /* Attenuate reverb according to its coverage (dirGain=0 will give - * Gain*ambientGain, and dirGain=1 will give Gain). */ - ambientGain = minf(sqrtf(2.0f/Device->NumSpeakers), 1.0f); + /* Attenuate reverb according to its coverage (len=0 will give + * ambientGain, and len>=1 will be fully panned using Gain). */ + ambientGain = minf(sqrtf(2.0f/Device->NumSpeakers), 1.0f) * Gain; length = earlyPan[0]*earlyPan[0] + earlyPan[1]*earlyPan[1] + earlyPan[2]*earlyPan[2]; - if(length > 1.0f) + if(length > FLT_EPSILON) { - length = 1.0f / sqrtf(length); - earlyPan[0] *= length; - earlyPan[1] *= length; - earlyPan[2] *= length; + length = sqrtf(length); + + invlen = 1.0f / length; + earlyPan[0] *= invlen; + earlyPan[1] *= invlen; + earlyPan[2] *= invlen; + + earlyLen = minf(1.0f, length); + ComputeDirectionalGains(Device, earlyPan, Gain, State->Early.PanGain); } + length = latePan[0]*latePan[0] + latePan[1]*latePan[1] + latePan[2]*latePan[2]; - if(length > 1.0f) + if(length > FLT_EPSILON) { - length = 1.0f / sqrtf(length); - latePan[0] *= length; - latePan[1] *= length; - latePan[2] *= length; - } + length = sqrtf(length); - dirGain = sqrtf(earlyPan[0]*earlyPan[0] + earlyPan[2]*earlyPan[2]); - ComputeAngleGains(Device, atan2f(earlyPan[0], earlyPan[2]), (1.0f-dirGain)*F_PI, - lerp(ambientGain, 1.0f, dirGain) * Gain, State->Early.PanGain); + invlen = 1.0f / length; + latePan[0] *= invlen; + latePan[1] *= invlen; + latePan[2] *= invlen; - dirGain = sqrtf(latePan[0]*latePan[0] + latePan[2]*latePan[2]); - ComputeAngleGains(Device, atan2f(latePan[0], latePan[2]), (1.0f-dirGain)*F_PI, - lerp(ambientGain, 1.0f, dirGain) * Gain, State->Late.PanGain); + lateLen = minf(1.0f, length); + ComputeDirectionalGains(Device, latePan, Gain, State->Late.PanGain); + } + + for(i = 0;i < Device->NumSpeakers;i++) + { + enum Channel chan = Device->Speaker[i].ChanName; + State->Early.PanGain[chan] = lerp(ambientGain, State->Early.PanGain[chan], earlyLen); + State->Late.PanGain[chan] = lerp(ambientGain, State->Late.PanGain[chan], lateLen); + } } static ALvoid ALreverbState_update(ALreverbState *State, ALCdevice *Device, const ALeffectslot *Slot) |