continuous updates for TDR/DFT with optional rate limit

This commit is contained in:
Jan Käberich 2024-05-08 20:00:15 +02:00
parent 5ae57bfa9a
commit 792a6a4974
5 changed files with 91 additions and 17 deletions

View file

@ -7,6 +7,9 @@
#include "ui_dftexplanationwidget.h"
#include "appwindow.h"
#include <chrono>
#include <thread>
#include <QDebug>
using namespace std;
@ -133,11 +136,6 @@ void Math::DFT::inputSamplesChanged(unsigned int begin, unsigned int end)
warning("Not enough input samples");
return;
}
// DFT is computationally expensive, only update at the end of sweep -> check if this is the first changed data in the next sweep
if(begin != 0) {
// not the end, do nothing
return;
}
// trigger calculation in thread
semphr.release();
success();
@ -159,6 +157,8 @@ Math::DFTThread::DFTThread(Math::DFT &dft)
void Math::DFTThread::run()
{
qDebug() << "DFT thread starting";
using namespace std::chrono;
auto lastCalc = system_clock::now();
while(1) {
dft.semphr.acquire();
// clear possible additional semaphores
@ -168,7 +168,13 @@ void Math::DFTThread::run()
qDebug() << "DFT thread exiting";
return;
}
qDebug() << "DFT thread calculating";
// limit update rate if configured in preferences
auto &p = Preferences::getInstance();
if(p.Acquisition.limitDFT) {
std::this_thread::sleep_until(lastCalc + duration<double>(1.0 / p.Acquisition.maxDFTrate));
lastCalc = system_clock::now();
}
// qDebug() << "DFT thread calculating";
double DC = dft.DCfreq;
TDR *tdr = nullptr;
if(dft.automaticDC) {