From 0faa5a81dbd7d2ee1b4f1f80000bbff15e4ca22e Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 29 May 2019 16:16:42 +0000 Subject: [PATCH] Peak detect - optional outputs - make general block git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@509 b431acfa-c32f-4a4a-93f1-934dc6c82436 --- gr-jay/grc/jay_peak_detect.xml | 2 ++ gr-jay/include/jay/peak_detect.h | 2 +- gr-jay/lib/peak_detect_impl.cc | 46 ++++++++++++++++++++++---------- gr-jay/lib/peak_detect_impl.h | 4 ++- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/gr-jay/grc/jay_peak_detect.xml b/gr-jay/grc/jay_peak_detect.xml index de5bbf5..38a5998 100644 --- a/gr-jay/grc/jay_peak_detect.xml +++ b/gr-jay/grc/jay_peak_detect.xml @@ -90,11 +90,13 @@ out float $vlen + 1 pbox float $vlen + 1 status diff --git a/gr-jay/include/jay/peak_detect.h b/gr-jay/include/jay/peak_detect.h index 804ea2d..0c252c8 100644 --- a/gr-jay/include/jay/peak_detect.h +++ b/gr-jay/include/jay/peak_detect.h @@ -33,7 +33,7 @@ namespace gr { * \ingroup jay * */ - class JAY_API peak_detect : virtual public gr::sync_block + class JAY_API peak_detect : virtual public gr::block { public: typedef boost::shared_ptr sptr; diff --git a/gr-jay/lib/peak_detect_impl.cc b/gr-jay/lib/peak_detect_impl.cc index eddc240..5a4ab3d 100644 --- a/gr-jay/lib/peak_detect_impl.cc +++ b/gr-jay/lib/peak_detect_impl.cc @@ -39,9 +39,9 @@ namespace gr { * The private constructor */ peak_detect_impl::peak_detect_impl(int vlen, float framerate, float bandwidth, float fcenter, float peak_height_min, int peak_width_min, int peak_width_max, float alpha_s, float alpha_m) - : gr::sync_block("peak_detect" + : gr::block("peak_detect" , gr::io_signature::make(1, 1, vlen*sizeof(float)) - , gr::io_signature::make(2, 2, vlen*sizeof(float))) + , gr::io_signature::make(0, 2, vlen*sizeof(float))) , m_vlen(vlen) , m_framerate (framerate) , m_bandwidth (bandwidth) @@ -126,23 +126,31 @@ namespace gr { } } return result; - } + } - int - peak_detect_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + void peak_detect_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required) + { + ninput_items_required[0] = noutput_items; + } + + int peak_detect_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { const int DATA = 0; const int PBOX = 1; - + int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(float); float *iptr = (float *)input_items[DATA]; - float *optr_data = (float *)output_items[DATA]; - float *optr_pbox = (float *)output_items[PBOX]; + float *optr_data = nullptr; + float *optr_pbox = nullptr; + + if (output_items.size() > 0) + { + optr_data = (float *)output_items[DATA]; + optr_pbox = (float *)output_items[PBOX]; + } - for (int k = 0; k < noutput_items; k++) + for (int k = 0; k < ninput_items[DATA]; k++) { // Initialization on first frame if (m_frameCount == 0) @@ -369,13 +377,23 @@ namespace gr { // ----------------------------------------------------------------- // Output peak box data // ----------------------------------------------------------------- - for (int i = 0; i < nitems_per_block; i++) + if (optr_data) { - *(optr_data++) = m_pXs[i]; - *(optr_pbox++) = m_pPeakBox_abs[i]; + for (int i = 0; i < nitems_per_block; i++) + { + *(optr_data++) = m_pXs[i]; + } + } + if (optr_pbox) + { + for (int i = 0; i < nitems_per_block; i++) + { + *(optr_pbox++) = m_pPeakBox_abs[i]; + } } m_frameCount++; + consume(0, ninput_items[DATA]); } // Tell runtime system how many output items we produced. diff --git a/gr-jay/lib/peak_detect_impl.h b/gr-jay/lib/peak_detect_impl.h index a51b1ee..4f61d7b 100644 --- a/gr-jay/lib/peak_detect_impl.h +++ b/gr-jay/lib/peak_detect_impl.h @@ -326,7 +326,9 @@ namespace jay { ~peak_detect_impl(); // Where all the action really happens - int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + private: void fill(float *pDst, int length, float value); float mean(float *pSrc, int length);