Imported Upstream version 3.2.2
[debian/gnuradio] / gnuradio-core / src / lib / general / gri_fft.h
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_complex.h>
30 #include <boost/thread.hpp>
31
32 /*!
33  * \brief Export reference to planner mutex for those apps that
34  * want to use FFTW w/o using the gri_fftw* classes.
35  */
36 class gri_fft_planner {
37 public:
38   typedef boost::mutex::scoped_lock scoped_lock;
39   /*!
40    * Return reference to planner mutex
41    */
42   static boost::mutex &mutex();
43 };
44
45 /*!
46  * \brief FFT: complex in, complex out
47  * \ingroup misc
48  */
49 class gri_fft_complex {
50   int         d_fft_size;
51   gr_complex *d_inbuf;
52   gr_complex *d_outbuf;
53   void       *d_plan;
54   
55 public:
56   gri_fft_complex (int fft_size, bool forward = true);
57   virtual ~gri_fft_complex ();
58
59   /*
60    * These return pointers to buffers owned by gri_fft_complex into which
61    * input and output take place.  It's done this way in order to
62    * ensure optimal alignment for SIMD instructions.
63    */
64   gr_complex *get_inbuf ()  const { return d_inbuf; }
65   gr_complex *get_outbuf () const { return d_outbuf; }
66
67   int inbuf_length ()  const { return d_fft_size; }
68   int outbuf_length () const { return d_fft_size; }
69
70   /*!
71    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
72    */
73   void execute ();
74 };
75
76 /*!
77  * \brief FFT: real in, complex out
78  * \ingroup misc
79  */
80 class gri_fft_real_fwd {
81   int         d_fft_size;
82   float      *d_inbuf;
83   gr_complex *d_outbuf;
84   void       *d_plan;
85   
86 public:
87   gri_fft_real_fwd (int fft_size);
88   virtual ~gri_fft_real_fwd ();
89
90   /*
91    * These return pointers to buffers owned by gri_fft_real_fwd into
92    * which input and output take place.  It's done this way in order
93    * to ensure optimal alignment for SIMD instructions.
94    */
95   float *get_inbuf ()      const { return d_inbuf; }
96   gr_complex *get_outbuf () const { return d_outbuf; }
97
98   int inbuf_length ()  const { return d_fft_size; }
99   int outbuf_length () const { return d_fft_size / 2 + 1; }
100
101   /*!
102    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
103    */
104   void execute ();
105 };
106
107 /*!
108  * \brief FFT: complex in, float out
109  * \ingroup misc
110  */
111 class gri_fft_real_rev {
112   int         d_fft_size;
113   gr_complex *d_inbuf;
114   float      *d_outbuf;
115   void       *d_plan;
116   
117 public:
118   gri_fft_real_rev (int fft_size);
119   virtual ~gri_fft_real_rev ();
120
121   /*
122    * These return pointers to buffers owned by gri_fft_real_rev into
123    * which input and output take place.  It's done this way in order
124    * to ensure optimal alignment for SIMD instructions.
125    */
126   gr_complex *get_inbuf () const { return d_inbuf; }
127   float *get_outbuf () const { return d_outbuf; }
128
129   int inbuf_length ()  const { return d_fft_size / 2 + 1; }
130   int outbuf_length () const { return d_fft_size; }
131
132   /*!
133    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
134    */
135   void execute ();
136 };
137
138 #endif