SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
fftwengine.cpp
Go to the documentation of this file.
1 #include <QTime>
2 #include "dsp/fftwengine.h"
3 
5  m_plans(),
6  m_currentPlan(NULL)
7 {
8 }
9 
11 {
12  freeAll();
13 }
14 
15 void FFTWEngine::configure(int n, bool inverse)
16 {
17  for(Plans::const_iterator it = m_plans.begin(); it != m_plans.end(); ++it) {
18  if(((*it)->n == n) && ((*it)->inverse == inverse)) {
19  m_currentPlan = *it;
20  return;
21  }
22  }
23 
24  m_currentPlan = new Plan;
25  m_currentPlan->n = n;
26  m_currentPlan->inverse = inverse;
27  m_currentPlan->in = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * n);
28  m_currentPlan->out = (fftwf_complex*)fftwf_malloc(sizeof(fftwf_complex) * n);
29  QTime t;
30  t.start();
31  m_globalPlanMutex.lock();
32  m_currentPlan->plan = fftwf_plan_dft_1d(n, m_currentPlan->in, m_currentPlan->out, inverse ? FFTW_BACKWARD : FFTW_FORWARD, FFTW_PATIENT);
33  m_globalPlanMutex.unlock();
34  qDebug("FFT: creating FFTW plan (n=%d,%s) took %dms", n, inverse ? "inverse" : "forward", t.elapsed());
35  m_plans.push_back(m_currentPlan);
36 }
37 
39 {
40  if(m_currentPlan != NULL)
41  fftwf_execute(m_currentPlan->plan);
42 }
43 
45 {
46  if(m_currentPlan != NULL)
47  return reinterpret_cast<Complex*>(m_currentPlan->in);
48  else return NULL;
49 }
50 
52 {
53  if(m_currentPlan != NULL)
54  return reinterpret_cast<Complex*>(m_currentPlan->out);
55  else return NULL;
56 }
57 
59 
61 {
62  for(Plans::iterator it = m_plans.begin(); it != m_plans.end(); ++it) {
63  fftwf_destroy_plan((*it)->plan);
64  fftwf_free((*it)->in);
65  fftwf_free((*it)->out);
66  delete *it;
67  }
68  m_plans.clear();
69 }
Complex * out()
Definition: fftwengine.cpp:51
fftwf_complex * in
Definition: fftwengine.h:28
Plan * m_currentPlan
Definition: fftwengine.h:33
Complex * in()
Definition: fftwengine.cpp:44
void freeAll()
Definition: fftwengine.cpp:60
void configure(int n, bool inverse)
Definition: fftwengine.cpp:15
fftwf_complex * out
Definition: fftwengine.h:29
void transform()
Definition: fftwengine.cpp:38
static QMutex m_globalPlanMutex
Definition: fftwengine.h:22
fftwf_plan plan
Definition: fftwengine.h:27
std::complex< Real > Complex
Definition: dsptypes.h:43
Plans m_plans
Definition: fftwengine.h:32