diff --git a/plugins/channel/CMakeLists.txt b/plugins/channel/CMakeLists.txt index f0ca94834..7b0d70a9d 100644 --- a/plugins/channel/CMakeLists.txt +++ b/plugins/channel/CMakeLists.txt @@ -10,4 +10,6 @@ add_subdirectory(udpsrc) add_subdirectory(demodwfm) add_subdirectory(chanalyzer) -#add_subdirectory(tetra) +if(LIBMBE_FOUND) + add_subdirectory(demoddsd) +endif(LIBMBE_FOUND) diff --git a/plugins/channel/demoddsd/CMakeLists.txt b/plugins/channel/demoddsd/CMakeLists.txt new file mode 100644 index 000000000..f0e8bf100 --- /dev/null +++ b/plugins/channel/demoddsd/CMakeLists.txt @@ -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) \ No newline at end of file diff --git a/plugins/channel/demoddsd/dsddemod.cpp b/plugins/channel/demoddsd/dsddemod.cpp new file mode 100644 index 000000000..2ad2b628f --- /dev/null +++ b/plugins/channel/demoddsd/dsddemod.cpp @@ -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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#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; +} diff --git a/plugins/channel/demoddsd/dsddemod.h b/plugins/channel/demoddsd/dsddemod.h new file mode 100644 index 000000000..22ac48dcd --- /dev/null +++ b/plugins/channel/demoddsd/dsddemod.h @@ -0,0 +1,173 @@ +#ifndef INCLUDE_DSDDEMOD_H +#define INCLUDE_DSDDEMOD_H + +#include +#include +#include +#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 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 diff --git a/plugins/channel/demoddsd/dsddemodgui.cpp b/plugins/channel/demoddsd/dsddemodgui.cpp new file mode 100644 index 000000000..b34040845 --- /dev/null +++ b/plugins/channel/demoddsd/dsddemodgui.cpp @@ -0,0 +1,348 @@ +#include +#include +#include +#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); }"); + } + } +} diff --git a/plugins/channel/demoddsd/dsddemodgui.h b/plugins/channel/demoddsd/dsddemodgui.h new file mode 100644 index 000000000..04f19e7fe --- /dev/null +++ b/plugins/channel/demoddsd/dsddemodgui.h @@ -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 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 diff --git a/plugins/channel/demoddsd/dsddemodgui.ui b/plugins/channel/demoddsd/dsddemodgui.ui new file mode 100644 index 000000000..37a672901 --- /dev/null +++ b/plugins/channel/demoddsd/dsddemodgui.ui @@ -0,0 +1,604 @@ + + + DSDDemodGUI + + + + 0 + 0 + 503 + 506 + + + + + 0 + 0 + + + + + Sans Serif + 9 + + + + DSD Demodulator + + + + + 0 + 0 + 501 + 171 + + + + + 0 + 0 + + + + Settings + + + + 3 + + + 2 + + + + + + + + + Frequency shift direction + + + ... + + + + :/plus.png + :/minus.png + + + + true + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Monospace + 12 + + + + SizeVerCursor + + + Qt::StrongFocus + + + Demod shift frequency from center in Hz + + + + + + + Hz + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Channel power (dB) + + + Qt::RightToLeft + + + 0.0 + + + + + + + dB + + + + + + + + + + + + + RFBW + + + + + + + Bandwidth (kHz) before discriminator + + + 500 + + + 1 + + + 100 + + + Qt::Horizontal + + + + + + + + 40 + 0 + + + + 00.0k + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 10 + 0 + + + + + + + + + + + Gain + + + + + + + + 0 + 0 + + + + Gain after discriminator + + + 50 + + + 150 + + + 1 + + + 100 + + + Qt::Horizontal + + + + + + + + 35 + 0 + + + + 0.00 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Qt::Vertical + + + + + + + Vol + + + + + + + + 24 + 24 + + + + Sound volume + + + 100 + + + 1 + + + 20 + + + + + + + + 0 + 0 + + + + + 30 + 16777215 + + + + Sound volume + + + 2.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + FMd + + + + + + + Maximum frequency deviation (kHz) + + + 500 + + + 1 + + + 50 + + + Qt::Horizontal + + + + + + + + 40 + 0 + + + + 00.0k + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Sq + + + + + + + + 24 + 24 + + + + Squelch threshold (dB) + + + -1000 + + + 0 + + + 1 + + + 1 + + + -150 + + + + + + + + 0 + 0 + + + + + 40 + 16777215 + + + + Squelch threshold (dB) + + + -15.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 24 + 24 + + + + Squelch gate (ms) + + + 1 + + + 50 + + + 1 + + + 5 + + + 5 + + + + + + + + 25 + 0 + + + + Squelch gate (ms) + + + 000 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Mute/Unmute audio + + + ... + + + + :/sound_on.png + :/sound_off.png:/sound_on.png + + + true + + + + + + + + + + false + + + + 0 + 180 + 501 + 291 + + + + + + 0 + 0 + 491 + 250 + + + + + 200 + 250 + + + + + Monospace + 8 + + + + + + + 0 + 260 + 481 + 26 + + + + + + + + RollupWidget + QWidget +
gui/rollupwidget.h
+ 1 +
+ + ValueDial + QWidget +
gui/valuedial.h
+ 1 +
+ + GLScope + QWidget +
gui/glscope.h
+ 1 +
+ + GLScopeGUI + QWidget +
gui/glscopegui.h
+ 1 +
+
+ + + + +
diff --git a/plugins/channel/demoddsd/dsddemodplugin.cpp b/plugins/channel/demoddsd/dsddemodplugin.cpp new file mode 100644 index 000000000..94d1f7e67 --- /dev/null +++ b/plugins/channel/demoddsd/dsddemodplugin.cpp @@ -0,0 +1,53 @@ +#include +#include +#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); +} diff --git a/plugins/channel/demoddsd/dsddemodplugin.h b/plugins/channel/demoddsd/dsddemodplugin.h new file mode 100644 index 000000000..afb52530b --- /dev/null +++ b/plugins/channel/demoddsd/dsddemodplugin.h @@ -0,0 +1,29 @@ +#ifndef INCLUDE_DSDDEMODLUGIN_H +#define INCLUDE_DSDDEMODLUGIN_H + +#include +#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 diff --git a/plugins/channel/udpsrc/CMakeLists.txt b/plugins/channel/udpsrc/CMakeLists.txt index cd26f937c..066bf685f 100644 --- a/plugins/channel/udpsrc/CMakeLists.txt +++ b/plugins/channel/udpsrc/CMakeLists.txt @@ -26,7 +26,6 @@ add_definitions(${QT_DEFINITIONS}) add_definitions(-DQT_PLUGIN) add_definitions(-DQT_SHARED) -#qt5_wrap_cpp(udpsrc_HEADERS_MOC ${udpsrc_HEADERS}) qt5_wrap_ui(udpsrc_FORMS_HEADERS ${udpsrc_FORMS}) add_library(demodudpsrc SHARED @@ -40,6 +39,6 @@ target_link_libraries(demodudpsrc 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) diff --git a/plugins/channel/udpsrc/udpsrcgui.ui b/plugins/channel/udpsrc/udpsrcgui.ui index 61fc34f2d..500ac7192 100644 --- a/plugins/channel/udpsrc/udpsrcgui.ui +++ b/plugins/channel/udpsrc/udpsrcgui.ui @@ -6,8 +6,8 @@ 0 0 - 290 - 158 + 292 + 355