From 90db129d60a8a3ec0ca0591f789d09ba777142ea Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 7 Mar 2022 17:32:13 -0800 Subject: [PATCH] Avoid a divide-by-zero in UhjDecoder::decodeStereo --- core/uhjfilter.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/uhjfilter.cpp b/core/uhjfilter.cpp index a56e25bf..7a68f1b1 100644 --- a/core/uhjfilter.cpp +++ b/core/uhjfilter.cpp @@ -191,14 +191,14 @@ void UhjDecoder::decodeStereo(const al::span samples, const size_t sampl */ const float wtarget{mWidthControl}; const float wcurrent{unlikely(mCurrentWidth < 0.0f) ? wtarget : mCurrentWidth}; - const float wstep{(wtarget - wcurrent) / static_cast(forwardSamples)}; - if(likely(wstep < 0.00001f)) + if(likely(wtarget == wcurrent) || unlikely(forwardSamples == 0)) { for(size_t i{0};i < samplesToDo+sFilterDelay;++i) - mD[i] = (left[i] - right[i]) * wtarget; + mD[i] = (left[i] - right[i]) * wcurrent; } else { + const float wstep{(wtarget - wcurrent) / static_cast(forwardSamples)}; float fi{0.0f}; size_t i{0}; for(;i < forwardSamples;++i) @@ -208,8 +208,8 @@ void UhjDecoder::decodeStereo(const al::span samples, const size_t sampl } for(;i < samplesToDo+sFilterDelay;++i) mD[i] = (left[i] - right[i]) * wtarget; + mCurrentWidth = wtarget; } - mCurrentWidth = wtarget; } float *RESTRICT woutput{al::assume_aligned<16>(samples[0])}; -- 2.11.4.GIT