aboutsummaryrefslogtreecommitdiffstats
path: root/alc/mixer
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2020-05-01 15:16:35 -0700
committerChris Robinson <[email protected]>2020-05-01 21:14:41 -0700
commit3898b77dd6b3d0bd9fad6b4f65f15b3c5b44c39b (patch)
treee341e7e1edd179542c2ac82fd96008de333efd5c /alc/mixer
parent8acf16fc820c1b36b5364bcf17cf4f96a27fedef (diff)
Avoid iterators for the main mixer
Diffstat (limited to 'alc/mixer')
-rw-r--r--alc/mixer/mixer_c.cpp20
-rw-r--r--alc/mixer/mixer_neon.cpp47
-rw-r--r--alc/mixer/mixer_sse.cpp47
3 files changed, 53 insertions, 61 deletions
diff --git a/alc/mixer/mixer_c.cpp b/alc/mixer/mixer_c.cpp
index 8a58ff10..b665b0a5 100644
--- a/alc/mixer/mixer_c.cpp
+++ b/alc/mixer/mixer_c.cpp
@@ -161,27 +161,25 @@ void Mix_<CTag>(const al::span<const float> InSamples, const al::span<FloatBuffe
float *CurrentGains, const float *TargetGains, const size_t Counter, const size_t OutPos)
{
const float delta{(Counter > 0) ? 1.0f / static_cast<float>(Counter) : 0.0f};
- const bool reached_target{InSamples.size() >= Counter};
- const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end();
+ const auto min_len = minz(Counter, InSamples.size());
for(FloatBufferLine &output : OutBuffer)
{
float *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
float gain{*CurrentGains};
- const float diff{*TargetGains - gain};
+ const float step{(*TargetGains-gain) * delta};
- auto in_iter = InSamples.begin();
- if(!(std::fabs(diff) > std::numeric_limits<float>::epsilon()))
+ size_t pos{0};
+ if(!(std::fabs(step) > std::numeric_limits<float>::epsilon()))
gain = *TargetGains;
else
{
- const float step{diff * delta};
float step_count{0.0f};
- while(in_iter != min_end)
+ for(;pos != min_len;++pos)
{
- *(dst++) += *(in_iter++) * (gain + step*step_count);
+ dst[pos] += InSamples[pos] * (gain + step*step_count);
step_count += 1.0f;
}
- if(reached_target)
+ if(pos == Counter)
gain = *TargetGains;
else
gain += step*step_count;
@@ -192,7 +190,7 @@ void Mix_<CTag>(const al::span<const float> InSamples, const al::span<FloatBuffe
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- while(in_iter != InSamples.end())
- *(dst++) += *(in_iter++) * gain;
+ for(;pos != InSamples.size();++pos)
+ dst[pos] += InSamples[pos] * gain;
}
}
diff --git a/alc/mixer/mixer_neon.cpp b/alc/mixer/mixer_neon.cpp
index b62213d4..6f58a72b 100644
--- a/alc/mixer/mixer_neon.cpp
+++ b/alc/mixer/mixer_neon.cpp
@@ -218,25 +218,22 @@ void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBu
float *CurrentGains, const float *TargetGains, const size_t Counter, const size_t OutPos)
{
const float delta{(Counter > 0) ? 1.0f / static_cast<float>(Counter) : 0.0f};
- const bool reached_target{InSamples.size() >= Counter};
- const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end();
- const auto aligned_end = minz(static_cast<uintptr_t>(min_end-InSamples.begin()+3) & ~3u,
- InSamples.size()) + InSamples.begin();
+ const auto min_len = minz(Counter, InSamples.size());
+ const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size());
for(FloatBufferLine &output : OutBuffer)
{
float *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
float gain{*CurrentGains};
- const float diff{*TargetGains - gain};
+ const float step{(*TargetGains-gain) * delta};
- auto in_iter = InSamples.begin();
- if(!(std::fabs(diff) > std::numeric_limits<float>::epsilon()))
+ size_t pos{0};
+ if(!(std::fabs(step) > std::numeric_limits<float>::epsilon()))
gain = *TargetGains;
else
{
- const float step{diff * delta};
float step_count{0.0f};
/* Mix with applying gain steps in aligned multiples of 4. */
- if(ptrdiff_t todo{(min_end-in_iter) >> 2})
+ if(size_t todo{(min_len-pos) >> 2})
{
const float32x4_t four4{vdupq_n_f32(4.0f)};
const float32x4_t step4{vdupq_n_f32(step)};
@@ -247,12 +244,12 @@ void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBu
step_count4 = vsetq_lane_f32(3.0f, step_count4, 3);
do {
- const float32x4_t val4 = vld1q_f32(in_iter);
- float32x4_t dry4 = vld1q_f32(dst);
+ const float32x4_t val4 = vld1q_f32(&InSamples[pos]);
+ float32x4_t dry4 = vld1q_f32(&dst[pos]);
dry4 = vmlaq_f32(dry4, val4, vmlaq_f32(gain4, step4, step_count4));
step_count4 = vaddq_f32(step_count4, four4);
- vst1q_f32(dst, dry4);
- in_iter += 4; dst += 4;
+ vst1q_f32(&dst[pos], dry4);
+ pos += 4;
} while(--todo);
/* NOTE: step_count4 now represents the next four counts after
* the last four mixed samples, so the lowest element
@@ -261,19 +258,19 @@ void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBu
step_count = vgetq_lane_f32(step_count4, 0);
}
/* Mix with applying left over gain steps that aren't aligned multiples of 4. */
- while(in_iter != min_end)
+ for(;pos != min_len;++pos)
{
- *(dst++) += *(in_iter++) * (gain + step*step_count);
+ dst[pos] += InSamples[pos] * (gain + step*step_count);
step_count += 1.0f;
}
- if(reached_target)
+ if(pos == Counter)
gain = *TargetGains;
else
gain += step*step_count;
/* Mix until pos is aligned with 4 or the mix is done. */
- while(in_iter != aligned_end)
- *(dst++) += *(in_iter++) * gain;
+ for(;pos != aligned_len;++pos)
+ dst[pos] += InSamples[pos] * gain;
}
*CurrentGains = gain;
++CurrentGains;
@@ -281,18 +278,18 @@ void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBu
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- if(ptrdiff_t todo{(InSamples.end()-in_iter) >> 2})
+ if(size_t todo{(InSamples.size()-pos) >> 2})
{
const float32x4_t gain4 = vdupq_n_f32(gain);
do {
- const float32x4_t val4 = vld1q_f32(in_iter);
- float32x4_t dry4 = vld1q_f32(dst);
+ const float32x4_t val4 = vld1q_f32(&InSamples[pos]);
+ float32x4_t dry4 = vld1q_f32(&dst[pos]);
dry4 = vmlaq_f32(dry4, val4, gain4);
- vst1q_f32(dst, dry4);
- in_iter += 4; dst += 4;
+ vst1q_f32(&dst[pos], dry4);
+ pos += 4;
} while(--todo);
}
- while(in_iter != InSamples.end())
- *(dst++) += *(in_iter++) * gain;
+ for(;pos != InSamples.size();++pos)
+ dst[pos] += InSamples[pos] * gain;
}
}
diff --git a/alc/mixer/mixer_sse.cpp b/alc/mixer/mixer_sse.cpp
index a3f93bf2..10c78d6d 100644
--- a/alc/mixer/mixer_sse.cpp
+++ b/alc/mixer/mixer_sse.cpp
@@ -191,40 +191,37 @@ void Mix_<SSETag>(const al::span<const float> InSamples, const al::span<FloatBuf
float *CurrentGains, const float *TargetGains, const size_t Counter, const size_t OutPos)
{
const float delta{(Counter > 0) ? 1.0f / static_cast<float>(Counter) : 0.0f};
- const bool reached_target{InSamples.size() >= Counter};
- const auto min_end = reached_target ? InSamples.begin() + Counter : InSamples.end();
- const auto aligned_end = minz(static_cast<uintptr_t>(min_end-InSamples.begin()+3) & ~3u,
- InSamples.size()) + InSamples.begin();
+ const auto min_len = minz(Counter, InSamples.size());
+ const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size());
for(FloatBufferLine &output : OutBuffer)
{
float *RESTRICT dst{al::assume_aligned<16>(output.data()+OutPos)};
float gain{*CurrentGains};
- const float diff{*TargetGains - gain};
+ const float step{(*TargetGains-gain) * delta};
- auto in_iter = InSamples.begin();
- if(!(std::fabs(diff) > std::numeric_limits<float>::epsilon()))
+ size_t pos{0};
+ if(!(std::fabs(step) > std::numeric_limits<float>::epsilon()))
gain = *TargetGains;
else
{
- const float step{diff * delta};
float step_count{0.0f};
/* Mix with applying gain steps in aligned multiples of 4. */
- if(ptrdiff_t todo{(min_end-in_iter) >> 2})
+ if(size_t todo{(min_len-pos) >> 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)};
do {
- const __m128 val4{_mm_load_ps(in_iter)};
- __m128 dry4{_mm_load_ps(dst)};
+ const __m128 val4{_mm_load_ps(&InSamples[pos])};
+ __m128 dry4{_mm_load_ps(&dst[pos])};
/* dry += val * (gain + step*step_count) */
dry4 = MLA4(dry4, val4, MLA4(gain4, step4, step_count4));
- _mm_store_ps(dst, dry4);
+ _mm_store_ps(&dst[pos], dry4);
step_count4 = _mm_add_ps(step_count4, four4);
- in_iter += 4; dst += 4;
+ pos += 4;
} while(--todo);
/* NOTE: step_count4 now represents the next four counts after
* the last four mixed samples, so the lowest element
@@ -233,19 +230,19 @@ void Mix_<SSETag>(const al::span<const float> InSamples, const al::span<FloatBuf
step_count = _mm_cvtss_f32(step_count4);
}
/* Mix with applying left over gain steps that aren't aligned multiples of 4. */
- while(in_iter != min_end)
+ for(;pos != min_len;++pos)
{
- *(dst++) += *(in_iter++) * (gain + step*step_count);
+ dst[pos] += InSamples[pos] * (gain + step*step_count);
step_count += 1.0f;
}
- if(reached_target)
+ if(pos == Counter)
gain = *TargetGains;
else
gain += step*step_count;
/* Mix until pos is aligned with 4 or the mix is done. */
- while(in_iter != aligned_end)
- *(dst++) += *(in_iter++) * gain;
+ for(;pos != aligned_len;++pos)
+ dst[pos] += InSamples[pos] * gain;
}
*CurrentGains = gain;
++CurrentGains;
@@ -253,18 +250,18 @@ void Mix_<SSETag>(const al::span<const float> InSamples, const al::span<FloatBuf
if(!(std::fabs(gain) > GAIN_SILENCE_THRESHOLD))
continue;
- if(ptrdiff_t todo{(InSamples.end()-in_iter) >> 2})
+ if(size_t todo{(InSamples.size()-pos) >> 2})
{
const __m128 gain4{_mm_set1_ps(gain)};
do {
- const __m128 val4{_mm_load_ps(in_iter)};
- __m128 dry4{_mm_load_ps(dst)};
+ const __m128 val4{_mm_load_ps(&InSamples[pos])};
+ __m128 dry4{_mm_load_ps(&dst[pos])};
dry4 = _mm_add_ps(dry4, _mm_mul_ps(val4, gain4));
- _mm_store_ps(dst, dry4);
- in_iter += 4; dst += 4;
+ _mm_store_ps(&dst[pos], dry4);
+ pos += 4;
} while(--todo);
}
- while(in_iter != InSamples.end())
- *(dst++) += *(in_iter++) * gain;
+ for(;pos != InSamples.size();++pos)
+ dst[pos] += InSamples[pos] * gain;
}
}