Mercurial > hg > devuvuzelator
diff devuvuzelator-vst.cpp @ 1:0d2126c32309
* split out core code, fix some things
author | Chris Cannam |
---|---|
date | Fri, 11 Jun 2010 10:31:29 +0100 |
parents | fe4c331213c5 |
children | e621e794011f |
line wrap: on
line diff
--- a/devuvuzelator-vst.cpp Thu Jun 10 21:39:32 2010 +0100 +++ b/devuvuzelator-vst.cpp Fri Jun 11 10:31:29 2010 +0100 @@ -64,8 +64,8 @@ float *m_input; float *m_output; + float m_low; float m_high; - float m_low; float m_fundamental; float m_bandwidth; float m_harmonics; @@ -82,34 +82,32 @@ double *m_window; }; +// VST params 0->1 + void Devuvuzelator::setParameter(VstInt32 index, float value) { - float *params[NumParams] = { - m_low, - m_high, - m_fundamental, - m_bandwidth, - m_harmonics, - m_reduction, - }; - - *params[index] = value; + switch (index) { + case 0: m_low = -80 + 80 * value; break; + case 1: m_high = -80 + 80 * value; break; + case 2: m_fundamental = 110 + 440 * value; break; + case 3: m_bandwidth = 20 + 80 * value; break; + case 4: m_harmonics = int(value * 6 + 0.5); break; + case 5: m_reduction = 20 * value; break; + } } float Devuvuzelator::getParameter(VstInt32 index) { - float *params[NumParams] = { - m_low, - m_high, - m_fundamental, - m_bandwidth, - m_harmonics, - m_reduction, - }; - - return *params[index]; + switch (index) { + case 0: return (m_low + 80) / 80; + case 1: return (m_high + 80) / 80; + case 2: return (m_fundamental - 110) / 440; + case 3: return (m_bandwidth - 20) / 80; + case 4: return (m_harmonics / 6.0); + case 5: return m_reduction / 20; + } } // NB! The max name length for VST parameter names, labels @@ -134,7 +132,16 @@ void Devuvuzelator::getParameterDisplay(VstInt32 index, char *label) { - snprintf(label, kVstMaxParamStrLen, "%f", getParameter(index)); + float *params[NumParams] = { + m_low, + m_high, + m_fundamental, + m_bandwidth, + m_harmonics, + m_reduction, + }; + + snprintf(label, kVstMaxParamStrLen, "%f", *params[index]); } void @@ -277,71 +284,6 @@ } } -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 low = -35; - double high = -20; - - if (m_low) low = *m_low; - if (m_high) high = *m_high; - - int harmonics = 3; - if (m_harmonics) harmonics = int(*m_harmonics + 0.5); - - double fun = 200; - if (m_fundamental) fun = *m_fundamental; - - double bw = 40; - if (m_bandwidth) bw = *m_bandwidth; - - double lowfun = fun - bw/2; - double highfun = fun + bw+2; - - double reduction = 10; - if (m_reduction) reduction = *m_reduction; - - for (int h = 0; h < harmonics; ++h) { - - double lowfreq = lowfun * (h+1); - double highfreq = highfun * (h+1); - - int lowbin = (m_fftsize * lowfreq) / m_sampleRate; - int highbin = (m_fftsize * highfreq) / m_sampleRate; - - for (int i = lowbin; i <= highbin; ++i) { - ratios[i] = 1.0; - double db = 10 * log10(mags[i]); - if (db > low && db < high) { - double r = reduction; - ratios[i] = pow(10, -r / 10); - } - } - } - - for (int i = 0; i < hs-1; ++i) { - if (ratios[i] == 1.0 && ratios[i+1] < 1.0) { - ratios[i] = (ratios[i+1] + 1) / 2; - } else if (ratios[i] < 1.0 && ratios[i+1] == 1.0) { - ratios[i+1] = (ratios[i] + 1) / 2; - ++i; - } - } - - for (int i = 0; i < hs; ++i) { - m_real[i] *= ratios[i]; - m_imag[i] *= ratios[i]; - } -} - // FFT implementation by Don Cross, public domain. // This version scales the forward transform. @@ -466,3 +408,5 @@ return new Devuvuzelator(audioMaster); } +#include "devuvuzelator.cpp" +