110 lines
3.9 KiB
C
Raw Normal View History

2021-12-03 19:46:09 +01:00
#pragma once
#include "../demod.h"
2022-06-15 16:08:28 +02:00
#include <dsp/demod/broadcast_fm.h>
2021-12-03 19:46:09 +01:00
namespace demod {
class WFM : public Demodulator {
public:
WFM() {}
2022-01-29 17:27:38 +01:00
WFM(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, EventHandler<float> afbwChangeHandler, double audioSR) {
init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, audioSR);
2021-12-03 19:46:09 +01:00
}
~WFM() {
stop();
}
2022-01-29 17:27:38 +01:00
void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler, EventHandler<float> afbwChangeHandler, double audioSR) {
2021-12-03 19:46:09 +01:00
this->name = name;
2021-12-04 04:49:51 +01:00
this->outputChangeHandler = outputChangeHandler;
2021-12-03 19:46:09 +01:00
_config = config;
// Load config
_config->acquire();
bool modified = false;
2021-12-03 19:46:09 +01:00
if (config->conf[name][getName()].contains("stereo")) {
2022-06-15 16:08:28 +02:00
_stereo = config->conf[name][getName()]["stereo"];
2021-12-03 19:46:09 +01:00
}
2022-06-18 00:33:08 +02:00
if (config->conf[name][getName()].contains("lowPass")) {
_lowPass = config->conf[name][getName()]["lowPass"];
}
2021-12-03 19:46:09 +01:00
_config->release(modified);
// Define structure
2022-06-18 00:33:08 +02:00
demod.init(input, bandwidth / 2.0f, getIFSampleRate(), _stereo, _lowPass);
2021-12-03 19:46:09 +01:00
}
void start() {
2022-06-15 16:08:28 +02:00
demod.start();
2021-12-03 19:46:09 +01:00
}
void stop() {
demod.stop();
}
void showMenu() {
2022-06-15 16:08:28 +02:00
if (ImGui::Checkbox(("Stereo##_radio_wfm_stereo_" + name).c_str(), &_stereo)) {
setStereo(_stereo);
2021-12-03 19:46:09 +01:00
_config->acquire();
2022-06-15 16:08:28 +02:00
_config->conf[name][getName()]["stereo"] = _stereo;
2021-12-03 19:46:09 +01:00
_config->release(true);
}
2022-06-17 17:34:23 +02:00
if (ImGui::Checkbox(("Low Pass##_radio_wfm_lowpass_" + name).c_str(), &_lowPass)) {
demod.setLowPass(_lowPass);
2022-06-18 00:33:08 +02:00
_config->acquire();
_config->conf[name][getName()]["lowPass"] = _lowPass;
_config->release(true);
2022-06-17 17:34:23 +02:00
}
2021-12-03 19:46:09 +01:00
}
void setBandwidth(double bandwidth) {
demod.setDeviation(bandwidth / 2.0f);
}
void setInput(dsp::stream<dsp::complex_t>* input) {
demod.setInput(input);
}
2021-12-04 17:46:48 +01:00
void AFSampRateChanged(double newSR) {}
2021-12-03 19:46:09 +01:00
// ============= 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; }
2021-12-04 04:49:51 +01:00
double getAFBandwidth(double bandwidth) { return 16000.0; }
bool getDynamicAFBandwidth() { return false; }
bool getFMIFNRAllowed() { return true; }
bool getNBAllowed() { return false; }
2022-06-15 16:08:28 +02:00
dsp::stream<dsp::stereo_t>* getOutput() { return &demod.out; }
2021-12-03 19:46:09 +01:00
// ============= DEDICATED FUNCTIONS =============
2022-06-15 16:08:28 +02:00
void setStereo(bool stereo) {
_stereo = stereo;
demod.setStereo(_stereo);
2021-12-03 19:46:09 +01:00
}
private:
2022-06-15 16:08:28 +02:00
dsp::demod::BroadcastFM demod;
2021-12-03 19:46:09 +01:00
ConfigManager* _config = NULL;
2022-06-15 16:08:28 +02:00
bool _stereo = false;
2022-06-17 17:34:23 +02:00
bool _lowPass = true;
2021-12-03 19:46:09 +01:00
std::string name;
2021-12-04 04:49:51 +01:00
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
2021-12-03 19:46:09 +01:00
};
}