[worker] more on removing qt dependency

This commit is contained in:
thibaud keller 2024-12-07 23:07:36 +00:00
parent 60d64e97ef
commit 34f96b508a
3 changed files with 18 additions and 15 deletions

View file

@ -1,4 +1,4 @@
#include "Amuencha.hpp"
#include "AmuenchaModel.hpp"
namespace Amuencha
{

View file

@ -84,7 +84,8 @@ void Amuencha::Model::worker::new_data(float* chunk, int size)
if (waiting_time != CYCLE_PERIOD) {
// and now resume the cyclic scheduling
waiting_time = CYCLE_PERIOD;
condition.wakeOne();
// condition.wakeOne();
condition.notify_one();
}
// Otherwise, do NOT wake the other thread, keep the low-freq cycle to decrease load
@ -161,7 +162,7 @@ void Amuencha::Model::worker::setup()
frequencies.resize(num_bins);
for (int b{0}; b < num_bins; ++b)
{
float bratio = (float)b / (num_bins - 1.);
float bratio = static_cast<float>(b / (num_bins - 1.));
frequencies[b] = exp2(log2_fmin + (log2_fmax - log2_fmin) * bratio);
}
@ -200,13 +201,13 @@ void Amuencha::Model::worker::setup()
if (i < window_size - 4)
{
v4sf tfs = {
(float)(i - window_size - 1) / sampling_rate,
(float)(i + 1 - window_size - 1) / sampling_rate,
(float)(i + 2 - window_size - 1) / sampling_rate,
(float)(i + 3 - window_size - 1) / sampling_rate
(i - window_size - 1) / sampling_rate,
(i + 1 - window_size - 1) / sampling_rate,
(i + 2 - window_size - 1) / sampling_rate,
(i + 3 - window_size - 1) / sampling_rate
};
tfs *= (float)(-two_pi * f);
tfs *= (-two_pi * f);
v4sf sin_tf, cos_tf;
sincos_ps(tfs, &sin_tf, &cos_tf);
@ -224,7 +225,7 @@ void Amuencha::Model::worker::setup()
i += 4;
continue;
}
float t = (float)(i - window_size - 1) / sampling_rate;
float t = (i - window_size - 1) / sampling_rate;
float re = cosf(-two_pi * t * f);
float im = sinf(-two_pi * t * f);
v4sf ws = {
@ -250,7 +251,8 @@ void Amuencha::Model::worker::work()
{
// Solution with a wait condition + time
// other possible solution = timer, but that would need to be stopped
mutex.lock();
std::unique_lock lk(mutex);
lk.lock();
// waiting_time is a mutex-protected info
waiting_time = CYCLE_PERIOD;
@ -258,7 +260,7 @@ void Amuencha::Model::worker::work()
// loop starts with mutex locked
while (true)
{
condition.wait_for(&mutex, waiting_time);
condition.wait_for(lk, std::chrono::milliseconds(waiting_time));
if (status == QUIT_NOW) break;
@ -270,7 +272,7 @@ void Amuencha::Model::worker::work()
vector<pair<float*, int>> chunks;
chunks.swap(this->chunks);
status = NO_DATA; // will be updated if new data indeed arrives
mutex.unlock();
lk.unlock();
// Now, we can take the time to do the frequency computations
data_mutex.lock();
@ -329,7 +331,7 @@ void Amuencha::Model::worker::work()
data_mutex.unlock();
// relock for the condition wait
mutex.lock();
lk.lock();
continue;
}
@ -337,7 +339,7 @@ void Amuencha::Model::worker::work()
waiting_time = ULONG_MAX;
// keep the lock for next loop
}
mutex.unlock();
lk.unlock();
}
void Amuencha::Model::worker::invalidate_samples()

View file

@ -24,7 +24,6 @@
#include <condition_variable>
#include <vector>
#include <map>
#include <complex>
#include <functional>
#include <Amuencha/AmuenchaModel.hpp>
@ -37,6 +36,8 @@ public:
worker();
~worker();
void work();
void new_data(float *chunk, int size);
// Called from DSP thread