Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/engine/enginefilterpansingle.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* FilterPan Single :
* + This delay will be applied on left channel following the
* leftDelayFrames parameter and on the right one by minus leftDelayFrames.
* + This delay is applied sample by sample and not on the full buffer.
*/

#ifndef ENGINEFILTERPANSINGLE_H
#define ENGINEFILTERPANSINGLE_H

Expand Down Expand Up @@ -31,6 +38,7 @@ class EngineFilterPanSingle {
virtual void process(const CSAMPLE* pIn, CSAMPLE* pOutput, double leftDelayFrames) {
double delayLeftSourceFrame;
double delayRightSourceFrame;

if (leftDelayFrames > 0) {
delayLeftSourceFrame = m_delayFrame + SIZE - leftDelayFrames;
delayRightSourceFrame = m_delayFrame + SIZE;
Expand All @@ -39,18 +47,23 @@ class EngineFilterPanSingle {
delayRightSourceFrame = m_delayFrame + SIZE + leftDelayFrames;
}

// put in samples into delay buffer:
// put in samples into delay buffer
m_buf[m_delayFrame * 2] = pIn[0];
m_buf[m_delayFrame * 2 + 1] = pIn[1];
// move the delay cursor forward
m_delayFrame = (m_delayFrame + 1) % SIZE;

double modLeft = fmod(delayLeftSourceFrame, 1);
double modRight = fmod(delayRightSourceFrame, 1);

pOutput[0] = m_buf[(static_cast<int>(floor(delayLeftSourceFrame)) % SIZE) * 2] * (1 - modLeft);
pOutput[1] = m_buf[(static_cast<int>(floor(delayRightSourceFrame)) % SIZE) * 2 + 1] * (1 - modRight);
pOutput[0] += m_buf[(static_cast<int>(ceil(delayLeftSourceFrame)) % SIZE) * 2] * modLeft;
pOutput[1] += m_buf[(static_cast<int>(ceil(delayRightSourceFrame)) % SIZE) * 2 + 1] * modRight;

// prepare coefficients for linear interpolation using a linear stretching
double timeBetweenFullSamplesLeft = fmod(delayLeftSourceFrame, 1);
double timeBetweenFullSamplesRight = fmod(delayRightSourceFrame, 1);

// applying the delay on left channel with linear interpolation between each sample
pOutput[0] = m_buf[(static_cast<int>(floor(delayLeftSourceFrame)) % SIZE) * 2] * (1 - timeBetweenFullSamplesLeft);
pOutput[0] += m_buf[(static_cast<int>(ceil(delayLeftSourceFrame)) % SIZE) * 2] * timeBetweenFullSamplesLeft;
// then on right channel
pOutput[1] = m_buf[(static_cast<int>(floor(delayRightSourceFrame)) % SIZE) * 2 + 1] * (1 - timeBetweenFullSamplesRight);
pOutput[1] += m_buf[(static_cast<int>(ceil(delayRightSourceFrame)) % SIZE) * 2 + 1] * timeBetweenFullSamplesRight;

m_doStart = false;
}

Expand Down