GNU Radio 3.5.3.2 C++ API
gri_fft.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2003,2008 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef _GRI_FFT_H_
23 #define _GRI_FFT_H_
24 
25 /*
26  * Wrappers for FFTW single precision 1d dft
27  */
28 
29 #include <gr_core_api.h>
30 #include <gr_complex.h>
31 #include <boost/thread.hpp>
32 
33 /*! \brief Helper function for allocating complex fft buffers
34  */
36 
37 /*! \brief Helper function for allocating float fft buffers
38  */
39 float* gri_fft_malloc_float(int size);
40 
41 /*! \brief Helper function for freeing fft buffers
42  */
43 void gri_fft_free(void *b);
44 
45 
46 /*!
47  * \brief Export reference to planner mutex for those apps that
48  * want to use FFTW w/o using the gri_fftw* classes.
49  */
51 public:
53  /*!
54  * Return reference to planner mutex
55  */
56  static boost::mutex &mutex();
57 };
58 
59 /*!
60  * \brief FFT: complex in, complex out
61  * \ingroup misc
62  */
64  int d_fft_size;
65  int d_nthreads;
66  gr_complex *d_inbuf;
67  gr_complex *d_outbuf;
68  void *d_plan;
69 
70 public:
71  gri_fft_complex (int fft_size, bool forward = true, int nthreads=1);
72  virtual ~gri_fft_complex ();
73 
74  /*
75  * These return pointers to buffers owned by gri_fft_complex into which
76  * input and output take place. It's done this way in order to
77  * ensure optimal alignment for SIMD instructions.
78  */
79  gr_complex *get_inbuf () const { return d_inbuf; }
80  gr_complex *get_outbuf () const { return d_outbuf; }
81 
82  int inbuf_length () const { return d_fft_size; }
83  int outbuf_length () const { return d_fft_size; }
84 
85  /*!
86  * Set the number of threads to use for caclulation.
87  */
88  void set_nthreads(int n);
89 
90  /*!
91  * Get the number of threads being used by FFTW
92  */
93  int nthreads() const { return d_nthreads; }
94 
95  /*!
96  * compute FFT. The input comes from inbuf, the output is placed in outbuf.
97  */
98  void execute ();
99 };
100 
101 /*!
102  * \brief FFT: real in, complex out
103  * \ingroup misc
104  */
106  int d_fft_size;
107  int d_nthreads;
108  float *d_inbuf;
109  gr_complex *d_outbuf;
110  void *d_plan;
111 
112 public:
113  gri_fft_real_fwd (int fft_size, int nthreads=1);
114  virtual ~gri_fft_real_fwd ();
115 
116  /*
117  * These return pointers to buffers owned by gri_fft_real_fwd into
118  * which input and output take place. It's done this way in order
119  * to ensure optimal alignment for SIMD instructions.
120  */
121  float *get_inbuf () const { return d_inbuf; }
122  gr_complex *get_outbuf () const { return d_outbuf; }
123 
124  int inbuf_length () const { return d_fft_size; }
125  int outbuf_length () const { return d_fft_size / 2 + 1; }
126 
127  /*!
128  * Set the number of threads to use for caclulation.
129  */
130  void set_nthreads(int n);
131 
132  /*!
133  * Get the number of threads being used by FFTW
134  */
135  int nthreads() const { return d_nthreads; }
136 
137  /*!
138  * compute FFT. The input comes from inbuf, the output is placed in outbuf.
139  */
140  void execute ();
141 };
142 
143 /*!
144  * \brief FFT: complex in, float out
145  * \ingroup misc
146  */
148  int d_fft_size;
149  int d_nthreads;
150  gr_complex *d_inbuf;
151  float *d_outbuf;
152  void *d_plan;
153 
154 public:
155  gri_fft_real_rev (int fft_size, int nthreads=1);
156  virtual ~gri_fft_real_rev ();
157 
158  /*
159  * These return pointers to buffers owned by gri_fft_real_rev into
160  * which input and output take place. It's done this way in order
161  * to ensure optimal alignment for SIMD instructions.
162  */
163  gr_complex *get_inbuf () const { return d_inbuf; }
164  float *get_outbuf () const { return d_outbuf; }
165 
166  int inbuf_length () const { return d_fft_size / 2 + 1; }
167  int outbuf_length () const { return d_fft_size; }
168 
169  /*!
170  * Set the number of threads to use for caclulation.
171  */
172  void set_nthreads(int n);
173 
174  /*!
175  * Get the number of threads being used by FFTW
176  */
177  int nthreads() const { return d_nthreads; }
178 
179  /*!
180  * compute FFT. The input comes from inbuf, the output is placed in outbuf.
181  */
182  void execute ();
183 };
184 
185 #endif