From 04da12c959b2950a24dc7eb67186a01cf13fa1b8 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Fri, 12 Jun 2009 16:06:45 +0000 Subject: [PATCH] speed optimzation, remove normalization value (I guess it is not needed...) --- src/server.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index 86b50d09..0e5b08f6 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -160,25 +160,34 @@ void CServer::OnTimer() CVector CServer::ProcessData ( CVector >& vecvecdData, CVector& vecdGains ) { - CVector vecsOutData ( MIN_SERVER_BLOCK_SIZE_SAMPLES ); + int i; + + // init return vector with zeros since we mix all channels on that vector + CVector vecsOutData ( MIN_SERVER_BLOCK_SIZE_SAMPLES, 0 ); const int iNumClients = vecvecdData.Size(); - // some offset to avoid overload when mixing clients together - const double dNorm = (double) 1.25; - // mix all audio data from all clients together - for ( int i = 0; i < MIN_SERVER_BLOCK_SIZE_SAMPLES; i++ ) + for ( int j = 0; j < iNumClients; j++ ) { - double dMixedData = 0.0; - - for ( int j = 0; j < iNumClients; j++ ) + // if channel gain is 1, avoid multiplication for speed optimization + if ( vecdGains[j] == static_cast ( 1.0 ) ) { - dMixedData += vecvecdData[j][i] * vecdGains[j]; + for ( int i = 0; i < MIN_SERVER_BLOCK_SIZE_SAMPLES; i++ ) + { + vecsOutData[i] = + Double2Short ( vecsOutData[i] + vecvecdData[j][i] ); + } + } + else + { + for ( int i = 0; i < MIN_SERVER_BLOCK_SIZE_SAMPLES; i++ ) + { + vecsOutData[i] = + Double2Short ( vecsOutData[i] + + vecvecdData[j][i] * vecdGains[j] ); + } } - - // normalization and truncating to short - vecsOutData[i] = Double2Short ( dMixedData / dNorm ); } return vecsOutData;