diff --git a/decoder_modules/radio/src/demod.h b/decoder_modules/radio/src/demod.h index 9cd690a5..1f456040 100644 --- a/decoder_modules/radio/src/demod.h +++ b/decoder_modules/radio/src/demod.h @@ -24,7 +24,7 @@ namespace demod { class Demodulator { public: virtual ~Demodulator() {} - virtual void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) = 0; + virtual void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) = 0; virtual void start() = 0; virtual void stop() = 0; virtual void showMenu() = 0; diff --git a/decoder_modules/radio/src/demodulators/am.h b/decoder_modules/radio/src/demodulators/am.h index d682c36a..564a0cf0 100644 --- a/decoder_modules/radio/src/demodulators/am.h +++ b/decoder_modules/radio/src/demodulators/am.h @@ -8,17 +8,16 @@ namespace demod { public: AM() {} - AM(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + AM(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~AM() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; - this->outputChangeHandler = outputChangeHandler; // Define structure demod.init(input); @@ -77,6 +76,5 @@ namespace demod { dsp::MonoToStereo m2s; std::string name; - EventHandler*> outputChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/cw.h b/decoder_modules/radio/src/demodulators/cw.h index b1a59193..999c73cb 100644 --- a/decoder_modules/radio/src/demodulators/cw.h +++ b/decoder_modules/radio/src/demodulators/cw.h @@ -8,18 +8,19 @@ namespace demod { public: CW() {} - CW(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + CW(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~CW() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; this->_config = config; - this->outputChangeHandler = outputChangeHandler; + this->_bandwidth = bandwidth; + this->afbwChangeHandler = afbwChangeHandler; // Load config config->acquire(); @@ -55,13 +56,14 @@ namespace demod { if (ImGui::InputInt(("Stereo##_radio_cw_tone_" + name).c_str(), &tone, 10, 100)) { tone = std::clamp(tone, 250, 1250); xlator.setFrequency(tone); + afbwChangeHandler.handler(getAFBandwidth(_bandwidth), afbwChangeHandler.ctx); _config->acquire(); _config->conf[name][getName()]["tone"] = tone; _config->release(true); } } - void setBandwidth(double bandwidth) {} + void setBandwidth(double bandwidth) { _bandwidth = bandwidth; } void setInput(dsp::stream* input) { xlator.setInput(input); @@ -84,7 +86,7 @@ namespace demod { bool getDeempAllowed() { return false; } bool getPostProcEnabled() { return true; } int getDefaultDeemphasisMode() { return DEEMP_MODE_NONE; } - double getAFBandwidth(double bandwidth) { return (bandwidth / 2.0) + 1000.0; } + double getAFBandwidth(double bandwidth) { return (bandwidth / 2.0) + (float)tone; } bool getDynamicAFBandwidth() { return true; } bool getFMIFNRAllowed() { return false; } bool getNBAllowed() { return false; } @@ -98,8 +100,10 @@ namespace demod { dsp::MonoToStereo m2s; std::string name; - EventHandler*> outputChangeHandler; int tone = 800; + double _bandwidth; + + EventHandler afbwChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/dsb.h b/decoder_modules/radio/src/demodulators/dsb.h index 1e10faa5..79d574cf 100644 --- a/decoder_modules/radio/src/demodulators/dsb.h +++ b/decoder_modules/radio/src/demodulators/dsb.h @@ -8,17 +8,16 @@ namespace demod { public: DSB() {} - DSB(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + DSB(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~DSB() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; - this->outputChangeHandler = outputChangeHandler; // Define structure demod.init(input, getIFSampleRate(), bandwidth, dsp::SSBDemod::MODE_DSB); @@ -79,6 +78,5 @@ namespace demod { dsp::MonoToStereo m2s; std::string name; - EventHandler*> outputChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/lsb.h b/decoder_modules/radio/src/demodulators/lsb.h index 1cf26bd1..07a4c505 100644 --- a/decoder_modules/radio/src/demodulators/lsb.h +++ b/decoder_modules/radio/src/demodulators/lsb.h @@ -8,17 +8,16 @@ namespace demod { public: LSB() {} - LSB(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + LSB(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~LSB() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; - this->outputChangeHandler = outputChangeHandler; // Define structure demod.init(input, getIFSampleRate(), bandwidth, dsp::SSBDemod::MODE_LSB); @@ -79,6 +78,5 @@ namespace demod { dsp::MonoToStereo m2s; std::string name; - EventHandler*> outputChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/nfm.h b/decoder_modules/radio/src/demodulators/nfm.h index f4c200d2..898917ed 100644 --- a/decoder_modules/radio/src/demodulators/nfm.h +++ b/decoder_modules/radio/src/demodulators/nfm.h @@ -8,17 +8,16 @@ namespace demod { public: NFM() {} - NFM(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + NFM(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~NFM() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; - this->outputChangeHandler = outputChangeHandler; // Define structure demod.init(input, getIFSampleRate(), bandwidth / 2.0f); @@ -69,6 +68,5 @@ namespace demod { dsp::FMDemod demod; std::string name; - EventHandler*> outputChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/raw.h b/decoder_modules/radio/src/demodulators/raw.h index 88fa3a95..1e66c41b 100644 --- a/decoder_modules/radio/src/demodulators/raw.h +++ b/decoder_modules/radio/src/demodulators/raw.h @@ -8,17 +8,16 @@ namespace demod { public: RAW() {} - RAW(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + RAW(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~RAW() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; - this->outputChangeHandler = outputChangeHandler; audioSampleRate = audioSR; // Define structure @@ -71,6 +70,5 @@ namespace demod { dsp::ComplexToStereo c2s; std::string name; - EventHandler*> outputChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/usb.h b/decoder_modules/radio/src/demodulators/usb.h index cb3a55a5..155117cb 100644 --- a/decoder_modules/radio/src/demodulators/usb.h +++ b/decoder_modules/radio/src/demodulators/usb.h @@ -8,17 +8,16 @@ namespace demod { public: USB() {} - USB(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + USB(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~USB() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; - this->outputChangeHandler = outputChangeHandler; // Define structure demod.init(input, getIFSampleRate(), bandwidth, dsp::SSBDemod::MODE_USB); @@ -79,6 +78,5 @@ namespace demod { dsp::MonoToStereo m2s; std::string name; - EventHandler*> outputChangeHandler; }; } \ No newline at end of file diff --git a/decoder_modules/radio/src/demodulators/wfm.h b/decoder_modules/radio/src/demodulators/wfm.h index 6a48c3c7..88bb28e0 100644 --- a/decoder_modules/radio/src/demodulators/wfm.h +++ b/decoder_modules/radio/src/demodulators/wfm.h @@ -8,15 +8,15 @@ namespace demod { public: WFM() {} - WFM(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { - init(name, config, input, bandwidth, outputChangeHandler, audioSR); + WFM(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { + init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR); } ~WFM() { stop(); } - void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, double audioSR) { + void init(std::string name, ConfigManager* config, dsp::stream* input, double bandwidth, EventHandler*> outputChangeHandler, EventHandler afbwChangeHandler, double audioSR) { this->name = name; this->outputChangeHandler = outputChangeHandler; _config = config; diff --git a/decoder_modules/radio/src/radio_module.h b/decoder_modules/radio/src/radio_module.h index cf9623b7..f1a57f38 100644 --- a/decoder_modules/radio/src/radio_module.h +++ b/decoder_modules/radio/src/radio_module.h @@ -88,8 +88,11 @@ public: // Load configuration for and enabled all demodulators EventHandler*> _demodOutputChangeHandler; + EventHandler _demodAfbwChangedHandler; _demodOutputChangeHandler.handler = demodOutputChangeHandler; _demodOutputChangeHandler.ctx = this; + _demodAfbwChangedHandler.handler = demodAfbwChangedHandler; + _demodAfbwChangedHandler.ctx = this; for (auto& demod : demods) { if (!demod) { continue; } @@ -104,7 +107,7 @@ public: bw = std::clamp(bw, demod->getMinBandwidth(), demod->getMaxBandwidth()); // Initialize - demod->init(name, &config, ifChain.getOutput(), bw, _demodOutputChangeHandler, stream.getSampleRate()); + demod->init(name, &config, ifChain.getOutput(), bw, _demodOutputChangeHandler, _demodAfbwChangedHandler, stream.getSampleRate()); } // Initialize audio DSP chain @@ -614,6 +617,17 @@ private: _this->afChain.setInput(output); } + static void demodAfbwChangedHandler(float output, void* ctx) { + RadioModule* _this = (RadioModule*)ctx; + + float audioBW = std::min(_this->selectedDemod->getMaxAFBandwidth(), _this->selectedDemod->getAFBandwidth(_this->bandwidth)); + audioBW = std::min(audioBW, _this->audioSampleRate / 2.0); + + _this->win.setCutoff(audioBW); + _this->win.setTransWidth(audioBW); + _this->resamp.block.updateWindow(&_this->win); + } + static void ifChainOutputChangeHandler(dsp::stream* output, void* ctx) { RadioModule* _this = (RadioModule*)ctx; if (!_this->selectedDemod) { return; }