From 6dae67d5b12a0ec899d2117f8ed2ab8b91ec7bd3 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 25 Aug 2019 00:45:36 +0200 Subject: [PATCH] MIMO engine: use SampleSinkVectors instead of SampleSinkFIFOs --- plugins/samplemimo/testmi/testmi.cpp | 3 +- plugins/samplemimo/testmi/testmithread.cpp | 2 +- plugins/samplemimo/testmi/testmithread.h | 6 +- sdrbase/dsp/devicesamplemimo.cpp | 2 +- sdrbase/dsp/devicesamplemimo.h | 6 +- sdrbase/dsp/dspdevicemimoengine.cpp | 96 ++++++---------------- sdrbase/dsp/samplesinkvector.cpp | 7 +- sdrbase/dsp/samplesinkvector.h | 8 +- sdrbase/dsp/threadedbasebandsamplesink.cpp | 4 +- 9 files changed, 47 insertions(+), 87 deletions(-) diff --git a/plugins/samplemimo/testmi/testmi.cpp b/plugins/samplemimo/testmi/testmi.cpp index cae59c3ab..6d43c1633 100644 --- a/plugins/samplemimo/testmi/testmi.cpp +++ b/plugins/samplemimo/testmi/testmi.cpp @@ -50,8 +50,7 @@ TestMI::TestMI(DeviceAPI *deviceAPI) : m_masterTimer(deviceAPI->getMasterTimer()) { m_mimoType = MIMOAsynchronous; - m_sampleSinkFifos.push_back(SampleSinkFifo(96000 * 4)); - m_sampleSinkFifos.push_back(SampleSinkFifo(96000 * 4)); + m_sampleSinkFifos.resize(2); m_deviceAPI->setNbSourceStreams(2); m_networkManager = new QNetworkAccessManager(); connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(networkManagerFinished(QNetworkReply*))); diff --git a/plugins/samplemimo/testmi/testmithread.cpp b/plugins/samplemimo/testmi/testmithread.cpp index 53457a7b4..e25a1272c 100644 --- a/plugins/samplemimo/testmi/testmithread.cpp +++ b/plugins/samplemimo/testmi/testmithread.cpp @@ -28,7 +28,7 @@ MESSAGE_CLASS_DEFINITION(TestMIThread::MsgStartStop, Message) -TestMIThread::TestMIThread(SampleSinkFifo* sampleFifo, int streamIndex, QObject* parent) : +TestMIThread::TestMIThread(SampleSinkVector* sampleFifo, int streamIndex, QObject* parent) : QThread(parent), m_running(false), m_buf(0), diff --git a/plugins/samplemimo/testmi/testmithread.h b/plugins/samplemimo/testmi/testmithread.h index 72e8bad97..e008a39f0 100644 --- a/plugins/samplemimo/testmi/testmithread.h +++ b/plugins/samplemimo/testmi/testmithread.h @@ -25,7 +25,7 @@ #include #include -#include "dsp/samplesinkfifo.h" +#include "dsp/samplesinkvector.h" #include "dsp/decimators.h" #include "dsp/ncof.h" #include "util/message.h" @@ -58,7 +58,7 @@ public: { } }; - TestMIThread(SampleSinkFifo* sampleFifo, int streamIndex, QObject* parent = 0); + TestMIThread(SampleSinkVector* sampleFifo, int streamIndex, QObject* parent = 0); ~TestMIThread(); void startStop(bool start); @@ -89,7 +89,7 @@ private: quint32 m_bufsize; quint32 m_chunksize; SampleVector m_convertBuffer; - SampleSinkFifo* m_sampleFifo; + SampleSinkVector* m_sampleFifo; int m_streamIndex; NCOF m_nco; NCOF m_toneNco; diff --git a/sdrbase/dsp/devicesamplemimo.cpp b/sdrbase/dsp/devicesamplemimo.cpp index 08a0e933b..a4381009e 100644 --- a/sdrbase/dsp/devicesamplemimo.cpp +++ b/sdrbase/dsp/devicesamplemimo.cpp @@ -52,7 +52,7 @@ SampleSourceFifo* DeviceSampleMIMO::getSampleSourceFifo(unsigned int index) } } -SampleSinkFifo* DeviceSampleMIMO::getSampleSinkFifo(unsigned int index) +SampleSinkVector* DeviceSampleMIMO::getSampleSinkFifo(unsigned int index) { if (index >= m_sampleSinkFifos.size()) { return nullptr; diff --git a/sdrbase/dsp/devicesamplemimo.h b/sdrbase/dsp/devicesamplemimo.h index 6dd597a3c..bb670b1f7 100644 --- a/sdrbase/dsp/devicesamplemimo.h +++ b/sdrbase/dsp/devicesamplemimo.h @@ -22,7 +22,7 @@ #include #include "samplesourcefifo.h" -#include "samplesinkfifo.h" +#include "samplesinkvector.h" #include "util/message.h" #include "util/messagequeue.h" #include "export.h" @@ -133,7 +133,7 @@ public: unsigned int getNbSourceFifos() const { return m_sampleSourceFifos.size(); } //!< Get the number of Tx FIFOs unsigned int getNbSinkFifos() const { return m_sampleSinkFifos.size(); } //!< Get the number of Rx FIFOs SampleSourceFifo* getSampleSourceFifo(unsigned int index); //!< Get Tx FIFO at index - SampleSinkFifo* getSampleSinkFifo(unsigned int index); //!< Get Rx FIFO at index + SampleSinkVector* getSampleSinkFifo(unsigned int index); //!< Get Rx FIFO at index // Streams and FIFOs are in opposed source/sink type whick makes it confusing when stream direction is involved: // Rx: source stream -> sink FIFO -> channel sinks // Tx: sink stream <- source FIFO <- channel sources @@ -146,7 +146,7 @@ protected slots: protected: MIMOType m_mimoType; std::vector m_sampleSourceFifos; //!< Tx FIFOs - std::vector m_sampleSinkFifos; //!< Rx FIFOs + std::vector m_sampleSinkFifos; //!< Rx FIFOs MessageQueue m_inputMessageQueue; //!< Input queue to the sink MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI }; diff --git a/sdrbase/dsp/dspdevicemimoengine.cpp b/sdrbase/dsp/dspdevicemimoengine.cpp index 42920e34d..ebbc44eee 100644 --- a/sdrbase/dsp/dspdevicemimoengine.cpp +++ b/sdrbase/dsp/dspdevicemimoengine.cpp @@ -254,79 +254,35 @@ QString DSPDeviceMIMOEngine::deviceDescription() */ void DSPDeviceMIMOEngine::workSampleSink(unsigned int sinkIndex) { - SampleSinkFifo* sampleFifo = m_deviceSampleMIMO->getSampleSinkFifo(sinkIndex); - int samplesDone = 0; + SampleSinkVector* sampleFifo = m_deviceSampleMIMO->getSampleSinkFifo(sinkIndex); + SampleVector::iterator vbegin; + SampleVector::iterator vend; bool positiveOnly = false; + sampleFifo->read(vbegin, vend); - while ((sampleFifo->fill() > 0) && (m_inputMessageQueue.size() == 0) && (samplesDone < m_deviceSampleMIMO->getSourceSampleRate(sinkIndex))) - { - SampleVector::iterator part1begin; - SampleVector::iterator part1end; - SampleVector::iterator part2begin; - SampleVector::iterator part2end; + // DC and IQ corrections + if (m_sourcesCorrections[sinkIndex].m_dcOffsetCorrection) { + iqCorrections(vbegin, vend, sinkIndex, m_sourcesCorrections[sinkIndex].m_iqImbalanceCorrection); + } - std::size_t count = sampleFifo->readBegin(sampleFifo->fill(), &part1begin, &part1end, &part2begin, &part2end); + // feed data to direct sinks + if (sinkIndex < m_basebandSampleSinks.size()) + { + for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[sinkIndex].begin(); it != m_basebandSampleSinks[sinkIndex].end(); ++it) { + (*it)->feed(vbegin, vend, positiveOnly); + } + } - // first part of FIFO data - if (part1begin != part1end) - { - // DC and IQ corrections - if (m_sourcesCorrections[sinkIndex].m_dcOffsetCorrection) { - iqCorrections(part1begin, part1end, sinkIndex, m_sourcesCorrections[sinkIndex].m_iqImbalanceCorrection); - } + // possibly feed data to spectrum sink + if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (sinkIndex == m_spectrumInputIndex)) { + m_spectrumSink->feed(vbegin, vend, positiveOnly); + } - // feed data to direct sinks - if (sinkIndex < m_basebandSampleSinks.size()) - { - for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[sinkIndex].begin(); it != m_basebandSampleSinks[sinkIndex].end(); ++it) { - (*it)->feed(part1begin, part1end, positiveOnly); - } - } - - // possibly feed data to spectrum sink - if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (sinkIndex == m_spectrumInputIndex)) { - m_spectrumSink->feed(part1begin, part1end, positiveOnly); - } - - // feed data to threaded sinks - for (ThreadedBasebandSampleSinks::const_iterator it = m_threadedBasebandSampleSinks[sinkIndex].begin(); it != m_threadedBasebandSampleSinks[sinkIndex].end(); ++it) - { - (*it)->feed(part1begin, part1end, positiveOnly); - } - } - - // second part of FIFO data (used when block wraps around) - if(part2begin != part2end) - { - // DC and IQ corrections - if (m_sourcesCorrections[sinkIndex].m_dcOffsetCorrection) { - iqCorrections(part2begin, part2end, sinkIndex, m_sourcesCorrections[sinkIndex].m_iqImbalanceCorrection); - } - - // feed data to direct sinks - if (sinkIndex < m_basebandSampleSinks.size()) - { - for (BasebandSampleSinks::const_iterator it = m_basebandSampleSinks[sinkIndex].begin(); it != m_basebandSampleSinks[sinkIndex].end(); ++it) { - (*it)->feed(part2begin, part2end, positiveOnly); - } - } - - // possibly feed data to spectrum sink - if ((m_spectrumSink) && (m_spectrumInputSourceElseSink) && (sinkIndex == m_spectrumInputIndex)) { - m_spectrumSink->feed(part2begin, part2end, positiveOnly); - } - - // feed data to threaded sinks - for (ThreadedBasebandSampleSinks::const_iterator it = m_threadedBasebandSampleSinks[sinkIndex].begin(); it != m_threadedBasebandSampleSinks[sinkIndex].end(); ++it) - { - (*it)->feed(part2begin, part2end, positiveOnly); - } - } - - // adjust FIFO pointers - sampleFifo->readCommit((unsigned int) count); - samplesDone += count; - } + // feed data to threaded sinks + for (ThreadedBasebandSampleSinks::const_iterator it = m_threadedBasebandSampleSinks[sinkIndex].begin(); it != m_threadedBasebandSampleSinks[sinkIndex].end(); ++it) + { + (*it)->feed(vbegin, vend, positiveOnly); + } } // notStarted -> idle -> init -> running -+ @@ -583,7 +539,7 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) qPrintable(mimo->getDeviceDescription()), isink); QObject::connect( m_deviceSampleMIMO->getSampleSinkFifo(isink), - &SampleSinkFifo::dataReady, + &SampleSinkVector::dataReady, this, [=](){ this->handleDataRxSync(); }, // lambda function is not strictly needed here Qt::QueuedConnection @@ -599,7 +555,7 @@ void DSPDeviceMIMOEngine::handleSetMIMO(DeviceSampleMIMO* mimo) qPrintable(mimo->getDeviceDescription()), isink); QObject::connect( m_deviceSampleMIMO->getSampleSinkFifo(isink), - &SampleSinkFifo::dataReady, + &SampleSinkVector::dataReady, this, [=](){ this->handleDataRxAsync(isink); }, Qt::QueuedConnection diff --git a/sdrbase/dsp/samplesinkvector.cpp b/sdrbase/dsp/samplesinkvector.cpp index 68808d921..40c3d8dfc 100644 --- a/sdrbase/dsp/samplesinkvector.cpp +++ b/sdrbase/dsp/samplesinkvector.cpp @@ -22,6 +22,11 @@ SampleSinkVector::SampleSinkVector(QObject* parent) : m_dataSize(0) {} +SampleSinkVector::SampleSinkVector(const SampleSinkVector& other) : + m_sampleVector(other.m_sampleVector), + m_dataSize(other.m_dataSize) +{} + SampleSinkVector::~SampleSinkVector() {} @@ -38,7 +43,7 @@ void SampleSinkVector::write(const SampleVector::const_iterator& begin, const Sa emit dataReady(); } -void SampleSinkVector::read(SampleVector::const_iterator& begin, SampleVector::const_iterator& end) +void SampleSinkVector::read(SampleVector::iterator& begin, SampleVector::iterator& end) { begin = m_sampleVector.begin(); end = m_sampleVector.begin() + m_dataSize; diff --git a/sdrbase/dsp/samplesinkvector.h b/sdrbase/dsp/samplesinkvector.h index 8eb008e52..887a0b352 100644 --- a/sdrbase/dsp/samplesinkvector.h +++ b/sdrbase/dsp/samplesinkvector.h @@ -28,10 +28,11 @@ class SDRBASE_API SampleSinkVector : public QObject { public: SampleSinkVector(QObject* parent = nullptr); + SampleSinkVector(const SampleSinkVector& other); ~SampleSinkVector(); void write(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end); - void read(SampleVector::const_iterator& begin, SampleVector::const_iterator& end); + void read(SampleVector::iterator& begin, SampleVector::iterator& end); signals: void dataReady(); @@ -39,9 +40,8 @@ signals: private: SampleVector m_sampleVector; int m_dataSize; - int m_sampleVectorSize; - SampleVector::const_iterator m_begin; - SampleVector::const_iterator m_end; + // SampleVector::const_iterator m_begin; + // SampleVector::const_iterator m_end; }; diff --git a/sdrbase/dsp/threadedbasebandsamplesink.cpp b/sdrbase/dsp/threadedbasebandsamplesink.cpp index 809e6815b..2dfd2787f 100644 --- a/sdrbase/dsp/threadedbasebandsamplesink.cpp +++ b/sdrbase/dsp/threadedbasebandsamplesink.cpp @@ -26,8 +26,8 @@ void ThreadedBasebandSampleSinkFifo::writeToFifo(SampleVector::const_iterator& b void ThreadedBasebandSampleSinkFifo::handleVectorData() { - SampleVector::const_iterator vbegin; - SampleVector::const_iterator vend; + SampleVector::iterator vbegin; + SampleVector::iterator vend; if (m_sampleSink) {