diff options
author | Johnathan Corgan | 2012-04-29 11:44:27 -0700 |
---|---|---|
committer | Johnathan Corgan | 2012-04-29 11:44:27 -0700 |
commit | 399969c8f9ad2ac19acd0f2299b0424dec2390b1 (patch) | |
tree | 9fe5a7a761ea2926d274d6ad64bec53eb6905c85 /gr-fft/include | |
parent | 8613b52b42585f1f0f1ca73b778cd47ec2548292 (diff) | |
download | gnuradio-399969c8f9ad2ac19acd0f2299b0424dec2390b1.tar.gz gnuradio-399969c8f9ad2ac19acd0f2299b0424dec2390b1.tar.bz2 gnuradio-399969c8f9ad2ac19acd0f2299b0424dec2390b1.zip |
fft: put helper classes in namespace
Diffstat (limited to 'gr-fft/include')
-rw-r--r-- | gr-fft/include/fft/CMakeLists.txt | 4 | ||||
-rw-r--r-- | gr-fft/include/fft/fft.h | 195 | ||||
-rw-r--r-- | gr-fft/include/fft/fft_impl_fft.h | 189 | ||||
-rw-r--r-- | gr-fft/include/fft/goertzel.h (renamed from gr-fft/include/fft/fft_impl_goertzel.h) | 59 |
4 files changed, 230 insertions, 217 deletions
diff --git a/gr-fft/include/fft/CMakeLists.txt b/gr-fft/include/fft/CMakeLists.txt index 33a8a1d21..bce3da674 100644 --- a/gr-fft/include/fft/CMakeLists.txt +++ b/gr-fft/include/fft/CMakeLists.txt @@ -22,11 +22,11 @@ ######################################################################## install(FILES api.h + fft.h fft_vcc.h fft_vfc.h + goertzel.h goertzel_fc.h - fft_impl_fft.h - fft_impl_goertzel.h DESTINATION ${GR_INCLUDE_DIR}/gnuradio/fft COMPONENT "fft_devel" ) diff --git a/gr-fft/include/fft/fft.h b/gr-fft/include/fft/fft.h new file mode 100644 index 000000000..5cc2e21e8 --- /dev/null +++ b/gr-fft/include/fft/fft.h @@ -0,0 +1,195 @@ +/* -*- c++ -*- */ +/* + * Copyright 2003,2008,2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef _FFT_FFT_H_ +#define _FFT_FFT_H_ + +/* + * Wrappers for FFTW single precision 1d dft + */ + +#include <fft/api.h> +#include <gr_complex.h> +#include <boost/thread.hpp> + +namespace gr { + namespace fft { + + + /*! \brief Helper function for allocating complex fft buffers + */ + gr_complex* malloc_complex(int size); + + /*! \brief Helper function for allocating float fft buffers + */ + float* malloc_float(int size); + + /*! \brief Helper function for freeing fft buffers + */ + void free(void *b); + + /*! + * \brief Export reference to planner mutex for those apps that + * want to use FFTW w/o using the fft_impl_fftw* classes. + */ + class FFT_API planner { + public: + typedef boost::mutex::scoped_lock scoped_lock; + /*! + * Return reference to planner mutex + */ + static boost::mutex &mutex(); + }; + + /*! + * \brief FFT: complex in, complex out + * \ingroup misc + */ + class FFT_API fft_complex { + int d_fft_size; + int d_nthreads; + gr_complex *d_inbuf; + gr_complex *d_outbuf; + void *d_plan; + + public: + fft_complex(int fft_size, bool forward = true, int nthreads=1); + virtual ~fft_complex(); + + /* + * These return pointers to buffers owned by fft_impl_fft_complex + * into which input and output take place. It's done this way in + * order to ensure optimal alignment for SIMD instructions. + */ + gr_complex *get_inbuf() const { return d_inbuf; } + gr_complex *get_outbuf() const { return d_outbuf; } + + int inbuf_length() const { return d_fft_size; } + int outbuf_length() const { return d_fft_size; } + + /*! + * Set the number of threads to use for caclulation. + */ + void set_nthreads(int n); + + /*! + * Get the number of threads being used by FFTW + */ + int nthreads() const { return d_nthreads; } + + /*! + * compute FFT. The input comes from inbuf, the output is placed in + * outbuf. + */ + void execute(); + }; + + /*! + * \brief FFT: real in, complex out + * \ingroup misc + */ + class FFT_API fft_real_fwd { + int d_fft_size; + int d_nthreads; + float *d_inbuf; + gr_complex *d_outbuf; + void *d_plan; + + public: + fft_real_fwd (int fft_size, int nthreads=1); + virtual ~fft_real_fwd (); + + /* + * These return pointers to buffers owned by fft_impl_fft_real_fwd + * into which input and output take place. It's done this way in + * order to ensure optimal alignment for SIMD instructions. + */ + float *get_inbuf() const { return d_inbuf; } + gr_complex *get_outbuf() const { return d_outbuf; } + + int inbuf_length() const { return d_fft_size; } + int outbuf_length() const { return d_fft_size / 2 + 1; } + + /*! + * Set the number of threads to use for caclulation. + */ + void set_nthreads(int n); + + /*! + * Get the number of threads being used by FFTW + */ + int nthreads() const { return d_nthreads; } + + /*! + * compute FFT. The input comes from inbuf, the output is placed in + * outbuf. + */ + void execute(); + }; + + /*! + * \brief FFT: complex in, float out + * \ingroup misc + */ + class FFT_API fft_real_rev { + int d_fft_size; + int d_nthreads; + gr_complex *d_inbuf; + float *d_outbuf; + void *d_plan; + + public: + fft_real_rev(int fft_size, int nthreads=1); + virtual ~fft_real_rev(); + + /* + * These return pointers to buffers owned by fft_impl_fft_real_rev + * into which input and output take place. It's done this way in + * order to ensure optimal alignment for SIMD instructions. + */ + gr_complex *get_inbuf() const { return d_inbuf; } + float *get_outbuf() const { return d_outbuf; } + + int inbuf_length() const { return d_fft_size / 2 + 1; } + int outbuf_length() const { return d_fft_size; } + + /*! + * Set the number of threads to use for caclulation. + */ + void set_nthreads(int n); + + /*! + * Get the number of threads being used by FFTW + */ + int nthreads() const { return d_nthreads; } + + /*! + * compute FFT. The input comes from inbuf, the output is placed in + * outbuf. + */ + void execute(); + }; + + } /* namespace fft */ +} /*namespace gr */ + +#endif /* _FFT_FFT_H_ */ diff --git a/gr-fft/include/fft/fft_impl_fft.h b/gr-fft/include/fft/fft_impl_fft.h deleted file mode 100644 index c27f2ae64..000000000 --- a/gr-fft/include/fft/fft_impl_fft.h +++ /dev/null @@ -1,189 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2003,2008,2012 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _FFT_IMPL_FFT_H_ -#define _FFT_IMPL_FFT_H_ - -/* - * Wrappers for FFTW single precision 1d dft - */ - -#include <fft/api.h> -#include <gr_complex.h> -#include <boost/thread.hpp> - -/*! \brief Helper function for allocating complex fft buffers - */ -gr_complex* fft_impl_fft_malloc_complex(int size); - -/*! \brief Helper function for allocating float fft buffers - */ -float* fft_impl_fft_malloc_float(int size); - -/*! \brief Helper function for freeing fft buffers - */ -void fft_impl_fft_free(void *b); - - -/*! - * \brief Export reference to planner mutex for those apps that - * want to use FFTW w/o using the fft_impl_fftw* classes. - */ -class FFT_API fft_impl_fft_planner { - public: - typedef boost::mutex::scoped_lock scoped_lock; - /*! - * Return reference to planner mutex - */ - static boost::mutex &mutex(); -}; - -/*! - * \brief FFT: complex in, complex out - * \ingroup misc - */ -class FFT_API fft_impl_fft_complex { - int d_fft_size; - int d_nthreads; - gr_complex *d_inbuf; - gr_complex *d_outbuf; - void *d_plan; - -public: - fft_impl_fft_complex(int fft_size, bool forward = true, int nthreads=1); - virtual ~fft_impl_fft_complex(); - - /* - * These return pointers to buffers owned by fft_impl_fft_complex - * into which input and output take place. It's done this way in - * order to ensure optimal alignment for SIMD instructions. - */ - gr_complex *get_inbuf() const { return d_inbuf; } - gr_complex *get_outbuf() const { return d_outbuf; } - - int inbuf_length() const { return d_fft_size; } - int outbuf_length() const { return d_fft_size; } - - /*! - * Set the number of threads to use for caclulation. - */ - void set_nthreads(int n); - - /*! - * Get the number of threads being used by FFTW - */ - int nthreads() const { return d_nthreads; } - - /*! - * compute FFT. The input comes from inbuf, the output is placed in - * outbuf. - */ - void execute(); -}; - -/*! - * \brief FFT: real in, complex out - * \ingroup misc - */ -class FFT_API fft_impl_fft_real_fwd { - int d_fft_size; - int d_nthreads; - float *d_inbuf; - gr_complex *d_outbuf; - void *d_plan; - -public: - fft_impl_fft_real_fwd (int fft_size, int nthreads=1); - virtual ~fft_impl_fft_real_fwd (); - - /* - * These return pointers to buffers owned by fft_impl_fft_real_fwd - * into which input and output take place. It's done this way in - * order to ensure optimal alignment for SIMD instructions. - */ - float *get_inbuf() const { return d_inbuf; } - gr_complex *get_outbuf() const { return d_outbuf; } - - int inbuf_length() const { return d_fft_size; } - int outbuf_length() const { return d_fft_size / 2 + 1; } - - /*! - * Set the number of threads to use for caclulation. - */ - void set_nthreads(int n); - - /*! - * Get the number of threads being used by FFTW - */ - int nthreads() const { return d_nthreads; } - - /*! - * compute FFT. The input comes from inbuf, the output is placed in - * outbuf. - */ - void execute(); -}; - -/*! - * \brief FFT: complex in, float out - * \ingroup misc - */ -class FFT_API fft_impl_fft_real_rev { - int d_fft_size; - int d_nthreads; - gr_complex *d_inbuf; - float *d_outbuf; - void *d_plan; - -public: - fft_impl_fft_real_rev(int fft_size, int nthreads=1); - virtual ~fft_impl_fft_real_rev(); - - /* - * These return pointers to buffers owned by fft_impl_fft_real_rev - * into which input and output take place. It's done this way in - * order to ensure optimal alignment for SIMD instructions. - */ - gr_complex *get_inbuf() const { return d_inbuf; } - float *get_outbuf() const { return d_outbuf; } - - int inbuf_length() const { return d_fft_size / 2 + 1; } - int outbuf_length() const { return d_fft_size; } - - /*! - * Set the number of threads to use for caclulation. - */ - void set_nthreads(int n); - - /*! - * Get the number of threads being used by FFTW - */ - int nthreads() const { return d_nthreads; } - - /*! - * compute FFT. The input comes from inbuf, the output is placed in - * outbuf. - */ - void execute(); -}; - -#endif diff --git a/gr-fft/include/fft/fft_impl_goertzel.h b/gr-fft/include/fft/goertzel.h index b6aa71d31..ff37355e6 100644 --- a/gr-fft/include/fft/fft_impl_goertzel.h +++ b/gr-fft/include/fft/goertzel.h @@ -26,32 +26,39 @@ #include <fft/api.h> #include <gr_types.h> -/*! - * \brief Implements Goertzel single-bin DFT calculation - * \ingroup misc - */ -class FFT_API fft_impl_goertzel -{ -public: - fft_impl_goertzel() {} - fft_impl_goertzel(int rate, int len, float freq); - void set_params(int rate, int len, float freq); - - // Process a input array - gr_complex batch(float *in); - - // Process sample by sample - void input(const float &in); - gr_complex output(); - bool ready() const { return d_processed == d_len; } +namespace gr { + namespace fft { -private: - float d_d1; - float d_d2; - float d_wr; - float d_wi; - int d_len; - int d_processed; -}; + /*! + * \brief Implements Goertzel single-bin DFT calculation + * \ingroup misc + */ + class FFT_API goertzel + { + public: + goertzel(){} + goertzel(int rate, int len, float freq); + + void set_params(int rate, int len, float freq); + + // Process a input array + gr_complex batch(float *in); + + // Process sample by sample + void input(const float &in); + gr_complex output(); + bool ready() const { return d_processed == d_len; } + + private: + float d_d1; + float d_d2; + float d_wr; + float d_wi; + int d_len; + int d_processed; + }; + + } /* namespace fft */ +} /* namespace gr */ #endif /* INCLUDED_FFT_IMPL_GOERTZEL_H */ |