From 746eca8d3e6b128e2c1a518f50102cf77870ae2f Mon Sep 17 00:00:00 2001 From: "Charles J. Cliffe" Date: Mon, 1 Dec 2014 02:10:36 -0500 Subject: [PATCH] Demod worker now handles filter reconstruction Reduces audio jittering and only generates the last queued filter to save redundant regeneration during dragging. --- src/demod/DemodulatorThread.cpp | 68 ++++++++++++--------------- src/demod/DemodulatorWorkerThread.cpp | 9 ++-- 2 files changed, 35 insertions(+), 42 deletions(-) diff --git a/src/demod/DemodulatorThread.cpp b/src/demod/DemodulatorThread.cpp index 1fd4d92..42aa7e1 100644 --- a/src/demod/DemodulatorThread.cpp +++ b/src/demod/DemodulatorThread.cpp @@ -15,9 +15,9 @@ DemodulatorThread::DemodulatorThread(DemodulatorThreadInputQueue* pQueue) : workerQueue = new DemodulatorThreadWorkerCommandQueue; workerResults = new DemodulatorThreadWorkerResultQueue; - workerThread = new DemodulatorWorkerThread(workerQueue,workerResults); + workerThread = new DemodulatorWorkerThread(workerQueue, workerResults); - t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain,workerThread); + t_Worker = new std::thread(&DemodulatorWorkerThread::threadMain, workerThread); } void DemodulatorThread::initialize() { @@ -113,51 +113,16 @@ void DemodulatorThread::threadMain() { } if (bandwidthChanged) { - std::cout << "Requesting new filters from worker.." << std::endl; DemodulatorWorkerThreadCommand command(DemodulatorWorkerThreadCommand::DEMOD_WORKER_THREAD_CMD_BUILD_FILTERS); command.audioSampleRate = bandwidthParams.audioSampleRate; command.bandwidth = bandwidthParams.bandwidth; command.frequency = bandwidthParams.frequency; command.inputRate = bandwidthParams.inputRate; -// + workerQueue->push(command); - -// params = bandwidthParams; -// initialize(); -// while (!inputQueue->empty()) { // catch up -// inputQueue->pop(inp); -// } } } - if (!workerResults->empty()) { - while (!workerResults->empty()) { - DemodulatorWorkerThreadResult result; - workerResults->pop(result); - - switch (result.cmd) { - case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS: - std::cout << "New filters arrived from worker.." << std::endl; - firfilt_crcf_destroy(fir_filter); - msresamp_crcf_destroy(resampler); - msresamp_crcf_destroy(audio_resampler); - - fir_filter = result.fir_filter; - resampler = result.resampler; - audio_resampler = result.audio_resampler; - - resample_ratio = result.resample_ratio; - audio_resample_ratio = result.audio_resample_ratio; - - params.audioSampleRate = result.audioSampleRate; - params.bandwidth = result.bandwidth; - params.inputRate = result.inputRate; - - break; - } - } - } - if (!initialized) { continue; } @@ -246,6 +211,33 @@ void DemodulatorThread::threadMain() { visOutQueue->push(ati); } } + + if (!workerResults->empty()) { + while (!workerResults->empty()) { + DemodulatorWorkerThreadResult result; + workerResults->pop(result); + + switch (result.cmd) { + case DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS: + firfilt_crcf_destroy(fir_filter); + msresamp_crcf_destroy(resampler); + msresamp_crcf_destroy(audio_resampler); + + fir_filter = result.fir_filter; + resampler = result.resampler; + audio_resampler = result.audio_resampler; + + resample_ratio = result.resample_ratio; + audio_resample_ratio = result.audio_resample_ratio; + + params.audioSampleRate = result.audioSampleRate; + params.bandwidth = result.bandwidth; + params.inputRate = result.inputRate; + + break; + } + } + } } std::cout << "Demodulator thread done." << std::endl; diff --git a/src/demod/DemodulatorWorkerThread.cpp b/src/demod/DemodulatorWorkerThread.cpp index 84c44d6..f002737 100644 --- a/src/demod/DemodulatorWorkerThread.cpp +++ b/src/demod/DemodulatorWorkerThread.cpp @@ -18,7 +18,6 @@ void DemodulatorWorkerThread::threadMain() { bool filterChanged = false; DemodulatorWorkerThreadCommand filterCommand; DemodulatorWorkerThreadCommand command; - DemodulatorWorkerThreadResult result; bool done = false; while (!done) { @@ -33,7 +32,7 @@ void DemodulatorWorkerThread::threadMain() { } if (filterChanged) { - result.cmd = DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS; + DemodulatorWorkerThreadResult result(DemodulatorWorkerThreadResult::DEMOD_WORKER_THREAD_RESULT_FILTERS); result.resample_ratio = (float) (filterCommand.bandwidth) / (float) filterCommand.inputRate; result.audio_resample_ratio = (float) (filterCommand.audioSampleRate) / (float) filterCommand.bandwidth; @@ -58,10 +57,12 @@ void DemodulatorWorkerThread::threadMain() { liquid_firdes_kaiser(h_len, fc, As, mu, h); result.fir_filter = firfilt_crcf_create(h, h_len); - result.resampler = msresamp_crcf_create(result.resample_ratio, As); result.audio_resampler = msresamp_crcf_create(result.audio_resample_ratio, As); - // msresamp_crcf_print(audio_resampler); + + result.audioSampleRate = filterCommand.audioSampleRate; + result.bandwidth = filterCommand.bandwidth; + result.inputRate = filterCommand.inputRate; resultQueue->push(result); }