created separate class for time response measurement
This commit is contained in:
parent
8a8cf0b543
commit
029719fd1d
6 changed files with 79 additions and 67 deletions
|
@ -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
|
||||||
|
|
11
src/client.h
11
src/client.h
|
@ -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 );
|
||||||
|
|
|
@ -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 )
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
52
src/util.h
52
src/util.h
|
@ -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_ ) */
|
||||||
|
|
Loading…
Reference in a new issue