added class for high precision timer for server

This commit is contained in:
Volker Fischer 2009-08-01 09:05:14 +00:00
parent 3bd2999252
commit eb0c8e3786
3 changed files with 102 additions and 60 deletions

View File

@ -387,7 +387,12 @@ void CClient::ProcessAudioData ( CVector<int16_t>& vecsStereoSndCrd )
// Socket.SendPacket ( Channel.PrepSendPacket ( vecsNetwork ),
// 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() );
@ -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 )
{
@ -448,7 +450,6 @@ for ( i = 0, j = 0; i < iMonoBlockSizeSam; i++, j += 2 )
}
}
else
{

View File

@ -25,14 +25,66 @@
#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,
const quint16 iPortNumber,
const quint16 iPortNumber,
const QString& strHTMLStatusFileName,
const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile ) :
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
// entire life time of the software
@ -56,29 +108,6 @@ CServer::CServer ( const QString& strLoggingFileName,
CycleTimeVariance.Init ( SYSTEM_BLOCK_FRAME_SAMPLES,
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)
if ( !strLoggingFileName.isEmpty() )
{
@ -109,6 +138,12 @@ CServer::CServer ( const QString& strLoggingFileName,
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
// make sure we have MAX_NUM_CHANNELS connections!!!
// send message
@ -195,8 +230,8 @@ void CServer::Start()
{
if ( !IsRunning() )
{
// start main timer with lowest possible resolution
HighPrecisionTimer.start ( MIN_TIMER_RESOLUTION_MS );
// start timer
HighPrecisionTimer.start();
// init time for response time evaluation
CycleTimeVariance.Reset();
@ -205,19 +240,13 @@ void CServer::Start()
void CServer::Stop()
{
// stop main timer
// stop timer
HighPrecisionTimer.stop();
// logging
Logging.AddServerStopped();
}
void CServer::OnHighPrecisionTimer()
{
// TEST
OnTimer();
}
void CServer::OnTimer()
{
CVector<int> vecChanID;

View File

@ -44,24 +44,37 @@
// minimum timer precision
#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 ********************************************************************/
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
{
Q_OBJECT
public:
CServer ( const QString& strLoggingFileName,
const quint16 iPortNumber,
const quint16 iPortNumber,
const QString& strHTMLStatusFileName,
const QString& strHistoryFileName,
const QString& strServerNameForHTMLStatusFile );
@ -113,7 +126,6 @@ protected:
CVector<double>& vecdGains );
virtual void customEvent ( QEvent* Event );
void OnTimer();
/* do not use the vector class since CChannel does not have appropriate
copy constructor/operator */
@ -134,7 +146,7 @@ protected:
QString strServerHTMLFileListName;
QString strServerNameWithPort;
QTimer HighPrecisionTimer;
CHighPrecisionTimer HighPrecisionTimer;
CVector<short> vecsSendData;
// actual working objects
@ -146,7 +158,7 @@ protected:
CServerLogging Logging;
public slots:
void OnHighPrecisionTimer();
void OnTimer();
void OnSendProtMessage ( int iChID, CVector<uint8_t> vecMessage );
// CODE TAG: MAX_NUM_CHANNELS_TAG