mirror of
				https://github.com/AlexandreRouma/SDRPlusPlus.git
				synced 2025-11-04 02:39:11 +01:00 
			
		
		
		
	Code cleanup, bugfix and optimisation
This commit is contained in:
		@@ -31,8 +31,8 @@ namespace dsp::demod {
 | 
			
		||||
            _bandwidth = bandwidth;
 | 
			
		||||
            _samplerate = samplerate;
 | 
			
		||||
 | 
			
		||||
            carrierAgc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
 | 
			
		||||
            audioAgc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
 | 
			
		||||
            carrierAgc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0, INFINITY);
 | 
			
		||||
            audioAgc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0, INFINITY);
 | 
			
		||||
            dcBlock.init(NULL, dcBlockRate);
 | 
			
		||||
            lpfTaps = taps::lowPass(bandwidth / 2.0, (bandwidth / 2.0) * 0.1, samplerate);
 | 
			
		||||
            lpf.init(NULL, lpfTaps);
 | 
			
		||||
 
 | 
			
		||||
@@ -16,9 +16,10 @@ namespace dsp::demod {
 | 
			
		||||
 | 
			
		||||
        void init(stream<complex_t>* in, double tone, double agcAttack, double agcDecay, double samplerate) {
 | 
			
		||||
            _tone = tone;
 | 
			
		||||
            _samplerate = samplerate;
 | 
			
		||||
            
 | 
			
		||||
            xlator.init(NULL, tone, samplerate);
 | 
			
		||||
            agc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
 | 
			
		||||
            agc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0, INFINITY);
 | 
			
		||||
 | 
			
		||||
            if constexpr (std::is_same_v<T, float>) {
 | 
			
		||||
                agc.out.free();
 | 
			
		||||
@@ -31,7 +32,7 @@ namespace dsp::demod {
 | 
			
		||||
            assert(base_type::_block_init);
 | 
			
		||||
            std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
 | 
			
		||||
            _tone = tone;
 | 
			
		||||
            xlator.setOffset(_tone);
 | 
			
		||||
            xlator.setOffset(_tone, _samplerate);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        void setAGCAttack(double attack) {
 | 
			
		||||
@@ -49,7 +50,8 @@ namespace dsp::demod {
 | 
			
		||||
        void setSamplerate(double samplerate) {
 | 
			
		||||
            assert(base_type::_block_init);
 | 
			
		||||
            std::lock_guard<std::recursive_mutex> lck(base_type::ctrlMtx);
 | 
			
		||||
            xlator.setOffset(_tone, samplerate);
 | 
			
		||||
            _samplerate = samplerate;
 | 
			
		||||
            xlator.setOffset(_tone, _samplerate);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        inline int process(int count, const complex_t* in, T* out) {
 | 
			
		||||
@@ -79,6 +81,7 @@ namespace dsp::demod {
 | 
			
		||||
 | 
			
		||||
    private:
 | 
			
		||||
        double _tone;
 | 
			
		||||
        double _samplerate;
 | 
			
		||||
 | 
			
		||||
        dsp::channel::FrequencyXlator xlator;
 | 
			
		||||
        dsp::loop::AGC<float> agc;
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ namespace dsp::demod {
 | 
			
		||||
            _samplerate = samplerate;
 | 
			
		||||
 | 
			
		||||
            xlator.init(NULL, getTranslation(), _samplerate);
 | 
			
		||||
            agc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0);
 | 
			
		||||
            agc.init(NULL, 1.0, agcAttack, agcDecay, 10e6, 10.0, INFINITY);
 | 
			
		||||
 | 
			
		||||
            if constexpr (std::is_same_v<T, float>) {
 | 
			
		||||
                agc.out.free();
 | 
			
		||||
 
 | 
			
		||||
@@ -24,7 +24,7 @@ namespace demod {
 | 
			
		||||
    class Demodulator {
 | 
			
		||||
    public:
 | 
			
		||||
        virtual ~Demodulator() {}
 | 
			
		||||
        virtual 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) = 0;
 | 
			
		||||
        virtual void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) = 0;
 | 
			
		||||
        virtual void start() = 0;
 | 
			
		||||
        virtual void stop() = 0;
 | 
			
		||||
        virtual void showMenu() = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,13 +7,13 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        AM() {}
 | 
			
		||||
 | 
			
		||||
        AM(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);
 | 
			
		||||
        AM(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~AM() { 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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            _config = config;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,15 +7,15 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        CW() {}
 | 
			
		||||
 | 
			
		||||
        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);
 | 
			
		||||
        CW(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~CW() {
 | 
			
		||||
            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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            this->_config = config;
 | 
			
		||||
            this->afbwChangeHandler = afbwChangeHandler;
 | 
			
		||||
 
 | 
			
		||||
@@ -7,15 +7,15 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        DSB() {}
 | 
			
		||||
 | 
			
		||||
        DSB(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);
 | 
			
		||||
        DSB(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~DSB() {
 | 
			
		||||
            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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            _config = config;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,15 +7,15 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        LSB() {}
 | 
			
		||||
 | 
			
		||||
        LSB(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);
 | 
			
		||||
        LSB(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~LSB() {
 | 
			
		||||
            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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            _config = config;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,13 +7,13 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        NFM() {}
 | 
			
		||||
 | 
			
		||||
        NFM(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);
 | 
			
		||||
        NFM(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~NFM() { 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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
 | 
			
		||||
            // Define structure
 | 
			
		||||
 
 | 
			
		||||
@@ -7,15 +7,15 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        RAW() {}
 | 
			
		||||
 | 
			
		||||
        RAW(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);
 | 
			
		||||
        RAW(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~RAW() {
 | 
			
		||||
            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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            audioSampleRate = audioSR;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -8,15 +8,15 @@ namespace demod {
 | 
			
		||||
    public:
 | 
			
		||||
        USB() {}
 | 
			
		||||
 | 
			
		||||
        USB(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);
 | 
			
		||||
        USB(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, audioSR);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ~USB() {
 | 
			
		||||
            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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            _config = config;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,15 +7,15 @@ namespace demod {
 | 
			
		||||
    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(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            init(name, config, input, bandwidth, 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) {
 | 
			
		||||
        void init(std::string name, ConfigManager* config, dsp::stream<dsp::complex_t>* input, double bandwidth, double audioSR) {
 | 
			
		||||
            this->name = name;
 | 
			
		||||
            this->outputChangeHandler = outputChangeHandler;
 | 
			
		||||
            _config = config;
 | 
			
		||||
 
 | 
			
		||||
@@ -57,17 +57,6 @@ public:
 | 
			
		||||
        selectedDemodID = config.conf[name]["selectedDemodId"];
 | 
			
		||||
        config.release(created);
 | 
			
		||||
 | 
			
		||||
        // Create demodulator instances
 | 
			
		||||
        demods.fill(NULL);
 | 
			
		||||
        demods[RADIO_DEMOD_WFM] = new demod::WFM();
 | 
			
		||||
        demods[RADIO_DEMOD_NFM] = new demod::NFM();
 | 
			
		||||
        demods[RADIO_DEMOD_AM] = new demod::AM();
 | 
			
		||||
        demods[RADIO_DEMOD_USB] = new demod::USB();
 | 
			
		||||
        demods[RADIO_DEMOD_LSB] = new demod::LSB();
 | 
			
		||||
        demods[RADIO_DEMOD_DSB] = new demod::DSB();
 | 
			
		||||
        demods[RADIO_DEMOD_CW] = new demod::CW();
 | 
			
		||||
        demods[RADIO_DEMOD_RAW] = new demod::RAW();
 | 
			
		||||
 | 
			
		||||
        // Initialize the VFO
 | 
			
		||||
        vfo = sigpath::vfoManager.createVFO(name, ImGui::WaterfallVFO::REF_CENTER, 0, 200000, 200000, 50000, 200000, false);
 | 
			
		||||
        onUserChangedBandwidthHandler.handler = vfoUserChangedBandwidthHandler;
 | 
			
		||||
@@ -85,30 +74,6 @@ public:
 | 
			
		||||
        ifChain.addBlock(&squelch, false);
 | 
			
		||||
        ifChain.addBlock(&fmnr, false);
 | 
			
		||||
 | 
			
		||||
        // Load configuration for and enabled all demodulators
 | 
			
		||||
        EventHandler<dsp::stream<dsp::stereo_t>*> _demodOutputChangeHandler;
 | 
			
		||||
        EventHandler<float> _demodAfbwChangedHandler;
 | 
			
		||||
        _demodOutputChangeHandler.handler = demodOutputChangeHandler;
 | 
			
		||||
        _demodOutputChangeHandler.ctx = this;
 | 
			
		||||
        _demodAfbwChangedHandler.handler = demodAfbwChangedHandler;
 | 
			
		||||
        _demodAfbwChangedHandler.ctx = this;
 | 
			
		||||
        for (auto& demod : demods) {
 | 
			
		||||
            if (!demod) { continue; }
 | 
			
		||||
 | 
			
		||||
            // Default config
 | 
			
		||||
            double bw = demod->getDefaultBandwidth();
 | 
			
		||||
            if (!config.conf[name].contains(demod->getName())) {
 | 
			
		||||
                config.conf[name][demod->getName()]["bandwidth"] = bw;
 | 
			
		||||
                config.conf[name][demod->getName()]["snapInterval"] = demod->getDefaultSnapInterval();
 | 
			
		||||
                config.conf[name][demod->getName()]["squelchLevel"] = MIN_SQUELCH;
 | 
			
		||||
                config.conf[name][demod->getName()]["squelchEnabled"] = false;
 | 
			
		||||
            }
 | 
			
		||||
            bw = std::clamp<double>(bw, demod->getMinBandwidth(), demod->getMaxBandwidth());
 | 
			
		||||
 | 
			
		||||
            // Initialize
 | 
			
		||||
            demod->init(name, &config, ifChain.out, bw, _demodOutputChangeHandler, _demodAfbwChangedHandler, stream.getSampleRate());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Initialize audio DSP chain
 | 
			
		||||
        afChain.init(&dummyAudioStream);
 | 
			
		||||
 | 
			
		||||
@@ -297,8 +262,45 @@ private:
 | 
			
		||||
        if (!_this->enabled) { style::endDisabled(); }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    demod::Demodulator* instantiateDemod(DemodID id) {
 | 
			
		||||
        demod::Demodulator* demod = NULL;
 | 
			
		||||
        switch (id) {
 | 
			
		||||
            case DemodID::RADIO_DEMOD_NFM:  demod = new demod::NFM(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_WFM:  demod = new demod::WFM(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_AM:   demod = new demod::AM(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_DSB:  demod = new demod::DSB(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_USB:  demod = new demod::USB(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_CW:   demod = new demod::CW(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_LSB:  demod = new demod::LSB(); break;
 | 
			
		||||
            case DemodID::RADIO_DEMOD_RAW:  demod = new demod::RAW(); break;
 | 
			
		||||
            default:                        demod = NULL; break;
 | 
			
		||||
        }
 | 
			
		||||
        if (!demod) { return NULL; }
 | 
			
		||||
 | 
			
		||||
        // Default config
 | 
			
		||||
        double bw = demod->getDefaultBandwidth();
 | 
			
		||||
        config.acquire();
 | 
			
		||||
        if (!config.conf[name].contains(demod->getName())) {
 | 
			
		||||
            config.conf[name][demod->getName()]["bandwidth"] = bw;
 | 
			
		||||
            config.conf[name][demod->getName()]["snapInterval"] = demod->getDefaultSnapInterval();
 | 
			
		||||
            config.conf[name][demod->getName()]["squelchLevel"] = MIN_SQUELCH;
 | 
			
		||||
            config.conf[name][demod->getName()]["squelchEnabled"] = false;
 | 
			
		||||
            config.release(true);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            config.release();
 | 
			
		||||
        }
 | 
			
		||||
        bw = std::clamp<double>(bw, demod->getMinBandwidth(), demod->getMaxBandwidth());
 | 
			
		||||
 | 
			
		||||
        // Initialize
 | 
			
		||||
        demod->init(name, &config, ifChain.out, bw, stream.getSampleRate());
 | 
			
		||||
 | 
			
		||||
        return demod;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void selectDemodByID(DemodID id) {
 | 
			
		||||
        demod::Demodulator* demod = demods[id];
 | 
			
		||||
        auto startTime = std::chrono::high_resolution_clock::now();
 | 
			
		||||
        demod::Demodulator* demod = instantiateDemod(id);
 | 
			
		||||
        if (!demod) {
 | 
			
		||||
            spdlog::error("Demodulator {0} not implemented", id);
 | 
			
		||||
            return;
 | 
			
		||||
@@ -310,11 +312,16 @@ private:
 | 
			
		||||
        config.acquire();
 | 
			
		||||
        config.conf[name]["selectedDemodId"] = id;
 | 
			
		||||
        config.release(true);
 | 
			
		||||
        auto endTime = std::chrono::high_resolution_clock::now();
 | 
			
		||||
        spdlog::warn("Demod switch took {0} us", (std::chrono::duration_cast<std::chrono::microseconds>(endTime - startTime)).count());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void selectDemod(demod::Demodulator* demod) {
 | 
			
		||||
        // Stopcurrently selected demodulator and select new
 | 
			
		||||
        if (selectedDemod) { selectedDemod->stop(); }
 | 
			
		||||
        if (selectedDemod) {
 | 
			
		||||
            selectedDemod->stop();
 | 
			
		||||
            delete selectedDemod;
 | 
			
		||||
        }
 | 
			
		||||
        selectedDemod = demod;
 | 
			
		||||
 | 
			
		||||
        // Give the demodulator the most recent audio SR
 | 
			
		||||
@@ -553,22 +560,6 @@ private:
 | 
			
		||||
        _this->setAudioSampleRate(sampleRate);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static void demodOutputChangeHandler(dsp::stream<dsp::stereo_t>* output, void* ctx) {
 | 
			
		||||
        RadioModule* _this = (RadioModule*)ctx;
 | 
			
		||||
        _this->afChain.setInput(output, [=](dsp::stream<dsp::stereo_t>* out){ _this->stream.setInput(out); });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static void demodAfbwChangedHandler(float output, void* ctx) {
 | 
			
		||||
        RadioModule* _this = (RadioModule*)ctx;
 | 
			
		||||
        
 | 
			
		||||
        float audioBW = std::min<float>(_this->selectedDemod->getMaxAFBandwidth(), _this->selectedDemod->getAFBandwidth(_this->bandwidth));
 | 
			
		||||
        audioBW = std::min<float>(audioBW, _this->audioSampleRate / 2.0);
 | 
			
		||||
 | 
			
		||||
        // _this->win.setCutoff(audioBW);
 | 
			
		||||
        // _this->win.setTransWidth(audioBW);
 | 
			
		||||
        // _this->resamp.block.updateWindow(&_this->win);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    static void ifChainOutputChangeHandler(dsp::stream<dsp::complex_t>* output, void* ctx) {
 | 
			
		||||
        RadioModule* _this = (RadioModule*)ctx;
 | 
			
		||||
        if (!_this->selectedDemod) { return; }
 | 
			
		||||
@@ -642,7 +633,6 @@ private:
 | 
			
		||||
 | 
			
		||||
    SinkManager::Stream stream;
 | 
			
		||||
 | 
			
		||||
    std::array<demod::Demodulator*, _RADIO_DEMOD_COUNT> demods;
 | 
			
		||||
    demod::Demodulator* selectedDemod = NULL;
 | 
			
		||||
 | 
			
		||||
    OptionList<std::string, DeemphasisMode> deempModes;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user