implementation for high precision timer
This commit is contained in:
parent
eb0c8e3786
commit
628c5e5b7f
2 changed files with 61 additions and 22 deletions
|
@ -26,8 +26,7 @@
|
||||||
|
|
||||||
|
|
||||||
// CHighPrecisionTimer implementation ******************************************
|
// CHighPrecisionTimer implementation ******************************************
|
||||||
CHighPrecisionTimer::CHighPrecisionTimer ( const int iFrameSize,
|
CHighPrecisionTimer::CHighPrecisionTimer()
|
||||||
const int iSampleRate )
|
|
||||||
{
|
{
|
||||||
// add some error checking, the high precision timer implementation only
|
// add some error checking, the high precision timer implementation only
|
||||||
// supports 128 and 256 samples frame size at 48 kHz sampling rate
|
// supports 128 and 256 samples frame size at 48 kHz sampling rate
|
||||||
|
@ -38,18 +37,32 @@ CHighPrecisionTimer::CHighPrecisionTimer ( const int iFrameSize,
|
||||||
# error "Only a system sample rate of 48 kHz is supported by this module"
|
# error "Only a system sample rate of 48 kHz is supported by this module"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
// Since QT only supports a minimum timer resolution of 1 ms but for our
|
||||||
// init timer stuff
|
// llcon server we require a timer interval of 2.333 ms for 128 samples
|
||||||
//vTimeOutIntervals = [0 ]
|
// frame size and 5.666 ms for 256 samples frame size at 48 kHz sampling
|
||||||
|
// rate.
|
||||||
// for 128 sample frame size at 48 kHz sampling rate:
|
// To support this interval, we use a timer at the minimum supported
|
||||||
// actual intervals: 0.0 2.666 5.333 8.0
|
// resolution and fire the actual frame timer if the error to the actual
|
||||||
// quantized to 1 ms: 0 3 5 8 (0)
|
// required interval is minimum.
|
||||||
|
veciTimeOutIntervals.Init ( 3 );
|
||||||
// for 256 sample frame size at 48 kHz sampling rate:
|
if ( SYSTEM_BLOCK_FRAME_SAMPLES == 128 )
|
||||||
// actual intervals: 0.0 5.333 10.666 16.0
|
{
|
||||||
// quantized to 1 ms: 0 5 11 16 (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)
|
||||||
|
veciTimeOutIntervals[0] = 3;
|
||||||
|
veciTimeOutIntervals[1] = 2;
|
||||||
|
veciTimeOutIntervals[2] = 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 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)
|
||||||
|
veciTimeOutIntervals[0] = 5;
|
||||||
|
veciTimeOutIntervals[1] = 6;
|
||||||
|
veciTimeOutIntervals[2] = 5;
|
||||||
|
}
|
||||||
|
|
||||||
// connect timer timeout signal
|
// connect timer timeout signal
|
||||||
QObject::connect ( &Timer, SIGNAL ( timeout() ),
|
QObject::connect ( &Timer, SIGNAL ( timeout() ),
|
||||||
|
@ -58,21 +71,45 @@ CHighPrecisionTimer::CHighPrecisionTimer ( const int iFrameSize,
|
||||||
|
|
||||||
void CHighPrecisionTimer::start()
|
void CHighPrecisionTimer::start()
|
||||||
{
|
{
|
||||||
// TODO
|
// reset position pointer and counter
|
||||||
|
iCurPosInVector = 0;
|
||||||
|
iIntervalCounter = 0;
|
||||||
|
|
||||||
// start internal timer with lowest possible resolution
|
// start internal timer with lowest possible resolution
|
||||||
Timer.start ( MIN_TIMER_RESOLUTION_MS );
|
Timer.start ( MIN_TIMER_RESOLUTION_MS );
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHighPrecisionTimer::stop()
|
void CHighPrecisionTimer::stop()
|
||||||
{
|
{
|
||||||
// TODO
|
// stop timer
|
||||||
Timer.stop();
|
Timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHighPrecisionTimer::OnTimer()
|
void CHighPrecisionTimer::OnTimer()
|
||||||
{
|
{
|
||||||
// TODO
|
// check if maximum number of high precision timer intervals are
|
||||||
emit timeout();
|
// finished
|
||||||
|
if ( veciTimeOutIntervals[iCurPosInVector] == iIntervalCounter )
|
||||||
|
{
|
||||||
|
// reset interval counter
|
||||||
|
iIntervalCounter = 0;
|
||||||
|
|
||||||
|
// go to next position in vector, take care of wrap around
|
||||||
|
iCurPosInVector++;
|
||||||
|
if ( iCurPosInVector == veciTimeOutIntervals.Size() )
|
||||||
|
{
|
||||||
|
iCurPosInVector = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// minimum time error to actual required timer interval is reached,
|
||||||
|
// emit signal for server
|
||||||
|
emit timeout();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// next high precision timer interval
|
||||||
|
iIntervalCounter++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,8 +120,7 @@ CServer::CServer ( const QString& strLoggingFileName,
|
||||||
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
|
||||||
|
|
|
@ -51,14 +51,17 @@ class CHighPrecisionTimer : public QObject
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CHighPrecisionTimer ( const int iFrameSize, const int iSampleRate );
|
CHighPrecisionTimer();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void stop();
|
void stop();
|
||||||
bool isActive() const { return Timer.isActive(); }
|
bool isActive() const { return Timer.isActive(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QTimer Timer;
|
QTimer Timer;
|
||||||
|
CVector<int> veciTimeOutIntervals;
|
||||||
|
int iCurPosInVector;
|
||||||
|
int iIntervalCounter;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void OnTimer();
|
void OnTimer();
|
||||||
|
|
Loading…
Reference in a new issue