From 8fd90334a13608a781e36fc830cd79bf746edd42 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 20 Aug 2019 00:27:28 -0700 Subject: Pass the MixRow buffer size as a span --- alc/alu.h | 4 ++-- alc/bformatdec.cpp | 13 +++++++------ alc/effects/reverb.cpp | 32 +++++++++++++++++--------------- alc/mixer/defs.h | 3 ++- alc/mixer/mixer_c.cpp | 14 ++++++-------- alc/mixer/mixer_neon.cpp | 25 +++++++++++-------------- alc/mixer/mixer_sse.cpp | 27 ++++++++++++--------------- 7 files changed, 57 insertions(+), 61 deletions(-) diff --git a/alc/alu.h b/alc/alu.h index 117c932d..c63e33fd 100644 --- a/alc/alu.h +++ b/alc/alu.h @@ -317,8 +317,8 @@ struct ALvoice { using MixerFunc = void(*)(const ALfloat *data, const al::span OutBuffer, ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos, const ALsizei BufferSize); -using RowMixerFunc = void(*)(ALfloat *OutBuffer, const al::span Gains, - const ALfloat *InSamples, const ALsizei InStride, const ALsizei BufferSize); +using RowMixerFunc = void(*)(const al::span OutBuffer, const al::span Gains, + const float *InSamples, const size_t InStride); using HrtfMixerFunc = void(*)(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize, MixHrtfFilter *hrtfparams, const ALsizei BufferSize); diff --git a/alc/bformatdec.cpp b/alc/bformatdec.cpp index ce4c4b3b..7d681bc6 100644 --- a/alc/bformatdec.cpp +++ b/alc/bformatdec.cpp @@ -162,10 +162,11 @@ void BFormatDec::process(const al::span OutBuffer, { if LIKELY(enabled&1) { - MixRowSamples(outbuf.data(), {(*mixmtx)[sHFBand], mNumChannels}, - mSamplesHF->data(), mSamplesHF->size(), SamplesToDo); - MixRowSamples(outbuf.data(), {(*mixmtx)[sLFBand], mNumChannels}, - mSamplesLF->data(), mSamplesLF->size(), SamplesToDo); + const al::span outspan{outbuf.data(), outbuf.data()+SamplesToDo}; + MixRowSamples(outspan, {(*mixmtx)[sHFBand], mNumChannels}, mSamplesHF->data(), + mSamplesHF->size()); + MixRowSamples(outspan, {(*mixmtx)[sLFBand], mNumChannels}, mSamplesLF->data(), + mSamplesLF->size()); } ++mixmtx; enabled >>= 1; @@ -178,8 +179,8 @@ void BFormatDec::process(const al::span OutBuffer, for(FloatBufferLine &outbuf : OutBuffer) { if LIKELY(enabled&1) - MixRowSamples(outbuf.data(), {*mixmtx, mNumChannels}, InSamples->data(), - InSamples->size(), SamplesToDo); + MixRowSamples({outbuf.data(), outbuf.data()+SamplesToDo}, {*mixmtx, mNumChannels}, + InSamples->data(), InSamples->size()); ++mixmtx; enabled >>= 1; } diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp index 8ff4feac..5f8daabe 100644 --- a/alc/effects/reverb.cpp +++ b/alc/effects/reverb.cpp @@ -421,19 +421,20 @@ struct ReverbState final : public EffectState { ASSUME(todo > 0); /* Convert back to B-Format, and mix the results to output. */ + const al::span tmpspan{mTempLine.begin(), mTempLine.begin()+todo}; for(size_t c{0u};c < NUM_LINES;c++) { - std::fill_n(mTempLine.begin(), todo, 0.0f); - MixRowSamples(mTempLine.data(), {A2B[c], NUM_LINES}, mEarlySamples[0].data(), - mEarlySamples[0].size(), todo); + std::fill(tmpspan.begin(), tmpspan.end(), 0.0f); + MixRowSamples(tmpspan, {A2B[c], NUM_LINES}, mEarlySamples[0].data(), + mEarlySamples[0].size()); MixSamples(mTempLine.data(), samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], counter, offset, todo); } for(size_t c{0u};c < NUM_LINES;c++) { - std::fill_n(mTempLine.begin(), todo, 0.0f); - MixRowSamples(mTempLine.data(), {A2B[c], NUM_LINES}, mLateSamples[0].data(), - mLateSamples[0].size(), todo); + std::fill(tmpspan.begin(), tmpspan.end(), 0.0f); + MixRowSamples(tmpspan, {A2B[c], NUM_LINES}, mLateSamples[0].data(), + mLateSamples[0].size()); MixSamples(mTempLine.data(), samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], counter, offset, todo); } @@ -444,11 +445,12 @@ struct ReverbState final : public EffectState { { ASSUME(todo > 0); + const al::span tmpspan{mTempLine.begin(), mTempLine.begin()+todo}; for(size_t c{0u};c < NUM_LINES;c++) { - std::fill_n(mTempLine.begin(), todo, 0.0f); - MixRowSamples(mTempLine.data(), {A2B[c], NUM_LINES}, mEarlySamples[0].data(), - mEarlySamples[0].size(), todo); + std::fill(tmpspan.begin(), tmpspan.end(), 0.0f); + MixRowSamples(tmpspan, {A2B[c], NUM_LINES}, mEarlySamples[0].data(), + mEarlySamples[0].size()); /* Apply scaling to the B-Format's HF response to "upsample" it to * higher-order output. @@ -461,9 +463,9 @@ struct ReverbState final : public EffectState { } for(size_t c{0u};c < NUM_LINES;c++) { - std::fill_n(mTempLine.begin(), todo, 0.0f); - MixRowSamples(mTempLine.data(), {A2B[c], NUM_LINES}, mLateSamples[0].data(), - mLateSamples[0].size(), todo); + std::fill(tmpspan.begin(), tmpspan.end(), 0.0f); + MixRowSamples(tmpspan, {A2B[c], NUM_LINES}, mLateSamples[0].data(), + mLateSamples[0].size()); const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]}; mAmbiSplitter[1][c].applyHfScale(mTempLine.data(), hfscale, todo); @@ -1457,11 +1459,11 @@ void ReverbState::process(const ALsizei samplesToDo, const FloatBufferLine *REST ASSUME(offset >= 0); /* Convert B-Format to A-Format for processing. */ + const al::span tmpspan{mTempLine.begin(), mTempLine.begin()+samplesToDo}; for(size_t c{0u};c < NUM_LINES;c++) { - std::fill_n(mTempLine.begin(), samplesToDo, 0.0f); - MixRowSamples(mTempLine.data(), {B2A[c], B2A[c]+numInput}, samplesIn->data(), - samplesIn->size(), samplesToDo); + std::fill(tmpspan.begin(), tmpspan.end(), 0.0f); + MixRowSamples(tmpspan, {B2A[c], B2A[c]+numInput}, samplesIn->data(), samplesIn->size()); /* Band-pass the incoming samples and feed the initial delay line. */ mFilter[c].Lp.process(mTempLine.data(), mTempLine.data(), samplesToDo); diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h index 19fb42d0..adaed8f5 100644 --- a/alc/mixer/defs.h +++ b/alc/mixer/defs.h @@ -32,7 +32,8 @@ const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, template void Mix_(const ALfloat *data, const al::span OutBuffer, ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos, const ALsizei BufferSize); template -void MixRow_(ALfloat *OutBuffer, const al::span Gains, const ALfloat *InSamples, const ALsizei InStride, const ALsizei BufferSize); +void MixRow_(const al::span OutBuffer, const al::span Gains, + const float *InSamples, const size_t InStride); template void MixHrtf_(FloatBufferLine &LeftOut, FloatBufferLine &RightOut, const ALfloat *InSamples, float2 *AccumSamples, const ALsizei OutPos, const ALsizei IrSize, MixHrtfFilter *hrtfparams, const ALsizei BufferSize); diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp index 4985933c..dd094040 100644 --- a/alc/mixer/mixer_c.cpp +++ b/alc/mixer/mixer_c.cpp @@ -189,20 +189,18 @@ void Mix_(const ALfloat *data, const al::span OutBuffer, * stepping is necessary. */ template<> -void MixRow_(ALfloat *OutBuffer, const al::span Gains, - const ALfloat *InSamples, const ALsizei InStride, const ALsizei BufferSize) +void MixRow_(const al::span OutBuffer, const al::span Gains, + const float *InSamples, const size_t InStride) { - ASSUME(BufferSize > 0); - - for(const ALfloat gain : Gains) + for(const float gain : Gains) { - const ALfloat *RESTRICT src{InSamples}; + const float *RESTRICT src{InSamples}; InSamples += InStride; if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - for(ALsizei i{0};i < BufferSize;i++) - OutBuffer[i] += src[i] * gain; + std::transform(OutBuffer.begin(), OutBuffer.end(), src, OutBuffer.begin(), + [gain](const ALfloat cur, const ALfloat src) -> ALfloat { return cur + src*gain; }); } } diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp index c6ea2c60..829d4ea1 100644 --- a/alc/mixer/mixer_neon.cpp +++ b/alc/mixer/mixer_neon.cpp @@ -276,11 +276,9 @@ void Mix_(const ALfloat *data, const al::span OutBuffe } template<> -void MixRow_(ALfloat *OutBuffer, const al::span Gains, - const ALfloat *InSamples, const ALsizei InStride, const ALsizei BufferSize) +void MixRow_(const al::span OutBuffer, const al::span Gains, + const ALfloat *InSamples, const ALsizei InStride) { - ASSUME(BufferSize > 0); - for(const ALfloat gain : Gains) { const ALfloat *RESTRICT src{InSamples}; @@ -289,20 +287,19 @@ void MixRow_(ALfloat *OutBuffer, const al::span Gains, if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - ALsizei pos{0}; - if LIKELY(BufferSize > 3) + auto out_iter = OutBuffer.begin(); + if(size_t todo{OutBuffer.size() >> 2}) { - ALsizei todo{BufferSize >> 2}; - float32x4_t gain4{vdupq_n_f32(gain)}; + const float32x4_t gain4{vdupq_n_f32(gain)}; do { - const float32x4_t val4 = vld1q_f32(&src[pos]); - float32x4_t dry4 = vld1q_f32(&OutBuffer[pos]); + const float32x4_t val4 = vld1q_f32(src); + float32x4_t dry4 = vld1q_f32(out_iter); dry4 = vmlaq_f32(dry4, val4, gain4); - vst1q_f32(&OutBuffer[pos], dry4); - pos += 4; + vst1q_f32(out_iter, dry4); + out_iter += 4; src += 4; } while(--todo); } - for(;pos < BufferSize;pos++) - OutBuffer[pos] += src[pos]*gain; + std::transform(out_iter, OutBuffer.end(), src, out_iter, + [gain](const ALfloat cur, const ALfloat src) -> ALfloat { return cur + src*gain; }); } } diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp index b5958c8e..b3454898 100644 --- a/alc/mixer/mixer_sse.cpp +++ b/alc/mixer/mixer_sse.cpp @@ -229,33 +229,30 @@ void Mix_(const ALfloat *data, const al::span OutBuffer } template<> -void MixRow_(ALfloat *OutBuffer, const al::span Gains, - const ALfloat *InSamples, const ALsizei InStride, const ALsizei BufferSize) +void MixRow_(const al::span OutBuffer, const al::span Gains, + const float *InSamples, const size_t InStride) { - ASSUME(BufferSize > 0); - - for(const ALfloat gain : Gains) + for(const float gain : Gains) { - const ALfloat *RESTRICT src{InSamples}; + const float *RESTRICT src{InSamples}; InSamples += InStride; if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD)) continue; - ALsizei pos{0}; - if LIKELY(BufferSize > 3) + auto out_iter = OutBuffer.begin(); + if(size_t todo{OutBuffer.size() >> 2}) { - ALsizei todo{BufferSize >> 2}; const __m128 gain4 = _mm_set1_ps(gain); do { - const __m128 val4{_mm_load_ps(&src[pos])}; - __m128 dry4{_mm_load_ps(&OutBuffer[pos])}; + const __m128 val4{_mm_load_ps(src)}; + __m128 dry4{_mm_load_ps(out_iter)}; dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4)); - _mm_store_ps(&OutBuffer[pos], dry4); - pos += 4; + _mm_store_ps(out_iter, dry4); + out_iter += 4; src += 4; } while(--todo); } - for(;pos < BufferSize;pos++) - OutBuffer[pos] += src[pos]*gain; + std::transform(out_iter, OutBuffer.end(), src, out_iter, + [gain](const ALfloat cur, const ALfloat src) -> ALfloat { return cur + src*gain; }); } } -- cgit v1.2.3