Mercurial > hg > devuvuzelator
view devuvuzelator.cpp @ 9:a1539d4e3b08
* Tidy code, start doc
author | Chris Cannam |
---|---|
date | Sat, 12 Jun 2010 13:08:33 +0100 |
parents | e15ebd222c63 |
children | 25580443645c |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ #ifdef VST #include "devuvuzelator-vst.h" #else #ifdef LADSPA #include "devuvuzelator-ladspa.h" #else #error Need to define either VST or LADSPA #endif #endif void Devuvuzelator::processSpectralFrame() { const int hs = m_fftsize/2 + 1; double *mags = (double *)alloca(hs * sizeof(double)); for (int i = 0; i < hs; ++i) { mags[i] = sqrt(m_real[i] * m_real[i] + m_imag[i] * m_imag[i]); } double lowfun = m_fundamental - m_bandwidth/2; double highfun = m_fundamental + m_bandwidth/2; int ix = 0; for (int h = 1; h <= m_harmonics; ++h) { double lowfreq = lowfun * h; double highfreq = highfun * h; int lowbin = 0.5 + (m_fftsize * lowfreq) / m_sampleRate; int highbin = 0.5 + (m_fftsize * highfreq) / m_sampleRate; for (int i = lowbin; i <= highbin; ++i) { if (!m_medians[i]) { // allocation in RT context, sorry! but this happens only // the first time through int filterlen = (m_filtersecs * m_sampleRate) / m_increment; m_medians[i] = new MedianFilter<double>(filterlen); } m_medians[i]->push(mags[i]); double threshold = m_medians[i]->getAt(m_reduction); if (ix++ == 2) { std::cerr << "threshold = " << threshold << std::endl; } if (mags[i] > threshold && mags[i] > 0.0) { double target = mags[i] - threshold; double ratio = (target / mags[i]); m_real[i] *= ratio; m_imag[i] *= ratio; } else { m_real[i] = 0.0; m_imag[i] = 0.0; } } } }