diff --git a/src/client.cpp b/src/client.cpp index 418d38d1..6a1f8768 100755 --- a/src/client.cpp +++ b/src/client.cpp @@ -248,11 +248,9 @@ void CClient::Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate ) vecsNetwork.Init ( iMonoBlockSizeSam ); vecdNetwData.Init ( iMonoBlockSizeSam ); - // init moving average buffer for response time evaluation - RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE ); - - // init time for response time evaluation - TimeLastBlock = PreciseTime.elapsed(); + // init response time evaluation + CycleTimeVariance.Init ( LEN_MOV_AV_RESPONSE ); + CycleTimeVariance.Reset(); AudioReverb.Clear(); } @@ -384,27 +382,10 @@ fflush(pFileDelay); } // update response time measurement and socket buffer size - UpdateTimeResponseMeasurement(); + CycleTimeVariance.Update(); UpdateSocketBufferSize(); } -void CClient::UpdateTimeResponseMeasurement() -{ - // add time difference - const int CurTime = PreciseTime.elapsed(); - - // we want to calculate the standard deviation (we assume that the mean - // is correct at the block period time) - const double dCurAddVal = - ( (double) ( CurTime - TimeLastBlock ) - - (double) iMonoBlockSizeSam / SYSTEM_SAMPLE_RATE * 1000 ); - - RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value - - // store old time value - TimeLastBlock = CurTime; -} - void CClient::UpdateSocketBufferSize() { // just update the socket buffer size if auto setting is enabled, otherwise @@ -425,7 +406,7 @@ void CClient::UpdateSocketBufferSize() // completely filled const double dHysteresis = 0.3; - if ( RespTimeMoAvBuf.IsInitialized() ) + if ( CycleTimeVariance.IsInitialized() ) { // calculate current buffer setting // TODO 2* seems not give optimal results, maybe use 3*? @@ -438,7 +419,7 @@ const double dAudioBufferDurationMs = iMonoBlockSizeSam / SYSTEM_SAMPLE_RATE * 1000; const double dEstCurBufSet = ( dAudioBufferDurationMs + - 3 * ( GetTimingStdDev() + 0.5 ) ) / + 3 * ( CycleTimeVariance.GetStdDev() + 0.5 ) ) / MIN_SERVER_BLOCK_DURATION_MS; // upper/lower hysteresis decision diff --git a/src/client.h b/src/client.h index 924251db..9386bcf2 100755 --- a/src/client.h +++ b/src/client.h @@ -74,9 +74,7 @@ public: double MicLevelR() { return SignalLevelMeter.MicLevelRight(); } bool IsConnected() { return Channel.IsConnected(); } - /* We want to return the standard deviation. For that we need to calculate - the sqaure root. */ - double GetTimingStdDev() { return sqrt ( RespTimeMoAvBuf.GetAverage() ); } + double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); } bool GetOpenChatOnNewMessage() { return bOpenChatOnNewMessage; } void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; } @@ -159,7 +157,6 @@ protected: void Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate ); void ProcessAudioData ( CVector& vecsStereoSndCrd ); - void UpdateTimeResponseMeasurement(); void UpdateSocketBufferSize(); // only one channel is needed for client application @@ -196,12 +193,10 @@ protected: CStereoAudioResample ResampleObjDown; CStereoAudioResample ResampleObjUp; - // for ping measurement and standard deviation of audio interface + // for ping measurement CPreciseTime PreciseTime; - // debugging, evaluating - CMovingAv RespTimeMoAvBuf; - int TimeLastBlock; + CCycleTimeVariance CycleTimeVariance; public slots: void OnSendProtMessage ( CVector vecMessage ); diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index b11ba340..f34f56cd 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -27,8 +27,8 @@ /* Implementation *************************************************************/ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, - Qt::WindowFlags f ) - : pClient ( pNCliP ), QDialog ( parent, f ), + Qt::WindowFlags f ) : + pClient ( pNCliP ), QDialog ( parent, f ), ClientSettingsDlg ( pNCliP, parent, Qt::WindowMinMaxButtonsHint ), ChatDlg ( parent, Qt::WindowMinMaxButtonsHint ) { @@ -38,7 +38,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, QString strInpLevH = tr ( "Input level meter: Shows the level of the " "input audio signal of the sound card. The level is in dB. Overload " "should be avoided." ); - TextLabelInputLevel->setWhatsThis ( strInpLevH ); + TextLabelInputLevel->setWhatsThis ( strInpLevH ); ProgressBarInputLevelL->setWhatsThis ( strInpLevH ); ProgressBarInputLevelR->setWhatsThis ( strInpLevH ); @@ -55,18 +55,18 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, "the IP address of the server can be set. If an invalid address was " "chosen, an error message is shown in the status bar." ); TextLabelServerAddr->setWhatsThis ( strServAddrH ); - LineEditServerAddr->setWhatsThis ( strServAddrH ); + LineEditServerAddr->setWhatsThis ( strServAddrH ); QString strFaderTag = tr ( "Fader Tag: In this edit control, " "the tag string of your fader can be set. This tag will appear " "at your fader on the mixer board when connected to the server."); TextLabelServerTag->setWhatsThis ( strFaderTag ); - LineEditFaderTag->setWhatsThis ( strFaderTag ); + LineEditFaderTag->setWhatsThis ( strFaderTag ); QString strAudFader = tr ( "Audio Fader: With the audio fader " "control the level of left and right audio input channels can " "be controlled." ); - TextAudInFader->setWhatsThis ( strAudFader ); + TextAudInFader->setWhatsThis ( strAudFader ); SliderAudInFader->setWhatsThis ( strAudFader ); QString strAudReverb = tr ( "Reverberation Level: The level of " @@ -74,15 +74,15 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, "which that reverberation effect shall be applied can be chosen " "with the Reverberation Channel Selection radio buttons." ); TextLabelAudReverb->setWhatsThis ( strAudReverb ); - SliderAudReverb->setWhatsThis ( strAudReverb ); + SliderAudReverb->setWhatsThis ( strAudReverb ); QString strRevChanSel = tr ( "Reverberation Channel Selection: " "With these radio buttons the audio input channel on which the " "reverberation effect is applied can be chosen. Either the left " "or right input channel can be selected." ); TextLabelReverbSelection->setWhatsThis ( strRevChanSel ); - RadioButtonRevSelL->setWhatsThis ( strRevChanSel ); - RadioButtonRevSelR->setWhatsThis ( strRevChanSel ); + RadioButtonRevSelL->setWhatsThis ( strRevChanSel ); + RadioButtonRevSelR->setWhatsThis ( strRevChanSel ); LEDOverallStatus->setWhatsThis ( tr ( "Overall Status: " "The overall status of the software is shown. If either the " diff --git a/src/server.cpp b/src/server.cpp index 2ce1e45f..9cebb02f 100755 --- a/src/server.cpp +++ b/src/server.cpp @@ -37,7 +37,7 @@ CServer::CServer ( const QString& strLoggingFileName, vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES ); // init moving average buffer for response time evaluation - RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE ); + CycleTimeVariance.Init ( LEN_MOV_AV_RESPONSE ); // connect timer timeout signal QObject::connect ( &Timer, SIGNAL ( timeout() ), @@ -106,8 +106,7 @@ void CServer::Start() Timer.start ( MIN_SERVER_BLOCK_DURATION_MS ); // init time for response time evaluation - TimeLastBlock = PreciseTime.elapsed(); - RespTimeMoAvBuf.Reset(); + CycleTimeVariance.Reset(); } } @@ -171,19 +170,8 @@ void CServer::OnTimer() #endif } - // update response time measurement ---------------------------------------- - // add time difference - const int CurTime = PreciseTime.elapsed(); - - // we want to calculate the standard deviation (we assume that the mean - // is correct at the block period time) - const double dCurAddVal = - ( (double) ( CurTime - TimeLastBlock ) - MIN_SERVER_BLOCK_DURATION_MS ); - - RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value - - // store old time value - TimeLastBlock = CurTime; + // update response time measurement + CycleTimeVariance.Update(); } CVector CServer::ProcessData ( CVector >& vecvecdData, @@ -217,13 +205,12 @@ bool CServer::GetTimingStdDev ( double& dCurTiStdDev ) { dCurTiStdDev = 0.0; // init return value - /* only return value if server is active and the actual measurement is - updated */ + // only return value if server is active and the actual measurement is + // updated if ( IsRunning() ) { - /* we want to return the standard deviation, for that we need to calculate - the sqaure root */ - dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage() ); + // return the standard deviation + dCurTiStdDev = CycleTimeVariance.GetStdDev(); return true; } diff --git a/src/server.h b/src/server.h index 8387a634..bf92ae8d 100755 --- a/src/server.h +++ b/src/server.h @@ -77,10 +77,7 @@ protected: CChannelSet ChannelSet; CSocket Socket; - // debugging, evaluating - CPreciseTime PreciseTime; - CMovingAv RespTimeMoAvBuf; - int TimeLastBlock; + CCycleTimeVariance CycleTimeVariance; // logging CLogging Logging; diff --git a/src/util.h b/src/util.h index 9a364381..23644cda 100755 --- a/src/util.h +++ b/src/util.h @@ -323,6 +323,7 @@ template void CMovingAv::Add ( const TData tNewD ) } + /******************************************************************************\ * GUI utilities * \******************************************************************************/ @@ -597,4 +598,55 @@ protected: QFile File; }; + + +/******************************************************************************\ +* Cycle Time Variance Measurement * +\******************************************************************************/ +// use for, e.g., measuring the variance of a timer +class CCycleTimeVariance +{ +public: + CCycleTimeVariance() {} + virtual ~CCycleTimeVariance() {} + + void Init ( const int iMovingAverageLength ) + { + RespTimeMoAvBuf.Init ( iMovingAverageLength ); + } + + void Reset() + { + TimeLastBlock = PreciseTime.elapsed(); + RespTimeMoAvBuf.Reset(); + } + + void Update() + { + // add time difference + const int CurTime = PreciseTime.elapsed(); + + // we want to calculate the standard deviation (we assume that the mean + // is correct at the block period time) + const double dCurAddVal = + ( (double) ( CurTime - TimeLastBlock ) - MIN_SERVER_BLOCK_DURATION_MS ); + + RespTimeMoAvBuf.Add ( dCurAddVal * dCurAddVal ); // add squared value + + // store old time value + TimeLastBlock = CurTime; + } + + // return the standard deviation, for that we need to calculate + // the sqaure root + double GetStdDev() { return sqrt ( RespTimeMoAvBuf.GetAverage() ); } + + bool IsInitialized() { return RespTimeMoAvBuf.IsInitialized(); } + +protected: + CPreciseTime PreciseTime; + CMovingAv RespTimeMoAvBuf; + int TimeLastBlock; +}; + #endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */