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

DSD demodulator: creation

This commit is contained in:
f4exb 2016-04-07 13:05:53 +02:00
parent 0978e17f2e
commit d4cd66f433
11 changed files with 1631 additions and 5 deletions

View File

@ -10,4 +10,6 @@ add_subdirectory(udpsrc)
add_subdirectory(demodwfm) add_subdirectory(demodwfm)
add_subdirectory(chanalyzer) add_subdirectory(chanalyzer)
#add_subdirectory(tetra) if(LIBMBE_FOUND)
add_subdirectory(demoddsd)
endif(LIBMBE_FOUND)

View File

@ -0,0 +1,44 @@
project(dsddemod)
set(dsddemod_SOURCES
dsddemod.cpp
dsddemodgui.cpp
dsddemodplugin.cpp
)
set(dsddemod_HEADERS
dsddemod.h
dsddemodgui.h
dsddemodplugin.h
)
set(dsddemod_FORMS
dsddemodgui.ui
)
include_directories(
.
${CMAKE_CURRENT_BINARY_DIR}
)
#include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED)
qt5_wrap_ui(dsddemod_FORMS_HEADERS ${dsddemod_FORMS})
add_library(demoddsd SHARED
${dsddemod_SOURCES}
${dsddemod_HEADERS_MOC}
${dsddemod_FORMS_HEADERS}
)
target_link_libraries(demoddsd
${QT_LIBRARIES}
sdrbase
)
qt5_use_modules(demoddsd Core Widgets OpenGL Multimedia)
install(TARGETS demoddsd DESTINATION lib/plugins/channel)

View File

@ -0,0 +1,294 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2012 maintech GmbH, Otto-Hahn-Str. 15, 97204 Hoechberg, Germany //
// written by Christian Daniel //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation as version 3 of the License, or //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#include <QTime>
#include <QDebug>
#include <stdio.h>
#include <complex.h>
#include "dsddemod.h"
#include "dsddemodgui.h"
#include "audio/audiooutput.h"
#include "dsp/channelizer.h"
#include "dsp/pidcontroller.h"
#include "dsp/dspengine.h"
static const Real afSqTones[2] = {1200.0, 6400.0}; // {1200.0, 8000.0};
MESSAGE_CLASS_DEFINITION(DSDDemod::MsgConfigureDSDDemod, Message)
DSDDemod::DSDDemod(SampleSink* sampleSink) :
m_sampleCount(0),
m_squelchCount(0),
m_agcAttack(2400),
m_audioMute(false),
m_squelchOpen(false),
m_afSquelch(2, afSqTones),
m_audioFifo(4, 48000),
m_fmExcursion(24),
m_settingsMutex(QMutex::Recursive),
m_scope(sampleSink),
m_scopeEnabled(false)
{
setObjectName("DSDDemod");
m_config.m_inputSampleRate = 96000;
m_config.m_inputFrequencyOffset = 0;
m_config.m_rfBandwidth = 100;
m_config.m_demodGain = 100;
m_config.m_fmDeviation = 100;
m_config.m_squelchGate = 5; // 10s of ms at 48000 Hz sample rate. Corresponds to 2400 for AGC attack
m_config.m_squelch = -30.0;
m_config.m_volume = 1.0;
m_config.m_audioMute = false;
m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate();
apply();
m_audioBuffer.resize(1<<14);
m_audioBufferFill = 0;
m_agcLevel = 1.0;
m_AGC.resize(m_agcAttack, m_agcLevel);
m_afSquelch.setCoefficients(24, 600, 48000.0, 200, 0); // 4000 Hz span, 250us, 100ms attack
DSPEngine::instance()->addAudioSink(&m_audioFifo);
}
DSDDemod::~DSDDemod()
{
DSPEngine::instance()->removeAudioSink(&m_audioFifo);
}
void DSDDemod::configure(MessageQueue* messageQueue,
int rfBandwidth,
int demodGain,
int fmDeviation,
int volume,
int squelchGate,
Real squelch,
bool audioMute)
{
Message* cmd = MsgConfigureDSDDemod::create(rfBandwidth,
demodGain,
fmDeviation,
volume,
squelchGate,
squelch,
audioMute);
messageQueue->push(cmd);
}
void DSDDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst)
{
Complex ci;
m_settingsMutex.lock();
m_scopeSampleBuffer.clear();
for (SampleVector::const_iterator it = begin; it != end; ++it)
{
Complex c(it->real(), it->imag());
c *= m_nco.nextIQ();
{
if (m_interpolator.interpolate(&m_interpolatorDistanceRemain, c, &ci))
{
qint16 sample;
m_AGC.feed(ci);
Real demod = m_phaseDiscri.phaseDiscriminator(ci);
m_sampleCount++;
// AF processing
if (getMag() > m_squelchLevel)
{
if (m_squelchCount < m_agcAttack)
{
m_squelchCount++;
}
}
else
{
m_squelchCount = 0;
}
m_squelchOpen = m_squelchCount == m_agcAttack; // wait for AGC to stabilize
if ((m_squelchOpen) && !m_running.m_audioMute)
{
sample = demod;
}
else
{
sample = 0;
}
Sample s(demod, 0.0);
m_scopeSampleBuffer.push_back(s);
// m_audioBuffer[m_audioBufferFill].l = sample;
// m_audioBuffer[m_audioBufferFill].r = sample;
// ++m_audioBufferFill;
//
// if (m_audioBufferFill >= m_audioBuffer.size())
// {
// uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
//
// if (res != m_audioBufferFill)
// {
// qDebug("DSDDemod::feed: %u/%u audio samples written", res, m_audioBufferFill);
// }
//
// m_audioBufferFill = 0;
// }
m_interpolatorDistanceRemain += m_interpolatorDistance;
}
}
}
if (m_audioBufferFill > 0)
{
uint res = m_audioFifo.write((const quint8*)&m_audioBuffer[0], m_audioBufferFill, 10);
if (res != m_audioBufferFill)
{
qDebug("NFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill);
}
m_audioBufferFill = 0;
}
if((m_scope != 0) && (m_scopeEnabled))
{
m_scope->feed(m_scopeSampleBuffer.begin(), m_scopeSampleBuffer.end(), true); // true = real samples for what it's worth
}
m_settingsMutex.unlock();
}
void DSDDemod::start()
{
m_audioFifo.clear();
m_phaseDiscri.reset();
}
void DSDDemod::stop()
{
}
bool DSDDemod::handleMessage(const Message& cmd)
{
qDebug() << "DSDDemod::handleMessage";
if (Channelizer::MsgChannelizerNotification::match(cmd))
{
Channelizer::MsgChannelizerNotification& notif = (Channelizer::MsgChannelizerNotification&) cmd;
m_config.m_inputSampleRate = notif.getSampleRate();
m_config.m_inputFrequencyOffset = notif.getFrequencyOffset();
apply();
qDebug() << "DSDDemod::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_config.m_inputSampleRate
<< " m_inputFrequencyOffset: " << m_config.m_inputFrequencyOffset;
return true;
}
else if (MsgConfigureDSDDemod::match(cmd))
{
MsgConfigureDSDDemod& cfg = (MsgConfigureDSDDemod&) cmd;
m_config.m_rfBandwidth = cfg.getRFBandwidth();
m_config.m_demodGain = cfg.getDemodGain();
m_config.m_fmDeviation = cfg.getFMDeviation();
m_config.m_volume = cfg.getVolume();
m_config.m_squelchGate = cfg.getSquelchGate();
m_config.m_squelch = cfg.getSquelch();
m_config.m_audioMute = cfg.getAudioMute();
apply();
qDebug() << "DSDDemod::handleMessage: MsgConfigureDSDDemod: m_rfBandwidth: " << m_config.m_rfBandwidth * 100
<< " m_demodGain: " << m_config.m_demodGain / 100.0
<< " m_fmDeviation: " << m_config.m_fmDeviation * 100
<< " m_volume: " << m_config.m_volume / 10.0
<< " m_squelchGate" << m_config.m_squelchGate
<< " m_squelch: " << m_config.m_squelch
<< " m_audioMute: " << m_config.m_audioMute;
return true;
}
else
{
return false;
}
}
void DSDDemod::apply()
{
if ((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) ||
(m_config.m_inputSampleRate != m_running.m_inputSampleRate))
{
m_nco.setFreq(-m_config.m_inputFrequencyOffset, m_config.m_inputSampleRate);
}
if ((m_config.m_inputSampleRate != m_running.m_inputSampleRate) ||
(m_config.m_rfBandwidth != m_running.m_rfBandwidth))
{
m_settingsMutex.lock();
m_interpolator.create(16, m_config.m_inputSampleRate, (m_config.m_rfBandwidth * 100) / 2.2);
m_interpolatorDistanceRemain = 0;
m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate;
m_phaseDiscri.setFMScaling((float) m_config.m_rfBandwidth / (float) m_config.m_fmDeviation);
m_settingsMutex.unlock();
}
if (m_config.m_fmDeviation != m_running.m_fmDeviation)
{
m_phaseDiscri.setFMScaling((float) m_config.m_rfBandwidth / (float) m_config.m_fmDeviation);
}
if (m_config.m_squelchGate != m_running.m_squelchGate)
{
m_agcAttack = 480 * m_config.m_squelchGate; // gate is given in 10s of ms at 48000 Hz audio sample rate
m_AGC.resize(m_agcAttack, m_agcLevel);
}
if (m_config.m_squelch != m_running.m_squelch)
{
// input is a value in tenths of dB
m_squelchLevel = std::pow(10.0, m_config.m_squelch / 200.0);
//m_squelchLevel *= m_squelchLevel;
m_afSquelch.setThreshold(m_squelchLevel);
}
m_running.m_inputSampleRate = m_config.m_inputSampleRate;
m_running.m_inputFrequencyOffset = m_config.m_inputFrequencyOffset;
m_running.m_rfBandwidth = m_config.m_rfBandwidth;
m_running.m_demodGain = m_config.m_demodGain;
m_running.m_fmDeviation = m_config.m_fmDeviation;
m_running.m_squelchGate = m_config.m_squelchGate;
m_running.m_squelch = m_config.m_squelch;
m_running.m_volume = m_config.m_volume;
m_running.m_audioSampleRate = m_config.m_audioSampleRate;
m_running.m_audioMute = m_config.m_audioMute;
}

View File

@ -0,0 +1,173 @@
#ifndef INCLUDE_DSDDEMOD_H
#define INCLUDE_DSDDEMOD_H
#include <dsp/phasediscri.h>
#include <QMutex>
#include <vector>
#include "dsp/samplesink.h"
#include "dsp/nco.h"
#include "dsp/interpolator.h"
#include "dsp/lowpass.h"
#include "dsp/bandpass.h"
#include "dsp/afsquelch.h"
#include "dsp/agc.h"
#include "dsp/afsquelch.h"
#include "audio/audiofifo.h"
#include "util/message.h"
class DSDDemodGUI;
class DSDDemod : public SampleSink {
public:
DSDDemod(SampleSink* sampleSink);
~DSDDemod();
void configure(MessageQueue* messageQueue,
int rfBandwidth,
int demodGain,
int volume,
int fmDeviation,
int squelchGate,
Real squelch,
bool audioMute);
virtual void feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool po);
virtual void start();
virtual void stop();
virtual bool handleMessage(const Message& cmd);
void registerGUI(DSDDemodGUI *dsdDemodGUI) {
m_dsdDemodGUI = dsdDemodGUI;
}
Real getMag() { return m_AGC.getAverage() / (1<<15); }
bool getSquelchOpen() const { return m_squelchOpen; }
private:
class MsgConfigureDSDDemod : public Message {
MESSAGE_CLASS_DECLARATION
public:
int getRFBandwidth() const { return m_rfBandwidth; }
int getDemodGain() const { return m_demodGain; }
int getFMDeviation() const { return m_fmDeviation; }
int getVolume() const { return m_volume; }
int getSquelchGate() const { return m_squelchGate; }
Real getSquelch() const { return m_squelch; }
bool getAudioMute() const { return m_audioMute; }
static MsgConfigureDSDDemod* create(int rfBandwidth,
int demodGain,
int fmDeviation,
int volume,
int squelchGate,
Real squelch,
bool audioMute)
{
return new MsgConfigureDSDDemod(rfBandwidth, demodGain, fmDeviation, volume, squelchGate, squelch, audioMute);
}
private:
Real m_rfBandwidth;
Real m_demodGain;
int m_fmDeviation;
int m_volume;
int m_squelchGate;
Real m_squelch;
bool m_audioMute;
MsgConfigureDSDDemod(int rfBandwidth,
int demodGain,
int fmDeviation,
int volume,
int squelchGate,
Real squelch,
bool audioMute) :
Message(),
m_rfBandwidth(rfBandwidth),
m_demodGain(demodGain),
m_fmDeviation(fmDeviation),
m_volume(volume),
m_squelchGate(squelchGate),
m_squelch(squelch),
m_audioMute(audioMute)
{ }
};
struct AudioSample {
qint16 l;
qint16 r;
};
typedef std::vector<AudioSample> AudioVector;
enum RateState {
RSInitialFill,
RSRunning
};
struct Config {
int m_inputSampleRate;
qint64 m_inputFrequencyOffset;
int m_rfBandwidth;
int m_demodGain;
int m_volume;
int m_fmDeviation;
int m_squelchGate;
Real m_squelch;
bool m_audioMute;
quint32 m_audioSampleRate;
Config() :
m_inputSampleRate(-1),
m_inputFrequencyOffset(0),
m_rfBandwidth(-1),
m_demodGain(-1),
m_volume(-1),
m_fmDeviation(1),
m_squelchGate(1),
m_squelch(0),
m_audioMute(false),
m_audioSampleRate(0)
{ }
};
Config m_config;
Config m_running;
NCO m_nco;
Interpolator m_interpolator;
Real m_interpolatorDistance;
Real m_interpolatorDistanceRemain;
int m_sampleCount;
int m_squelchCount;
int m_agcAttack;
bool m_audioMute;
double m_squelchLevel;
bool m_squelchOpen;
Real m_lastArgument;
MagAGC m_AGC;
AFSquelch m_afSquelch;
Real m_agcLevel; // AGC will aim to this level
Real m_agcFloor; // AGC will not go below this level
Real m_fmExcursion;
SampleVector m_scopeSampleBuffer;
AudioVector m_audioBuffer;
uint m_audioBufferFill;
AudioFifo m_audioFifo;
SampleSink* m_scope;
bool m_scopeEnabled;
DSDDemodGUI *m_dsdDemodGUI;
QMutex m_settingsMutex;
PhaseDiscriminators m_phaseDiscri;
void apply();
};
#endif // INCLUDE_DSDDEMOD_H

View File

@ -0,0 +1,348 @@
#include <QDockWidget>
#include <QMainWindow>
#include <QDebug>
#include "dsddemodgui.h"
#include "ui_dsddemodgui.h"
#include "dsp/threadedsamplesink.h"
#include "dsp/channelizer.h"
#include "dsp/scopevis.h"
#include "dsddemod.h"
#include "dsp/nullsink.h"
#include "plugin/pluginapi.h"
#include "util/simpleserializer.h"
#include "util/db.h"
#include "gui/basicchannelsettingswidget.h"
#include "dsp/dspengine.h"
#include "mainwindow.h"
DSDDemodGUI* DSDDemodGUI::create(PluginAPI* pluginAPI)
{
DSDDemodGUI* gui = new DSDDemodGUI(pluginAPI);
return gui;
}
void DSDDemodGUI::destroy()
{
delete this;
}
void DSDDemodGUI::setName(const QString& name)
{
setObjectName(name);
}
QString DSDDemodGUI::getName() const
{
return objectName();
}
qint64 DSDDemodGUI::getCenterFrequency() const
{
return m_channelMarker.getCenterFrequency();
}
void DSDDemodGUI::setCenterFrequency(qint64 centerFrequency)
{
m_channelMarker.setCenterFrequency(centerFrequency);
applySettings();
}
void DSDDemodGUI::resetToDefaults()
{
blockApplySettings(true);
ui->rfBW->setValue(100); // x100 Hz
ui->demodGain->setValue(100); // 100ths
ui->fmDeviation->setValue(50); // x100 Hz
ui->volume->setValue(20); // /10.0
ui->squelchGate->setValue(5);
ui->squelch->setValue(-40);
ui->deltaFrequency->setValue(0);
blockApplySettings(false);
applySettings();
}
QByteArray DSDDemodGUI::serialize() const
{
SimpleSerializer s(1);
s.writeS32(1, m_channelMarker.getCenterFrequency());
s.writeS32(2, ui->rfBW->value());
s.writeS32(3, ui->demodGain->value());
s.writeS32(4, ui->fmDeviation->value());
s.writeS32(5, ui->squelch->value());
s.writeU32(7, m_channelMarker.getColor().rgb());
s.writeS32(8, ui->squelchGate->value());
s.writeS32(9, ui->volume->value());
return s.final();
}
bool DSDDemodGUI::deserialize(const QByteArray& data)
{
SimpleDeserializer d(data);
if (!d.isValid())
{
resetToDefaults();
return false;
}
if (d.getVersion() == 1)
{
QByteArray bytetmp;
quint32 u32tmp;
qint32 tmp;
bool boolTmp;
blockApplySettings(true);
m_channelMarker.blockSignals(true);
d.readS32(1, &tmp, 0);
m_channelMarker.setCenterFrequency(tmp);
d.readS32(2, &tmp, 4);
ui->rfBW->setValue(tmp);
d.readS32(3, &tmp, 3);
ui->demodGain->setValue(tmp);
d.readS32(4, &tmp, 20);
ui->fmDeviation->setValue(tmp);
d.readS32(5, &tmp, -40);
ui->squelch->setValue(tmp);
if(d.readU32(7, &u32tmp))
{
m_channelMarker.setColor(u32tmp);
}
d.readS32(8, &tmp, 5);
ui->squelchGate->setValue(tmp);
d.readS32(9, &tmp, 20);
ui->volume->setValue(tmp);
blockApplySettings(false);
m_channelMarker.blockSignals(false);
applySettings();
return true;
}
else
{
resetToDefaults();
return false;
}
}
bool DSDDemodGUI::handleMessage(const Message& message)
{
return false;
}
void DSDDemodGUI::viewChanged()
{
applySettings();
}
void DSDDemodGUI::on_deltaMinus_toggled(bool minus)
{
int deltaFrequency = m_channelMarker.getCenterFrequency();
bool minusDelta = (deltaFrequency < 0);
if (minus ^ minusDelta) // sign change
{
m_channelMarker.setCenterFrequency(-deltaFrequency);
}
}
void DSDDemodGUI::on_deltaFrequency_changed(quint64 value)
{
if (ui->deltaMinus->isChecked())
{
m_channelMarker.setCenterFrequency(-value);
}
else
{
m_channelMarker.setCenterFrequency(value);
}
}
void DSDDemodGUI::on_rfBW_valueChanged(int value)
{
qDebug() << "DSDDemodGUI::on_rfBW_valueChanged" << value * 100;
m_channelMarker.setBandwidth(value * 100);
applySettings();
}
void DSDDemodGUI::on_demodGain_valueChanged(int value)
{
applySettings();
}
void DSDDemodGUI::on_fmDeviation_valueChanged(int value)
{
applySettings();
}
void DSDDemodGUI::on_volume_valueChanged(int value)
{
applySettings();
}
void DSDDemodGUI::on_squelchGate_valueChanged(int value)
{
applySettings();
}
void DSDDemodGUI::on_squelch_valueChanged(int value)
{
ui->squelchText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1));
applySettings();
}
void DSDDemodGUI::on_audioMute_toggled(bool checked)
{
m_audioMute = checked;
applySettings();
}
void DSDDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown)
{
/*
if((widget == ui->spectrumContainer) && (DSDDemodGUI != NULL))
m_dsdDemod->setSpectrum(m_threadedSampleSink->getMessageQueue(), rollDown);
*/
}
void DSDDemodGUI::onMenuDoubleClicked()
{
if (!m_basicSettingsShown)
{
m_basicSettingsShown = true;
BasicChannelSettingsWidget* bcsw = new BasicChannelSettingsWidget(&m_channelMarker, this);
bcsw->show();
}
}
DSDDemodGUI::DSDDemodGUI(PluginAPI* pluginAPI, QWidget* parent) :
RollupWidget(parent),
ui(new Ui::DSDDemodGUI),
m_pluginAPI(pluginAPI),
m_channelMarker(this),
m_basicSettingsShown(false),
m_doApplySettings(true),
m_squelchOpen(false),
m_channelPowerDbAvg(20,0)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose, true);
connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool)));
connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked()));
m_scopeVis = new ScopeVis(ui->glScope);
m_dsdDemod = new DSDDemod(m_scopeVis);
m_dsdDemod->registerGUI(this);
ui->glScope->connectTimer(m_pluginAPI->getMainWindow()->getMasterTimer());
connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick()));
ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold));
m_channelizer = new Channelizer(m_dsdDemod);
m_threadedChannelizer = new ThreadedSampleSink(m_channelizer, this);
DSPEngine::instance()->addThreadedSink(m_threadedChannelizer);
//m_channelMarker = new ChannelMarker(this);
m_channelMarker.setColor(Qt::cyan);
m_channelMarker.setBandwidth(10000);
m_channelMarker.setCenterFrequency(0);
m_channelMarker.setVisible(true);
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged()));
m_pluginAPI->addChannelMarker(&m_channelMarker);
ui->scopeGUI->setBuddies(m_scopeVis->getInputMessageQueue(), m_scopeVis, ui->glScope);
applySettings();
}
DSDDemodGUI::~DSDDemodGUI()
{
m_pluginAPI->removeChannelInstance(this);
DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer);
delete m_threadedChannelizer;
delete m_channelizer;
delete m_dsdDemod;
//delete m_channelMarker;
delete ui;
}
void DSDDemodGUI::applySettings()
{
if (m_doApplySettings)
{
qDebug() << "DSDDemodGUI::applySettings";
setTitleColor(m_channelMarker.getColor());
m_channelizer->configure(m_channelizer->getInputMessageQueue(),
48000,
m_channelMarker.getCenterFrequency());
ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency()));
ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0);
ui->rfBWText->setText(QString("%1k").arg(ui->rfBW->value() / 10.0, 0, 'f', 1));
ui->demodGainText->setText(QString("%1").arg(ui->demodGain->value() / 100.0, 0, 'f', 2));
ui->fmDeviationText->setText(QString("%1k").arg(ui->fmDeviation->value() / 10.0, 0, 'f', 1));
ui->squelchGateText->setText(QString("%1").arg(ui->squelchGate->value() * 10.0, 0, 'f', 0));
ui->volumeText->setText(QString("%1").arg(ui->volume->value() / 10.0, 0, 'f', 1));
m_dsdDemod->configure(m_dsdDemod->getInputMessageQueue(),
ui->rfBW->value(),
ui->demodGain->value(),
ui->fmDeviation->value(),
ui->volume->value(),
ui->squelchGate->value(), // in 10ths of ms
ui->squelch->value(),
ui->audioMute->isChecked());
}
}
void DSDDemodGUI::leaveEvent(QEvent*)
{
blockApplySettings(true);
m_channelMarker.setHighlighted(false);
blockApplySettings(false);
}
void DSDDemodGUI::enterEvent(QEvent*)
{
blockApplySettings(true);
m_channelMarker.setHighlighted(true);
blockApplySettings(false);
}
void DSDDemodGUI::blockApplySettings(bool block)
{
m_doApplySettings = !block;
}
void DSDDemodGUI::tick()
{
Real powDb = CalcDb::dbPower(m_dsdDemod->getMag()) * 2;
m_channelPowerDbAvg.feed(powDb);
ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1));
bool squelchOpen = m_dsdDemod->getSquelchOpen();
if (squelchOpen != m_squelchOpen)
{
m_squelchOpen = squelchOpen;
if (m_squelchOpen) {
ui->audioMute->setStyleSheet("QToolButton { background-color : green; }");
} else {
ui->audioMute->setStyleSheet("QToolButton { background:rgb(79,79,79); }");
}
}
}

View File

@ -0,0 +1,80 @@
#ifndef INCLUDE_DSDDEMODGUI_H
#define INCLUDE_DSDDEMODGUI_H
#include "gui/rollupwidget.h"
#include "plugin/plugingui.h"
#include "dsp/dsptypes.h"
#include "dsp/channelmarker.h"
#include "dsp/movingaverage.h"
class PluginAPI;
class ThreadedSampleSink;
class Channelizer;
class ScopeVis;
class DSDDemod;
namespace Ui {
class DSDDemodGUI;
}
class DSDDemodGUI : public RollupWidget, public PluginGUI {
Q_OBJECT
public:
static DSDDemodGUI* create(PluginAPI* pluginAPI);
void destroy();
void setName(const QString& name);
QString getName() const;
virtual qint64 getCenterFrequency() const;
virtual void setCenterFrequency(qint64 centerFrequency);
void resetToDefaults();
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
virtual bool handleMessage(const Message& message);
private slots:
void viewChanged();
void on_deltaFrequency_changed(quint64 value);
void on_deltaMinus_toggled(bool minus);
void on_rfBW_valueChanged(int index);
void on_demodGain_valueChanged(int value);
void on_volume_valueChanged(int value);
void on_fmDeviation_valueChanged(int value);
void on_squelchGate_valueChanged(int value);
void on_squelch_valueChanged(int value);
void on_audioMute_toggled(bool checked);
void onWidgetRolled(QWidget* widget, bool rollDown);
void onMenuDoubleClicked();
void tick();
private:
Ui::DSDDemodGUI* ui;
PluginAPI* m_pluginAPI;
ChannelMarker m_channelMarker;
bool m_basicSettingsShown;
bool m_doApplySettings;
ThreadedSampleSink* m_threadedChannelizer;
Channelizer* m_channelizer;
ScopeVis* m_scopeVis;
DSDDemod* m_dsdDemod;
bool m_audioMute;
bool m_squelchOpen;
MovingAverage<Real> m_channelPowerDbAvg;
explicit DSDDemodGUI(PluginAPI* pluginAPI, QWidget* parent = NULL);
virtual ~DSDDemodGUI();
void blockApplySettings(bool block);
void applySettings();
void leaveEvent(QEvent*);
void enterEvent(QEvent*);
};
#endif // INCLUDE_DSDDEMODGUI_H

View File

@ -0,0 +1,604 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DSDDemodGUI</class>
<widget class="RollupWidget" name="DSDDemodGUI">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>503</width>
<height>506</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Sans Serif</family>
<pointsize>9</pointsize>
</font>
</property>
<property name="windowTitle">
<string>DSD Demodulator</string>
</property>
<widget class="QWidget" name="settingsContainer" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>501</width>
<height>171</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="margin">
<number>2</number>
</property>
<item>
<layout class="QHBoxLayout" name="deltaFreqPowerLayout">
<item>
<layout class="QHBoxLayout" name="DeltaFrequencyLayout">
<item>
<widget class="QToolButton" name="deltaMinus">
<property name="toolTip">
<string>Frequency shift direction</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset>
<selectedoff>:/plus.png</selectedoff>
<selectedon>:/minus.png</selectedon>
</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="ValueDial" name="deltaFrequency" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>32</width>
<height>16</height>
</size>
</property>
<property name="font">
<font>
<family>Monospace</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="cursor">
<cursorShape>SizeVerCursor</cursorShape>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string>Demod shift frequency from center in Hz</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="deltaUnits">
<property name="text">
<string>Hz </string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="channnelPowerLayout">
<item>
<widget class="QLabel" name="channelPower">
<property name="toolTip">
<string>Channel power (dB)</string>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>0.0</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="channelPowerUnits">
<property name="text">
<string> dB</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="rfBWLayout">
<item>
<widget class="QLabel" name="rfBWLabel">
<property name="text">
<string>RFBW</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="rfBW">
<property name="toolTip">
<string>Bandwidth (kHz) before discriminator</string>
</property>
<property name="maximum">
<number>500</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="sliderPosition">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="rfBWText">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>00.0k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="bwSpacer">
<property name="minimumSize">
<size>
<width>10</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="demodGainLabel">
<property name="text">
<string>Gain</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="demodGain">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Gain after discriminator</string>
</property>
<property name="minimum">
<number>50</number>
</property>
<property name="maximum">
<number>150</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="sliderPosition">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="demodGainText">
<property name="minimumSize">
<size>
<width>35</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>0.00</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="volumeLabel">
<property name="text">
<string>Vol</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="volume">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Sound volume</string>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>20</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="volumeText">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Sound volume</string>
</property>
<property name="text">
<string>2.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="squelchLayout">
<item>
<widget class="QLabel" name="fmDeviationLabel">
<property name="text">
<string>FMd</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="fmDeviation">
<property name="toolTip">
<string>Maximum frequency deviation (kHz)</string>
</property>
<property name="maximum">
<number>500</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="sliderPosition">
<number>50</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="fmDeviationText">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>00.0k</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="squelchLabel">
<property name="text">
<string>Sq</string>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="squelch">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Squelch threshold (dB)</string>
</property>
<property name="minimum">
<number>-1000</number>
</property>
<property name="maximum">
<number>0</number>
</property>
<property name="singleStep">
<number>1</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>-150</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="squelchText">
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>Squelch threshold (dB)</string>
</property>
<property name="text">
<string>-15.0</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QDial" name="squelchGate">
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="toolTip">
<string>Squelch gate (ms)</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>50</number>
</property>
<property name="pageStep">
<number>1</number>
</property>
<property name="value">
<number>5</number>
</property>
<property name="sliderPosition">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="squelchGateText">
<property name="minimumSize">
<size>
<width>25</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Squelch gate (ms)</string>
</property>
<property name="text">
<string>000</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="audioMute">
<property name="toolTip">
<string>Mute/Unmute audio</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../sdrbase/resources/res.qrc">
<normaloff>:/sound_on.png</normaloff>
<normalon>:/sound_off.png</normalon>:/sound_on.png</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="scopeContainer" native="true">
<property name="enabled">
<bool>false</bool>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>180</y>
<width>501</width>
<height>291</height>
</rect>
</property>
<widget class="GLScope" name="glScope" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>491</width>
<height>250</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>250</height>
</size>
</property>
<property name="font">
<font>
<family>Monospace</family>
<pointsize>8</pointsize>
</font>
</property>
</widget>
<widget class="GLScopeGUI" name="scopeGUI" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>260</y>
<width>481</width>
<height>26</height>
</rect>
</property>
</widget>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>RollupWidget</class>
<extends>QWidget</extends>
<header>gui/rollupwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>ValueDial</class>
<extends>QWidget</extends>
<header>gui/valuedial.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GLScope</class>
<extends>QWidget</extends>
<header>gui/glscope.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>GLScopeGUI</class>
<extends>QWidget</extends>
<header>gui/glscopegui.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../../sdrbase/resources/res.qrc"/>
</resources>
<connections/>
</ui>

View File

@ -0,0 +1,53 @@
#include <QtPlugin>
#include <QAction>
#include "plugin/pluginapi.h"
#include "dsddemodplugin.h"
#include "dsddemodgui.h"
const PluginDescriptor DSDDemodPlugin::m_pluginDescriptor = {
QString("DSD Demodulator"),
QString("---"),
QString("(c) Edouard Griffiths, F4EXB"),
QString("https://github.com/f4exb/sdrangel"),
true,
QString("https://github.com/f4exb/sdrangel")
};
DSDDemodPlugin::DSDDemodPlugin(QObject* parent) :
QObject(parent)
{
}
const PluginDescriptor& DSDDemodPlugin::getPluginDescriptor() const
{
return m_pluginDescriptor;
}
void DSDDemodPlugin::initPlugin(PluginAPI* pluginAPI)
{
m_pluginAPI = pluginAPI;
// register DSD demodulator
QAction* action = new QAction(tr("&DSD Demodulator"), this);
connect(action, SIGNAL(triggered()), this, SLOT(createInstanceDSDDemod()));
m_pluginAPI->registerChannel("sdrangel.channel.dsddemod", this, action);
}
PluginGUI* DSDDemodPlugin::createChannel(const QString& channelName)
{
if(channelName == "sdrangel.channel.dsddemod") {
DSDDemodGUI* gui = DSDDemodGUI::create(m_pluginAPI);
m_pluginAPI->registerChannelInstance("sdrangel.channel.dsddemod", gui);
m_pluginAPI->addChannelRollup(gui);
return gui;
} else {
return NULL;
}
}
void DSDDemodPlugin::createInstanceDSDDemod()
{
DSDDemodGUI* gui = DSDDemodGUI::create(m_pluginAPI);
m_pluginAPI->registerChannelInstance("sdrangel.channel.dsddemod", gui);
m_pluginAPI->addChannelRollup(gui);
}

View File

@ -0,0 +1,29 @@
#ifndef INCLUDE_DSDDEMODLUGIN_H
#define INCLUDE_DSDDEMODLUGIN_H
#include <QObject>
#include "plugin/plugininterface.h"
class DSDDemodPlugin : public QObject, PluginInterface {
Q_OBJECT
Q_INTERFACES(PluginInterface)
Q_PLUGIN_METADATA(IID "sdrangel.channel.dsddemod")
public:
explicit DSDDemodPlugin(QObject* parent = NULL);
const PluginDescriptor& getPluginDescriptor() const;
void initPlugin(PluginAPI* pluginAPI);
PluginGUI* createChannel(const QString& channelName);
private:
static const PluginDescriptor m_pluginDescriptor;
PluginAPI* m_pluginAPI;
private slots:
void createInstanceDSDDemod();
};
#endif // INCLUDE_DSDDEMODLUGIN_H

View File

@ -26,7 +26,6 @@ add_definitions(${QT_DEFINITIONS})
add_definitions(-DQT_PLUGIN) add_definitions(-DQT_PLUGIN)
add_definitions(-DQT_SHARED) add_definitions(-DQT_SHARED)
#qt5_wrap_cpp(udpsrc_HEADERS_MOC ${udpsrc_HEADERS})
qt5_wrap_ui(udpsrc_FORMS_HEADERS ${udpsrc_FORMS}) qt5_wrap_ui(udpsrc_FORMS_HEADERS ${udpsrc_FORMS})
add_library(demodudpsrc SHARED add_library(demodudpsrc SHARED
@ -40,6 +39,6 @@ target_link_libraries(demodudpsrc
sdrbase sdrbase
) )
qt5_use_modules(demodudpsrc Core Widgets OpenGL Network) qt5_use_modules(demodudpsrc Core Widgets OpenGL Network Multimedia)
install(TARGETS demodudpsrc DESTINATION lib/plugins/channel) install(TARGETS demodudpsrc DESTINATION lib/plugins/channel)

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>290</width> <width>292</width>
<height>158</height> <height>355</height>
</rect> </rect>
</property> </property>
<property name="font"> <property name="font">