From e04bf7e9b85797db90a36776581a381dd877a340 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Fri, 13 Dec 2019 14:13:46 +0100 Subject: [PATCH] Use rounding instead of truncating for a more natural behavior of the quantization at the edges of the relevant range --- src/sfizz/EventEnvelopes.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/sfizz/EventEnvelopes.cpp b/src/sfizz/EventEnvelopes.cpp index 20d56201..7e4efb01 100644 --- a/src/sfizz/EventEnvelopes.cpp +++ b/src/sfizz/EventEnvelopes.cpp @@ -136,9 +136,8 @@ void LinearEnvelope::getQuantizedBlock(absl::Span output, Type quant ASSERT(quantizationStep != 0.0); int index { 0 }; - const auto halfStep = quantizationStep / 2; - auto quantize = [quantizationStep, halfStep](Type value) -> Type { - return static_cast((value + halfStep) / quantizationStep) * quantizationStep; + auto quantize = [quantizationStep](Type value) -> Type { + return std::round(value / quantizationStep) * quantizationStep; }; const auto outputSize = static_cast(output.size()); @@ -227,7 +226,7 @@ void MultiplicativeEnvelope::getQuantizedBlock(absl::Span output, Ty // log q log q // and log(b)\log(q) is between 0 and 1. auto quantize = [logStep](Type value) -> Type { - return std::exp(logStep * static_cast(std::log(value)/logStep)); + return std::exp(logStep * std::round(std::log(value)/logStep)); }; const auto outputSize = static_cast(output.size());