GNU Radio Manual and C++ API Reference  v3.9.2.0-89-gb7c7001e
The Free & Open Software Radio Ecosystem
fft.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003,2008,2012,2020 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef _FFT_FFT_H_
12 #define _FFT_FFT_H_
13 
14 /*
15  * Wrappers for FFTW single precision 1d dft
16  */
17 
18 #include <gnuradio/fft/api.h>
19 #include <gnuradio/gr_complex.h>
20 #include <gnuradio/logger.h>
21 #include <volk/volk_alloc.hh>
22 #include <boost/thread.hpp>
23 
24 namespace gr {
25 namespace fft {
26 
27 /*!
28  * \brief Export reference to planner mutex for those apps that
29  * want to use FFTW w/o using the fft_impl_fftw* classes.
30  */
32 {
33 public:
35  /*!
36  * Return reference to planner mutex
37  */
38  static boost::mutex& mutex();
39 };
40 
41 
42 /*!
43  \brief FFT: templated
44  \ingroup misc
45  */
46 
47 
48 template <class T, bool forward>
49 struct fft_inbuf {
50  typedef T type;
51 };
52 
53 template <>
54 struct fft_inbuf<float, false> {
55  typedef gr_complex type;
56 };
57 
58 
59 template <class T, bool forward>
60 struct fft_outbuf {
61  typedef T type;
62 };
63 
64 template <>
65 struct fft_outbuf<float, true> {
66  typedef gr_complex type;
67 };
68 
69 template <class T, bool forward>
70 class FFT_API fft
71 {
72  int d_nthreads;
73  volk::vector<typename fft_inbuf<T, forward>::type> d_inbuf;
74  volk::vector<typename fft_outbuf<T, forward>::type> d_outbuf;
75  void* d_plan;
76  gr::logger_ptr d_logger;
77  gr::logger_ptr d_debug_logger;
78  void initialize_plan(int fft_size);
79 
80 public:
81  fft(int fft_size, int nthreads = 1);
82  // Copy disabled due to d_plan.
83  fft(const fft&) = delete;
84  fft& operator=(const fft&) = delete;
85  virtual ~fft();
86 
87  /*
88  * These return pointers to buffers owned by fft_impl_fft_complex
89  * into which input and output take place. It's done this way in
90  * order to ensure optimal alignment for SIMD instructions.
91  */
92  typename fft_inbuf<T, forward>::type* get_inbuf() { return d_inbuf.data(); }
93  typename fft_outbuf<T, forward>::type* get_outbuf() { return d_outbuf.data(); }
94 
95  int inbuf_length() const { return d_inbuf.size(); }
96  int outbuf_length() const { return d_outbuf.size(); }
97 
98  /*!
99  * Set the number of threads to use for calculation.
100  */
101  void set_nthreads(int n);
102 
103  /*!
104  * Get the number of threads being used by FFTW
105  */
106  int nthreads() const { return d_nthreads; }
107 
108  /*!
109  * compute FFT. The input comes from inbuf, the output is placed in
110  * outbuf.
111  */
112  void execute();
113 };
114 
119 
120 } /* namespace fft */
121 } /*namespace gr */
122 
123 #endif /* _FFT_FFT_H_ */
Definition: fft.h:71
fft(const fft &)=delete
fft & operator=(const fft &)=delete
int inbuf_length() const
Definition: fft.h:95
fft_outbuf< T, forward >::type * get_outbuf()
Definition: fft.h:93
void execute()
fft(int fft_size, int nthreads=1)
int outbuf_length() const
Definition: fft.h:96
virtual ~fft()
fft_inbuf< T, forward >::type * get_inbuf()
Definition: fft.h:92
void set_nthreads(int n)
int nthreads() const
Definition: fft.h:106
Export reference to planner mutex for those apps that want to use FFTW w/o using the fft_impl_fftw* c...
Definition: fft.h:32
static boost::mutex & mutex()
boost::mutex::scoped_lock scoped_lock
Definition: fft.h:34
#define FFT_API
Definition: gr-fft/include/gnuradio/fft/api.h:18
std::complex< float > gr_complex
Definition: gr_complex.h:15
boost::mutex mutex
Definition: thread.h:37
boost::unique_lock< boost::mutex > scoped_lock
Definition: thread.h:38
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:29
log4cpp::Category * logger_ptr
GR_LOG macros.
Definition: logger.h:60
gr_complex type
Definition: fft.h:55
FFT: templated.
Definition: fft.h:49
T type
Definition: fft.h:50
gr_complex type
Definition: fft.h:66
Definition: fft.h:60
T type
Definition: fft.h:61