diff options
author | Thomas Habets <thomas@habets.se> | 2019-12-23 22:51:49 +0000 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2020-01-03 00:15:53 +0100 |
commit | 9a3270e8752f1bbac36eac49310b3fe4fa1020ca (patch) | |
tree | de854556f32da38cd1b477d7870df0c85ed7c82a /gr-filter | |
parent | 2024c428c25cd6832da1a05009bcb59d46ecfc2e (diff) |
gr-filter/fft_filter: Use smart instead of raw pointers
Diffstat (limited to 'gr-filter')
-rw-r--r-- | gr-filter/include/gnuradio/filter/fft_filter.h | 31 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter.cc | 80 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter_ccc_impl.cc | 21 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter_ccc_impl.h | 4 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter_ccf_impl.cc | 21 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter_ccf_impl.h | 4 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter_fff_impl.cc | 21 | ||||
-rw-r--r-- | gr-filter/lib/fft_filter_fff_impl.h | 4 |
8 files changed, 53 insertions, 133 deletions
diff --git a/gr-filter/include/gnuradio/filter/fft_filter.h b/gr-filter/include/gnuradio/filter/fft_filter.h index c58d05252b..b50451ec74 100644 --- a/gr-filter/include/gnuradio/filter/fft_filter.h +++ b/gr-filter/include/gnuradio/filter/fft_filter.h @@ -26,6 +26,7 @@ #include <gnuradio/fft/fft.h> #include <gnuradio/filter/api.h> #include <gnuradio/gr_complex.h> +#include <volk/volk_alloc.hh> #include <vector> namespace gr { @@ -70,13 +71,13 @@ private: int d_ntaps; int d_nsamples; int d_fftsize; // fftsize = ntaps + nsamples - 1 - int d_decimation; - fft::fft_real_fwd* d_fwdfft; // forward "plan" - fft::fft_real_rev* d_invfft; // inverse "plan" + const int d_decimation; + std::unique_ptr<fft::fft_real_fwd> d_fwdfft; // forward "plan" + std::unique_ptr<fft::fft_real_rev> d_invfft; // inverse "plan" int d_nthreads; // number of FFTW threads to use std::vector<float> d_tail; // state carried between blocks for overlap-add std::vector<float> d_taps; // stores time domain taps - gr_complex* d_xformed_taps; // Fourier xformed taps + volk::vector<gr_complex> d_xformed_taps; // Fourier xformed taps void compute_sizes(int ntaps); int tailsize() const { return d_ntaps - 1; } @@ -95,8 +96,6 @@ public: */ fft_filter_fff(int decimation, const std::vector<float>& taps, int nthreads = 1); - ~fft_filter_fff(); - /*! * \brief Set new taps for the filter. * @@ -174,13 +173,13 @@ private: int d_ntaps; int d_nsamples; int d_fftsize; // fftsize = ntaps + nsamples - 1 - int d_decimation; - fft::fft_complex* d_fwdfft; // forward "plan" - fft::fft_complex* d_invfft; // inverse "plan" + const int d_decimation; + std::unique_ptr<fft::fft_complex> d_fwdfft; // forward "plan" + std::unique_ptr<fft::fft_complex> d_invfft; // inverse "plan" int d_nthreads; // number of FFTW threads to use std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add std::vector<gr_complex> d_taps; // stores time domain taps - gr_complex* d_xformed_taps; // Fourier xformed taps + volk::vector<gr_complex> d_xformed_taps; // Fourier xformed taps void compute_sizes(int ntaps); int tailsize() const { return d_ntaps - 1; } @@ -199,8 +198,6 @@ public: */ fft_filter_ccc(int decimation, const std::vector<gr_complex>& taps, int nthreads = 1); - ~fft_filter_ccc(); - /*! * \brief Set new taps for the filter. * @@ -278,13 +275,13 @@ private: int d_ntaps; int d_nsamples; int d_fftsize; // fftsize = ntaps + nsamples - 1 - int d_decimation; - fft::fft_complex* d_fwdfft; // forward "plan" - fft::fft_complex* d_invfft; // inverse "plan" + const int d_decimation; + std::unique_ptr<fft::fft_complex> d_fwdfft; // forward "plan" + std::unique_ptr<fft::fft_complex> d_invfft; // inverse "plan" int d_nthreads; // number of FFTW threads to use std::vector<gr_complex> d_tail; // state carried between blocks for overlap-add std::vector<float> d_taps; // stores time domain taps - gr_complex* d_xformed_taps; // Fourier xformed taps + volk::vector<gr_complex> d_xformed_taps; // Fourier xformed taps void compute_sizes(int ntaps); int tailsize() const { return d_ntaps - 1; } @@ -303,8 +300,6 @@ public: */ fft_filter_ccf(int decimation, const std::vector<float>& taps, int nthreads = 1); - ~fft_filter_ccf(); - /*! * \brief Set new taps for the filter. * diff --git a/gr-filter/lib/fft_filter.cc b/gr-filter/lib/fft_filter.cc index 0da55bbaf1..6a79f729cc 100644 --- a/gr-filter/lib/fft_filter.cc +++ b/gr-filter/lib/fft_filter.cc @@ -24,6 +24,7 @@ #include "config.h" #endif +#include <boost/smart_ptr/make_unique.hpp> #include <gnuradio/filter/fft_filter.h> #include <volk/volk.h> #include <cstring> @@ -40,22 +41,11 @@ fft_filter_fff::fft_filter_fff(int decimation, int nthreads) : d_fftsize(-1), d_decimation(decimation), - d_fwdfft(NULL), - d_invfft(NULL), - d_nthreads(nthreads), - d_xformed_taps(NULL) + d_nthreads(nthreads) { set_taps(taps); } -fft_filter_fff::~fft_filter_fff() -{ - delete d_fwdfft; - delete d_invfft; - if (d_xformed_taps != NULL) - volk_free(d_xformed_taps); -} - /* * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps */ @@ -106,14 +96,9 @@ void fft_filter_fff::compute_sizes(int ntaps) // compute new plans if (d_fftsize != old_fftsize) { - delete d_fwdfft; - delete d_invfft; - if (d_xformed_taps != NULL) - volk_free(d_xformed_taps); - d_fwdfft = new fft::fft_real_fwd(d_fftsize); - d_invfft = new fft::fft_real_rev(d_fftsize); - d_xformed_taps = (gr_complex*)volk_malloc( - sizeof(gr_complex) * (d_fftsize / 2 + 1), volk_get_alignment()); + d_fwdfft = boost::make_unique<fft::fft_real_fwd>(d_fftsize); + d_invfft = boost::make_unique<fft::fft_real_rev>(d_fftsize); + d_xformed_taps.resize(d_fftsize / 2 + 1); } } @@ -148,10 +133,9 @@ int fft_filter_fff::filter(int nitems, const float* input, float* output) d_fwdfft->execute(); // compute fwd xform gr_complex* a = d_fwdfft->get_outbuf(); - gr_complex* b = d_xformed_taps; gr_complex* c = d_invfft->get_inbuf(); - volk_32fc_x2_multiply_32fc_a(c, a, b, d_fftsize / 2 + 1); + volk_32fc_x2_multiply_32fc_a(c, a, d_xformed_taps.data(), d_xformed_taps.size()); d_invfft->execute(); // compute inv xform @@ -187,22 +171,11 @@ fft_filter_ccc::fft_filter_ccc(int decimation, int nthreads) : d_fftsize(-1), d_decimation(decimation), - d_fwdfft(NULL), - d_invfft(NULL), - d_nthreads(nthreads), - d_xformed_taps(NULL) + d_nthreads(nthreads) { set_taps(taps); } -fft_filter_ccc::~fft_filter_ccc() -{ - delete d_fwdfft; - delete d_invfft; - if (d_xformed_taps != NULL) - volk_free(d_xformed_taps); -} - /* * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps */ @@ -253,14 +226,9 @@ void fft_filter_ccc::compute_sizes(int ntaps) // compute new plans if (d_fftsize != old_fftsize) { - delete d_fwdfft; - delete d_invfft; - if (d_xformed_taps != NULL) - volk_free(d_xformed_taps); - d_fwdfft = new fft::fft_complex(d_fftsize, true, d_nthreads); - d_invfft = new fft::fft_complex(d_fftsize, false, d_nthreads); - d_xformed_taps = (gr_complex*)volk_malloc(sizeof(gr_complex) * d_fftsize, - volk_get_alignment()); + d_fwdfft = boost::make_unique<fft::fft_complex>(d_fftsize, true, d_nthreads); + d_invfft = boost::make_unique<fft::fft_complex>(d_fftsize, false, d_nthreads); + d_xformed_taps.resize(d_fftsize); } } @@ -294,7 +262,7 @@ int fft_filter_ccc::filter(int nitems, const gr_complex* input, gr_complex* outp d_fwdfft->execute(); // compute fwd xform gr_complex* a = d_fwdfft->get_outbuf(); - gr_complex* b = d_xformed_taps; + gr_complex* b = d_xformed_taps.data(); gr_complex* c = d_invfft->get_inbuf(); volk_32fc_x2_multiply_32fc_a(c, a, b, d_fftsize); @@ -334,22 +302,11 @@ fft_filter_ccf::fft_filter_ccf(int decimation, int nthreads) : d_fftsize(-1), d_decimation(decimation), - d_fwdfft(NULL), - d_invfft(NULL), - d_nthreads(nthreads), - d_xformed_taps(NULL) + d_nthreads(nthreads) { set_taps(taps); } -fft_filter_ccf::~fft_filter_ccf() -{ - delete d_fwdfft; - delete d_invfft; - if (d_xformed_taps != NULL) - volk_free(d_xformed_taps); -} - /* * determines d_ntaps, d_nsamples, d_fftsize, d_xformed_taps */ @@ -400,14 +357,9 @@ void fft_filter_ccf::compute_sizes(int ntaps) // compute new plans if (d_fftsize != old_fftsize) { - delete d_fwdfft; - delete d_invfft; - if (d_xformed_taps != NULL) - volk_free(d_xformed_taps); - d_fwdfft = new fft::fft_complex(d_fftsize, true, d_nthreads); - d_invfft = new fft::fft_complex(d_fftsize, false, d_nthreads); - d_xformed_taps = (gr_complex*)volk_malloc(sizeof(gr_complex) * d_fftsize, - volk_get_alignment()); + d_fwdfft = boost::make_unique<fft::fft_complex>(d_fftsize, true, d_nthreads); + d_invfft = boost::make_unique<fft::fft_complex>(d_fftsize, false, d_nthreads); + d_xformed_taps.resize(d_fftsize); } } @@ -443,7 +395,7 @@ int fft_filter_ccf::filter(int nitems, const gr_complex* input, gr_complex* outp d_fwdfft->execute(); // compute fwd xform gr_complex* a = d_fwdfft->get_outbuf(); - gr_complex* b = d_xformed_taps; + gr_complex* b = d_xformed_taps.data(); gr_complex* c = d_invfft->get_inbuf(); volk_32fc_x2_multiply_32fc_a(c, a, b, d_fftsize); diff --git a/gr-filter/lib/fft_filter_ccc_impl.cc b/gr-filter/lib/fft_filter_ccc_impl.cc index 78b91b4007..40612f66ad 100644 --- a/gr-filter/lib/fft_filter_ccc_impl.cc +++ b/gr-filter/lib/fft_filter_ccc_impl.cc @@ -48,19 +48,16 @@ fft_filter_ccc_impl::fft_filter_ccc_impl(int decimation, io_signature::make(1, 1, sizeof(gr_complex)), io_signature::make(1, 1, sizeof(gr_complex)), decimation), - d_updated(false) + d_updated(false), + d_filter(decimation, taps, nthreads) { set_history(1); - d_filter = new kernel::fft_filter_ccc(decimation, taps, nthreads); - d_new_taps = taps; - d_nsamples = d_filter->set_taps(taps); + d_nsamples = d_filter.set_taps(taps); set_output_multiple(d_nsamples); } -fft_filter_ccc_impl::~fft_filter_ccc_impl() { delete d_filter; } - void fft_filter_ccc_impl::set_taps(const std::vector<gr_complex>& taps) { d_new_taps = taps; @@ -71,16 +68,12 @@ std::vector<gr_complex> fft_filter_ccc_impl::taps() const { return d_new_taps; } void fft_filter_ccc_impl::set_nthreads(int n) { - if (d_filter) - d_filter->set_nthreads(n); + d_filter.set_nthreads(n); } int fft_filter_ccc_impl::nthreads() const { - if (d_filter) - return d_filter->nthreads(); - else - return 0; + return d_filter.nthreads(); } int fft_filter_ccc_impl::work(int noutput_items, @@ -91,13 +84,13 @@ int fft_filter_ccc_impl::work(int noutput_items, gr_complex* out = (gr_complex*)output_items[0]; if (d_updated) { - d_nsamples = d_filter->set_taps(d_new_taps); + d_nsamples = d_filter.set_taps(d_new_taps); d_updated = false; set_output_multiple(d_nsamples); return 0; // output multiple may have changed } - d_filter->filter(noutput_items, in, out); + d_filter.filter(noutput_items, in, out); return noutput_items; } diff --git a/gr-filter/lib/fft_filter_ccc_impl.h b/gr-filter/lib/fft_filter_ccc_impl.h index edf89e214d..419f7b32e4 100644 --- a/gr-filter/lib/fft_filter_ccc_impl.h +++ b/gr-filter/lib/fft_filter_ccc_impl.h @@ -34,7 +34,7 @@ class FILTER_API fft_filter_ccc_impl : public fft_filter_ccc private: int d_nsamples; bool d_updated; - kernel::fft_filter_ccc* d_filter; + kernel::fft_filter_ccc d_filter; std::vector<gr_complex> d_new_taps; public: @@ -42,8 +42,6 @@ public: const std::vector<gr_complex>& taps, int nthreads = 1); - ~fft_filter_ccc_impl(); - void set_taps(const std::vector<gr_complex>& taps); std::vector<gr_complex> taps() const; diff --git a/gr-filter/lib/fft_filter_ccf_impl.cc b/gr-filter/lib/fft_filter_ccf_impl.cc index 3d614a5034..4b8d1ce3c6 100644 --- a/gr-filter/lib/fft_filter_ccf_impl.cc +++ b/gr-filter/lib/fft_filter_ccf_impl.cc @@ -48,19 +48,16 @@ fft_filter_ccf_impl::fft_filter_ccf_impl(int decimation, io_signature::make(1, 1, sizeof(gr_complex)), io_signature::make(1, 1, sizeof(gr_complex)), decimation), - d_updated(false) + d_updated(false), + d_filter(decimation, taps, nthreads) { set_history(1); - d_filter = new kernel::fft_filter_ccf(decimation, taps, nthreads); - d_new_taps = taps; - d_nsamples = d_filter->set_taps(taps); + d_nsamples = d_filter.set_taps(taps); set_output_multiple(d_nsamples); } -fft_filter_ccf_impl::~fft_filter_ccf_impl() { delete d_filter; } - void fft_filter_ccf_impl::set_taps(const std::vector<float>& taps) { d_new_taps = taps; @@ -71,16 +68,12 @@ std::vector<float> fft_filter_ccf_impl::taps() const { return d_new_taps; } void fft_filter_ccf_impl::set_nthreads(int n) { - if (d_filter) - d_filter->set_nthreads(n); + d_filter.set_nthreads(n); } int fft_filter_ccf_impl::nthreads() const { - if (d_filter) - return d_filter->nthreads(); - else - return 0; + return d_filter.nthreads(); } int fft_filter_ccf_impl::work(int noutput_items, @@ -91,13 +84,13 @@ int fft_filter_ccf_impl::work(int noutput_items, gr_complex* out = (gr_complex*)output_items[0]; if (d_updated) { - d_nsamples = d_filter->set_taps(d_new_taps); + d_nsamples = d_filter.set_taps(d_new_taps); d_updated = false; set_output_multiple(d_nsamples); return 0; // output multiple may have changed } - d_filter->filter(noutput_items, in, out); + d_filter.filter(noutput_items, in, out); return noutput_items; } diff --git a/gr-filter/lib/fft_filter_ccf_impl.h b/gr-filter/lib/fft_filter_ccf_impl.h index 69a132ba9d..d08f919dea 100644 --- a/gr-filter/lib/fft_filter_ccf_impl.h +++ b/gr-filter/lib/fft_filter_ccf_impl.h @@ -35,14 +35,12 @@ class FILTER_API fft_filter_ccf_impl : public fft_filter_ccf private: int d_nsamples; bool d_updated; - kernel::fft_filter_ccf* d_filter; + kernel::fft_filter_ccf d_filter; std::vector<float> d_new_taps; public: fft_filter_ccf_impl(int decimation, const std::vector<float>& taps, int nthreads = 1); - ~fft_filter_ccf_impl(); - void set_taps(const std::vector<float>& taps); std::vector<float> taps() const; diff --git a/gr-filter/lib/fft_filter_fff_impl.cc b/gr-filter/lib/fft_filter_fff_impl.cc index 8100beba0f..a3c5aba2bf 100644 --- a/gr-filter/lib/fft_filter_fff_impl.cc +++ b/gr-filter/lib/fft_filter_fff_impl.cc @@ -49,19 +49,16 @@ fft_filter_fff_impl::fft_filter_fff_impl(int decimation, io_signature::make(1, 1, sizeof(float)), io_signature::make(1, 1, sizeof(float)), decimation), - d_updated(false) + d_updated(false), + d_filter(decimation, taps, nthreads) { set_history(1); - d_filter = new kernel::fft_filter_fff(decimation, taps, nthreads); - d_new_taps = taps; - d_nsamples = d_filter->set_taps(taps); + d_nsamples = d_filter.set_taps(taps); set_output_multiple(d_nsamples); } -fft_filter_fff_impl::~fft_filter_fff_impl() { delete d_filter; } - void fft_filter_fff_impl::set_taps(const std::vector<float>& taps) { d_new_taps = taps; @@ -72,16 +69,12 @@ std::vector<float> fft_filter_fff_impl::taps() const { return d_new_taps; } void fft_filter_fff_impl::set_nthreads(int n) { - if (d_filter) - d_filter->set_nthreads(n); + d_filter.set_nthreads(n); } int fft_filter_fff_impl::nthreads() const { - if (d_filter) - return d_filter->nthreads(); - else - return 0; + return d_filter.nthreads(); } int fft_filter_fff_impl::work(int noutput_items, @@ -92,13 +85,13 @@ int fft_filter_fff_impl::work(int noutput_items, float* out = (float*)output_items[0]; if (d_updated) { - d_nsamples = d_filter->set_taps(d_new_taps); + d_nsamples = d_filter.set_taps(d_new_taps); d_updated = false; set_output_multiple(d_nsamples); return 0; // output multiple may have changed } - d_filter->filter(noutput_items, in, out); + d_filter.filter(noutput_items, in, out); return noutput_items; } diff --git a/gr-filter/lib/fft_filter_fff_impl.h b/gr-filter/lib/fft_filter_fff_impl.h index 22bf34c909..784adabe10 100644 --- a/gr-filter/lib/fft_filter_fff_impl.h +++ b/gr-filter/lib/fft_filter_fff_impl.h @@ -34,14 +34,12 @@ class FILTER_API fft_filter_fff_impl : public fft_filter_fff private: int d_nsamples; bool d_updated; - kernel::fft_filter_fff* d_filter; + kernel::fft_filter_fff d_filter; std::vector<float> d_new_taps; public: fft_filter_fff_impl(int decimation, const std::vector<float>& taps, int nthreads = 1); - ~fft_filter_fff_impl(); - void set_taps(const std::vector<float>& taps); std::vector<float> taps() const; |