diff options
author | Chris Robinson <[email protected]> | 2021-02-06 14:39:30 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2021-02-06 14:39:30 -0800 |
commit | dfe627133c1d018748bd66ad1f8c72945448a34a (patch) | |
tree | e1b13de1178629836538ccec8e573dc0b67227cc /core | |
parent | 72c4dd4d10659fb0e3fa973e68f399c6b34d4b99 (diff) |
Use spans instead of references to arrays
Diffstat (limited to 'core')
-rw-r--r-- | core/bufferline.h | 3 | ||||
-rw-r--r-- | core/mixer/defs.h | 2 | ||||
-rw-r--r-- | core/mixer/hrtfbase.h | 12 | ||||
-rw-r--r-- | core/mixer/hrtfdefs.h | 5 | ||||
-rw-r--r-- | core/mixer/mixer_c.cpp | 4 | ||||
-rw-r--r-- | core/mixer/mixer_neon.cpp | 4 | ||||
-rw-r--r-- | core/mixer/mixer_sse.cpp | 4 | ||||
-rw-r--r-- | core/uhjfilter.cpp | 2 | ||||
-rw-r--r-- | core/uhjfilter.h | 2 |
9 files changed, 22 insertions, 16 deletions
diff --git a/core/bufferline.h b/core/bufferline.h index 503e208d..8b445f3f 100644 --- a/core/bufferline.h +++ b/core/bufferline.h @@ -3,6 +3,8 @@ #include <array> +#include "alspan.h" + /* Size for temporary storage of buffer data, in floats. Larger values need * more memory and are harder on cache, while smaller values may need more * iterations for mixing. @@ -10,5 +12,6 @@ constexpr int BufferLineSize{1024}; using FloatBufferLine = std::array<float,BufferLineSize>; +using FloatBufferSpan = al::span<float,BufferLineSize>; #endif /* CORE_BUFFERLINE_H */ diff --git a/core/mixer/defs.h b/core/mixer/defs.h index acf60350..e8e7be6c 100644 --- a/core/mixer/defs.h +++ b/core/mixer/defs.h @@ -80,7 +80,7 @@ template<typename InstTag> void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const uint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize); template<typename InstTag> -void MixDirectHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, +void MixDirectHrtf_(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize); diff --git a/core/mixer/hrtfbase.h b/core/mixer/hrtfbase.h index 7419f960..79b09a3d 100644 --- a/core/mixer/hrtfbase.h +++ b/core/mixer/hrtfbase.h @@ -12,7 +12,7 @@ using uint = unsigned int; using ApplyCoeffsT = void(&)(float2 *RESTRICT Values, const size_t irSize, - const HrirArray &Coeffs, const float left, const float right); + const ConstHrirSpan Coeffs, const float left, const float right); template<ApplyCoeffsT ApplyCoeffs> inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, const size_t IrSize, @@ -20,7 +20,7 @@ inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, c { ASSUME(BufferSize > 0); - const HrirArray &Coeffs = *hrtfparams->Coeffs; + const ConstHrirSpan Coeffs{hrtfparams->Coeffs}; const float gainstep{hrtfparams->GainStep}; const float gain{hrtfparams->Gain}; @@ -45,9 +45,9 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl { ASSUME(BufferSize > 0); - const auto &OldCoeffs = oldparams->Coeffs; + const ConstHrirSpan OldCoeffs{oldparams->Coeffs}; const float oldGainStep{oldparams->Gain / static_cast<float>(BufferSize)}; - const auto &NewCoeffs = *newparams->Coeffs; + const ConstHrirSpan NewCoeffs{newparams->Coeffs}; const float newGainStep{newparams->GainStep}; if LIKELY(oldparams->Gain > GainSilenceThreshold) @@ -84,7 +84,7 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl } template<ApplyCoeffsT ApplyCoeffs> -inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, +inline void MixDirectHrtfBase(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const al::span<const FloatBufferLine> InSamples, float2 *RESTRICT AccumSamples, float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize) { @@ -133,7 +133,7 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu ChanState->mSplitter.processHfScale(tempbuf, ChanState->mHfScale); /* Now apply the HRIR coefficients to this channel. */ - const auto &Coeffs = ChanState->mCoeffs; + const ConstHrirSpan Coeffs{ChanState->mCoeffs}; for(size_t i{0u};i < BufferSize;++i) { const float insample{tempbuf[i]}; diff --git a/core/mixer/hrtfdefs.h b/core/mixer/hrtfdefs.h index 89a9bb8d..7046a31e 100644 --- a/core/mixer/hrtfdefs.h +++ b/core/mixer/hrtfdefs.h @@ -3,6 +3,7 @@ #include <array> +#include "alspan.h" #include "core/ambidefs.h" #include "core/bufferline.h" #include "core/filters/splitter.h" @@ -28,9 +29,11 @@ constexpr uint MinIrLength{8}; constexpr uint HrtfDirectDelay{256}; using HrirArray = std::array<float2,HrirLength>; +using HrirSpan = al::span<float2,HrirLength>; +using ConstHrirSpan = al::span<const float2,HrirLength>; struct MixHrtfFilter { - const HrirArray *Coeffs; + const ConstHrirSpan Coeffs; uint2 Delay; float Gain; float GainStep; diff --git a/core/mixer/mixer_c.cpp b/core/mixer/mixer_c.cpp index ff9538a4..6b9c4344 100644 --- a/core/mixer/mixer_c.cpp +++ b/core/mixer/mixer_c.cpp @@ -83,7 +83,7 @@ float *DoResample(const InterpState *state, float *RESTRICT src, uint frac, uint return dst.data(); } -inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs, +inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs, const float left, const float right) { ASSUME(IrSize >= MinIrLength); @@ -149,7 +149,7 @@ void MixHrtfBlend_<CTag>(const float *InSamples, float2 *AccumSamples, const uin } template<> -void MixDirectHrtf_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, +void MixDirectHrtf_<CTag>(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize) { diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index f3e5f130..220d412e 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -34,7 +34,7 @@ inline float32x4_t set_f4(float l0, float l1, float l2, float l3) constexpr uint FracPhaseBitDiff{MixerFracBits - BSincPhaseBits}; constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff}; -inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs, +inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs, const float left, const float right) { float32x4_t leftright4; @@ -213,7 +213,7 @@ void MixHrtfBlend_<NEONTag>(const float *InSamples, float2 *AccumSamples, const } template<> -void MixDirectHrtf_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, +void MixDirectHrtf_<NEONTag>(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize) { diff --git a/core/mixer/mixer_sse.cpp b/core/mixer/mixer_sse.cpp index 23caf797..8c748a57 100644 --- a/core/mixer/mixer_sse.cpp +++ b/core/mixer/mixer_sse.cpp @@ -27,7 +27,7 @@ constexpr uint FracPhaseDiffOne{1 << FracPhaseBitDiff}; #define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z)) -inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs, +inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const ConstHrirSpan Coeffs, const float left, const float right) { const __m128 lrlr{_mm_setr_ps(left, right, left, right)}; @@ -180,7 +180,7 @@ void MixHrtfBlend_<SSETag>(const float *InSamples, float2 *AccumSamples, const u } template<> -void MixDirectHrtf_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, +void MixDirectHrtf_<SSETag>(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const al::span<const FloatBufferLine> InSamples, float2 *AccumSamples, float *TempBuf, HrtfChannelState *ChanState, const size_t IrSize, const size_t BufferSize) { diff --git a/core/uhjfilter.cpp b/core/uhjfilter.cpp index 92f35901..350a9aaa 100644 --- a/core/uhjfilter.cpp +++ b/core/uhjfilter.cpp @@ -221,7 +221,7 @@ void allpass_process(al::span<float> dst, const float *RESTRICT src) * with the desired shift. */ -void Uhj2Encoder::encode(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, +void Uhj2Encoder::encode(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const FloatBufferLine *InSamples, const size_t SamplesToDo) { ASSUME(SamplesToDo > 0); diff --git a/core/uhjfilter.h b/core/uhjfilter.h index c2cb8722..7cd797d9 100644 --- a/core/uhjfilter.h +++ b/core/uhjfilter.h @@ -30,7 +30,7 @@ struct Uhj2Encoder { * Encodes a 2-channel UHJ (stereo-compatible) signal from a B-Format input * signal. The input must use FuMa channel ordering and scaling. */ - void encode(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, + void encode(const FloatBufferSpan LeftOut, const FloatBufferSpan RightOut, const FloatBufferLine *InSamples, const size_t SamplesToDo); DEF_NEWDEL(Uhj2Encoder) |