From 2021ac6396fa34047ac55778532376c06a7062a4 Mon Sep 17 00:00:00 2001 From: paulfd Date: Mon, 9 Sep 2019 22:15:35 +0200 Subject: [PATCH] Added boundary checks for the velocity curves --- sfizz/Region.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/sfizz/Region.cpp b/sfizz/Region.cpp index 72ab7272..5aea56e9 100644 --- a/sfizz/Region.cpp +++ b/sfizz/Region.cpp @@ -749,12 +749,13 @@ float sfz::Region::velocityCurve(uint8_t velocity) const noexcept float segmentEndpoints { after->second - before->second }; gain *= relativePositionInSegment * segmentEndpoints; } else { // Standard velocity curve - const float floatVelocity { static_cast(velocity) / 127 }; + const float floatVelocity { static_cast(velocity) / 127.0f }; + // FIXME: Maybe there's a prettier way to check the boundaries? const float gaindB = [&]() { - if (ampVeltrack > 0) - return 40 * std::log(floatVelocity) / std::log(10.0f); - else - return 40 * std::log(1 - floatVelocity) / std::log(10.0f); + if (ampVeltrack >= 0) + return floatVelocity == 0.0f ? -90.0f : 40 * std::log(floatVelocity) / std::log(10.0f); + else + return floatVelocity == 1.0f ? -90.0f : 40 * std::log(1 - floatVelocity) / std::log(10.0f); }(); gain *= db2mag( gaindB * std::abs(ampVeltrack) / sfz::Default::ampVeltrackRange.getEnd()); }