speed optimzation

This commit is contained in:
Volker Fischer 2009-02-13 21:28:39 +00:00
parent e6945fdf67
commit 85d37b53b5

View file

@ -29,30 +29,44 @@
// Input level meter implementation -------------------------------------------- // Input level meter implementation --------------------------------------------
void CSignalLevelMeter::Update ( CVector<double>& vecdAudio ) void CSignalLevelMeter::Update ( CVector<double>& vecdAudio )
{ {
// do the update for entire vector // get the vector size
const int iVecSize = vecdAudio.Size(); const int iVecSize = vecdAudio.Size();
for ( int i = 0; i < iVecSize; i++ ) // Get maximum of current block
//
// Speed optimization:
// - we only make use of the positive values and ignore the negative ones
// -> we do not need to call the fabs() function
// - we only evaluate every third sample
//
// With these speed optimizations we might loose some information in
// special cases but for the average music signals the following code
// should give good results.
//
double dMax = 0.0;
for ( int i = 0; i < iVecSize; i += 3 )
{ {
// norm of current audio sample if ( dMax < vecdAudio[i] )
const double dCurSig = fabs ( vecdAudio[i] ); {
dMax = vecdAudio[i];
}
}
// search for maximum. Decrease this max with time
// decrease max with time // decrease max with time
if ( dCurLevel >= METER_FLY_BACK ) if ( dCurLevel >= METER_FLY_BACK )
{ {
dCurLevel *= 0.9999; // TODO calculate factor from sample rate
dCurLevel *= 0.99;
} }
else else
{ {
dCurLevel = 0; dCurLevel = 0;
} }
// search for max // update current level -> only use maximum
if ( dCurSig > dCurLevel ) if ( dMax > dCurLevel )
{ {
dCurLevel = dCurSig; dCurLevel = dMax;
}
} }
} }