Mercurial > hg > devuvuzelator
view devuvuzelator.cpp @ 4:d90abfa9585a
* Adaptive method
author | Chris Cannam |
---|---|
date | Fri, 11 Jun 2010 15:38:44 +0100 |
parents | e621e794011f |
children | 5adad2ca3188 |
line wrap: on
line source
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ void Devuvuzelator::processSpectralFrame() { const int hs = m_fftsize/2 + 1; double *mags = (double *)alloca(hs * sizeof(double)); double *ratios = (double *)alloca(hs * sizeof(double)); for (int i = 0; i < hs; ++i) { ratios[i] = 1.0; 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; 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]) { const float filtersecs = 5.f; int filterlen = (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 (mags[i] > threshold) { double target = mags[i] - threshold; ratios[i] = (target / mags[i]); } else { ratios[i] = 0.0; } } } for (int i = 0; i < hs; ++i) { m_real[i] *= ratios[i]; m_imag[i] *= ratios[i]; } }