From ee056bcea828e373605ec1cdd81d53dd421472b3 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Sun, 15 Nov 2020 11:27:34 +0100 Subject: [PATCH] Use SIMD helpers for zero-filling --- src/sfizz/BeatClock.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/sfizz/BeatClock.cpp b/src/sfizz/BeatClock.cpp index 154cf138..32e997c7 100644 --- a/src/sfizz/BeatClock.cpp +++ b/src/sfizz/BeatClock.cpp @@ -5,6 +5,7 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "BeatClock.h" +#include "SIMDHelpers.h" #include "Config.h" #include "Debug.h" #include @@ -161,18 +162,18 @@ void BeatClock::fillBufferUpTo(unsigned delay) int *beatNumberData = runningBeatNumber_.data(); float *beatNumberPosition = runningBeatPosition_.data(); int *beatsPerBarData = runningBeatsPerBar_.data(); - unsigned fill = currentCycleFill_; + unsigned fillIdx = currentCycleFill_; const TimeSignature sig = timeSig_; - for (unsigned i = fill; i < delay; ++i) + for (unsigned i = fillIdx; i < delay; ++i) beatsPerBarData[i] = sig.beatsPerBar; if (!isPlaying_) { - for (; fill < delay; ++fill) { - beatNumberData[fill] = 0; - beatNumberPosition[fill] = 0; + if (fillIdx < delay) { + fill(absl::MakeSpan(&beatNumberData[fillIdx], delay - fillIdx), 0); + fill(absl::MakeSpan(&beatNumberPosition[fillIdx], delay - fillIdx), 0.0f); } - currentCycleFill_ = fill; + currentCycleFill_ = fillIdx; return; } @@ -182,18 +183,18 @@ void BeatClock::fillBufferUpTo(unsigned delay) const BBT hostPos = lastHostPos_; bool mustApplyHostPos = mustApplyHostPos_; - for (; fill < delay; ++fill) { + for (; fillIdx < delay; ++fillIdx) { clientPos = BBT::fromBeats(sig, clientPos.toBeats(sig) + beatsPerFrame); clientPos = mustApplyHostPos ? hostPos : clientPos; mustApplyHostPos = false; // quantization to nearest for prevention of rounding errors double beats = clientPos.toBeats(sig); - beatNumberData[fill] = dequantize(quantize(beats)); - beatNumberPosition[fill] = static_cast(beats); + beatNumberData[fillIdx] = dequantize(quantize(beats)); + beatNumberPosition[fillIdx] = static_cast(beats); } - currentCycleFill_ = fill; + currentCycleFill_ = fillIdx; lastClientPos_ = clientPos; mustApplyHostPos_ = mustApplyHostPos; }