diff options
author | Chris Robinson <[email protected]> | 2020-12-25 20:52:18 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2020-12-25 20:52:18 -0800 |
commit | 5f233a2c24de58fde98e08ad8acb6cfe1803d716 (patch) | |
tree | a62086d205cfa4d66719dd2d4b42eac7563ded39 /core/mixer | |
parent | 223f93e13d2a36375fa71251a2e565799cc2ab3e (diff) |
Use more constexpr variables instead of macros
Diffstat (limited to 'core/mixer')
-rw-r--r-- | core/mixer/hrtfbase.h | 22 | ||||
-rw-r--r-- | core/mixer/hrtfdefs.h | 33 | ||||
-rw-r--r-- | core/mixer/mixer_c.cpp | 2 | ||||
-rw-r--r-- | core/mixer/mixer_neon.cpp | 2 | ||||
-rw-r--r-- | core/mixer/mixer_sse.cpp | 2 |
5 files changed, 31 insertions, 30 deletions
diff --git a/core/mixer/hrtfbase.h b/core/mixer/hrtfbase.h index 39155adb..7419f960 100644 --- a/core/mixer/hrtfbase.h +++ b/core/mixer/hrtfbase.h @@ -24,8 +24,8 @@ inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, c const float gainstep{hrtfparams->GainStep}; const float gain{hrtfparams->Gain}; - size_t ldelay{HRTF_HISTORY_LENGTH - hrtfparams->Delay[0]}; - size_t rdelay{HRTF_HISTORY_LENGTH - hrtfparams->Delay[1]}; + size_t ldelay{HrtfHistoryLength - hrtfparams->Delay[0]}; + size_t rdelay{HrtfHistoryLength - hrtfparams->Delay[1]}; float stepcount{0.0f}; for(size_t i{0u};i < BufferSize;++i) { @@ -52,8 +52,8 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl if LIKELY(oldparams->Gain > GainSilenceThreshold) { - size_t ldelay{HRTF_HISTORY_LENGTH - oldparams->Delay[0]}; - size_t rdelay{HRTF_HISTORY_LENGTH - oldparams->Delay[1]}; + size_t ldelay{HrtfHistoryLength - oldparams->Delay[0]}; + size_t rdelay{HrtfHistoryLength - oldparams->Delay[1]}; auto stepcount = static_cast<float>(BufferSize); for(size_t i{0u};i < BufferSize;++i) { @@ -68,8 +68,8 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl if LIKELY(newGainStep*static_cast<float>(BufferSize) > GainSilenceThreshold) { - size_t ldelay{HRTF_HISTORY_LENGTH+1 - newparams->Delay[0]}; - size_t rdelay{HRTF_HISTORY_LENGTH+1 - newparams->Delay[1]}; + size_t ldelay{HrtfHistoryLength+1 - newparams->Delay[0]}; + size_t rdelay{HrtfHistoryLength+1 - newparams->Delay[1]}; float stepcount{1.0f}; for(size_t i{1u};i < BufferSize;++i) { @@ -95,8 +95,8 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu */ for(size_t i{0};i < BufferSize;++i) { - AccumSamples[HRTF_DIRECT_DELAY+i][0] += LeftOut[i]; - AccumSamples[HRTF_DIRECT_DELAY+i][1] += RightOut[i]; + AccumSamples[HrtfDirectDelay+i][0] += LeftOut[i]; + AccumSamples[HrtfDirectDelay+i][1] += RightOut[i]; } for(const FloatBufferLine &input : InSamples) @@ -111,7 +111,7 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu * padding. The delay serves to reduce the error caused by the IIR * filter's phase shift on a partial input. */ - al::span<float> tempbuf{al::assume_aligned<16>(TempBuf), HRTF_DIRECT_DELAY+BufferSize}; + al::span<float> tempbuf{al::assume_aligned<16>(TempBuf), HrtfDirectDelay+BufferSize}; auto tmpiter = std::reverse_copy(input.begin(), input.begin()+BufferSize, tempbuf.begin()); std::copy(ChanState->mDelay.cbegin(), ChanState->mDelay.cend(), tmpiter); @@ -123,7 +123,7 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu * phase shift (+n degrees becomes -n degrees). */ ChanState->mSplitter.applyAllpass(tempbuf); - tempbuf = tempbuf.subspan<HRTF_DIRECT_DELAY>(); + tempbuf = tempbuf.subspan<HrtfDirectDelay>(); std::reverse(tempbuf.begin(), tempbuf.end()); /* Now apply the HF scale with the band-splitter. This applies the @@ -151,7 +151,7 @@ inline void MixDirectHrtfBase(FloatBufferLine &LeftOut, FloatBufferLine &RightOu /* Copy the new in-progress accumulation values to the front and clear the * following samples for the next mix. */ - auto accum_iter = std::copy_n(AccumSamples+BufferSize, HRIR_LENGTH+HRTF_DIRECT_DELAY, + auto accum_iter = std::copy_n(AccumSamples+BufferSize, HrirLength+HrtfDirectDelay, AccumSamples); std::fill_n(accum_iter, BufferSize, float2{}); } diff --git a/core/mixer/hrtfdefs.h b/core/mixer/hrtfdefs.h index 552fc152..89a9bb8d 100644 --- a/core/mixer/hrtfdefs.h +++ b/core/mixer/hrtfdefs.h @@ -8,42 +8,43 @@ #include "core/filters/splitter.h" -#define HRTF_HISTORY_BITS 6 -#define HRTF_HISTORY_LENGTH (1<<HRTF_HISTORY_BITS) -#define HRTF_HISTORY_MASK (HRTF_HISTORY_LENGTH-1) - -#define HRIR_BITS 7 -#define HRIR_LENGTH (1<<HRIR_BITS) -#define HRIR_MASK (HRIR_LENGTH-1) - -#define MIN_IR_LENGTH 8 - -#define HRTF_DIRECT_DELAY 256 - using float2 = std::array<float,2>; -using HrirArray = std::array<float2,HRIR_LENGTH>; using ubyte = unsigned char; using ubyte2 = std::array<ubyte,2>; using ushort = unsigned short; using uint = unsigned int; +using uint2 = std::array<uint,2>; + +constexpr uint HrtfHistoryBits{6}; +constexpr uint HrtfHistoryLength{1 << HrtfHistoryBits}; +constexpr uint HrtfHistoryMask{HrtfHistoryLength - 1}; + +constexpr uint HrirBits{7}; +constexpr uint HrirLength{1 << HrirBits}; +constexpr uint HrirMask{HrirLength - 1}; + +constexpr uint MinIrLength{8}; + +constexpr uint HrtfDirectDelay{256}; +using HrirArray = std::array<float2,HrirLength>; struct MixHrtfFilter { const HrirArray *Coeffs; - std::array<uint,2> Delay; + uint2 Delay; float Gain; float GainStep; }; struct HrtfFilter { alignas(16) HrirArray Coeffs; - std::array<uint,2> Delay; + uint2 Delay; float Gain; }; struct HrtfChannelState { - std::array<float,HRTF_DIRECT_DELAY> mDelay{}; + std::array<float,HrtfDirectDelay> mDelay{}; BandSplitter mSplitter; float mHfScale{}; alignas(16) HrirArray mCoeffs{}; diff --git a/core/mixer/mixer_c.cpp b/core/mixer/mixer_c.cpp index 6b25b6cc..6d4909f4 100644 --- a/core/mixer/mixer_c.cpp +++ b/core/mixer/mixer_c.cpp @@ -86,7 +86,7 @@ const float *DoResample(const InterpState *state, const float *RESTRICT src, uin inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const HrirArray &Coeffs, const float left, const float right) { - ASSUME(IrSize >= MIN_IR_LENGTH); + ASSUME(IrSize >= MinIrLength); for(size_t c{0};c < IrSize;++c) { Values[c][0] += Coeffs[c][0] * left; diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp index cc6dd71d..6ecb25fe 100644 --- a/core/mixer/mixer_neon.cpp +++ b/core/mixer/mixer_neon.cpp @@ -46,7 +46,7 @@ inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const Hrir leftright4 = vcombine_f32(leftright2, leftright2); } - ASSUME(IrSize >= MIN_IR_LENGTH); + ASSUME(IrSize >= MinIrLength); for(size_t c{0};c < IrSize;c += 2) { float32x4_t vals = vld1q_f32(&Values[c][0]); diff --git a/core/mixer/mixer_sse.cpp b/core/mixer/mixer_sse.cpp index f21ec227..3ecac384 100644 --- a/core/mixer/mixer_sse.cpp +++ b/core/mixer/mixer_sse.cpp @@ -32,7 +32,7 @@ inline void ApplyCoeffs(float2 *RESTRICT Values, const size_t IrSize, const Hrir { const __m128 lrlr{_mm_setr_ps(left, right, left, right)}; - ASSUME(IrSize >= MIN_IR_LENGTH); + ASSUME(IrSize >= MinIrLength); /* This isn't technically correct to test alignment, but it's true for * systems that support SSE, which is the only one that needs to know the * alignment of Values (which alternates between 8- and 16-byte aligned). |