diff options
author | Thomas Habets <thomas@habets.se> | 2021-02-19 17:38:58 +0000 |
---|---|---|
committer | Martin Braun <martin@gnuradio.org> | 2021-02-26 01:17:25 -0800 |
commit | 4b7006db76b570e4d916e263301333d2f4d2a2df (patch) | |
tree | fb618398b0a1900f2b47749d6a2928570c9ebbf2 | |
parent | 044b4a3b49b67adfe53e0e88f9adf847a25fad61 (diff) |
qtgui: Remove manual memory management
Signed-off-by: Thomas Habets <thomas@habets.se>
39 files changed, 619 insertions, 942 deletions
diff --git a/gr-qtgui/include/gnuradio/qtgui/const_sink_c.h b/gr-qtgui/include/gnuradio/qtgui/const_sink_c.h index c70fe04cdc..db4c22b77e 100644 --- a/gr-qtgui/include/gnuradio/qtgui/const_sink_c.h +++ b/gr-qtgui/include/gnuradio/qtgui/const_sink_c.h @@ -137,7 +137,16 @@ public: virtual int nsamps() const = 0; virtual void reset() = 0; + // Disallow copy/move because of the pointer. + const_sink_c(const const_sink_c&) = delete; + const_sink_c& operator=(const const_sink_c&) = delete; + const_sink_c(const_sink_c&&) = delete; + const_sink_c& operator=(const_sink_c&&) = delete; + QApplication* d_qApplication; + +protected: + const_sink_c() = default; }; } /* namespace qtgui */ diff --git a/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h b/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h index 42a351f833..db96e07625 100644 --- a/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h +++ b/gr-qtgui/include/gnuradio/qtgui/spectrumUpdateEvents.h @@ -14,6 +14,7 @@ #include <gnuradio/high_res_timer.h> #include <gnuradio/qtgui/api.h> #include <gnuradio/tags.h> +#include <volk/volk_alloc.hh> #include <QEvent> #include <QString> #include <complex> @@ -109,7 +110,7 @@ private: class TimeUpdateEvent : public QEvent { public: - TimeUpdateEvent(const std::vector<double*> timeDomainPoints, + TimeUpdateEvent(const std::vector<volk::vector<double>> timeDomainPoints, const uint64_t numTimeDomainDataPoints, const std::vector<std::vector<gr::tag_t>> tags); @@ -139,7 +140,8 @@ private: class FreqUpdateEvent : public QEvent { public: - FreqUpdateEvent(const std::vector<double*> dataPoints, const uint64_t numDataPoints); + FreqUpdateEvent(const std::vector<volk::vector<double>> dataPoints, + const uint64_t numDataPoints); ~FreqUpdateEvent() override; @@ -178,8 +180,8 @@ private: class QTGUI_API ConstUpdateEvent : public QEvent { public: - ConstUpdateEvent(const std::vector<double*> realDataPoints, - const std::vector<double*> imagDataPoints, + ConstUpdateEvent(const std::vector<volk::vector<double>> realDataPoints, + const std::vector<volk::vector<double>> imagDataPoints, const uint64_t numDataPoints); ~ConstUpdateEvent() override; @@ -207,7 +209,7 @@ private: class WaterfallUpdateEvent : public QEvent { public: - WaterfallUpdateEvent(const std::vector<double*> dataPoints, + WaterfallUpdateEvent(const std::vector<volk::vector<double>> dataPoints, const uint64_t numDataPoints, const gr::high_res_timer_type dataTimestamp); @@ -238,7 +240,7 @@ private: class TimeRasterUpdateEvent : public QEvent { public: - TimeRasterUpdateEvent(const std::vector<double*> dataPoints, + TimeRasterUpdateEvent(const std::vector<volk::vector<double>> dataPoints, const uint64_t numDataPoints); ~TimeRasterUpdateEvent() override; @@ -280,7 +282,8 @@ private: class HistogramUpdateEvent : public QEvent { public: - HistogramUpdateEvent(const std::vector<double*> points, const uint64_t npoints); + HistogramUpdateEvent(const std::vector<volk::vector<double>> points, + const uint64_t npoints); ~HistogramUpdateEvent() override; diff --git a/gr-qtgui/lib/ber_sink_b_impl.cc b/gr-qtgui/lib/ber_sink_b_impl.cc index 0740858c66..c223570a0b 100644 --- a/gr-qtgui/lib/ber_sink_b_impl.cc +++ b/gr-qtgui/lib/ber_sink_b_impl.cc @@ -61,10 +61,8 @@ ber_sink_b_impl::ber_sink_b_impl(std::vector<float> esnos, d_total_errors.reserve(curves * esnos.size()); for (int j = 0; j < curves; j++) { - d_esno_buffers.push_back( - (double*)volk_malloc(esnos.size() * sizeof(double), volk_get_alignment())); - d_ber_buffers.push_back( - (double*)volk_malloc(esnos.size() * sizeof(double), volk_get_alignment())); + d_esno_buffers.emplace_back(esnos.size()); + d_ber_buffers.emplace_back(esnos.size()); for (int i = 0; i < d_nconnections; i++) { d_esno_buffers[j][i] = esnos[i]; @@ -75,10 +73,8 @@ ber_sink_b_impl::ber_sink_b_impl(std::vector<float> esnos, } // Now add the known curves - d_esno_buffers.push_back( - (double*)volk_malloc(esnos.size() * sizeof(double), volk_get_alignment())); - d_ber_buffers.push_back( - (double*)volk_malloc(esnos.size() * sizeof(double), volk_get_alignment())); + d_esno_buffers.emplace_back(esnos.size()); + d_ber_buffers.emplace_back(esnos.size()); for (size_t i = 0; i < esnos.size(); i++) { double e = pow(10.0, esnos[i] / 10.0); d_esno_buffers[curves][i] = esnos[i]; @@ -114,11 +110,6 @@ ber_sink_b_impl::~ber_sink_b_impl() if (!d_main_gui->isClosed()) { d_main_gui->close(); } - - for (unsigned int i = 0; i < d_esno_buffers.size(); i++) { - volk_free(d_esno_buffers[i]); - volk_free(d_ber_buffers[i]); - } } bool ber_sink_b_impl::check_topology(int ninputs, int noutputs) diff --git a/gr-qtgui/lib/ber_sink_b_impl.h b/gr-qtgui/lib/ber_sink_b_impl.h index 195bad4586..05aa91011e 100644 --- a/gr-qtgui/lib/ber_sink_b_impl.h +++ b/gr-qtgui/lib/ber_sink_b_impl.h @@ -16,6 +16,8 @@ #include <gnuradio/high_res_timer.h> #include <gnuradio/qtgui/constellationdisplayform.h> +#include <volk/volk_alloc.hh> + namespace gr { namespace qtgui { @@ -24,10 +26,10 @@ class QTGUI_API ber_sink_b_impl : public ber_sink_b private: void initialize(); - std::vector<double*> d_esno_buffers; - std::vector<double*> d_ber_buffers; + std::vector<volk::vector<double>> d_esno_buffers; + std::vector<volk::vector<double>> d_ber_buffers; - ConstellationDisplayForm* d_main_gui; + ConstellationDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; std::vector<int> d_total_errors; int d_ber_min_errors; @@ -49,6 +51,12 @@ public: QWidget* parent = NULL); ~ber_sink_b_impl() override; + // Disallow copy/move because of the raw pointers. + ber_sink_b_impl(const ber_sink_b_impl&) = delete; + ber_sink_b_impl& operator=(const ber_sink_b_impl&) = delete; + ber_sink_b_impl(ber_sink_b_impl&&) = delete; + ber_sink_b_impl& operator=(ber_sink_b_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/const_sink_c_impl.cc b/gr-qtgui/lib/const_sink_c_impl.cc index 2f203901d7..568949c977 100644 --- a/gr-qtgui/lib/const_sink_c_impl.cc +++ b/gr-qtgui/lib/const_sink_c_impl.cc @@ -18,6 +18,7 @@ #include <gnuradio/prefs.h> #include <qwt_symbol.h> #include <volk/volk.h> +#include <volk/volk_alloc.hh> #include <cstring> namespace gr { @@ -42,39 +43,15 @@ const_sink_c_impl::const_sink_c_impl(int size, d_nconnections(nconnections), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - - d_index = 0; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); - for (int i = 0; i < d_nconnections; i++) { - d_residbufs_real.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - d_residbufs_imag.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - memset(d_residbufs_real[i], 0, d_buffer_size * sizeof(double)); - memset(d_residbufs_imag[i], 0, d_buffer_size * sizeof(double)); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs_real.emplace_back(d_buffer_size); + d_residbufs_imag.emplace_back(d_buffer_size); } - // Used for PDU message input - d_residbufs_real.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - d_residbufs_imag.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - memset(d_residbufs_real[d_nconnections], 0, d_buffer_size * sizeof(double)); - memset(d_residbufs_imag[d_nconnections], 0, d_buffer_size * sizeof(double)); - // Set alignment properties for VOLK const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); set_alignment(std::max(1, alignment_multiple)); @@ -90,14 +67,6 @@ const_sink_c_impl::~const_sink_c_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // d_main_gui is a qwidget destroyed with its parent - for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs_real[i]); - volk_free(d_residbufs_imag[i]); - } - - delete d_argv; } bool const_sink_c_impl::check_topology(int ninputs, int noutputs) @@ -276,15 +245,10 @@ void const_sink_c_impl::set_nsamps(const int newsize) // Resize residbuf and replace data // +1 to handle PDU message input buffers for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs_real[i]); - volk_free(d_residbufs_imag[i]); - d_residbufs_real[i] = (double*)volk_malloc(d_buffer_size * sizeof(double), - volk_get_alignment()); - d_residbufs_imag[i] = (double*)volk_malloc(d_buffer_size * sizeof(double), - volk_get_alignment()); - - memset(d_residbufs_real[i], 0, d_buffer_size * sizeof(double)); - memset(d_residbufs_imag[i], 0, d_buffer_size * sizeof(double)); + d_residbufs_real[i].clear(); + d_residbufs_imag[i].clear(); + d_residbufs_real[i].resize(d_buffer_size); + d_residbufs_imag[i].resize(d_buffer_size); } d_main_gui->setNPoints(d_size); @@ -437,10 +401,10 @@ int const_sink_c_impl::work(int noutput_items, if ((d_triggered) && (d_index == d_end)) { // Copy data to be plotted to start of buffers. for (n = 0; n < d_nconnections; n++) { - memmove(d_residbufs_real[n], + memmove(d_residbufs_real[n].data(), &d_residbufs_real[n][d_start], d_size * sizeof(double)); - memmove(d_residbufs_imag[n], + memmove(d_residbufs_imag[n].data(), &d_residbufs_imag[n][d_start], d_size * sizeof(double)); } @@ -500,8 +464,10 @@ void const_sink_c_impl::handle_pdus(pmt::pmt_t msg) d_last_time = gr::high_res_timer_now(); // Copy data into the buffers. - volk_32fc_deinterleave_64f_x2( - d_residbufs_real[d_nconnections], d_residbufs_imag[d_nconnections], in, len); + volk_32fc_deinterleave_64f_x2(d_residbufs_real[d_nconnections].data(), + d_residbufs_imag[d_nconnections].data(), + in, + len); d_qApplication->postEvent( d_main_gui, new ConstUpdateEvent(d_residbufs_real, d_residbufs_imag, len)); diff --git a/gr-qtgui/lib/const_sink_c_impl.h b/gr-qtgui/lib/const_sink_c_impl.h index 17f9e97e2e..686a0ea30b 100644 --- a/gr-qtgui/lib/const_sink_c_impl.h +++ b/gr-qtgui/lib/const_sink_c_impl.h @@ -28,14 +28,21 @@ private: std::string d_name; int d_nconnections; - int d_index, d_start, d_end; - std::vector<double*> d_residbufs_real; - std::vector<double*> d_residbufs_imag; - - int d_argc; - char* d_argv; + int d_index = 0; + int d_start; + int d_end; + std::vector<volk::vector<double>> d_residbufs_real; + std::vector<volk::vector<double>> d_residbufs_imag; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - ConstellationDisplayForm* d_main_gui; + ConstellationDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -66,6 +73,12 @@ public: QWidget* parent = NULL); ~const_sink_c_impl() override; + // Disallow copy/move because of the pointers. + const_sink_c_impl(const const_sink_c_impl&) = delete; + const_sink_c_impl& operator=(const const_sink_c_impl&) = delete; + const_sink_c_impl(const_sink_c_impl&&) = delete; + const_sink_c_impl& operator=(const_sink_c_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/edit_box_msg_impl.cc b/gr-qtgui/lib/edit_box_msg_impl.cc index bb1b069857..19e66aceb7 100644 --- a/gr-qtgui/lib/edit_box_msg_impl.cc +++ b/gr-qtgui/lib/edit_box_msg_impl.cc @@ -45,14 +45,6 @@ edit_box_msg_impl::edit_box_msg_impl(data_type_t type, QObject(parent), d_port(pmt::mp("msg")) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - if (qApp != NULL) { d_qApplication = qApp; } else { diff --git a/gr-qtgui/lib/edit_box_msg_impl.h b/gr-qtgui/lib/edit_box_msg_impl.h index f56eaeaef4..bf84d784ba 100644 --- a/gr-qtgui/lib/edit_box_msg_impl.h +++ b/gr-qtgui/lib/edit_box_msg_impl.h @@ -28,8 +28,14 @@ class QTGUI_API edit_box_msg_impl : public QObject, public edit_box_msg Q_OBJECT private: - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; + data_type_t d_type; bool d_is_pair; bool d_is_static; diff --git a/gr-qtgui/lib/eye_sink_c_impl.cc b/gr-qtgui/lib/eye_sink_c_impl.cc index cb70f468bc..8a602790a0 100644 --- a/gr-qtgui/lib/eye_sink_c_impl.cc +++ b/gr-qtgui/lib/eye_sink_c_impl.cc @@ -51,32 +51,18 @@ eye_sink_c_impl::eye_sink_c_impl(int size, if (nconnections > 12) throw std::runtime_error("eye_sink_c only supports up to 12 inputs"); - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); // +2 for the PDU message buffers for (unsigned int n = 0; n < d_nconnections + 2; n++) { - d_buffers.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); + d_buffers.emplace_back(d_buffer_size); } // We don't use cbuffers with the PDU message handling capabilities. for (unsigned int n = 0; n < d_nconnections / 2; n++) { - d_cbuffers.push_back((gr_complex*)volk_malloc(d_buffer_size * sizeof(gr_complex), - volk_get_alignment())); - std::fill_n(d_cbuffers[n], d_buffer_size, 0); + d_cbuffers.emplace_back(d_buffer_size); } // Set alignment properties for VOLK @@ -98,16 +84,6 @@ eye_sink_c_impl::~eye_sink_c_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // d_main_gui is a qwidget destroyed with its parent - for (unsigned int n = 0; n < d_nconnections + 2; n++) { - volk_free(d_buffers[n]); - } - for (unsigned int n = 0; n < d_nconnections / 2; n++) { - volk_free(d_cbuffers[n]); - } - - delete d_argv; } bool eye_sink_c_impl::check_topology(int ninputs, int noutputs) @@ -299,17 +275,13 @@ void eye_sink_c_impl::set_nsamps(const int newsize) // Resize buffers and replace data for (unsigned int n = 0; n < d_nconnections + 2; n++) { - volk_free(d_buffers[n]); - d_buffers[n] = (double*)volk_malloc(d_buffer_size * sizeof(double), - volk_get_alignment()); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); + d_buffers[n].clear(); + d_buffers[n].resize(d_buffer_size); } for (unsigned int n = 0; n < d_nconnections / 2; n++) { - volk_free(d_cbuffers[n]); - d_cbuffers[n] = (gr_complex*)volk_malloc(d_buffer_size * sizeof(gr_complex), - volk_get_alignment()); - std::fill_n(d_cbuffers[n], d_buffer_size, 0); + d_cbuffers[n].clear(); + d_cbuffers[n].resize(d_buffer_size); } // If delay was set beyond the new boundary, pull it back. @@ -396,7 +368,7 @@ void eye_sink_c_impl::_reset() // represents data that might have to be plotted again if a // trigger occurs and we have a trigger delay set. The tail // section is between (d_end-d_trigger_delay) and d_end. - memmove(d_cbuffers[n], + memmove(d_cbuffers[n].data(), &d_cbuffers[n][d_end - d_trigger_delay], d_trigger_delay * sizeof(gr_complex)); @@ -594,8 +566,8 @@ int eye_sink_c_impl::work(int noutput_items, if ((d_triggered) && (d_index == d_end)) { // Copy data to be plotted to start of buffers. for (n = 0; n < d_nconnections / 2; n++) { - volk_32fc_deinterleave_64f_x2(d_buffers[2 * n + 0], - d_buffers[2 * n + 1], + volk_32fc_deinterleave_64f_x2(d_buffers[2 * n + 0].data(), + d_buffers[2 * n + 1].data(), &d_cbuffers[n][d_start], d_size); } @@ -677,8 +649,8 @@ void eye_sink_c_impl::handle_pdus(pmt::pmt_t msg) set_nsamps(len); - volk_32fc_deinterleave_64f_x2(d_buffers[2 * d_nconnections + 0], - d_buffers[2 * d_nconnections + 1], + volk_32fc_deinterleave_64f_x2(d_buffers[2 * d_nconnections + 0].data(), + d_buffers[2 * d_nconnections + 1].data(), in, len); diff --git a/gr-qtgui/lib/eye_sink_c_impl.h b/gr-qtgui/lib/eye_sink_c_impl.h index 7283a023d8..16f965298b 100644 --- a/gr-qtgui/lib/eye_sink_c_impl.h +++ b/gr-qtgui/lib/eye_sink_c_impl.h @@ -15,6 +15,8 @@ #include <gnuradio/high_res_timer.h> #include <gnuradio/qtgui/eyedisplayform.h> +#include <volk/volk_alloc.hh> + namespace gr { namespace qtgui { @@ -30,14 +32,19 @@ private: const pmt::pmt_t d_tag_key; int d_index, d_start, d_end; - std::vector<gr_complex*> d_cbuffers; - std::vector<double*> d_buffers; + std::vector<volk::vector<gr_complex>> d_cbuffers; + std::vector<volk::vector<double>> d_buffers; std::vector<std::vector<gr::tag_t>> d_tags; - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - EyeDisplayForm* d_main_gui; + EyeDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -70,6 +77,12 @@ public: QWidget* parent = NULL); ~eye_sink_c_impl() override; + // Disallow copy/move because of the raw pointers. + eye_sink_c_impl(const eye_sink_c_impl&) = delete; + eye_sink_c_impl& operator=(const eye_sink_c_impl&) = delete; + eye_sink_c_impl(eye_sink_c_impl&&) = delete; + eye_sink_c_impl& operator=(eye_sink_c_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/eye_sink_f_impl.cc b/gr-qtgui/lib/eye_sink_f_impl.cc index f96a5734f9..16b4c39c63 100644 --- a/gr-qtgui/lib/eye_sink_f_impl.cc +++ b/gr-qtgui/lib/eye_sink_f_impl.cc @@ -50,29 +50,14 @@ eye_sink_f_impl::eye_sink_f_impl(int size, if (nconnections > 24) throw std::runtime_error("eye_sink_f only supports up to 24 inputs"); - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); // +1 for the PDU buffer for (unsigned int n = 0; n < d_nconnections + 1; n++) { - d_buffers.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); - - d_fbuffers.push_back( - (float*)volk_malloc(d_buffer_size * sizeof(float), volk_get_alignment())); - memset(d_fbuffers[n], 0, d_buffer_size * sizeof(float)); + d_buffers.emplace_back(d_buffer_size); + d_fbuffers.emplace_back(d_buffer_size); } // Set alignment properties for VOLK @@ -94,14 +79,6 @@ eye_sink_f_impl::~eye_sink_f_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // d_main_gui is a qwidget destroyed with its parent - for (unsigned int n = 0; n < d_nconnections + 1; n++) { - volk_free(d_buffers[n]); - volk_free(d_fbuffers[n]); - } - - delete d_argv; } bool eye_sink_f_impl::check_topology(int ninputs, int noutputs) @@ -284,15 +261,10 @@ void eye_sink_f_impl::set_nsamps(const int newsize) // Resize buffers and replace data for (unsigned int n = 0; n < d_nconnections + 1; n++) { - volk_free(d_buffers[n]); - d_buffers[n] = (double*)volk_malloc(d_buffer_size * sizeof(double), - volk_get_alignment()); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); - - volk_free(d_fbuffers[n]); - d_fbuffers[n] = - (float*)volk_malloc(d_buffer_size * sizeof(float), volk_get_alignment()); - memset(d_fbuffers[n], 0, d_buffer_size * sizeof(float)); + d_buffers[n].clear(); + d_buffers[n].resize(d_buffer_size); + d_fbuffers[n].clear(); + d_fbuffers[n].resize(d_buffer_size); } // If delay was set beyond the new boundary, pull it back. @@ -380,7 +352,7 @@ void eye_sink_f_impl::_reset() // represents data that might have to be plotted again if a // trigger occurs and we have a trigger delay set. The tail // section is between (d_end-d_trigger_delay) and d_end. - memmove(d_fbuffers[n], + memmove(d_fbuffers[n].data(), &d_fbuffers[n][d_end - d_trigger_delay], d_trigger_delay * sizeof(float)); @@ -573,7 +545,7 @@ int eye_sink_f_impl::work(int noutput_items, if ((d_triggered) && (d_index == d_end)) { // Copy data to be plotted to start of buffers. for (n = 0; n < d_nconnections; n++) { - volk_32f_convert_64f(d_buffers[n], &d_fbuffers[n][d_start], d_size); + volk_32f_convert_64f(d_buffers[n].data(), &d_fbuffers[n][d_start], d_size); } // Plot if we are able to update @@ -629,7 +601,7 @@ void eye_sink_f_impl::handle_pdus(pmt::pmt_t msg) set_nsamps(len); - volk_32f_convert_64f(d_buffers[d_nconnections], in, len); + volk_32f_convert_64f(d_buffers[d_nconnections].data(), in, len); std::vector<std::vector<gr::tag_t>> t; d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_buffers, len, t)); diff --git a/gr-qtgui/lib/eye_sink_f_impl.h b/gr-qtgui/lib/eye_sink_f_impl.h index 5711c8a322..bcacf02ea9 100644 --- a/gr-qtgui/lib/eye_sink_f_impl.h +++ b/gr-qtgui/lib/eye_sink_f_impl.h @@ -27,15 +27,22 @@ private: double d_samp_rate; unsigned int d_nconnections; - int d_index, d_start, d_end; - std::vector<float*> d_fbuffers; - std::vector<double*> d_buffers; + int d_index = 0; + int d_start; + int d_end; + std::vector<volk::vector<float>> d_fbuffers; + std::vector<volk::vector<double>> d_buffers; std::vector<std::vector<gr::tag_t>> d_tags; - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - EyeDisplayForm* d_main_gui; + EyeDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -67,6 +74,12 @@ public: QWidget* parent = NULL); ~eye_sink_f_impl() override; + // Disallow copy/move because of the raw pointers. + eye_sink_f_impl(const eye_sink_f_impl&) = delete; + eye_sink_f_impl& operator=(const eye_sink_f_impl&) = delete; + eye_sink_f_impl(eye_sink_f_impl&&) = delete; + eye_sink_f_impl& operator=(eye_sink_f_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/freq_sink_c_impl.cc b/gr-qtgui/lib/freq_sink_c_impl.cc index 059007f983..267e31e419 100644 --- a/gr-qtgui/lib/freq_sink_c_impl.cc +++ b/gr-qtgui/lib/freq_sink_c_impl.cc @@ -64,14 +64,6 @@ freq_sink_c_impl::freq_sink_c_impl(int fftsize, d_port_bw(pmt::mp("bw")), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - // setup bw input port message_port_register_in(d_port_bw); set_msg_handler(d_port_bw, [this](pmt::pmt_t msg) { this->handle_set_bw(msg); }); @@ -86,34 +78,16 @@ freq_sink_c_impl::freq_sink_c_impl(int fftsize, message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); - d_main_gui = NULL; - - // Perform fftshift operation; - // this is usually desired when plotting - d_shift = true; - - d_fft = new fft::fft_complex_fwd(d_fftsize); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); + d_fbuf.resize(d_fftsize); - d_index = 0; // save the last "connection" for the PDU memory - for (int i = 0; i < d_nconnections; i++) { - d_residbufs.push_back((gr_complex*)volk_malloc(d_fftsize * sizeof(gr_complex), - volk_get_alignment())); - d_magbufs.push_back( - (double*)volk_malloc(d_fftsize * sizeof(double), volk_get_alignment())); - - std::fill_n(d_residbufs[i], d_fftsize, 0); - memset(d_magbufs[i], 0, d_fftsize * sizeof(double)); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs.emplace_back(d_fftsize); + d_magbufs.emplace_back(d_fftsize); } - d_residbufs.push_back( - (gr_complex*)volk_malloc(d_fftsize * sizeof(gr_complex), volk_get_alignment())); - d_pdu_magbuf = (double*)volk_malloc(d_fftsize * sizeof(double), volk_get_alignment()); - d_magbufs.push_back(d_pdu_magbuf); - std::fill_n(d_residbufs[d_nconnections], d_fftsize, 0); - memset(d_pdu_magbuf, 0, d_fftsize * sizeof(double)); + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); buildwindow(); @@ -126,16 +100,6 @@ freq_sink_c_impl::~freq_sink_c_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // +1 to handle PDU buffers; will also take care of d_pdu_magbuf - for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - } - delete d_fft; - volk_free(d_fbuf); - - delete d_argv; } bool freq_sink_c_impl::check_topology(int ninputs, int noutputs) @@ -433,20 +397,14 @@ bool freq_sink_c_impl::fftresize() // Resize residbuf and replace data // +1 to handle PDU buffers for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - - d_residbufs[i] = (gr_complex*)volk_malloc(newfftsize * sizeof(gr_complex), - volk_get_alignment()); - d_magbufs[i] = - (double*)volk_malloc(newfftsize * sizeof(double), volk_get_alignment()); - - std::fill_n(d_residbufs[i], newfftsize, 0); - memset(d_magbufs[i], 0, newfftsize * sizeof(double)); + d_residbufs[i].clear(); + d_residbufs[i].resize(newfftsize); + d_magbufs[i].clear(); + d_magbufs[i].resize(newfftsize); } // Update the pointer to the newly allocated memory - d_pdu_magbuf = d_magbufs[d_nconnections]; + d_pdu_magbuf = d_magbufs[d_nconnections].data(); // Set new fft size and reset buffer index // (throws away any currently held data, but who cares?) @@ -457,12 +415,10 @@ bool freq_sink_c_impl::fftresize() buildwindow(); // Reset FFTW plan for new size - delete d_fft; - d_fft = new fft::fft_complex_fwd(d_fftsize); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); - volk_free(d_fbuf); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); + d_fbuf.clear(); + d_fbuf.resize(d_fftsize); d_fft_shift.resize(d_fftsize); @@ -535,9 +491,10 @@ void freq_sink_c_impl::_test_trigger_tags(int start, int nitems) } } -void freq_sink_c_impl::_test_trigger_norm(int nitems, std::vector<double*> inputs) +void freq_sink_c_impl::_test_trigger_norm(int nitems, + std::vector<volk::vector<double>> inputs) { - const double* in = (const double*)inputs[d_trigger_channel]; + const double* in = (const double*)inputs[d_trigger_channel].data(); for (int i = 0; i < nitems; i++) { d_trigger_count++; @@ -592,9 +549,10 @@ int freq_sink_c_impl::work(int noutput_items, // Perform FFT and shift operations into d_magbufs for (int n = 0; n < d_nconnections; n++) { in = (const gr_complex*)input_items[n]; - memcpy(d_residbufs[n], &in[d_index], sizeof(gr_complex) * d_fftsize); + memcpy( + d_residbufs[n].data(), &in[d_index], sizeof(gr_complex) * d_fftsize); - fft(d_fbuf, d_residbufs[n], d_fftsize); + fft(d_fbuf.data(), d_residbufs[n].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_magbufs[n][x] = (double)((1.0 - d_fftavg) * d_magbufs[n][x] + (d_fftavg)*d_fbuf[x]); @@ -671,15 +629,18 @@ void freq_sink_c_impl::handle_pdus(pmt::pmt_t msg) size_t max = std::min(d_fftsize, static_cast<int>(len)); for (int n = 0; n < nffts; n++) { // Clear in case (max-min) < d_fftsize - std::fill_n(d_residbufs[d_nconnections], d_fftsize, 0x00); + std::fill(std::begin(d_residbufs[d_nconnections]), + std::end(d_residbufs[d_nconnections]), + 0x00); // Copy in as much of the input samples as we can - memcpy( - d_residbufs[d_nconnections], &in[min], sizeof(gr_complex) * (max - min)); + memcpy(d_residbufs[d_nconnections].data(), + &in[min], + sizeof(gr_complex) * (max - min)); // Apply the window and FFT; copy data into the PDU // magnitude buffer. - fft(d_fbuf, d_residbufs[d_nconnections], d_fftsize); + fft(d_fbuf.data(), d_residbufs[d_nconnections].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_pdu_magbuf[x] += (double)d_fbuf[x]; } diff --git a/gr-qtgui/lib/freq_sink_c_impl.h b/gr-qtgui/lib/freq_sink_c_impl.h index 66fce9d946..2ac5ba47d6 100644 --- a/gr-qtgui/lib/freq_sink_c_impl.h +++ b/gr-qtgui/lib/freq_sink_c_impl.h @@ -41,19 +41,26 @@ private: const pmt::pmt_t d_port; const pmt::pmt_t d_port_bw; - bool d_shift; - fft::fft_complex_fwd* d_fft; - - int d_index; - std::vector<gr_complex*> d_residbufs; - std::vector<double*> d_magbufs; + // Perform fftshift operation; + // this is usually desired when plotting + bool d_shift = true; + std::unique_ptr<fft::fft_complex_fwd> d_fft; + + int d_index = 0; + std::vector<volk::vector<gr_complex>> d_residbufs; + std::vector<volk::vector<double>> d_magbufs; double* d_pdu_magbuf; - float* d_fbuf; - - int d_argc; - char* d_argv; + volk::vector<float> d_fbuf; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - FreqDisplayForm* d_main_gui; + FreqDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -86,7 +93,7 @@ private: void _reset(); void _gui_update_trigger(); void _test_trigger_tags(int start, int nitems); - void _test_trigger_norm(int nitems, std::vector<double*> inputs); + void _test_trigger_norm(int nitems, std::vector<volk::vector<double>> inputs); public: freq_sink_c_impl(int size, @@ -98,6 +105,12 @@ public: QWidget* parent = NULL); ~freq_sink_c_impl() override; + // Disallow copy/move because of the raw pointers. + freq_sink_c_impl(const freq_sink_c_impl&) = delete; + freq_sink_c_impl& operator=(const freq_sink_c_impl&) = delete; + freq_sink_c_impl(freq_sink_c_impl&&) = delete; + freq_sink_c_impl& operator=(freq_sink_c_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/freq_sink_f_impl.cc b/gr-qtgui/lib/freq_sink_f_impl.cc index f16af85bab..cfc5f2d9d4 100644 --- a/gr-qtgui/lib/freq_sink_f_impl.cc +++ b/gr-qtgui/lib/freq_sink_f_impl.cc @@ -64,14 +64,6 @@ freq_sink_f_impl::freq_sink_f_impl(int fftsize, d_port_bw(pmt::mp("bw")), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - // setup bw input port message_port_register_in(d_port_bw); set_msg_handler(d_port_bw, [this](pmt::pmt_t msg) { this->handle_set_bw(msg); }); @@ -86,34 +78,16 @@ freq_sink_f_impl::freq_sink_f_impl(int fftsize, message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); - d_main_gui = NULL; - - // Perform fftshift operation; - // this is usually desired when plotting - d_shift = true; - - d_fft = new fft::fft_complex_fwd(d_fftsize, true); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize, true); + d_fbuf.resize(d_fftsize); - d_index = 0; // save the last "connection" for the PDU memory - for (int i = 0; i < d_nconnections; i++) { - d_residbufs.push_back( - (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment())); - d_magbufs.push_back( - (double*)volk_malloc(d_fftsize * sizeof(double), volk_get_alignment())); - - memset(d_residbufs[i], 0, d_fftsize * sizeof(float)); - memset(d_magbufs[i], 0, d_fftsize * sizeof(double)); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs.emplace_back(d_fftsize); + d_magbufs.emplace_back(d_fftsize); } - d_residbufs.push_back( - (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment())); - d_pdu_magbuf = (double*)volk_malloc(d_fftsize * sizeof(double), volk_get_alignment()); - d_magbufs.push_back(d_pdu_magbuf); - memset(d_residbufs[d_nconnections], 0, d_fftsize * sizeof(float)); - memset(d_pdu_magbuf, 0, d_fftsize * sizeof(double)); + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); buildwindow(); @@ -126,16 +100,6 @@ freq_sink_f_impl::~freq_sink_f_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // +1 to handle PDU buffers; will also take care of d_pdu_magbuf - for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - } - delete d_fft; - volk_free(d_fbuf); - - delete d_argv; } bool freq_sink_f_impl::check_topology(int ninputs, int noutputs) @@ -436,20 +400,14 @@ bool freq_sink_f_impl::fftresize() // Resize residbuf and replace data // +1 to handle PDU buffers for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - - d_residbufs[i] = - (float*)volk_malloc(newfftsize * sizeof(float), volk_get_alignment()); - d_magbufs[i] = - (double*)volk_malloc(newfftsize * sizeof(double), volk_get_alignment()); - - memset(d_residbufs[i], 0, newfftsize * sizeof(float)); - memset(d_magbufs[i], 0, newfftsize * sizeof(double)); + d_residbufs[i].clear(); + d_residbufs[i].resize(newfftsize); + d_magbufs[i].clear(); + d_magbufs[i].resize(newfftsize); } // Update the pointer to the newly allocated memory - d_pdu_magbuf = d_magbufs[d_nconnections]; + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); // Set new fft size and reset buffer index // (throws away any currently held data, but who cares?) @@ -460,12 +418,10 @@ bool freq_sink_f_impl::fftresize() buildwindow(); // Reset FFTW plan for new size - delete d_fft; - d_fft = new fft::fft_complex_fwd(d_fftsize); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); - volk_free(d_fbuf); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); + d_fbuf.clear(); + d_fbuf.resize(d_fftsize); d_fft_shift.resize(d_fftsize); @@ -538,9 +494,10 @@ void freq_sink_f_impl::_test_trigger_tags(int start, int nitems) } } -void freq_sink_f_impl::_test_trigger_norm(int nitems, std::vector<double*> inputs) +void freq_sink_f_impl::_test_trigger_norm(int nitems, + std::vector<volk::vector<double>> inputs) { - const double* in = (const double*)inputs[d_trigger_channel]; + const double* in = (const double*)inputs[d_trigger_channel].data(); for (int i = 0; i < nitems; i++) { d_trigger_count++; @@ -595,9 +552,9 @@ int freq_sink_f_impl::work(int noutput_items, for (int n = 0; n < d_nconnections; n++) { // Fill up residbuf with d_fftsize number of items in = (const float*)input_items[n]; - memcpy(d_residbufs[n], &in[d_index], sizeof(float) * d_fftsize); + memcpy(d_residbufs[n].data(), &in[d_index], sizeof(float) * d_fftsize); - fft(d_fbuf, d_residbufs[n], d_fftsize); + fft(d_fbuf.data(), d_residbufs[n].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_magbufs[n][x] = (double)((1.0 - d_fftavg) * d_magbufs[n][x] + (d_fftavg)*d_fbuf[x]); @@ -673,14 +630,16 @@ void freq_sink_f_impl::handle_pdus(pmt::pmt_t msg) size_t max = std::min(d_fftsize, static_cast<int>(len)); for (int n = 0; n < nffts; n++) { // Clear in case (max-min) < d_fftsize - memset(d_residbufs[d_nconnections], 0x00, sizeof(float) * d_fftsize); + memset(d_residbufs[d_nconnections].data(), 0x00, sizeof(float) * d_fftsize); // Copy in as much of the input samples as we can - memcpy(d_residbufs[d_nconnections], &in[min], sizeof(float) * (max - min)); + memcpy(d_residbufs[d_nconnections].data(), + &in[min], + sizeof(float) * (max - min)); // Apply the window and FFT; copy data into the PDU // magnitude buffer. - fft(d_fbuf, d_residbufs[d_nconnections], d_fftsize); + fft(d_fbuf.data(), d_residbufs[d_nconnections].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_pdu_magbuf[x] += (double)d_fbuf[x]; } diff --git a/gr-qtgui/lib/freq_sink_f_impl.h b/gr-qtgui/lib/freq_sink_f_impl.h index 67fe4094af..8119d0d275 100644 --- a/gr-qtgui/lib/freq_sink_f_impl.h +++ b/gr-qtgui/lib/freq_sink_f_impl.h @@ -41,19 +41,26 @@ private: const pmt::pmt_t d_port; const pmt::pmt_t d_port_bw; - bool d_shift; - fft::fft_complex_fwd* d_fft; - - int d_index; - std::vector<float*> d_residbufs; - std::vector<double*> d_magbufs; + // Perform fftshift operation; + // this is usually desired when plotting + bool d_shift = true; + std::unique_ptr<fft::fft_complex_fwd> d_fft; + + int d_index = 0; + std::vector<volk::vector<float>> d_residbufs; + std::vector<volk::vector<double>> d_magbufs; double* d_pdu_magbuf; - float* d_fbuf; - - int d_argc; - char* d_argv; + volk::vector<float> d_fbuf; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - FreqDisplayForm* d_main_gui; + FreqDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -86,7 +93,7 @@ private: void _reset(); void _gui_update_trigger(); void _test_trigger_tags(int start, int nitems); - void _test_trigger_norm(int nitems, std::vector<double*> inputs); + void _test_trigger_norm(int nitems, std::vector<volk::vector<double>> inputs); public: freq_sink_f_impl(int size, @@ -98,6 +105,12 @@ public: QWidget* parent = NULL); ~freq_sink_f_impl() override; + // Disallow copy/move because of the raw pointers. + freq_sink_f_impl(const freq_sink_f_impl&) = delete; + freq_sink_f_impl& operator=(const freq_sink_f_impl&) = delete; + freq_sink_f_impl(freq_sink_f_impl&&) = delete; + freq_sink_f_impl& operator=(freq_sink_f_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/histogram_sink_f_impl.cc b/gr-qtgui/lib/histogram_sink_f_impl.cc index 591e3747da..f6c58ebf47 100644 --- a/gr-qtgui/lib/histogram_sink_f_impl.cc +++ b/gr-qtgui/lib/histogram_sink_f_impl.cc @@ -55,27 +55,13 @@ histogram_sink_f_impl::histogram_sink_f_impl(int size, d_nconnections(nconnections), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - - d_index = 0; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); // +1 for the PDU buffer for (int i = 0; i < d_nconnections + 1; i++) { - d_residbufs.push_back( - (double*)volk_malloc(d_size * sizeof(double), volk_get_alignment())); - memset(d_residbufs[i], 0, d_size * sizeof(double)); + d_residbufs.emplace_back(d_size); } // Set alignment properties for VOLK @@ -89,13 +75,6 @@ histogram_sink_f_impl::~histogram_sink_f_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // d_main_gui is a qwidget destroyed with its parent - for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - } - - delete d_argv; } bool histogram_sink_f_impl::check_topology(int ninputs, int noutputs) @@ -244,11 +223,8 @@ void histogram_sink_f_impl::set_nsamps(const int newsize) if (newsize != d_size) { // Resize residbuf and replace data for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - d_residbufs[i] = - (double*)volk_malloc(newsize * sizeof(double), volk_get_alignment()); - - memset(d_residbufs[i], 0, newsize * sizeof(double)); + d_residbufs[i].clear(); + d_residbufs[i].resize(newsize); } // Set new size and reset buffer index @@ -392,7 +368,7 @@ void histogram_sink_f_impl::handle_pdus(pmt::pmt_t msg) int idx = 0; for (int n = 0; n < nplots; n++) { int size = std::min(d_size, (int)(len - idx)); - volk_32f_convert_64f_u(d_residbufs[d_nconnections], &in[idx], size); + volk_32f_convert_64f_u(d_residbufs[d_nconnections].data(), &in[idx], size); d_qApplication->postEvent(d_main_gui, new HistogramUpdateEvent(d_residbufs, size)); diff --git a/gr-qtgui/lib/histogram_sink_f_impl.h b/gr-qtgui/lib/histogram_sink_f_impl.h index f181654108..3c9e682790 100644 --- a/gr-qtgui/lib/histogram_sink_f_impl.h +++ b/gr-qtgui/lib/histogram_sink_f_impl.h @@ -30,13 +30,18 @@ private: const std::string d_name; int d_nconnections; - int d_index; - std::vector<double*> d_residbufs; - - int d_argc; - char* d_argv; + int d_index = 0; + std::vector<volk::vector<double>> d_residbufs; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - HistogramDisplayForm* d_main_gui; + HistogramDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -56,6 +61,12 @@ public: QWidget* parent = NULL); ~histogram_sink_f_impl() override; + // Disallow copy/move because of the raw pointers. + histogram_sink_f_impl(const histogram_sink_f_impl&) = delete; + histogram_sink_f_impl& operator=(const histogram_sink_f_impl&) = delete; + histogram_sink_f_impl(histogram_sink_f_impl&&) = delete; + histogram_sink_f_impl& operator=(histogram_sink_f_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/number_sink_impl.cc b/gr-qtgui/lib/number_sink_impl.cc index 5d1828a900..93ea4979f1 100644 --- a/gr-qtgui/lib/number_sink_impl.cc +++ b/gr-qtgui/lib/number_sink_impl.cc @@ -60,16 +60,6 @@ number_sink_impl::number_sink_impl( d_iir[n].set_taps(d_average); } - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - // Set alignment properties for VOLK const int alignment_multiple = volk_get_alignment() / d_itemsize; set_alignment(std::max(1, alignment_multiple)); diff --git a/gr-qtgui/lib/number_sink_impl.h b/gr-qtgui/lib/number_sink_impl.h index 05d78aaa3c..7b5dfdc37f 100644 --- a/gr-qtgui/lib/number_sink_impl.h +++ b/gr-qtgui/lib/number_sink_impl.h @@ -31,13 +31,18 @@ private: int d_nconnections; int d_index, d_start, d_end; - std::vector<double*> d_buffers; + std::vector<volk::vector<double>> d_buffers; std::vector<std::vector<gr::tag_t>> d_tags; - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - NumberDisplayForm* d_main_gui; + NumberDisplayForm* d_main_gui = nullptr; std::vector<float> d_avg_value; std::vector<filter::single_pole_iir<float, float, float>> d_iir; diff --git a/gr-qtgui/lib/sink_c_impl.cc b/gr-qtgui/lib/sink_c_impl.cc index f0e3355bc3..c6fea87876 100644 --- a/gr-qtgui/lib/sink_c_impl.cc +++ b/gr-qtgui/lib/sink_c_impl.cc @@ -24,6 +24,10 @@ namespace gr { namespace qtgui { +namespace { +constexpr uint64_t maxBufferSize = 32768; +} + sink_c::sptr sink_c::make(int fftsize, int wintype, double fc, @@ -66,52 +70,28 @@ sink_c_impl::sink_c_impl(int fftsize, d_bandwidth(bw), d_name(name), d_port(pmt::mp("freq")), + d_fft(std::make_unique<fft::fft_complex_fwd>(d_fftsize)), + d_residbuf(d_fftsize), + d_magbuf(d_fftsize), d_plotfreq(plotfreq), d_plotwaterfall(plotwaterfall), d_plottime(plottime), d_plotconst(plotconst), - d_parent(parent) + d_parent(parent), + d_main_gui(maxBufferSize, d_fftsize, d_center_freq, -d_bandwidth, d_bandwidth) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - // setup output message port to post frequency when display is // double-clicked message_port_register_out(d_port); message_port_register_in(d_port); set_msg_handler(d_port, [this](pmt::pmt_t msg) { this->handle_set_freq(msg); }); - d_main_gui = NULL; - - // Perform fftshift operation; - // this is usually desired when plotting - d_shift = true; - - d_fft = new fft::fft_complex_fwd(d_fftsize); - - d_index = 0; - d_residbuf = - (gr_complex*)volk_malloc(d_fftsize * sizeof(gr_complex), volk_get_alignment()); - d_magbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - buildwindow(); initialize(); } -sink_c_impl::~sink_c_impl() -{ - delete d_main_gui; - delete d_fft; - delete d_argv; - volk_free(d_residbuf); - volk_free(d_magbuf); -} +sink_c_impl::~sink_c_impl() {} bool sink_c_impl::check_topology(int ninputs, int noutputs) { return ninputs == 1; } @@ -142,15 +122,11 @@ void sink_c_impl::initialize() throw std::runtime_error("sink_c_impl: Received bad center frequency."); } - uint64_t maxBufferSize = 32768; - d_main_gui = new SpectrumGUIClass( - maxBufferSize, d_fftsize, d_center_freq, -d_bandwidth, d_bandwidth); - - d_main_gui->setDisplayTitle(d_name); - d_main_gui->setWindowType((int)d_wintype); + d_main_gui.setDisplayTitle(d_name); + d_main_gui.setWindowType((int)d_wintype); set_fft_size(d_fftsize); - d_main_gui->openSpectrumWindow( + d_main_gui.openSpectrumWindow( d_parent, d_plotfreq, d_plotwaterfall, d_plottime, d_plotconst); // initialize update time to 10 times a second @@ -162,12 +138,12 @@ void sink_c_impl::initialize() void sink_c_impl::exec_() { d_qApplication->exec(); } -QWidget* sink_c_impl::qwidget() { return d_main_gui->qwidget(); } +QWidget* sink_c_impl::qwidget() { return d_main_gui.qwidget(); } #ifdef ENABLE_PYTHON PyObject* sink_c_impl::pyqwidget() { - PyObject* w = PyLong_FromVoidPtr((void*)d_main_gui->qwidget()); + PyObject* w = PyLong_FromVoidPtr((void*)d_main_gui.qwidget()); PyObject* retarg = Py_BuildValue("N", w); return retarg; } @@ -178,7 +154,7 @@ void* sink_c_impl::pyqwidget() { return NULL; } void sink_c_impl::set_fft_size(const int fftsize) { d_fftsize = fftsize; - d_main_gui->setFFTSize(fftsize); + d_main_gui.setFFTSize(fftsize); } int sink_c_impl::fft_size() const { return d_fftsize; } @@ -187,41 +163,41 @@ void sink_c_impl::set_frequency_range(const double centerfreq, const double band { d_center_freq = centerfreq; d_bandwidth = bandwidth; - d_main_gui->setFrequencyRange(d_center_freq, -d_bandwidth, d_bandwidth); + d_main_gui.setFrequencyRange(d_center_freq, -d_bandwidth, d_bandwidth); } void sink_c_impl::set_fft_power_db(double min, double max) { - d_main_gui->setFrequencyAxis(min, max); + d_main_gui.setFrequencyAxis(min, max); } -void sink_c_impl::enable_rf_freq(bool en) { d_main_gui->enableRFFreq(en); } +void sink_c_impl::enable_rf_freq(bool en) { d_main_gui.enableRFFreq(en); } /* void sink_c_impl::set_time_domain_axis(double min, double max) { - d_main_gui->setTimeDomainAxis(min, max); + d_main_gui.setTimeDomainAxis(min, max); } void sink_c_impl::set_constellation_axis(double xmin, double xmax, double ymin, double ymax) { - d_main_gui->setConstellationAxis(xmin, xmax, ymin, ymax); + d_main_gui.setConstellationAxis(xmin, xmax, ymin, ymax); } void sink_c_impl::set_constellation_pen_size(int size) { - d_main_gui->setConstellationPenSize(size); + d_main_gui.setConstellationPenSize(size); } */ void sink_c_impl::set_update_time(double t) { d_update_time = t * gr::high_res_timer_tps(); - d_main_gui->setUpdateTime(t); + d_main_gui.setUpdateTime(t); } void sink_c_impl::fft(float* data_out, const gr_complex* data_in, int size) @@ -240,7 +216,7 @@ void sink_c_impl::fft(float* data_out, const gr_complex* data_in, int size) void sink_c_impl::windowreset() { fft::window::win_type newwintype; - newwintype = (fft::window::win_type)d_main_gui->getWindowType(); + newwintype = (fft::window::win_type)d_main_gui.getWindowType(); if (d_wintype != newwintype) { d_wintype = newwintype; buildwindow(); @@ -257,17 +233,13 @@ void sink_c_impl::buildwindow() void sink_c_impl::fftresize() { - int newfftsize = d_main_gui->getFFTSize(); + int newfftsize = d_main_gui.getFFTSize(); if (newfftsize != d_fftsize) { // Resize residbuf and replace data - volk_free(d_residbuf); - d_residbuf = (gr_complex*)volk_malloc(newfftsize * sizeof(gr_complex), - volk_get_alignment()); - - volk_free(d_magbuf); - d_magbuf = (float*)volk_malloc(newfftsize * sizeof(float), volk_get_alignment()); + d_residbuf.resize(newfftsize); + d_magbuf.resize(newfftsize); // Set new fft size and reset buffer index // (throws away any currently held data, but who cares?) @@ -278,15 +250,14 @@ void sink_c_impl::fftresize() buildwindow(); // Reset FFTW plan for new size - delete d_fft; - d_fft = new fft::fft_complex_fwd(d_fftsize); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); } } void sink_c_impl::check_clicked() { - if (d_main_gui->checkClicked()) { - double freq = d_main_gui->getClickedFreq(); + if (d_main_gui.checkClicked()) { + double freq = d_main_gui.getClickedFreq(); message_port_pub(d_port, pmt::cons(d_port, pmt::from_double(freq))); } } @@ -333,26 +304,26 @@ int sink_c_impl::general_work(int noutput_items, const gr::high_res_timer_type currentTime = gr::high_res_timer_now(); // Fill up residbuf with d_fftsize number of items - memcpy(d_residbuf + d_index, &in[j], sizeof(gr_complex) * resid); + memcpy(d_residbuf.data() + d_index, &in[j], sizeof(gr_complex) * resid); d_index = 0; j += resid; - fft(d_magbuf, d_residbuf, d_fftsize); - - d_main_gui->updateWindow(true, - d_magbuf, - d_fftsize, - NULL, - 0, - (float*)d_residbuf, - d_fftsize, - currentTime, - true); + fft(d_magbuf.data(), d_residbuf.data(), d_fftsize); + + d_main_gui.updateWindow(true, + d_magbuf.data(), + d_fftsize, + NULL, + 0, + reinterpret_cast<float*>(d_residbuf.data()), + d_fftsize, + currentTime, + true); d_update_active = false; } // Otherwise, copy what we received into the residbuf for next time else { - memcpy(d_residbuf + d_index, &in[j], sizeof(gr_complex) * datasize); + memcpy(d_residbuf.data() + d_index, &in[j], sizeof(gr_complex) * datasize); d_index += datasize; j += datasize; } diff --git a/gr-qtgui/lib/sink_c_impl.h b/gr-qtgui/lib/sink_c_impl.h index 364d53730a..b78e76048c 100644 --- a/gr-qtgui/lib/sink_c_impl.h +++ b/gr-qtgui/lib/sink_c_impl.h @@ -40,21 +40,24 @@ private: const pmt::pmt_t d_port; - bool d_shift; - fft::fft_complex_fwd* d_fft; + // Perform fftshift operation; + // this is usually desired when plotting + bool d_shift = true; + std::unique_ptr<fft::fft_complex_fwd> d_fft; - int d_index; - gr_complex* d_residbuf; - float* d_magbuf; + int d_index = 0; + volk::vector<gr_complex> d_residbuf; + volk::vector<float> d_magbuf; bool d_plotfreq, d_plotwaterfall, d_plottime, d_plotconst; gr::high_res_timer_type d_update_time; - int d_argc; - char* d_argv; + int d_argc = 1; + char zero = 0; + char* d_argv = &zero; QWidget* d_parent; - SpectrumGUIClass* d_main_gui; + SpectrumGUIClass d_main_gui; void windowreset(); void buildwindow(); @@ -78,6 +81,12 @@ public: bool plotconst, QWidget* parent); ~sink_c_impl() override; + // Disallow copy/move because of the pointers. + sink_c_impl(const sink_c_impl&) = delete; + sink_c_impl(sink_c_impl&&) = delete; + sink_c_impl& operator=(const sink_c_impl&) = delete; + sink_c_impl& operator=(sink_c_impl&&) = delete; + bool check_topology(int ninputs, int noutputs) override; diff --git a/gr-qtgui/lib/sink_f_impl.cc b/gr-qtgui/lib/sink_f_impl.cc index 074c04219e..74d8cf6430 100644 --- a/gr-qtgui/lib/sink_f_impl.cc +++ b/gr-qtgui/lib/sink_f_impl.cc @@ -25,6 +25,10 @@ namespace gr { namespace qtgui { +namespace { +constexpr uint64_t maxBufferSize = 32768; +} + sink_f::sptr sink_f::make(int fftsize, int wintype, double fc, @@ -66,51 +70,28 @@ sink_f_impl::sink_f_impl(int fftsize, d_bandwidth(bw), d_name(name), d_port(pmt::mp("freq")), + d_fft(std::make_unique<fft::fft_complex_fwd>(d_fftsize)), + d_residbuf(d_fftsize), + d_magbuf(d_fftsize), d_plotfreq(plotfreq), d_plotwaterfall(plotwaterfall), d_plottime(plottime), d_plotconst(plotconst), - d_parent(parent) + d_parent(parent), + d_main_gui(maxBufferSize, d_fftsize, d_center_freq, -d_bandwidth, d_bandwidth) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - // setup output message port to post frequency when display is // double-clicked message_port_register_out(d_port); message_port_register_in(d_port); set_msg_handler(d_port, [this](pmt::pmt_t msg) { this->handle_set_freq(msg); }); - d_main_gui = NULL; - - // Perform fftshift operation; - // this is usually desired when plotting - d_shift = true; - - d_fft = new fft::fft_complex_fwd(d_fftsize); - - d_index = 0; - d_residbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - d_magbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - buildwindow(); initialize(); } -sink_f_impl::~sink_f_impl() -{ - delete d_main_gui; - delete d_fft; - delete d_argv; - volk_free(d_residbuf); - volk_free(d_magbuf); -} +sink_f_impl::~sink_f_impl() {} bool sink_f_impl::check_topology(int ninputs, int noutputs) { return ninputs == 1; } @@ -137,14 +118,11 @@ void sink_f_impl::initialize() // If a style sheet is set in the prefs file, enable it here. check_set_qss(d_qApplication); - uint64_t maxBufferSize = 32768; - d_main_gui = new SpectrumGUIClass( - maxBufferSize, d_fftsize, d_center_freq, -d_bandwidth, d_bandwidth); - d_main_gui->setDisplayTitle(d_name); - d_main_gui->setWindowType((int)d_wintype); + d_main_gui.setDisplayTitle(d_name); + d_main_gui.setWindowType((int)d_wintype); set_fft_size(d_fftsize); - d_main_gui->openSpectrumWindow( + d_main_gui.openSpectrumWindow( d_parent, d_plotfreq, d_plotwaterfall, d_plottime, d_plotconst); // initialize update time to 10 times a second @@ -153,12 +131,12 @@ void sink_f_impl::initialize() void sink_f_impl::exec_() { d_qApplication->exec(); } -QWidget* sink_f_impl::qwidget() { return d_main_gui->qwidget(); } +QWidget* sink_f_impl::qwidget() { return d_main_gui.qwidget(); } #ifdef ENABLE_PYTHON PyObject* sink_f_impl::pyqwidget() { - PyObject* w = PyLong_FromVoidPtr((void*)d_main_gui->qwidget()); + PyObject* w = PyLong_FromVoidPtr((void*)d_main_gui.qwidget()); PyObject* retarg = Py_BuildValue("N", w); return retarg; } @@ -169,7 +147,7 @@ void* sink_f_impl::pyqwidget() { return NULL; } void sink_f_impl::set_fft_size(const int fftsize) { d_fftsize = fftsize; - d_main_gui->setFFTSize(fftsize); + d_main_gui.setFFTSize(fftsize); } int sink_f_impl::fft_size() const { return d_fftsize; } @@ -178,41 +156,41 @@ void sink_f_impl::set_frequency_range(const double centerfreq, const double band { d_center_freq = centerfreq; d_bandwidth = bandwidth; - d_main_gui->setFrequencyRange(d_center_freq, -d_bandwidth, d_bandwidth); + d_main_gui.setFrequencyRange(d_center_freq, -d_bandwidth, d_bandwidth); } void sink_f_impl::set_fft_power_db(double min, double max) { - d_main_gui->setFrequencyAxis(min, max); + d_main_gui.setFrequencyAxis(min, max); } -void sink_f_impl::enable_rf_freq(bool en) { d_main_gui->enableRFFreq(en); } +void sink_f_impl::enable_rf_freq(bool en) { d_main_gui.enableRFFreq(en); } /* void sink_f_impl::set_time_domain_axis(double min, double max) { - d_main_gui->setTimeDomainAxis(min, max); + d_main_gui.setTimeDomainAxis(min, max); } void sink_f_impl::set_constellation_axis(double xmin, double xmax, double ymin, double ymax) { - d_main_gui->setConstellationAxis(xmin, xmax, ymin, ymax); + d_main_gui.setConstellationAxis(xmin, xmax, ymin, ymax); } void sink_f_impl::set_constellation_pen_size(int size) { - d_main_gui->setConstellationPenSize(size); + d_main_gui.setConstellationPenSize(size); } */ void sink_f_impl::set_update_time(double t) { d_update_time = t; - d_main_gui->setUpdateTime(d_update_time); + d_main_gui.setUpdateTime(d_update_time); } void sink_f_impl::fft(float* data_out, const float* data_in, int size) @@ -235,7 +213,7 @@ void sink_f_impl::fft(float* data_out, const float* data_in, int size) void sink_f_impl::windowreset() { fft::window::win_type newwintype; - newwintype = (fft::window::win_type)d_main_gui->getWindowType(); + newwintype = (fft::window::win_type)d_main_gui.getWindowType(); if (d_wintype != newwintype) { d_wintype = newwintype; buildwindow(); @@ -252,17 +230,13 @@ void sink_f_impl::buildwindow() void sink_f_impl::fftresize() { - int newfftsize = d_main_gui->getFFTSize(); + int newfftsize = d_main_gui.getFFTSize(); if (newfftsize != d_fftsize) { // Resize residbuf and replace data - volk_free(d_residbuf); - d_residbuf = - (float*)volk_malloc(newfftsize * sizeof(float), volk_get_alignment()); - - volk_free(d_magbuf); - d_magbuf = (float*)volk_malloc(newfftsize * sizeof(float), volk_get_alignment()); + d_residbuf.resize(newfftsize); + d_magbuf.resize(newfftsize); // Set new fft size and reset buffer index // (throws away any currently held data, but who cares?) @@ -273,15 +247,14 @@ void sink_f_impl::fftresize() buildwindow(); // Reset FFTW plan for new size - delete d_fft; - d_fft = new fft::fft_complex_fwd(d_fftsize); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); } } void sink_f_impl::check_clicked() { - if (d_main_gui->checkClicked()) { - double freq = d_main_gui->getClickedFreq(); + if (d_main_gui.checkClicked()) { + double freq = d_main_gui.getClickedFreq(); message_port_pub(d_port, pmt::cons(d_port, pmt::from_double(freq))); } } @@ -319,25 +292,25 @@ int sink_f_impl::general_work(int noutput_items, const gr::high_res_timer_type currentTime = gr::high_res_timer_now(); // Fill up residbuf with d_fftsize number of items - memcpy(d_residbuf + d_index, &in[j], sizeof(float) * resid); + memcpy(d_residbuf.data() + d_index, &in[j], sizeof(float) * resid); d_index = 0; j += resid; - fft(d_magbuf, d_residbuf, d_fftsize); - - d_main_gui->updateWindow(true, - d_magbuf, - d_fftsize, - (float*)d_residbuf, - d_fftsize, - NULL, - 0, - currentTime, - true); + fft(d_magbuf.data(), d_residbuf.data(), d_fftsize); + + d_main_gui.updateWindow(true, + d_magbuf.data(), + d_fftsize, + d_residbuf.data(), + d_fftsize, + NULL, + 0, + currentTime, + true); } // Otherwise, copy what we received into the residbuf for next time else { - memcpy(d_residbuf + d_index, &in[j], sizeof(float) * datasize); + memcpy(d_residbuf.data() + d_index, &in[j], sizeof(float) * datasize); d_index += datasize; j += datasize; } diff --git a/gr-qtgui/lib/sink_f_impl.h b/gr-qtgui/lib/sink_f_impl.h index 61470a4217..726991f0d9 100644 --- a/gr-qtgui/lib/sink_f_impl.h +++ b/gr-qtgui/lib/sink_f_impl.h @@ -38,21 +38,28 @@ private: const pmt::pmt_t d_port; - bool d_shift; - fft::fft_complex_fwd* d_fft; + // Perform fftshift operation; + // this is usually desired when plotting + bool d_shift = true; + std::unique_ptr<fft::fft_complex_fwd> d_fft; - int d_index; - float* d_residbuf; - float* d_magbuf; + int d_index = 0; + volk::vector<float> d_residbuf; + volk::vector<float> d_magbuf; bool d_plotfreq, d_plotwaterfall, d_plottime, d_plotconst; double d_update_time; - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char zero = 0; + int d_argc = 1; + char* d_argv = &zero; QWidget* d_parent; - SpectrumGUIClass* d_main_gui; + SpectrumGUIClass d_main_gui; void windowreset(); void buildwindow(); @@ -76,6 +83,11 @@ public: bool plotconst, QWidget* parent); ~sink_f_impl() override; + // Disallow copy/move because of the pointers. + sink_f_impl(const sink_f_impl&) = delete; + sink_f_impl(sink_f_impl&&) = delete; + sink_f_impl& operator=(const sink_f_impl&) = delete; + sink_f_impl& operator=(sink_f_impl&&) = delete; bool check_topology(int ninputs, int noutputs) override; diff --git a/gr-qtgui/lib/spectrumUpdateEvents.cc b/gr-qtgui/lib/spectrumUpdateEvents.cc index 6906c1af9e..8a1d631686 100644 --- a/gr-qtgui/lib/spectrumUpdateEvents.cc +++ b/gr-qtgui/lib/spectrumUpdateEvents.cc @@ -150,7 +150,7 @@ double SpectrumFrequencyRangeEvent::GetStopFrequency() const { return _stopFrequ /***************************************************************************/ -TimeUpdateEvent::TimeUpdateEvent(const std::vector<double*> timeDomainPoints, +TimeUpdateEvent::TimeUpdateEvent(const std::vector<volk::vector<double>> timeDomainPoints, const uint64_t numTimeDomainDataPoints, const std::vector<std::vector<gr::tag_t>> tags) : QEvent(QEvent::Type(SpectrumUpdateEventType)) @@ -161,12 +161,13 @@ TimeUpdateEvent::TimeUpdateEvent(const std::vector<double*> timeDomainPoints, _numTimeDomainDataPoints = numTimeDomainDataPoints; } + // TODO: make this whole thing a vector copy. _nplots = timeDomainPoints.size(); for (size_t i = 0; i < _nplots; i++) { _dataTimeDomainPoints.push_back(new double[_numTimeDomainDataPoints]); if (numTimeDomainDataPoints > 0) { memcpy(_dataTimeDomainPoints[i], - timeDomainPoints[i], + timeDomainPoints[i].data(), _numTimeDomainDataPoints * sizeof(double)); } } @@ -199,7 +200,7 @@ const std::vector<std::vector<gr::tag_t>> TimeUpdateEvent::getTags() const /***************************************************************************/ -FreqUpdateEvent::FreqUpdateEvent(const std::vector<double*> dataPoints, +FreqUpdateEvent::FreqUpdateEvent(const std::vector<volk::vector<double>> dataPoints, const uint64_t numDataPoints) : QEvent(QEvent::Type(SpectrumUpdateEventType)) { @@ -210,10 +211,11 @@ FreqUpdateEvent::FreqUpdateEvent(const std::vector<double*> dataPoints, } _nplots = dataPoints.size(); + // TODO: do a vector copy. for (size_t i = 0; i < _nplots; i++) { _dataPoints.push_back(new double[_numDataPoints]); if (numDataPoints > 0) { - memcpy(_dataPoints[i], dataPoints[i], _numDataPoints * sizeof(double)); + memcpy(_dataPoints[i], dataPoints[i].data(), _numDataPoints * sizeof(double)); } } } @@ -247,8 +249,8 @@ double SetFreqEvent::getBandwidth() const { return _bandwidth; } /***************************************************************************/ -ConstUpdateEvent::ConstUpdateEvent(const std::vector<double*> realDataPoints, - const std::vector<double*> imagDataPoints, +ConstUpdateEvent::ConstUpdateEvent(const std::vector<volk::vector<double>> realDataPoints, + const std::vector<volk::vector<double>> imagDataPoints, const uint64_t numDataPoints) : QEvent(QEvent::Type(SpectrumUpdateEventType)) { @@ -258,15 +260,18 @@ ConstUpdateEvent::ConstUpdateEvent(const std::vector<double*> realDataPoints, _numDataPoints = numDataPoints; } + // Todo: do vector copies. _nplots = realDataPoints.size(); for (size_t i = 0; i < _nplots; i++) { _realDataPoints.push_back(new double[_numDataPoints]); _imagDataPoints.push_back(new double[_numDataPoints]); if (numDataPoints > 0) { - memcpy( - _realDataPoints[i], realDataPoints[i], _numDataPoints * sizeof(double)); - memcpy( - _imagDataPoints[i], imagDataPoints[i], _numDataPoints * sizeof(double)); + memcpy(_realDataPoints[i], + realDataPoints[i].data(), + _numDataPoints * sizeof(double)); + memcpy(_imagDataPoints[i], + imagDataPoints[i].data(), + _numDataPoints * sizeof(double)); } } } @@ -295,9 +300,10 @@ uint64_t ConstUpdateEvent::getNumDataPoints() const { return _numDataPoints; } /***************************************************************************/ -WaterfallUpdateEvent::WaterfallUpdateEvent(const std::vector<double*> dataPoints, - const uint64_t numDataPoints, - const gr::high_res_timer_type dataTimestamp) +WaterfallUpdateEvent::WaterfallUpdateEvent( + const std::vector<volk::vector<double>> dataPoints, + const uint64_t numDataPoints, + const gr::high_res_timer_type dataTimestamp) : QEvent(QEvent::Type(SpectrumUpdateEventType)) { if (numDataPoints < 1) { @@ -310,7 +316,7 @@ WaterfallUpdateEvent::WaterfallUpdateEvent(const std::vector<double*> dataPoints for (size_t i = 0; i < _nplots; i++) { _dataPoints.push_back(new double[_numDataPoints]); if (numDataPoints > 0) { - memcpy(_dataPoints[i], dataPoints[i], _numDataPoints * sizeof(double)); + memcpy(_dataPoints[i], dataPoints[i].data(), _numDataPoints * sizeof(double)); } } @@ -337,8 +343,8 @@ gr::high_res_timer_type WaterfallUpdateEvent::getDataTimestamp() const /***************************************************************************/ -TimeRasterUpdateEvent::TimeRasterUpdateEvent(const std::vector<double*> dataPoints, - const uint64_t numDataPoints) +TimeRasterUpdateEvent::TimeRasterUpdateEvent( + const std::vector<volk::vector<double>> dataPoints, const uint64_t numDataPoints) : QEvent(QEvent::Type(SpectrumUpdateEventType)) { if (numDataPoints < 1) { @@ -351,7 +357,7 @@ TimeRasterUpdateEvent::TimeRasterUpdateEvent(const std::vector<double*> dataPoin for (size_t i = 0; i < _nplots; i++) { _dataPoints.push_back(new double[_numDataPoints]); if (numDataPoints > 0) { - memcpy(_dataPoints[i], dataPoints[i], _numDataPoints * sizeof(double)); + memcpy(_dataPoints[i], dataPoints[i].data(), _numDataPoints * sizeof(double)); } } } @@ -385,7 +391,7 @@ double TimeRasterSetSize::nCols() const { return _ncols; } /***************************************************************************/ -HistogramUpdateEvent::HistogramUpdateEvent(const std::vector<double*> points, +HistogramUpdateEvent::HistogramUpdateEvent(const std::vector<volk::vector<double>> points, const uint64_t npoints) : QEvent(QEvent::Type(SpectrumUpdateEventType)) { @@ -399,7 +405,7 @@ HistogramUpdateEvent::HistogramUpdateEvent(const std::vector<double*> points, for (size_t i = 0; i < _nplots; i++) { _points.push_back(new double[_npoints]); if (npoints > 0) { - memcpy(_points[i], points[i], _npoints * sizeof(double)); + memcpy(_points[i], points[i].data(), _npoints * sizeof(double)); } } } diff --git a/gr-qtgui/lib/time_raster_sink_b_impl.cc b/gr-qtgui/lib/time_raster_sink_b_impl.cc index 3aa4efe89f..f9e8b2faa5 100644 --- a/gr-qtgui/lib/time_raster_sink_b_impl.cc +++ b/gr-qtgui/lib/time_raster_sink_b_impl.cc @@ -57,18 +57,6 @@ time_raster_sink_b_impl::time_raster_sink_b_impl(double samp_rate, d_offset(std::vector<float>(nconnections + 1, 0)), d_samp_rate(samp_rate) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - - d_index = 0; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); @@ -76,14 +64,11 @@ time_raster_sink_b_impl::time_raster_sink_b_impl(double samp_rate, d_scale = 1.0f; d_icols = static_cast<int>(ceil(d_cols)); - d_tmpflt = (float*)volk_malloc(d_icols * sizeof(float), volk_get_alignment()); - memset(d_tmpflt, 0, d_icols * sizeof(float)); + d_tmpflt.resize(d_icols); // +1 for the PDU buffer for (int i = 0; i < d_nconnections + 1; i++) { - d_residbufs.push_back( - (double*)volk_malloc(d_icols * sizeof(double), volk_get_alignment())); - memset(d_residbufs[i], 0, d_icols * sizeof(double)); + d_residbufs.emplace_back(d_icols); } set_multiplier(mult); @@ -96,13 +81,6 @@ time_raster_sink_b_impl::~time_raster_sink_b_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - volk_free(d_tmpflt); - for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - } - - delete d_argv; } bool time_raster_sink_b_impl::check_topology(int ninputs, int noutputs) @@ -247,15 +225,12 @@ void time_raster_sink_b_impl::set_num_cols(double cols) d_cols = cols; d_icols = static_cast<int>(ceil(d_cols)); - volk_free(d_tmpflt); - d_tmpflt = (float*)volk_malloc(d_icols * sizeof(float), volk_get_alignment()); - memset(d_tmpflt, 0, d_icols * sizeof(float)); + d_tmpflt.clear(); + d_tmpflt.resize(d_icols); for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - d_residbufs[i] = - (double*)volk_malloc(d_icols * sizeof(double), volk_get_alignment()); - memset(d_residbufs[i], 0, d_icols * sizeof(double)); + d_residbufs[i].clear(); + d_residbufs[i].resize(d_icols); } reset(); } @@ -386,14 +361,15 @@ int time_raster_sink_b_impl::work(int noutput_items, // Fill up residbufs with d_size number of items for (n = 0; n < d_nconnections; n++) { in = (const int8_t*)input_items[idx++]; - volk_8i_s32f_convert_32f(d_tmpflt, &in[j], d_scale, resid); + volk_8i_s32f_convert_32f(d_tmpflt.data(), &in[j], d_scale, resid); // Scale and add offset - volk_32f_s32f_multiply_32f(d_tmpflt, d_tmpflt, d_mult[n], resid); + volk_32f_s32f_multiply_32f( + d_tmpflt.data(), d_tmpflt.data(), d_mult[n], resid); for (unsigned int s = 0; s < resid; s++) d_tmpflt[s] = d_tmpflt[s] + d_offset[n]; - volk_32f_convert_64f_u(&d_residbufs[n][d_index], d_tmpflt, resid); + volk_32f_convert_64f_u(&d_residbufs[n][d_index], d_tmpflt.data(), resid); } if (gr::high_res_timer_now() - d_last_time > d_update_time) { @@ -410,14 +386,15 @@ int time_raster_sink_b_impl::work(int noutput_items, else { for (n = 0; n < d_nconnections; n++) { in = (const int8_t*)input_items[idx++]; - volk_8i_s32f_convert_32f(d_tmpflt, &in[j], d_scale, datasize); + volk_8i_s32f_convert_32f(d_tmpflt.data(), &in[j], d_scale, datasize); // Scale and add offset - volk_32f_s32f_multiply_32f(d_tmpflt, d_tmpflt, d_mult[n], datasize); + volk_32f_s32f_multiply_32f( + d_tmpflt.data(), d_tmpflt.data(), d_mult[n], datasize); for (unsigned int s = 0; s < datasize; s++) d_tmpflt[s] = d_tmpflt[s] + d_offset[n]; - volk_32f_convert_64f(&d_residbufs[n][d_index], d_tmpflt, datasize); + volk_32f_convert_64f(&d_residbufs[n][d_index], d_tmpflt.data(), datasize); } d_index += datasize; j += datasize; @@ -473,15 +450,16 @@ void time_raster_sink_b_impl::handle_pdus(pmt::pmt_t msg) for (int r = 0; r < irows; r++) { // Scale and add offset int cpy_len = std::min(static_cast<size_t>(d_cols), len - idx); - memset(d_residbufs[d_nconnections], 0, d_cols * sizeof(double)); - volk_8i_s32f_convert_32f(d_tmpflt, &in[idx], d_scale, cpy_len); + memset(d_residbufs[d_nconnections].data(), 0, d_cols * sizeof(double)); + volk_8i_s32f_convert_32f(d_tmpflt.data(), &in[idx], d_scale, cpy_len); volk_32f_s32f_multiply_32f( - d_tmpflt, d_tmpflt, d_mult[d_nconnections], cpy_len); + d_tmpflt.data(), d_tmpflt.data(), d_mult[d_nconnections], cpy_len); for (int c = 0; c < cpy_len; c++) { d_tmpflt[c] = d_tmpflt[c] + d_offset[d_nconnections]; } - volk_32f_convert_64f_u(d_residbufs[d_nconnections], d_tmpflt, cpy_len); + volk_32f_convert_64f_u( + d_residbufs[d_nconnections].data(), d_tmpflt.data(), cpy_len); d_qApplication->postEvent(d_main_gui, new TimeRasterUpdateEvent(d_residbufs, d_cols)); diff --git a/gr-qtgui/lib/time_raster_sink_b_impl.h b/gr-qtgui/lib/time_raster_sink_b_impl.h index 3ea51bbb1c..d8dcf527fb 100644 --- a/gr-qtgui/lib/time_raster_sink_b_impl.h +++ b/gr-qtgui/lib/time_raster_sink_b_impl.h @@ -29,16 +29,21 @@ private: const std::string d_name; int d_nconnections; - int d_index; - std::vector<double*> d_residbufs; + int d_index = 0; + std::vector<volk::vector<double>> d_residbufs; float d_scale; - float* d_tmpflt; - - int d_argc; - char* d_argv; + volk::vector<float> d_tmpflt; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - TimeRasterDisplayForm* d_main_gui; + TimeRasterDisplayForm* d_main_gui = nullptr; int d_icols; double d_rows, d_cols; diff --git a/gr-qtgui/lib/time_raster_sink_f_impl.cc b/gr-qtgui/lib/time_raster_sink_f_impl.cc index c59e632966..a9104b0b77 100644 --- a/gr-qtgui/lib/time_raster_sink_f_impl.cc +++ b/gr-qtgui/lib/time_raster_sink_f_impl.cc @@ -50,38 +50,22 @@ time_raster_sink_f_impl::time_raster_sink_f_impl(double samp_rate, io_signature::make(0, 0, 0)), d_name(name), d_nconnections(nconnections), - d_parent(parent), d_rows(rows), d_cols(cols), + d_icols(static_cast<int>(ceil(d_cols))), + d_tmpflt(d_icols), + d_parent(parent), d_mult(std::vector<float>(nconnections + 1, 1)), d_offset(std::vector<float>(nconnections + 1, 0)), d_samp_rate(samp_rate) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - - d_index = 0; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); - d_icols = static_cast<int>(ceil(d_cols)); - d_tmpflt = (float*)volk_malloc(d_icols * sizeof(float), volk_get_alignment()); - memset(d_tmpflt, 0, d_icols * sizeof(float)); - // +1 for the PDU buffer for (int i = 0; i < d_nconnections + 1; i++) { - d_residbufs.push_back( - (double*)volk_malloc(d_icols * sizeof(double), volk_get_alignment())); - memset(d_residbufs[i], 0, d_icols * sizeof(double)); + d_residbufs.emplace_back(d_icols); } set_multiplier(mult); @@ -94,13 +78,6 @@ time_raster_sink_f_impl::~time_raster_sink_f_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - volk_free(d_tmpflt); - for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - } - - delete d_argv; } bool time_raster_sink_f_impl::check_topology(int ninputs, int noutputs) @@ -250,15 +227,12 @@ void time_raster_sink_f_impl::set_num_cols(double cols) d_cols = cols; d_icols = static_cast<int>(ceil(d_cols)); - volk_free(d_tmpflt); - d_tmpflt = (float*)volk_malloc(d_icols * sizeof(float), volk_get_alignment()); - memset(d_tmpflt, 0, d_icols * sizeof(float)); + d_tmpflt.clear(); + d_tmpflt.resize(d_icols); for (int i = 0; i < d_nconnections + 1; i++) { - volk_free(d_residbufs[i]); - d_residbufs[i] = - (double*)volk_malloc(d_icols * sizeof(double), volk_get_alignment()); - memset(d_residbufs[i], 0, d_icols * sizeof(double)); + d_residbufs[i].clear(); + d_residbufs[i].resize(d_icols); } reset(); } @@ -383,11 +357,11 @@ int time_raster_sink_f_impl::work(int noutput_items, in = (const float*)input_items[idx++]; // Scale and add offset - volk_32f_s32f_multiply_32f(d_tmpflt, &in[j], d_mult[n], resid); + volk_32f_s32f_multiply_32f(d_tmpflt.data(), &in[j], d_mult[n], resid); for (unsigned int s = 0; s < resid; s++) d_tmpflt[s] = d_tmpflt[s] + d_offset[n]; - volk_32f_convert_64f_u(&d_residbufs[n][d_index], d_tmpflt, resid); + volk_32f_convert_64f_u(&d_residbufs[n][d_index], d_tmpflt.data(), resid); } // Update the plot if its time @@ -407,11 +381,11 @@ int time_raster_sink_f_impl::work(int noutput_items, in = (const float*)input_items[idx++]; // Scale and add offset - volk_32f_s32f_multiply_32f(d_tmpflt, &in[j], d_mult[n], datasize); + volk_32f_s32f_multiply_32f(d_tmpflt.data(), &in[j], d_mult[n], datasize); for (unsigned int s = 0; s < datasize; s++) d_tmpflt[s] = d_tmpflt[s] + d_offset[n]; - volk_32f_convert_64f(&d_residbufs[n][d_index], d_tmpflt, datasize); + volk_32f_convert_64f(&d_residbufs[n][d_index], d_tmpflt.data(), datasize); } d_index += datasize; j += datasize; @@ -464,14 +438,15 @@ void time_raster_sink_f_impl::handle_pdus(pmt::pmt_t msg) for (int r = 0; r < irows; r++) { // Scale and add offset int cpy_len = std::min(static_cast<size_t>(d_cols), len - idx); - memset(d_residbufs[d_nconnections], 0, d_cols * sizeof(double)); + memset(d_residbufs[d_nconnections].data(), 0, d_cols * sizeof(double)); volk_32f_s32f_multiply_32f( - d_tmpflt, &in[idx], d_mult[d_nconnections], cpy_len); + d_tmpflt.data(), &in[idx], d_mult[d_nconnections], cpy_len); for (int c = 0; c < cpy_len; c++) { d_tmpflt[c] = d_tmpflt[c] + d_offset[d_nconnections]; } - volk_32f_convert_64f_u(d_residbufs[d_nconnections], d_tmpflt, cpy_len); + volk_32f_convert_64f_u( + d_residbufs[d_nconnections].data(), d_tmpflt.data(), cpy_len); d_qApplication->postEvent(d_main_gui, new TimeRasterUpdateEvent(d_residbufs, d_cols)); diff --git a/gr-qtgui/lib/time_raster_sink_f_impl.h b/gr-qtgui/lib/time_raster_sink_f_impl.h index 444d61f0f5..5cf2da6257 100644 --- a/gr-qtgui/lib/time_raster_sink_f_impl.h +++ b/gr-qtgui/lib/time_raster_sink_f_impl.h @@ -29,18 +29,23 @@ private: const std::string d_name; int d_nconnections; - int d_index; - std::vector<double*> d_residbufs; + int d_index = 0; + std::vector<volk::vector<double>> d_residbufs; - float* d_tmpflt; - - int d_argc; - char* d_argv; + double d_rows, d_cols; + int d_icols; + volk::vector<float> d_tmpflt; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - TimeRasterDisplayForm* d_main_gui; + TimeRasterDisplayForm* d_main_gui = nullptr; - int d_icols; - double d_rows, d_cols; std::vector<float> d_mult; std::vector<float> d_offset; double d_samp_rate; diff --git a/gr-qtgui/lib/time_sink_c_impl.cc b/gr-qtgui/lib/time_sink_c_impl.cc index 1994a6501a..05c110b33a 100644 --- a/gr-qtgui/lib/time_sink_c_impl.cc +++ b/gr-qtgui/lib/time_sink_c_impl.cc @@ -56,32 +56,18 @@ time_sink_c_impl::time_sink_c_impl(int size, if (nconnections > 12) throw std::runtime_error("time_sink_c only supports up to 12 inputs"); - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); // +2 for the PDU message buffers for (unsigned int n = 0; n < d_nconnections + 2; n++) { - d_buffers.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); + d_buffers.emplace_back(d_buffer_size); } // We don't use cbuffers with the PDU message handling capabilities. for (unsigned int n = 0; n < d_nconnections / 2; n++) { - d_cbuffers.push_back((gr_complex*)volk_malloc(d_buffer_size * sizeof(gr_complex), - volk_get_alignment())); - std::fill_n(d_cbuffers[n], d_buffer_size, 0); + d_cbuffers.emplace_back(d_buffer_size); } // Set alignment properties for VOLK @@ -103,16 +89,6 @@ time_sink_c_impl::~time_sink_c_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - // d_main_gui is a qwidget destroyed with its parent - for (unsigned int n = 0; n < d_nconnections + 2; n++) { - volk_free(d_buffers[n]); - } - for (unsigned int n = 0; n < d_nconnections / 2; n++) { - volk_free(d_cbuffers[n]); - } - - delete d_argv; } bool time_sink_c_impl::check_topology(int ninputs, int noutputs) @@ -302,17 +278,10 @@ void time_sink_c_impl::set_nsamps(const int newsize) // Resize buffers and replace data for (unsigned int n = 0; n < d_nconnections + 2; n++) { - volk_free(d_buffers[n]); - d_buffers[n] = (double*)volk_malloc(d_buffer_size * sizeof(double), - volk_get_alignment()); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); - } - - for (unsigned int n = 0; n < d_nconnections / 2; n++) { - volk_free(d_cbuffers[n]); - d_cbuffers[n] = (gr_complex*)volk_malloc(d_buffer_size * sizeof(gr_complex), - volk_get_alignment()); - std::fill_n(d_cbuffers[n], d_buffer_size, 0); + d_buffers[n].clear(); + d_buffers[n].resize(d_buffer_size); + d_cbuffers[n].clear(); + d_cbuffers[n].resize(d_buffer_size); } // If delay was set beyond the new boundary, pull it back. @@ -391,7 +360,7 @@ void time_sink_c_impl::_reset() // represents data that might have to be plotted again if a // trigger occurs and we have a trigger delay set. The tail // section is between (d_end-d_trigger_delay) and d_end. - memmove(d_cbuffers[n], + memmove(d_cbuffers[n].data(), &d_cbuffers[n][d_end - d_trigger_delay], d_trigger_delay * sizeof(gr_complex)); @@ -588,8 +557,8 @@ int time_sink_c_impl::work(int noutput_items, if ((d_triggered) && (d_index == d_end)) { // Copy data to be plotted to start of buffers. for (n = 0; n < d_nconnections / 2; n++) { - volk_32fc_deinterleave_64f_x2(d_buffers[2 * n + 0], - d_buffers[2 * n + 1], + volk_32fc_deinterleave_64f_x2(d_buffers[2 * n + 0].data(), + d_buffers[2 * n + 1].data(), &d_cbuffers[n][d_start], d_size); } @@ -671,8 +640,8 @@ void time_sink_c_impl::handle_pdus(pmt::pmt_t msg) set_nsamps(len); - volk_32fc_deinterleave_64f_x2(d_buffers[2 * d_nconnections + 0], - d_buffers[2 * d_nconnections + 1], + volk_32fc_deinterleave_64f_x2(d_buffers[2 * d_nconnections + 0].data(), + d_buffers[2 * d_nconnections + 1].data(), in, len); diff --git a/gr-qtgui/lib/time_sink_c_impl.h b/gr-qtgui/lib/time_sink_c_impl.h index 903734d53f..9e2d4f4e35 100644 --- a/gr-qtgui/lib/time_sink_c_impl.h +++ b/gr-qtgui/lib/time_sink_c_impl.h @@ -32,14 +32,19 @@ private: const pmt::pmt_t d_tag_key; int d_index, d_start, d_end; - std::vector<gr_complex*> d_cbuffers; - std::vector<double*> d_buffers; + std::vector<volk::vector<gr_complex>> d_cbuffers; + std::vector<volk::vector<double>> d_buffers; std::vector<std::vector<gr::tag_t>> d_tags; - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - TimeDisplayForm* d_main_gui; + TimeDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; diff --git a/gr-qtgui/lib/time_sink_f_impl.cc b/gr-qtgui/lib/time_sink_f_impl.cc index d14f7ef293..7bad006d16 100644 --- a/gr-qtgui/lib/time_sink_f_impl.cc +++ b/gr-qtgui/lib/time_sink_f_impl.cc @@ -57,29 +57,14 @@ time_sink_f_impl::time_sink_f_impl(int size, if (nconnections > 24) throw std::runtime_error("time_sink_f only supports up to 24 inputs"); - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - // setup PDU handling input port message_port_register_in(pmt::mp("in")); set_msg_handler(pmt::mp("in"), [this](pmt::pmt_t msg) { this->handle_pdus(msg); }); // +1 for the PDU buffer for (unsigned int n = 0; n < d_nconnections + 1; n++) { - d_buffers.push_back( - (double*)volk_malloc(d_buffer_size * sizeof(double), volk_get_alignment())); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); - - d_fbuffers.push_back( - (float*)volk_malloc(d_buffer_size * sizeof(float), volk_get_alignment())); - memset(d_fbuffers[n], 0, d_buffer_size * sizeof(float)); + d_buffers.emplace_back(d_buffer_size); + d_fbuffers.emplace_back(d_buffer_size); } // Set alignment properties for VOLK @@ -101,14 +86,7 @@ time_sink_f_impl::~time_sink_f_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - // d_main_gui is a qwidget destroyed with its parent - for (unsigned int n = 0; n < d_nconnections + 1; n++) { - volk_free(d_buffers[n]); - volk_free(d_fbuffers[n]); - } - - delete d_argv; } bool time_sink_f_impl::check_topology(int ninputs, int noutputs) @@ -298,15 +276,10 @@ void time_sink_f_impl::set_nsamps(const int newsize) // Resize buffers and replace data for (unsigned int n = 0; n < d_nconnections + 1; n++) { - volk_free(d_buffers[n]); - d_buffers[n] = (double*)volk_malloc(d_buffer_size * sizeof(double), - volk_get_alignment()); - memset(d_buffers[n], 0, d_buffer_size * sizeof(double)); - - volk_free(d_fbuffers[n]); - d_fbuffers[n] = - (float*)volk_malloc(d_buffer_size * sizeof(float), volk_get_alignment()); - memset(d_fbuffers[n], 0, d_buffer_size * sizeof(float)); + d_buffers[n].clear(); + d_buffers[n].resize(d_buffer_size); + d_fbuffers[n].clear(); + d_fbuffers[n].resize(d_buffer_size); } // If delay was set beyond the new boundary, pull it back. @@ -385,7 +358,7 @@ void time_sink_f_impl::_reset() // represents data that might have to be plotted again if a // trigger occurs and we have a trigger delay set. The tail // section is between (d_end-d_trigger_delay) and d_end. - memmove(d_fbuffers[n], + memmove(d_fbuffers[n].data(), &d_fbuffers[n][d_end - d_trigger_delay], d_trigger_delay * sizeof(float)); @@ -580,7 +553,7 @@ int time_sink_f_impl::work(int noutput_items, // Copy data to be plotted to start of buffers. for (n = 0; n < d_nconnections; n++) { // memmove(d_buffers[n], &d_buffers[n][d_start], d_size*sizeof(double)); - volk_32f_convert_64f(d_buffers[n], &d_fbuffers[n][d_start], d_size); + volk_32f_convert_64f(d_buffers[n].data(), &d_fbuffers[n][d_start], d_size); } // Plot if we are able to update @@ -658,7 +631,7 @@ void time_sink_f_impl::handle_pdus(pmt::pmt_t msg) set_nsamps(len); - volk_32f_convert_64f(d_buffers[d_nconnections], in, len); + volk_32f_convert_64f(d_buffers[d_nconnections].data(), in, len); d_qApplication->postEvent(d_main_gui, new TimeUpdateEvent(d_buffers, len, t)); } diff --git a/gr-qtgui/lib/time_sink_f_impl.h b/gr-qtgui/lib/time_sink_f_impl.h index d011b2681e..cedef648f0 100644 --- a/gr-qtgui/lib/time_sink_f_impl.h +++ b/gr-qtgui/lib/time_sink_f_impl.h @@ -31,14 +31,19 @@ private: const pmt::pmt_t d_tag_key; int d_index, d_start, d_end; - std::vector<float*> d_fbuffers; - std::vector<double*> d_buffers; + std::vector<volk::vector<float>> d_fbuffers; + std::vector<volk::vector<double>> d_buffers; std::vector<std::vector<gr::tag_t>> d_tags; - int d_argc; - char* d_argv; + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - TimeDisplayForm* d_main_gui; + TimeDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; diff --git a/gr-qtgui/lib/vector_sink_f_impl.cc b/gr-qtgui/lib/vector_sink_f_impl.cc index 5338007bf3..30e49cd931 100644 --- a/gr-qtgui/lib/vector_sink_f_impl.cc +++ b/gr-qtgui/lib/vector_sink_f_impl.cc @@ -59,24 +59,12 @@ vector_sink_f_impl::vector_sink_f_impl(unsigned int vlen, d_msg(pmt::mp("x")), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - // setup output message port to post frequency when display is // double-clicked message_port_register_out(d_port); - d_main_gui = NULL; - for (int i = 0; i < d_nconnections; i++) { - d_magbufs.push_back( - (double*)volk_malloc(d_vlen * sizeof(double), volk_get_alignment())); - memset(d_magbufs[i], 0, d_vlen * sizeof(double)); + d_magbufs.emplace_back(d_vlen); } initialize(name, x_axis_label, y_axis_label, x_start, x_step); @@ -87,12 +75,6 @@ vector_sink_f_impl::~vector_sink_f_impl() if (!d_main_gui->isClosed()) { d_main_gui->close(); } - - for (int i = 0; i < d_nconnections; i++) { - volk_free(d_magbufs[i]); - } - - delete d_argv; } bool vector_sink_f_impl::check_topology(int ninputs, int noutputs) diff --git a/gr-qtgui/lib/vector_sink_f_impl.h b/gr-qtgui/lib/vector_sink_f_impl.h index 527a2ea39d..a76e0c6402 100644 --- a/gr-qtgui/lib/vector_sink_f_impl.h +++ b/gr-qtgui/lib/vector_sink_f_impl.h @@ -37,13 +37,17 @@ private: const pmt::pmt_t d_port; const pmt::pmt_t d_msg; //< Key of outgoing messages - std::vector<double*> d_magbufs; - - - int d_argc; - char* d_argv; + std::vector<volk::vector<double>> d_magbufs; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - VectorDisplayForm* d_main_gui; + VectorDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; @@ -66,6 +70,13 @@ public: QWidget* parent = NULL); ~vector_sink_f_impl() override; + // Disallow copy/move because raw pointers. + vector_sink_f_impl(const vector_sink_f_impl&) = delete; + vector_sink_f_impl(vector_sink_f_impl&&) = delete; + vector_sink_f_impl& operator=(const vector_sink_f_impl&) = delete; + vector_sink_f_impl& operator=(vector_sink_f_impl&&) = delete; + + bool check_topology(int ninputs, int noutputs) override; void exec_() override; diff --git a/gr-qtgui/lib/waterfall_sink_c_impl.cc b/gr-qtgui/lib/waterfall_sink_c_impl.cc index 5de8535585..3ca73c343a 100644 --- a/gr-qtgui/lib/waterfall_sink_c_impl.cc +++ b/gr-qtgui/lib/waterfall_sink_c_impl.cc @@ -60,44 +60,18 @@ waterfall_sink_c_impl::waterfall_sink_c_impl(int fftsize, d_nrows(200), d_port(pmt::mp("freq")), d_port_bw(pmt::mp("bw")), + d_fft(std::make_unique<fft::fft_complex_fwd>(fftsize)), + d_fbuf(fftsize), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - - // Perform fftshift operation; - // this is usually desired when plotting - d_shift = true; - - d_fft = new fft::fft_complex_fwd(d_fftsize); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); - - d_index = 0; // save the last "connection" for the PDU memory - for (int i = 0; i < d_nconnections; i++) { - d_residbufs.push_back((gr_complex*)volk_malloc(d_fftsize * sizeof(gr_complex), - volk_get_alignment())); - d_magbufs.push_back( - (double*)volk_malloc(d_fftsize * sizeof(double), volk_get_alignment())); - std::fill_n(d_residbufs[i], d_fftsize, 0); - memset(d_magbufs[i], 0, d_fftsize * sizeof(double)); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs.emplace_back(d_fftsize); + d_magbufs.emplace_back(d_fftsize); } - d_residbufs.push_back( - (gr_complex*)volk_malloc(d_fftsize * sizeof(gr_complex), volk_get_alignment())); - d_pdu_magbuf = - (double*)volk_malloc(d_fftsize * sizeof(double) * d_nrows, volk_get_alignment()); - d_magbufs.push_back(d_pdu_magbuf); - memset(d_pdu_magbuf, 0, d_fftsize * sizeof(double) * d_nrows); - std::fill_n(d_residbufs[d_nconnections], d_fftsize, 0); + d_residbufs.emplace_back(d_fftsize); + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); buildwindow(); @@ -122,15 +96,6 @@ waterfall_sink_c_impl::~waterfall_sink_c_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - for (int i = 0; i < (int)d_residbufs.size(); i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - } - delete d_fft; - volk_free(d_fbuf); - - delete d_argv; } bool waterfall_sink_c_impl::check_topology(int ninputs, int noutputs) @@ -348,31 +313,13 @@ void waterfall_sink_c_impl::fftresize() if (newfftsize != d_fftsize) { // Resize residbuf and replace data - for (int i = 0; i < d_nconnections; i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - - d_residbufs[i] = (gr_complex*)volk_malloc(newfftsize * sizeof(gr_complex), - volk_get_alignment()); - d_magbufs[i] = - (double*)volk_malloc(newfftsize * sizeof(double), volk_get_alignment()); - - std::fill_n(d_residbufs[i], newfftsize, 0); - memset(d_magbufs[i], 0, newfftsize * sizeof(double)); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs[i].clear(); + d_residbufs[i].resize(newfftsize); + d_magbufs[i].clear(); + d_magbufs[i].resize(newfftsize); } - - // Handle the PDU buffers separately because of the different - // size requirement of the pdu_magbuf. - volk_free(d_residbufs[d_nconnections]); - volk_free(d_pdu_magbuf); - - d_residbufs[d_nconnections] = (gr_complex*)volk_malloc( - newfftsize * sizeof(gr_complex), volk_get_alignment()); - d_pdu_magbuf = (double*)volk_malloc(newfftsize * sizeof(double) * d_nrows, - volk_get_alignment()); - d_magbufs[d_nconnections] = d_pdu_magbuf; - std::fill_n(d_residbufs[d_nconnections], newfftsize, 0); - memset(d_pdu_magbuf, 0, newfftsize * sizeof(double) * d_nrows); + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); // Set new fft size and reset buffer index // (throws away any currently held data, but who cares?) @@ -383,14 +330,12 @@ void waterfall_sink_c_impl::fftresize() buildwindow(); // Reset FFTW plan for new size - delete d_fft; - d_fft = new fft::fft_complex_fwd(d_fftsize); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); d_fft_shift.resize(d_fftsize); - volk_free(d_fbuf); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); + d_fbuf.clear(); + d_fbuf.resize(d_fftsize); d_last_time = 0; } @@ -453,9 +398,11 @@ int waterfall_sink_c_impl::work(int noutput_items, for (int n = 0; n < d_nconnections; n++) { // Fill up residbuf with d_fftsize number of items in = (const gr_complex*)input_items[n]; - memcpy(d_residbufs[n] + d_index, &in[j], sizeof(gr_complex) * resid); + memcpy(d_residbufs[n].data() + d_index, + &in[j], + sizeof(gr_complex) * resid); - fft(d_fbuf, d_residbufs[n], d_fftsize); + fft(d_fbuf.data(), d_residbufs[n].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_magbufs[n][x] = (double)((1.0 - d_fftavg) * d_magbufs[n][x] + (d_fftavg)*d_fbuf[x]); @@ -476,7 +423,9 @@ int waterfall_sink_c_impl::work(int noutput_items, else { for (int n = 0; n < d_nconnections; n++) { in = (const gr_complex*)input_items[n]; - memcpy(d_residbufs[n] + d_index, &in[j], sizeof(gr_complex) * datasize); + memcpy(d_residbufs[n].data() + d_index, + &in[j], + sizeof(gr_complex) * datasize); } d_index += datasize; j += datasize; @@ -544,15 +493,16 @@ void waterfall_sink_c_impl::handle_pdus(pmt::pmt_t msg) size_t max = std::min(d_fftsize, static_cast<int>(len)); for (size_t i = 0; j < d_nrows; i += stride) { // Clear residbufs if len < d_fftsize - std::fill_n(d_residbufs[d_nconnections], d_fftsize, 0x00); + std::fill_n(d_residbufs[d_nconnections].data(), d_fftsize, 0x00); // Copy in as much of the input samples as we can - memcpy( - d_residbufs[d_nconnections], &in[min], sizeof(gr_complex) * (max - min)); + memcpy(d_residbufs[d_nconnections].data(), + &in[min], + sizeof(gr_complex) * (max - min)); // Apply the window and FFT; copy data into the PDU // magnitude buffer. - fft(d_fbuf, d_residbufs[d_nconnections], d_fftsize); + fft(d_fbuf.data(), d_residbufs[d_nconnections].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_pdu_magbuf[j * d_fftsize + x] = (double)d_fbuf[x]; } diff --git a/gr-qtgui/lib/waterfall_sink_c_impl.h b/gr-qtgui/lib/waterfall_sink_c_impl.h index add30af47d..a4b03ff689 100644 --- a/gr-qtgui/lib/waterfall_sink_c_impl.h +++ b/gr-qtgui/lib/waterfall_sink_c_impl.h @@ -43,19 +43,26 @@ private: const pmt::pmt_t d_port; const pmt::pmt_t d_port_bw; - bool d_shift; - fft::fft_complex_fwd* d_fft; - - int d_index; - std::vector<gr_complex*> d_residbufs; - std::vector<double*> d_magbufs; + // Perform fftshift operation; + // this is usually desired when plotting + bool d_shift = true; + std::unique_ptr<fft::fft_complex_fwd> d_fft; + + int d_index = 0; + std::vector<volk::vector<gr_complex>> d_residbufs; + std::vector<volk::vector<double>> d_magbufs; double* d_pdu_magbuf; - float* d_fbuf; - - int d_argc; - char* d_argv; + volk::vector<float> d_fbuf; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - WaterfallDisplayForm* d_main_gui; + WaterfallDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; diff --git a/gr-qtgui/lib/waterfall_sink_f_impl.cc b/gr-qtgui/lib/waterfall_sink_f_impl.cc index 00fe487303..d46e58cd56 100644 --- a/gr-qtgui/lib/waterfall_sink_f_impl.cc +++ b/gr-qtgui/lib/waterfall_sink_f_impl.cc @@ -58,44 +58,17 @@ waterfall_sink_f_impl::waterfall_sink_f_impl(int fftsize, d_nrows(200), d_port(pmt::mp("freq")), d_port_bw(pmt::mp("bw")), + d_fft(std::make_unique<fft::fft_complex_fwd>(d_fftsize)), + d_fbuf(fftsize), d_parent(parent) { - // Required now for Qt; argc must be greater than 0 and argv - // must have at least one valid character. Must be valid through - // life of the qApplication: - // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html - d_argc = 1; - d_argv = new char; - d_argv[0] = '\0'; - - d_main_gui = NULL; - - // Perform fftshift operation; - // this is usually desired when plotting - d_shift = true; - - d_fft = new fft::fft_complex_fwd(d_fftsize); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); - - d_index = 0; // save the last "connection" for the PDU memory - for (int i = 0; i < d_nconnections; i++) { - d_residbufs.push_back( - (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment())); - d_magbufs.push_back( - (double*)volk_malloc(d_fftsize * sizeof(double), volk_get_alignment())); - memset(d_residbufs[i], 0, d_fftsize * sizeof(float)); - memset(d_magbufs[i], 0, d_fftsize * sizeof(double)); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs.emplace_back(d_fftsize); + d_magbufs.emplace_back(d_fftsize); } - d_residbufs.push_back( - (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment())); - d_pdu_magbuf = - (double*)volk_malloc(d_fftsize * sizeof(double) * d_nrows, volk_get_alignment()); - d_magbufs.push_back(d_pdu_magbuf); - memset(d_pdu_magbuf, 0, d_fftsize * sizeof(double) * d_nrows); - memset(d_residbufs[d_nconnections], 0, d_fftsize * sizeof(float)); + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); buildwindow(); @@ -120,15 +93,6 @@ waterfall_sink_f_impl::~waterfall_sink_f_impl() { if (!d_main_gui->isClosed()) d_main_gui->close(); - - for (int i = 0; i < (int)d_residbufs.size(); i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - } - delete d_fft; - volk_free(d_fbuf); - - delete d_argv; } bool waterfall_sink_f_impl::check_topology(int ninputs, int noutputs) @@ -354,31 +318,14 @@ void waterfall_sink_f_impl::fftresize() if (newfftsize != d_fftsize) { // Resize residbuf and replace data - for (int i = 0; i < d_nconnections; i++) { - volk_free(d_residbufs[i]); - volk_free(d_magbufs[i]); - - d_residbufs[i] = - (float*)volk_malloc(newfftsize * sizeof(float), volk_get_alignment()); - d_magbufs[i] = - (double*)volk_malloc(newfftsize * sizeof(double), volk_get_alignment()); + for (int i = 0; i < d_nconnections + 1; i++) { + d_residbufs[i].clear(); + d_magbufs[i].clear(); - memset(d_residbufs[i], 0, newfftsize * sizeof(float)); - memset(d_magbufs[i], 0, newfftsize * sizeof(double)); + d_residbufs[i].resize(newfftsize); + d_magbufs[i].resize(newfftsize); } - - // Handle the PDU buffers separately because of the different - // size requirement of the pdu_magbuf. - volk_free(d_residbufs[d_nconnections]); - volk_free(d_pdu_magbuf); - - d_residbufs[d_nconnections] = - (float*)volk_malloc(newfftsize * sizeof(float), volk_get_alignment()); - d_pdu_magbuf = (double*)volk_malloc(newfftsize * sizeof(double) * d_nrows, - volk_get_alignment()); - d_magbufs[d_nconnections] = d_pdu_magbuf; - memset(d_residbufs[d_nconnections], 0, newfftsize * sizeof(float)); - memset(d_pdu_magbuf, 0, newfftsize * sizeof(double) * d_nrows); + d_pdu_magbuf = d_magbufs[d_magbufs.size() - 1].data(); // Set new fft size and reset buffer index // (throws away any currently held data, but who cares?) @@ -389,14 +336,12 @@ void waterfall_sink_f_impl::fftresize() buildwindow(); // Reset FFTW plan for new size - delete d_fft; - d_fft = new fft::fft_complex_fwd(d_fftsize); + d_fft = std::make_unique<fft::fft_complex_fwd>(d_fftsize); d_fft_shift.resize(d_fftsize); - volk_free(d_fbuf); - d_fbuf = (float*)volk_malloc(d_fftsize * sizeof(float), volk_get_alignment()); - memset(d_fbuf, 0, d_fftsize * sizeof(float)); + d_fbuf.clear(); + d_fbuf.resize(d_fftsize); d_last_time = 0; } @@ -459,9 +404,10 @@ int waterfall_sink_f_impl::work(int noutput_items, for (int n = 0; n < d_nconnections; n++) { // Fill up residbuf with d_fftsize number of items in = (const float*)input_items[n]; - memcpy(d_residbufs[n] + d_index, &in[j], sizeof(float) * resid); + memcpy( + d_residbufs[n].data() + d_index, &in[j], sizeof(float) * resid); - fft(d_fbuf, d_residbufs[n], d_fftsize); + fft(d_fbuf.data(), d_residbufs[n].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_magbufs[n][x] = (double)((1.0 - d_fftavg) * d_magbufs[n][x] + (d_fftavg)*d_fbuf[x]); @@ -482,7 +428,7 @@ int waterfall_sink_f_impl::work(int noutput_items, else { for (int n = 0; n < d_nconnections; n++) { in = (const float*)input_items[n]; - memcpy(d_residbufs[n] + d_index, &in[j], sizeof(float) * datasize); + memcpy(d_residbufs[n].data() + d_index, &in[j], sizeof(float) * datasize); } d_index += datasize; j += datasize; @@ -550,14 +496,16 @@ void waterfall_sink_f_impl::handle_pdus(pmt::pmt_t msg) size_t max = std::min(d_fftsize, static_cast<int>(len)); for (size_t i = 0; j < d_nrows; i += stride) { // Clear residbufs if len < d_fftsize - memset(d_residbufs[d_nconnections], 0x00, sizeof(float) * d_fftsize); + memset(d_residbufs[d_nconnections].data(), 0x00, sizeof(float) * d_fftsize); // Copy in as much of the input samples as we can - memcpy(d_residbufs[d_nconnections], &in[min], sizeof(float) * (max - min)); + memcpy(d_residbufs[d_nconnections].data(), + &in[min], + sizeof(float) * (max - min)); // Apply the window and FFT; copy data into the PDU // magnitude buffer. - fft(d_fbuf, d_residbufs[d_nconnections], d_fftsize); + fft(d_fbuf.data(), d_residbufs[d_nconnections].data(), d_fftsize); for (int x = 0; x < d_fftsize; x++) { d_pdu_magbuf[j * d_fftsize + x] = (double)d_fbuf[x]; } diff --git a/gr-qtgui/lib/waterfall_sink_f_impl.h b/gr-qtgui/lib/waterfall_sink_f_impl.h index d206825d8c..cd70e20de6 100644 --- a/gr-qtgui/lib/waterfall_sink_f_impl.h +++ b/gr-qtgui/lib/waterfall_sink_f_impl.h @@ -43,19 +43,26 @@ private: const pmt::pmt_t d_port; const pmt::pmt_t d_port_bw; - bool d_shift; - fft::fft_complex_fwd* d_fft; - - int d_index; - std::vector<float*> d_residbufs; - std::vector<double*> d_magbufs; + // Perform fftshift operation; + // this is usually desired when plotting + bool d_shift = true; + std::unique_ptr<fft::fft_complex_fwd> d_fft; + + int d_index = 0; + std::vector<volk::vector<float>> d_residbufs; + std::vector<volk::vector<double>> d_magbufs; double* d_pdu_magbuf; - float* d_fbuf; - - int d_argc; - char* d_argv; + volk::vector<float> d_fbuf; + + // Required now for Qt; argc must be greater than 0 and argv + // must have at least one valid character. Must be valid through + // life of the qApplication: + // http://harmattan-dev.nokia.com/docs/library/html/qt4/qapplication.html + char d_zero = 0; + int d_argc = 1; + char* d_argv = &d_zero; QWidget* d_parent; - WaterfallDisplayForm* d_main_gui; + WaterfallDisplayForm* d_main_gui = nullptr; gr::high_res_timer_type d_update_time; gr::high_res_timer_type d_last_time; |