diff --git a/plugins/channel/CMakeLists.txt b/plugins/channel/CMakeLists.txt index 00011db34..ff5e30726 100644 --- a/plugins/channel/CMakeLists.txt +++ b/plugins/channel/CMakeLists.txt @@ -2,6 +2,7 @@ project(demod) add_subdirectory(lora) add_subdirectory(am) +add_subdirectory(bfm) add_subdirectory(nfm) add_subdirectory(ssb) add_subdirectory(tcpsrc) diff --git a/plugins/channel/bfm/CMakeLists.txt b/plugins/channel/bfm/CMakeLists.txt new file mode 100644 index 000000000..39903accf --- /dev/null +++ b/plugins/channel/bfm/CMakeLists.txt @@ -0,0 +1,46 @@ +project(bfm) + +set(bfm_SOURCES + bfmdemod.cpp + bfmdemodgui.cpp + bfmplugin.cpp +) + +set(bfm_HEADERS + bfmdemod.h + bfmdemodgui.h + bfmplugin.h +) + +set(bfm_FORMS + bfmdemodgui.ui +) + +include_directories( + . + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/include-gpl + ${OPENGL_INCLUDE_DIR} +) + +#include(${QT_USE_FILE}) +add_definitions(${QT_DEFINITIONS}) +add_definitions(-DQT_PLUGIN) +add_definitions(-DQT_SHARED) + +qt5_wrap_ui(bfm_FORMS_HEADERS ${bfm_FORMS}) + +add_library(demodbfm SHARED + ${bfm_SOURCES} + ${bfm_HEADERS_MOC} + ${bfm_FORMS_HEADERS} +) + +target_link_libraries(demodbfm + ${QT_LIBRARIES} + ${OPENGL_LIBRARIES} + sdrbase +) + +qt5_use_modules(demodbfm Core Widgets OpenGL Multimedia) \ No newline at end of file diff --git a/plugins/channel/bfm/bfmdemod.cpp b/plugins/channel/bfm/bfmdemod.cpp new file mode 100644 index 000000000..7bca8fe89 --- /dev/null +++ b/plugins/channel/bfm/bfmdemod.cpp @@ -0,0 +1,284 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 "audio/audiooutput.h" +#include "dsp/dspengine.h" +#include "dsp/channelizer.h" +#include "dsp/pidcontroller.h" + +#include "bfmdemod.h" + +MESSAGE_CLASS_DEFINITION(BFMDemod::MsgConfigureBFMDemod, Message) + +BFMDemod::BFMDemod(SampleSink* sampleSink) : + m_sampleSink(sampleSink), + m_audioFifo(4, 250000), + m_settingsMutex(QMutex::Recursive) +{ + setObjectName("BFMDemod"); + + m_config.m_inputSampleRate = 384000; + m_config.m_inputFrequencyOffset = 0; + m_config.m_rfBandwidth = 180000; + m_config.m_afBandwidth = 15000; + m_config.m_squelch = -60.0; + m_config.m_volume = 2.0; + m_config.m_audioSampleRate = DSPEngine::instance()->getAudioSampleRate(); + m_rfFilter = new fftfilt(-50000.0 / 384000.0, 50000.0 / 384000.0, rfFilterFftLength); + + apply(); + + m_audioBuffer.resize(16384); + m_audioBufferFill = 0; + + m_movingAverage.resize(16, 0); + + DSPEngine::instance()->addAudioSink(&m_audioFifo); +} + +BFMDemod::~BFMDemod() +{ + if (m_rfFilter) + { + delete m_rfFilter; + } + + DSPEngine::instance()->removeAudioSink(&m_audioFifo); +} + +void BFMDemod::configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch) +{ + Message* cmd = MsgConfigureBFMDemod::create(rfBandwidth, afBandwidth, volume, squelch); + messageQueue->push(cmd); +} + +void BFMDemod::feed(const SampleVector::const_iterator& begin, const SampleVector::const_iterator& end, bool firstOfBurst) +{ + Complex ci; + fftfilt::cmplx *rf; + int rf_out; + Real msq, demod; + + m_settingsMutex.lock(); + + for (SampleVector::const_iterator it = begin; it != end; ++it) + { + Complex c(it->real() / 32768.0f, it->imag() / 32768.0f); + c *= m_nco.nextIQ(); + + rf_out = m_rfFilter->runFilt(c, &rf); // filter RF before demod + + for (int i =0 ; i = m_squelchLevel) + m_squelchState = m_running.m_rfBandwidth / 20; // decay rate + + if(m_squelchState > 0) + { + m_squelchState--; + + // Alternative without atan + // http://www.embedded.com/design/configurable-systems/4212086/DSP-Tricks--Frequency-demodulation-algorithms- + // in addition it needs scaling by instantaneous magnitude squared and volume (0..10) adjustment factor + Real ip = rf[i].real() - m_m2Sample.real(); + Real qp = rf[i].imag() - m_m2Sample.imag(); + Real h1 = m_m1Sample.real() * qp; + Real h2 = m_m1Sample.imag() * ip; + demod = (h1 - h2) / (msq * 10.0); + } + else + { + demod = 0; + } + + m_m2Sample = m_m1Sample; + m_m1Sample = rf[i]; + + Complex e(demod, 0); + + if(m_interpolator.interpolate(&m_interpolatorDistanceRemain, e, &ci)) + { + quint16 sample = (qint16)(ci.real() * 3000 * m_running.m_volume); + m_sampleBuffer.push_back(Sample(sample, sample)); + 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, 1); + + if(res != m_audioBufferFill) + { + qDebug("BFMDemod::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, 1); + + if(res != m_audioBufferFill) + { + qDebug("BFMDemod::feed: %u/%u tail samples written", res, m_audioBufferFill); + } + + m_audioBufferFill = 0; + } + + if(m_sampleSink != 0) + { + m_sampleSink->feed(m_sampleBuffer.begin(), m_sampleBuffer.end(), false); + } + + m_sampleBuffer.clear(); + + m_settingsMutex.unlock(); +} + +void BFMDemod::start() +{ + m_squelchState = 0; + m_audioFifo.clear(); + m_m1Sample = 0; +} + +void BFMDemod::stop() +{ +} + +bool BFMDemod::handleMessage(const Message& cmd) +{ + qDebug() << "BFMDemod::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() << "BFMDemod::handleMessage: MsgChannelizerNotification: m_inputSampleRate: " << m_config.m_inputSampleRate + << " m_inputFrequencyOffset: " << m_config.m_inputFrequencyOffset; + + return true; + } + else if (MsgConfigureBFMDemod::match(cmd)) + { + MsgConfigureBFMDemod& cfg = (MsgConfigureBFMDemod&) cmd; + + m_config.m_rfBandwidth = cfg.getRFBandwidth(); + m_config.m_afBandwidth = cfg.getAFBandwidth(); + m_config.m_volume = cfg.getVolume(); + m_config.m_squelch = cfg.getSquelch(); + + apply(); + + qDebug() << "BFMDemod::handleMessage: MsgConfigureBFMDemod: m_rfBandwidth: " << m_config.m_rfBandwidth + << " m_afBandwidth: " << m_config.m_afBandwidth + << " m_volume: " << m_config.m_volume + << " m_squelch: " << m_config.m_squelch; + + return true; + } + else + { + if (m_sampleSink != 0) + { + return m_sampleSink->handleMessage(cmd); + } + else + { + return false; + } + } +} + +void BFMDemod::apply() +{ + + if((m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset) || + (m_config.m_inputSampleRate != m_running.m_inputSampleRate)) + { + qDebug() << "BFMDemod::handleMessage: m_nco.setFreq"; + m_nco.setFreq(-m_config.m_inputFrequencyOffset, m_config.m_inputSampleRate); + } + + if((m_config.m_inputSampleRate != m_running.m_inputSampleRate) || + (m_config.m_afBandwidth != m_running.m_afBandwidth)) + { + m_settingsMutex.lock(); + qDebug() << "BFMDemod::handleMessage: m_interpolator.create"; + m_interpolator.create(16, m_config.m_inputSampleRate, m_config.m_afBandwidth); + m_interpolatorDistanceRemain = (Real) m_config.m_inputSampleRate / m_config.m_audioSampleRate; + m_interpolatorDistance = (Real) m_config.m_inputSampleRate / (Real) m_config.m_audioSampleRate; + m_settingsMutex.unlock(); + } + + if((m_config.m_inputSampleRate != m_running.m_inputSampleRate) || + (m_config.m_rfBandwidth != m_running.m_rfBandwidth) || + (m_config.m_inputFrequencyOffset != m_running.m_inputFrequencyOffset)) + { + m_settingsMutex.lock(); + qDebug() << "BFMDemod::handleMessage: m_rfFilter->create_filter"; + Real lowCut = -(m_config.m_rfBandwidth / 2.0) / m_config.m_inputSampleRate; + Real hiCut = (m_config.m_rfBandwidth / 2.0) / m_config.m_inputSampleRate; + m_rfFilter->create_filter(lowCut, hiCut); + m_settingsMutex.unlock(); + } + + if((m_config.m_afBandwidth != m_running.m_afBandwidth) || + (m_config.m_audioSampleRate != m_running.m_audioSampleRate)) + { + m_settingsMutex.lock(); + qDebug() << "BFMDemod::handleMessage: m_lowpass.create"; + m_lowpass.create(21, m_config.m_audioSampleRate, m_config.m_afBandwidth); + m_settingsMutex.unlock(); + } + + if(m_config.m_squelch != m_running.m_squelch) { + qDebug() << "BFMDemod::handleMessage: set m_squelchLevel"; + m_squelchLevel = pow(10.0, m_config.m_squelch / 20.0); + m_squelchLevel *= 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_afBandwidth = m_config.m_afBandwidth; + m_running.m_squelch = m_config.m_squelch; + m_running.m_volume = m_config.m_volume; + m_running.m_audioSampleRate = m_config.m_audioSampleRate; + +} diff --git a/plugins/channel/bfm/bfmdemod.h b/plugins/channel/bfm/bfmdemod.h new file mode 100644 index 000000000..b650e5bc7 --- /dev/null +++ b/plugins/channel/bfm/bfmdemod.h @@ -0,0 +1,138 @@ +/////////////////////////////////////////////////////////////////////////////////// +// 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 . // +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef INCLUDE_BFMDEMOD_H +#define INCLUDE_BFMDEMOD_H + +#include +#include +#include "dsp/samplesink.h" +#include "dsp/nco.h" +#include "dsp/interpolator.h" +#include "dsp/lowpass.h" +#include "dsp/movingaverage.h" +#include "dsp/fftfilt.h" +#include "audio/audiofifo.h" +#include "util/message.h" + +#define rfFilterFftLength 1024 + +class BFMDemod : public SampleSink { +public: + BFMDemod(SampleSink* sampleSink); + virtual ~BFMDemod(); + + void configure(MessageQueue* messageQueue, Real rfBandwidth, Real afBandwidth, Real volume, Real squelch); + + 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); + + Real getMagSq() const { return m_movingAverage.average(); } + +private: + class MsgConfigureBFMDemod : public Message { + MESSAGE_CLASS_DECLARATION + + public: + Real getRFBandwidth() const { return m_rfBandwidth; } + Real getAFBandwidth() const { return m_afBandwidth; } + Real getVolume() const { return m_volume; } + Real getSquelch() const { return m_squelch; } + + static MsgConfigureBFMDemod* create(Real rfBandwidth, Real afBandwidth, Real volume, Real squelch) + { + return new MsgConfigureBFMDemod(rfBandwidth, afBandwidth, volume, squelch); + } + + private: + Real m_rfBandwidth; + Real m_afBandwidth; + Real m_volume; + Real m_squelch; + + MsgConfigureBFMDemod(Real rfBandwidth, Real afBandwidth, Real volume, Real squelch) : + Message(), + m_rfBandwidth(rfBandwidth), + m_afBandwidth(afBandwidth), + m_volume(volume), + m_squelch(squelch) + { } + }; + + struct AudioSample { + qint16 l; + qint16 r; + }; + typedef std::vector AudioVector; + + enum RateState { + RSInitialFill, + RSRunning + }; + + struct Config { + int m_inputSampleRate; + qint64 m_inputFrequencyOffset; + Real m_rfBandwidth; + Real m_afBandwidth; + Real m_squelch; + Real m_volume; + quint32 m_audioSampleRate; + + Config() : + m_inputSampleRate(-1), + m_inputFrequencyOffset(0), + m_rfBandwidth(-1), + m_afBandwidth(-1), + m_squelch(0), + m_volume(0), + m_audioSampleRate(0) + { } + }; + + Config m_config; + Config m_running; + + NCO m_nco; + Interpolator m_interpolator; //!< Interpolator between sample rate sent from DSP engine and requested RF bandwidth (rational) + Real m_interpolatorDistance; + Real m_interpolatorDistanceRemain; + Lowpass m_lowpass; + fftfilt* m_rfFilter; + + Real m_squelchLevel; + int m_squelchState; + + Real m_lastArgument; + Complex m_m1Sample; //!< x^-1 sample + Complex m_m2Sample; //!< x^-1 sample + MovingAverage m_movingAverage; + + AudioVector m_audioBuffer; + uint m_audioBufferFill; + + SampleSink* m_sampleSink; + AudioFifo m_audioFifo; + SampleVector m_sampleBuffer; + QMutex m_settingsMutex; + + void apply(); +}; + +#endif // INCLUDE_BFMDEMOD_H diff --git a/plugins/channel/bfm/bfmdemodgui.cpp b/plugins/channel/bfm/bfmdemodgui.cpp new file mode 100644 index 000000000..a2cbb5818 --- /dev/null +++ b/plugins/channel/bfm/bfmdemodgui.cpp @@ -0,0 +1,302 @@ +#include +#include +#include +#include "dsp/threadedsamplesink.h" +#include "dsp/channelizer.h" +#include "dsp/dspengine.h" +#include "gui/glspectrum.h" +#include "plugin/pluginapi.h" +#include "util/simpleserializer.h" +#include "util/db.h" +#include "gui/basicchannelsettingswidget.h" +#include "mainwindow.h" + +#include "bfmdemodgui.h" + +#include "ui_bfmdemodgui.h" +#include "bfmdemod.h" + +const int BFMDemodGUI::m_rfBW[] = { + 48000, 80000, 120000, 140000, 160000, 180000, 200000, 220000, 250000 +}; + +int requiredBW(int rfBW) +{ + if (rfBW <= 48000) + return 48000; + else if (rfBW < 100000) + return 96000; + else + return 384000; +} + +BFMDemodGUI* BFMDemodGUI::create(PluginAPI* pluginAPI) +{ + BFMDemodGUI* gui = new BFMDemodGUI(pluginAPI); + return gui; +} + +void BFMDemodGUI::destroy() +{ + delete this; +} + +void BFMDemodGUI::setName(const QString& name) +{ + setObjectName(name); +} + +QString BFMDemodGUI::getName() const +{ + return objectName(); +} + +qint64 BFMDemodGUI::getCenterFrequency() const +{ + return m_channelMarker.getCenterFrequency(); +} + +void BFMDemodGUI::setCenterFrequency(qint64 centerFrequency) +{ + m_channelMarker.setCenterFrequency(centerFrequency); + applySettings(); +} + +void BFMDemodGUI::resetToDefaults() +{ + blockApplySettings(true); + + ui->rfBW->setValue(4); + ui->afBW->setValue(3); + ui->volume->setValue(20); + ui->squelch->setValue(-40); + ui->deltaFrequency->setValue(0); + + blockApplySettings(false); + applySettings(); +} + +QByteArray BFMDemodGUI::serialize() const +{ + SimpleSerializer s(1); + s.writeS32(1, m_channelMarker.getCenterFrequency()); + s.writeS32(2, ui->rfBW->value()); + s.writeS32(3, ui->afBW->value()); + s.writeS32(4, ui->volume->value()); + s.writeS32(5, ui->squelch->value()); + s.writeU32(7, m_channelMarker.getColor().rgb()); + return s.final(); +} + +bool BFMDemodGUI::deserialize(const QByteArray& data) +{ + SimpleDeserializer d(data); + + if (!d.isValid()) + { + resetToDefaults(); + return false; + } + + if (d.getVersion() == 1) + { + QByteArray bytetmp; + quint32 u32tmp; + qint32 tmp; + + 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->afBW->setValue(tmp); + d.readS32(4, &tmp, 20); + ui->volume->setValue(tmp); + d.readS32(5, &tmp, -40); + ui->squelch->setValue(tmp); + + if(d.readU32(7, &u32tmp)) + { + m_channelMarker.setColor(u32tmp); + } + + blockApplySettings(false); + m_channelMarker.blockSignals(false); + + applySettings(); + return true; + } + else + { + resetToDefaults(); + return false; + } +} + +bool BFMDemodGUI::handleMessage(const Message& message) +{ + return false; +} + +void BFMDemodGUI::viewChanged() +{ + applySettings(); +} + +void BFMDemodGUI::on_deltaMinus_toggled(bool minus) +{ + int deltaFrequency = m_channelMarker.getCenterFrequency(); + bool minusDelta = (deltaFrequency < 0); + + if (minus ^ minusDelta) // sign change + { + m_channelMarker.setCenterFrequency(-deltaFrequency); + } +} + +void BFMDemodGUI::on_deltaFrequency_changed(quint64 value) +{ + if (ui->deltaMinus->isChecked()) + { + m_channelMarker.setCenterFrequency(-value); + } + else + { + m_channelMarker.setCenterFrequency(value); + } +} + +void BFMDemodGUI::on_rfBW_valueChanged(int value) +{ + ui->rfBWText->setText(QString("%1 kHz").arg(m_rfBW[value] / 1000.0)); + m_channelMarker.setBandwidth(m_rfBW[value]); + applySettings(); +} + +void BFMDemodGUI::on_afBW_valueChanged(int value) +{ + ui->afBWText->setText(QString("%1 kHz").arg(value)); + applySettings(); +} + +void BFMDemodGUI::on_volume_valueChanged(int value) +{ + ui->volumeText->setText(QString("%1").arg(value / 10.0, 0, 'f', 1)); + applySettings(); +} + +void BFMDemodGUI::on_squelch_valueChanged(int value) +{ + ui->squelchText->setText(QString("%1 dB").arg(value)); + applySettings(); +} + + +void BFMDemodGUI::onWidgetRolled(QWidget* widget, bool rollDown) +{ +} + +void BFMDemodGUI::onMenuDoubleClicked() +{ + if(!m_basicSettingsShown) + { + m_basicSettingsShown = true; + BasicChannelSettingsWidget* bcsw = new BasicChannelSettingsWidget(&m_channelMarker, this); + bcsw->show(); + } +} + +BFMDemodGUI::BFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent) : + RollupWidget(parent), + ui(new Ui::BFMDemodGUI), + m_pluginAPI(pluginAPI), + m_channelMarker(this), + m_basicSettingsShown(false), + m_channelPowerDbAvg(20,0) +{ + ui->setupUi(this); + ui->deltaFrequency->setColorMapper(ColorMapper(ColorMapper::ReverseGold)); + ui->deltaFrequency->setValueRange(7, 0U, 9999999U); + + setAttribute(Qt::WA_DeleteOnClose, true); + connect(this, SIGNAL(widgetRolled(QWidget*,bool)), this, SLOT(onWidgetRolled(QWidget*,bool))); + connect(this, SIGNAL(menuDoubleClickEvent()), this, SLOT(onMenuDoubleClicked())); + + m_wfmDemod = new BFMDemod(0); + m_channelizer = new Channelizer(m_wfmDemod); + m_threadedChannelizer = new ThreadedSampleSink(m_channelizer, this); + DSPEngine::instance()->addThreadedSink(m_threadedChannelizer); + + connect(&m_pluginAPI->getMainWindow()->getMasterTimer(), SIGNAL(timeout()), this, SLOT(tick())); + + //m_channelMarker = new ChannelMarker(this); + m_channelMarker.setColor(Qt::blue); + m_channelMarker.setBandwidth(12500); + m_channelMarker.setCenterFrequency(0); + m_channelMarker.setVisible(true); + connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(viewChanged())); + m_pluginAPI->addChannelMarker(&m_channelMarker); + + applySettings(); +} + +BFMDemodGUI::~BFMDemodGUI() +{ + m_pluginAPI->removeChannelInstance(this); + DSPEngine::instance()->removeThreadedSink(m_threadedChannelizer); + delete m_threadedChannelizer; + delete m_channelizer; + delete m_wfmDemod; + //delete m_channelMarker; + delete ui; +} + +void BFMDemodGUI::blockApplySettings(bool block) +{ + m_doApplySettings = !block; +} + +void BFMDemodGUI::applySettings() +{ + if (m_doApplySettings) + { + setTitleColor(m_channelMarker.getColor()); + + m_channelizer->configure(m_channelizer->getInputMessageQueue(), + requiredBW(m_rfBW[ui->rfBW->value()]), // TODO: this is where requested sample rate is specified + m_channelMarker.getCenterFrequency()); + + ui->deltaFrequency->setValue(abs(m_channelMarker.getCenterFrequency())); + ui->deltaMinus->setChecked(m_channelMarker.getCenterFrequency() < 0); + + m_wfmDemod->configure(m_wfmDemod->getInputMessageQueue(), + m_rfBW[ui->rfBW->value()], + ui->afBW->value() * 1000.0, + ui->volume->value() / 10.0, + ui->squelch->value()); + } +} + +void BFMDemodGUI::leaveEvent(QEvent*) +{ + blockApplySettings(true); + m_channelMarker.setHighlighted(false); + blockApplySettings(false); +} + +void BFMDemodGUI::enterEvent(QEvent*) +{ + blockApplySettings(true); + m_channelMarker.setHighlighted(true); + blockApplySettings(false); +} + +void BFMDemodGUI::tick() +{ + Real powDb = CalcDb::dbPower(m_wfmDemod->getMagSq()); + m_channelPowerDbAvg.feed(powDb); + ui->channelPower->setText(QString::number(m_channelPowerDbAvg.average(), 'f', 1)); +} diff --git a/plugins/channel/bfm/bfmdemodgui.h b/plugins/channel/bfm/bfmdemodgui.h new file mode 100644 index 000000000..a2eef8490 --- /dev/null +++ b/plugins/channel/bfm/bfmdemodgui.h @@ -0,0 +1,73 @@ +#ifndef INCLUDE_BFMDEMODGUI_H +#define INCLUDE_BFMDEMODGUI_H + +#include "gui/rollupwidget.h" +#include "plugin/plugingui.h" +#include "dsp/channelmarker.h" +#include "dsp/movingaverage.h" + +class PluginAPI; + +class ThreadedSampleSink; +class Channelizer; +class BFMDemod; + +namespace Ui { + class BFMDemodGUI; +} + +class BFMDemodGUI : public RollupWidget, public PluginGUI { + Q_OBJECT + +public: + static BFMDemodGUI* 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 value); + void on_afBW_valueChanged(int value); + void on_volume_valueChanged(int value); + void on_squelch_valueChanged(int value); + void onWidgetRolled(QWidget* widget, bool rollDown); + void onMenuDoubleClicked(); + void tick(); + +private: + Ui::BFMDemodGUI* ui; + PluginAPI* m_pluginAPI; + ChannelMarker m_channelMarker; + bool m_basicSettingsShown; + bool m_doApplySettings; + + ThreadedSampleSink* m_threadedChannelizer; + Channelizer* m_channelizer; + BFMDemod* m_wfmDemod; + MovingAverage m_channelPowerDbAvg; + + static const int m_rfBW[]; + + explicit BFMDemodGUI(PluginAPI* pluginAPI, QWidget* parent = NULL); + virtual ~BFMDemodGUI(); + + void blockApplySettings(bool block); + void applySettings(); + + void leaveEvent(QEvent*); + void enterEvent(QEvent*); +}; + +#endif // INCLUDE_BFMDEMODGUI_H diff --git a/plugins/channel/bfm/bfmdemodgui.ui b/plugins/channel/bfm/bfmdemodgui.ui new file mode 100644 index 000000000..69bff07ac --- /dev/null +++ b/plugins/channel/bfm/bfmdemodgui.ui @@ -0,0 +1,336 @@ + + + BFMDemodGUI + + + + 0 + 0 + 302 + 373 + + + + Broadcast FM Demod + + + + + 20 + 20 + 235 + 121 + + + + Settings + + + + 3 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + + + + + ... + + + + :/plus.png + :/minus.png + + + + true + + + + + + + + 0 + 0 + + + + + 32 + 16 + + + + + Monospace + 12 + + + + SizeVerCursor + + + Qt::StrongFocus + + + Demod shift frequency from center in Hz + + + + + + + Hz + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Channel power + + + Qt::RightToLeft + + + 0.0 + + + + + + + dB + + + + + + + + + + + + + RF BW + + + + + + + 8 + + + 1 + + + 4 + + + Qt::Horizontal + + + + + + + + 50 + 0 + + + + 12.5kHz + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + AF BW + + + + + + + 1 + + + 20 + + + 1 + + + 3 + + + Qt::Horizontal + + + + + + + + 50 + 0 + + + + 3 kHz + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Vol + + + + + + + 100 + + + 20 + + + Qt::Horizontal + + + + + + + + 50 + 0 + + + + 2.0 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + Sq + + + + + + + -100 + + + 0 + + + -40 + + + Qt::Horizontal + + + + + + + + 50 + 0 + + + + -40dB + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + + + + RollupWidget + QWidget +
gui/rollupwidget.h
+ 1 +
+ + ValueDial + QWidget +
gui/valuedial.h
+ 1 +
+
+ + + + +
diff --git a/plugins/channel/bfm/bfmplugin.cpp b/plugins/channel/bfm/bfmplugin.cpp new file mode 100644 index 000000000..d6ed37728 --- /dev/null +++ b/plugins/channel/bfm/bfmplugin.cpp @@ -0,0 +1,55 @@ +#include +#include +#include "plugin/pluginapi.h" + +#include "bfmplugin.h" + +#include "bfmdemodgui.h" + +const PluginDescriptor BFMPlugin::m_pluginDescriptor = { + QString("Broadcast FM Demodulator"), + QString("---"), + QString("(c) Edouard Griffiths, F4EXB"), + QString("https://github.com/f4exb/sdrangel"), + true, + QString("https://github.com/f4exb/sdrangel") +}; + +BFMPlugin::BFMPlugin(QObject* parent) : + QObject(parent) +{ +} + +const PluginDescriptor& BFMPlugin::getPluginDescriptor() const +{ + return m_pluginDescriptor; +} + +void BFMPlugin::initPlugin(PluginAPI* pluginAPI) +{ + m_pluginAPI = pluginAPI; + + // register BFM demodulator + QAction* action = new QAction(tr("&Broadcast FM Demodulator"), this); + connect(action, SIGNAL(triggered()), this, SLOT(createInstanceBFM())); + m_pluginAPI->registerChannel("sdrangel.channel.bfm", this, action); +} + +PluginGUI* BFMPlugin::createChannel(const QString& channelName) +{ + if(channelName == "sdrangel.channel.bfm") { + BFMDemodGUI* gui = BFMDemodGUI::create(m_pluginAPI); + m_pluginAPI->registerChannelInstance("sdrangel.channel.bfm", gui); + m_pluginAPI->addChannelRollup(gui); + return gui; + } else { + return 0; + } +} + +void BFMPlugin::createInstanceBFM() +{ + BFMDemodGUI* gui = BFMDemodGUI::create(m_pluginAPI); + m_pluginAPI->registerChannelInstance("sdrangel.channel.bfm", gui); + m_pluginAPI->addChannelRollup(gui); +} diff --git a/plugins/channel/bfm/bfmplugin.h b/plugins/channel/bfm/bfmplugin.h new file mode 100644 index 000000000..f3e198bbe --- /dev/null +++ b/plugins/channel/bfm/bfmplugin.h @@ -0,0 +1,29 @@ +#ifndef INCLUDE_BFMPLUGIN_H +#define INCLUDE_BFMPLUGIN_H + +#include +#include "plugin/plugininterface.h" + +class BFMPlugin : public QObject, PluginInterface { + Q_OBJECT + Q_INTERFACES(PluginInterface) + Q_PLUGIN_METADATA(IID "sdrangel.channel.bfm") + +public: + explicit BFMPlugin(QObject* parent = 0); + + 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 createInstanceBFM(); +}; + +#endif // INCLUDE_BFMPLUGIN_H