1 // Copyright (c) Charles J. Cliffe 2 // SPDX-License-Identifier: GPL-2.0+ 3 4 #pragma once 5 6 #include <queue> 7 #include <vector> 8 #include <atomic> 9 #include <memory> 10 11 #include "CubicSDRDefs.h" 12 #include "DemodDefs.h" 13 #include "DemodulatorWorkerThread.h" 14 15 class DemodulatorInstance; 16 17 class DemodulatorPreThread : public IOThread { 18 public: 19 20 explicit DemodulatorPreThread(DemodulatorInstance* parent); 21 ~DemodulatorPreThread() override; 22 23 void run() override; 24 25 void setDemodType(std::string demodType_in); 26 std::string getDemodType(); 27 28 void setFrequency(long long sampleRate); 29 long long getFrequency(); 30 31 void setSampleRate(long long sampleRate); 32 long long getSampleRate(); 33 34 void setBandwidth(int bandwidth); 35 int getBandwidth(); 36 37 void setAudioSampleRate(int rate); 38 int getAudioSampleRate(); 39 40 bool isInitialized(); 41 42 void terminate() override; 43 44 Modem *getModem(); 45 ModemKit *getModemKit(); 46 47 std::string readModemSetting(const std::string& setting); 48 void writeModemSetting(const std::string& setting, std::string value); 49 ModemSettings readModemSettings(); 50 void writeModemSettings(ModemSettings settings); 51 52 protected: 53 54 DemodulatorInstance* parent; 55 56 msresamp_crcf iqResampler; 57 double iqResampleRatio; 58 std::vector<liquid_float_complex> resampledData; 59 60 Modem *cModem; 61 ModemKit *cModemKit; 62 63 std::atomic_llong currentSampleRate, newSampleRate; 64 std::atomic_llong currentFrequency, newFrequency; 65 std::atomic_int currentBandwidth, newBandwidth; 66 std::atomic_int currentAudioSampleRate, newAudioSampleRate; 67 68 std::atomic_bool sampleRateChanged, frequencyChanged, bandwidthChanged, audioSampleRateChanged; 69 70 ModemSettings modemSettingsBuffered; 71 std::atomic_bool modemSettingsChanged; 72 73 nco_crcf freqShifter; 74 int shiftFrequency; 75 76 std::atomic_bool initialized; 77 std::atomic_bool demodTypeChanged; 78 std::string demodType; 79 std::string newDemodType; 80 81 DemodulatorWorkerThread *workerThread; 82 std::thread *t_Worker; 83 84 DemodulatorThreadWorkerCommandQueuePtr workerQueue; 85 DemodulatorThreadWorkerResultQueuePtr workerResults; 86 87 DemodulatorThreadInputQueuePtr iqInputQueue; 88 DemodulatorThreadPostInputQueuePtr iqOutputQueue; 89 }; 90