GNU Radio 3.5.1 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_core_api.h>
00030 #include <gr_complex.h>
00031 #include <boost/thread.hpp>
00032 
00033 /*!
00034  * \brief Export reference to planner mutex for those apps that
00035  * want to use FFTW w/o using the gri_fftw* classes.
00036  */
00037 class GR_CORE_API gri_fft_planner {
00038 public:
00039   typedef boost::mutex::scoped_lock scoped_lock;
00040   /*!
00041    * Return reference to planner mutex
00042    */
00043   static boost::mutex &mutex();
00044 };
00045 
00046 /*!
00047  * \brief FFT: complex in, complex out
00048  * \ingroup misc
00049  */
00050 class GR_CORE_API gri_fft_complex {
00051   int         d_fft_size;
00052   gr_complex *d_inbuf;
00053   gr_complex *d_outbuf;
00054   void       *d_plan;
00055   
00056 public:
00057   gri_fft_complex (int fft_size, bool forward = true);
00058   virtual ~gri_fft_complex ();
00059 
00060   /*
00061    * These return pointers to buffers owned by gri_fft_complex into which
00062    * input and output take place.  It's done this way in order to
00063    * ensure optimal alignment for SIMD instructions.
00064    */
00065   gr_complex *get_inbuf ()  const { return d_inbuf; }
00066   gr_complex *get_outbuf () const { return d_outbuf; }
00067 
00068   int inbuf_length ()  const { return d_fft_size; }
00069   int outbuf_length () const { return d_fft_size; }
00070 
00071   /*!
00072    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
00073    */
00074   void execute ();
00075 };
00076 
00077 /*!
00078  * \brief FFT: real in, complex out
00079  * \ingroup misc
00080  */
00081 class GR_CORE_API gri_fft_real_fwd {
00082   int         d_fft_size;
00083   float      *d_inbuf;
00084   gr_complex *d_outbuf;
00085   void       *d_plan;
00086   
00087 public:
00088   gri_fft_real_fwd (int fft_size);
00089   virtual ~gri_fft_real_fwd ();
00090 
00091   /*
00092    * These return pointers to buffers owned by gri_fft_real_fwd into
00093    * which input and output take place.  It's done this way in order
00094    * to ensure optimal alignment for SIMD instructions.
00095    */
00096   float *get_inbuf ()      const { return d_inbuf; }
00097   gr_complex *get_outbuf () const { return d_outbuf; }
00098 
00099   int inbuf_length ()  const { return d_fft_size; }
00100   int outbuf_length () const { return d_fft_size / 2 + 1; }
00101 
00102   /*!
00103    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
00104    */
00105   void execute ();
00106 };
00107 
00108 /*!
00109  * \brief FFT: complex in, float out
00110  * \ingroup misc
00111  */
00112 class GR_CORE_API gri_fft_real_rev {
00113   int         d_fft_size;
00114   gr_complex *d_inbuf;
00115   float      *d_outbuf;
00116   void       *d_plan;
00117   
00118 public:
00119   gri_fft_real_rev (int fft_size);
00120   virtual ~gri_fft_real_rev ();
00121 
00122   /*
00123    * These return pointers to buffers owned by gri_fft_real_rev into
00124    * which input and output take place.  It's done this way in order
00125    * to ensure optimal alignment for SIMD instructions.
00126    */
00127   gr_complex *get_inbuf () const { return d_inbuf; }
00128   float *get_outbuf () const { return d_outbuf; }
00129 
00130   int inbuf_length ()  const { return d_fft_size / 2 + 1; }
00131   int outbuf_length () const { return d_fft_size; }
00132 
00133   /*!
00134    * compute FFT.  The input comes from inbuf, the output is placed in outbuf.
00135    */
00136   void execute ();
00137 };
00138 
00139 #endif