From 81ee1f2e590d854447bf27527c2025b9fde2c309 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Thu, 7 May 2020 17:52:29 +0200 Subject: [PATCH] Add a tick method to the OPF --- src/sfizz/OnePoleFilter.h | 32 ++++++++++++++++++++------------ src/sfizz/Voice.cpp | 25 ++----------------------- src/sfizz/Voice.h | 16 ++++++++++++---- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/sfizz/OnePoleFilter.h b/src/sfizz/OnePoleFilter.h index 3e0ea5fc..9781b39e 100644 --- a/src/sfizz/OnePoleFilter.h +++ b/src/sfizz/OnePoleFilter.h @@ -57,18 +57,14 @@ public: void processLowpass(const Type* input, Type* output, unsigned size) { for (unsigned i = 0; i < size; ++i) { - const Type intermediate = G * (input[i] - state); - output[i] = intermediate + state; - state = output[i] + intermediate; + output[i] = tickLowpass(input[i]); } } void processHighpass(const Type* input, Type* output, unsigned size) { for (unsigned i = 0; i < size; ++i) { - const Type intermediate = G * (input[i] - state); - output[i] = input[i] - intermediate - state; - state += 2 * intermediate; + output[i] = tickHighpass(input[i]); } } @@ -76,9 +72,7 @@ public: { for (unsigned i = 0; i < size; ++i) { setGain(gain[i]); - const Type intermediate = G * (input[i] - state); - output[i] = intermediate + state; - state = output[i] + intermediate; + output[i] = tickLowpass(input[i]); } } @@ -86,12 +80,26 @@ public: { for (unsigned i = 0; i < size; ++i) { setGain(gain[i]); - const Type intermediate = G * (input[i] - state); - output[i] = input[i] - intermediate - state; - state += 2 * intermediate; + output[i] = tickHighpass(input[i]); } } + Type tickHighpass(const Type& input) + { + const Type intermediate = G * (input - state); + const Type output = input - intermediate - state; + state += 2 * intermediate; + return output; + } + + Type tickLowpass(const Type& input) + { + const Type intermediate = G * (input - state); + const Type output = intermediate + state; + state = output + intermediate; + return output; + } + void reset(Type value = 0.0) { state = value; diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index fc7bd4f0..4692930e 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -614,21 +614,6 @@ bool sfz::Voice::checkOffGroup(int delay, uint32_t group) noexcept return false; } -int sfz::Voice::getTriggerNumber() const noexcept -{ - return triggerNumber; -} - -float sfz::Voice::getTriggerValue() const noexcept -{ - return triggerValue; -} - -sfz::Voice::TriggerType sfz::Voice::getTriggerType() const noexcept -{ - return triggerType; -} - void sfz::Voice::reset() noexcept { state = State::idle; @@ -743,15 +728,9 @@ void sfz::Voice::updateChannelPowers(AudioSpan buffer) if (buffer.getNumFrames() == 0) return; - auto tempSpan = resources.bufferPool.getBuffer(buffer.getNumFrames()); - if (!tempSpan) - return; - for (unsigned i = 0; i < channelPowers.size(); ++i) { + const auto input = buffer.getConstSpan(i); for (unsigned s = 0; s < buffer.getNumFrames(); ++s) - (*tempSpan)[s] = std::abs(buffer.getConstSpan(i)[s]); - - channelPowerFilters[i].processLowpass(*tempSpan, *tempSpan); - channelPowers[i] = tempSpan->back(); + channelPowers[i] = channelPowerFilters[i].tickLowpass(std::abs(input[s])); } } diff --git a/src/sfizz/Voice.h b/src/sfizz/Voice.h index e3572c65..0a617a82 100644 --- a/src/sfizz/Voice.h +++ b/src/sfizz/Voice.h @@ -156,19 +156,19 @@ public: * * @return int */ - int getTriggerNumber() const noexcept; + constexpr int getTriggerNumber() const noexcept { return triggerNumber; } /** * @brief Get the value that triggered the voice (note velocity or cc value) * * @return float */ - float getTriggerValue() const noexcept; + constexpr float getTriggerValue() const noexcept { return triggerValue; } /** * @brief Get the type of trigger * * @return TriggerType */ - TriggerType getTriggerType() const noexcept; + constexpr TriggerType getTriggerType() const noexcept { return triggerType; } /** * @brief Reset the voice to its initial values @@ -220,7 +220,7 @@ public: * * @return */ - int getAge() const noexcept { return age; } + constexpr int getAge() const noexcept { return age; } Duration getLastDataDuration() const noexcept { return dataDuration; } Duration getLastAmplitudeDuration() const noexcept { return amplitudeDuration; } @@ -314,4 +314,12 @@ private: LEAK_DETECTOR(Voice); }; +constexpr bool sisterVoices(const Voice* lhs, const Voice* rhs) +{ + return lhs->getAge() == rhs->getAge() + && lhs->getTriggerNumber() == rhs->getTriggerNumber() + && lhs->getTriggerValue() == rhs->getTriggerValue() + && lhs->getTriggerType() == rhs->getTriggerType(); +} + } // namespace sfz