diff options
-rw-r--r-- | core/converter.cpp | 10 | ||||
-rw-r--r-- | core/mixer/defs.h | 8 | ||||
-rw-r--r-- | core/mixer/mixer_c.cpp | 49 | ||||
-rw-r--r-- | core/mixer/mixer_neon.cpp | 20 | ||||
-rw-r--r-- | core/mixer/mixer_sse.cpp | 15 | ||||
-rw-r--r-- | core/mixer/mixer_sse2.cpp | 5 | ||||
-rw-r--r-- | core/mixer/mixer_sse41.cpp | 5 | ||||
-rw-r--r-- | core/voice.cpp | 13 |
8 files changed, 53 insertions, 72 deletions
diff --git a/core/converter.cpp b/core/converter.cpp index 35b1f289..132859f4 100644 --- a/core/converter.cpp +++ b/core/converter.cpp @@ -16,7 +16,6 @@ #include "fpu_ctrl.h" struct CTag; -struct CopyTag; namespace { @@ -182,7 +181,8 @@ SampleConverterPtr SampleConverter::Create(DevFmtType srcType, DevFmtType dstTyp mind(srcRate*double{MixerFracOne}/dstRate + 0.5, MaxPitch*MixerFracOne)); converter->mIncrement = maxu(step, 1); if(converter->mIncrement == MixerFracOne) - converter->mResample = Resample_<CopyTag,CTag>; + converter->mResample = [](const InterpState*, const float *RESTRICT src, uint, const uint, + const al::span<float> dst) { std::copy_n(src, dst.size(), dst.begin()); }; else converter->mResample = PrepareResampler(resampler, converter->mIncrement, &converter->mState); @@ -284,10 +284,10 @@ uint SampleConverter::convert(const void **src, uint *srcframes, void *dst, uint std::end(mChan[chan].PrevSamples), 0.0f); /* Now resample, and store the result in the output buffer. */ - const float *ResampledData{mResample(&mState, SrcData+(MaxResamplerPadding>>1), - DataPosFrac, increment, {DstData, DstSize})}; + mResample(&mState, SrcData+MaxResamplerEdge, DataPosFrac, increment, + {DstData, DstSize}); - StoreSamples(DstSamples, ResampledData, mChan.size(), mDstType, DstSize); + StoreSamples(DstSamples, DstData, mChan.size(), mDstType, DstSize); } /* Update the number of prep samples still available, as well as the diff --git a/core/mixer/defs.h b/core/mixer/defs.h index 74a474fe..e02eb0b9 100644 --- a/core/mixer/defs.h +++ b/core/mixer/defs.h @@ -64,15 +64,15 @@ union InterpState { BsincState bsinc; }; -using ResamplerFunc = float*(*)(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst); +using ResamplerFunc = void(*)(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst); ResamplerFunc PrepareResampler(Resampler resampler, uint increment, InterpState *state); template<typename TypeTag, typename InstTag> -float *Resample_(const InterpState *state, float *RESTRICT src, uint frac, uint increment, - const al::span<float> dst); +void Resample_(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst); template<typename InstTag> void Mix_(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer, diff --git a/core/mixer/mixer_c.cpp b/core/mixer/mixer_c.cpp index 88524368..28a92ef7 100644 --- a/core/mixer/mixer_c.cpp +++ b/core/mixer/mixer_c.cpp @@ -11,7 +11,6 @@ #include "hrtfbase.h" struct CTag; -struct CopyTag; struct PointTag; struct LerpTag; struct CubicTag; @@ -87,8 +86,8 @@ inline float do_fastbsinc(const InterpState &istate, const float *RESTRICT vals, using SamplerT = float(&)(const InterpState&, const float*RESTRICT, const uint); template<SamplerT Sampler> -float *DoResample(const InterpState *state, float *RESTRICT src, uint frac, uint increment, - const al::span<float> dst) +void DoResample(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { const InterpState istate{*state}; ASSUME(frac < MixerFracOne); @@ -100,7 +99,6 @@ float *DoResample(const InterpState *state, float *RESTRICT src, uint frac, uint src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs, @@ -148,42 +146,29 @@ force_inline void MixLine(const al::span<const float> InSamples, float *RESTRICT } // namespace template<> -float *Resample_<CopyTag,CTag>(const InterpState*, float *RESTRICT src, uint, uint, - const al::span<float> dst) -{ -#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.data())&15)) - return src; -#endif - std::copy_n(src, dst.size(), dst.begin()); - return dst.data(); -} - -template<> -float *Resample_<PointTag,CTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) -{ return DoResample<do_point>(state, src, frac, increment, dst); } +void Resample_<PointTag,CTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) +{ DoResample<do_point>(state, src, frac, increment, dst); } template<> -float *Resample_<LerpTag,CTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) -{ return DoResample<do_lerp>(state, src, frac, increment, dst); } +void Resample_<LerpTag,CTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) +{ DoResample<do_lerp>(state, src, frac, increment, dst); } template<> -float *Resample_<CubicTag,CTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) -{ return DoResample<do_cubic>(state, src-1, frac, increment, dst); } +void Resample_<CubicTag,CTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) +{ DoResample<do_cubic>(state, src-1, frac, increment, dst); } template<> -float *Resample_<BSincTag,CTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) -{ return DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst); } +void Resample_<BSincTag,CTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) +{ DoResample<do_bsinc>(state, src-state->bsinc.l, frac, increment, dst); } template<> -float *Resample_<FastBSincTag,CTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) -{ return DoResample<do_fastbsinc>(state, src-state->bsinc.l, frac, increment, dst); } +void Resample_<FastBSincTag,CTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) +{ DoResample<do_fastbsinc>(state, src-state->bsinc.l, frac, increment, dst); } template<> diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index 96cdfb29..ef2936b3 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -138,8 +138,8 @@ force_inline void MixLine(const al::span<const float> InSamples, float *RESTRICT } // namespace template<> -float *Resample_<LerpTag,NEONTag>(const InterpState*, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<LerpTag,NEONTag>(const InterpState*, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { ASSUME(frac < MixerFracOne); @@ -189,12 +189,11 @@ float *Resample_<LerpTag,NEONTag>(const InterpState*, float *RESTRICT src, uint frac &= MixerFracMask; } while(--todo); } - return dst.data(); } template<> -float *Resample_<CubicTag,NEONTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<CubicTag,NEONTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { ASSUME(frac < MixerFracOne); @@ -222,12 +221,11 @@ float *Resample_<CubicTag,NEONTag>(const InterpState *state, float *RESTRICT src src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } template<> -float *Resample_<BSincTag,NEONTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<BSincTag,NEONTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { const float *const filter{state->bsinc.filter}; const float32x4_t sf4{vdupq_n_f32(state->bsinc.sf)}; @@ -270,12 +268,11 @@ float *Resample_<BSincTag,NEONTag>(const InterpState *state, float *RESTRICT src src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } template<> -float *Resample_<FastBSincTag,NEONTag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<FastBSincTag,NEONTag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { const float *const filter{state->bsinc.filter}; const size_t m{state->bsinc.m}; @@ -313,7 +310,6 @@ float *Resample_<FastBSincTag,NEONTag>(const InterpState *state, float *RESTRICT src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } diff --git a/core/mixer/mixer_sse.cpp b/core/mixer/mixer_sse.cpp index 6bbb3d3c..0aa5d5fb 100644 --- a/core/mixer/mixer_sse.cpp +++ b/core/mixer/mixer_sse.cpp @@ -154,8 +154,8 @@ force_inline void MixLine(const al::span<const float> InSamples, float *RESTRICT } // namespace template<> -float *Resample_<CubicTag,SSETag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<CubicTag,SSETag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { ASSUME(frac < MixerFracOne); @@ -184,12 +184,11 @@ float *Resample_<CubicTag,SSETag>(const InterpState *state, float *RESTRICT src, src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } template<> -float *Resample_<BSincTag,SSETag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<BSincTag,SSETag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { const float *const filter{state->bsinc.filter}; const __m128 sf4{_mm_set1_ps(state->bsinc.sf)}; @@ -233,12 +232,11 @@ float *Resample_<BSincTag,SSETag>(const InterpState *state, float *RESTRICT src, src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } template<> -float *Resample_<FastBSincTag,SSETag>(const InterpState *state, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<FastBSincTag,SSETag>(const InterpState *state, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { const float *const filter{state->bsinc.filter}; const size_t m{state->bsinc.m}; @@ -277,7 +275,6 @@ float *Resample_<FastBSincTag,SSETag>(const InterpState *state, float *RESTRICT src += frac>>MixerFracBits; frac &= MixerFracMask; } - return dst.data(); } diff --git a/core/mixer/mixer_sse2.cpp b/core/mixer/mixer_sse2.cpp index 923924db..edaaf7a1 100644 --- a/core/mixer/mixer_sse2.cpp +++ b/core/mixer/mixer_sse2.cpp @@ -35,8 +35,8 @@ struct LerpTag; #endif template<> -float *Resample_<LerpTag,SSE2Tag>(const InterpState*, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<LerpTag,SSE2Tag>(const InterpState*, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { ASSUME(frac < MixerFracOne); @@ -87,5 +87,4 @@ float *Resample_<LerpTag,SSE2Tag>(const InterpState*, float *RESTRICT src, uint frac &= MixerFracMask; } while(--todo); } - return dst.data(); } diff --git a/core/mixer/mixer_sse41.cpp b/core/mixer/mixer_sse41.cpp index 23994735..8ccd9fd3 100644 --- a/core/mixer/mixer_sse41.cpp +++ b/core/mixer/mixer_sse41.cpp @@ -36,8 +36,8 @@ struct LerpTag; #endif template<> -float *Resample_<LerpTag,SSE4Tag>(const InterpState*, float *RESTRICT src, uint frac, - uint increment, const al::span<float> dst) +void Resample_<LerpTag,SSE4Tag>(const InterpState*, const float *RESTRICT src, uint frac, + const uint increment, const al::span<float> dst) { ASSUME(frac < MixerFracOne); @@ -92,5 +92,4 @@ float *Resample_<LerpTag,SSE4Tag>(const InterpState*, float *RESTRICT src, uint frac &= MixerFracMask; } while(--todo); } - return dst.data(); } diff --git a/core/voice.cpp b/core/voice.cpp index b7e1c67d..f84c5555 100644 --- a/core/voice.cpp +++ b/core/voice.cpp @@ -48,7 +48,6 @@ struct SSETag; #ifdef HAVE_NEON struct NEONTag; #endif -struct CopyTag; static_assert(!(sizeof(DeviceBase::MixerBufferLine)&15), @@ -189,6 +188,11 @@ void SendSourceStoppedEvent(ContextBase *context, uint id) } +void CopyResample(const InterpState*, const float *RESTRICT src, uint, const uint, + const al::span<float> dst) +{ std::copy_n(src, dst.size(), dst.begin()); } + + const float *DoFilters(BiquadFilter &lpfilter, BiquadFilter &hpfilter, float *dst, const al::span<const float> src, int type) { @@ -562,7 +566,7 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi MixingSamples.begin(), offset_bufferline); const ResamplerFunc Resample{(increment == MixerFracOne && DataPosFrac == 0) ? - Resample_<CopyTag,CTag> : mResampler}; + CopyResample : mResampler}; const uint PostPadding{MaxResamplerEdge + mDecoderPadding}; uint buffers_done{0u}; do { @@ -720,8 +724,9 @@ void Voice::mix(const State vstate, ContextBase *Context, const nanoseconds devi for(auto &chandata : mChans) { /* Resample, then apply ambisonic upsampling as needed. */ - float *ResampledData{Resample(&mResampleState, *voiceSamples, DataPosFrac, increment, - {Device->ResampledData, DstBufferSize})}; + float *ResampledData{Device->ResampledData}; + Resample(&mResampleState, *voiceSamples, DataPosFrac, increment, + {ResampledData, DstBufferSize}); ++voiceSamples; if(mFlags.test(VoiceIsAmbisonic)) |