Mercurial > hg > devuvuzelator
view devuvuzelator.cpp @ 19:0cdedb2fab81 tip
* OS/X build fixes
author | Chris Cannam |
---|---|
date | Fri, 18 Jun 2010 11:18:49 +0100 |
parents | 366f678dea8c |
children |
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() { 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 = int(0.5 + (m_fftsize * lowfreq) / m_sampleRate); int highbin = int(0.5 + (m_fftsize * highfreq) / m_sampleRate); for (int i = lowbin; i <= highbin; ++i) { double mag = sqrt(m_real[i] * m_real[i] + m_imag[i] * m_imag[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(mag); double threshold = m_medians[i]->getAt(m_reduction); if (mag > threshold && mag > 0.0) { double target = mag - threshold; double ratio = (target / mag); m_real[i] *= ratio; m_imag[i] *= ratio; } else { m_real[i] = 0.0; m_imag[i] = 0.0; } } } }