diff --git a/sdrbase/dsp/basebandsamplesource.cpp b/sdrbase/dsp/basebandsamplesource.cpp index edbf2d2f4..f8de665b8 100644 --- a/sdrbase/dsp/basebandsamplesource.cpp +++ b/sdrbase/dsp/basebandsamplesource.cpp @@ -20,7 +20,8 @@ BasebandSampleSource::BasebandSampleSource() : m_guiMessageQueue(0), - m_sampleFifo(48000) // arbitrary, will be adjusted to match device sink FIFO size + m_sampleFifo(48000), // arbitrary, will be adjusted to match device sink FIFO size + m_deviceSampleFifo(0) { connect(&m_inputMessageQueue, SIGNAL(messageEnqueued()), this, SLOT(handleInputMessages())); connect(&m_sampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleWriteToFifo(int))); @@ -44,16 +45,41 @@ void BasebandSampleSource::handleInputMessages() } void BasebandSampleSource::handleWriteToFifo(int nbSamples) +{ + handleWriteToFifo(&m_sampleFifo, nbSamples); +} + +void BasebandSampleSource::handleWriteToDeviceFifo(int nbSamples) +{ + handleWriteToFifo(m_deviceSampleFifo, nbSamples); +} + +void BasebandSampleSource::handleWriteToFifo(SampleSourceFifo *sampleFifo, int nbSamples) { SampleVector::iterator writeAt; - m_sampleFifo.getWriteIterator(writeAt); + sampleFifo->getWriteIterator(writeAt); pullAudio(nbSamples); // Pre-fetch input audio samples this is mandatory to keep things running smoothly for (int i = 0; i < nbSamples; i++) { pull((*writeAt)); - m_sampleFifo.bumpIndex(writeAt); + sampleFifo->bumpIndex(writeAt); } } +void BasebandSampleSource::setDeviceSampleSourceFifo(SampleSourceFifo *deviceSampleFifo) +{ + if (m_deviceSampleFifo != deviceSampleFifo) + { + if (m_deviceSampleFifo) { + disconnect(m_deviceSampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleWriteToDeviceFifo(int))); + } + + if (deviceSampleFifo) { + connect(deviceSampleFifo, SIGNAL(dataWrite(int)), this, SLOT(handleWriteToDeviceFifo(int))); + } + + m_deviceSampleFifo = deviceSampleFifo; + } +} diff --git a/sdrbase/dsp/basebandsamplesource.h b/sdrbase/dsp/basebandsamplesource.h index d860505d1..4daac5840 100644 --- a/sdrbase/dsp/basebandsamplesource.h +++ b/sdrbase/dsp/basebandsamplesource.h @@ -58,15 +58,20 @@ public: MessageQueue *getInputMessageQueue() { return &m_inputMessageQueue; } //!< Get the queue for asynchronous inbound communication virtual void setMessageQueueToGUI(MessageQueue *queue) { m_guiMessageQueue = queue; } MessageQueue *getMessageQueueToGUI() { return m_guiMessageQueue; } + void setDeviceSampleSourceFifo(SampleSourceFifo *deviceSampleFifo); protected: - MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication - MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI - SampleSourceFifo m_sampleFifo; //!< Internal FIFO for multi-channel processing + MessageQueue m_inputMessageQueue; //!< Queue for asynchronous inbound communication + MessageQueue *m_guiMessageQueue; //!< Input message queue to the GUI + SampleSourceFifo m_sampleFifo; //!< Internal FIFO for multi-channel processing + SampleSourceFifo *m_deviceSampleFifo; //!< Reference to the device FIFO for single channel processing + + void handleWriteToFifo(SampleSourceFifo *sampleFifo, int nbSamples); protected slots: void handleInputMessages(); void handleWriteToFifo(int nbSamples); + void handleWriteToDeviceFifo(int nbSamples); }; #endif /* SDRBASE_DSP_BASEBANDSAMPLESOURCE_H_ */ diff --git a/sdrbase/dsp/dspdevicesinkengine.cpp b/sdrbase/dsp/dspdevicesinkengine.cpp index 93143e641..d8c41eede 100644 --- a/sdrbase/dsp/dspdevicesinkengine.cpp +++ b/sdrbase/dsp/dspdevicesinkengine.cpp @@ -179,9 +179,9 @@ void DSPDeviceSinkEngine::work(int nbWriteSamples) { // qDebug("DSPDeviceSinkEngine::work: single channel source handling"); if (m_threadedBasebandSampleSources.size() == 1) { - m_threadedBasebandSampleSources.back()->feed(sampleFifo, nbWriteSamples); + m_threadedBasebandSampleSources.back()->setDeviceSampleSourceFifo(sampleFifo); } else if (m_basebandSampleSources.size() == 1) { - m_basebandSampleSources.back()->feed(sampleFifo, nbWriteSamples); + m_threadedBasebandSampleSources.back()->setDeviceSampleSourceFifo(sampleFifo); } } // multiple channel sources handling @@ -257,11 +257,13 @@ void DSPDeviceSinkEngine::work(int nbWriteSamples) for (ThreadedBasebandSampleSources::iterator it = m_threadedBasebandSampleSources.begin(); it != m_threadedBasebandSampleSources.end(); ++it) { + (*it)->setDeviceSampleSourceFifo(0); (*it)->pullAudio(nbWriteSamples); } for (BasebandSampleSources::iterator it = m_basebandSampleSources.begin(); it != m_basebandSampleSources.end(); ++it) { + (*it)->setDeviceSampleSourceFifo(0); (*it)->pullAudio(nbWriteSamples); } diff --git a/sdrbase/dsp/threadedbasebandsamplesource.h b/sdrbase/dsp/threadedbasebandsamplesource.h index 4f509ee88..defb1cfb5 100644 --- a/sdrbase/dsp/threadedbasebandsamplesource.h +++ b/sdrbase/dsp/threadedbasebandsamplesource.h @@ -51,6 +51,7 @@ public: int nbSamples); SampleSourceFifo& getSampleSourceFifo() { return m_basebandSampleSource->getSampleSourceFifo(); } + void setDeviceSampleSourceFifo(SampleSourceFifo *deviceSampleFifo) { m_basebandSampleSource->setDeviceSampleSourceFifo(deviceSampleFifo); } QString getSampleSourceObjectName() const;