summaryrefslogtreecommitdiff
path: root/gr-fft/include/gnuradio/fft/fft.h
diff options
context:
space:
mode:
Diffstat (limited to 'gr-fft/include/gnuradio/fft/fft.h')
-rw-r--r--gr-fft/include/gnuradio/fft/fft.h137
1 files changed, 36 insertions, 101 deletions
diff --git a/gr-fft/include/gnuradio/fft/fft.h b/gr-fft/include/gnuradio/fft/fft.h
index cc47a4f169..6163d2f83f 100644
--- a/gr-fft/include/gnuradio/fft/fft.h
+++ b/gr-fft/include/gnuradio/fft/fft.h
@@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
- * Copyright 2003,2008,2012 Free Software Foundation, Inc.
+ * Copyright 2003,2008,2012,2020 Free Software Foundation, Inc.
*
* This file is part of GNU Radio
*
@@ -38,135 +38,65 @@ public:
static boost::mutex& mutex();
};
-/*!
- * \brief FFT: complex in, complex out
- * \ingroup misc
- */
-class FFT_API fft_complex
-{
- int d_nthreads;
- volk::vector<gr_complex> d_inbuf;
- volk::vector<gr_complex> d_outbuf;
- void* d_plan;
- gr::logger_ptr d_logger;
- gr::logger_ptr d_debug_logger;
-
-public:
- fft_complex(int fft_size, bool forward = true, int nthreads = 1);
- // Copy disabled due to d_plan.
- fft_complex(const fft_complex&) = delete;
- fft_complex& operator=(const fft_complex&) = delete;
- 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() { return d_inbuf.data(); }
- gr_complex* get_outbuf() { return d_outbuf.data(); }
-
- int inbuf_length() const { return d_inbuf.size(); }
- int outbuf_length() const { return d_outbuf.size(); }
-
- /*!
- * Set the number of threads to use for calculation.
- */
- 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
+ \brief FFT: templated
+ \ingroup misc
*/
-class FFT_API fft_real_fwd
-{
- int d_nthreads;
- volk::vector<float> d_inbuf;
- volk::vector<gr_complex> d_outbuf;
- void* d_plan;
- gr::logger_ptr d_logger;
- gr::logger_ptr d_debug_logger;
-public:
- fft_real_fwd(int fft_size, int nthreads = 1);
- // Copy disabled due to d_plan.
- fft_real_fwd(const fft_real_fwd&) = delete;
- fft_real_fwd& operator=(const fft_real_fwd&) = delete;
- 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() { return d_inbuf.data(); }
- gr_complex* get_outbuf() { return d_outbuf.data(); }
+template <class T, bool forward>
+struct fft_inbuf {
+ typedef T type;
+};
- int inbuf_length() const { return d_inbuf.size(); }
- int outbuf_length() const { return d_outbuf.size(); }
+template <>
+struct fft_inbuf<float, false> {
+ typedef gr_complex type;
+};
- /*!
- * 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; }
+template <class T, bool forward>
+struct fft_outbuf {
+ typedef T type;
+};
- /*!
- * compute FFT. The input comes from inbuf, the output is placed in
- * outbuf.
- */
- void execute();
+template <>
+struct fft_outbuf<float, true> {
+ typedef gr_complex type;
};
-/*!
- * \brief FFT: complex in, float out
- * \ingroup misc
- */
-class FFT_API fft_real_rev
+template <class T, bool forward>
+class FFT_API fft
{
int d_nthreads;
- volk::vector<gr_complex> d_inbuf;
- volk::vector<float> d_outbuf;
+ volk::vector<typename fft_inbuf<T, forward>::type> d_inbuf;
+ volk::vector<typename fft_outbuf<T, forward>::type> d_outbuf;
void* d_plan;
gr::logger_ptr d_logger;
gr::logger_ptr d_debug_logger;
+ void initialize_plan(int fft_size);
public:
- fft_real_rev(int fft_size, int nthreads = 1);
+ fft(int fft_size, int nthreads = 1);
// Copy disabled due to d_plan.
- fft_real_rev(const fft_real_rev&) = delete;
- fft_real_rev& operator=(const fft_real_rev&) = delete;
- virtual ~fft_real_rev();
+ fft(const fft&) = delete;
+ fft& operator=(const fft&) = delete;
+ virtual ~fft();
/*
- * These return pointers to buffers owned by fft_impl_fft_real_rev
+ * 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() { return d_inbuf.data(); }
- float* get_outbuf() { return d_outbuf.data(); }
+ typename fft_inbuf<T, forward>::type* get_inbuf() { return d_inbuf.data(); }
+ typename fft_outbuf<T, forward>::type* get_outbuf() { return d_outbuf.data(); }
int inbuf_length() const { return d_inbuf.size(); }
int outbuf_length() const { return d_outbuf.size(); }
/*!
- * Set the number of threads to use for caclulation.
+ * Set the number of threads to use for calculation.
*/
void set_nthreads(int n);
@@ -182,6 +112,11 @@ public:
void execute();
};
+using fft_complex_fwd = fft<gr_complex, true>;
+using fft_complex_rev = fft<gr_complex, false>;
+using fft_real_fwd = fft<float, true>;
+using fft_real_rev = fft<float, false>;
+
} /* namespace fft */
} /*namespace gr */