diff --git a/src/sfizz/EGDescription.h b/src/sfizz/EGDescription.h index e7a93d15..66c6c820 100644 --- a/src/sfizz/EGDescription.h +++ b/src/sfizz/EGDescription.h @@ -79,7 +79,7 @@ struct EGDescription */ float getAttack(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccAttack, attack) + normalizeCC(velocity)*vel2attack; + return ccSwitchedValue(ccValues, ccAttack, attack) + normalizeVelocity(velocity)*vel2attack; } /** * @brief Get the decay with possibly a CC modifier and a velocity modifier @@ -90,7 +90,7 @@ struct EGDescription */ float getDecay(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccDecay, decay) + normalizeCC(velocity)*vel2decay; + return ccSwitchedValue(ccValues, ccDecay, decay) + normalizeVelocity(velocity)*vel2decay; } /** * @brief Get the delay with possibly a CC modifier and a velocity modifier @@ -101,7 +101,7 @@ struct EGDescription */ float getDelay(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccDelay, delay) + normalizeCC(velocity)*vel2delay; + return ccSwitchedValue(ccValues, ccDelay, delay) + normalizeVelocity(velocity)*vel2delay; } /** * @brief Get the holding duration with possibly a CC modifier and a velocity modifier @@ -112,7 +112,7 @@ struct EGDescription */ float getHold(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccHold, hold) + normalizeCC(velocity)*vel2hold; + return ccSwitchedValue(ccValues, ccHold, hold) + normalizeVelocity(velocity)*vel2hold; } /** * @brief Get the release duration with possibly a CC modifier and a velocity modifier @@ -123,7 +123,7 @@ struct EGDescription */ float getRelease(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccRelease, release) + normalizeCC(velocity)*vel2release; + return ccSwitchedValue(ccValues, ccRelease, release) + normalizeVelocity(velocity)*vel2release; } /** * @brief Get the starting level with possibly a CC modifier and a velocity modifier @@ -145,7 +145,7 @@ struct EGDescription */ float getSustain(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { - return ccSwitchedValue(ccValues, ccSustain, sustain) + normalizeCC(velocity)*vel2sustain; + return ccSwitchedValue(ccValues, ccSustain, sustain) + normalizeVelocity(velocity)*vel2sustain; } LEAK_DETECTOR(EGDescription); }; diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index b847d757..295f5279 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -64,6 +64,20 @@ constexpr float normalizeCC(T ccValue) return static_cast(std::min(std::max(ccValue, static_cast(0)), static_cast(127))) / 127.0f; } +/** + * @brief Normalize a velocity between (T)0.0 and (T)1.0 + * + * @tparam T + * @param ccValue + * @return constexpr float + */ +template +constexpr float normalizeVelocity(T velocity) +{ + return normalizeCC(velocity); +} + + /** * @brief Normalize a percentage between 0 and 1 *