More work on the new radio
This commit is contained in:
@@ -10,6 +10,13 @@ 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;
|
||||
#include "demod.h"
|
||||
|
||||
@@ -29,6 +36,12 @@ public:
|
||||
// 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();
|
||||
|
||||
// Initialize the VFO
|
||||
vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 200000, 200000, 50000, 200000, false);
|
||||
@@ -43,6 +56,9 @@ public:
|
||||
sigpath::sinkManager.registerStream(name, &stream);
|
||||
|
||||
// Load configuration for all demodulators
|
||||
EventHandler<dsp::stream<dsp::stereo_t>*> _demodOutputChangeHandler;
|
||||
_demodOutputChangeHandler.handler = demodOutputChangeHandler;
|
||||
_demodOutputChangeHandler.ctx = this;
|
||||
for (auto& demod : demods) {
|
||||
if (!demod) { continue; }
|
||||
|
||||
@@ -52,11 +68,13 @@ public:
|
||||
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;
|
||||
config.conf[name][demod->getName()]["deempMode"] = demod->getDefaultDeemphasisMode();
|
||||
}
|
||||
bw = std::clamp<double>(bw, demod->getMinBandwidth(), demod->getMaxBandwidth());
|
||||
|
||||
// Initialize
|
||||
demod->init(name, &config, &squelch.out, bw);
|
||||
demod->init(name, &config, &squelch.out, bw, _demodOutputChangeHandler);
|
||||
}
|
||||
|
||||
// Initialize DSP
|
||||
@@ -119,8 +137,6 @@ private:
|
||||
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->selectedDemodID == 0) && _this->selectedDemodID != 0) {
|
||||
_this->selectDemodByID(RADIO_DEMOD_NFM);
|
||||
@@ -153,16 +169,57 @@ private:
|
||||
|
||||
ImGui::EndGroup();
|
||||
|
||||
_this->selectedDemod->showMenu();
|
||||
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);
|
||||
config.acquire();
|
||||
config.conf[_this->name][_this->selectedDemod->getName()]["bandwidth"] = _this->bandwidth;
|
||||
config.release(true);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::LeftLabel("Squelch");
|
||||
ImGui::LeftLabel("Snap Interval");
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::SliderFloat(("##_radio_sqelch_" + _this->name).c_str(), &_this->squelchLevel, _this->MIN_SQUELCH, _this->MAX_SQUELCH, "%.3fdB")) {
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
config.acquire();
|
||||
config.conf[_this->name][_this->selectedDemod->getName()]["deempMode"] = _this->deempMode;
|
||||
config.release(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Checkbox(("Squelch##_radio_sqelch_ena_" + _this->name).c_str(), &_this->squelchEnabled)) {
|
||||
_this->setSquelchEnabled(_this->squelchEnabled);
|
||||
config.acquire();
|
||||
config.conf[_this->name][_this->selectedDemod->getName()]["squelchEnabled"] = _this->squelchEnabled;
|
||||
config.release(true);
|
||||
}
|
||||
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->squelch.setLevel(_this->squelchLevel);
|
||||
config.acquire();
|
||||
config.conf[_this->name][_this->selectedDemod->getName()]["squelchLevel"] = _this->squelchLevel;
|
||||
config.release(true);
|
||||
}
|
||||
if (!_this->squelchEnabled && _this->enabled) { style::endDisabled(); }
|
||||
|
||||
_this->selectedDemod->showMenu();
|
||||
|
||||
if (!_this->enabled) { style::endDisabled(); }
|
||||
}
|
||||
@@ -184,10 +241,13 @@ private:
|
||||
|
||||
// Load config
|
||||
bandwidth = selectedDemod->getDefaultBandwidth();
|
||||
double minBandwidth = selectedDemod->getMinBandwidth();
|
||||
double maxBandwidth = selectedDemod->getMaxBandwidth();
|
||||
minBandwidth = selectedDemod->getMinBandwidth();
|
||||
maxBandwidth = selectedDemod->getMaxBandwidth();
|
||||
bandwidthLocked = selectedDemod->getBandwidthLocked();
|
||||
snapInterval = selectedDemod->getDefaultSnapInterval();
|
||||
squelchLevel = MIN_SQUELCH;
|
||||
deempMode = DEEMP_MODE_NONE;
|
||||
squelchEnabled = false;
|
||||
if (config.conf[name][selectedDemod->getName()].contains("snapInterval")) {
|
||||
bandwidth = config.conf[name][selectedDemod->getName()]["bandwidth"];
|
||||
bandwidth = std::clamp<double>(bandwidth, minBandwidth, maxBandwidth);
|
||||
@@ -198,6 +258,13 @@ private:
|
||||
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) {
|
||||
@@ -209,6 +276,7 @@ private:
|
||||
|
||||
// Configure squelch
|
||||
squelch.setLevel(squelchLevel);
|
||||
setSquelchEnabled(squelchEnabled);
|
||||
|
||||
// Configure resampler
|
||||
resamp.stop();
|
||||
@@ -217,6 +285,15 @@ private:
|
||||
setAudioSampleRate(audioSampleRate);
|
||||
resamp.start();
|
||||
|
||||
// Configure deemphasis
|
||||
deempAllowed = selectedDemod->getDeempAllowed();
|
||||
if (deempAllowed) {
|
||||
setDeemphasisMode(deempMode);
|
||||
}
|
||||
else {
|
||||
setDeemphasisMode(DEEMP_MODE_NONE);
|
||||
}
|
||||
|
||||
// Start new demodulator
|
||||
selectedDemod->start();
|
||||
}
|
||||
@@ -224,7 +301,14 @@ private:
|
||||
void setBandwidth(double bw) {
|
||||
bandwidth = bw;
|
||||
if (!selectedDemod) { return; }
|
||||
float audioBW = std::min<float>(selectedDemod->getMaxAFBandwidth(), selectedDemod->getAFBandwidth(bandwidth));
|
||||
vfo->setBandwidth(bandwidth);
|
||||
selectedDemod->setBandwidth(bandwidth);
|
||||
if (selectedDemod->getDynamicAFBandwidth()) {
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
}
|
||||
config.acquire();
|
||||
config.conf[name][selectedDemod->getName()]["bandwidth"] = bandwidth;
|
||||
config.release(true);
|
||||
@@ -233,14 +317,45 @@ private:
|
||||
void setAudioSampleRate(double sr) {
|
||||
audioSampleRate = sr;
|
||||
if (!selectedDemod) { return; }
|
||||
float audioBW = std::min<float>(selectedDemod->getMaxAFBandwidth(), audioSampleRate / 2.0f);
|
||||
float audioBW = std::min<float>(selectedDemod->getMaxAFBandwidth(), selectedDemod->getAFBandwidth(bandwidth));
|
||||
resamp.stop();
|
||||
deemp.stop();
|
||||
deemp.setSampleRate(audioSampleRate);
|
||||
resamp.setOutSampleRate(audioSampleRate);
|
||||
win.setSampleRate(audioSampleRate * resamp.getInterpolation());
|
||||
win.setSampleRate(selectedDemod->getAFSampleRate() * resamp.getInterpolation());
|
||||
win.setCutoff(audioBW);
|
||||
win.setTransWidth(audioBW);
|
||||
resamp.updateWindow(&win);
|
||||
resamp.start();
|
||||
if (deempMode != DEEMP_MODE_NONE) { deemp.start(); }
|
||||
}
|
||||
|
||||
void setDeemphasisMode(int mode) {
|
||||
deempMode = mode;
|
||||
if (mode != DEEMP_MODE_NONE) {
|
||||
// TODO: Investigate why not stopping the deemp here causes the DSP to stall
|
||||
deemp.stop();
|
||||
stream.setInput(&deemp.out);
|
||||
deemp.setTau(DeemphasisModes[deempMode]);
|
||||
deemp.start();
|
||||
}
|
||||
else {
|
||||
deemp.stop();
|
||||
stream.setInput(&resamp.out);
|
||||
}
|
||||
}
|
||||
|
||||
void setSquelchEnabled(bool enable) {
|
||||
squelchEnabled = enable;
|
||||
if (!selectedDemod) { return; }
|
||||
if (squelchEnabled) {
|
||||
selectedDemod->setInput(&squelch.out);
|
||||
squelch.start();
|
||||
}
|
||||
else {
|
||||
squelch.stop();
|
||||
selectedDemod->setInput(vfo->output);
|
||||
}
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
@@ -252,6 +367,11 @@ private:
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->setAudioSampleRate(sampleRate);
|
||||
}
|
||||
|
||||
static void demodOutputChangeHandler(dsp::stream<dsp::stereo_t>* output, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->resamp.setInput(output);
|
||||
}
|
||||
|
||||
EventHandler<double> onUserChangedBandwidthHandler;
|
||||
VFOManager::VFO* vfo;
|
||||
@@ -268,10 +388,16 @@ private:
|
||||
demod::Demodulator* selectedDemod = NULL;
|
||||
|
||||
double audioSampleRate = 48000.0;
|
||||
double bandwidth;
|
||||
double snapInterval;
|
||||
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;
|
||||
|
||||
const double MIN_SQUELCH = -100.0;
|
||||
const double MAX_SQUELCH = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user