From c7e49c9f5735df52d4e847529ae9cb23027547e7 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 25 Jul 2008 19:31:12 -0700 Subject: Implement yet another low-pass filter This one using the Butterworth IIR filter design --- Alc/ALu.c | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'Alc/ALu.c') diff --git a/Alc/ALu.c b/Alc/ALu.c index 43837123..ea0f0dcb 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -596,8 +596,6 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma ALfloat Pitch; ALint Looping,State; ALint fraction,increment; - ALint LowFrac; - ALuint LowStep; ALuint Buffer; ALuint SamplesToDo; ALsource *ALSource; @@ -609,6 +607,7 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma ALbufferlistitem *BufferListItem; ALuint loop; ALint64 DataSize64,DataPos64; + FILTER *Filter; SuspendContext(ALContext); @@ -667,6 +666,7 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma //Get source info DataPosInt = ALSource->position; DataPosFrac = ALSource->position_fraction; + Filter = &ALSource->iirFilter; //Compute 18.14 fixed point step increment = (ALint)(Pitch*(ALfloat)(1L<queue; for(loop = 0; loop < ALSource->BuffersPlayed; loop++) @@ -718,16 +716,14 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma { k = DataPosFrac>>FRACTIONBITS; fraction = DataPosFrac&FRACTIONMASK; - LowFrac = ((DataPosFrac+(DataPosInt<> FRACTIONBITS; - lowsamp = (Data[((k+DataPosInt)/LowStep )*LowStep - DataPosInt]*((1<> - FRACTIONBITS; + lowsamp = lpFilter(Filter, sample); //Direct path final mix buffer and panning outsamp = aluComputeSample(DryGainHF, sample, lowsamp); @@ -915,9 +911,9 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma ALfloat Gain = ALEffectSlot->effect.Reverb.Gain; ALfloat ReflectGain = ALEffectSlot->effect.Reverb.ReflectionsGain; ALfloat LateReverbGain = ALEffectSlot->effect.Reverb.LateReverbGain; - ALfloat LastDecaySample = ALEffectSlot->LastDecaySample; - ALfloat sample; + ALfloat sample, lowsample; + Filter = &ALEffectSlot->iirFilter; for(i = 0;i < SamplesToDo;i++) { DelayBuffer[Pos] = ReverbBuffer[i] * Gain; @@ -927,12 +923,10 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma DelayBuffer[LatePos] *= LateReverbGain; Pos = (Pos+1) % Length; - DelayBuffer[Pos] *= DecayHFRatio; - DelayBuffer[Pos] += LastDecaySample * (1.0f-DecayHFRatio); - LastDecaySample = DelayBuffer[Pos]; - DelayBuffer[Pos] *= DecayGain; + lowsample = lpFilter(Filter, DelayBuffer[Pos]); + lowsample += (DelayBuffer[Pos]-lowsample) * DecayHFRatio; - DelayBuffer[LatePos] += DelayBuffer[Pos]; + DelayBuffer[LatePos] += lowsample * DecayGain; sample += DelayBuffer[LatePos]; @@ -950,7 +944,6 @@ ALvoid aluMixData(ALCcontext *ALContext,ALvoid *buffer,ALsizei size,ALenum forma ALEffectSlot->ReverbPos = Pos; ALEffectSlot->ReverbLatePos = LatePos; ALEffectSlot->ReverbReflectPos = ReflectPos; - ALEffectSlot->LastDecaySample = LastDecaySample; } ALEffectSlot = ALEffectSlot->next; -- cgit v1.2.3