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 );
|
||||
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
|
||||
|
|
11
src/client.h
11
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<short>& 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<double> RespTimeMoAvBuf;
|
||||
int TimeLastBlock;
|
||||
CCycleTimeVariance CycleTimeVariance;
|
||||
|
||||
public slots:
|
||||
void OnSendProtMessage ( CVector<uint8_t> vecMessage );
|
||||
|
|
|
@ -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 )
|
||||
{
|
||||
|
|
|
@ -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<short> CServer::ProcessData ( CVector<CVector<double> >& 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;
|
||||
}
|
||||
|
|
|
@ -77,10 +77,7 @@ protected:
|
|||
CChannelSet ChannelSet;
|
||||
CSocket Socket;
|
||||
|
||||
// debugging, evaluating
|
||||
CPreciseTime PreciseTime;
|
||||
CMovingAv<double> RespTimeMoAvBuf;
|
||||
int TimeLastBlock;
|
||||
CCycleTimeVariance CycleTimeVariance;
|
||||
|
||||
// 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 *
|
||||
\******************************************************************************/
|
||||
|
@ -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<double> RespTimeMoAvBuf;
|
||||
int TimeLastBlock;
|
||||
};
|
||||
|
||||
#endif /* !defined ( UTIL_HOIH934256GEKJH98_3_43445KJIUHF1912__INCLUDED_ ) */
|
||||
|
|
Loading…
Reference in a new issue