SDRPlusPlus/decoder_modules/radio/src/demodulators/wfm.h

104 wiersze
3.6 KiB
C++

#pragma once
#include "../demod.h"
#include <dsp/demod/broadcast_fm.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, EventHandler<float> afbwChangeHandler, double audioSR) {
init(name, config, input, bandwidth, outputChangeHandler, afbwChangeHandler, 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, EventHandler<float> afbwChangeHandler, double audioSR) {
this->name = name;
this->outputChangeHandler = outputChangeHandler;
_config = config;
// Load config
_config->acquire();
bool modified = false;
if (config->conf[name][getName()].contains("stereo")) {
_stereo = config->conf[name][getName()]["stereo"];
}
_config->release(modified);
// Define structure
demod.init(input, bandwidth / 2.0f, getIFSampleRate(), _stereo);
}
void start() {
demod.start();
}
void stop() {
demod.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);
}
if (ImGui::Checkbox(("Low Pass##_radio_wfm_lowpass_" + name).c_str(), &_lowPass)) {
demod.setLowPass(_lowPass);
}
}
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 "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; }
bool getFMIFNRAllowed() { return true; }
bool getNBAllowed() { return false; }
dsp::stream<dsp::stereo_t>* getOutput() { return &demod.out; }
// ============= DEDICATED FUNCTIONS =============
void setStereo(bool stereo) {
_stereo = stereo;
demod.setStereo(_stereo);
}
private:
dsp::demod::BroadcastFM demod;
ConfigManager* _config = NULL;
bool _stereo = false;
bool _lowPass = true;
std::string name;
EventHandler<dsp::stream<dsp::stereo_t>*> outputChangeHandler;
};
}