Mercurial > hg > devuvuzelator
view devuvuzelator.cpp @ 8:e15ebd222c63
* (Messy) fixes to VST (e.g. for in-place buffers)
author | Chris Cannam |
---|---|
date | Fri, 11 Jun 2010 20:20:20 +0100 |
parents | 5adad2ca3188 |
children | a1539d4e3b08 |
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); */ double threshold = 0.0; if (mags[i] > threshold && mags[i] > 0.0) { 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]; } }