From c792d318e6a0ed54cdbcc3f6ecf9e0343a5c024e Mon Sep 17 00:00:00 2001 From: David Chocholaty Date: Sun, 24 Jul 2022 18:24:14 +0200 Subject: [PATCH] EngineFilterDelay: clamp wrong delay values This commit moves the correctness evaluation of the delay value into a setter and the set value is directly checked instead of calculated index values. --- src/engine/filters/enginefilterdelay.h | 33 ++++++-------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/src/engine/filters/enginefilterdelay.h b/src/engine/filters/enginefilterdelay.h index f52ff275dd4f..4b9832209ebd 100644 --- a/src/engine/filters/enginefilterdelay.h +++ b/src/engine/filters/enginefilterdelay.h @@ -29,6 +29,13 @@ class EngineFilterDelay : public EngineObjectConstIn { void setDelay(unsigned int delaySamples) { m_delaySamples = delaySamples; + + // When mixxx will support other channel count variants than stereo, + // the kMaxDelay has to be divisible by the number of channels. + // Otherwise, channels may be swapped. + VERIFY_OR_DEBUG_ASSERT(m_delaySamples <= SIZE - mixxx::kEngineChannelCount) { + m_delaySamples = SIZE - mixxx::kEngineChannelCount; + } } virtual void process(const CSAMPLE* pIn, CSAMPLE* pOutput, @@ -41,15 +48,6 @@ class EngineFilterDelay : public EngineObjectConstIn { // (but in math the result value is positive). int delaySourcePos = (m_delayPos + SIZE - m_delaySamples) % SIZE; - VERIFY_OR_DEBUG_ASSERT(delaySourcePos >= 0) { - SampleUtil::copy(pOutput, pIn, iBufferSize); - return; - } - VERIFY_OR_DEBUG_ASSERT(delaySourcePos <= static_cast(SIZE)) { - SampleUtil::copy(pOutput, pIn, iBufferSize); - return; - } - for (int i = 0; i < iBufferSize; ++i) { // put sample into delay buffer: m_buf[m_delayPos] = pIn[i]; @@ -68,23 +66,6 @@ class EngineFilterDelay : public EngineObjectConstIn { int delaySourcePos = (m_delayPos + SIZE - m_delaySamples + iBufferSize / 2) % SIZE; int oldDelaySourcePos = (m_delayPos + SIZE - m_oldDelaySamples) % SIZE; - VERIFY_OR_DEBUG_ASSERT(delaySourcePos >= 0) { - SampleUtil::copy(pOutput, pIn, iBufferSize); - return; - } - VERIFY_OR_DEBUG_ASSERT(delaySourcePos <= static_cast(SIZE)) { - SampleUtil::copy(pOutput, pIn, iBufferSize); - return; - } - VERIFY_OR_DEBUG_ASSERT(oldDelaySourcePos >= 0) { - SampleUtil::copy(pOutput, pIn, iBufferSize); - return; - } - VERIFY_OR_DEBUG_ASSERT(oldDelaySourcePos <= static_cast(SIZE)) { - SampleUtil::copy(pOutput, pIn, iBufferSize); - return; - } - double cross_mix = 0.0; double cross_inc = 2 / static_cast(iBufferSize);