mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-04-06 11:38:48 -04:00
Demod worker now handles filter reconstruction
Reduces audio jittering and only generates the last queued filter to save redundant regeneration during dragging.
This commit is contained in:
parent
38b1393c44
commit
746eca8d3e
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user