~lann/guitartuner/master

« back to all changes in this revision

Viewing changes to src/worker.cpp

  • Committer: lannic
  • Date: 2020-08-28 08:35:05 UTC
  • Revision ID: git-v1:23693ca8d21e0ccf5902face3fb73b4df6570441
Portaudio integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "SoundCard.h"
 
2
#include "worker.h"
 
3
#include <chrono>
 
4
 
 
5
Worker::Worker() : m_Mutex(), m_shall_stop(false)
 
6
{
 
7
 
 
8
}
 
9
 
 
10
Worker::~Worker()
 
11
{
 
12
}
 
13
 
 
14
void Worker::stop_work()
 
15
{
 
16
     std::lock_guard<std::mutex> lock(m_Mutex);
 
17
     m_shall_stop=true;
 
18
}
 
19
 
 
20
void Worker::do_work(CSoundCard *caller)
 
21
{
 
22
  {
 
23
       std::lock_guard<std::mutex> lock(m_Mutex);
 
24
       data=caller->Get_Data();
 
25
       m_shall_stop=false;
 
26
  }
 
27
  {
 
28
       do
 
29
       {
 
30
            std::this_thread::sleep_for(std::chrono::milliseconds(250));
 
31
            {
 
32
                 std::lock_guard<std::mutex> lock(m_Mutex);
 
33
                 fft.fft_float(data->num_Samples, 0, data->RealIn, data->ImagIn,
 
34
                               data->data_out.RealOut, data->data_out.ImagOut);
 
35
                 caller->notify();
 
36
            }
 
37
            if (m_shall_stop)
 
38
            {
 
39
                 break;
 
40
            }
 
41
       } while (true);
 
42
  }
 
43
  caller->notify();
 
44
}