Browse Source

Add Denormal CPU Spike Workaround via a minimal value threshhold,

this adds a minimal sound to the filters if it falls below the range the spike usually happens(for me). This prevents huge CPU overhead when using multiple Formants and Filter Plugins on slow lines.
master
aj_genius 21 years ago
parent
commit
241f31dbb9
2 changed files with 95 additions and 57 deletions
  1. +64
    -52
      SpiralSound/Plugins/FilterPlugin/FilterPlugin.C
  2. +31
    -5
      SpiralSound/Plugins/FormantFilterPlugin/FormantFilterPlugin.C

+ 64
- 52
SpiralSound/Plugins/FilterPlugin/FilterPlugin.C View File

@@ -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; n<m_HostInfo->BUFSIZE; n++)
for (int n=0; n<m_HostInfo->BUFSIZE; 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 (Resonance<MIN_RES) Resonance=MIN_RES;
if (Cutoff<MIN_CUTOFF) Cutoff=MIN_CUTOFF;
if (Resonance>MAX_RES) Resonance=MAX_RES;
if (Cutoff>MAX_CUTOFF) Cutoff=MAX_CUTOFF;
if (Resonance<MIN_RES) Resonance=MIN_RES;
if (Cutoff<MIN_CUTOFF) Cutoff=MIN_CUTOFF;
if (n%FILTERGRAN==0)
{
for (nInd = 0; nInd < iir.length; nInd++)
{
a2 = ProtoCoef[nInd].a2;
if (n%FILTERGRAN==0)
{
for (nInd = 0; nInd < iir.length; nInd++)
{
a2 = ProtoCoef[nInd].a2;
a0 = ProtoCoef[nInd].a0;
a1 = ProtoCoef[nInd].a1;
a0 = ProtoCoef[nInd].a0;
a1 = ProtoCoef[nInd].a1;
b0 = ProtoCoef[nInd].b0;
b1 = ProtoCoef[nInd].b1 / Resonance;
b2 = ProtoCoef[nInd].b2;
szxform(&a0, &a1, &a2, &b0, &b1, &b2, Cutoff*(Cutoff/1000.0f), fs, &k, coef);
coef += 4;
b0 = ProtoCoef[nInd].b0;
b1 = ProtoCoef[nInd].b1 / Resonance;
b2 = ProtoCoef[nInd].b2;
szxform(&a0, &a1, &a2, &b0, &b1, &b2, Cutoff*(Cutoff/1000.0f), fs, &k, coef);
coef += 4;

iir.coef[0] = k;
iir.coef[0] = k;
m_LastQ=Q;
m_LastFC=fc;
}
}
m_LastQ=Q;
m_LastFC=fc;
}
}
float in = GetInput(0,n);
//if (in!=0)
//{
SetOutput(0,n,iir_filter(in/0.5f,&iir));
//}
//else
//{
// m_Output[0]->Set(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;
}

+ 31
- 5
SpiralSound/Plugins/FormantFilterPlugin/FormantFilterPlugin.C View File

@@ -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);
}


Loading…
Cancel
Save