diff --git a/sdrdaemon/channel/sdrdaemonchannelsource.cpp b/sdrdaemon/channel/sdrdaemonchannelsource.cpp index 8d6131eae..d51ca6680 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsource.cpp +++ b/sdrdaemon/channel/sdrdaemonchannelsource.cpp @@ -265,8 +265,10 @@ void SDRDaemonChannelSource::handleDataBlock(SDRDaemonDataBlock* dataBlock) m_deviceAPI->getSampleSink()->setCenterFrequency(metaData->m_centerFrequency); } - if (m_currentMeta.m_sampleRate != metaData->m_sampleRate) { + if (m_currentMeta.m_sampleRate != metaData->m_sampleRate) + { m_channelizer->configure(m_channelizer->getInputMessageQueue(), metaData->m_sampleRate, 0); + m_dataReadQueue.setSize(calculateDataReadQueueSize(metaData->m_sampleRate)); } } @@ -304,3 +306,12 @@ void SDRDaemonChannelSource::printMeta(const QString& header, SDRDaemonMetaDataF << ":" << metaData->m_tv_usec << "|"; } + +uint32_t SDRDaemonChannelSource::calculateDataReadQueueSize(int sampleRate) +{ + // scale for 20 blocks at 48 kS/s. Take next even number. + uint32_t maxSize = sampleRate / 2400; + maxSize = (maxSize % 2 == 0) ? maxSize : maxSize + 1; + qDebug("SDRDaemonChannelSource::calculateDataReadQueueSize: set max queue size to %u blocks", maxSize); + return maxSize; +} diff --git a/sdrdaemon/channel/sdrdaemonchannelsource.h b/sdrdaemon/channel/sdrdaemonchannelsource.h index f61c5cca1..e743b3418 100644 --- a/sdrdaemon/channel/sdrdaemonchannelsource.h +++ b/sdrdaemon/channel/sdrdaemonchannelsource.h @@ -106,6 +106,7 @@ private: void applySettings(const SDRDaemonChannelSourceSettings& settings, bool force = false); void handleDataBlock(SDRDaemonDataBlock *dataBlock); void printMeta(const QString& header, SDRDaemonMetaDataFEC *metaData); + uint32_t calculateDataReadQueueSize(int sampleRate); private slots: void handleData(); diff --git a/sdrdaemon/channel/sdrdaemondatareadqueue.cpp b/sdrdaemon/channel/sdrdaemondatareadqueue.cpp index 7081ee569..7dc92be51 100644 --- a/sdrdaemon/channel/sdrdaemondatareadqueue.cpp +++ b/sdrdaemon/channel/sdrdaemondatareadqueue.cpp @@ -23,10 +23,11 @@ #include "channel/sdrdaemondatablock.h" #include "channel/sdrdaemondatareadqueue.h" -const uint32_t SDRDaemonDataReadQueue::MaxSize = 20; +const uint32_t SDRDaemonDataReadQueue::MinimumMaxSize = 10; SDRDaemonDataReadQueue::SDRDaemonDataReadQueue() : m_dataBlock(0), + m_maxSize(MinimumMaxSize), m_blockIndex(1), m_sampleIndex(0), m_full(false) @@ -45,7 +46,7 @@ SDRDaemonDataReadQueue::~SDRDaemonDataReadQueue() void SDRDaemonDataReadQueue::push(SDRDaemonDataBlock* dataBlock) { - if (size() >= MaxSize) + if (size() >= m_maxSize) { qWarning("SDRDaemonDataReadQueue::push: queue is full"); m_full = true; // stop filling the queue @@ -54,7 +55,7 @@ void SDRDaemonDataReadQueue::push(SDRDaemonDataBlock* dataBlock) } if (m_full) { - m_full = (size() > MaxSize/2); // do not fill queue again before queue is half size + m_full = (size() > m_maxSize/2); // do not fill queue again before queue is half size } if (!m_full) { @@ -77,17 +78,24 @@ SDRDaemonDataBlock* SDRDaemonDataReadQueue::pop() } } -uint32_t SDRDaemonDataReadQueue::size() +uint32_t SDRDaemonDataReadQueue::size() const { return m_dataReadQueue.size(); } +void SDRDaemonDataReadQueue::setSize(uint32_t size) +{ + if (size != m_maxSize) { + m_maxSize = size < MinimumMaxSize ? MinimumMaxSize : size; + } +} + void SDRDaemonDataReadQueue::readSample(Sample& s) { // depletion/repletion state if (m_dataBlock == 0) { - if (size() >= MaxSize/2) + if (size() >= m_maxSize/2) { qDebug("SDRDaemonDataReadQueue::readSample: initial pop new block: queue size: %u", size()); m_blockIndex = 1; diff --git a/sdrdaemon/channel/sdrdaemondatareadqueue.h b/sdrdaemon/channel/sdrdaemondatareadqueue.h index 7caa3e5e6..fe9a88edc 100644 --- a/sdrdaemon/channel/sdrdaemondatareadqueue.h +++ b/sdrdaemon/channel/sdrdaemondatareadqueue.h @@ -37,13 +37,15 @@ public: void push(SDRDaemonDataBlock* dataBlock); //!< push block on the queue SDRDaemonDataBlock* pop(); //!< Pop block from the queue void readSample(Sample& s); //!< Read sample from queue - uint32_t size(); //!< Returns queue size + uint32_t size() const; //!< Returns queue size + void setSize(uint32_t size); //!< Sets the queue size - static const uint32_t MaxSize; + static const uint32_t MinimumMaxSize; private: QQueue m_dataReadQueue; SDRDaemonDataBlock *m_dataBlock; + uint32_t m_maxSize; uint32_t m_blockIndex; uint32_t m_sampleIndex; bool m_full; //!< full condition was hit