From 7ec5da9ddbc062bed40efd7058ef6916b9ffcbbc Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Tue, 8 Sep 2020 12:38:02 +0200 Subject: [PATCH 1/2] Memorize the flags to avoid a recurrent switch --- src/sfizz/modulations/ModKey.cpp | 5 ----- src/sfizz/modulations/ModKey.h | 7 +++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/sfizz/modulations/ModKey.cpp b/src/sfizz/modulations/ModKey.cpp index 5ba5e02c..bfdd198a 100644 --- a/src/sfizz/modulations/ModKey.cpp +++ b/src/sfizz/modulations/ModKey.cpp @@ -5,7 +5,6 @@ // If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz #include "ModKey.h" -#include "ModId.h" #include "../Debug.h" #include #include @@ -74,10 +73,6 @@ bool ModKey::isTarget() const noexcept return ModIds::isTarget(id_); } -int ModKey::flags() const noexcept -{ - return ModIds::flags(id_); -} std::string ModKey::toString() const { diff --git a/src/sfizz/modulations/ModKey.h b/src/sfizz/modulations/ModKey.h index 37b8b072..96ab3705 100644 --- a/src/sfizz/modulations/ModKey.h +++ b/src/sfizz/modulations/ModKey.h @@ -6,6 +6,7 @@ #pragma once #include "ModKeyHash.h" +#include "ModId.h" #include "../NumericId.h" #include @@ -24,7 +25,7 @@ public: ModKey() = default; explicit ModKey(ModId id, NumericId region = {}, Parameters params = {}) - : id_(id), region_(region), params_(params) {} + : id_(id), region_(region), params_(params), flags_(ModIds::flags(id_)) {} static ModKey createCC(uint16_t cc, uint8_t curve, uint8_t smooth, float value, float step); static ModKey createNXYZ(ModId id, NumericId region, uint8_t N = 0, uint8_t X = 0, uint8_t Y = 0, uint8_t Z = 0); @@ -34,10 +35,10 @@ public: const ModId& id() const noexcept { return id_; } NumericId region() const noexcept { return region_; } const Parameters& parameters() const noexcept { return params_; } + int flags() const noexcept { return flags_; } bool isSource() const noexcept; bool isTarget() const noexcept; - int flags() const noexcept; std::string toString() const; struct Parameters { @@ -73,6 +74,8 @@ private: NumericId region_; //! List of values which identify the key uniquely, along with the hash and region Parameters params_ {}; + // Memorize the flag + int flags_; }; } // namespace sfz From db9840c5bd7064974563e55478723e2f5ad7ccd8 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Tue, 8 Sep 2020 21:43:14 +0200 Subject: [PATCH 2/2] Put operator == in the constructor for the modkeyThis function is called alot, this seems to favor inlining --- src/sfizz/modulations/ModKey.cpp | 21 --------------------- src/sfizz/modulations/ModKey.h | 25 +++++++++++++++++++++---- src/sfizz/modulations/ModMatrix.cpp | 3 +-- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/src/sfizz/modulations/ModKey.cpp b/src/sfizz/modulations/ModKey.cpp index bfdd198a..c5ee2a37 100644 --- a/src/sfizz/modulations/ModKey.cpp +++ b/src/sfizz/modulations/ModKey.cpp @@ -7,7 +7,6 @@ #include "ModKey.h" #include "../Debug.h" #include -#include namespace sfz { @@ -31,16 +30,6 @@ ModKey::Parameters& ModKey::Parameters::operator=(const Parameters& other) noexc return *this; } -bool ModKey::Parameters::operator==(const Parameters& other) const noexcept -{ - return std::memcmp(this, &other, sizeof(*this)) == 0; -} - -bool ModKey::Parameters::operator!=(const Parameters& other) const noexcept -{ - return std::memcmp(this, &other, sizeof(*this)) != 0; -} - ModKey ModKey::createCC(uint16_t cc, uint8_t curve, uint8_t smooth, float value, float step) { ModKey::Parameters p; @@ -106,13 +95,3 @@ std::string ModKey::toString() const } // namespace sfz -bool sfz::ModKey::operator==(const ModKey &other) const noexcept -{ - return id_ == other.id_ && region_ == other.region_ && - parameters() == other.parameters(); -} - -bool sfz::ModKey::operator!=(const ModKey &other) const noexcept -{ - return !this->operator==(other); -} diff --git a/src/sfizz/modulations/ModKey.h b/src/sfizz/modulations/ModKey.h index 96ab3705..5fff0197 100644 --- a/src/sfizz/modulations/ModKey.h +++ b/src/sfizz/modulations/ModKey.h @@ -9,6 +9,7 @@ #include "ModId.h" #include "../NumericId.h" #include +#include namespace sfz { @@ -49,8 +50,15 @@ public: Parameters(Parameters&&) = delete; Parameters &operator=(Parameters&&) = delete; - bool operator==(const Parameters& other) const noexcept; - bool operator!=(const Parameters& other) const noexcept; + bool operator==(const Parameters& other) const noexcept + { + return std::memcmp(this, &other, sizeof(*this)) == 0; + } + + bool operator!=(const Parameters& other) const noexcept + { + return std::memcmp(this, &other, sizeof(*this)) != 0; + } union { //! Parameters if this key identifies a CC source @@ -64,8 +72,17 @@ public: }; public: - bool operator==(const ModKey &other) const noexcept; - bool operator!=(const ModKey &other) const noexcept; + bool operator==(const ModKey &other) const noexcept + { + return id_ == other.id_ && region_ == other.region_ && + parameters() == other.parameters(); + } + + bool operator!=(const ModKey &other) const noexcept + { + return !this->operator==(other); + } + private: //! Identifier diff --git a/src/sfizz/modulations/ModMatrix.cpp b/src/sfizz/modulations/ModMatrix.cpp index 9290ba2d..643f168d 100644 --- a/src/sfizz/modulations/ModMatrix.cpp +++ b/src/sfizz/modulations/ModMatrix.cpp @@ -364,8 +364,7 @@ float* ModMatrix::getModulation(TargetId targetId) } else { ASSERT(targetFlags & kModIsAdditive); - for (uint32_t i = 0; i < numFrames; ++i) - buffer[i] += sourceDepth * sourceBuffer[i]; + sfz::multiplyAdd1(sourceDepth, sourceBuffer, buffer); } } }