GNU Radio 3.5.3.2 C++ API
|
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 /*! \brief Helper function for allocating complex fft buffers 00034 */ 00035 gr_complex* gri_fft_malloc_complex(int size); 00036 00037 /*! \brief Helper function for allocating float fft buffers 00038 */ 00039 float* gri_fft_malloc_float(int size); 00040 00041 /*! \brief Helper function for freeing fft buffers 00042 */ 00043 void gri_fft_free(void *b); 00044 00045 00046 /*! 00047 * \brief Export reference to planner mutex for those apps that 00048 * want to use FFTW w/o using the gri_fftw* classes. 00049 */ 00050 class GR_CORE_API gri_fft_planner { 00051 public: 00052 typedef boost::mutex::scoped_lock scoped_lock; 00053 /*! 00054 * Return reference to planner mutex 00055 */ 00056 static boost::mutex &mutex(); 00057 }; 00058 00059 /*! 00060 * \brief FFT: complex in, complex out 00061 * \ingroup misc 00062 */ 00063 class GR_CORE_API gri_fft_complex { 00064 int d_fft_size; 00065 int d_nthreads; 00066 gr_complex *d_inbuf; 00067 gr_complex *d_outbuf; 00068 void *d_plan; 00069 00070 public: 00071 gri_fft_complex (int fft_size, bool forward = true, int nthreads=1); 00072 virtual ~gri_fft_complex (); 00073 00074 /* 00075 * These return pointers to buffers owned by gri_fft_complex into which 00076 * input and output take place. It's done this way in order to 00077 * ensure optimal alignment for SIMD instructions. 00078 */ 00079 gr_complex *get_inbuf () const { return d_inbuf; } 00080 gr_complex *get_outbuf () const { return d_outbuf; } 00081 00082 int inbuf_length () const { return d_fft_size; } 00083 int outbuf_length () const { return d_fft_size; } 00084 00085 /*! 00086 * Set the number of threads to use for caclulation. 00087 */ 00088 void set_nthreads(int n); 00089 00090 /*! 00091 * Get the number of threads being used by FFTW 00092 */ 00093 int nthreads() const { return d_nthreads; } 00094 00095 /*! 00096 * compute FFT. The input comes from inbuf, the output is placed in outbuf. 00097 */ 00098 void execute (); 00099 }; 00100 00101 /*! 00102 * \brief FFT: real in, complex out 00103 * \ingroup misc 00104 */ 00105 class GR_CORE_API gri_fft_real_fwd { 00106 int d_fft_size; 00107 int d_nthreads; 00108 float *d_inbuf; 00109 gr_complex *d_outbuf; 00110 void *d_plan; 00111 00112 public: 00113 gri_fft_real_fwd (int fft_size, int nthreads=1); 00114 virtual ~gri_fft_real_fwd (); 00115 00116 /* 00117 * These return pointers to buffers owned by gri_fft_real_fwd into 00118 * which input and output take place. It's done this way in order 00119 * to ensure optimal alignment for SIMD instructions. 00120 */ 00121 float *get_inbuf () const { return d_inbuf; } 00122 gr_complex *get_outbuf () const { return d_outbuf; } 00123 00124 int inbuf_length () const { return d_fft_size; } 00125 int outbuf_length () const { return d_fft_size / 2 + 1; } 00126 00127 /*! 00128 * Set the number of threads to use for caclulation. 00129 */ 00130 void set_nthreads(int n); 00131 00132 /*! 00133 * Get the number of threads being used by FFTW 00134 */ 00135 int nthreads() const { return d_nthreads; } 00136 00137 /*! 00138 * compute FFT. The input comes from inbuf, the output is placed in outbuf. 00139 */ 00140 void execute (); 00141 }; 00142 00143 /*! 00144 * \brief FFT: complex in, float out 00145 * \ingroup misc 00146 */ 00147 class GR_CORE_API gri_fft_real_rev { 00148 int d_fft_size; 00149 int d_nthreads; 00150 gr_complex *d_inbuf; 00151 float *d_outbuf; 00152 void *d_plan; 00153 00154 public: 00155 gri_fft_real_rev (int fft_size, int nthreads=1); 00156 virtual ~gri_fft_real_rev (); 00157 00158 /* 00159 * These return pointers to buffers owned by gri_fft_real_rev into 00160 * which input and output take place. It's done this way in order 00161 * to ensure optimal alignment for SIMD instructions. 00162 */ 00163 gr_complex *get_inbuf () const { return d_inbuf; } 00164 float *get_outbuf () const { return d_outbuf; } 00165 00166 int inbuf_length () const { return d_fft_size / 2 + 1; } 00167 int outbuf_length () const { return d_fft_size; } 00168 00169 /*! 00170 * Set the number of threads to use for caclulation. 00171 */ 00172 void set_nthreads(int n); 00173 00174 /*! 00175 * Get the number of threads being used by FFTW 00176 */ 00177 int nthreads() const { return d_nthreads; } 00178 00179 /*! 00180 * compute FFT. The input comes from inbuf, the output is placed in outbuf. 00181 */ 00182 void execute (); 00183 }; 00184 00185 #endif