Mercurial > hg > devuvuzelator
annotate devuvuzelator.cpp @ 19:0cdedb2fab81 tip
* OS/X build fixes
author | Chris Cannam |
---|---|
date | Fri, 18 Jun 2010 11:18:49 +0100 |
parents | 366f678dea8c |
children |
rev | line source |
---|---|
Chris@0 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@0 | 2 |
Chris@9 | 3 #ifdef VST |
Chris@9 | 4 #include "devuvuzelator-vst.h" |
Chris@9 | 5 #else |
Chris@9 | 6 #ifdef LADSPA |
Chris@9 | 7 #include "devuvuzelator-ladspa.h" |
Chris@9 | 8 #else |
Chris@9 | 9 #error Need to define either VST or LADSPA |
Chris@9 | 10 #endif |
Chris@9 | 11 #endif |
Chris@9 | 12 |
Chris@0 | 13 void |
Chris@0 | 14 Devuvuzelator::processSpectralFrame() |
Chris@0 | 15 { |
Chris@2 | 16 double lowfun = m_fundamental - m_bandwidth/2; |
Chris@2 | 17 double highfun = m_fundamental + m_bandwidth/2; |
Chris@0 | 18 |
Chris@2 | 19 for (int h = 1; h <= m_harmonics; ++h) { |
Chris@0 | 20 |
Chris@1 | 21 double lowfreq = lowfun * h; |
Chris@1 | 22 double highfreq = highfun * h; |
Chris@0 | 23 |
Chris@11 | 24 int lowbin = int(0.5 + (m_fftsize * lowfreq) / m_sampleRate); |
Chris@11 | 25 int highbin = int(0.5 + (m_fftsize * highfreq) / m_sampleRate); |
Chris@1 | 26 |
Chris@4 | 27 for (int i = lowbin; i <= highbin; ++i) { |
Chris@9 | 28 |
Chris@11 | 29 double mag = sqrt(m_real[i] * m_real[i] + m_imag[i] * m_imag[i]); |
Chris@11 | 30 |
Chris@4 | 31 if (!m_medians[i]) { |
Chris@9 | 32 // allocation in RT context, sorry! but this happens only |
Chris@9 | 33 // the first time through |
Chris@9 | 34 int filterlen = (m_filtersecs * m_sampleRate) / m_increment; |
Chris@4 | 35 m_medians[i] = new MedianFilter<double>(filterlen); |
Chris@4 | 36 } |
Chris@4 | 37 |
Chris@11 | 38 m_medians[i]->push(mag); |
Chris@4 | 39 double threshold = m_medians[i]->getAt(m_reduction); |
Chris@8 | 40 |
Chris@11 | 41 if (mag > threshold && mag > 0.0) { |
Chris@11 | 42 double target = mag - threshold; |
Chris@11 | 43 double ratio = (target / mag); |
Chris@9 | 44 m_real[i] *= ratio; |
Chris@9 | 45 m_imag[i] *= ratio; |
Chris@4 | 46 } else { |
Chris@9 | 47 m_real[i] = 0.0; |
Chris@9 | 48 m_imag[i] = 0.0; |
Chris@0 | 49 } |
Chris@0 | 50 } |
Chris@0 | 51 } |
Chris@0 | 52 } |