aboutsummaryrefslogtreecommitdiffstats
path: root/core/mixer/mixer_neon.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/mixer/mixer_neon.cpp')
-rw-r--r--core/mixer/mixer_neon.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/core/mixer/mixer_neon.cpp b/core/mixer/mixer_neon.cpp
index a3468926..f3d54fec 100644
--- a/core/mixer/mixer_neon.cpp
+++ b/core/mixer/mixer_neon.cpp
@@ -305,3 +305,80 @@ void Mix_<NEONTag>(const al::span<const float> InSamples, const al::span<FloatBu
dst[pos] += InSamples[pos] * gain;
}
}
+
+template<>
+void Mix_<NEONTag>(const al::span<const float> InSamples, float *OutBuffer, float &CurrentGain,
+ const float TargetGain, const size_t Counter)
+{
+ const float delta{(Counter > 0) ? 1.0f / static_cast<float>(Counter) : 0.0f};
+ const auto min_len = minz(Counter, InSamples.size());
+ const auto aligned_len = minz((min_len+3) & ~size_t{3}, InSamples.size()) - min_len;
+
+ float *RESTRICT dst{al::assume_aligned<16>(OutBuffer)};
+ float gain{CurrentGain};
+ const float step{(TargetGain-gain) * delta};
+
+ size_t pos{0};
+ if(!(std::abs(step) > std::numeric_limits<float>::epsilon()))
+ gain = TargetGain;
+ else
+ {
+ float step_count{0.0f};
+ /* Mix with applying gain steps in aligned multiples of 4. */
+ if(size_t todo{min_len >> 2})
+ {
+ const float32x4_t four4{vdupq_n_f32(4.0f)};
+ const float32x4_t step4{vdupq_n_f32(step)};
+ const float32x4_t gain4{vdupq_n_f32(gain)};
+ float32x4_t step_count4{vdupq_n_f32(0.0f)};
+ step_count4 = vsetq_lane_f32(1.0f, step_count4, 1);
+ step_count4 = vsetq_lane_f32(2.0f, step_count4, 2);
+ step_count4 = vsetq_lane_f32(3.0f, step_count4, 3);
+
+ do {
+ 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[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 represents the
+ * next step count to apply.
+ */
+ step_count = vgetq_lane_f32(step_count4, 0);
+ }
+ /* Mix with applying left over gain steps that aren't aligned multiples of 4. */
+ for(size_t leftover{min_len&3};leftover;++pos,--leftover)
+ {
+ dst[pos] += InSamples[pos] * (gain + step*step_count);
+ step_count += 1.0f;
+ }
+ if(pos == Counter)
+ gain = TargetGain;
+ else
+ gain += step*step_count;
+
+ /* Mix until pos is aligned with 4 or the mix is done. */
+ for(size_t leftover{aligned_len&3};leftover;++pos,--leftover)
+ dst[pos] += InSamples[pos] * gain;
+ }
+ CurrentGain = gain;
+
+ if(!(std::abs(gain) > GainSilenceThreshold))
+ return;
+ if(size_t todo{(InSamples.size()-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]);
+ dry4 = vmlaq_f32(dry4, val4, gain4);
+ vst1q_f32(&dst[pos], dry4);
+ pos += 4;
+ } while(--todo);
+ }
+ for(size_t leftover{(InSamples.size()-pos)&3};leftover;++pos,--leftover)
+ dst[pos] += InSamples[pos] * gain;
+}