From ba700399da875640dd23a710eae5aaf178c7ed8a Mon Sep 17 00:00:00 2001 From: Vesa Date: Thu, 26 Jun 2014 13:15:20 +0300 Subject: [PATCH] basic_filters - even more optimization Use more efficient interpolation, optimize some calculations --- include/basic_filters.h | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/include/basic_filters.h b/include/basic_filters.h index e27766c3c..f026226a1 100644 --- a/include/basic_filters.h +++ b/include/basic_filters.h @@ -39,6 +39,7 @@ #include "Mixer.h" #include "templates.h" #include "lmms_constants.h" +#include "interpolation.h" //#include //#include @@ -498,21 +499,19 @@ public: { 320, 3200 }, { 500, 1000 }, { 320, 800 } }; + static const float freqRatio = 4.0f / 14000.0f; // Stretch Q/resonance m_vfq = _q/4.f; // frequency in lmms ranges from 1Hz to 14000Hz - const int vowel = (int)( floor( _freq/14000.f * 4.f ) ); - const float fract = ( _freq/14000.f * 4.f ) - - (float)vowel; + const float vowelf = _freq * freqRatio; + const int vowel = static_cast( vowelf ); + const float fract = vowelf - vowel; // interpolate between formant frequencies - const float f0 = _f[vowel+0][0] * ( 1.0f - fract ) + - _f[vowel+1][0] * ( fract ); - - const float f1 = _f[vowel+0][1] * ( 1.0f - fract ) + - _f[vowel+1][1] * ( fract ); + const float f0 = linearInterpolate( _f[vowel+0][0], _f[vowel+1][0], fract ); + const float f1 = linearInterpolate( _f[vowel+0][1], _f[vowel+1][1], fract ); m_vfa[0] = 1.0f - (1.0f/(m_sampleRate*4)) / ( (1.0f/(f0*2.0f*M_PI)) +