diff --git a/SpiralSound/Plugins/FilterPlugin/FilterPlugin.C b/SpiralSound/Plugins/FilterPlugin/FilterPlugin.C index ad1835b..df360ea 100644 --- a/SpiralSound/Plugins/FilterPlugin/FilterPlugin.C +++ b/SpiralSound/Plugins/FilterPlugin/FilterPlugin.C @@ -113,58 +113,70 @@ SpiralGUIType *FilterPlugin::CreateGUI() void FilterPlugin::Execute() { float Cutoff; - float Resonance; + float Resonance; + float out, in; - if (fc<0) return; + if (fc<0) return; - for (int n=0; nBUFSIZE; n++) + for (int n=0; nBUFSIZE; n++) { - coef = iir.coef + 1; /* Skip k, or gain */ - k=0.25; + + //reset memory if disconnected, and skip out (prevents CPU spike) + if (! InputExists(0)) + { + out = 0; + } + else + { + in = GetInput(0,n); + + // work around denormal calculation CPU spikes where in --> 0 + if ((in >= 0) && (in < 0.000000001)) + in += 0.000000001; + else + if ((in <= 0) && (in > -0.000000001)) + in -= 0.000000001; + + coef = iir.coef + 1; /* Skip k, or gain */ + k=0.25; - Cutoff = fc + (GetInput(1,n) * 1000); - Resonance = Q + GetInput(2,n); + Cutoff = fc + (GetInput(1,n) * 1000); + Resonance = Q + GetInput(2,n); - Cutoff/=2; + Cutoff/=2; - if (Resonance>MAX_RES) Resonance=MAX_RES; - if (Cutoff>MAX_CUTOFF) Cutoff=MAX_CUTOFF; - if (ResonanceMAX_RES) Resonance=MAX_RES; + if (Cutoff>MAX_CUTOFF) Cutoff=MAX_CUTOFF; + if (ResonanceSet(n,0); - //} - } - + out = iir_filter(in/0.5f,&iir); + } + + SetOutput(0,n,out); + } } void FilterPlugin::StreamOut(ostream &s) @@ -182,16 +194,16 @@ void FilterPlugin::StreamIn(istream &s) void FilterPlugin::SetupCoeffs() { ProtoCoef[0].a0 = 1.0; - ProtoCoef[0].a1 = 0; - ProtoCoef[0].a2 = 0; - ProtoCoef[0].b0 = 1.0; - ProtoCoef[0].b1 = 0.765367; - ProtoCoef[0].b2 = 1.0; - - ProtoCoef[1].a0 = 1.0; - ProtoCoef[1].a1 = 0; - ProtoCoef[1].a2 = 0; - ProtoCoef[1].b0 = 1.0; - ProtoCoef[1].b1 = 1.847759; - ProtoCoef[1].b2 = 1.0; + ProtoCoef[0].a1 = 0; + ProtoCoef[0].a2 = 0; + ProtoCoef[0].b0 = 1.0; + ProtoCoef[0].b1 = 0.765367; + ProtoCoef[0].b2 = 1.0; + + ProtoCoef[1].a0 = 1.0; + ProtoCoef[1].a1 = 0; + ProtoCoef[1].a2 = 0; + ProtoCoef[1].b0 = 1.0; + ProtoCoef[1].b1 = 1.847759; + ProtoCoef[1].b2 = 1.0; } diff --git a/SpiralSound/Plugins/FormantFilterPlugin/FormantFilterPlugin.C b/SpiralSound/Plugins/FormantFilterPlugin/FormantFilterPlugin.C index eee48d3..4492052 100644 --- a/SpiralSound/Plugins/FormantFilterPlugin/FormantFilterPlugin.C +++ b/SpiralSound/Plugins/FormantFilterPlugin/FormantFilterPlugin.C @@ -140,6 +140,13 @@ void FormantFilterPlugin::Execute() { in = GetInput(0,n); + // work around denormal calculation CPU spikes where in --> 0 + if ((in >= 0) && (in < 0.000000001)) + in += 0.000000001; + else + if ((in <= 0) && (in > -0.000000001)) + in -= 0.000000001; + for (int v=0; v<5; v++) { res= (float) (coeff[v][0]*(in*0.1f) + @@ -174,11 +181,30 @@ void FormantFilterPlugin::Execute() } // mix between vowel sounds - if (m_Vowel<1) out=Linear(0,1,m_Vowel,o[1],o[0]); - else if (m_Vowel>1 && m_Vowel<2) out=Linear(0,1,m_Vowel-1.0f,o[2],o[1]); - else if (m_Vowel>2 && m_Vowel<3) out=Linear(0,1,m_Vowel-2.0f,o[3],o[2]); - else if (m_Vowel>3 && m_Vowel<4) out=Linear(0,1,m_Vowel-3.0f,o[4],o[3]); - else if (m_Vowel==4) out=o[4]; + if (m_Vowel<1) + { + out=Linear(0,1,m_Vowel,o[1],o[0]); + } + else + if (m_Vowel>1 && m_Vowel<2) + { + out=Linear(0,1,m_Vowel-1.0f,o[2],o[1]); + } + else + if (m_Vowel>2 && m_Vowel<3) + { + out=Linear(0,1,m_Vowel-2.0f,o[3],o[2]); + } + else + if (m_Vowel>3 && m_Vowel<4) + { + out=Linear(0,1,m_Vowel-3.0f,o[4],o[3]); + } + else + if (m_Vowel==4) + { + out=o[4]; + } } SetOutput(0,n,out); }