fixed: use a ringbuffer to avoid calling memmove on every sample

This commit is contained in:
Bob 2012-11-08 21:42:55 +01:00
parent c7e683ac29
commit d872a79a27
2 changed files with 15 additions and 4 deletions

View file

@ -27,6 +27,7 @@
Cfft::Cfft()
{
m_inbuf = NULL;
m_inbufpos = 0;
m_fftin = NULL;
m_outbuf = NULL;
m_window = NULL;
@ -69,6 +70,7 @@ void Cfft::Free()
fftw_free(m_outbuf);
delete[] m_window;
m_inbuf = NULL;
m_inbufpos = 0;
m_fftin = NULL;
m_outbuf = NULL;
m_window = NULL;
@ -83,10 +85,16 @@ void Cfft::Free()
void Cfft::ApplyWindow()
{
float* in = m_inbuf;
float* in = m_inbuf + m_inbufpos;
float* inend = m_inbuf + m_bufsize;
float* window = m_window;
float* out = m_fftin;
float* window = m_window;
while (in != inend)
*(out++) = *(in++) * *(window++);
in = m_inbuf;
inend = m_inbuf + m_inbufpos;
while (in != inend)
*(out++) = *(in++) * *(window++);
@ -94,7 +102,9 @@ void Cfft::ApplyWindow()
void Cfft::AddSample(float sample)
{
memmove(m_inbuf, m_inbuf + 1, (m_bufsize - 1) * sizeof(float));
m_inbuf[m_bufsize - 1] = sample;
m_inbuf[m_inbufpos] = sample;
m_inbufpos++;
if (m_inbufpos == m_bufsize)
m_inbufpos = 0;
}

View file

@ -34,6 +34,7 @@ class Cfft
void AddSample(float sample);
float* m_inbuf;
unsigned int m_inbufpos;
float* m_fftin;
float* m_window;
fftwf_complex* m_outbuf;