diff --git a/src/demod/DemodDefs.h b/src/demod/DemodDefs.h index ec40035..52f1050 100644 --- a/src/demod/DemodDefs.h +++ b/src/demod/DemodDefs.h @@ -82,6 +82,7 @@ class DemodulatorThreadPostIQData: public ReferenceCounter { public: std::vector data; long long sampleRate; + std::string modemType; Modem *modem; ModemKit *modemKit; diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index e3dc0bf..0ba23f3 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -18,6 +18,7 @@ void DemodulatorWorkerThread::run() { while (!terminated) { bool filterChanged = false; + bool makeDemod = false; DemodulatorWorkerThreadCommand filterCommand; DemodulatorWorkerThreadCommand command; @@ -29,6 +30,10 @@ void DemodulatorWorkerThread::run() { filterChanged = true; filterCommand = command; break; + case DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD: + makeDemod = true; + filterCommand = command; + break; default: break; } @@ -46,44 +51,16 @@ void DemodulatorWorkerThread::run() { result.iqResampler = msresamp_crcf_create(result.iqResampleRatio, As); } + if (makeDemod) { + cModem = Modem::makeModem(filterCommand.demodType); + } + if (filterCommand.bandwidth && filterCommand.audioSampleRate) { -// result.audioResamplerRatio = (double) (filterCommand.audioSampleRate) / (double) filterCommand.bandwidth; -// result.audioResampler = msresamp_rrrf_create(result.audioResamplerRatio, As); -// result.stereoResampler = msresamp_rrrf_create(result.audioResamplerRatio, As); -// result.audioSampleRate = filterCommand.audioSampleRate; - -/* // Stereo filters / shifters - double firStereoCutoff = ((double) 16000 / (double) filterCommand.audioSampleRate); - float ft = ((double) 1000 / (double) filterCommand.audioSampleRate); // filter transition - float mu = 0.0f; // fractional timing offset - - if (firStereoCutoff < 0) { - firStereoCutoff = 0; + result.modem = cModem; + if (cModem != nullptr) { + cModemKit = cModem->buildKit(filterCommand.bandwidth, filterCommand.audioSampleRate); } - - if (firStereoCutoff > 0.5) { - firStereoCutoff = 0.5; - } - - unsigned int h_len = estimate_req_filter_len(ft, As); - float *h = new float[h_len]; - liquid_firdes_kaiser(h_len, firStereoCutoff, As, mu, h); - - result.firStereoLeft = firfilt_rrrf_create(h, h_len); - result.firStereoRight = firfilt_rrrf_create(h, h_len); - - float bw = filterCommand.bandwidth; - if (bw < 100000.0) { - bw = 100000.0; - } - // stereo pilot filter - unsigned int order = 5; // filter order - float f0 = ((double) 19000 / bw); - float fc = ((double) 19500 / bw); - float Ap = 1.0f; - As = 60.0f; - - result.iirStereoPilot = iirfilt_crcf_create_prototype(LIQUID_IIRDES_CHEBY2, LIQUID_IIRDES_BANDPASS, LIQUID_IIRDES_SOS, order, fc, f0, Ap, As); */ + result.modemKit = cModemKit; } if (filterCommand.bandwidth) { diff --git a/src/demod/DemodulatorWorkerThread.h b/src/demod/DemodulatorWorkerThread.h index 38fb77a..2a47ce4 100644 --- a/src/demod/DemodulatorWorkerThread.h +++ b/src/demod/DemodulatorWorkerThread.h @@ -41,16 +41,16 @@ public: class DemodulatorWorkerThreadCommand { public: enum DemodulatorThreadCommandEnum { - DEMOD_WORKER_THREAD_CMD_NULL, DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS + DEMOD_WORKER_THREAD_CMD_NULL, DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS, DEMOD_WORKER_THREAD_CMD_MAKE_DEMOD }; DemodulatorWorkerThreadCommand() : - cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) { + cmd(DEMOD_WORKER_THREAD_CMD_NULL), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0), demodType("") { } DemodulatorWorkerThreadCommand(DemodulatorThreadCommandEnum cmd) : - cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0) { + cmd(cmd), frequency(0), sampleRate(0), bandwidth(0), audioSampleRate(0), demodType("") { } @@ -60,6 +60,7 @@ public: long long sampleRate; unsigned int bandwidth; unsigned int audioSampleRate; + std::string demodType; }; typedef ThreadQueue DemodulatorThreadWorkerCommandQueue; @@ -87,4 +88,6 @@ protected: DemodulatorThreadWorkerCommandQueue *commandQueue; DemodulatorThreadWorkerResultQueue *resultQueue; + Modem *cModem; + ModemKit *cModemKit; }; diff --git a/src/modules/modem/Modem.cpp b/src/modules/modem/Modem.cpp index 058b10d..c72a6a4 100644 --- a/src/modules/modem/Modem.cpp +++ b/src/modules/modem/Modem.cpp @@ -10,18 +10,10 @@ ModemFactoryList Modem::getFactories() { return modemFactories; } -Modem *Modem::factory() { +Modem *Modem::makeModem(std::string modemType) { + if (modemFactories.find(modemType) != modemFactories.end()) { + return modemFactories[modemType]->factory(); + } + return nullptr; } - -ModemKit *Modem::buildKit(long long sampleRate, int audioSampleRate) { - return nullptr; -} - -void Modem::disposeKit(ModemKit *kit) { - return; -} - -void Modem::demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) { - return; -} diff --git a/src/modules/modem/Modem.h b/src/modules/modem/Modem.h index 52587fe..e528b2d 100644 --- a/src/modules/modem/Modem.h +++ b/src/modules/modem/Modem.h @@ -36,12 +36,13 @@ class Modem { public: static void addModemFactory(std::string modemName, Modem *factorySingle); static ModemFactoryList getFactories(); + static Modem *makeModem(std::string modemType); - virtual Modem *factory(); + virtual Modem *factory() = 0; - virtual ModemKit *buildKit(long long sampleRate, int audioSampleRate); - virtual void disposeKit(ModemKit *kit); - virtual void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut); + virtual ModemKit *buildKit(long long sampleRate, int audioSampleRate) = 0; + virtual void disposeKit(ModemKit *kit) = 0; + virtual void demodulate(ModemKit *kit, ModemIQData *input, AudioThreadInput *audioOut) = 0; private: static ModemFactoryList modemFactories; }; \ No newline at end of file