1
0
mirror of https://github.com/ShaYmez/xlxd.git synced 2024-12-24 10:50:26 -05:00

Improve circular buffer

This commit is contained in:
Geoffrey Merck 2020-02-03 22:23:10 +01:00
parent adbea50027
commit 4ba6a77ecc
2 changed files with 5 additions and 5 deletions

View File

@ -34,7 +34,7 @@ CFIRFilter::CFIRFilter(const float* taps, int tapsLength)
::memcpy(m_taps, taps, tapsLength * sizeof(float));
::memset(m_buffer, 0, tapsLength * sizeof(float));
m_currentBufferPostion = 0;
m_currentBufferPosition = m_tapsLength -1;
}
CFIRFilter::~CFIRFilter()
@ -46,15 +46,15 @@ CFIRFilter::~CFIRFilter()
inline float CFIRFilter::Process(float inputSample)
{
// Buffer latest sample
m_buffer[m_currentBufferPostion] = inputSample;
m_buffer[m_currentBufferPosition] = inputSample;
float outputSample = 0.0f;
for(int i = 0; i < m_tapsLength; i++)
{
outputSample += m_taps[i] * m_buffer[(m_currentBufferPostion + i) % m_tapsLength];
outputSample += m_taps[i] * m_buffer[(m_currentBufferPosition + i) % m_tapsLength];
}
m_currentBufferPostion = (m_currentBufferPostion + 1) % m_tapsLength;
m_currentBufferPosition = MAX(0, m_currentBufferPosition - 1);
return outputSample;
}

View File

@ -45,7 +45,7 @@ private:
float* m_taps;
int m_tapsLength;
float* m_buffer;
int m_currentBufferPostion;
int m_currentBufferPosition;
};
#endif //cfirfilter_h