From 9764057ca76d04a2486b206991e5a16fa20d9d03 Mon Sep 17 00:00:00 2001 From: Iscle Date: Thu, 18 May 2023 01:05:27 +0200 Subject: [PATCH] Clamp floatToFloat accomulate result --- src/ViperContext.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ViperContext.cpp b/src/ViperContext.cpp index 390c7e7..7fab920 100644 --- a/src/ViperContext.cpp +++ b/src/ViperContext.cpp @@ -378,7 +378,7 @@ static const T& clamp(const T& v, const T& lo, const T& hi) { static void floatToFloat(float *dst, const float *src, size_t frameCount, bool accumulate) { if (accumulate) { for (size_t i = 0; i < frameCount * 2; i++) { - dst[i] += clamp(src[i], -1.0f, 1.0f); + dst[i] = clamp(dst[i] + src[i], -1.0f, 1.0f); } } else { memcpy(dst, src, frameCount * 2 * sizeof(float)); @@ -391,8 +391,7 @@ void floatToPcm(T *dst, const float *src, size_t frameCount, bool accumulate) { constexpr T min_val = std::numeric_limits::min(); for (size_t i = 0; i < frameCount * 2; i++) { - float f = clamp(src[i], -1.0f, 1.0f); - T pcm = static_cast(f * static_cast(max_val)); + T pcm = static_cast(src[i] * static_cast(max_val)); if (accumulate) { U temp = static_cast(dst[i]) + pcm; dst[i] = static_cast(clamp(temp, static_cast(min_val), static_cast(max_val)));