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 )
|
||||
{
|
||||
|
@ -38,7 +38,7 @@ CLlconClientDlg::CLlconClientDlg ( CClient* pNCliP, QWidget* parent,
|
|||
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 "
|
||||
"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 ( "<b>Fader Tag:</b> 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 ( "<b>Audio Fader:</b> 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 ( "<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 "
|
||||
"with the Reverberation Channel Selection radio buttons." );
|
||||
TextLabelAudReverb->setWhatsThis ( strAudReverb );
|
||||
SliderAudReverb->setWhatsThis ( strAudReverb );
|
||||
SliderAudReverb->setWhatsThis ( strAudReverb );
|
||||
|
||||
QString strRevChanSel = tr ( "<b>Reverberation Channel Selection:</b> "
|
||||
"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 ( "<b>Overall Status:</b> "
|
||||
"The overall status of the software is shown. If either the "
|
||||
|
|
|
@ -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