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

111 wiersze
3.9 KiB
C
Czysty Zwykły widok Historia

2021-12-04 03:49:51 +00:00
#pragma once
#include "../demod.h"
2022-06-15 14:08:28 +00:00
#include <dsp/channel/frequency_xlator.h>
#include <dsp/convert/complex_to_real.h>
#include <dsp/convert/mono_to_stereo.h>
#include <dsp/loop/agc.h>
2021-12-04 03:49:51 +00:00
namespace demod {
class CW : public Demodulator {
public:
CW() {}
2022-01-29 16:27:38 +00:00
CW(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-04 03:49:51 +00:00
}
~CW() {
stop();
}
2022-01-29 16:27:38 +00: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-04 03:49:51 +00:00
this->name = name;
2022-01-29 15:55:31 +00:00
this->_config = config;
2022-01-29 16:27:38 +00:00
this->_bandwidth = bandwidth;
this->afbwChangeHandler = afbwChangeHandler;
2021-12-04 03:49:51 +00:00
2022-01-29 15:55:31 +00:00
// Load config
config->acquire();
if (config->conf[name][getName()].contains("tone")) {
tone = config->conf[name][getName()]["tone"];
}
config->release();
2021-12-04 03:49:51 +00:00
// Define structure
2022-06-15 14:08:28 +00:00
xlator.init(input, tone, getIFSampleRate());
2021-12-04 03:49:51 +00:00
c2r.init(&xlator.out);
2022-06-17 15:34:23 +00:00
agc.init(&c2r.out, 1.0, 24.0 / getIFSampleRate(), 10e6, 10.0);
2021-12-04 03:49:51 +00:00
m2s.init(&agc.out);
}
void start() {
xlator.start();
c2r.start();
agc.start();
m2s.start();
}
void stop() {
xlator.stop();
c2r.stop();
agc.stop();
m2s.stop();
}
2022-01-29 15:55:31 +00:00
void showMenu() {
ImGui::LeftLabel("Tone Frequency");
ImGui::FillWidth();
if (ImGui::InputInt(("Stereo##_radio_cw_tone_" + name).c_str(), &tone, 10, 100)) {
tone = std::clamp<int>(tone, 250, 1250);
2022-06-15 14:08:28 +00:00
xlator.setOffset(tone, getIFSampleRate());
2022-01-29 16:27:38 +00:00
afbwChangeHandler.handler(getAFBandwidth(_bandwidth), afbwChangeHandler.ctx);
2022-01-29 15:55:31 +00:00
_config->acquire();
_config->conf[name][getName()]["tone"] = tone;
_config->release(true);
}
}
2021-12-04 03:49:51 +00:00
2022-01-29 16:27:38 +00:00
void setBandwidth(double bandwidth) { _bandwidth = bandwidth; }
2021-12-04 03:49:51 +00:00
void setInput(dsp::stream<dsp::complex_t>* input) {
xlator.setInput(input);
}
2021-12-04 16:46:48 +00:00
void AFSampRateChanged(double newSR) {}
2021-12-04 03:49:51 +00:00
// ============= 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; }
2022-01-29 16:27:38 +00:00
double getAFBandwidth(double bandwidth) { return (bandwidth / 2.0) + (float)tone; }
bool getDynamicAFBandwidth() { return true; }
bool getFMIFNRAllowed() { return false; }
bool getNBAllowed() { return false; }
2021-12-04 03:49:51 +00:00
dsp::stream<dsp::stereo_t>* getOutput() { return &m2s.out; }
private:
2022-01-29 15:55:31 +00:00
ConfigManager* _config = NULL;
2022-06-15 14:08:28 +00:00
dsp::channel::FrequencyXlator xlator;
dsp::convert::ComplexToReal c2r;
dsp::loop::AGC<float> agc;
dsp::convert::MonoToStereo m2s;
2021-12-04 03:49:51 +00:00
std::string name;
2022-01-29 15:55:31 +00:00
int tone = 800;
2022-01-29 16:27:38 +00:00
double _bandwidth;
EventHandler<float> afbwChangeHandler;
2021-12-04 03:49:51 +00:00
};
}