Skip to content

Commit

Permalink
EngineFilterDelay: clamp wrong delay values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
davidchocholaty committed Jul 26, 2022
1 parent 0d1dc9f commit 855be72
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions src/engine/filters/enginefilterdelay.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ 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.
const int maxDelaySamples = static_cast<int>(SIZE - mixxx::kEngineChannelCount);

VERIFY_OR_DEBUG_ASSERT(m_delaySamples <= maxDelaySamples) {
m_delaySamples = maxDelaySamples;
}
}

virtual void process(const CSAMPLE* pIn, CSAMPLE* pOutput,
Expand All @@ -41,15 +50,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<int>(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];
Expand All @@ -68,23 +68,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<int>(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<int>(SIZE)) {
SampleUtil::copy(pOutput, pIn, iBufferSize);
return;
}

double cross_mix = 0.0;
double cross_inc = 2 / static_cast<double>(iBufferSize);

Expand Down

0 comments on commit 855be72

Please sign in to comment.