diff --git a/src/bitvis.cpp b/src/bitvis.cpp index f36df66..44c58fe 100644 --- a/src/bitvis.cpp +++ b/src/bitvis.cpp @@ -39,6 +39,7 @@ CBitVis::CBitVis(int argc, char *argv[]) m_buf = NULL; m_bufsize = 0; m_fftbuf = NULL; + m_displaybuf = NULL; m_samplecounter = 0; m_nrffts = 0; } @@ -180,6 +181,7 @@ void CBitVis::ProcessAudio() { const int bins = 1024; const int lines = 46; + const float decay = 0.5; int samplerate; int samples; if ((samples = m_jackclient.GetAudio(m_buf, m_bufsize, samplerate)) > 0) @@ -191,6 +193,12 @@ void CBitVis::ProcessAudio() memset(m_fftbuf, 0, bins * sizeof(float)); } + if (!m_displaybuf) + { + m_displaybuf = new float[lines]; + memset(m_displaybuf, 0, lines * sizeof(float)); + } + int additions = 0; for (int i = 1; i < lines; i++) additions += i; @@ -214,7 +222,7 @@ void CBitVis::ProcessAudio() m_fftbuf[j] += cabsf(m_fft.m_outbuf[j]) / m_fft.m_bufsize; } - if (m_samplecounter % (samplerate / 20) == 0) + if (m_samplecounter % (samplerate / 30) == 0) { m_fft.ApplyWindow(); fftwf_execute(m_fft.m_plan); @@ -232,7 +240,8 @@ void CBitVis::ProcessAudio() for (int k = bin; k < bin + nrbins; k++) outval += m_fftbuf[k] / m_nrffts; - out += string(Clamp(Round32(outval * 300.0f), 1, 100), '|'); + m_displaybuf[j] = m_displaybuf[j] * decay + outval * (1.0f - decay); + out += string(Clamp(Round32(m_displaybuf[j] * 300.0f), 1, 100), '|'); out += '\n'; start = next; diff --git a/src/bitvis.h b/src/bitvis.h index 8eb2969..e5b7045 100644 --- a/src/bitvis.h +++ b/src/bitvis.h @@ -40,6 +40,7 @@ class CBitVis float* m_buf; int m_bufsize; float* m_fftbuf; + float* m_displaybuf; int m_samplecounter; int m_nrffts;