diff options
author | Josh Blum <josh@joshknows.com> | 2013-06-07 08:34:26 -0700 |
---|---|---|
committer | Johnathan Corgan <johnathan@corganlabs.com> | 2013-06-07 11:41:27 -0400 |
commit | c25304bf1c87f0044a34188d51142b8a7e2b4378 (patch) | |
tree | efca7e9584035a95a0fdaa140956a526e195863f | |
parent | fed9214214380a1d8ce3aef8c3a953e0490adb1f (diff) |
blocks: plateau_detector_fb is now a gr_block and forecasts
The detector actually could return 0 with insufficient input.
The forecast always requires at least 2*d_max_len.
However, forecast could be conditionalized to only
require this based on the last threshold detected.
-rw-r--r-- | gr-blocks/include/gnuradio/blocks/plateau_detector_fb.h | 2 | ||||
-rw-r--r-- | gr-blocks/lib/plateau_detector_fb_impl.cc | 18 | ||||
-rw-r--r-- | gr-blocks/lib/plateau_detector_fb_impl.h | 9 |
3 files changed, 20 insertions, 9 deletions
diff --git a/gr-blocks/include/gnuradio/blocks/plateau_detector_fb.h b/gr-blocks/include/gnuradio/blocks/plateau_detector_fb.h index 3f5ea189e9..cb43625c1f 100644 --- a/gr-blocks/include/gnuradio/blocks/plateau_detector_fb.h +++ b/gr-blocks/include/gnuradio/blocks/plateau_detector_fb.h @@ -51,7 +51,7 @@ namespace gr { * An implicit hysteresis is provided by the fact that after detecting one plateau, * it waits at least max_len samples before the next plateau can be detected. */ - class BLOCKS_API plateau_detector_fb : virtual public sync_block + class BLOCKS_API plateau_detector_fb : virtual public block { public: typedef boost::shared_ptr<plateau_detector_fb> sptr; diff --git a/gr-blocks/lib/plateau_detector_fb_impl.cc b/gr-blocks/lib/plateau_detector_fb_impl.cc index 0c35a32f68..14d52b392c 100644 --- a/gr-blocks/lib/plateau_detector_fb_impl.cc +++ b/gr-blocks/lib/plateau_detector_fb_impl.cc @@ -38,7 +38,7 @@ namespace gr { } plateau_detector_fb_impl::plateau_detector_fb_impl(int max_len, float threshold) - : sync_block("plateau_detector_fb", + : block("plateau_detector_fb", io_signature::make(1, 1, sizeof(float)), io_signature::make(1, 1, sizeof(char))), d_max_len(max_len), @@ -49,15 +49,22 @@ namespace gr { { } + void + plateau_detector_fb_impl::forecast(int, gr_vector_int &ninput_items_required) + { + ninput_items_required[0] = 2*d_max_len; + } + int - plateau_detector_fb_impl::work(int noutput_items, - gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + plateau_detector_fb_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 float *in = (const float *) input_items[0]; unsigned char *out = (unsigned char *) output_items[0]; int flank_start; - + noutput_items = std::min(noutput_items, ninput_items[0]); memset((void *) out, 0x00, noutput_items); int i; for(i = 0; i < noutput_items; i++) { @@ -75,6 +82,7 @@ namespace gr { } } + this->consume_each(i); return i; } diff --git a/gr-blocks/lib/plateau_detector_fb_impl.h b/gr-blocks/lib/plateau_detector_fb_impl.h index 6497f0e838..906891d62b 100644 --- a/gr-blocks/lib/plateau_detector_fb_impl.h +++ b/gr-blocks/lib/plateau_detector_fb_impl.h @@ -38,9 +38,12 @@ class plateau_detector_fb_impl : public plateau_detector_fb plateau_detector_fb_impl(int max_len, float threshold); ~plateau_detector_fb_impl(); - int work(int noutput_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); + + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); }; } // namespace blocks |