From 57c683f822c11b89806c3d59bdcf6f29c0c65f91 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 13 Jun 2014 16:07:25 -0700 Subject: Get the mixer and resampler functions when needed --- Alc/ALu.c | 65 ---------------------------------- Alc/mixer.c | 85 ++++++++++++++++++++++++++++++++++++++------- OpenAL32/Include/alSource.h | 5 +-- 3 files changed, 74 insertions(+), 81 deletions(-) diff --git a/Alc/ALu.c b/Alc/ALu.c index 0b5c2998..f28e6e6d 100644 --- a/Alc/ALu.c +++ b/Alc/ALu.c @@ -36,8 +36,6 @@ #include "hrtf.h" #include "static_assert.h" -#include "mixer_defs.h" - #include "midi/base.h" @@ -82,63 +80,6 @@ extern inline ALuint64 clampu64(ALuint64 val, ALuint64 min, ALuint64 max); extern inline ALfloat lerp(ALfloat val1, ALfloat val2, ALfloat mu); extern inline ALfloat cubic(ALfloat val0, ALfloat val1, ALfloat val2, ALfloat val3, ALfloat mu); -static ResamplerFunc SelectResampler(enum Resampler Resampler, ALuint increment) -{ - if(increment == FRACTIONONE) - return Resample_copy32_C; - switch(Resampler) - { - case PointResampler: - return Resample_point32_C; - case LinearResampler: -#ifdef HAVE_SSE4_1 - if((CPUCapFlags&CPU_CAP_SSE4_1)) - return Resample_lerp32_SSE41; -#endif -#ifdef HAVE_SSE2 - if((CPUCapFlags&CPU_CAP_SSE2)) - return Resample_lerp32_SSE2; -#endif - return Resample_lerp32_C; - case CubicResampler: - return Resample_cubic32_C; - case ResamplerMax: - /* Shouldn't happen */ - break; - } - - return Resample_point32_C; -} - - -static HrtfMixerFunc SelectHrtfMixer(void) -{ -#ifdef HAVE_SSE - if((CPUCapFlags&CPU_CAP_SSE)) - return MixHrtf_SSE; -#endif -#ifdef HAVE_NEON - if((CPUCapFlags&CPU_CAP_NEON)) - return MixHrtf_Neon; -#endif - - return MixHrtf_C; -} - -static MixerFunc SelectMixer(void) -{ -#ifdef HAVE_SSE - if((CPUCapFlags&CPU_CAP_SSE)) - return Mix_SSE; -#endif -#ifdef HAVE_NEON - if((CPUCapFlags&CPU_CAP_NEON)) - return Mix_Neon; -#endif - - return Mix_C; -} - static inline void aluCrossproduct(const ALfloat *inVector1, const ALfloat *inVector2, ALfloat *outVector) { @@ -336,7 +277,6 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext) if(src->Step == 0) src->Step = 1; } - src->Resample = SelectResampler(Resampler, src->Step); Channels = ALBuffer->FmtChannels; break; @@ -581,8 +521,6 @@ ALvoid CalcNonAttnSourceParams(ALactivesource *src, const ALCcontext *ALContext) src->Send[i].Counter = 64; } } - src->Mix = SelectMixer(); - src->HrtfMix = SelectHrtfMixer(); { ALfloat gainhf = maxf(0.01f, DryGainHF); @@ -955,7 +893,6 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext) if(src->Step == 0) src->Step = 1; } - src->Resample = SelectResampler(Resampler, src->Step); break; } @@ -1106,8 +1043,6 @@ ALvoid CalcSourceParams(ALactivesource *src, const ALCcontext *ALContext) src->Send[i].Counter = 64; } } - src->Mix = SelectMixer(); - src->HrtfMix = SelectHrtfMixer(); { ALfloat gainhf = maxf(0.01f, DryGainHF); diff --git a/Alc/mixer.c b/Alc/mixer.c index 1ecc8d88..a1502488 100644 --- a/Alc/mixer.c +++ b/Alc/mixer.c @@ -34,12 +34,70 @@ #include "alListener.h" #include "alAuxEffectSlot.h" #include "alu.h" -#include "bs2b.h" + +#include "mixer_defs.h" extern inline void InitiatePositionArrays(ALuint frac, ALuint increment, ALuint *frac_arr, ALuint *pos_arr, ALuint size); +static inline HrtfMixerFunc SelectHrtfMixer(void) +{ +#ifdef HAVE_SSE + if((CPUCapFlags&CPU_CAP_SSE)) + return MixHrtf_SSE; +#endif +#ifdef HAVE_NEON + if((CPUCapFlags&CPU_CAP_NEON)) + return MixHrtf_Neon; +#endif + + return MixHrtf_C; +} + +static inline MixerFunc SelectMixer(void) +{ +#ifdef HAVE_SSE + if((CPUCapFlags&CPU_CAP_SSE)) + return Mix_SSE; +#endif +#ifdef HAVE_NEON + if((CPUCapFlags&CPU_CAP_NEON)) + return Mix_Neon; +#endif + + return Mix_C; +} + +static inline ResamplerFunc SelectResampler(enum Resampler Resampler, ALuint increment) +{ + if(increment == FRACTIONONE) + return Resample_copy32_C; + switch(Resampler) + { + case PointResampler: + return Resample_point32_C; + case LinearResampler: +#ifdef HAVE_SSE4_1 + if((CPUCapFlags&CPU_CAP_SSE4_1)) + return Resample_lerp32_SSE41; +#endif +#ifdef HAVE_SSE2 + if((CPUCapFlags&CPU_CAP_SSE2)) + return Resample_lerp32_SSE2; +#endif + return Resample_lerp32_C; + case CubicResampler: + return Resample_cubic32_C; + case ResamplerMax: + /* Shouldn't happen */ + break; + } + + return Resample_point32_C; +} + + static inline ALfloat Sample_ALbyte(ALbyte val) { return val * (1.0f/127.0f); } @@ -122,6 +180,9 @@ static const ALfloat *DoFilters(ALfilterState *lpfilter, ALfilterState *hpfilter ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) { + MixerFunc Mix; + HrtfMixerFunc HrtfMix; + ResamplerFunc Resample; ALsource *Source = src->Source; ALbufferlistitem *BufferListItem; ALuint DataPosInt, DataPosFrac; @@ -146,7 +207,9 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) NumChannels = Source->NumChannels; SampleSize = Source->SampleSize; - /* Get current buffer queue item */ + Mix = SelectMixer(); + HrtfMix = SelectHrtfMixer(); + Resample = SelectResampler(Resampler, increment); OutPos = 0; do { @@ -344,7 +407,7 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) } /* Now resample, then filter and mix to the appropriate outputs. */ - ResampledData = src->Resample( + ResampledData = Resample( &SrcData[BufferPrePadding], DataPosFrac, increment, Device->ResampledData, DstBufferSize ); @@ -358,14 +421,12 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) parms->Filters[chan].ActiveType ); if(!src->IsHrtf) - src->Mix(samples, MaxChannels, parms->OutBuffer, parms->Mix.Gains[chan], - parms->Counter, OutPos, DstBufferSize); + Mix(samples, MaxChannels, parms->OutBuffer, parms->Mix.Gains[chan], + parms->Counter, OutPos, DstBufferSize); else - src->HrtfMix( - parms->OutBuffer, samples, parms->Counter, src->Offset, - OutPos, parms->Mix.Hrtf.IrSize, &parms->Mix.Hrtf.Params[chan], - &parms->Mix.Hrtf.State[chan], DstBufferSize - ); + HrtfMix(parms->OutBuffer, samples, parms->Counter, src->Offset, + OutPos, parms->Mix.Hrtf.IrSize, &parms->Mix.Hrtf.Params[chan], + &parms->Mix.Hrtf.State[chan], DstBufferSize); } for(j = 0;j < Device->NumAuxSends;j++) @@ -381,8 +442,8 @@ ALvoid MixSource(ALactivesource *src, ALCdevice *Device, ALuint SamplesToDo) Device->FilteredData, ResampledData, DstBufferSize, parms->Filters[chan].ActiveType ); - src->Mix(samples, 1, parms->OutBuffer, &parms->Gain, - parms->Counter, OutPos, DstBufferSize); + Mix(samples, 1, parms->OutBuffer, &parms->Gain, + parms->Counter, OutPos, DstBufferSize); } } /* Update positions */ diff --git a/OpenAL32/Include/alSource.h b/OpenAL32/Include/alSource.h index f75a670b..6c6485ae 100644 --- a/OpenAL32/Include/alSource.h +++ b/OpenAL32/Include/alSource.h @@ -31,12 +31,9 @@ typedef struct ALactivesource { ALvoid (*Update)(struct ALactivesource *self, const ALCcontext *context); /** Current target parameters used for mixing. */ - ResamplerFunc Resample; - MixerFunc Mix; - HrtfMixerFunc HrtfMix; + ALint Step; ALboolean IsHrtf; - ALint Step; ALuint Offset; /* Number of output samples mixed since starting. */ -- cgit v1.2.3