mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-06-25 20:07:51 +02:00
Switch old radio module to new radio module
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.13)
|
||||
project(radio)
|
||||
|
||||
file(GLOB SRC "src/*.cpp")
|
||||
file(GLOB_RECURSE SRC "src/*.cpp")
|
||||
|
||||
add_library(radio SHARED ${SRC})
|
||||
target_link_libraries(radio PRIVATE sdrpp_core)
|
||||
|
@ -1,219 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class AMDemodulator : public Demodulator {
|
||||
public:
|
||||
AMDemodulator() {}
|
||||
AMDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("AM")) {
|
||||
_config->conf[prefix]["AM"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["AM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["AM"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["AM"];
|
||||
if (conf.contains("bandwidth")) { bw = conf["bandwidth"]; }
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["AM"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["AM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["AM"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
demod.init(&squelch.out);
|
||||
|
||||
agc.init(&demod.out, 20.0f, bbSampRate);
|
||||
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw / 2.0f);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
resamp.init(&agc.out, &win, bbSampRate, audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
m2s.init(&resamp.out);
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
demod.start();
|
||||
agc.start();
|
||||
resamp.start();
|
||||
m2s.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
resamp.stop();
|
||||
m2s.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_CENTER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw / 2.0f);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &m2s.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_am_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["AM"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_am_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["AM"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_am_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["AM"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
AMDemodulator* _this = (AMDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["AM"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw / 2.0f);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["AM"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["AM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["AM"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
const float bwMax = 15000;
|
||||
const float bwMin = 1000;
|
||||
const float bbSampRate = 15000;
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 1000;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 12500;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
dsp::AMDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<float> resamp;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
@ -1,224 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class CWDemodulator : public Demodulator {
|
||||
public:
|
||||
CWDemodulator() {}
|
||||
CWDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("CW")) {
|
||||
_config->conf[prefix]["CW"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["CW"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["CW"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["CW"];
|
||||
if (conf.contains("bandwidth")) { bw = conf["bandwidth"]; }
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["CW"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["CW"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["CW"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
xlator.init(&squelch.out, bbSampRate, 1000.0f);
|
||||
|
||||
c2r.init(&xlator.out);
|
||||
|
||||
agc.init(&c2r.out, 20.0f, bbSampRate);
|
||||
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, (bw / 2.0f) + 1000.0f);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
resamp.init(&agc.out, &win, bbSampRate, audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
m2s.init(&resamp.out);
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
xlator.start();
|
||||
c2r.start();
|
||||
agc.start();
|
||||
resamp.start();
|
||||
m2s.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
xlator.stop();
|
||||
c2r.stop();
|
||||
agc.stop();
|
||||
resamp.stop();
|
||||
m2s.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_CENTER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, (bw / 2.0f) + 1000.0f);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &m2s.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_cw_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["CW"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_cw_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["CW"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_cw_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["CW"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
CWDemodulator* _this = (CWDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["CW"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, (bw / 2.0f) + 1000.0f);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["CW"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["CW"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["CW"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
const float bwMax = 500;
|
||||
const float bwMin = 50;
|
||||
const float bbSampRate = 3000;
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 10;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 500;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
dsp::FrequencyXlator<dsp::complex_t> xlator;
|
||||
dsp::ComplexToReal c2r;
|
||||
dsp::AGC agc;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<float> resamp;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
53
decoder_modules/radio/src/demod.h
Normal file
53
decoder_modules/radio/src/demod.h
Normal file
@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
#include <dsp/stream.h>
|
||||
#include <dsp/types.h>
|
||||
#include <gui/widgets/waterfall.h>
|
||||
#include <config.h>
|
||||
#include <utils/event.h>
|
||||
|
||||
enum DeemphasisMode {
|
||||
DEEMP_MODE_50US,
|
||||
DEEMP_MODE_75US,
|
||||
DEEMP_MODE_NONE,
|
||||
_DEEMP_MODE_COUNT
|
||||
};
|
||||
|
||||
namespace demod {
|
||||
class Demodulator {
|
||||
public:
|
||||
virtual ~Demodulator() {}
|
||||
virtual void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) = 0;
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void showMenu() = 0;
|
||||
virtual void setBandwidth(double bandwidth) = 0;
|
||||
virtual void setInput(dsp::stream<dsp::complex_t>* input) = 0;
|
||||
virtual void AFSampRateChanged(double newSR) = 0;
|
||||
virtual const char* getName() = 0;
|
||||
virtual double getIFSampleRate() = 0;
|
||||
virtual double getAFSampleRate() = 0;
|
||||
virtual double getDefaultBandwidth() = 0;
|
||||
virtual double getMinBandwidth() = 0;
|
||||
virtual double getMaxBandwidth() = 0;
|
||||
virtual bool getBandwidthLocked() = 0;
|
||||
virtual double getMaxAFBandwidth() = 0;
|
||||
virtual double getDefaultSnapInterval() = 0;
|
||||
virtual int getVFOReference() = 0;
|
||||
virtual bool getDeempAllowed() = 0;
|
||||
virtual bool getPostProcEnabled() = 0;
|
||||
virtual int getDefaultDeemphasisMode() = 0;
|
||||
virtual double getAFBandwidth(double bandwidth) = 0;
|
||||
|
||||
virtual bool getDynamicAFBandwidth() = 0;
|
||||
virtual dsp::stream<dsp::stereo_t>* getOutput() = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#include "demodulators/wfm.h"
|
||||
#include "demodulators/nfm.h"
|
||||
#include "demodulators/am.h"
|
||||
#include "demodulators/usb.h"
|
||||
#include "demodulators/lsb.h"
|
||||
#include "demodulators/dsb.h"
|
||||
#include "demodulators/cw.h"
|
||||
#include "demodulators/raw.h"
|
80
decoder_modules/radio/src/demodulators/am.h
Normal file
80
decoder_modules/radio/src/demodulators/am.h
Normal file
@ -0,0 +1,80 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class AM : public Demodulator {
|
||||
public:
|
||||
AM() {}
|
||||
|
||||
AM(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~AM() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
|
||||
// Define structure
|
||||
demod.init(input);
|
||||
agc.init(&demod.out, 20.0f, getIFSampleRate());
|
||||
m2s.init(&agc.out);
|
||||
}
|
||||
|
||||
void start() {
|
||||
demod.start();
|
||||
agc.start();
|
||||
m2s.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
m2s.stop();
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
// TODO: Adjust AGC settings
|
||||
}
|
||||
|
||||
void setBandwidth(double bandwidth) {}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
demod.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "AM"; }
|
||||
double getIFSampleRate() { return 15000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 10000.0; }
|
||||
double getMinBandwidth() { return 1000.0; }
|
||||
double getMaxBandwidth() { return getIFSampleRate(); }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
double getDefaultSnapInterval() { return 1000.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_CENTER; }
|
||||
bool getDeempAllowed() { return false; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return bandwidth / 2.0; }
|
||||
bool getDynamicAFBandwidth() { return true; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &m2s.out; }
|
||||
|
||||
private:
|
||||
dsp::AMDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
82
decoder_modules/radio/src/demodulators/cw.h
Normal file
82
decoder_modules/radio/src/demodulators/cw.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class CW : public Demodulator {
|
||||
public:
|
||||
CW() {}
|
||||
|
||||
CW(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~CW() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
|
||||
// Define structure
|
||||
xlator.init(input, getIFSampleRate(), 1000.0);
|
||||
c2r.init(&xlator.out);
|
||||
agc.init(&c2r.out, 20.0f, getIFSampleRate());
|
||||
m2s.init(&agc.out);
|
||||
}
|
||||
|
||||
void start() {
|
||||
xlator.start();
|
||||
c2r.start();
|
||||
agc.start();
|
||||
m2s.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
xlator.stop();
|
||||
c2r.stop();
|
||||
agc.stop();
|
||||
m2s.stop();
|
||||
}
|
||||
|
||||
void showMenu() {}
|
||||
|
||||
void setBandwidth(double bandwidth) {}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
xlator.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "CW"; }
|
||||
double getIFSampleRate() { return 3000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 500.0; }
|
||||
double getMinBandwidth() { return 50.0; }
|
||||
double getMaxBandwidth() { return 500.0; }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
double getDefaultSnapInterval() { return 10.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_CENTER; }
|
||||
bool getDeempAllowed() { return false; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return (bandwidth / 2.0) + 1000.0; }
|
||||
bool getDynamicAFBandwidth() { return true; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &m2s.out; }
|
||||
|
||||
private:
|
||||
dsp::FrequencyXlator<dsp::complex_t> xlator;
|
||||
dsp::ComplexToReal c2r;
|
||||
dsp::AGC agc;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
82
decoder_modules/radio/src/demodulators/dsb.h
Normal file
82
decoder_modules/radio/src/demodulators/dsb.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class DSB : public Demodulator {
|
||||
public:
|
||||
DSB() {}
|
||||
|
||||
DSB(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~DSB() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
|
||||
// Define structure
|
||||
demod.init(input, getIFSampleRate(), bandwidth, dsp::SSBDemod::MODE_DSB);
|
||||
agc.init(&demod.out, 20.0f, getIFSampleRate());
|
||||
m2s.init(&agc.out);
|
||||
}
|
||||
|
||||
void start() {
|
||||
demod.start();
|
||||
agc.start();
|
||||
m2s.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
m2s.stop();
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
// TODO: Adjust AGC settings
|
||||
}
|
||||
|
||||
void setBandwidth(double bandwidth) {
|
||||
demod.setBandWidth(bandwidth);
|
||||
}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
demod.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "DSB"; }
|
||||
double getIFSampleRate() { return 24000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 4600.0; }
|
||||
double getMinBandwidth() { return 1000.0; }
|
||||
double getMaxBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
double getDefaultSnapInterval() { return 100.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_CENTER; }
|
||||
bool getDeempAllowed() { return false; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return bandwidth / 2.0; }
|
||||
bool getDynamicAFBandwidth() { return true; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &m2s.out; }
|
||||
|
||||
private:
|
||||
dsp::SSBDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
82
decoder_modules/radio/src/demodulators/lsb.h
Normal file
82
decoder_modules/radio/src/demodulators/lsb.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class LSB : public Demodulator {
|
||||
public:
|
||||
LSB() {}
|
||||
|
||||
LSB(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~LSB() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
|
||||
// Define structure
|
||||
demod.init(input, getIFSampleRate(), bandwidth, dsp::SSBDemod::MODE_LSB);
|
||||
agc.init(&demod.out, 20.0f, getIFSampleRate());
|
||||
m2s.init(&agc.out);
|
||||
}
|
||||
|
||||
void start() {
|
||||
demod.start();
|
||||
agc.start();
|
||||
m2s.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
m2s.stop();
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
// TODO: Adjust AGC settings
|
||||
}
|
||||
|
||||
void setBandwidth(double bandwidth) {
|
||||
demod.setBandWidth(bandwidth);
|
||||
}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
demod.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "LSB"; }
|
||||
double getIFSampleRate() { return 24000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 2800.0; }
|
||||
double getMinBandwidth() { return 500.0; }
|
||||
double getMaxBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
double getDefaultSnapInterval() { return 100.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_UPPER; }
|
||||
bool getDeempAllowed() { return false; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return bandwidth; }
|
||||
bool getDynamicAFBandwidth() { return true; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &m2s.out; }
|
||||
|
||||
private:
|
||||
dsp::SSBDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
72
decoder_modules/radio/src/demodulators/nfm.h
Normal file
72
decoder_modules/radio/src/demodulators/nfm.h
Normal file
@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class NFM : public Demodulator {
|
||||
public:
|
||||
NFM() {}
|
||||
|
||||
NFM(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~NFM() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
|
||||
// Define structure
|
||||
demod.init(input, getIFSampleRate(), bandwidth / 2.0f);
|
||||
}
|
||||
|
||||
void start() {
|
||||
demod.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
demod.stop();
|
||||
}
|
||||
|
||||
void showMenu() {}
|
||||
|
||||
void setBandwidth(double bandwidth) {
|
||||
demod.setDeviation(bandwidth / 2.0f);
|
||||
}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
demod.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "FM"; }
|
||||
double getIFSampleRate() { return 50000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 12500.0; }
|
||||
double getMinBandwidth() { return 1000.0; }
|
||||
double getMaxBandwidth() { return getIFSampleRate(); }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
double getDefaultSnapInterval() { return 2500.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_CENTER; }
|
||||
bool getDeempAllowed() { return true; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return bandwidth / 2.0; }
|
||||
bool getDynamicAFBandwidth() { return true; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &demod.out; }
|
||||
|
||||
private:
|
||||
dsp::FMDemod demod;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
74
decoder_modules/radio/src/demodulators/raw.h
Normal file
74
decoder_modules/radio/src/demodulators/raw.h
Normal file
@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class RAW : public Demodulator {
|
||||
public:
|
||||
RAW() {}
|
||||
|
||||
RAW(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~RAW() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
audioSampleRate = audioSR;
|
||||
|
||||
// Define structure
|
||||
c2s.init(input);
|
||||
}
|
||||
|
||||
void start() {
|
||||
c2s.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
c2s.stop();
|
||||
}
|
||||
|
||||
void showMenu() {}
|
||||
|
||||
void setBandwidth(double bandwidth) {}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
c2s.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {
|
||||
audioSampleRate = newSR;
|
||||
}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "RAW"; }
|
||||
double getIFSampleRate() { return audioSampleRate; }
|
||||
double getAFSampleRate() { return audioSampleRate; }
|
||||
double getDefaultBandwidth() { return audioSampleRate; }
|
||||
double getMinBandwidth() { return audioSampleRate; }
|
||||
double getMaxBandwidth() { return audioSampleRate; }
|
||||
bool getBandwidthLocked() { return true; }
|
||||
double getMaxAFBandwidth() { return audioSampleRate; }
|
||||
double getDefaultSnapInterval() { return 2500.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_CENTER; }
|
||||
bool getDeempAllowed() { return false; }
|
||||
bool getPostProcEnabled() { return false; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return bandwidth; }
|
||||
bool getDynamicAFBandwidth() { return false; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &c2s.out; }
|
||||
|
||||
private:
|
||||
double audioSampleRate;
|
||||
dsp::ComplexToStereo c2s;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
82
decoder_modules/radio/src/demodulators/usb.h
Normal file
82
decoder_modules/radio/src/demodulators/usb.h
Normal file
@ -0,0 +1,82 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class USB : public Demodulator {
|
||||
public:
|
||||
USB() {}
|
||||
|
||||
USB(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~USB() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
|
||||
// Define structure
|
||||
demod.init(input, getIFSampleRate(), bandwidth, dsp::SSBDemod::MODE_USB);
|
||||
agc.init(&demod.out, 20.0f, getIFSampleRate());
|
||||
m2s.init(&agc.out);
|
||||
}
|
||||
|
||||
void start() {
|
||||
demod.start();
|
||||
agc.start();
|
||||
m2s.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
m2s.stop();
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
// TODO: Adjust AGC settings
|
||||
}
|
||||
|
||||
void setBandwidth(double bandwidth) {
|
||||
demod.setBandWidth(bandwidth);
|
||||
}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
demod.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "USB"; }
|
||||
double getIFSampleRate() { return 24000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 2800.0; }
|
||||
double getMinBandwidth() { return 500.0; }
|
||||
double getMaxBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return getIFSampleRate() / 2.0; }
|
||||
double getDefaultSnapInterval() { return 100.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_LOWER; }
|
||||
bool getDeempAllowed() { return false; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; }
|
||||
double getAFBandwidth(double bandwidth) { return bandwidth; }
|
||||
bool getDynamicAFBandwidth() { return true; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return &m2s.out; }
|
||||
|
||||
private:
|
||||
dsp::SSBDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
117
decoder_modules/radio/src/demodulators/wfm.h
Normal file
117
decoder_modules/radio/src/demodulators/wfm.h
Normal file
@ -0,0 +1,117 @@
|
||||
#pragma once
|
||||
#include "../demod.h"
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/filter.h>
|
||||
|
||||
namespace demod {
|
||||
class WFM : public Demodulator {
|
||||
public:
|
||||
WFM() {}
|
||||
|
||||
WFM(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
init(name, config, input, bandwidth, outputChangeHandler, audioSR);
|
||||
}
|
||||
|
||||
~WFM() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, double audioSR) {
|
||||
this->name = name;
|
||||
this->outputChangeHandler = outputChangeHandler;
|
||||
_config = config;
|
||||
|
||||
// Load config
|
||||
_config->acquire();
|
||||
bool modified =false;
|
||||
if (!config->conf[name].contains(getName())) {
|
||||
config->conf[name][getName()]["stereo"] = false;
|
||||
modified = true;
|
||||
}
|
||||
if (config->conf[name][getName()].contains("stereo")) {
|
||||
stereo = config->conf[name][getName()]["stereo"];
|
||||
}
|
||||
_config->release(modified);
|
||||
|
||||
// Define structure
|
||||
demod.init(input, getIFSampleRate(), bandwidth / 2.0f);
|
||||
demodStereo.init(input, getIFSampleRate(), bandwidth / 2.0f);
|
||||
}
|
||||
|
||||
void start() {
|
||||
stereo ? demodStereo.start() : demod.start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
demod.stop();
|
||||
demodStereo.stop();
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
if (ImGui::Checkbox(("Stereo##_radio_wfm_stereo_" + name).c_str(), &stereo)) {
|
||||
setStereo(stereo);
|
||||
_config->acquire();
|
||||
_config->conf[name][getName()]["stereo"] = stereo;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(double bandwidth) {
|
||||
demod.setDeviation(bandwidth / 2.0f);
|
||||
demodStereo.setDeviation(bandwidth / 2.0f);
|
||||
}
|
||||
|
||||
void setInput(dsp::stream<dsp::complex_t>* input) {
|
||||
demod.setInput(input);
|
||||
demodStereo.setInput(input);
|
||||
}
|
||||
|
||||
void AFSampRateChanged(double newSR) {}
|
||||
|
||||
// ============= INFO =============
|
||||
|
||||
const char* getName() { return "WFM"; }
|
||||
double getIFSampleRate() { return 250000.0; }
|
||||
double getAFSampleRate() { return getIFSampleRate(); }
|
||||
double getDefaultBandwidth() { return 150000.0; }
|
||||
double getMinBandwidth() { return 50000.0; }
|
||||
double getMaxBandwidth() { return getIFSampleRate(); }
|
||||
bool getBandwidthLocked() { return false; }
|
||||
double getMaxAFBandwidth() { return 16000.0; }
|
||||
double getDefaultSnapInterval() { return 100000.0; }
|
||||
int getVFOReference() { return ImGui::WaterfallVFO::REF_CENTER; }
|
||||
bool getDeempAllowed() { return true; }
|
||||
bool getPostProcEnabled() { return true; }
|
||||
int getDefaultDeemphasisMode() { return DEEMP_MODE_50US; }
|
||||
double getAFBandwidth(double bandwidth) { return 16000.0; }
|
||||
bool getDynamicAFBandwidth() { return false; }
|
||||
dsp::stream<dsp::stereo_t>* getOutput() { return stereo ? demodStereo.out : &demod.out; }
|
||||
|
||||
// ============= DEDICATED FUNCTIONS =============
|
||||
|
||||
void setStereo(bool _stereo) {
|
||||
stereo = _stereo;
|
||||
if (stereo) {
|
||||
demod.stop();
|
||||
outputChangeHandler.handler(demodStereo.out, outputChangeHandler.ctx);
|
||||
demodStereo.start();
|
||||
}
|
||||
else {
|
||||
demodStereo.stop();
|
||||
outputChangeHandler.handler(&demod.out, outputChangeHandler.ctx);
|
||||
demod.start();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
dsp::FMDemod demod;
|
||||
dsp::StereoFMDemod demodStereo;
|
||||
|
||||
ConfigManager* _config = NULL;
|
||||
|
||||
bool stereo = false;
|
||||
|
||||
std::string name;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
|
||||
};
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class DSBDemodulator : public Demodulator {
|
||||
public:
|
||||
DSBDemodulator() {}
|
||||
DSBDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("DSB")) {
|
||||
_config->conf[prefix]["DSB"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["DSB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["DSB"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["DSB"];
|
||||
if (conf.contains("bandwidth")) { bw = conf["bandwidth"]; }
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["DSB"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["DSB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["DSB"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
demod.init(&squelch.out, bbSampRate, bw, dsp::SSBDemod::MODE_DSB);
|
||||
|
||||
agc.init(&demod.out, 20.0f, bbSampRate);
|
||||
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw / 2.0f);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
resamp.init(&agc.out, &win, bbSampRate, audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
m2s.init(&resamp.out);
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
demod.start();
|
||||
agc.start();
|
||||
resamp.start();
|
||||
m2s.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
resamp.stop();
|
||||
m2s.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_CENTER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw / 2.0f);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &m2s.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_dsb_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["DSB"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_dsb_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["DSB"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_dsb_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["DSB"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
DSBDemodulator* _this = (DSBDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["DSB"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["DSB"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["DSB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["DSB"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
const float bwMax = 12000;
|
||||
const float bwMin = 1000;
|
||||
const float bbSampRate = 12000;
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 100;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 6000;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
dsp::SSBDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<float> resamp;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
@ -1,206 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class FMDemodulator : public Demodulator {
|
||||
public:
|
||||
FMDemodulator() {}
|
||||
FMDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("FM")) {
|
||||
_config->conf[prefix]["FM"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["FM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["FM"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["FM"];
|
||||
if (conf.contains("bandwidth")) { bw = conf["bandwidth"]; }
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["FM"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["FM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["FM"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
demod.init(&squelch.out, bbSampRate, bw / 2.0f);
|
||||
|
||||
float audioBW = std::min<float>(audioSampleRate / 2.0f, bw / 2.0f);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
resamp.init(&demod.out, &win, bbSampRate, audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
demod.start();
|
||||
resamp.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
demod.stop();
|
||||
resamp.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_CENTER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw / 2.0f);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &resamp.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_fm_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["FM"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_fm_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["FM"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_fm_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["FM"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
FMDemodulator* _this = (FMDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["FM"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
demod.setDeviation(bw / 2.0f);
|
||||
setAudioSampleRate(audioSampRate);
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["FM"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["FM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["FM"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
const float bwMax = 50000;
|
||||
const float bwMin = 1000;
|
||||
const float bbSampRate = 50000;
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 2500;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 50000;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
dsp::FMDemod demod;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<dsp::stereo_t> resamp;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
@ -1,220 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class LSBDemodulator : public Demodulator {
|
||||
public:
|
||||
LSBDemodulator() {}
|
||||
LSBDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("LSB")) {
|
||||
_config->conf[prefix]["LSB"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["LSB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["LSB"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["LSB"];
|
||||
if (conf.contains("bandwidth")) { bw = conf["bandwidth"]; }
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["LSB"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["LSB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["LSB"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
demod.init(&squelch.out, bbSampRate, bw, dsp::SSBDemod::MODE_LSB);
|
||||
|
||||
agc.init(&demod.out, 20.0f, bbSampRate);
|
||||
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
resamp.init(&agc.out, &win, bbSampRate, audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
m2s.init(&resamp.out);
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
demod.start();
|
||||
agc.start();
|
||||
resamp.start();
|
||||
m2s.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
resamp.stop();
|
||||
m2s.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_UPPER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &m2s.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_lsb_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["LSB"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_lsb_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["LSB"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_lsb_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["LSB"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
LSBDemodulator* _this = (LSBDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["LSB"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
demod.setBandWidth(bw);
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["LSB"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["LSB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["LSB"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
const float bwMax = 12000;
|
||||
const float bwMin = 500;
|
||||
const float bbSampRate = 24000;
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 100;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 3000;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
dsp::SSBDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<float> resamp;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
@ -1,237 +1,14 @@
|
||||
#include <imgui.h>
|
||||
#include <config.h>
|
||||
#include <core.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/style.h>
|
||||
#include <signal_path/signal_path.h>
|
||||
#include <radio_demod.h>
|
||||
#include <module.h>
|
||||
#include <wfm_demod.h>
|
||||
#include <fm_demod.h>
|
||||
#include <am_demod.h>
|
||||
#include <usb_demod.h>
|
||||
#include <lsb_demod.h>
|
||||
#include <dsb_demod.h>
|
||||
#include <raw_demod.h>
|
||||
#include <cw_demod.h>
|
||||
#include "radio_module.h"
|
||||
#include <options.h>
|
||||
#include <radio_interface.h>
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
|
||||
SDRPP_MOD_INFO {
|
||||
/* Name: */ "radio",
|
||||
/* Description: */ "Radio module for SDR++",
|
||||
/* Description: */ "Analog radio decoder",
|
||||
/* Author: */ "Ryzerth",
|
||||
/* Version: */ 0, 3, 0,
|
||||
/* Version: */ 2, 0, 0,
|
||||
/* Max instances */ -1
|
||||
};
|
||||
|
||||
static ConfigManager config;
|
||||
|
||||
class RadioModule : public ModuleManager::Instance {
|
||||
public:
|
||||
RadioModule(std::string name) {
|
||||
this->name = name;
|
||||
|
||||
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 200000, 200000, 50000, 200000, false);
|
||||
|
||||
ns.init(vfo->output);
|
||||
|
||||
config.acquire();
|
||||
if (!config.conf.contains(name)) {
|
||||
config.conf[name]["selectedDemodId"] = 1;
|
||||
}
|
||||
demodId = config.conf[name]["selectedDemodId"];
|
||||
config.release(true);
|
||||
|
||||
wfmDemod.init(name, vfo, audioSampRate, 200000, &config);
|
||||
fmDemod.init(name, vfo, audioSampRate, 12500, &config);
|
||||
amDemod.init(name, vfo, audioSampRate, 12500, &config);
|
||||
usbDemod.init(name, vfo, audioSampRate, 3000, &config);
|
||||
lsbDemod.init(name, vfo, audioSampRate, 3000, &config);
|
||||
dsbDemod.init(name, vfo, audioSampRate, 6000, &config);
|
||||
rawDemod.init(name, vfo, audioSampRate, audioSampRate, &config);
|
||||
cwDemod.init(name, vfo, audioSampRate, 200, &config);
|
||||
|
||||
srChangeHandler.ctx = this;
|
||||
srChangeHandler.handler = sampleRateChangeHandler;
|
||||
stream.init(wfmDemod.getOutput(), &srChangeHandler, audioSampRate);
|
||||
sigpath::sinkManager.registerStream(name, &stream);
|
||||
|
||||
selectDemodById(demodId);
|
||||
|
||||
stream.start();
|
||||
|
||||
gui::menu.registerEntry(name, menuHandler, this, this);
|
||||
|
||||
core::modComManager.registerInterface("radio", name, moduleInterfaceHandler, this);
|
||||
}
|
||||
|
||||
~RadioModule() {
|
||||
core::modComManager.unregisterInterface(name);
|
||||
gui::menu.removeEntry(name);
|
||||
stream.stop();
|
||||
if (enabled) {
|
||||
currentDemod->stop();
|
||||
sigpath::vfoManager.deleteVFO(vfo);
|
||||
}
|
||||
sigpath::sinkManager.unregisterStream(name);
|
||||
}
|
||||
|
||||
void postInit() {}
|
||||
|
||||
void enable() {
|
||||
double bw = gui::waterfall.getBandwidth();
|
||||
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, std::clamp<double>(0, -bw/2.0, bw/2.0), 200000, 200000, 50000, 200000, false);
|
||||
|
||||
wfmDemod.setVFO(vfo);
|
||||
fmDemod.setVFO(vfo);
|
||||
amDemod.setVFO(vfo);
|
||||
usbDemod.setVFO(vfo);
|
||||
lsbDemod.setVFO(vfo);
|
||||
dsbDemod.setVFO(vfo);
|
||||
rawDemod.setVFO(vfo);
|
||||
cwDemod.setVFO(vfo);
|
||||
|
||||
currentDemod->select();
|
||||
currentDemod->start();
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
void disable() {
|
||||
currentDemod->stop();
|
||||
sigpath::vfoManager.deleteVFO(vfo);
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
bool isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
private:
|
||||
static void menuHandler(void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
|
||||
if (!_this->enabled) { style::beginDisabled(); }
|
||||
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
ImGui::BeginGroup();
|
||||
|
||||
// TODO: Change VFO ref in signal path
|
||||
|
||||
ImGui::Columns(4, CONCAT("RadioModeColumns##_", _this->name), false);
|
||||
if (ImGui::RadioButton(CONCAT("NFM##_", _this->name), _this->demodId == 0) && _this->demodId != 0) {
|
||||
_this->selectDemodById(0);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("WFM##_", _this->name), _this->demodId == 1) && _this->demodId != 1) {
|
||||
_this->selectDemodById(1);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("AM##_", _this->name), _this->demodId == 2) && _this->demodId != 2) {
|
||||
_this->selectDemodById(2);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("DSB##_", _this->name), _this->demodId == 3) && _this->demodId != 3) {
|
||||
_this->selectDemodById(3);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("USB##_", _this->name), _this->demodId == 4) && _this->demodId != 4) {
|
||||
_this->selectDemodById(4);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("CW##_", _this->name), _this->demodId == 5) && _this->demodId != 5) {
|
||||
_this->selectDemodById(5);
|
||||
};
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("LSB##_", _this->name), _this->demodId == 6) && _this->demodId != 6) {
|
||||
_this->selectDemodById(6);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("RAW##_", _this->name), _this->demodId == 7) && _this->demodId != 7) {
|
||||
_this->selectDemodById(7);
|
||||
};
|
||||
ImGui::Columns(1, CONCAT("EndRadioModeColumns##_", _this->name), false);
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
_this->currentDemod->showMenu();
|
||||
|
||||
if (!_this->enabled) { style::endDisabled(); }
|
||||
}
|
||||
|
||||
static void sampleRateChangeHandler(float sampleRate, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
// TODO: If too slow, change all demods here and not when setting
|
||||
_this->audioSampRate = sampleRate;
|
||||
if (_this->currentDemod != NULL) {
|
||||
_this->currentDemod->setAudioSampleRate(_this->audioSampRate);
|
||||
}
|
||||
}
|
||||
|
||||
static void moduleInterfaceHandler(int code, void* in, void* out, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
if (code == RADIO_IFACE_CMD_GET_MODE) {
|
||||
int* _out = (int*)out;
|
||||
*_out = _this->demodId;
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_SET_MODE) {
|
||||
int* _in = (int*)in;
|
||||
if (*_in != _this->demodId) { _this->selectDemodById(*_in); }
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_SET_BANDWIDTH) {
|
||||
float* _in = (float*)in;
|
||||
_this->currentDemod->setBandwidth(*_in, true);
|
||||
_this->currentDemod->saveParameters();
|
||||
}
|
||||
}
|
||||
|
||||
void selectDemod(Demodulator* demod) {
|
||||
if (currentDemod != NULL) { currentDemod->stop(); }
|
||||
currentDemod = demod;
|
||||
currentDemod->setAudioSampleRate(audioSampRate);
|
||||
stream.setInput(currentDemod->getOutput());
|
||||
currentDemod->select();
|
||||
vfo->output->flush();
|
||||
currentDemod->start();
|
||||
}
|
||||
|
||||
void selectDemodById(int id) {
|
||||
demodId = id;
|
||||
if (id == 0) { selectDemod(&fmDemod); }
|
||||
if (id == 1) { selectDemod(&wfmDemod); }
|
||||
if (id == 2) { selectDemod(&amDemod); }
|
||||
if (id == 3) { selectDemod(&dsbDemod); }
|
||||
if (id == 4) { selectDemod(&usbDemod); }
|
||||
if (id == 5) { selectDemod(&cwDemod); }
|
||||
if (id == 6) { selectDemod(&lsbDemod); }
|
||||
if (id == 7) { selectDemod(&rawDemod); }
|
||||
config.acquire();
|
||||
config.conf[name]["selectedDemodId"] = demodId;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
std::string name;
|
||||
bool enabled = true;
|
||||
int demodId = 0;
|
||||
float audioSampRate = 48000;
|
||||
Demodulator* currentDemod = NULL;
|
||||
|
||||
VFOManager::VFO* vfo;
|
||||
|
||||
WFMDemodulator wfmDemod;
|
||||
FMDemodulator fmDemod;
|
||||
AMDemodulator amDemod;
|
||||
USBDemodulator usbDemod;
|
||||
LSBDemodulator lsbDemod;
|
||||
DSBDemodulator dsbDemod;
|
||||
RAWDemodulator rawDemod;
|
||||
CWDemodulator cwDemod;
|
||||
|
||||
dsp::NullSink<dsp::complex_t> ns;
|
||||
|
||||
EventHandler<float> srChangeHandler;
|
||||
SinkManager::Stream stream;
|
||||
|
||||
};
|
||||
|
||||
MOD_EXPORT void _INIT_() {
|
||||
json def = json({});
|
||||
config.setPath(options::opts.root + "/radio_config.json");
|
||||
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
#include <dsp/stream.h>
|
||||
#include <signal_path/vfo_manager.h>
|
||||
|
||||
class Demodulator {
|
||||
public:
|
||||
virtual void start() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual bool isRunning() = 0;
|
||||
virtual void select() = 0;
|
||||
virtual void setVFO(VFOManager::VFO* vfo) = 0;
|
||||
virtual VFOManager::VFO* getVFO() = 0;
|
||||
virtual void setAudioSampleRate(float sampleRate) = 0;
|
||||
virtual float getAudioSampleRate() = 0;
|
||||
virtual void setBandwidth(float bandWidth, bool updateWaterfall = true) = 0;
|
||||
virtual dsp::stream<dsp::stereo_t>* getOutput() = 0;
|
||||
virtual void showMenu() = 0;
|
||||
virtual void saveParameters(bool lock = true) = 0;
|
||||
};
|
@ -3,7 +3,12 @@
|
||||
enum {
|
||||
RADIO_IFACE_CMD_GET_MODE,
|
||||
RADIO_IFACE_CMD_SET_MODE,
|
||||
RADIO_IFACE_CMD_GET_BANDWIDTH,
|
||||
RADIO_IFACE_CMD_SET_BANDWIDTH,
|
||||
RADIO_IFACE_CMD_GET_SQUELCH_ENABLED,
|
||||
RADIO_IFACE_CMD_SET_SQUELCH_ENABLED,
|
||||
RADIO_IFACE_CMD_GET_SQUELCH_LEVEL,
|
||||
RADIO_IFACE_CMD_SET_SQUELCH_LEVEL,
|
||||
};
|
||||
|
||||
enum {
|
||||
|
556
decoder_modules/radio/src/radio_module.h
Normal file
556
decoder_modules/radio/src/radio_module.h
Normal file
@ -0,0 +1,556 @@
|
||||
#pragma once
|
||||
#include <imgui.h>
|
||||
#include <module.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/style.h>
|
||||
#include <signal_path/signal_path.h>
|
||||
#include <config.h>
|
||||
#include <dsp/chain.h>
|
||||
#include <dsp/noise_reduction.h>
|
||||
#include <core.h>
|
||||
#include "radio_interface.h"
|
||||
#include "demod.h"
|
||||
|
||||
ConfigManager config;
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
|
||||
const double DeemphasisModes[] {
|
||||
50e-6,
|
||||
75e-6
|
||||
};
|
||||
|
||||
const char* DeemhasisModesTxt = "50µS\00075µS\000None\000";
|
||||
|
||||
class RadioModule : public ModuleManager::Instance {
|
||||
public:
|
||||
RadioModule(std::string name) {
|
||||
this->name = name;
|
||||
|
||||
// Initialize the config if it doesn't exist
|
||||
bool created = false;
|
||||
config.acquire();
|
||||
if (!config.conf.contains(name)) {
|
||||
config.conf[name]["selectedDemodId"] = 1;
|
||||
created = true;
|
||||
}
|
||||
selectedDemodID = config.conf[name]["selectedDemodId"];
|
||||
config.release(created);
|
||||
|
||||
// Create demodulator instances
|
||||
demods.fill(NULL);
|
||||
demods[RADIO_DEMOD_WFM] = new demod::WFM();
|
||||
demods[RADIO_DEMOD_NFM] = new demod::NFM();
|
||||
demods[RADIO_DEMOD_AM] = new demod::AM();
|
||||
demods[RADIO_DEMOD_USB] = new demod::USB();
|
||||
demods[RADIO_DEMOD_LSB] = new demod::LSB();
|
||||
demods[RADIO_DEMOD_DSB] = new demod::DSB();
|
||||
demods[RADIO_DEMOD_CW] = new demod::CW();
|
||||
demods[RADIO_DEMOD_RAW] = new demod::RAW();
|
||||
|
||||
// Initialize the VFO
|
||||
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 200000, 200000, 50000, 200000, false);
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
|
||||
// Initialize IF DSP chain
|
||||
ifChainOutputChanged.ctx = this;
|
||||
ifChainOutputChanged.handler = ifChainOutputChangeHandler;
|
||||
ifChain.init(vfo->output, &ifChainOutputChanged);
|
||||
|
||||
squelch.block.init(NULL, MIN_SQUELCH);
|
||||
|
||||
ifChain.add(&squelch);
|
||||
|
||||
// Load configuration for and enabled all demodulators
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> _demodOutputChangeHandler;
|
||||
_demodOutputChangeHandler.handler = demodOutputChangeHandler;
|
||||
_demodOutputChangeHandler.ctx = this;
|
||||
for (auto& demod : demods) {
|
||||
if (!demod) { continue; }
|
||||
|
||||
// Default config
|
||||
double bw = demod->getDefaultBandwidth();
|
||||
if (!config.conf[name].contains(demod->getName())) {
|
||||
config.conf[name][demod->getName()]["bandwidth"] = bw;
|
||||
config.conf[name][demod->getName()]["snapInterval"] = demod->getDefaultSnapInterval();
|
||||
config.conf[name][demod->getName()]["squelchLevel"] = MIN_SQUELCH;
|
||||
config.conf[name][demod->getName()]["squelchEnabled"] = false;
|
||||
}
|
||||
bw = std::clamp<double>(bw, demod->getMinBandwidth(), demod->getMaxBandwidth());
|
||||
|
||||
// Initialize
|
||||
demod->init(name, &config, ifChain.getOutput(), bw, _demodOutputChangeHandler, stream.getSampleRate());
|
||||
}
|
||||
|
||||
// Initialize audio DSP chain
|
||||
afChainOutputChanged.ctx = this;
|
||||
afChainOutputChanged.handler = afChainOutputChangeHandler;
|
||||
afChain.init(&dummyAudioStream, &afChainOutputChanged);
|
||||
|
||||
win.init(24000, 24000, 48000);
|
||||
resamp.block.init(NULL, &win, 250000, 48000);
|
||||
deemp.block.init(NULL, 48000, 50e-6);
|
||||
deemp.block.bypass = false;
|
||||
|
||||
afChain.add(&resamp);
|
||||
afChain.add(&deemp);
|
||||
|
||||
// Initialize the sink
|
||||
srChangeHandler.ctx = this;
|
||||
srChangeHandler.handler = sampleRateChangeHandler;
|
||||
stream.init(afChain.getOutput(), &srChangeHandler, audioSampleRate);
|
||||
sigpath::sinkManager.registerStream(name, &stream);
|
||||
|
||||
// Select the demodulator
|
||||
selectDemodByID((DemodID)selectedDemodID);
|
||||
|
||||
// Start IF chain
|
||||
ifChain.start();
|
||||
|
||||
// Start AF chain
|
||||
afChain.start();
|
||||
|
||||
// Start stream, the rest was started when selecting the demodulator
|
||||
stream.start();
|
||||
|
||||
// Register the menu
|
||||
gui::menu.registerEntry(name, menuHandler, this, this);
|
||||
|
||||
// Register the module interface
|
||||
core::modComManager.registerInterface("radio", name, moduleInterfaceHandler, this);
|
||||
}
|
||||
|
||||
~RadioModule() {
|
||||
gui::menu.removeEntry(name);
|
||||
stream.stop();
|
||||
if (enabled) {
|
||||
disable();
|
||||
}
|
||||
sigpath::sinkManager.unregisterStream(name);
|
||||
}
|
||||
|
||||
void postInit() {}
|
||||
|
||||
void enable() {
|
||||
enabled = true;
|
||||
if (!vfo) {
|
||||
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 200000, 200000, 50000, 200000, false);
|
||||
vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
ifChain.setInput(vfo->output);
|
||||
ifChain.start();
|
||||
selectDemodByID((DemodID)selectedDemodID);
|
||||
afChain.start();
|
||||
}
|
||||
|
||||
void disable() {
|
||||
enabled = false;
|
||||
ifChain.stop();
|
||||
if (selectedDemod) { selectedDemod->stop(); }
|
||||
afChain.stop();
|
||||
if (vfo) { sigpath::vfoManager.deleteVFO(vfo); }
|
||||
vfo = NULL;
|
||||
}
|
||||
|
||||
bool isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
std::string name;
|
||||
|
||||
enum DemodID {
|
||||
RADIO_DEMOD_NFM,
|
||||
RADIO_DEMOD_WFM,
|
||||
RADIO_DEMOD_AM,
|
||||
RADIO_DEMOD_DSB,
|
||||
RADIO_DEMOD_USB,
|
||||
RADIO_DEMOD_CW,
|
||||
RADIO_DEMOD_LSB,
|
||||
RADIO_DEMOD_RAW,
|
||||
_RADIO_DEMOD_COUNT,
|
||||
};
|
||||
|
||||
private:
|
||||
static void menuHandler(void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
|
||||
if (!_this->enabled) { style::beginDisabled(); }
|
||||
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
ImGui::BeginGroup();
|
||||
|
||||
ImGui::Columns(4, CONCAT("RadioModeColumns##_", _this->name), false);
|
||||
if (ImGui::RadioButton(CONCAT("NFM##_", _this->name), _this->selectedDemodID == 0) && _this->selectedDemodID != 0) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_NFM);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("WFM##_", _this->name), _this->selectedDemodID == 1) && _this->selectedDemodID != 1) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_WFM);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("AM##_", _this->name), _this->selectedDemodID == 2) && _this->selectedDemodID != 2) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_AM);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("DSB##_", _this->name), _this->selectedDemodID == 3) && _this->selectedDemodID != 3) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_DSB);
|
||||
}
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("USB##_", _this->name), _this->selectedDemodID == 4) && _this->selectedDemodID != 4) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_USB);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("CW##_", _this->name), _this->selectedDemodID == 5) && _this->selectedDemodID != 5) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_CW);
|
||||
};
|
||||
ImGui::NextColumn();
|
||||
if (ImGui::RadioButton(CONCAT("LSB##_", _this->name), _this->selectedDemodID == 6) && _this->selectedDemodID != 6) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_LSB);
|
||||
}
|
||||
if (ImGui::RadioButton(CONCAT("RAW##_", _this->name), _this->selectedDemodID == 7) && _this->selectedDemodID != 7) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_RAW);
|
||||
};
|
||||
ImGui::Columns(1, CONCAT("EndRadioModeColumns##_", _this->name), false);
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
if (!_this->bandwidthLocked) {
|
||||
ImGui::LeftLabel("Bandwidth");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_bw_" + _this->name).c_str(), &_this->bandwidth, 1, 100, "%.0f")) {
|
||||
_this->bandwidth = std::clamp<float>(_this->bandwidth, _this->minBandwidth, _this->maxBandwidth);
|
||||
_this->setBandwidth(_this->bandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
// VFO snap interval
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputInt(("##_radio_snap_" + _this->name).c_str(), &_this->snapInterval, 1, 100)) {
|
||||
if (_this->snapInterval < 1) { _this->snapInterval = 1; }
|
||||
_this->vfo->setSnapInterval(_this->snapInterval);
|
||||
config.acquire();
|
||||
config.conf[_this->name][_this->selectedDemod->getName()]["snapInterval"] = _this->snapInterval;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
// Deemphasis mode
|
||||
if (_this->deempAllowed) {
|
||||
ImGui::LeftLabel("De-emphasis");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::Combo(("##_radio_wfm_deemp_" + _this->name).c_str(), &_this->deempMode, DeemhasisModesTxt)) {
|
||||
_this->setDeemphasisMode(_this->deempMode);
|
||||
}
|
||||
}
|
||||
|
||||
// Squelch
|
||||
if (ImGui::Checkbox(("Squelch##_radio_sqelch_ena_" + _this->name).c_str(), &_this->squelchEnabled)) {
|
||||
_this->setSquelchEnabled(_this->squelchEnabled);
|
||||
}
|
||||
if (!_this->squelchEnabled && _this->enabled) { style::beginDisabled(); }
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_sqelch_lvl_" + _this->name).c_str(), &_this->squelchLevel, _this->MIN_SQUELCH, _this->MAX_SQUELCH, "%.3fdB")) {
|
||||
_this->setSquelchLevel(_this->squelchLevel);
|
||||
}
|
||||
if (!_this->squelchEnabled && _this->enabled) { style::endDisabled(); }
|
||||
|
||||
// Demodulator specific menu
|
||||
_this->selectedDemod->showMenu();
|
||||
|
||||
if (!_this->enabled) { style::endDisabled(); }
|
||||
}
|
||||
|
||||
void selectDemodByID(DemodID id) {
|
||||
demod::Demodulator* demod = demods[id];
|
||||
if (!demod) {
|
||||
spdlog::error("Demodulator {0} not implemented", id);
|
||||
return;
|
||||
}
|
||||
selectedDemodID = id;
|
||||
selectDemod(demod);
|
||||
|
||||
// Save config
|
||||
config.acquire();
|
||||
config.conf[name]["selectedDemodId"] = id;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
void selectDemod(demod::Demodulator* demod) {
|
||||
// Stopcurrently selected demodulator and select new
|
||||
if (selectedDemod) { selectedDemod->stop(); }
|
||||
selectedDemod = demod;
|
||||
|
||||
// Give the demodulator the most recent audio SR
|
||||
selectedDemod->AFSampRateChanged(audioSampleRate);
|
||||
|
||||
// Set the demodulator's input
|
||||
selectedDemod->setInput(ifChain.getOutput());
|
||||
|
||||
// Set AF chain's input
|
||||
afChain.setInput(selectedDemod->getOutput());
|
||||
|
||||
// Load config
|
||||
bandwidth = selectedDemod->getDefaultBandwidth();
|
||||
minBandwidth = selectedDemod->getMinBandwidth();
|
||||
maxBandwidth = selectedDemod->getMaxBandwidth();
|
||||
bandwidthLocked = selectedDemod->getBandwidthLocked();
|
||||
snapInterval = selectedDemod->getDefaultSnapInterval();
|
||||
squelchLevel = MIN_SQUELCH;
|
||||
deempAllowed = selectedDemod->getDeempAllowed();
|
||||
deempMode = DEEMP_MODE_NONE;
|
||||
squelchEnabled = false;
|
||||
postProcEnabled = selectedDemod->getPostProcEnabled();
|
||||
if (config.conf[name][selectedDemod->getName()].contains("snapInterval")) {
|
||||
bandwidth = config.conf[name][selectedDemod->getName()]["bandwidth"];
|
||||
bandwidth = std::clamp<double>(bandwidth, minBandwidth, maxBandwidth);
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("snapInterval")) {
|
||||
snapInterval = config.conf[name][selectedDemod->getName()]["snapInterval"];
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("squelchLevel")) {
|
||||
squelchLevel = config.conf[name][selectedDemod->getName()]["squelchLevel"];
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("squelchEnabled")) {
|
||||
squelchEnabled = config.conf[name][selectedDemod->getName()]["squelchEnabled"];
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("deempMode")) {
|
||||
deempMode = config.conf[name][selectedDemod->getName()]["deempMode"];
|
||||
}
|
||||
deempMode = std::clamp<int>(deempMode, 0, _DEEMP_MODE_COUNT-1);
|
||||
|
||||
// Configure VFO
|
||||
if (vfo) {
|
||||
vfo->setBandwidthLimits(minBandwidth, maxBandwidth, selectedDemod->getBandwidthLocked());
|
||||
vfo->setReference(selectedDemod->getVFOReference());
|
||||
vfo->setSnapInterval(snapInterval);
|
||||
vfo->setSampleRate(selectedDemod->getIFSampleRate(), bandwidth);
|
||||
}
|
||||
|
||||
// Configure IF chain
|
||||
squelch.block.setLevel(squelchLevel);
|
||||
setSquelchEnabled(squelchEnabled);
|
||||
|
||||
// Configure AF chain
|
||||
if (postProcEnabled) {
|
||||
// Configure resampler
|
||||
afChain.stop();
|
||||
resamp.block.setInSampleRate(selectedDemod->getAFSampleRate());
|
||||
setAudioSampleRate(audioSampleRate);
|
||||
afChain.enable(&resamp);
|
||||
|
||||
// Configure deemphasis
|
||||
setDeemphasisMode(deempMode);
|
||||
}
|
||||
else {
|
||||
// Disable everyting if post processing is disabled
|
||||
afChain.disableAll();
|
||||
}
|
||||
|
||||
// Start new demodulator
|
||||
selectedDemod->start();
|
||||
}
|
||||
|
||||
|
||||
void setBandwidth(double bw) {
|
||||
bw = std::clamp<double>(bw, minBandwidth, maxBandwidth);
|
||||
bandwidth = bw;
|
||||
if (!selectedDemod) { return; }
|
||||
float audioBW = std::min<float>(selectedDemod->getMaxAFBandwidth(), selectedDemod->getAFBandwidth(bandwidth));
|
||||
audioBW = std::min<float>(audioBW, audioSampleRate / 2.0);
|
||||
vfo->setBandwidth(bandwidth);
|
||||
selectedDemod->setBandwidth(bandwidth);
|
||||
|
||||
// Only bother with setting the resampling setting if we're actually post processing and dynamic bw is enabled
|
||||
if (selectedDemod->getDynamicAFBandwidth() && postProcEnabled) {
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.block.updateWindow(&win);
|
||||
}
|
||||
|
||||
config.acquire();
|
||||
config.conf[name][selectedDemod->getName()]["bandwidth"] = bandwidth;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
void setAudioSampleRate(double sr) {
|
||||
audioSampleRate = sr;
|
||||
if (!selectedDemod) { return; }
|
||||
selectedDemod->AFSampRateChanged(audioSampleRate);
|
||||
if (!postProcEnabled) {
|
||||
// If postproc is disabled, IF SR = AF SR
|
||||
minBandwidth = selectedDemod->getMinBandwidth();
|
||||
maxBandwidth = selectedDemod->getMaxBandwidth();
|
||||
bandwidth = selectedDemod->getIFSampleRate();
|
||||
vfo->setBandwidthLimits(minBandwidth, maxBandwidth, selectedDemod->getBandwidthLocked());
|
||||
vfo->setSampleRate(selectedDemod->getIFSampleRate(), bandwidth);
|
||||
return;
|
||||
}
|
||||
float audioBW = std::min<float>(selectedDemod->getMaxAFBandwidth(), selectedDemod->getAFBandwidth(bandwidth));
|
||||
audioBW = std::min<float>(audioBW, audioSampleRate / 2.0);
|
||||
|
||||
afChain.stop();
|
||||
|
||||
// Configure resampler
|
||||
resamp.block.setOutSampleRate(audioSampleRate);
|
||||
win.setSampleRate(selectedDemod->getAFSampleRate() * resamp.block.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.block.updateWindow(&win);
|
||||
|
||||
// Configure deemphasis sample rate
|
||||
deemp.block.setSampleRate(audioSampleRate);
|
||||
|
||||
afChain.start();
|
||||
}
|
||||
|
||||
void setDeemphasisMode(int mode) {
|
||||
deempMode = std::clamp<int>(mode, 0, _DEEMP_MODE_COUNT-1);
|
||||
if (!postProcEnabled || !selectedDemod) { return; }
|
||||
bool deempEnabled = (deempMode != DEEMP_MODE_NONE);
|
||||
if (deempEnabled) {
|
||||
deemp.block.setTau(DeemphasisModes[deempMode]);
|
||||
}
|
||||
afChain.setState(&deemp, deempEnabled);
|
||||
|
||||
// Save config
|
||||
config.acquire();
|
||||
config.conf[name][selectedDemod->getName()]["deempMode"] = deempMode;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
void setSquelchEnabled(bool enable) {
|
||||
squelchEnabled = enable;
|
||||
if (!selectedDemod) { return; }
|
||||
ifChain.setState(&squelch, squelchEnabled);
|
||||
|
||||
// Save config
|
||||
config.acquire();
|
||||
config.conf[name][selectedDemod->getName()]["squelchEnabled"] = squelchEnabled;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
void setSquelchLevel(float level) {
|
||||
squelchLevel = std::clamp<float>(level, MIN_SQUELCH, MAX_SQUELCH);
|
||||
squelch.block.setLevel(squelchLevel);
|
||||
|
||||
// Save config
|
||||
config.acquire();
|
||||
config.conf[name][selectedDemod->getName()]["squelchLevel"] = squelchLevel;
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->setBandwidth(newBw);
|
||||
}
|
||||
|
||||
static void sampleRateChangeHandler(float sampleRate, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->setAudioSampleRate(sampleRate);
|
||||
}
|
||||
|
||||
static void demodOutputChangeHandler(dsp::stream<dsp::stereo_t>* output, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->afChain.setInput(output);
|
||||
}
|
||||
|
||||
static void ifChainOutputChangeHandler(dsp::stream<dsp::complex_t>* output, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
if (!_this->selectedDemod) { return; }
|
||||
_this->selectedDemod->setInput(output);
|
||||
}
|
||||
|
||||
static void afChainOutputChangeHandler(dsp::stream<dsp::stereo_t>* output, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->stream.setInput(output);
|
||||
}
|
||||
|
||||
static void moduleInterfaceHandler(int code, void* in, void* out, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
if (!_this->enabled || !_this->selectedDemod) { return; }
|
||||
|
||||
// Execute commands
|
||||
if (code == RADIO_IFACE_CMD_GET_MODE && out) {
|
||||
int* _out = (int*)out;
|
||||
*_out = _this->selectedDemodID;
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_SET_MODE && in) {
|
||||
int* _in = (int*)in;
|
||||
_this->selectDemodByID((DemodID)*_in);
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_GET_BANDWIDTH && out) {
|
||||
float* _out = (float*)out;
|
||||
*_out = _this->bandwidth;
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_SET_BANDWIDTH && in) {
|
||||
float* _in = (float*)in;
|
||||
if (_this->bandwidthLocked) { return; }
|
||||
_this->setBandwidth(*_in);
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_GET_SQUELCH_ENABLED && out) {
|
||||
bool* _out = (bool*)out;
|
||||
*_out = _this->squelchEnabled;
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_SET_SQUELCH_ENABLED && in) {
|
||||
bool* _in = (bool*)in;
|
||||
_this->setSquelchEnabled(*_in);
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_GET_SQUELCH_LEVEL && out) {
|
||||
float* _out = (float*)out;
|
||||
*_out = _this->squelchLevel;
|
||||
}
|
||||
else if (code == RADIO_IFACE_CMD_SET_SQUELCH_LEVEL && in) {
|
||||
float* _in = (float*)in;
|
||||
_this->setSquelchLevel(*_in);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
// Success
|
||||
return;
|
||||
}
|
||||
|
||||
// Handlers
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
EventHandler<float> srChangeHandler;
|
||||
EventHandler<dsp::stream<dsp::complex_t>*> ifChainOutputChanged;
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> afChainOutputChanged;
|
||||
|
||||
VFOManager::VFO* vfo = NULL;
|
||||
|
||||
// IF chain
|
||||
dsp::Chain<dsp::complex_t> ifChain;
|
||||
dsp::ChainLink<dsp::Squelch, dsp::complex_t> squelch;
|
||||
|
||||
// Audio chain
|
||||
dsp::stream<dsp::stereo_t> dummyAudioStream;
|
||||
dsp::Chain<dsp::stereo_t> afChain;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::ChainLink<dsp::PolyphaseResampler<dsp::stereo_t>, dsp::stereo_t> resamp;
|
||||
dsp::ChainLink<dsp::BFMDeemp, dsp::stereo_t> deemp;
|
||||
|
||||
SinkManager::Stream stream;
|
||||
|
||||
std::array<demod::Demodulator*, _RADIO_DEMOD_COUNT> demods;
|
||||
demod::Demodulator* selectedDemod = NULL;
|
||||
|
||||
double audioSampleRate = 48000.0;
|
||||
float minBandwidth;
|
||||
float maxBandwidth;
|
||||
float bandwidth;
|
||||
bool bandwidthLocked;
|
||||
int snapInterval;
|
||||
bool squelchEnabled = false;
|
||||
float squelchLevel;
|
||||
int selectedDemodID = 1;
|
||||
int deempMode = DEEMP_MODE_NONE;
|
||||
bool deempAllowed;
|
||||
bool postProcEnabled;
|
||||
|
||||
const double MIN_SQUELCH = -100.0;
|
||||
const double MAX_SQUELCH = 0.0;
|
||||
|
||||
bool enabled = true;
|
||||
|
||||
};
|
@ -1,144 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/conversion.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class RAWDemodulator : public Demodulator {
|
||||
public:
|
||||
RAWDemodulator() {}
|
||||
RAWDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("RAW")) {
|
||||
_config->conf[prefix]["RAW"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["RAW"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["RAW"];
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["RAW"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["RAW"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(audioSampRate, audioSampRate);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_CENTER);
|
||||
_vfo->setBandwidthLimits(0, 0, true);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
audioSampRate = sampleRate;
|
||||
if (running) {
|
||||
_vfo->setSampleRate(audioSampRate, audioSampRate);
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return (dsp::stream<dsp::stereo_t>*)&squelch.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_raw_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["RAW"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_raw_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["RAW"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
// TODO: Allow selection of the bandwidth
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["RAW"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["RAW"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 10000;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 12500;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
};
|
@ -1,220 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class USBDemodulator : public Demodulator {
|
||||
public:
|
||||
USBDemodulator() {}
|
||||
USBDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("USB")) {
|
||||
_config->conf[prefix]["USB"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["USB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["USB"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
json conf = _config->conf[prefix]["USB"];
|
||||
if (conf.contains("bandwidth")) { bw = conf["bandwidth"]; }
|
||||
if (conf.contains("snapInterval")) { snapInterval = conf["snapInterval"]; }
|
||||
if (conf.contains("squelchLevel")) { squelchLevel = conf["squelchLevel"]; }
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["USB"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["USB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["USB"]["squelchLevel"] = squelchLevel;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
demod.init(&squelch.out, bbSampRate, bw, dsp::SSBDemod::MODE_USB);
|
||||
|
||||
agc.init(&demod.out, 20.0f, bbSampRate);
|
||||
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
resamp.init(&agc.out, &win, bbSampRate, audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
m2s.init(&resamp.out);
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
demod.start();
|
||||
agc.start();
|
||||
resamp.start();
|
||||
m2s.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
demod.stop();
|
||||
agc.stop();
|
||||
resamp.stop();
|
||||
m2s.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_LOWER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &m2s.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_usb_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["USB"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_usb_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["USB"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_usb_squelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["USB"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
USBDemodulator* _this = (USBDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["USB"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
demod.setBandWidth(bw);
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, bw);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["USB"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["USB"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["USB"]["squelchLevel"] = squelchLevel;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
const float bwMax = 12000;
|
||||
const float bwMin = 500;
|
||||
const float bbSampRate = 24000;
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 100;
|
||||
float audioSampRate = 48000;
|
||||
float bw = 3000;
|
||||
bool running = false;
|
||||
float squelchLevel = -100.0f;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
dsp::SSBDemod demod;
|
||||
dsp::AGC agc;
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<float> resamp;
|
||||
dsp::MonoToStereo m2s;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
@ -1,295 +0,0 @@
|
||||
#pragma once
|
||||
#include <radio_demod.h>
|
||||
#include <dsp/demodulator.h>
|
||||
#include <dsp/resampling.h>
|
||||
#include <dsp/filter.h>
|
||||
#include <dsp/audio.h>
|
||||
#include <string>
|
||||
#include <config.h>
|
||||
#include <imgui.h>
|
||||
|
||||
|
||||
class WFMDemodulator : public Demodulator {
|
||||
public:
|
||||
WFMDemodulator() {}
|
||||
WFMDemodulator(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
init(prefix, vfo, audioSampleRate, bandWidth, config);
|
||||
}
|
||||
|
||||
void init(std::string prefix, VFOManager::VFO* vfo, float audioSampleRate, float bandWidth, ConfigManager* config) {
|
||||
uiPrefix = prefix;
|
||||
_vfo = vfo;
|
||||
audioSampRate = audioSampleRate;
|
||||
bw = bandWidth;
|
||||
_config = config;
|
||||
|
||||
_config->acquire();
|
||||
if(_config->conf.contains(prefix)) {
|
||||
if(!_config->conf[prefix].contains("WFM")) {
|
||||
_config->conf[prefix]["WFM"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["WFM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["WFM"]["deempMode"] = deempId;
|
||||
_config->conf[prefix]["WFM"]["squelchLevel"] = squelchLevel;
|
||||
_config->conf[prefix]["WFM"]["stereo"] = false;
|
||||
}
|
||||
|
||||
// Correct for new settings
|
||||
if (!config->conf[prefix]["WFM"].contains("stereo")) { _config->conf[prefix]["WFM"]["stereo"] = false;}
|
||||
|
||||
json conf = _config->conf[prefix]["WFM"];
|
||||
bw = conf["bandwidth"];
|
||||
snapInterval = conf["snapInterval"];
|
||||
deempId = conf["deempMode"];
|
||||
squelchLevel = conf["squelchLevel"];
|
||||
stereo = conf["stereo"];
|
||||
}
|
||||
else {
|
||||
_config->conf[prefix]["WFM"]["bandwidth"] = bw;
|
||||
_config->conf[prefix]["WFM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[prefix]["WFM"]["deempMode"] = deempId;
|
||||
_config->conf[prefix]["WFM"]["squelchLevel"] = squelchLevel;
|
||||
_config->conf[prefix]["WFM"]["stereo"] = false;
|
||||
}
|
||||
_config->release(true);
|
||||
|
||||
squelch.init(_vfo->output, squelchLevel);
|
||||
|
||||
demod.init(&squelch.out, bbSampRate, bw / 2.0f);
|
||||
demodStereo.init(&squelch.out, bbSampRate, bw / 2.0f);
|
||||
|
||||
float audioBW = std::min<float>(audioSampleRate / 2.0f, 16000.0f);
|
||||
win.init(audioBW, audioBW, bbSampRate);
|
||||
if (stereo) {
|
||||
resamp.init(demodStereo.out, &win, bbSampRate, audioSampRate);
|
||||
}
|
||||
else {
|
||||
resamp.init(&demod.out, &win, bbSampRate, audioSampRate);
|
||||
}
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
resamp.updateWindow(&win);
|
||||
|
||||
deemp.init(&resamp.out, audioSampRate, tau);
|
||||
|
||||
if (deempId == 2) { deemp.bypass = true; }
|
||||
|
||||
onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
|
||||
onUserChangedBandwidthHandler.ctx = this;
|
||||
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
void start() {
|
||||
squelch.start();
|
||||
if (stereo) {
|
||||
demodStereo.start();
|
||||
}
|
||||
else {
|
||||
demod.start();
|
||||
}
|
||||
resamp.start();
|
||||
deemp.start();
|
||||
running = true;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
squelch.stop();
|
||||
if (stereo) {
|
||||
demodStereo.stop();
|
||||
}
|
||||
else {
|
||||
demod.stop();
|
||||
}
|
||||
resamp.stop();
|
||||
deemp.stop();
|
||||
running = false;
|
||||
}
|
||||
|
||||
bool isRunning() {
|
||||
return running;
|
||||
}
|
||||
|
||||
void select() {
|
||||
_vfo->setSampleRate(bbSampRate, bw);
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
_vfo->setReference(ImGui::WaterfallVFO::REF_CENTER);
|
||||
_vfo->setBandwidthLimits(bwMin, bwMax, false);
|
||||
}
|
||||
|
||||
void setVFO(VFOManager::VFO* vfo) {
|
||||
_vfo = vfo;
|
||||
squelch.setInput(_vfo->output);
|
||||
_vfo->wtfVFO->onUserChangedBandwidth.bindHandler(&onUserChangedBandwidthHandler);
|
||||
}
|
||||
|
||||
VFOManager::VFO* getVFO() {
|
||||
return _vfo;
|
||||
}
|
||||
|
||||
void setAudioSampleRate(float sampleRate) {
|
||||
if (running) {
|
||||
resamp.stop();
|
||||
deemp.stop();
|
||||
}
|
||||
audioSampRate = sampleRate;
|
||||
float audioBW = std::min<float>(audioSampRate / 2.0f, 16000.0f);
|
||||
resamp.setOutSampleRate(audioSampRate);
|
||||
win.setSampleRate(bbSampRate * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
deemp.setSampleRate(audioSampRate);
|
||||
if (running) {
|
||||
resamp.start();
|
||||
deemp.start();
|
||||
}
|
||||
}
|
||||
|
||||
float getAudioSampleRate() {
|
||||
return audioSampRate;
|
||||
}
|
||||
|
||||
dsp::stream<dsp::stereo_t>* getOutput() {
|
||||
return &deemp.out;
|
||||
}
|
||||
|
||||
void showMenu() {
|
||||
float menuWidth = ImGui::GetContentRegionAvailWidth();
|
||||
|
||||
ImGui::SetNextItemWidth(menuWidth);
|
||||
if (ImGui::InputFloat(("##_radio_wfm_bw_" + uiPrefix).c_str(), &bw, 1, 100, "%.0f", 0)) {
|
||||
bw = std::clamp<float>(bw, bwMin, bwMax);
|
||||
setBandwidth(bw);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["WFM"]["bandwidth"] = bw;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::InputFloat(("##_radio_wfm_snap_" + uiPrefix).c_str(), &snapInterval, 1, 100, "%.0f", 0)) {
|
||||
if (snapInterval < 1) { snapInterval = 1; }
|
||||
setSnapInterval(snapInterval);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
|
||||
ImGui::LeftLabel("De-emphasis");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::Combo(("##_radio_wfm_deemp_" + uiPrefix).c_str(), &deempId, deempModes)) {
|
||||
setDeempIndex(deempId);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["WFM"]["deempMode"] = deempId;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_wfm_sqelch_" + uiPrefix).c_str(), &squelchLevel, -100.0f, 0.0f, "%.3fdB")) {
|
||||
squelch.setLevel(squelchLevel);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel;
|
||||
_config->release(true);
|
||||
}
|
||||
|
||||
if (ImGui::Checkbox(("Stereo##_radio_wfm_stereo_" + uiPrefix).c_str(), &stereo)) {
|
||||
setStereo(stereo);
|
||||
_config->acquire();
|
||||
_config->conf[uiPrefix]["WFM"]["stereo"] = stereo;
|
||||
_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
WFMDemodulator* _this = (WFMDemodulator*)ctx;
|
||||
if (_this->running) {
|
||||
_this->bw = newBw;
|
||||
_this->setBandwidth(_this->bw, false);
|
||||
_this->_config->acquire();
|
||||
_this->_config->conf[_this->uiPrefix]["WFM"]["bandwidth"] = _this->bw;
|
||||
_this->_config->release(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setDeempIndex(int id) {
|
||||
if (id >= 2 || id < 0) {
|
||||
deemp.bypass = true;
|
||||
return;
|
||||
}
|
||||
deemp.setTau(deempVals[id]);
|
||||
deemp.bypass = false;
|
||||
}
|
||||
|
||||
void setSnapInterval(float snapInt) {
|
||||
snapInterval = snapInt;
|
||||
_vfo->setSnapInterval(snapInterval);
|
||||
}
|
||||
|
||||
void setBandwidth(float bandWidth, bool updateWaterfall = true) {
|
||||
bandWidth = std::clamp<float>(bandWidth, bwMin, bwMax);
|
||||
bw = bandWidth;
|
||||
_vfo->setBandwidth(bw, updateWaterfall);
|
||||
demod.setDeviation(bw / 2.0f);
|
||||
demodStereo.setDeviation(bw / 2.0f);
|
||||
}
|
||||
|
||||
void setStereo(bool enabled) {
|
||||
if (running) {
|
||||
demod.stop();
|
||||
demodStereo.stop();
|
||||
}
|
||||
|
||||
if (enabled) {
|
||||
resamp.setInput(demodStereo.out);
|
||||
if (running) { demodStereo.start(); }
|
||||
}
|
||||
else {
|
||||
resamp.setInput(&demod.out);
|
||||
if (running) { demod.start(); }
|
||||
}
|
||||
}
|
||||
|
||||
void saveParameters(bool lock = true) {
|
||||
if (lock) { _config->acquire(); }
|
||||
_config->conf[uiPrefix]["WFM"]["bandwidth"] = bw;
|
||||
_config->conf[uiPrefix]["WFM"]["snapInterval"] = snapInterval;
|
||||
_config->conf[uiPrefix]["WFM"]["deempMode"] = deempId;
|
||||
_config->conf[uiPrefix]["WFM"]["squelchLevel"] = squelchLevel;
|
||||
_config->conf[uiPrefix]["WFM"]["stereo"] = stereo;
|
||||
if (lock) { _config->release(true); }
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
const float bwMax = 250000;
|
||||
const float bwMin = 50000;
|
||||
const float bbSampRate = 250000;
|
||||
const char* deempModes = "50µs\00075µs\000none\000";
|
||||
const float deempVals[2] = { 50e-6, 75e-6 };
|
||||
|
||||
std::string uiPrefix;
|
||||
float snapInterval = 100000;
|
||||
float audioSampRate = 48000;
|
||||
float squelchLevel = -100.0f;
|
||||
float bw = 200000;
|
||||
bool stereo = false;
|
||||
int deempId = 0;
|
||||
float tau = 50e-6;
|
||||
bool running = false;
|
||||
|
||||
VFOManager::VFO* _vfo;
|
||||
dsp::Squelch squelch;
|
||||
|
||||
dsp::FMDemod demod;
|
||||
dsp::StereoFMDemod demodStereo;
|
||||
|
||||
dsp::filter_window::BlackmanWindow win;
|
||||
dsp::PolyphaseResampler<dsp::stereo_t> resamp;
|
||||
dsp::BFMDeemp deemp;
|
||||
|
||||
ConfigManager* _config;
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
|
||||
};
|
Reference in New Issue
Block a user