1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-16 05:11:49 -05:00

SDRdaemon: channel source data read queue: scale max length to sample rate

This commit is contained in:
f4exb 2018-08-29 08:48:57 +02:00
parent 5013e77f24
commit c7bcfaead1
4 changed files with 30 additions and 8 deletions

View File

@ -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;
}

View File

@ -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();

View File

@ -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;

View File

@ -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<SDRDaemonDataBlock*> m_dataReadQueue;
SDRDaemonDataBlock *m_dataBlock;
uint32_t m_maxSize;
uint32_t m_blockIndex;
uint32_t m_sampleIndex;
bool m_full; //!< full condition was hit