diff options
-rw-r--r-- | Alc/effects/autowah.c | 17 | ||||
-rw-r--r-- | Alc/effects/chorus.c | 7 | ||||
-rw-r--r-- | Alc/effects/dedicated.c | 7 | ||||
-rw-r--r-- | Alc/effects/distortion.c | 14 | ||||
-rw-r--r-- | Alc/effects/echo.c | 7 | ||||
-rw-r--r-- | Alc/effects/equalizer.c | 9 | ||||
-rw-r--r-- | Alc/effects/flanger.c | 7 | ||||
-rw-r--r-- | Alc/effects/modulator.c | 12 | ||||
-rw-r--r-- | Alc/effects/reverb.c | 18 | ||||
-rw-r--r-- | Alc/panning.c | 12 | ||||
-rw-r--r-- | OpenAL32/Include/alu.h | 19 |
11 files changed, 40 insertions, 89 deletions
diff --git a/Alc/effects/autowah.c b/Alc/effects/autowah.c index cc207858..e0556cf3 100644 --- a/Alc/effects/autowah.c +++ b/Alc/effects/autowah.c @@ -80,16 +80,12 @@ static ALboolean ALautowahState_deviceUpdate(ALautowahState *state, ALCdevice *d static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *Device, const ALeffectslot *Slot)
{
- ALuint i;
- ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain;
-
- /* computing high-pass cutoff and bandwidth */
const ALfloat cutoff = LOWPASSFREQREF / (Device->Frequency * 4.0f);
const ALfloat bandwidth = (cutoff / 2.0f) / (cutoff * 0.67f);
+ ALfloat gain;
/* computing high-pass filter coefficients */
- ALfilterState_setParams(&state->high_pass,
- ALfilterType_HighPass, 1.0f,
+ ALfilterState_setParams(&state->high_pass, ALfilterType_HighPass, 1.0f,
cutoff, bandwidth);
state->AttackTime = Slot->EffectProps.Autowah.AttackTime;
@@ -102,13 +98,8 @@ static ALvoid ALautowahState_update(ALautowahState *state, ALCdevice *Device, co ALfilterState_clear(&state->low_pass);
- for(i = 0;i < MaxChannels;i++)
- state->Gain[i] = 0.0f;
- for(i = 0;i < Device->NumChan;i++)
- {
- enum Channel chan = Device->Speaker2Chan[i];
- state->Gain[chan] = gain;
- }
+ gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain;
+ SetGains(Device, gain, state->Gain);
}
static ALvoid ALautowahState_process(ALautowahState *state, ALuint SamplesToDo, const ALfloat *SamplesIn, ALfloat (*SamplesOut)[BUFFERSIZE])
diff --git a/Alc/effects/chorus.c b/Alc/effects/chorus.c index cec6f435..ba664268 100644 --- a/Alc/effects/chorus.c +++ b/Alc/effects/chorus.c @@ -103,13 +103,6 @@ static ALvoid ALchorusState_update(ALchorusState *state, ALCdevice *Device, cons ALfloat frequency = (ALfloat)Device->Frequency; ALfloat rate; ALint phase; - ALuint it; - - for (it = 0; it < MaxChannels; it++) - { - state->Gain[0][it] = 0.0f; - state->Gain[1][it] = 0.0f; - } state->waveform = Slot->EffectProps.Chorus.Waveform; state->depth = Slot->EffectProps.Chorus.Depth; diff --git a/Alc/effects/dedicated.c b/Alc/effects/dedicated.c index 8be7fee6..2aa08953 100644 --- a/Alc/effects/dedicated.c +++ b/Alc/effects/dedicated.c @@ -61,13 +61,14 @@ static ALvoid ALdedicatedState_update(ALdedicatedState *state, ALCdevice *device ALsizei s; Gain = Slot->Gain * Slot->EffectProps.Dedicated.Gain; - for(s = 0;s < MaxChannels;s++) - state->gains[s] = 0.0f; - 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; state->gains[LFE] = Gain; + } } static ALvoid ALdedicatedState_process(ALdedicatedState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE]) diff --git a/Alc/effects/distortion.c b/Alc/effects/distortion.c index dce0d64d..768d1ee2 100644 --- a/Alc/effects/distortion.c +++ b/Alc/effects/distortion.c @@ -64,20 +64,11 @@ static ALboolean ALdistortionState_deviceUpdate(ALdistortionState *state, ALCdev static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Device, const ALeffectslot *Slot) { - ALfloat gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain; ALfloat frequency = (ALfloat)Device->Frequency; - ALuint it; ALfloat bandwidth; ALfloat cutoff; ALfloat edge; - - for(it = 0;it < MaxChannels;it++) - state->Gain[it] = 0.0f; - for(it = 0;it < Device->NumChan;it++) - { - enum Channel chan = Device->Speaker2Chan[it]; - state->Gain[chan] = gain; - } + ALfloat gain; /* Store distorted signal attenuation settings */ state->attenuation = Slot->EffectProps.Distortion.Gain; @@ -100,6 +91,9 @@ static ALvoid ALdistortionState_update(ALdistortionState *state, ALCdevice *Devi bandwidth = Slot->EffectProps.Distortion.EQBandwidth / (cutoff * 0.67f); ALfilterState_setParams(&state->bandpass, ALfilterType_BandPass, 1.0f, cutoff / (frequency*4.0f), bandwidth); + + gain = sqrtf(1.0f / Device->NumChan) * Slot->Gain; + SetGains(Device, gain, state->Gain); } static ALvoid ALdistortionState_process(ALdistortionState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE]) diff --git a/Alc/effects/echo.c b/Alc/effects/echo.c index 6d6d70fb..8a457162 100644 --- a/Alc/effects/echo.c +++ b/Alc/effects/echo.c @@ -93,7 +93,6 @@ static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const AL ALuint frequency = Device->Frequency; ALfloat lrpan, gain; ALfloat dirGain; - ALuint i; state->Tap[0].delay = fastf2u(Slot->EffectProps.Echo.Delay * frequency) + 1; state->Tap[1].delay = fastf2u(Slot->EffectProps.Echo.LRDelay * frequency); @@ -108,12 +107,6 @@ static ALvoid ALechoState_update(ALechoState *state, ALCdevice *Device, const AL (ALfloat)LOWPASSFREQREF/frequency, 0.0f); gain = Slot->Gain; - for(i = 0;i < MaxChannels;i++) - { - state->Gain[0][i] = 0.0f; - state->Gain[1][i] = 0.0f; - } - dirGain = fabsf(lrpan); /* First tap panning */ diff --git a/Alc/effects/equalizer.c b/Alc/effects/equalizer.c index fd79462f..3fd0b0f7 100644 --- a/Alc/effects/equalizer.c +++ b/Alc/effects/equalizer.c @@ -104,15 +104,8 @@ static ALvoid ALequalizerState_update(ALequalizerState *state, ALCdevice *device { ALfloat frequency = (ALfloat)device->Frequency; ALfloat gain = sqrtf(1.0f / device->NumChan) * slot->Gain; - ALuint it; - for(it = 0;it < MaxChannels;it++) - state->Gain[it] = 0.0f; - for(it = 0; it < device->NumChan; it++) - { - enum Channel chan = device->Speaker2Chan[it]; - state->Gain[chan] = gain; - } + SetGains(device, gain, state->Gain); /* Calculate coefficients for the each type of filter */ ALfilterState_setParams(&state->filter[0], ALfilterType_LowShelf, diff --git a/Alc/effects/flanger.c b/Alc/effects/flanger.c index e9de888a..6b1a84ad 100644 --- a/Alc/effects/flanger.c +++ b/Alc/effects/flanger.c @@ -103,13 +103,6 @@ static ALvoid ALflangerState_update(ALflangerState *state, ALCdevice *Device, co ALfloat frequency = (ALfloat)Device->Frequency; ALfloat rate; ALint phase; - ALuint it; - - for(it = 0;it < MaxChannels;it++) - { - state->Gain[0][it] = 0.0f; - state->Gain[1][it] = 0.0f; - } state->waveform = Slot->EffectProps.Flanger.Waveform; state->depth = Slot->EffectProps.Flanger.Depth; diff --git a/Alc/effects/modulator.c b/Alc/effects/modulator.c index 356f0fd6..a77a42df 100644 --- a/Alc/effects/modulator.c +++ b/Alc/effects/modulator.c @@ -136,7 +136,6 @@ static ALboolean ALmodulatorState_deviceUpdate(ALmodulatorState *state, ALCdevic static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device, const ALeffectslot *Slot) { ALfloat gain, cw, a; - ALuint index; if(Slot->EffectProps.Modulator.Waveform == AL_RING_MODULATOR_SINUSOID) state->Waveform = SINUSOID; @@ -161,15 +160,8 @@ static ALvoid ALmodulatorState_update(ALmodulatorState *state, ALCdevice *Device state->Filter.a[1] = -a; state->Filter.a[2] = 0.0f; - gain = sqrtf(1.0f/Device->NumChan); - gain *= Slot->Gain; - for(index = 0;index < MaxChannels;index++) - state->Gain[index] = 0.0f; - for(index = 0;index < Device->NumChan;index++) - { - enum Channel chan = Device->Speaker2Chan[index]; - state->Gain[chan] = gain; - } + gain = sqrtf(1.0f/Device->NumChan) * Slot->Gain; + SetGains(Device, gain, state->Gain); } static ALvoid ALmodulatorState_process(ALmodulatorState *state, ALuint SamplesToDo, const ALfloat *restrict SamplesIn, ALfloat (*restrict SamplesOut)[BUFFERSIZE]) diff --git a/Alc/effects/reverb.c b/Alc/effects/reverb.c index 5758a09e..261a1f7f 100644 --- a/Alc/effects/reverb.c +++ b/Alc/effects/reverb.c @@ -1044,7 +1044,6 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection ALfloat ambientGain; ALfloat dirGain; ALfloat length; - ALuint index; Gain *= ReverbBoost; @@ -1070,14 +1069,10 @@ static ALvoid Update3DPanning(const ALCdevice *Device, const ALfloat *Reflection } dirGain = sqrtf(earlyPan[0]*earlyPan[0] + earlyPan[2]*earlyPan[2]); - for(index = 0;index < MaxChannels;index++) - State->Early.PanGain[index] = 0.0f; ComputeAngleGains(Device, atan2f(earlyPan[0], earlyPan[2]), (1.0f-dirGain)*F_PI, lerp(ambientGain, 1.0f, dirGain) * Gain, State->Early.PanGain); dirGain = sqrtf(latePan[0]*latePan[0] + latePan[2]*latePan[2]); - for(index = 0;index < MaxChannels;index++) - State->Late.PanGain[index] = 0.0f; ComputeAngleGains(Device, atan2f(latePan[0], latePan[2]), (1.0f-dirGain)*F_PI, lerp(ambientGain, 1.0f, dirGain) * Gain, State->Late.PanGain); } @@ -1168,18 +1163,9 @@ static ALvoid ALreverbState_update(ALreverbState *State, ALCdevice *Device, cons } else { - ALfloat gain = Slot->Gain; - ALuint index; - /* Update channel gains */ - gain *= sqrtf(2.0f/Device->NumChan) * ReverbBoost; - for(index = 0;index < MaxChannels;index++) - State->Gain[index] = 0.0f; - for(index = 0;index < Device->NumChan;index++) - { - enum Channel chan = Device->Speaker2Chan[index]; - State->Gain[chan] = gain; - } + ALfloat gain = sqrtf(2.0f/Device->NumChan) * ReverbBoost * Slot->Gain; + SetGains(Device, gain, State->Gain); } } diff --git a/Alc/panning.c b/Alc/panning.c index 02387336..188844e6 100644 --- a/Alc/panning.c +++ b/Alc/panning.c @@ -140,13 +140,7 @@ static void SetSpeakerArrangement(const char *name, ALfloat SpeakerAngle[MaxChan } -/** - * ComputeAngleGains - * - * Sets channel gains based on a given source's angle and its half-width. The - * angle and hwidth parameters are in radians. - */ -ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains) +void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat gains[MaxChannels]) { ALfloat tmpgains[MaxChannels] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }; enum Channel Speaker2Chan[MaxChannels]; @@ -164,6 +158,8 @@ ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, if(device->NumChan <= 1 || hwidth >= F_PI) { /* Full coverage for all speakers. */ + for(i = 0;i < MaxChannels;i++) + gains[i] = 0.0f; for(i = 0;i < device->NumChan;i++) { enum Channel chan = Speaker2Chan[i]; @@ -174,6 +170,8 @@ ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, if(hwidth <= 0.0f) { /* Infinitely small sound point. */ + for(i = 0;i < MaxChannels;i++) + gains[i] = 0.0f; for(i = 0;i < device->NumChan-1;i++) { if(angle >= SpeakerAngle[i] && angle < SpeakerAngle[i+1]) diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index b389ec1e..076abea6 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -105,7 +105,24 @@ static inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat va ALvoid aluInitPanning(ALCdevice *Device); -ALvoid ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat *gains); +/** + * ComputeAngleGains + * + * Sets channel gains based on a given source's angle and its half-width. The + * angle and hwidth parameters are in radians. + */ +void ComputeAngleGains(const ALCdevice *device, ALfloat angle, ALfloat hwidth, ALfloat ingain, ALfloat gains[MaxChannels]); + +/** + * SetGains + * + * Helper to set the appropriate channels to the specified gain. + */ +static inline void SetGains(const ALCdevice *device, ALfloat ingain, ALfloat gains[MaxChannels]) +{ + ComputeAngleGains(device, 0.0f, F_PI, ingain, gains); +} + ALvoid CalcSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext); ALvoid CalcNonAttnSourceParams(struct ALsource *ALSource, const ALCcontext *ALContext); |