aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-08-20 04:16:44 -0700
committerChris Robinson <[email protected]>2019-08-20 04:16:44 -0700
commit102ef6cb3356ef81e2a392d3aa8bd6324eb3ff30 (patch)
tree2f661c63be78c7f611665b2fb5a29ff58813b543
parent4883091f5de278b7469790efa466df5d93d465b0 (diff)
Pass a span for the Mix function's input
-rw-r--r--alc/alu.h6
-rw-r--r--alc/effects/autowah.cpp4
-rw-r--r--alc/effects/chorus.cpp8
-rw-r--r--alc/effects/dedicated.cpp4
-rw-r--r--alc/effects/echo.cpp4
-rw-r--r--alc/effects/equalizer.cpp4
-rw-r--r--alc/effects/fshifter.cpp4
-rw-r--r--alc/effects/modulator.cpp4
-rw-r--r--alc/effects/pshifter.cpp4
-rw-r--r--alc/effects/reverb.cpp20
-rw-r--r--alc/effects/vmorpher.cpp11
-rw-r--r--alc/mixer/defs.h5
-rw-r--r--alc/mixer/mixer_c.cpp24
-rw-r--r--alc/mixer/mixer_neon.cpp54
-rw-r--r--alc/mixer/mixer_sse.cpp51
-rw-r--r--alc/mixvoice.cpp22
16 files changed, 110 insertions, 119 deletions
diff --git a/alc/alu.h b/alc/alu.h
index eba9ee0e..9765e113 100644
--- a/alc/alu.h
+++ b/alc/alu.h
@@ -314,9 +314,9 @@ struct ALvoice {
};
-using MixerFunc = void(*)(const ALfloat *InSamples, const al::span<FloatBufferLine> OutBuffer,
- ALfloat *CurrentGains, const ALfloat *TargetGains, const ALsizei Counter, const ALsizei OutPos,
- const ALsizei BufferSize);
+using MixerFunc = void(*)(const al::span<const float> InSamples,
+ const al::span<FloatBufferLine> OutBuffer, float *CurrentGains, const float *TargetGains,
+ const ALsizei Counter, const ALsizei OutPos);
using RowMixerFunc = void(*)(const al::span<float> OutBuffer, const al::span<const float> Gains,
const float *InSamples, const size_t InStride);
using HrtfMixerFunc = void(*)(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
diff --git a/alc/effects/autowah.cpp b/alc/effects/autowah.cpp
index f16c5ba5..10d69b6c 100644
--- a/alc/effects/autowah.cpp
+++ b/alc/effects/autowah.cpp
@@ -190,8 +190,8 @@ void ALautowahState::process(const ALsizei samplesToDo, const FloatBufferLine *R
mChans[c].Filter.z2 = z2;
/* Now, mix the processed sound data to the output. */
- MixSamples(mBufferOut, samplesOut, mChans[c].CurrentGains, mChans[c].TargetGains,
- samplesToDo, 0, samplesToDo);
+ MixSamples({mBufferOut, mBufferOut+samplesToDo}, samplesOut, mChans[c].CurrentGains,
+ mChans[c].TargetGains, samplesToDo, 0);
}
}
diff --git a/alc/effects/chorus.cpp b/alc/effects/chorus.cpp
index 5966d3bd..7b43962c 100644
--- a/alc/effects/chorus.cpp
+++ b/alc/effects/chorus.cpp
@@ -218,9 +218,8 @@ void ChorusState::process(const ALsizei samplesToDo, const FloatBufferLine *REST
for(ALsizei base{0};base < samplesToDo;)
{
const ALsizei todo = mini(256, samplesToDo-base);
- ALint moddelays[2][256];
- alignas(16) ALfloat temps[2][256];
+ ALint moddelays[2][256];
if(mWaveform == WaveForm::Sinusoid)
{
GetSinusoidDelays(moddelays[0], mLfoOffset, mLfoRange, mLfoScale, mDepth, mDelay,
@@ -237,6 +236,7 @@ void ChorusState::process(const ALsizei samplesToDo, const FloatBufferLine *REST
}
mLfoOffset = (mLfoOffset+todo) % mLfoRange;
+ alignas(16) ALfloat temps[2][256];
for(ALsizei i{0};i < todo;i++)
{
// Feed the buffer's input first (necessary for delays < 1).
@@ -262,8 +262,8 @@ void ChorusState::process(const ALsizei samplesToDo, const FloatBufferLine *REST
}
for(ALsizei c{0};c < 2;c++)
- MixSamples(temps[c], samplesOut, mGains[c].Current, mGains[c].Target, samplesToDo-base,
- base, todo);
+ MixSamples({temps[c], temps[c]+todo}, samplesOut, mGains[c].Current, mGains[c].Target,
+ samplesToDo-base, base);
base += todo;
}
diff --git a/alc/effects/dedicated.cpp b/alc/effects/dedicated.cpp
index 2e49658f..dc5e8527 100644
--- a/alc/effects/dedicated.cpp
+++ b/alc/effects/dedicated.cpp
@@ -88,8 +88,8 @@ void DedicatedState::update(const ALCcontext*, const ALeffectslot *slot, const E
void DedicatedState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRICT samplesIn, const ALsizei /*numInput*/, const al::span<FloatBufferLine> samplesOut)
{
- MixSamples(samplesIn[0].data(), samplesOut, mCurrentGains, mTargetGains, samplesToDo, 0,
- samplesToDo);
+ MixSamples({samplesIn[0].data(), samplesIn[0].data()+samplesToDo}, samplesOut, mCurrentGains,
+ mTargetGains, samplesToDo, 0);
}
diff --git a/alc/effects/echo.cpp b/alc/effects/echo.cpp
index d41c4f67..57279005 100644
--- a/alc/effects/echo.cpp
+++ b/alc/effects/echo.cpp
@@ -156,8 +156,8 @@ void EchoState::process(const ALsizei samplesToDo, const FloatBufferLine *RESTRI
mOffset = offset;
for(ALsizei c{0};c < 2;c++)
- MixSamples(mTempBuffer[c], samplesOut, mGains[c].Current, mGains[c].Target, samplesToDo, 0,
- samplesToDo);
+ MixSamples({mTempBuffer[c], mTempBuffer[c]+samplesToDo}, samplesOut, mGains[c].Current,
+ mGains[c].Target, samplesToDo, 0);
}
diff --git a/alc/effects/equalizer.cpp b/alc/effects/equalizer.cpp
index 12183814..27de12ad 100644
--- a/alc/effects/equalizer.cpp
+++ b/alc/effects/equalizer.cpp
@@ -167,8 +167,8 @@ void EqualizerState::process(const ALsizei samplesToDo, const FloatBufferLine *R
mChans[c].filter[2].process(mSampleBuffer, mSampleBuffer, samplesToDo);
mChans[c].filter[3].process(mSampleBuffer, mSampleBuffer, samplesToDo);
- MixSamples(mSampleBuffer, samplesOut, mChans[c].CurrentGains, mChans[c].TargetGains,
- samplesToDo, 0, samplesToDo);
+ MixSamples({mSampleBuffer, mSampleBuffer+samplesToDo}, samplesOut, mChans[c].CurrentGains,
+ mChans[c].TargetGains, samplesToDo, 0);
}
}
diff --git a/alc/effects/fshifter.cpp b/alc/effects/fshifter.cpp
index 7688c762..638325ec 100644
--- a/alc/effects/fshifter.cpp
+++ b/alc/effects/fshifter.cpp
@@ -222,8 +222,8 @@ void FshifterState::process(const ALsizei samplesToDo, const FloatBufferLine *RE
}
/* Now, mix the processed sound data to the output. */
- MixSamples(BufferOut, samplesOut, mGains[c].Current, mGains[c].Target,
- maxi(samplesToDo, 512), 0, samplesToDo);
+ MixSamples({BufferOut, BufferOut+samplesToDo}, samplesOut, mGains[c].Current,
+ mGains[c].Target, maxi(samplesToDo, 512), 0);
}
}
diff --git a/alc/effects/modulator.cpp b/alc/effects/modulator.cpp
index 8a6378cd..48022e15 100644
--- a/alc/effects/modulator.cpp
+++ b/alc/effects/modulator.cpp
@@ -160,8 +160,8 @@ void ModulatorState::process(const ALsizei samplesToDo, const FloatBufferLine *R
for(i = 0;i < td;i++)
temps[i] *= modsamples[i];
- MixSamples(temps, samplesOut, mChans[c].CurrentGains, mChans[c].TargetGains,
- samplesToDo-base, base, td);
+ MixSamples({temps, temps+td}, samplesOut, mChans[c].CurrentGains,
+ mChans[c].TargetGains, samplesToDo-base, base);
}
base += td;
diff --git a/alc/effects/pshifter.cpp b/alc/effects/pshifter.cpp
index 0ba0b496..e1181fe7 100644
--- a/alc/effects/pshifter.cpp
+++ b/alc/effects/pshifter.cpp
@@ -285,8 +285,8 @@ void PshifterState::process(const ALsizei samplesToDo, const FloatBufferLine *RE
mCount = count;
/* Now, mix the processed sound data to the output. */
- MixSamples(bufferOut, samplesOut, mCurrentGains, mTargetGains, maxi(samplesToDo, 512), 0,
- samplesToDo);
+ MixSamples({bufferOut, bufferOut+samplesToDo}, samplesOut, mCurrentGains, mTargetGains,
+ maxi(samplesToDo, 512), 0);
}
diff --git a/alc/effects/reverb.cpp b/alc/effects/reverb.cpp
index 5f8daabe..1e5cb861 100644
--- a/alc/effects/reverb.cpp
+++ b/alc/effects/reverb.cpp
@@ -427,16 +427,16 @@ struct ReverbState final : public EffectState {
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);
+ MixSamples(tmpspan, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], counter,
+ offset);
}
for(size_t c{0u};c < NUM_LINES;c++)
{
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);
+ MixSamples(tmpspan, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], counter,
+ offset);
}
}
@@ -456,10 +456,10 @@ struct ReverbState final : public EffectState {
* higher-order output.
*/
const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]};
- mAmbiSplitter[0][c].applyHfScale(mTempLine.data(), hfscale, todo);
+ mAmbiSplitter[0][c].applyHfScale(tmpspan.data(), hfscale, todo);
- MixSamples(mTempLine.data(), samplesOut, mEarly.CurrentGain[c],
- mEarly.PanGain[c], counter, offset, todo);
+ MixSamples(tmpspan, samplesOut, mEarly.CurrentGain[c], mEarly.PanGain[c], counter,
+ offset);
}
for(size_t c{0u};c < NUM_LINES;c++)
{
@@ -468,10 +468,10 @@ struct ReverbState final : public EffectState {
mLateSamples[0].size());
const ALfloat hfscale{(c==0) ? mOrderScales[0] : mOrderScales[1]};
- mAmbiSplitter[1][c].applyHfScale(mTempLine.data(), hfscale, todo);
+ mAmbiSplitter[1][c].applyHfScale(tmpspan.data(), hfscale, todo);
- MixSamples(mTempLine.data(), samplesOut, mLate.CurrentGain[c], mLate.PanGain[c],
- counter, offset, todo);
+ MixSamples(tmpspan, samplesOut, mLate.CurrentGain[c], mLate.PanGain[c], counter,
+ offset);
}
}
diff --git a/alc/effects/vmorpher.cpp b/alc/effects/vmorpher.cpp
index bf144abb..1f796786 100644
--- a/alc/effects/vmorpher.cpp
+++ b/alc/effects/vmorpher.cpp
@@ -279,14 +279,13 @@ void VmorpherState::process(const ALsizei samplesToDo, const FloatBufferLine *RE
vowelB[2].process(&samplesIn[c][base], mSampleBufferB, td);
vowelB[3].process(&samplesIn[c][base], mSampleBufferB, td);
- alignas(16) ALfloat samplesBlended[MAX_UPDATE_SAMPLES];
-
- for (ALsizei i{0};i < td;i++)
- samplesBlended[i] = lerp(mSampleBufferA[i], mSampleBufferB[i], lfo[i]);
+ alignas(16) ALfloat blended[MAX_UPDATE_SAMPLES];
+ for(ALsizei i{0};i < td;i++)
+ blended[i] = lerp(mSampleBufferA[i], mSampleBufferB[i], lfo[i]);
/* Now, mix the processed sound data to the output. */
- MixSamples(samplesBlended, samplesOut, mChans[c].CurrentGains, mChans[c].TargetGains,
- samplesToDo-base, base, td);
+ MixSamples({blended, blended+td}, samplesOut, mChans[c].CurrentGains,
+ mChans[c].TargetGains, samplesToDo-base, base);
}
base += td;
diff --git a/alc/mixer/defs.h b/alc/mixer/defs.h
index 1e5e68bb..9d4fd063 100644
--- a/alc/mixer/defs.h
+++ b/alc/mixer/defs.h
@@ -30,9 +30,8 @@ template<ResampleType TypeTag, InstSetType InstTag>
const ALfloat *Resample_(const InterpState *state, const ALfloat *RESTRICT src, ALsizei frac, ALint increment, ALfloat *RESTRICT dst, ALsizei dstlen);
template<InstSetType InstTag>
-void Mix_(const float *InSamples, const al::span<FloatBufferLine> OutBuffer, float *CurrentGains,
- const float *TargetGains, const ALsizei Counter, const ALsizei OutPos,
- const ALsizei BufferSize);
+void Mix_(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer,
+ float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos);
template<InstSetType InstTag>
void MixRow_(const al::span<float> OutBuffer, const al::span<const float> Gains,
const float *InSamples, const size_t InStride);
diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp
index 8b5c0f41..e7ca23d5 100644
--- a/alc/mixer/mixer_c.cpp
+++ b/alc/mixer/mixer_c.cpp
@@ -142,31 +142,29 @@ void MixDirectHrtf_<CTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
template<>
-void Mix_<CTag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffer,
- float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos,
- const ALsizei BufferSize)
+void Mix_<CTag>(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer,
+ float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos)
{
- ASSUME(BufferSize > 0);
-
const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f};
+ const bool reached_target{InSamples.size() >= static_cast<size_t>(Counter)};
+ const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end();
for(FloatBufferLine &output : OutBuffer)
{
- ALfloat *RESTRICT dst{output.data()+OutPos};
+ ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
ALfloat gain{*CurrentGains};
const ALfloat diff{*TargetGains - gain};
- ALsizei pos{0};
+ auto in_iter = InSamples.begin();
if(std::fabs(diff) > std::numeric_limits<float>::epsilon())
{
- ALsizei minsize{mini(BufferSize, Counter)};
const ALfloat step{diff * delta};
ALfloat step_count{0.0f};
- for(;pos < minsize;pos++)
+ while(in_iter != min_end)
{
- dst[pos] += InSamples[pos] * (gain + step*step_count);
+ *(dst++) += *(in_iter++) * (gain + step*step_count);
step_count += 1.0f;
}
- if(pos == Counter)
+ if(reached_target)
gain = *TargetGains;
else
gain += step*step_count;
@@ -177,8 +175,8 @@ void Mix_<CTag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffe
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- for(;pos < BufferSize;pos++)
- dst[pos] += InSamples[pos]*gain;
+ while(in_iter != InSamples.end())
+ *(dst++) += *(in_iter++) * gain;
}
}
diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp
index b80f8cf8..1c4466c2 100644
--- a/alc/mixer/mixer_neon.cpp
+++ b/alc/mixer/mixer_neon.cpp
@@ -189,27 +189,27 @@ void MixDirectHrtf_<NEONTag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut
template<>
-void Mix_<NEONTag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffer,
- float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos,
- const ALsizei BufferSize)
+void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer,
+ float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos)
{
- ASSUME(BufferSize > 0);
-
- const ALfloat delta{(Counter > 0) ? 1.0f/(ALfloat)Counter : 0.0f};
+ const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f};
+ const bool reached_target{InSamples.size() >= static_cast<size_t>(Counter)};
+ const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end();
+ const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3) +
+ InSamples.begin();
for(FloatBufferLine &output : OutBuffer)
{
ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
ALfloat gain{*CurrentGains};
const ALfloat diff{*TargetGains - gain};
- ALsizei pos{0};
+ auto in_iter = InSamples.begin();
if(std::fabs(diff) > std::numeric_limits<float>::epsilon())
{
- ALsizei minsize{mini(BufferSize, Counter)};
const ALfloat step{diff * delta};
ALfloat step_count{0.0f};
/* Mix with applying gain steps in aligned multiples of 4. */
- if LIKELY(minsize > 3)
+ if(ptrdiff_t todo{(min_end-in_iter) >> 2})
{
const float32x4_t four4{vdupq_n_f32(4.0f)};
const float32x4_t step4{vdupq_n_f32(step)};
@@ -220,15 +220,13 @@ void Mix_<NEONTag>(const float *InSamples, const al::span<FloatBufferLine> OutBu
vsetq_lane_f32(3.0f, vdupq_n_f32(0.0f), 3),
2), 1), 0
)};
- ALsizei todo{minsize >> 2};
-
do {
- const float32x4_t val4 = vld1q_f32(&InSamples[pos]);
- float32x4_t dry4 = vld1q_f32(&dst[pos]);
+ const float32x4_t val4 = vld1q_f32(in_iter);
+ float32x4_t dry4 = vld1q_f32(dst);
dry4 = vmlaq_f32(dry4, val4, vmlaq_f32(gain4, step4, step_count4));
step_count4 = vaddq_f32(step_count4, four4);
- vst1q_f32(&dst[pos], dry4);
- pos += 4;
+ vst1q_f32(dst, dry4);
+ in_iter += 4; dst += 4;
} while(--todo);
/* NOTE: step_count4 now represents the next four counts after
* the last four mixed samples, so the lowest element
@@ -237,41 +235,39 @@ void Mix_<NEONTag>(const float *InSamples, const al::span<FloatBufferLine> OutBu
step_count = vgetq_lane_f32(step_count4, 0);
}
/* Mix with applying left over gain steps that aren't aligned multiples of 4. */
- for(;pos < minsize;pos++)
+ while(in_iter != min_end)
{
- dst[pos] += InSamples[pos]*(gain + step*step_count);
+ *(dst++) += *(in_iter++) * (gain + step*step_count);
step_count += 1.0f;
}
- if(pos == Counter)
+ if(reached_target)
gain = *TargetGains;
else
gain += step*step_count;
*CurrentGains = gain;
/* Mix until pos is aligned with 4 or the mix is done. */
- minsize = mini(BufferSize, (pos+3)&~3);
- for(;pos < minsize;pos++)
- dst[pos] += InSamples[pos]*gain;
+ while(in_iter != aligned_end)
+ *(dst++) += *(in_iter++) * gain;
}
++CurrentGains;
++TargetGains;
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- if LIKELY(BufferSize-pos > 3)
+ if(ptrdiff_t todo{(InSamples.end()-in_iter) >> 2})
{
- ALsizei todo{(BufferSize-pos) >> 2};
const float32x4_t gain4 = vdupq_n_f32(gain);
do {
- const float32x4_t val4 = vld1q_f32(&InSamples[pos]);
- float32x4_t dry4 = vld1q_f32(&dst[pos]);
+ const float32x4_t val4 = vld1q_f32(in_iter);
+ float32x4_t dry4 = vld1q_f32(dst);
dry4 = vmlaq_f32(dry4, val4, gain4);
- vst1q_f32(&dst[pos], dry4);
- pos += 4;
+ vst1q_f32(dst, dry4);
+ in_iter += 4; dst += 4;
} while(--todo);
}
- for(;pos < BufferSize;pos++)
- dst[pos] += InSamples[pos]*gain;
+ while(in_iter != InSamples.end())
+ *(dst++) += *(in_iter++) * gain;
}
}
diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp
index bd0042a1..3c8204d2 100644
--- a/alc/mixer/mixer_sse.cpp
+++ b/alc/mixer/mixer_sse.cpp
@@ -145,43 +145,42 @@ void MixDirectHrtf_<SSETag>(FloatBufferLine &LeftOut, FloatBufferLine &RightOut,
template<>
-void Mix_<SSETag>(const float *InSamples, const al::span<FloatBufferLine> OutBuffer,
- float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos,
- const ALsizei BufferSize)
+void Mix_<SSETag>(const al::span<const float> InSamples, const al::span<FloatBufferLine> OutBuffer,
+ float *CurrentGains, const float *TargetGains, const ALsizei Counter, const ALsizei OutPos)
{
- ASSUME(BufferSize > 0);
-
const ALfloat delta{(Counter > 0) ? 1.0f / static_cast<ALfloat>(Counter) : 0.0f};
+ const bool reached_target{InSamples.size() >= static_cast<size_t>(Counter)};
+ const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end();
+ const auto aligned_end = minz(InSamples.size(), (min_end-InSamples.begin()+3) & ~3) +
+ InSamples.begin();
for(FloatBufferLine &output : OutBuffer)
{
ALfloat *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
ALfloat gain{*CurrentGains};
const ALfloat diff{*TargetGains - gain};
- ALsizei pos{0};
+ auto in_iter = InSamples.begin();
if(std::fabs(diff) > std::numeric_limits<float>::epsilon())
{
- ALsizei minsize{mini(BufferSize, Counter)};
const ALfloat step{diff * delta};
ALfloat step_count{0.0f};
/* Mix with applying gain steps in aligned multiples of 4. */
- if LIKELY(minsize > 3)
+ if(ptrdiff_t todo{(min_end-in_iter) >> 2})
{
const __m128 four4{_mm_set1_ps(4.0f)};
const __m128 step4{_mm_set1_ps(step)};
const __m128 gain4{_mm_set1_ps(gain)};
__m128 step_count4{_mm_setr_ps(0.0f, 1.0f, 2.0f, 3.0f)};
- ALsizei todo{minsize >> 2};
do {
- const __m128 val4{_mm_load_ps(&InSamples[pos])};
- __m128 dry4{_mm_load_ps(&dst[pos])};
+ const __m128 val4{_mm_load_ps(in_iter)};
+ __m128 dry4{_mm_load_ps(dst)};
#define MLA4(x, y, z) _mm_add_ps(x, _mm_mul_ps(y, z))
/* dry += val * (gain + step*step_count) */
dry4 = MLA4(dry4, val4, MLA4(gain4, step4, step_count4));
#undef MLA4
- _mm_store_ps(&dst[pos], dry4);
+ _mm_store_ps(dst, dry4);
step_count4 = _mm_add_ps(step_count4, four4);
- pos += 4;
+ in_iter += 4; dst += 4;
} while(--todo);
/* NOTE: step_count4 now represents the next four counts after
* the last four mixed samples, so the lowest element
@@ -190,41 +189,39 @@ void Mix_<SSETag>(const float *InSamples, const al::span<FloatBufferLine> OutBuf
step_count = _mm_cvtss_f32(step_count4);
}
/* Mix with applying left over gain steps that aren't aligned multiples of 4. */
- for(;pos < minsize;pos++)
+ while(in_iter != min_end)
{
- dst[pos] += InSamples[pos]*(gain + step*step_count);
+ *(dst++) += *(in_iter++) * (gain + step*step_count);
step_count += 1.0f;
}
- if(pos == Counter)
+ if(reached_target)
gain = *TargetGains;
else
gain += step*step_count;
*CurrentGains = gain;
/* Mix until pos is aligned with 4 or the mix is done. */
- minsize = mini(BufferSize, (pos+3)&~3);
- for(;pos < minsize;pos++)
- dst[pos] += InSamples[pos]*gain;
+ while(in_iter != aligned_end)
+ *(dst++) += *(in_iter++) * gain;
}
++CurrentGains;
++TargetGains;
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- if LIKELY(BufferSize-pos > 3)
+ if(ptrdiff_t todo{(InSamples.end()-in_iter) >> 2})
{
- ALsizei todo{(BufferSize-pos) >> 2};
const __m128 gain4{_mm_set1_ps(gain)};
do {
- const __m128 val4{_mm_load_ps(&InSamples[pos])};
- __m128 dry4{_mm_load_ps(&dst[pos])};
+ const __m128 val4{_mm_load_ps(in_iter)};
+ __m128 dry4{_mm_load_ps(dst)};
dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
- _mm_store_ps(&dst[pos], dry4);
- pos += 4;
+ _mm_store_ps(dst, dry4);
+ in_iter += 4; dst += 4;
} while(--todo);
}
- for(;pos < BufferSize;pos++)
- dst[pos] += InSamples[pos]*gain;
+ while(in_iter != InSamples.end())
+ *(dst++) += *(in_iter++) * gain;
}
}
diff --git a/alc/mixvoice.cpp b/alc/mixvoice.cpp
index 1fc5bd33..a44b6a10 100644
--- a/alc/mixvoice.cpp
+++ b/alc/mixvoice.cpp
@@ -762,19 +762,21 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc
SilentTarget : parms.Gains.Target};
const size_t outcount{Device->NumChannelsPerOrder[0]};
- MixSamples(samples, voice->mDirect.Buffer.first(outcount), parms.Gains.Current,
- TargetGains, Counter, OutPos, DstBufferSize);
+ MixSamples({samples, samples+DstBufferSize},
+ voice->mDirect.Buffer.first(outcount), parms.Gains.Current, TargetGains,
+ Counter, OutPos);
- ALfloat (&nfcsamples)[BUFFERSIZE] = Device->NfcSampleData;
+ const al::span<float> nfcsamples{Device->NfcSampleData,
+ static_cast<size_t>(DstBufferSize)};
size_t chanoffset{outcount};
using FilterProc = void (NfcFilter::*)(float*,const float*,int);
- auto apply_nfc = [voice,&parms,samples,TargetGains,DstBufferSize,Counter,OutPos,&chanoffset,&nfcsamples](const FilterProc process, const size_t outcount) -> void
+ auto apply_nfc = [voice,&parms,samples,TargetGains,DstBufferSize,Counter,OutPos,&chanoffset,nfcsamples](const FilterProc process, const size_t outcount) -> void
{
if(outcount < 1) return;
- (parms.NFCtrlFilter.*process)(nfcsamples, samples, DstBufferSize);
+ (parms.NFCtrlFilter.*process)(nfcsamples.data(), samples, DstBufferSize);
MixSamples(nfcsamples, voice->mDirect.Buffer.subspan(chanoffset, outcount),
parms.Gains.Current+chanoffset, TargetGains+chanoffset, Counter,
- OutPos, DstBufferSize);
+ OutPos);
chanoffset += outcount;
};
apply_nfc(&NfcFilter::process1, Device->NumChannelsPerOrder[1]);
@@ -785,8 +787,8 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc
{
const ALfloat *TargetGains{UNLIKELY(vstate == ALvoice::Stopping) ?
SilentTarget : parms.Gains.Target};
- MixSamples(samples, voice->mDirect.Buffer, parms.Gains.Current, TargetGains,
- Counter, OutPos, DstBufferSize);
+ MixSamples({samples, samples+DstBufferSize}, voice->mDirect.Buffer,
+ parms.Gains.Current, TargetGains, Counter, OutPos);
}
}
@@ -802,8 +804,8 @@ void MixVoice(ALvoice *voice, ALvoice::State vstate, const ALuint SourceID, ALCc
const ALfloat *TargetGains{UNLIKELY(vstate==ALvoice::Stopping) ? SilentTarget :
parms.Gains.Target};
- MixSamples(samples, voice->mSend[send].Buffer, parms.Gains.Current, TargetGains,
- Counter, OutPos, DstBufferSize);
+ MixSamples({samples, samples+DstBufferSize}, voice->mSend[send].Buffer,
+ parms.Gains.Current, TargetGains, Counter, OutPos);
};
}
/* Update positions */