speed optimization with the channel levels in the server

This commit is contained in:
Volker Fischer 2020-06-23 18:07:14 +02:00
parent f3eb0b3baa
commit 68a9fc7c7e

View file

@ -1680,29 +1680,34 @@ bool CServer::CreateLevelsForAllConChannels ( const int i
// get a reference to the audio data // get a reference to the audio data
const CVector<int16_t>& vecsData = vecvecsData[j]; const CVector<int16_t>& vecsData = vecvecsData[j];
double dCurLevel = 0.0; // 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
int16_t sMax = 0;
if ( vecNumAudioChannels[j] == 1 ) if ( vecNumAudioChannels[j] == 1 )
{ {
// mono // mono
for ( i = 0; i < iServerFrameSizeSamples; i += 3 ) for ( i = 0; i < iServerFrameSizeSamples; i += 3 )
{ {
dCurLevel = std::max ( dCurLevel, fabs ( static_cast<double> ( vecsData[i] ) ) ); sMax = std::max ( sMax, vecsData[i] );
} }
} }
else else
{ {
// stereo: apply stereo-to-mono attenuation // stereo
for ( i = 0, k = 0; i < iServerFrameSizeSamples; i += 3, k += 6 ) for ( i = 0, k = 0; i < iServerFrameSizeSamples; i += 3, k += 6 ) // 2 * 3 = 6 -> stereo
{ {
double sMix = ( static_cast<double> ( vecsData[k] ) + vecsData[k + 1] ) / 2; // left/right channels separately
dCurLevel = std::max ( dCurLevel, fabs ( sMix ) ); sMax = std::max ( sMax, vecsData[k] );
sMax = std::max ( sMax, vecsData[k + 1] );
} }
} }
// smoothing // smoothing
const int iChId = vecChanIDsCurConChan[j]; const int iChId = vecChanIDsCurConChan[j];
dCurLevel = std::max ( dCurLevel, vecChannels[iChId].GetPrevLevel() * 0.5 ); const double dCurLevel = std::max ( static_cast<double> ( sMax ), vecChannels[iChId].GetPrevLevel() * 0.5 );
vecChannels[iChId].SetPrevLevel ( dCurLevel ); vecChannels[iChId].SetPrevLevel ( dCurLevel );
// logarithmic measure // logarithmic measure