diff options
-rw-r--r-- | Alc/mixer.c | 55 | ||||
-rw-r--r-- | OpenAL32/Include/alAuxEffectSlot.h | 2 | ||||
-rw-r--r-- | OpenAL32/alAuxEffectSlot.c | 2 |
3 files changed, 52 insertions, 7 deletions
diff --git a/Alc/mixer.c b/Alc/mixer.c index 8aa1a42b..99ecb9d1 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -87,11 +87,13 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, float (*DryBuffer)[OUTPUTCHANNELS], ALuint SamplesToDo) { static float DummyBuffer[BUFFERSIZE]; + static ALfloat DummyClickRemoval[OUTPUTCHANNELS]; ALfloat *WetBuffer[MAX_SENDS]; ALfloat DrySend[OUTPUTCHANNELS]; ALfloat dryGainDiff[OUTPUTCHANNELS]; ALfloat wetGainDiff[MAX_SENDS]; ALboolean UpdateClick; + ALfloat *WetClickRemoval[MAX_SENDS]; ALfloat *ClickRemoval; ALuint i, j, out; ALfloat value, outsamp; @@ -150,6 +152,9 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, WetBuffer[i] = (ALSource->Send[i].Slot ? ALSource->Send[i].Slot->WetBuffer : DummyBuffer); + WetClickRemoval[i] = (ALSource->Send[i].Slot ? + ALSource->Send[i].Slot->ClickRemoval : + DummyClickRemoval); } /* Get current buffer queue item */ @@ -234,6 +239,8 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, #define DO_MIX(resampler) do { \ if(j == 0 && UpdateClick) \ { \ + const ALboolean FirstStart = ALSource->FirstStart; \ + \ value = (resampler)(Data[DataPosInt], Data[DataPosInt+1], \ DataPosFrac); \ outsamp = lpFilter4PC(DryFilter, 0, value); \ @@ -245,7 +252,7 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, ClickRemoval[BACK_RIGHT] += outsamp*dryGainDiff[BACK_RIGHT]; \ ClickRemoval[FRONT_CENTER] += outsamp*dryGainDiff[FRONT_CENTER]; \ ClickRemoval[BACK_CENTER] += outsamp*dryGainDiff[BACK_CENTER]; \ - if(ALSource->FirstStart) \ + if(FirstStart) \ { \ ClickRemoval[FRONT_LEFT] += -outsamp*DrySend[FRONT_LEFT]; \ ClickRemoval[FRONT_RIGHT] += -outsamp*DrySend[FRONT_RIGHT]; \ @@ -256,6 +263,14 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, ClickRemoval[FRONT_CENTER] += -outsamp*DrySend[FRONT_CENTER]; \ ClickRemoval[BACK_CENTER] += -outsamp*DrySend[BACK_CENTER]; \ } \ + \ + for(out = 0;out < MAX_SENDS;out++) \ + { \ + outsamp = lpFilter2PC(WetFilter[out], 0, value); \ + WetClickRemoval[out][0] += outsamp*wetGainDiff[BACK_CENTER]; \ + if(FirstStart) \ + WetClickRemoval[out][0] += -outsamp*WetSend[out]; \ + } \ } \ while(BufferSize--) \ { \ @@ -312,8 +327,10 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, }; #define DO_MIX(resampler) do { \ - if(j == 0 && ALSource->FirstStart) \ + const ALfloat scaler = 1.0f/Channels; \ + if(j == 0 && UpdateClick) \ { \ + const ALboolean FirstStart = ALSource->FirstStart; \ for(i = 0;i < Channels;i++) \ { \ value = (resampler)(Data[DataPosInt*Channels + i], \ @@ -324,15 +341,22 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, ClickRemoval[chans[i]] += outsamp*dryGainDiff[chans[i]]; \ ClickRemoval[chans2[i*2+0]] += outsamp*dryGainDiff[chans2[i*2+0]];\ ClickRemoval[chans2[i*2+1]] += outsamp*dryGainDiff[chans2[i*2+1]];\ - if(ALSource->FirstStart) \ + if(FirstStart) \ { \ ClickRemoval[chans[i]] += -outsamp*DrySend[chans[i]]; \ ClickRemoval[chans2[i*2+0]] += -outsamp*DrySend[chans2[i*2+0]];\ ClickRemoval[chans2[i*2+1]] += -outsamp*DrySend[chans2[i*2+1]];\ } \ + \ + for(out = 0;out < MAX_SENDS;out++) \ + { \ + outsamp = lpFilter1PC(WetFilter[out], chans[out], value) * scaler;\ + WetClickRemoval[out][0] += outsamp*wetGainDiff[out]; \ + if(FirstStart) \ + WetClickRemoval[out][0] += -outsamp*WetSend[out]; \ + } \ } \ } \ - const ALfloat scaler = 1.0f/Channels; \ while(BufferSize--) \ { \ for(i = 0;i < Channels;i++) \ @@ -382,8 +406,10 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, }; #define DO_MIX(resampler) do { \ - if(j == 0 && ALSource->FirstStart) \ + const ALfloat scaler = 1.0f/Channels; \ + if(j == 0 && UpdateClick) \ { \ + const ALboolean FirstStart = ALSource->FirstStart; \ for(i = 0;i < Channels;i++) \ { \ value = (resampler)(Data[DataPosInt*Channels + i], \ @@ -392,11 +418,18 @@ static void MixSource(ALsource *ALSource, ALCcontext *ALContext, \ outsamp = lpFilter2PC(DryFilter, chans[i]*2, value); \ ClickRemoval[chans[i]] += outsamp*dryGainDiff[chans[i]]; \ - if(ALSource->FirstStart) \ + if(FirstStart) \ ClickRemoval[chans[i]] += -outsamp*DrySend[chans[i]]; \ + \ + for(out = 0;out < MAX_SENDS;out++) \ + { \ + outsamp = lpFilter1PC(WetFilter[out], chans[out], value) * scaler;\ + WetClickRemoval[out][0] += outsamp*wetGainDiff[out]; \ + if(FirstStart) \ + WetClickRemoval[out][0] += -outsamp*WetSend[out]; \ + } \ } \ } \ - const ALfloat scaler = 1.0f/Channels; \ while(BufferSize--) \ { \ for(i = 0;i < Channels;i++) \ @@ -609,6 +642,14 @@ ALvoid aluMixData(ALCdevice *device, ALvoid *buffer, ALsizei size) for(e = 0;e < ALContext->EffectSlotMap.size;e++) { ALEffectSlot = ALContext->EffectSlotMap.array[e].value; + + ClickRemoval = ALEffectSlot->ClickRemoval; + for(i = 0;i < SamplesToDo;i++) + { + ClickRemoval[0] -= ClickRemoval[0] / 256.0f; + ALEffectSlot->WetBuffer[i] += ClickRemoval[0]; + } + ALEffect_Process(ALEffectSlot->EffectState, ALEffectSlot, SamplesToDo, ALEffectSlot->WetBuffer, DryBuffer); for(i = 0;i < SamplesToDo;i++) diff --git a/OpenAL32/Include/alAuxEffectSlot.h b/OpenAL32/Include/alAuxEffectSlot.h index 9a916dd8..eb7351b2 100644 --- a/OpenAL32/Include/alAuxEffectSlot.h +++ b/OpenAL32/Include/alAuxEffectSlot.h @@ -22,6 +22,8 @@ typedef struct ALeffectslot ALfloat WetBuffer[BUFFERSIZE]; + ALfloat ClickRemoval[1]; + ALuint refcount; // Index to itself diff --git a/OpenAL32/alAuxEffectSlot.c b/OpenAL32/alAuxEffectSlot.c index e8a76d35..a7ea0e32 100644 --- a/OpenAL32/alAuxEffectSlot.c +++ b/OpenAL32/alAuxEffectSlot.c @@ -88,6 +88,8 @@ AL_API ALvoid AL_APIENTRY alGenAuxiliaryEffectSlots(ALsizei n, ALuint *effectslo slot->AuxSendAuto = AL_TRUE; for(j = 0;j < BUFFERSIZE;j++) slot->WetBuffer[j] = 0.0f; + for(j = 0;j < 1;j++) + slot->ClickRemoval[j] = 0.0f; slot->refcount = 0; } } |