From a2e73a2d1bf3c78f41a86e857acff881b87ef4b1 Mon Sep 17 00:00:00 2001 From: Nelson Nunes Date: Wed, 25 Jan 2023 22:52:33 -0500 Subject: [PATCH] Fixes bug preventing last spectra from being output by SCTracker --- sctrac/TaskCore.cpp | 67 +++++++++++++++++++++++++++------------------ sctrac/TaskCore.h | 6 ++++ 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/sctrac/TaskCore.cpp b/sctrac/TaskCore.cpp index 407772d..f6c4031 100644 --- a/sctrac/TaskCore.cpp +++ b/sctrac/TaskCore.cpp @@ -298,6 +298,12 @@ int TaskCore::join() */ int TaskCore::finalize() { + /* process final completed spectrum */ + if (cfg.fft_overlap_factor > 1) + { + process_completed_spectrum(); + } + terminate_worker = true; this->processing_stage = STAGE_NONE; while (processing_stage != STAGE_EXIT) @@ -620,30 +626,7 @@ void TaskCore::doMaths() bool gotCompleteSpectrum = (this->num_ffts_computed >= (cfg.averaged_overlapped_ffts + (cfg.fft_overlap_factor - 1))); if (gotCompleteSpectrum) { - - /* scale */ - size_t nbytes; - ippsMulC_64f_I(1.0 / cfg.averaged_overlapped_ffts, reinterpret_cast(fft_accu_reim), cfg.singlesided_fft_out_len); - - /* convert double/float and copy to output Buffer */ - if (cfg.write_doubleprecision_data) - { - nbytes = cfg.singlesided_fft_out_len * sizeof(Ipp64f); - memcpy((void *)buf_out->getData(), (void *)fft_accu_reim, nbytes); - } - else - { - nbytes = cfg.singlesided_fft_out_len * sizeof(Ipp32f); - ippsConvert_64f32f(reinterpret_cast(fft_accu_reim), reinterpret_cast(this->vtemp[0]), cfg.singlesided_fft_out_len); - memcpy((void *)buf_out->getData(), (void *)this->vtemp[0], nbytes); - } - buf_out->setLength(nbytes); - - /* write full spectra to sink */ - if (cfg.write_output_spectra) - { - cfg.sinks[DSINK_SPECTRUM]->write(buf_out); // currently write() is a blocking call, buffercopying actually unnecessary... - } + process_completed_spectrum(); /* recompute the PLL coefficients and readjust the tones */ if (cfg.do_SCtracking) @@ -660,9 +643,6 @@ void TaskCore::doMaths() } } - /* statistics and join() output info */ - this->num_spectra_calculated++; - /* reset old results */ ippsZero_64fc(fft_accu_reim, cfg.fft_points); this->num_ffts_computed = 0; @@ -682,6 +662,39 @@ void TaskCore::doMaths() return; } +/** +* Scales a completed integrated spectrum and writes it to the sink +*/ +void TaskCore::process_completed_spectrum() +{ + /* scale */ + size_t nbytes; + ippsMulC_64f_I(1.0 / cfg.averaged_overlapped_ffts, reinterpret_cast(fft_accu_reim), cfg.singlesided_fft_out_len); + + /* convert double/float and copy to output Buffer */ + if (cfg.write_doubleprecision_data) + { + nbytes = cfg.singlesided_fft_out_len * sizeof(Ipp64f); + memcpy((void *)buf_out->getData(), (void *)fft_accu_reim, nbytes); + } + else + { + nbytes = cfg.singlesided_fft_out_len * sizeof(Ipp32f); + ippsConvert_64f32f(reinterpret_cast(fft_accu_reim), reinterpret_cast(this->vtemp[0]), cfg.singlesided_fft_out_len); + memcpy((void *)buf_out->getData(), (void *)this->vtemp[0], nbytes); + } + buf_out->setLength(nbytes); + + /* write full spectra to sink */ + if (cfg.write_output_spectra) + { + cfg.sinks[DSINK_SPECTRUM]->write(buf_out); // currently write() is a blocking call, buffercopying actually unnecessary... + } + + /* statistics and join() output info */ + this->num_spectra_calculated++; +} + /** * Applies the phase correction polynomial to a Nfft sized vector * of real input samples 0..Nfft-1. The polynomial for sample# n is diff --git a/sctrac/TaskCore.h b/sctrac/TaskCore.h index 2ac6ab6..6146547 100644 --- a/sctrac/TaskCore.h +++ b/sctrac/TaskCore.h @@ -230,6 +230,12 @@ public: bool shouldTerminate() { return terminate_worker; } private: + + /** + * Scales a completed integrated spectrum and writes it to the sink + */ + void process_completed_spectrum(); + /** * Applies the phase correction polynomial to a Nfft sized vector * of real input samples 0..Nfft-1. The polynomial for sample# n is -- GitLab