diff options
author | Chris Robinson <[email protected]> | 2019-01-23 11:11:41 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-01-23 11:11:41 -0800 |
commit | 23179d0bcdd27d2b5ab5ddf0e38b180e2d6969e6 (patch) | |
tree | f42d1323eada3d1f2a1f9c053eba6d6784a0a1ee /Alc | |
parent | e332ac852892327d913ce8adfbb85bf30c8ccd24 (diff) |
Use a template declaration for the resampler functions
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/converter.cpp | 2 | ||||
-rw-r--r-- | Alc/mixer/defs.h | 47 | ||||
-rw-r--r-- | Alc/mixer/mixer_c.cpp | 49 | ||||
-rw-r--r-- | Alc/mixer/mixer_neon.cpp | 19 | ||||
-rw-r--r-- | Alc/mixer/mixer_sse.cpp | 6 | ||||
-rw-r--r-- | Alc/mixer/mixer_sse2.cpp | 13 | ||||
-rw-r--r-- | Alc/mixer/mixer_sse41.cpp | 13 | ||||
-rw-r--r-- | Alc/mixvoice.cpp | 22 |
8 files changed, 82 insertions, 89 deletions
diff --git a/Alc/converter.cpp b/Alc/converter.cpp index 3caa2fed..9ec97e23 100644 --- a/Alc/converter.cpp +++ b/Alc/converter.cpp @@ -157,7 +157,7 @@ SampleConverterPtr CreateSampleConverter(DevFmtType srcType, DevFmtType dstType, mind(static_cast<ALdouble>(srcRate)/dstRate*FRACTIONONE + 0.5, MAX_PITCH*FRACTIONONE)); converter->mIncrement = maxi(step, 1); if(converter->mIncrement == FRACTIONONE) - converter->mResample = Resample_copy_C; + converter->mResample = Resample_<CopyTag,CTag>; else { if(resampler == BSinc24Resampler) diff --git a/Alc/mixer/defs.h b/Alc/mixer/defs.h index 649e6d44..4b1e0303 100644 --- a/Alc/mixer/defs.h +++ b/Alc/mixer/defs.h @@ -12,12 +12,22 @@ struct MixHrtfParams; struct HrtfState; struct DirectHrtfState; -/* C resamplers */ -const ALfloat *Resample_copy_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); -const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); -const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); -const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); -const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); + +struct CTag { }; +struct SSETag { }; +struct SSE2Tag { }; +struct SSE3Tag { }; +struct SSE4Tag { }; +struct NEONTag { }; + +struct CopyTag { }; +struct PointTag { }; +struct LerpTag { }; +struct CubicTag { }; +struct BSincTag { }; + +template<typename TypeTag, typename InstTag> +const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen); /* C mixers */ @@ -58,14 +68,12 @@ void Mix_SSE(const ALfloat *data, const ALsizei OutChans, ALfloat (*OutBuffer)[B void MixRow_SSE(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*data)[BUFFERSIZE], const ALsizei InChans, const ALsizei InPos, const ALsizei BufferSize); -/* SSE resamplers */ +/* Vectorized resampler helpers */ inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTRICT frac_arr, ALsizei *RESTRICT pos_arr, ALsizei size) { - ALsizei i; - pos_arr[0] = 0; frac_arr[0] = frac; - for(i = 1;i < size;i++) + for(ALsizei i{1};i < size;i++) { ALint frac_tmp = frac_arr[i-1] + increment; pos_arr[i] = pos_arr[i-1] + (frac_tmp>>FRACTIONBITS); @@ -73,17 +81,6 @@ inline void InitiatePositionArrays(ALsizei frac, ALint increment, ALsizei *RESTR } } -const ALfloat *Resample_lerp_SSE2(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples); -const ALfloat *Resample_lerp_SSE41(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples); - -const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei dstlen); - /* Neon mixers */ void MixHrtf_Neon(ALfloat *RESTRICT LeftOut, ALfloat *RESTRICT RightOut, const ALfloat *data, ALsizei Offset, const ALsizei OutPos, @@ -103,12 +100,4 @@ void Mix_Neon(const ALfloat *data, const ALsizei OutChans, ALfloat (*OutBuffer)[ void MixRow_Neon(ALfloat *OutBuffer, const ALfloat *Gains, const ALfloat (*data)[BUFFERSIZE], const ALsizei InChans, const ALsizei InPos, const ALsizei BufferSize); -/* Neon resamplers */ -const ALfloat *Resample_lerp_Neon(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples); -const ALfloat *Resample_bsinc_Neon(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei dstlen); - #endif /* MIXER_DEFS_H */ diff --git a/Alc/mixer/mixer_c.cpp b/Alc/mixer/mixer_c.cpp index 0d8b1d5f..5f9f45a2 100644 --- a/Alc/mixer/mixer_c.cpp +++ b/Alc/mixer/mixer_c.cpp @@ -39,17 +39,18 @@ static inline ALfloat do_bsinc(const InterpState &istate, const ALfloat *RESTRIC return r; } -const ALfloat *Resample_copy_C(const InterpState* UNUSED(state), - const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment), - ALfloat *RESTRICT dst, ALsizei numsamples) +template<> +const ALfloat *Resample_<CopyTag,CTag>(const InterpState* UNUSED(state), + const ALfloat *RESTRICT src, ALsizei UNUSED(frac), ALint UNUSED(increment), + ALfloat *RESTRICT dst, ALsizei dstlen) { - ASSUME(numsamples > 0); + ASSUME(dstlen > 0); #if defined(HAVE_SSE) || defined(HAVE_NEON) /* Avoid copying the source data if it's aligned like the destination. */ if((reinterpret_cast<intptr_t>(src)&15) == (reinterpret_cast<intptr_t>(dst)&15)) return src; #endif - std::copy_n(src, numsamples, dst); + std::copy_n(src, dstlen, dst); return dst; } @@ -78,25 +79,25 @@ static const ALfloat *DoResample(const InterpState *state, const ALfloat *RESTRI return dst; } -const ALfloat *Resample_point_C(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples) -{ return DoResample<do_point>(state, src, frac, increment, dst, numsamples); } - -const ALfloat *Resample_lerp_C(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples) -{ return DoResample<do_lerp>(state, src, frac, increment, dst, numsamples); } - -const ALfloat *Resample_cubic_C(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples) -{ return DoResample<do_cubic>(state, src-1, frac, increment, dst, numsamples); } - -const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei numsamples) -{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, numsamples); } +template<> +const ALfloat *Resample_<PointTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) +{ return DoResample<do_point>(state, src, frac, increment, dst, dstlen); } + +template<> +const ALfloat *Resample_<LerpTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) +{ return DoResample<do_lerp>(state, src, frac, increment, dst, dstlen); } + +template<> +const ALfloat *Resample_<CubicTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) +{ return DoResample<do_cubic>(state, src-1, frac, increment, dst, dstlen); } + +template<> +const ALfloat *Resample_<BSincTag,CTag>(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) +{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst, dstlen); } static inline void ApplyCoeffs(ALsizei Offset, ALfloat (&Values)[HRIR_LENGTH][2], diff --git a/Alc/mixer/mixer_neon.cpp b/Alc/mixer/mixer_neon.cpp index 8d70d979..d9eac59c 100644 --- a/Alc/mixer/mixer_neon.cpp +++ b/Alc/mixer/mixer_neon.cpp @@ -12,9 +12,10 @@ #include "defs.h" -const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state), +template<> +const ALfloat *Resample_<LerpTag,NEONTag>(const InterpState* UNUSED(state), const ALfloat *RESTRICT src, ALsizei frac, ALint increment, - ALfloat *RESTRICT dst, ALsizei numsamples) + ALfloat *RESTRICT dst, ALsizei dstlen) { const int32x4_t increment4 = vdupq_n_s32(increment*4); const float32x4_t fracOne4 = vdupq_n_f32(1.0f/FRACTIONONE); @@ -23,15 +24,15 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state), int32x4_t pos4, frac4; ALsizei todo, pos, i; - ASSUME(numsamples > 0); - ASSUME(increment > 0); ASSUME(frac >= 0); + ASSUME(increment > 0); + ASSUME(dstlen > 0); InitiatePositionArrays(frac, increment, frac_, pos_, 4); frac4 = vld1q_s32(frac_); pos4 = vld1q_s32(pos_); - todo = numsamples & ~3; + todo = dstlen & ~3; for(i = 0;i < todo;i += 4) { const int pos0 = vgetq_lane_s32(pos4, 0); @@ -59,7 +60,7 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state), pos = vgetq_lane_s32(pos4, 0); frac = vgetq_lane_s32(frac4, 0); - for(;i < numsamples;++i) + for(;i < dstlen;++i) { dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); @@ -70,9 +71,9 @@ const ALfloat *Resample_lerp_Neon(const InterpState* UNUSED(state), return dst; } -const ALfloat *Resample_bsinc_Neon(const InterpState *state, - const ALfloat *RESTRICT src, ALsizei frac, ALint increment, - ALfloat *RESTRICT dst, ALsizei dstlen) +template<> +const ALfloat *Resample_<BSincTag,NEONTag>(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) { const ALfloat *const filter = state->bsinc.filter; const float32x4_t sf4 = vdupq_n_f32(state->bsinc.sf); diff --git a/Alc/mixer/mixer_sse.cpp b/Alc/mixer/mixer_sse.cpp index d18af086..ec0fbfc5 100644 --- a/Alc/mixer/mixer_sse.cpp +++ b/Alc/mixer/mixer_sse.cpp @@ -14,9 +14,9 @@ #include "defs.h" -const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *RESTRICT src, - ALsizei frac, ALint increment, ALfloat *RESTRICT dst, - ALsizei dstlen) +template<> +const ALfloat *Resample_<BSincTag,SSETag>(const InterpState *state, const ALfloat *RESTRICT src, + ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen) { const ALfloat *const filter{state->bsinc.filter}; const __m128 sf4{_mm_set1_ps(state->bsinc.sf)}; diff --git a/Alc/mixer/mixer_sse2.cpp b/Alc/mixer/mixer_sse2.cpp index 6408c8f9..2b594d90 100644 --- a/Alc/mixer/mixer_sse2.cpp +++ b/Alc/mixer/mixer_sse2.cpp @@ -27,24 +27,25 @@ #include "defs.h" -const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state), +template<> +const ALfloat *Resample_<LerpTag,SSE2Tag>(const InterpState* UNUSED(state), const ALfloat *RESTRICT src, ALsizei frac, ALint increment, - ALfloat *RESTRICT dst, ALsizei numsamples) + ALfloat *RESTRICT dst, ALsizei dstlen) { const __m128i increment4{_mm_set1_epi32(increment*4)}; const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)}; const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)}; - ASSUME(numsamples > 0); + ASSUME(frac > 0); ASSUME(increment > 0); - ASSUME(frac >= 0); + ASSUME(dstlen >= 0); alignas(16) ALsizei pos_[4], frac_[4]; InitiatePositionArrays(frac, increment, frac_, pos_, 4); __m128i frac4{_mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3])}; __m128i pos4{_mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3])}; - const ALsizei todo{numsamples & ~3}; + const ALsizei todo{dstlen & ~3}; for(ALsizei i{0};i < todo;i += 4) { const int pos0{_mm_cvtsi128_si32(_mm_shuffle_epi32(pos4, _MM_SHUFFLE(0, 0, 0, 0)))}; @@ -72,7 +73,7 @@ const ALfloat *Resample_lerp_SSE2(const InterpState* UNUSED(state), ALsizei pos{_mm_cvtsi128_si32(pos4)}; frac = _mm_cvtsi128_si32(frac4); - for(ALsizei i{todo};i < numsamples;++i) + for(ALsizei i{todo};i < dstlen;++i) { dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); diff --git a/Alc/mixer/mixer_sse41.cpp b/Alc/mixer/mixer_sse41.cpp index fea03764..55639f11 100644 --- a/Alc/mixer/mixer_sse41.cpp +++ b/Alc/mixer/mixer_sse41.cpp @@ -28,24 +28,25 @@ #include "defs.h" -const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state), +template<> +const ALfloat *Resample_<LerpTag,SSE4Tag>(const InterpState* UNUSED(state), const ALfloat *RESTRICT src, ALsizei frac, ALint increment, - ALfloat *RESTRICT dst, ALsizei numsamples) + ALfloat *RESTRICT dst, ALsizei dstlen) { const __m128i increment4{_mm_set1_epi32(increment*4)}; const __m128 fracOne4{_mm_set1_ps(1.0f/FRACTIONONE)}; const __m128i fracMask4{_mm_set1_epi32(FRACTIONMASK)}; - ASSUME(numsamples > 0); + ASSUME(frac > 0); ASSUME(increment > 0); - ASSUME(frac >= 0); + ASSUME(dstlen >= 0); alignas(16) ALsizei pos_[4], frac_[4]; InitiatePositionArrays(frac, increment, frac_, pos_, 4); __m128i frac4{_mm_setr_epi32(frac_[0], frac_[1], frac_[2], frac_[3])}; __m128i pos4{_mm_setr_epi32(pos_[0], pos_[1], pos_[2], pos_[3])}; - const ALsizei todo{numsamples & ~3}; + const ALsizei todo{dstlen & ~3}; for(ALsizei i{0};i < todo;i += 4) { const int pos0{_mm_extract_epi32(pos4, 0)}; @@ -73,7 +74,7 @@ const ALfloat *Resample_lerp_SSE41(const InterpState* UNUSED(state), ALsizei pos{_mm_cvtsi128_si32(pos4)}; frac = _mm_cvtsi128_si32(frac4); - for(ALsizei i{todo};i < numsamples;++i) + for(ALsizei i{todo};i < dstlen;++i) { dst[i] = lerp(src[pos], src[pos+1], frac * (1.0f/FRACTIONONE)); diff --git a/Alc/mixvoice.cpp b/Alc/mixvoice.cpp index b23b8d2e..fd379cd0 100644 --- a/Alc/mixvoice.cpp +++ b/Alc/mixvoice.cpp @@ -118,37 +118,37 @@ ResamplerFunc SelectResampler(Resampler resampler) switch(resampler) { case PointResampler: - return Resample_point_C; + return Resample_<PointTag,CTag>; case LinearResampler: #ifdef HAVE_NEON if((CPUCapFlags&CPU_CAP_NEON)) - return Resample_lerp_Neon; + return Resample_<LerpTag,NEONTag>; #endif #ifdef HAVE_SSE4_1 if((CPUCapFlags&CPU_CAP_SSE4_1)) - return Resample_lerp_SSE41; + return Resample_<LerpTag,SSE4Tag>; #endif #ifdef HAVE_SSE2 if((CPUCapFlags&CPU_CAP_SSE2)) - return Resample_lerp_SSE2; + return Resample_<LerpTag,SSE2Tag>; #endif - return Resample_lerp_C; + return Resample_<LerpTag,CTag>; case FIR4Resampler: - return Resample_cubic_C; + return Resample_<CubicTag,CTag>; case BSinc12Resampler: case BSinc24Resampler: #ifdef HAVE_NEON if((CPUCapFlags&CPU_CAP_NEON)) - return Resample_bsinc_Neon; + return Resample_<BSincTag,NEONTag>; #endif #ifdef HAVE_SSE if((CPUCapFlags&CPU_CAP_SSE)) - return Resample_bsinc_SSE; + return Resample_<BSincTag,SSETag>; #endif - return Resample_bsinc_C; + return Resample_<BSincTag,CTag>; } - return Resample_point_C; + return Resample_<PointTag,CTag>; } @@ -317,7 +317,7 @@ ALboolean MixSource(ALvoice *voice, const ALuint SourceID, ALCcontext *Context, ASSUME(IrSize >= 0); ResamplerFunc Resample{(increment == FRACTIONONE && DataPosFrac == 0) ? - Resample_copy_C : voice->Resampler}; + Resample_<CopyTag,CTag> : voice->Resampler}; ALsizei Counter{(voice->Flags&VOICE_IS_FADING) ? SamplesToDo : 0}; if(!Counter) |