added class for high precision timer for server
This commit is contained in:
parent
3bd2999252
commit
eb0c8e3786
3 changed files with 102 additions and 60 deletions
|
@ -387,7 +387,12 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
|
||||||
// Socket.SendPacket ( Channel.PrepSendPacket ( vecsNetwork ),
|
// Socket.SendPacket ( Channel.PrepSendPacket ( vecsNetwork ),
|
||||||
// Channel.GetAddress() );
|
// Channel.GetAddress() );
|
||||||
|
|
||||||
celt_encode ( CeltEncoder, &vecsNetwork[0], NULL, &vecCeltData[0], iCeltNumCodedBytes );
|
celt_encode ( CeltEncoder,
|
||||||
|
&vecsNetwork[0],
|
||||||
|
NULL,
|
||||||
|
&vecCeltData[0],
|
||||||
|
iCeltNumCodedBytes );
|
||||||
|
|
||||||
Socket.SendPacket ( vecCeltData, Channel.GetAddress() );
|
Socket.SendPacket ( vecCeltData, Channel.GetAddress() );
|
||||||
|
|
||||||
|
|
||||||
|
@ -429,17 +434,14 @@ fflush(pFileDelay);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CVector<short> vecsAudioSndCrdMono ( iMonoBlockSizeSam );
|
|
||||||
/*
|
|
||||||
for ( i = 0; i < iMonoBlockSizeSam; i++ )
|
|
||||||
{
|
|
||||||
vecsAudioSndCrdMono[i] = Double2Short ( vecdNetwData[i] );
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
// TEST CELT
|
|
||||||
//celt_encode(CeltEncoder, &vecsAudioSndCrdMono[0], NULL, &vecCeltData[0], iCeltNumCodedBytes);
|
|
||||||
celt_decode ( CeltDecoder, &vecbyNetwData[0], iCeltNumCodedBytes, &vecsAudioSndCrdMono[0] );
|
|
||||||
|
|
||||||
|
// TEST CELT
|
||||||
|
CVector<short> vecsAudioSndCrdMono ( iMonoBlockSizeSam );
|
||||||
|
|
||||||
|
celt_decode ( CeltDecoder,
|
||||||
|
&vecbyNetwData[0],
|
||||||
|
iCeltNumCodedBytes,
|
||||||
|
&vecsAudioSndCrdMono[0] );
|
||||||
|
|
||||||
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
{
|
{
|
||||||
|
@ -448,7 +450,6 @@ for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,14 +25,66 @@
|
||||||
#include "server.h"
|
#include "server.h"
|
||||||
|
|
||||||
|
|
||||||
/* Implementation *************************************************************/
|
// CHighPrecisionTimer implementation ******************************************
|
||||||
|
CHighPrecisionTimer::CHighPrecisionTimer ( const int iFrameSize,
|
||||||
|
const int iSampleRate )
|
||||||
|
{
|
||||||
|
// add some error checking, the high precision timer implementation only
|
||||||
|
// supports 128 and 256 samples frame size at 48 kHz sampling rate
|
||||||
|
#if ( ( SYSTEM_BLOCK_FRAME_SAMPLES != 128 ) && ( SYSTEM_BLOCK_FRAME_SAMPLES != 256 ) )
|
||||||
|
# error "Only system frame sizes of 128 and 256 samples are supported by this module"
|
||||||
|
#endif
|
||||||
|
#if SYSTEM_SAMPLE_RATE != 48000
|
||||||
|
# error "Only a system sample rate of 48 kHz is supported by this module"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
// init timer stuff
|
||||||
|
//vTimeOutIntervals = [0 ]
|
||||||
|
|
||||||
|
// for 128 sample frame size at 48 kHz sampling rate:
|
||||||
|
// actual intervals: 0.0 2.666 5.333 8.0
|
||||||
|
// quantized to 1 ms: 0 3 5 8 (0)
|
||||||
|
|
||||||
|
// for 256 sample frame size at 48 kHz sampling rate:
|
||||||
|
// actual intervals: 0.0 5.333 10.666 16.0
|
||||||
|
// quantized to 1 ms: 0 5 11 16 (0)
|
||||||
|
*/
|
||||||
|
|
||||||
|
// connect timer timeout signal
|
||||||
|
QObject::connect ( &Timer, SIGNAL ( timeout() ),
|
||||||
|
this, SLOT ( OnTimer() ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHighPrecisionTimer::start()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
// start internal timer with lowest possible resolution
|
||||||
|
Timer.start ( MIN_TIMER_RESOLUTION_MS );
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHighPrecisionTimer::stop()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
Timer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHighPrecisionTimer::OnTimer()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
emit timeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// CServer implementation ******************************************************
|
||||||
CServer::CServer ( const QString& strLoggingFileName,
|
CServer::CServer ( const QString& strLoggingFileName,
|
||||||
const quint16 iPortNumber,
|
const quint16 iPortNumber,
|
||||||
const QString& strHTMLStatusFileName,
|
const QString& strHTMLStatusFileName,
|
||||||
const QString& strHistoryFileName,
|
const QString& strHistoryFileName,
|
||||||
const QString& strServerNameForHTMLStatusFile ) :
|
const QString& strServerNameForHTMLStatusFile ) :
|
||||||
Socket ( this, iPortNumber ),
|
Socket ( this, iPortNumber ),
|
||||||
bWriteStatusHTMLFile ( false )
|
bWriteStatusHTMLFile ( false ),
|
||||||
|
HighPrecisionTimer ( SYSTEM_BLOCK_FRAME_SAMPLES, SYSTEM_SAMPLE_RATE )
|
||||||
{
|
{
|
||||||
// enable all channels (for the server all channel must be enabled the
|
// enable all channels (for the server all channel must be enabled the
|
||||||
// entire life time of the software
|
// entire life time of the software
|
||||||
|
@ -56,29 +108,6 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
CycleTimeVariance.Init ( SYSTEM_BLOCK_FRAME_SAMPLES,
|
CycleTimeVariance.Init ( SYSTEM_BLOCK_FRAME_SAMPLES,
|
||||||
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
|
SYSTEM_SAMPLE_RATE, TIME_MOV_AV_RESPONSE );
|
||||||
|
|
||||||
|
|
||||||
// connect timer timeout signal
|
|
||||||
QObject::connect ( &HighPrecisionTimer, SIGNAL ( timeout() ),
|
|
||||||
this, SLOT ( OnHighPrecisionTimer() ) );
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
// init timer stuff
|
|
||||||
//vTimeOutIntervals = [0 ]
|
|
||||||
|
|
||||||
// for 128 sample frame size at 48 kHz sampling rate:
|
|
||||||
// actual intervals: 0.0 2.666 5.333 8.0
|
|
||||||
// quantized to 1 ms: 0 3 5 8 (0)
|
|
||||||
|
|
||||||
// for 256 sample frame size at 48 kHz sampling rate:
|
|
||||||
// actual intervals: 0.0 5.333 10.666 16.0
|
|
||||||
// quantized to 1 ms: 0 5 11 16 (0)
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// enable logging (if requested)
|
// enable logging (if requested)
|
||||||
if ( !strLoggingFileName.isEmpty() )
|
if ( !strLoggingFileName.isEmpty() )
|
||||||
{
|
{
|
||||||
|
@ -109,6 +138,12 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
QString().number( static_cast<int> ( iPortNumber ) ) );
|
QString().number( static_cast<int> ( iPortNumber ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// connections -------------------------------------------------------------
|
||||||
|
// connect timer timeout signal
|
||||||
|
QObject::connect ( &HighPrecisionTimer, SIGNAL ( timeout() ),
|
||||||
|
this, SLOT ( OnTimer() ) );
|
||||||
|
|
||||||
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
||||||
// make sure we have MAX_NUM_CHANNELS connections!!!
|
// make sure we have MAX_NUM_CHANNELS connections!!!
|
||||||
// send message
|
// send message
|
||||||
|
@ -195,8 +230,8 @@ void CServer::Start()
|
||||||
{
|
{
|
||||||
if ( !IsRunning() )
|
if ( !IsRunning() )
|
||||||
{
|
{
|
||||||
// start main timer with lowest possible resolution
|
// start timer
|
||||||
HighPrecisionTimer.start ( MIN_TIMER_RESOLUTION_MS );
|
HighPrecisionTimer.start();
|
||||||
|
|
||||||
// init time for response time evaluation
|
// init time for response time evaluation
|
||||||
CycleTimeVariance.Reset();
|
CycleTimeVariance.Reset();
|
||||||
|
@ -205,19 +240,13 @@ void CServer::Start()
|
||||||
|
|
||||||
void CServer::Stop()
|
void CServer::Stop()
|
||||||
{
|
{
|
||||||
// stop main timer
|
// stop timer
|
||||||
HighPrecisionTimer.stop();
|
HighPrecisionTimer.stop();
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
Logging.AddServerStopped();
|
Logging.AddServerStopped();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CServer::OnHighPrecisionTimer()
|
|
||||||
{
|
|
||||||
// TEST
|
|
||||||
OnTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CServer::OnTimer()
|
void CServer::OnTimer()
|
||||||
{
|
{
|
||||||
CVector<int> vecChanID;
|
CVector<int> vecChanID;
|
||||||
|
|
36
src/server.h
36
src/server.h
|
@ -44,17 +44,30 @@
|
||||||
// minimum timer precision
|
// minimum timer precision
|
||||||
#define MIN_TIMER_RESOLUTION_MS 1 // ms
|
#define MIN_TIMER_RESOLUTION_MS 1 // ms
|
||||||
|
|
||||||
// add some error checking, the high precision timer implementation only
|
|
||||||
// supports 128 and 256 samples frame size at 48 kHz sampling rate
|
|
||||||
#if ( ( SYSTEM_BLOCK_FRAME_SAMPLES != 128 ) && ( SYSTEM_BLOCK_FRAME_SAMPLES != 256 ) )
|
|
||||||
# error "Only system frame sizes of 128 and 256 samples are supported by this module"
|
|
||||||
#endif
|
|
||||||
#if SYSTEM_SAMPLE_RATE != 48000
|
|
||||||
# error "Only a system sample rate of 48 kHz is supported by this module"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* Classes ********************************************************************/
|
/* Classes ********************************************************************/
|
||||||
|
class CHighPrecisionTimer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CHighPrecisionTimer ( const int iFrameSize, const int iSampleRate );
|
||||||
|
|
||||||
|
void start();
|
||||||
|
void stop();
|
||||||
|
bool isActive() const { return Timer.isActive(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QTimer Timer;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void OnTimer();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void timeout();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class CServer : public QObject
|
class CServer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -113,7 +126,6 @@ protected:
|
||||||
CVector<double>& vecdGains );
|
CVector<double>& vecdGains );
|
||||||
|
|
||||||
virtual void customEvent ( QEvent* Event );
|
virtual void customEvent ( QEvent* Event );
|
||||||
void OnTimer();
|
|
||||||
|
|
||||||
/* do not use the vector class since CChannel does not have appropriate
|
/* do not use the vector class since CChannel does not have appropriate
|
||||||
copy constructor/operator */
|
copy constructor/operator */
|
||||||
|
@ -134,7 +146,7 @@ protected:
|
||||||
QString strServerHTMLFileListName;
|
QString strServerHTMLFileListName;
|
||||||
QString strServerNameWithPort;
|
QString strServerNameWithPort;
|
||||||
|
|
||||||
QTimer HighPrecisionTimer;
|
CHighPrecisionTimer HighPrecisionTimer;
|
||||||
CVector<short> vecsSendData;
|
CVector<short> vecsSendData;
|
||||||
|
|
||||||
// actual working objects
|
// actual working objects
|
||||||
|
@ -146,7 +158,7 @@ protected:
|
||||||
CServerLogging Logging;
|
CServerLogging Logging;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnHighPrecisionTimer();
|
void OnTimer();
|
||||||
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
|
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
|
||||||
|
|
||||||
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
// CODE TAG: MAX_NUM_CHANNELS_TAG
|
||||||
|
|
Loading…
Reference in a new issue