From 54b49594e61373613630d01c8a84c878681dee34 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 5 Jan 2020 17:12:48 -0800 Subject: [PATCH] Simplify post-mix HRTF gain storage --- alc/mixer/defs.h | 4 ++-- alc/mixer/hrtfbase.h | 8 ++------ alc/mixer/mixer_c.cpp | 4 ++-- alc/mixer/mixer_neon.cpp | 4 ++-- alc/mixer/mixer_sse.cpp | 4 ++-- alc/voice.cpp | 18 +++++------------- 6 files changed, 15 insertions(+), 27 deletions(-) diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h index 1e5b40d8..a3b49ad3 100644 --- a/alc/mixer/defs.h +++ b/alc/mixer/defs.h @@ -42,10 +42,10 @@ void MixRow_(const al::span OutBuffer, const al::span Gains, template void MixHrtf_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - MixHrtfFilter *hrtfparams, const size_t BufferSize); + const MixHrtfFilter *hrtfparams, const size_t BufferSize); template void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - const HrtfFilter *oldparams, MixHrtfFilter *newparams, const size_t BufferSize); + const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize); template void MixDirectHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, const al::span InSamples, float2 *AccumSamples, DirectHrtfState *State, diff --git a/alc/mixer/hrtfbase.h b/alc/mixer/hrtfbase.h index 942c56c3..ed40328c 100644 --- a/alc/mixer/hrtfbase.h +++ b/alc/mixer/hrtfbase.h @@ -14,7 +14,7 @@ using ApplyCoeffsT = void(&)(float2 *RESTRICT Values, const ALuint irSize, const template inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, const ALuint IrSize, - MixHrtfFilter *hrtfparams, const size_t BufferSize) + const MixHrtfFilter *hrtfparams, const size_t BufferSize) { ASSUME(BufferSize > 0); @@ -35,13 +35,11 @@ inline void MixHrtfBase(const float *InSamples, float2 *RESTRICT AccumSamples, c stepcount += 1.0f; } - - hrtfparams->Gain = gain + gainstep*stepcount; } template inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSamples, - const ALuint IrSize, const HrtfFilter *oldparams, MixHrtfFilter *newparams, + const ALuint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize) { const auto &OldCoeffs = oldparams->Coeffs; @@ -78,8 +76,6 @@ inline void MixHrtfBlendBase(const float *InSamples, float2 *RESTRICT AccumSampl stepcount += 1.0f; } - - newparams->Gain = newGainStep*stepcount; } template diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 64d12ef7..c086dd8d 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -137,12 +137,12 @@ const ALfloat *Resample_(const InterpState *state, const ALfl template<> void MixHrtf_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - MixHrtfFilter *hrtfparams, const size_t BufferSize) + const MixHrtfFilter *hrtfparams, const size_t BufferSize) { MixHrtfBase(InSamples, AccumSamples, IrSize, hrtfparams, BufferSize); } template<> void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - const HrtfFilter *oldparams, MixHrtfFilter *newparams, const size_t BufferSize) + const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize) { MixHrtfBlendBase(InSamples, AccumSamples, IrSize, oldparams, newparams, BufferSize); diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index ccfc5761..afc9768a 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -191,12 +191,12 @@ const ALfloat *Resample_(const InterpState *state, template<> void MixHrtf_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - MixHrtfFilter *hrtfparams, const size_t BufferSize) + const MixHrtfFilter *hrtfparams, const size_t BufferSize) { MixHrtfBase(InSamples, AccumSamples, IrSize, hrtfparams, BufferSize); } template<> void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - const HrtfFilter *oldparams, MixHrtfFilter *newparams, const size_t BufferSize) + const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize) { MixHrtfBlendBase(InSamples, AccumSamples, IrSize, oldparams, newparams, BufferSize); diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index 2fb856e1..3bc7b30f 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -167,12 +167,12 @@ const ALfloat *Resample_(const InterpState *state, template<> void MixHrtf_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - MixHrtfFilter *hrtfparams, const size_t BufferSize) + const MixHrtfFilter *hrtfparams, const size_t BufferSize) { MixHrtfBase(InSamples, AccumSamples, IrSize, hrtfparams, BufferSize); } template<> void MixHrtfBlend_(const float *InSamples, float2 *AccumSamples, const ALuint IrSize, - const HrtfFilter *oldparams, MixHrtfFilter *newparams, const size_t BufferSize) + const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize) { MixHrtfBlendBase(InSamples, AccumSamples, IrSize, oldparams, newparams, BufferSize); diff --git a/alc/voice.cpp b/alc/voice.cpp index ef26b630..42d9021f 100644 --- a/alc/voice.cpp +++ b/alc/voice.cpp @@ -73,9 +73,9 @@ Resampler ResamplerDefault{Resampler::Linear}; namespace { using HrtfMixerFunc = void(*)(const ALfloat *InSamples, float2 *AccumSamples, const ALuint IrSize, - MixHrtfFilter *hrtfparams, const size_t BufferSize); + const MixHrtfFilter *hrtfparams, const size_t BufferSize); using HrtfMixerBlendFunc = void(*)(const ALfloat *InSamples, float2 *AccumSamples, - const ALuint IrSize, const HrtfFilter *oldparams, MixHrtfFilter *newparams, + const ALuint IrSize, const HrtfFilter *oldparams, const MixHrtfFilter *newparams, const size_t BufferSize); HrtfMixerFunc MixHrtfSamples = MixHrtf_; @@ -468,10 +468,7 @@ void DoHrtfMix(const float *samples, const ALuint DstBufferSize, DirectParams &p fademix); /* Update the old parameters with the result. */ parms.Hrtf.Old = parms.Hrtf.Target; - if(fademix < Counter) - parms.Hrtf.Old.Gain = hrtfparams.Gain; - else - parms.Hrtf.Old.Gain = TargetGain; + parms.Hrtf.Old.Gain = gain; OutPos += fademix; } @@ -496,13 +493,8 @@ void DoHrtfMix(const float *samples, const ALuint DstBufferSize, DirectParams &p hrtfparams.Gain = parms.Hrtf.Old.Gain; hrtfparams.GainStep = (gain - parms.Hrtf.Old.Gain) / static_cast(todo); MixHrtfSamples(HrtfSamples+fademix, AccumSamples+OutPos, IrSize, &hrtfparams, todo); - /* Store the interpolated gain or the final target gain depending if - * the fade is done. - */ - if(DstBufferSize < Counter) - parms.Hrtf.Old.Gain = gain; - else - parms.Hrtf.Old.Gain = TargetGain; + /* Store the now-current gain for next time. */ + parms.Hrtf.Old.Gain = gain; } }