From b5f2475fbf8ec72246420d0058bd202eecd8c15f Mon Sep 17 00:00:00 2001 From: f4exb Date: Fri, 14 Aug 2015 09:02:10 +0200 Subject: [PATCH] Deep redesign: phase #3 --- include-gpl/dsp/dspengine.h | 1 + include/dsp/samplesource/samplesource.h | 10 +++- sdrbase/dsp/dspengine.cpp | 37 ++++++++++++ sdrbase/dsp/samplesource/samplesource.cpp | 71 +++++++++-------------- 4 files changed, 75 insertions(+), 44 deletions(-) diff --git a/include-gpl/dsp/dspengine.h b/include-gpl/dsp/dspengine.h index ca85ef400..1f90f7aa8 100644 --- a/include-gpl/dsp/dspengine.h +++ b/include-gpl/dsp/dspengine.h @@ -118,6 +118,7 @@ private: private slots: void handleData(); //!< Handle data when samples from source FIFO are ready to be processed + void handleSourceMessages(); //!< Handle source message output void handleInputMessages(); //!< Handle input message queue void handleSynchronousMessages(Message *message); //!< Handle synchronous messages with the thread }; diff --git a/include/dsp/samplesource/samplesource.h b/include/dsp/samplesource/samplesource.h index f33d4104f..c6bd0cc29 100644 --- a/include/dsp/samplesource/samplesource.h +++ b/include/dsp/samplesource/samplesource.h @@ -34,8 +34,8 @@ public: virtual void stop() = 0; virtual const QString& getDeviceDescription() const = 0; - virtual int getSampleRate() const = 0; - virtual quint64 getCenterFrequency() const = 0; + virtual int getSampleRate() const { return m_sampleRate; }; + virtual quint64 getCenterFrequency() const { return m_centerFrequency; }; virtual bool handleMessage(const Message& message) = 0; @@ -44,9 +44,15 @@ public: SampleFifo* getSampleFifo() { return &m_sampleFifo; } protected: + void setSampleRate(int sampleRate); + void setCenterFrequency(quint64 centerFrequency); + void sendNewData(); + SampleFifo m_sampleFifo; MessageQueue m_inputMessageQueue; MessageQueue m_outputMessageQueue; + int m_sampleRate; + quint64 m_centerFrequency; }; #endif // INCLUDE_SAMPLESOURCE_H diff --git a/sdrbase/dsp/dspengine.cpp b/sdrbase/dsp/dspengine.cpp index aff05a6d8..0c57f9c5f 100644 --- a/sdrbase/dsp/dspengine.cpp +++ b/sdrbase/dsp/dspengine.cpp @@ -438,6 +438,7 @@ void DSPEngine::handleSetSource(SampleSource* source) if(m_sampleSource != 0) { disconnect(m_sampleSource->getSampleFifo(), SIGNAL(dataReady()), this, SLOT(handleData())); + disconnect(m_sampleSource->getOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); } m_sampleSource = source; @@ -446,6 +447,7 @@ void DSPEngine::handleSetSource(SampleSource* source) { qDebug() << " - connect"; connect(m_sampleSource->getSampleFifo(), SIGNAL(dataReady()), this, SLOT(handleData()), Qt::QueuedConnection); + connect(m_sampleSource->getOutputMessageQueue(), SIGNAL(messageEnqueued()), this, SLOT(handleSourceMessages())); } } @@ -566,3 +568,38 @@ void DSPEngine::handleInputMessages() delete message; } } + +void DSPEngine::handleSourceMessages() +{ + Message *message; + + qDebug() << "DSPEngine::handleSourceMessages"; + + while ((message = m_sampleSource->getOutputMessageQueue()->pop()) != 0) + { + if (DSPSignalNotification::match(message)) + { + DSPSignalNotification *notif = (DSPSignalNotification *) &message; + + // update DSP values + + m_sampleRate = notif->getSampleRate(); + m_centerFrequency = notif->getFrequencyOffset(); + + // forward source changes to sinks + + for(SampleSinks::const_iterator it = m_sampleSinks.begin(); it != m_sampleSinks.end(); it++) + { + qDebug() << " - initializing " << (*it)->objectName().toStdString().c_str(); + (*it)->init(*message); + } + + // forward changes to listeners + + DSPEngineReport* rep = new DSPEngineReport(m_sampleRate, m_centerFrequency); + m_outputMessageQueue.push(rep); + } + + delete message; + } +} diff --git a/sdrbase/dsp/samplesource/samplesource.cpp b/sdrbase/dsp/samplesource/samplesource.cpp index c48e60ba0..ac91bf4db 100644 --- a/sdrbase/dsp/samplesource/samplesource.cpp +++ b/sdrbase/dsp/samplesource/samplesource.cpp @@ -16,54 +16,41 @@ /////////////////////////////////////////////////////////////////////////////////// #include "dsp/samplesource/samplesource.h" -#include "util/simpleserializer.h" +#include "dsp/dspcommands.h" #include -SampleSource::GeneralSettings::GeneralSettings() : - m_centerFrequency(100000000) -{ -} - -void SampleSource::GeneralSettings::resetToDefaults() -{ - m_centerFrequency = 100000000; -} - -QByteArray SampleSource::GeneralSettings::serialize() const -{ - SimpleSerializer s(1); - s.writeU64(1, m_centerFrequency); - return s.final(); -} - -bool SampleSource::GeneralSettings::deserialize(const QByteArray& data) -{ - SimpleDeserializer d(data); - - if(!d.isValid()) { - qDebug() << "SampleSource::GeneralSettings::deserialize: invalid deserializer"; - resetToDefaults(); - return false; - } - - if(d.getVersion() == 1) { - d.readU64(1, &m_centerFrequency, 100000000); - qDebug() << "SampleSource::GeneralSettings::deserialize: center frequency = " - << m_centerFrequency; - return true; - } else { - resetToDefaults(); - return false; - } -} - -SampleSource::SampleSource(MessageQueue* guiMessageQueue) : - m_sampleFifo(), - m_guiMessageQueue(guiMessageQueue) +SampleSource::SampleSource() : + m_sampleRate(0), + m_centerFrequency(0) { } SampleSource::~SampleSource() { } + +void SampleSource::setSampleRate(int sampleRate) +{ + if (sampleRate != m_sampleRate) + { + // TODO: adjust FIFO size + m_sampleRate = sampleRate; + sendNewData(); + } +} + +void SampleSource::setCenterFrequency(quint64 centerFrequency) +{ + if (centerFrequency != m_centerFrequency) + { + m_centerFrequency = centerFrequency; + sendNewData(); + } +} + +void SampleSource::sendNewData() +{ + DSPSignalNotification *notif = new DSPSignalNotification(m_sampleRate, m_centerFrequency); + m_outputMessageQueue.push(notif); +}