1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-09-30 08:46:46 -04:00

SDRdaemon plugin: attempt to fix the skew rate calculation

This commit is contained in:
f4exb 2016-03-16 09:10:29 +01:00
parent d5f65a7e39
commit 87a53f03a2
2 changed files with 9 additions and 5 deletions

View File

@ -60,7 +60,8 @@ SDRdaemonBuffer::SDRdaemonBuffer(uint32_t throttlems) :
m_skewTest(false), m_skewTest(false),
m_skewCorrection(false), m_skewCorrection(false),
m_readCount(0), m_readCount(0),
m_writeCount(0) m_writeCount(0),
m_nbCycles(0)
{ {
m_currentMeta.init(); m_currentMeta.init();
} }
@ -180,8 +181,8 @@ bool SDRdaemonBuffer::readMeta(char *array, uint32_t length)
{ {
if (m_skewCorrection) if (m_skewCorrection)
{ {
uint64_t newRate = (m_sampleRate * m_writeCount) / (m_readCount * m_iqSampleSize); int64_t deltaRate = (m_writeCount - m_readCount) / (m_nbCycles * m_rawBufferLengthSeconds * m_iqSampleSize);
m_sampleRate = newRate * m_iqSampleSize; // ensure it is a multiple of the I/Q sample size m_sampleRate = ((m_sampleRate + deltaRate) / m_iqSampleSize) * m_iqSampleSize; // ensure it is a multiple of the I/Q sample size
resetIndexes(); resetIndexes();
} }
} }
@ -243,6 +244,7 @@ uint8_t *SDRdaemonBuffer::readData(int32_t length)
{ {
int dIndex = (m_readIndex - m_writeIndex > 0 ? m_readIndex - m_writeIndex : m_writeIndex - m_readIndex); // absolute delta int dIndex = (m_readIndex - m_writeIndex > 0 ? m_readIndex - m_writeIndex : m_writeIndex - m_readIndex); // absolute delta
m_skewCorrection = (dIndex < m_rawSize / 10); // close by 10% m_skewCorrection = (dIndex < m_rawSize / 10); // close by 10%
m_nbCycles++;
m_skewTest = false; m_skewTest = false;
} }
@ -367,6 +369,7 @@ void SDRdaemonBuffer::resetIndexes()
m_readIndex = m_rawSize / 2; m_readIndex = m_rawSize / 2;
m_readCount = 0; m_readCount = 0;
m_writeCount = 0; m_writeCount = 0;
m_nbCycles = 0;
m_skewTest = false; m_skewTest = false;
m_skewCorrection = false; m_skewCorrection = false;
} }

View File

@ -132,8 +132,9 @@ private:
bool m_autoFollowRate; //!< Auto follow stream sample rate else stick with meta data sample rate bool m_autoFollowRate; //!< Auto follow stream sample rate else stick with meta data sample rate
bool m_skewTest; bool m_skewTest;
bool m_skewCorrection; //!< Do a skew rate correction at next meta data reception bool m_skewCorrection; //!< Do a skew rate correction at next meta data reception
uint64_t m_readCount; int64_t m_readCount;
uint64_t m_writeCount; int64_t m_writeCount;
uint32_t m_nbCycles; //!< Number of buffer cycles since start of byte counting
}; };