From ec021ae5de81977a8a6b9910d0b3f4a927820217 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Sat, 20 Mar 2021 22:12:36 +0100 Subject: [PATCH] Correcting w.r.t. comments --- src/sfizz/BeatClock.cpp | 5 ++--- src/sfizz/BeatClock.h | 2 +- src/sfizz/Smoothers.cpp | 13 +++++++++++++ src/sfizz/Smoothers.h | 9 +++++++++ src/sfizz/Synth.cpp | 2 +- 5 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/sfizz/BeatClock.cpp b/src/sfizz/BeatClock.cpp index bfef364b..2b1d635e 100644 --- a/src/sfizz/BeatClock.cpp +++ b/src/sfizz/BeatClock.cpp @@ -157,10 +157,9 @@ absl::Span BeatClock::getRunningBeatPosition() return absl::MakeConstSpan(runningBeatPosition_.data(), currentCycleFrames_); } -float BeatClock::getLastBeatPosition() const +double BeatClock::getLastBeatPosition() const { - double beats = lastClientPos_.toBeats(timeSig_); - return static_cast(beats); + return lastClientPos_.toBeats(timeSig_); } absl::Span BeatClock::getRunningBeatsPerBar() diff --git a/src/sfizz/BeatClock.h b/src/sfizz/BeatClock.h index 62ed3d81..a3fbc38d 100644 --- a/src/sfizz/BeatClock.h +++ b/src/sfizz/BeatClock.h @@ -145,7 +145,7 @@ public: * * @return float */ - float getLastBeatPosition() const; + double getLastBeatPosition() const; /** * @brief Get the Beats Per Frame object * diff --git a/src/sfizz/Smoothers.cpp b/src/sfizz/Smoothers.cpp index df17280e..dd6f0146 100644 --- a/src/sfizz/Smoothers.cpp +++ b/src/sfizz/Smoothers.cpp @@ -31,6 +31,12 @@ void OnePoleSmoother::setSmoothing(unsigned smoothValue, float sampleRate) void OnePoleSmoother::reset(float value) { filter.reset(value); + target_ = value; +} + +void OnePoleSmoother::resetToTarget() +{ + reset(target_); } void OnePoleSmoother::process(absl::Span input, absl::Span output, bool canShortcut) @@ -55,6 +61,8 @@ void OnePoleSmoother::process(absl::Span input, absl::Span o } else if (input.data() != output.data()) { copy(input, output); } + + target_ = input.back(); } /// @@ -76,6 +84,11 @@ void LinearSmoother::reset(float value) //framesToTarget_ = 0; } +void LinearSmoother::resetToTarget() +{ + reset(target_); +} + void LinearSmoother::process(absl::Span input, absl::Span output, bool canShortcut) { CHECK_SPAN_SIZES(input, output); diff --git a/src/sfizz/Smoothers.h b/src/sfizz/Smoothers.h index 0527e96d..8614f327 100644 --- a/src/sfizz/Smoothers.h +++ b/src/sfizz/Smoothers.h @@ -31,6 +31,10 @@ public: * @param value */ void reset(float value = 0.0f); + /** + * @brief Reset to the target value (the back of the last vector passed) + */ + void resetToTarget(); /** * @brief Process a span of data. Input and output can refer to the same * memory. @@ -47,6 +51,7 @@ public: private: bool smoothing { false }; OnePoleFilter filter {}; + float target_ { 0.0f }; }; /** @@ -70,6 +75,10 @@ public: * @param value */ void reset(float value = 0.0f); + /** + * @brief Reset to the target value (the back of the last vector passed) + */ + void resetToTarget(); /** * @brief Process a span of data. Input and output can refer to the same * memory. diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 69885d39..5d18dc6c 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -1312,7 +1312,7 @@ void Synth::timePosition(int delay, int bar, double barBeat) const auto newBeatPosition = newPosition.toBeats(impl.resources_.beatClock.getTimeSignature()); const auto currentBeatPosition = impl.resources_.beatClock.getLastBeatPosition(); const auto positionDifference = std::abs(newBeatPosition - currentBeatPosition); - const auto threshold = 2 * static_cast(impl.resources_.beatClock.getBeatsPerFrame()); + const auto threshold = 2 * impl.resources_.beatClock.getBeatsPerFrame(); if (positionDifference > threshold) impl.playheadMoved_ = true;