created separate class for time response measurement

This commit is contained in:
Volker Fischer 2009-03-07 10:52:06 +00:00
parent 8a8cf0b543
commit 029719fd1d
6 changed files with 79 additions and 67 deletions

View file

@ -248,11 +248,9 @@ void CClient::Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate )
vecsNetwork.Init ( iMonoBlockSizeSam ); vecsNetwork.Init ( iMonoBlockSizeSam );
vecdNetwData.Init ( iMonoBlockSizeSam ); vecdNetwData.Init ( iMonoBlockSizeSam );
// init moving average buffer for response time evaluation // init response time evaluation
RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE ); CycleTimeVariance.Init ( LEN_MOV_AV_RESPONSE );
CycleTimeVariance.Reset();
// init time for response time evaluation
TimeLastBlock = PreciseTime.elapsed();
AudioReverb.Clear(); AudioReverb.Clear();
} }
@ -384,27 +382,10 @@ fflush(pFileDelay);
} }
// update response time measurement and socket buffer size // update response time measurement and socket buffer size
UpdateTimeResponseMeasurement(); CycleTimeVariance.Update();
UpdateSocketBufferSize(); 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() void CClient::UpdateSocketBufferSize()
{ {
// just update the socket buffer size if auto setting is enabled, otherwise // just update the socket buffer size if auto setting is enabled, otherwise
@ -425,7 +406,7 @@ void CClient::UpdateSocketBufferSize()
// completely filled // completely filled
const double dHysteresis = 0.3; const double dHysteresis = 0.3;
if ( RespTimeMoAvBuf.IsInitialized() ) if ( CycleTimeVariance.IsInitialized() )
{ {
// calculate current buffer setting // calculate current buffer setting
// TODO 2* seems not give optimal results, maybe use 3*? // TODO 2* seems not give optimal results, maybe use 3*?
@ -438,7 +419,7 @@ const double dAudioBufferDurationMs =
iMonoBlockSizeSam / SYSTEM_SAMPLE_RATE * 1000; iMonoBlockSizeSam / SYSTEM_SAMPLE_RATE * 1000;
const double dEstCurBufSet = ( dAudioBufferDurationMs + const double dEstCurBufSet = ( dAudioBufferDurationMs +
3 * ( GetTimingStdDev() + 0.5 ) ) / 3 * ( CycleTimeVariance.GetStdDev() + 0.5 ) ) /
MIN_SERVER_BLOCK_DURATION_MS; MIN_SERVER_BLOCK_DURATION_MS;
// upper/lower hysteresis decision // upper/lower hysteresis decision

View file

@ -74,9 +74,7 @@ public:
double MicLevelR() { return SignalLevelMeter.MicLevelRight(); } double MicLevelR() { return SignalLevelMeter.MicLevelRight(); }
bool IsConnected() { return Channel.IsConnected(); } bool IsConnected() { return Channel.IsConnected(); }
/* We want to return the standard deviation. For that we need to calculate double GetTimingStdDev() { return CycleTimeVariance.GetStdDev(); }
the sqaure root. */
double GetTimingStdDev() { return sqrt ( RespTimeMoAvBuf.GetAverage() ); }
bool GetOpenChatOnNewMessage() { return bOpenChatOnNewMessage; } bool GetOpenChatOnNewMessage() { return bOpenChatOnNewMessage; }
void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; } void SetOpenChatOnNewMessage ( const bool bNV ) { bOpenChatOnNewMessage = bNV; }
@ -159,7 +157,6 @@ protected:
void Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate ); void Init ( const int iPrefMonoBlockSizeSamIndexAtSndCrdSamRate );
void ProcessAudioData ( CVector<short>& vecsStereoSndCrd ); void ProcessAudioData ( CVector<short>& vecsStereoSndCrd );
void UpdateTimeResponseMeasurement();
void UpdateSocketBufferSize(); void UpdateSocketBufferSize();
// only one channel is needed for client application // only one channel is needed for client application
@ -196,12 +193,10 @@ protected:
CStereoAudioResample ResampleObjDown; CStereoAudioResample ResampleObjDown;
CStereoAudioResample ResampleObjUp; CStereoAudioResample ResampleObjUp;
// for ping measurement and standard deviation of audio interface // for ping measurement
CPreciseTime PreciseTime; CPreciseTime PreciseTime;
// debugging, evaluating CCycleTimeVariance CycleTimeVariance;
CMovingAv<double> RespTimeMoAvBuf;
int TimeLastBlock;
public slots: public slots:
void OnSendProtMessage ( CVector<uint8_t> vecMessage ); void OnSendProtMessage ( CVector<uint8_t> vecMessage );

View file

@ -27,8 +27,8 @@
/* Implementation *************************************************************/ /* Implementation *************************************************************/
CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent, CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
Qt::WindowFlags f ) Qt::WindowFlags f ) :
: pClient ( pNCliP ), QDialog ( parent, f ), pClient ( pNCliP ), QDialog ( parent, f ),
ClientSettingsDlg ( pNCliP, parent, Qt::WindowMinMaxButtonsHint ), ClientSettingsDlg ( pNCliP, parent, Qt::WindowMinMaxButtonsHint ),
ChatDlg ( parent, Qt::WindowMinMaxButtonsHint ) ChatDlg ( parent, Qt::WindowMinMaxButtonsHint )
{ {
@ -38,7 +38,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
QString strInpLevH = tr ( "<b>Input level meter:</b> Shows the level of the " QString strInpLevH = tr ( "<b>Input level meter:</b> Shows the level of the "
"input audio signal of the sound card. The level is in dB. Overload " "input audio signal of the sound card. The level is in dB. Overload "
"should be avoided." ); "should be avoided." );
TextLabelInputLevel->setWhatsThis ( strInpLevH ); TextLabelInputLevel->setWhatsThis ( strInpLevH );
ProgressBarInputLevelL->setWhatsThis ( strInpLevH ); ProgressBarInputLevelL->setWhatsThis ( strInpLevH );
ProgressBarInputLevelR->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 " "the IP address of the server can be set. If an invalid address was "
"chosen, an error message is shown in the status bar." ); "chosen, an error message is shown in the status bar." );
TextLabelServerAddr->setWhatsThis ( strServAddrH ); TextLabelServerAddr->setWhatsThis ( strServAddrH );
LineEditServerAddr->setWhatsThis ( strServAddrH ); LineEditServerAddr->setWhatsThis ( strServAddrH );
QString strFaderTag = tr ( "<b>Fader Tag:</b> In this edit control, " QString strFaderTag = tr ( "<b>Fader Tag:</b> In this edit control, "
"the tag string of your fader can be set. This tag will appear " "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."); "at your fader on the mixer board when connected to the server.");
TextLabelServerTag->setWhatsThis ( strFaderTag ); TextLabelServerTag->setWhatsThis ( strFaderTag );
LineEditFaderTag->setWhatsThis ( strFaderTag ); LineEditFaderTag->setWhatsThis ( strFaderTag );
QString strAudFader = tr ( "<b>Audio Fader:</b> With the audio fader " QString strAudFader = tr ( "<b>Audio Fader:</b> With the audio fader "
"control the level of left and right audio input channels can " "control the level of left and right audio input channels can "
"be controlled." ); "be controlled." );
TextAudInFader->setWhatsThis ( strAudFader ); TextAudInFader->setWhatsThis ( strAudFader );
SliderAudInFader->setWhatsThis ( strAudFader ); SliderAudInFader->setWhatsThis ( strAudFader );
QString strAudReverb = tr ( "<b>Reverberation Level:</b> The level of " QString strAudReverb = tr ( "<b>Reverberation Level:</b> The level of "
@ -74,15 +74,15 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
"which that reverberation effect shall be applied can be chosen " "which that reverberation effect shall be applied can be chosen "
"with the Reverberation Channel Selection radio buttons." ); "with the Reverberation Channel Selection radio buttons." );
TextLabelAudReverb->setWhatsThis ( strAudReverb ); TextLabelAudReverb->setWhatsThis ( strAudReverb );
SliderAudReverb->setWhatsThis ( strAudReverb ); SliderAudReverb->setWhatsThis ( strAudReverb );
QString strRevChanSel = tr ( "<b>Reverberation Channel Selection:</b> " QString strRevChanSel = tr ( "<b>Reverberation Channel Selection:</b> "
"With these radio buttons the audio input channel on which the " "With these radio buttons the audio input channel on which the "
"reverberation effect is applied can be chosen. Either the left " "reverberation effect is applied can be chosen. Either the left "
"or right input channel can be selected." ); "or right input channel can be selected." );
TextLabelReverbSelection->setWhatsThis ( strRevChanSel ); TextLabelReverbSelection->setWhatsThis ( strRevChanSel );
RadioButtonRevSelL->setWhatsThis ( strRevChanSel ); RadioButtonRevSelL->setWhatsThis ( strRevChanSel );
RadioButtonRevSelR->setWhatsThis ( strRevChanSel ); RadioButtonRevSelR->setWhatsThis ( strRevChanSel );
LEDOverallStatus->setWhatsThis ( tr ( "<b>Overall Status:</b> " LEDOverallStatus->setWhatsThis ( tr ( "<b>Overall Status:</b> "
"The overall status of the software is shown. If either the " "The overall status of the software is shown. If either the "

View file

@ -37,7 +37,7 @@ CServer::CServer ( const QString& strLoggingFileName,
vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES ); vecsSendData.Init ( MIN_SERVER_BLOCK_SIZE_SAMPLES );
// init moving average buffer for response time evaluation // init moving average buffer for response time evaluation
RespTimeMoAvBuf.Init ( LEN_MOV_AV_RESPONSE ); CycleTimeVariance.Init ( LEN_MOV_AV_RESPONSE );
// connect timer timeout signal // connect timer timeout signal
QObject::connect ( &Timer, SIGNAL ( timeout() ), QObject::connect ( &Timer, SIGNAL ( timeout() ),
@ -106,8 +106,7 @@ void CServer::Start()
Timer.start ( MIN_SERVER_BLOCK_DURATION_MS ); Timer.start ( MIN_SERVER_BLOCK_DURATION_MS );
// init time for response time evaluation // init time for response time evaluation
TimeLastBlock = PreciseTime.elapsed(); CycleTimeVariance.Reset();
RespTimeMoAvBuf.Reset();
} }
} }
@ -171,19 +170,8 @@ void CServer::OnTimer()
#endif #endif
} }
// update response time measurement ---------------------------------------- // update response time measurement
// add time difference CycleTimeVariance.Update();
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;
} }
CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData, CVector<short> CServer::ProcessData ( CVector<CVector<double> >& vecvecdData,
@ -217,13 +205,12 @@ bool CServer::GetTimingStdDev ( double& dCurTiStdDev )
{ {
dCurTiStdDev = 0.0; // init return value dCurTiStdDev = 0.0; // init return value
/* only return value if server is active and the actual measurement is // only return value if server is active and the actual measurement is
updated */ // updated
if ( IsRunning() ) if ( IsRunning() )
{ {
/* we want to return the standard deviation, for that we need to calculate // return the standard deviation
the sqaure root */ dCurTiStdDev = CycleTimeVariance.GetStdDev();
dCurTiStdDev = sqrt ( RespTimeMoAvBuf.GetAverage() );
return true; return true;
} }

View file

@ -77,10 +77,7 @@ protected:
CChannelSet ChannelSet; CChannelSet ChannelSet;
CSocket Socket; CSocket Socket;
// debugging, evaluating CCycleTimeVariance CycleTimeVariance;
CPreciseTime PreciseTime;
CMovingAv<double> RespTimeMoAvBuf;
int TimeLastBlock;
// logging // logging
CLogging Logging; CLogging Logging;

View file

@ -323,6 +323,7 @@ template<class TData> void CMovingAv<TData>::Add ( const TData tNewD )
} }
/******************************************************************************\ /******************************************************************************\
* GUI utilities * * GUI utilities *
\******************************************************************************/ \******************************************************************************/
@ -597,4 +598,55 @@ protected:
QFile File; 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<double> RespTimeMoAvBuf;
int TimeLastBlock;
};
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */ #endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */