mirror of
https://github.com/ShaYmez/xlxd.git
synced 2024-12-23 18:15:46 -05:00
Improve circular buffer
This commit is contained in:
parent
adbea50027
commit
4ba6a77ecc
@ -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;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ private:
|
||||
float* m_taps;
|
||||
int m_tapsLength;
|
||||
float* m_buffer;
|
||||
int m_currentBufferPostion;
|
||||
int m_currentBufferPosition;
|
||||
};
|
||||
|
||||
#endif //cfirfilter_h
|
||||
|
Loading…
Reference in New Issue
Block a user