GNU Radio 3.4.0 C++ API
gri_fft.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2003,2008 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 #ifndef _GRI_FFT_H_
00023 #define _GRI_FFT_H_
00024 
00025 /*
00026  * Wrappers for FFTW single precision 1d dft
00027  */
00028 
00029 #include <gr_complex.h>
00030 #include <boost/thread.hpp>
00031 
00032 /*!
00033  * \brief Export reference to planner mutex for those apps that
00034  * want to use FFTW w/o using the gri_fftw* classes.
00035  */
00036 class gri_fft_planner {
00037 public:
00038   typedef boost::mutex::scoped_lock scoped_lock;
00039   /*!
00040    * Return reference to planner mutex
00041    */
00042   static boost::mutex &mutex();
00043 };
00044 
00045 /*!
00046  * \brief FFT: complex in, complex out
00047  * \ingroup misc
00048  */
00049 class gri_fft_complex {
00050   int         d_fft_size;
00051   gr_complex *d_inbuf;
00052   gr_complex *d_outbuf;
00053   void       *d_plan;
00054   
00055 public:
00056   gri_fft_complex (int fft_size, bool forward = true);
00057   virtual ~gri_fft_complex ();
00058 
00059   /*
00060    * These return pointers to buffers owned by gri_fft_complex into which
00061    * input and output take place.  It's done this way in order to
00062    * ensure optimal alignment for SIMD instructions.
00063    */
00064   gr_complex *get_inbuf ()  const { return d_inbuf; }
00065   gr_complex *get_outbuf () const { return d_outbuf; }
00066 
00067   int inbuf_length ()  const { return d_fft_size; }
00068   int outbuf_length () const { return d_fft_size; }
00069 
00070   /*!
00071    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
00072    */
00073   void execute ();
00074 };
00075 
00076 /*!
00077  * \brief FFT: real in, complex out
00078  * \ingroup misc
00079  */
00080 class gri_fft_real_fwd {
00081   int         d_fft_size;
00082   float      *d_inbuf;
00083   gr_complex *d_outbuf;
00084   void       *d_plan;
00085   
00086 public:
00087   gri_fft_real_fwd (int fft_size);
00088   virtual ~gri_fft_real_fwd ();
00089 
00090   /*
00091    * These return pointers to buffers owned by gri_fft_real_fwd into
00092    * which input and output take place.  It's done this way in order
00093    * to ensure optimal alignment for SIMD instructions.
00094    */
00095   float *get_inbuf ()      const { return d_inbuf; }
00096   gr_complex *get_outbuf () const { return d_outbuf; }
00097 
00098   int inbuf_length ()  const { return d_fft_size; }
00099   int outbuf_length () const { return d_fft_size / 2 + 1; }
00100 
00101   /*!
00102    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
00103    */
00104   void execute ();
00105 };
00106 
00107 /*!
00108  * \brief FFT: complex in, float out
00109  * \ingroup misc
00110  */
00111 class gri_fft_real_rev {
00112   int         d_fft_size;
00113   gr_complex *d_inbuf;
00114   float      *d_outbuf;
00115   void       *d_plan;
00116   
00117 public:
00118   gri_fft_real_rev (int fft_size);
00119   virtual ~gri_fft_real_rev ();
00120 
00121   /*
00122    * These return pointers to buffers owned by gri_fft_real_rev into
00123    * which input and output take place.  It's done this way in order
00124    * to ensure optimal alignment for SIMD instructions.
00125    */
00126   gr_complex *get_inbuf () const { return d_inbuf; }
00127   float *get_outbuf () const { return d_outbuf; }
00128 
00129   int inbuf_length ()  const { return d_fft_size / 2 + 1; }
00130   int outbuf_length () const { return d_fft_size; }
00131 
00132   /*!
00133    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
00134    */
00135   void execute ();
00136 };
00137 
00138 #endif