From 8e04a8a0228aea5df0881f6b44d0fea61036d080 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 19 May 2014 02:24:31 -0700 Subject: [PATCH] Put per-channel filter properties together --- Alc/ALu.c | 40 ++++++++++++++++++++-------------------- Alc/mixer.c | 25 ++++++++++++++----------- OpenAL32/Include/alu.h | 20 ++++++++++++-------- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index 9102fbf1..dc9480c7 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -611,15 +611,15 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext) ALfloat lfscale = ALSource->Direct.LFReference / Frequency; for(c = 0;c < num_channels;c++) { - src->Direct.Filters[c] = (gainhf != 1.0f && gainlf != 1.0f) ? AF_BandPass : - (gainhf != 1.0f) ? AF_LowPass : - (gainlf != 1.0f) ? AF_HighPass : AF_None; + src->Direct.Filters[c].ActiveType = AF_None; + if(gainhf != 1.0f) src->Direct.Filters[c].ActiveType |= AF_LowPass; + if(gainlf != 1.0f) src->Direct.Filters[c].ActiveType |= AF_HighPass; ALfilterState_setParams( - &src->Direct.LpFilter[c], ALfilterType_HighShelf, gainhf, + &src->Direct.Filters[c].LowPass, ALfilterType_HighShelf, gainhf, hfscale, 0.0f ); ALfilterState_setParams( - &src->Direct.HpFilter[c], ALfilterType_LowShelf, gainlf, + &src->Direct.Filters[c].HighPass, ALfilterType_LowShelf, gainlf, lfscale, 0.0f ); } @@ -632,15 +632,15 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext) ALfloat lfscale = ALSource->Send[i].LFReference / Frequency; for(c = 0;c < num_channels;c++) { - src->Send[i].Filters[c] = (gainhf != 1.0f && gainlf != 1.0f) ? AF_BandPass : - (gainhf != 1.0f) ? AF_LowPass : - (gainlf != 1.0f) ? AF_HighPass : AF_None; + src->Send[i].Filters[c].ActiveType = AF_None; + if(gainhf != 1.0f) src->Send[i].Filters[c].ActiveType |= AF_LowPass; + if(gainlf != 1.0f) src->Send[i].Filters[c].ActiveType |= AF_HighPass; ALfilterState_setParams( - &src->Send[i].LpFilter[c], ALfilterType_HighShelf, gainhf, + &src->Send[i].Filters[c].LowPass, ALfilterType_HighShelf, gainhf, hfscale, 0.0f ); ALfilterState_setParams( - &src->Send[i].HpFilter[c], ALfilterType_LowShelf, gainlf, + &src->Send[i].Filters[c].HighPass, ALfilterType_LowShelf, gainlf, lfscale, 0.0f ); } @@ -1147,15 +1147,15 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext) ALfloat gainlf = maxf(0.01f, DryGainLF); ALfloat hfscale = ALSource->Direct.HFReference / Frequency; ALfloat lfscale = ALSource->Direct.LFReference / Frequency; - src->Direct.Filters[0] = (gainhf != 1.0f && gainlf != 1.0f) ? AF_BandPass : - (gainhf != 1.0f) ? AF_LowPass : - (gainlf != 1.0f) ? AF_HighPass : AF_None; + src->Direct.Filters[0].ActiveType = AF_None; + if(gainhf != 1.0f) src->Direct.Filters[0].ActiveType |= AF_LowPass; + if(gainlf != 1.0f) src->Direct.Filters[0].ActiveType |= AF_HighPass; ALfilterState_setParams( - &src->Direct.LpFilter[0], ALfilterType_HighShelf, gainhf, + &src->Direct.Filters[0].LowPass, ALfilterType_HighShelf, gainhf, hfscale, 0.0f ); ALfilterState_setParams( - &src->Direct.HpFilter[0], ALfilterType_LowShelf, gainlf, + &src->Direct.Filters[0].HighPass, ALfilterType_LowShelf, gainlf, lfscale, 0.0f ); } @@ -1165,15 +1165,15 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext) ALfloat gainlf = maxf(0.01f, WetGainLF[i]); ALfloat hfscale = ALSource->Send[i].HFReference / Frequency; ALfloat lfscale = ALSource->Send[i].LFReference / Frequency; - src->Direct.Filters[0] = (gainhf != 1.0f && gainlf != 1.0f) ? AF_BandPass : - (gainhf != 1.0f) ? AF_LowPass : - (gainlf != 1.0f) ? AF_HighPass : AF_None; + src->Send[i].Filters[0].ActiveType = AF_None; + if(gainhf != 1.0f) src->Send[i].Filters[0].ActiveType |= AF_LowPass; + if(gainlf != 1.0f) src->Send[i].Filters[0].ActiveType |= AF_HighPass; ALfilterState_setParams( - &src->Send[i].LpFilter[0], ALfilterType_HighShelf, gainhf, + &src->Send[i].Filters[0].LowPass, ALfilterType_HighShelf, gainhf, hfscale, 0.0f ); ALfilterState_setParams( - &src->Send[i].HpFilter[0], ALfilterType_LowShelf, gainlf, + &src->Send[i].Filters[0].HighPass, ALfilterType_LowShelf, gainlf, lfscale, 0.0f ); } diff --git a/Alc/mixer.c b/Alc/mixer.c index 04efcf44..86a0eef6 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -348,19 +348,21 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) DirectParams *parms = &src->Direct; const ALfloat *samples; - samples = DoFilters(&parms->LpFilter[chan], &parms->HpFilter[chan], - SrcData, ResampledData, DstBufferSize, - parms->Filters[chan]); + samples = DoFilters( + &parms->Filters[chan].LowPass, &parms->Filters[chan].HighPass, + SrcData, ResampledData, DstBufferSize, parms->Filters[chan].ActiveType + ); if(!src->IsHrtf) src->Dry.Mix(parms->OutBuffer, samples, &parms->Mix.Gains[chan], maxu(parms->Counter, OutPos) - OutPos, OutPos, DstBufferSize); else - src->Dry.HrtfMix(parms->OutBuffer, SrcData, - maxu(parms->Counter, OutPos) - OutPos, - parms->Offset + OutPos, OutPos, - parms->Mix.Hrtf.IrSize, &parms->Mix.Hrtf.Params[chan], - &parms->Mix.Hrtf.State[chan], DstBufferSize); + src->Dry.HrtfMix( + parms->OutBuffer, SrcData, maxu(parms->Counter, OutPos) - OutPos, + parms->Offset + OutPos, OutPos, parms->Mix.Hrtf.IrSize, + &parms->Mix.Hrtf.Params[chan], &parms->Mix.Hrtf.State[chan], + DstBufferSize + ); } for(j = 0;j < Device->NumAuxSends;j++) @@ -371,9 +373,10 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) if(!parms->OutBuffer) continue; - samples = DoFilters(&parms->LpFilter[chan], &parms->HpFilter[chan], - SrcData, ResampledData, DstBufferSize, - parms->Filters[chan]); + samples = DoFilters( + &parms->Filters[chan].LowPass, &parms->Filters[chan].HighPass, + SrcData, ResampledData, DstBufferSize, parms->Filters[chan].ActiveType + ); src->WetMix(parms->OutBuffer, samples, &parms->Gain, maxu(parms->Counter, OutPos) - OutPos, OutPos, DstBufferSize); diff --git a/OpenAL32/Include/alu.h b/OpenAL32/Include/alu.h index 254b15e3..7fdb75cc 100644 --- a/OpenAL32/Include/alu.h +++ b/OpenAL32/Include/alu.h @@ -76,10 +76,6 @@ typedef struct MixGainMono { typedef struct DirectParams { ALfloat (*OutBuffer)[BUFFERSIZE]; - enum ActiveFilters Filters[MAX_INPUT_CHANNELS]; - ALfilterState LpFilter[MAX_INPUT_CHANNELS]; - ALfilterState HpFilter[MAX_INPUT_CHANNELS]; - /* If not 'moving', gain/coefficients are set directly without fading. */ ALboolean Moving; /* Stepping counter for gain/coefficient fading. */ @@ -87,6 +83,12 @@ typedef struct DirectParams { /* History/coefficient offset. */ ALuint Offset; + struct { + enum ActiveFilters ActiveType; + ALfilterState LowPass; + ALfilterState HighPass; + } Filters[MAX_INPUT_CHANNELS]; + union { struct { HrtfParams Params[MAX_INPUT_CHANNELS]; @@ -103,13 +105,15 @@ typedef struct DirectParams { typedef struct SendParams { ALfloat (*OutBuffer)[BUFFERSIZE]; - enum ActiveFilters Filters[MAX_INPUT_CHANNELS]; - ALfilterState LpFilter[MAX_INPUT_CHANNELS]; - ALfilterState HpFilter[MAX_INPUT_CHANNELS]; - ALboolean Moving; ALuint Counter; + struct { + enum ActiveFilters ActiveType; + ALfilterState LowPass; + ALfilterState HighPass; + } Filters[MAX_INPUT_CHANNELS]; + /* Gain control, which applies to all input channels to a single (mono) * output buffer. */ MixGainMono Gain;