Switch old radio module to new radio module

This commit is contained in:
AlexandreRouma
2021-12-07 23:56:11 +01:00
parent 355a6352da
commit 1594051a5d
25 changed files with 102 additions and 2072 deletions

View 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;
};
}

View 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;
};
}

View 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;
};
}

View 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;
};
}

View 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;
};
}

View 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;
};
}

View 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;
};
}

View 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;
};
}