Added preset system for FM IF NR

This commit is contained in:
AlexandreRouma
2021-12-24 21:42:04 +01:00
parent ad2ddc6ad3
commit 07294034f6
53 changed files with 6538 additions and 5603 deletions

View File

@ -13,6 +13,13 @@ enum DeemphasisMode {
_DEEMP_MODE_COUNT
};
enum IFNRPreset {
IFNR_PRESET_NOAA_APT,
IFNR_PRESET_VOICE,
IFNR_PRESET_NARROW_BAND,
IFNR_PRESET_BROADCAST
};
namespace demod {
class Demodulator {
public:

View File

@ -22,6 +22,13 @@ std::map<DeemphasisMode, double> deempTaus = {
{ DEEMP_MODE_75US, 75e-6 }
};
std::map<IFNRPreset, double> ifnrTaps = {
{ IFNR_PRESET_NOAA_APT, 9},
{ IFNR_PRESET_VOICE, 15 },
{ IFNR_PRESET_NARROW_BAND, 31 },
{ IFNR_PRESET_BROADCAST, 32 }
};
class RadioModule : public ModuleManager::Instance {
public:
RadioModule(std::string name) {
@ -33,6 +40,10 @@ public:
deempModes.define("50us", DEEMP_MODE_50US);
deempModes.define("75us", DEEMP_MODE_75US);
ifnrPresets.define("NOAA APT", IFNR_PRESET_NOAA_APT);
ifnrPresets.define("Voice", IFNR_PRESET_VOICE);
ifnrPresets.define("Narrow Band", IFNR_PRESET_NARROW_BAND);
// Initialize the config if it doesn't exist
bool created = false;
config.acquire();
@ -297,6 +308,15 @@ private:
if (ImGui::Checkbox(("IF Noise Reduction##_radio_fmifnr_ena_" + _this->name).c_str(), &_this->FMIFNREnabled)) {
_this->setFMIFNREnabled(_this->FMIFNREnabled);
}
if (_this->selectedDemodID == RADIO_DEMOD_NFM) {
if (!_this->FMIFNREnabled && _this->enabled) { style::beginDisabled(); }
ImGui::SameLine();
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
if (ImGui::Combo(("##_radio_fmifnr_ena_" + _this->name).c_str(), &_this->fmIFPresetId, _this->ifnrPresets.txt)) {
_this->setIFNRPreset(_this->ifnrPresets[_this->fmIFPresetId]);
}
if (!_this->FMIFNREnabled && _this->enabled) { style::endDisabled(); }
}
}
// Demodulator specific menu
@ -347,6 +367,7 @@ private:
postProcEnabled = selectedDemod->getPostProcEnabled();
FMIFNRAllowed = selectedDemod->getFMIFNRAllowed();
FMIFNREnabled = false;
fmIFPresetId = ifnrPresets.valueId(IFNR_PRESET_VOICE);
nbAllowed = selectedDemod->getNBAllowed();
nbEnabled = false;
nbLevel = 0.0f;
@ -365,7 +386,6 @@ private:
squelchEnabled = config.conf[name][selectedDemod->getName()]["squelchEnabled"];
}
if (config.conf[name][selectedDemod->getName()].contains("deempMode")) {
// Upgrade to the text key
if (!config.conf[name][selectedDemod->getName()]["deempMode"].is_string()) {
config.conf[name][selectedDemod->getName()]["deempMode"] = deempModes.key(deempId);
}
@ -378,6 +398,12 @@ private:
if (config.conf[name][selectedDemod->getName()].contains("FMIFNREnabled")) {
FMIFNREnabled = config.conf[name][selectedDemod->getName()]["FMIFNREnabled"];
}
if (config.conf[name][selectedDemod->getName()].contains("fmifnrPreset")) {
std::string presetOpt = config.conf[name][selectedDemod->getName()]["fmifnrPreset"];
if (ifnrPresets.keyExists(presetOpt)) {
fmIFPresetId = ifnrPresets.keyId(presetOpt);
}
}
if (config.conf[name][selectedDemod->getName()].contains("noiseBlankerEnabled")) {
nbEnabled = config.conf[name][selectedDemod->getName()]["noiseBlankerEnabled"];
}
@ -401,6 +427,7 @@ private:
setBandwidth(bandwidth);
// Configure FM IF Noise Reduction
setIFNRPreset((selectedDemodID == RADIO_DEMOD_NFM) ? ifnrPresets[fmIFPresetId] : IFNR_PRESET_BROADCAST);
setFMIFNREnabled(FMIFNRAllowed ? FMIFNREnabled : false);
// Configure notch
@ -411,7 +438,6 @@ private:
setSquelchEnabled(squelchEnabled);
// Configure noise blanker
fmnr.block.setTapCount((selectedDemod->getIFSampleRate() < 100000.0f) ? 9 : 32);
nb.block.setLevel(nbLevel);
setNoiseBlankerEnabled(nbEnabled);
@ -555,6 +581,24 @@ private:
config.release(true);
}
void setIFNRPreset(IFNRPreset preset) {
// Don't save if in broadcast mode
if (preset == IFNR_PRESET_BROADCAST) {
if (!selectedDemod) { return; }
fmnr.block.setTapCount(ifnrTaps[preset]);
return;
}
fmIFPresetId = ifnrPresets.valueId(preset);
if (!selectedDemod) { return; }
fmnr.block.setTapCount(ifnrTaps[preset]);
// Save config
config.acquire();
config.conf[name][selectedDemod->getName()]["fmifnrPreset"] = ifnrPresets.key(fmIFPresetId);
config.release(true);
}
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
RadioModule* _this = (RadioModule*)ctx;
_this->setBandwidth(newBw);
@ -655,6 +699,7 @@ private:
demod::Demodulator* selectedDemod = NULL;
OptionList<std::string, DeemphasisMode> deempModes;
OptionList<std::string, IFNRPreset> ifnrPresets;
double audioSampleRate = 48000.0;
float minBandwidth;
@ -673,6 +718,7 @@ private:
bool FMIFNRAllowed;
bool FMIFNREnabled = false;
int fmIFPresetId;
bool notchEnabled = false;
float notchPos = 0;