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

SSB demod: separate GUI from demod

This commit is contained in:
f4exb 2017-10-01 22:12:10 +02:00
parent 6095cf549c
commit 06ac0d6b4d
4 changed files with 68 additions and 24 deletions

View File

@ -16,19 +16,25 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // // along with this program. If not, see <http://www.gnu.org/licenses/>. //
/////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////
#include "ssbdemod.h"
#include <dsp/downchannelizer.h>
#include <QTime> #include <QTime>
#include <QDebug> #include <QDebug>
#include <stdio.h> #include <stdio.h>
#include "audio/audiooutput.h" #include "audio/audiooutput.h"
#include "dsp/dspengine.h" #include "dsp/dspengine.h"
#include <dsp/downchannelizer.h>
#include "dsp/threadedbasebandsamplesink.h"
#include "device/devicesourceapi.h"
#include "util/db.h" #include "util/db.h"
MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message) #include "ssbdemod.h"
SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) : MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureSSBDemod, Message)
MESSAGE_CLASS_DEFINITION(SSBDemod::MsgConfigureChannelizer, Message)
SSBDemod::SSBDemod(DeviceSourceAPI *deviceAPI) :
m_deviceAPI(deviceAPI),
m_audioBinaual(false), m_audioBinaual(false),
m_audioFlipChannels(false), m_audioFlipChannels(false),
m_dsb(false), m_dsb(false),
@ -40,7 +46,7 @@ SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) :
m_agcPowerThreshold(1e-2), m_agcPowerThreshold(1e-2),
m_agcThresholdGate(0), m_agcThresholdGate(0),
m_audioActive(false), m_audioActive(false),
m_sampleSink(sampleSink), m_sampleSink(0),
m_audioFifo(24000), m_audioFifo(24000),
m_settingsMutex(QMutex::Recursive) m_settingsMutex(QMutex::Recursive)
{ {
@ -75,6 +81,10 @@ SSBDemod::SSBDemod(BasebandSampleSink* sampleSink) :
SSBFilter = new fftfilt(m_LowCutoff / m_audioSampleRate, m_Bandwidth / m_audioSampleRate, ssbFftLen); SSBFilter = new fftfilt(m_LowCutoff / m_audioSampleRate, m_Bandwidth / m_audioSampleRate, ssbFftLen);
DSBFilter = new fftfilt((2.0f * m_Bandwidth) / m_audioSampleRate, 2 * ssbFftLen); DSBFilter = new fftfilt((2.0f * m_Bandwidth) / m_audioSampleRate, 2 * ssbFftLen);
m_channelizer = new DownChannelizer(this);
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this);
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
DSPEngine::instance()->addAudioSink(&m_audioFifo); DSPEngine::instance()->addAudioSink(&m_audioFifo);
} }
@ -84,6 +94,10 @@ SSBDemod::~SSBDemod()
if (DSBFilter) delete DSBFilter; if (DSBFilter) delete DSBFilter;
DSPEngine::instance()->removeAudioSink(&m_audioFifo); DSPEngine::instance()->removeAudioSink(&m_audioFifo);
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
} }
void SSBDemod::configure(MessageQueue* messageQueue, void SSBDemod::configure(MessageQueue* messageQueue,
@ -284,6 +298,16 @@ bool SSBDemod::handleMessage(const Message& cmd)
return true; return true;
} }
else if (MsgConfigureChannelizer::match(cmd))
{
MsgConfigureChannelizer& cfg = (MsgConfigureChannelizer&) cmd;
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
cfg.getSampleRate(),
cfg.getCenterFrequency());
return true;
}
else if (MsgConfigureSSBDemod::match(cmd)) else if (MsgConfigureSSBDemod::match(cmd))
{ {
MsgConfigureSSBDemod& cfg = (MsgConfigureSSBDemod&) cmd; MsgConfigureSSBDemod& cfg = (MsgConfigureSSBDemod&) cmd;

View File

@ -31,10 +31,38 @@
#define ssbFftLen 1024 #define ssbFftLen 1024
#define agcTarget 3276.8 // -10 dB amplitude => -20 dB power: center of normal signal #define agcTarget 3276.8 // -10 dB amplitude => -20 dB power: center of normal signal
class DeviceSourceAPI;
class ThreadedBasebandSampleSink;
class DownChannelizer;
class SSBDemod : public BasebandSampleSink { class SSBDemod : public BasebandSampleSink {
public: public:
SSBDemod(BasebandSampleSink* sampleSink); class MsgConfigureChannelizer : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getSampleRate() const { return m_sampleRate; }
int getCenterFrequency() const { return m_centerFrequency; }
static MsgConfigureChannelizer* create(int sampleRate, int centerFrequency)
{
return new MsgConfigureChannelizer(sampleRate, centerFrequency);
}
private:
int m_sampleRate;
int m_centerFrequency;
MsgConfigureChannelizer(int sampleRate, int centerFrequency) :
Message(),
m_sampleRate(sampleRate),
m_centerFrequency(centerFrequency)
{ }
};
SSBDemod(DeviceSourceAPI *deviceAPI);
virtual ~SSBDemod(); virtual ~SSBDemod();
void setSampleSink(BasebandSampleSink* sampleSink) { m_sampleSink = sampleSink; }
void configure(MessageQueue* messageQueue, void configure(MessageQueue* messageQueue,
Real Bandwidth, Real Bandwidth,
@ -164,6 +192,10 @@ private:
{ } { }
}; };
DeviceSourceAPI *m_deviceAPI;
ThreadedBasebandSampleSink* m_threadedChannelizer;
DownChannelizer* m_channelizer;
Real m_Bandwidth; Real m_Bandwidth;
Real m_LowCutoff; Real m_LowCutoff;
Real m_volume; Real m_volume;

View File

@ -2,11 +2,9 @@
#include "ssbdemodgui.h" #include "ssbdemodgui.h"
#include <device/devicesourceapi.h> #include <device/devicesourceapi.h>
#include <dsp/downchannelizer.h>
#include <QDockWidget> #include <QDockWidget>
#include <QMainWindow> #include <QMainWindow>
#include "dsp/threadedbasebandsamplesink.h"
#include "ui_ssbdemodgui.h" #include "ui_ssbdemodgui.h"
#include "ui_ssbdemodgui.h" #include "ui_ssbdemodgui.h"
#include "dsp/spectrumvis.h" #include "dsp/spectrumvis.h"
@ -373,10 +371,9 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
m_spectrumVis = new SpectrumVis(ui->glSpectrum); m_spectrumVis = new SpectrumVis(ui->glSpectrum);
m_ssbDemod = new SSBDemod(m_spectrumVis); m_ssbDemod = new SSBDemod(m_deviceAPI);
m_channelizer = new DownChannelizer(m_ssbDemod); m_ssbDemod->setMessageQueueToGUI(getInputMessageQueue());
m_threadedChannelizer = new ThreadedBasebandSampleSink(m_channelizer, this); m_ssbDemod->setSampleSink(m_spectrumVis);
m_deviceAPI->addThreadedSink(m_threadedChannelizer);
ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03))); ui->deltaFrequencyLabel->setText(QString("%1f").arg(QChar(0x94, 0x03)));
ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold)); ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::GrayGold));
@ -389,7 +386,6 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg
connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
//m_channelMarker = new ChannelMarker(this);
m_channelMarker.setColor(Qt::green); m_channelMarker.setColor(Qt::green);
m_channelMarker.setBandwidth(m_rate); m_channelMarker.setBandwidth(m_rate);
m_channelMarker.setSidebands(ChannelMarker::usb); m_channelMarker.setSidebands(ChannelMarker::usb);
@ -413,12 +409,8 @@ SSBDemodGUI::SSBDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidg
SSBDemodGUI::~SSBDemodGUI() SSBDemodGUI::~SSBDemodGUI()
{ {
m_deviceAPI->removeChannelInstance(this); m_deviceAPI->removeChannelInstance(this);
m_deviceAPI->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
delete m_ssbDemod; delete m_ssbDemod;
delete m_spectrumVis; delete m_spectrumVis;
//delete m_channelMarker;
delete ui; delete ui;
} }
@ -511,9 +503,9 @@ void SSBDemodGUI::applySettings()
setTitleColor(m_channelMarker.getColor()); setTitleColor(m_channelMarker.getColor());
ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency()); ui->deltaFrequency->setValue(m_channelMarker.getCenterFrequency());
m_channelizer->configure(m_channelizer->getInputMessageQueue(), SSBDemod::MsgConfigureChannelizer* channelConfigMsg = SSBDemod::MsgConfigureChannelizer::create(
48000, 48000, m_channelMarker.getCenterFrequency());
m_channelMarker.getCenterFrequency()); m_ssbDemod->getInputMessageQueue()->push(channelConfigMsg);
m_ssbDemod->configure(m_ssbDemod->getInputMessageQueue(), m_ssbDemod->configure(m_ssbDemod->getInputMessageQueue(),
ui->BW->value() * 100.0, ui->BW->value() * 100.0,

View File

@ -11,8 +11,6 @@ class PluginAPI;
class DeviceSourceAPI; class DeviceSourceAPI;
class AudioFifo; class AudioFifo;
class ThreadedBasebandSampleSink;
class DownChannelizer;
class SSBDemod; class SSBDemod;
class SpectrumVis; class SpectrumVis;
@ -76,8 +74,6 @@ private:
bool m_squelchOpen; bool m_squelchOpen;
uint32_t m_tickCount; uint32_t m_tickCount;
ThreadedBasebandSampleSink* m_threadedChannelizer;
DownChannelizer* m_channelizer;
SSBDemod* m_ssbDemod; SSBDemod* m_ssbDemod;
SpectrumVis* m_spectrumVis; SpectrumVis* m_spectrumVis;
MessageQueue m_inputMessageQueue; MessageQueue m_inputMessageQueue;