Roy Vegard Ovesen:
I guess it is much more efficient to compare integers than comparing long strings like "double-exponential" every frame.
This commit is contained in:
parent
33b6694311
commit
4d8da078a4
2 changed files with 15 additions and 6 deletions
|
@ -607,7 +607,15 @@ FGDigitalFilter::FGDigitalFilter(SGPropertyNode *node)
|
||||||
} else if ( cname == "debug" ) {
|
} else if ( cname == "debug" ) {
|
||||||
debug = child->getBoolValue();
|
debug = child->getBoolValue();
|
||||||
} else if ( cname == "type" ) {
|
} else if ( cname == "type" ) {
|
||||||
filterType = cval;
|
if ( cval == "exponential" ) {
|
||||||
|
filterType = exponential;
|
||||||
|
} else if (cval == "double-exponential") {
|
||||||
|
filterType = doubleExponential;
|
||||||
|
} else if (cval == "moving-average") {
|
||||||
|
filterType = movingAverage;
|
||||||
|
} else if (cval == "noise-spike") {
|
||||||
|
filterType = noiseSpike;
|
||||||
|
}
|
||||||
} else if ( cname == "input" ) {
|
} else if ( cname == "input" ) {
|
||||||
input_prop = fgGetNode( child->getStringValue(), true );
|
input_prop = fgGetNode( child->getStringValue(), true );
|
||||||
} else if ( cname == "filter-time" ) {
|
} else if ( cname == "filter-time" ) {
|
||||||
|
@ -645,7 +653,7 @@ void FGDigitalFilter::update(double dt)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (filterType == "exponential")
|
if (filterType == exponential)
|
||||||
{
|
{
|
||||||
double alpha = 1 / ((Tf/dt) + 1);
|
double alpha = 1 / ((Tf/dt) + 1);
|
||||||
output.push_front(alpha * input[0] +
|
output.push_front(alpha * input[0] +
|
||||||
|
@ -656,7 +664,7 @@ void FGDigitalFilter::update(double dt)
|
||||||
}
|
}
|
||||||
output.resize(1);
|
output.resize(1);
|
||||||
}
|
}
|
||||||
else if (filterType == "double-exponential")
|
else if (filterType == doubleExponential)
|
||||||
{
|
{
|
||||||
double alpha = 1 / ((Tf/dt) + 1);
|
double alpha = 1 / ((Tf/dt) + 1);
|
||||||
output.push_front(alpha * alpha * input[0] +
|
output.push_front(alpha * alpha * input[0] +
|
||||||
|
@ -668,7 +676,7 @@ void FGDigitalFilter::update(double dt)
|
||||||
}
|
}
|
||||||
output.resize(2);
|
output.resize(2);
|
||||||
}
|
}
|
||||||
else if (filterType == "moving-average")
|
else if (filterType == movingAverage)
|
||||||
{
|
{
|
||||||
output.push_front(output[0] +
|
output.push_front(output[0] +
|
||||||
(input[0] - input.back()) / samples);
|
(input[0] - input.back()) / samples);
|
||||||
|
@ -678,7 +686,7 @@ void FGDigitalFilter::update(double dt)
|
||||||
}
|
}
|
||||||
output.resize(1);
|
output.resize(1);
|
||||||
}
|
}
|
||||||
else if (filterType == "noise-spike")
|
else if (filterType == noiseSpike)
|
||||||
{
|
{
|
||||||
double maxChange = rateOfChange * dt;
|
double maxChange = rateOfChange * dt;
|
||||||
|
|
||||||
|
|
|
@ -230,7 +230,8 @@ private:
|
||||||
double rateOfChange; // The maximum allowable rate of change [1/s]
|
double rateOfChange; // The maximum allowable rate of change [1/s]
|
||||||
deque <double> output;
|
deque <double> output;
|
||||||
deque <double> input;
|
deque <double> input;
|
||||||
string filterType;
|
enum filterTypes { exponential, doubleExponential, movingAverage, noiseSpike };
|
||||||
|
filterTypes filterType;
|
||||||
|
|
||||||
bool debug;
|
bool debug;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue