commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 03/24: Adding new test block to adjust the


From: git
Subject: [Commit-gnuradio] [gnuradio] 03/24: Adding new test block to adjust the sample rate of a stream and make sure tags are being placed in the correct locations.
Date: Tue, 14 Jun 2016 00:40:55 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch packet2
in repository gnuradio.

commit 78e2b15125434142ab999cb32006516062abb6e7
Author: Tom Rondeau <address@hidden>
Date:   Thu Nov 19 16:24:53 2015 -0500

    Adding new test block to adjust the sample rate of a stream and make
    sure tags are being placed in the correct locations.
---
 gnuradio-runtime/include/gnuradio/block_detail.h   |    3 +
 gnuradio-runtime/lib/block_detail.cc               |    8 +
 gnuradio-runtime/lib/block_executor.cc             |   21 +-
 gr-blocks/examples/tags/test_tag_prop.grc          | 1145 ++++++++++++++++++++
 gr-blocks/grc/blocks_block_tree.xml                |    2 +
 gr-blocks/grc/blocks_test_tag_variable_rate_ff.xml |   47 +
 gr-blocks/include/gnuradio/blocks/CMakeLists.txt   |    1 +
 .../gnuradio/blocks/test_tag_variable_rate_ff.h    |   79 ++
 gr-blocks/lib/CMakeLists.txt                       |    1 +
 gr-blocks/lib/test_tag_variable_rate_ff_impl.cc    |  139 +++
 gr-blocks/lib/test_tag_variable_rate_ff_impl.h     |   56 +
 gr-blocks/swig/blocks_swig5.i                      |    3 +
 12 files changed, 1495 insertions(+), 10 deletions(-)

diff --git a/gnuradio-runtime/include/gnuradio/block_detail.h 
b/gnuradio-runtime/include/gnuradio/block_detail.h
index a71030b..8a9f4ab 100644
--- a/gnuradio-runtime/include/gnuradio/block_detail.h
+++ b/gnuradio-runtime/include/gnuradio/block_detail.h
@@ -241,6 +241,8 @@ namespace gr {
     tpb_detail d_tpb;  // used by thread-per-block scheduler
     int d_produce_or;
 
+    int consumed() const;
+
     // 
----------------------------------------------------------------------------
 
   private:
@@ -249,6 +251,7 @@ namespace gr {
     std::vector<buffer_reader_sptr> d_input;
     std::vector<buffer_sptr>        d_output;
     bool                            d_done;
+    int                             d_consumed;
 
     // Performance counters
     float d_ins_noutput_items;
diff --git a/gnuradio-runtime/lib/block_detail.cc 
b/gnuradio-runtime/lib/block_detail.cc
index 484d849..9e2e29f 100644
--- a/gnuradio-runtime/lib/block_detail.cc
+++ b/gnuradio-runtime/lib/block_detail.cc
@@ -110,14 +110,22 @@ namespace gr {
   void
   block_detail::consume(int which_input, int how_many_items)
   {
+    d_consumed = how_many_items;
     if(how_many_items > 0) {
       input(which_input)->update_read_pointer(how_many_items);
     }
   }
 
+  int
+  block_detail::consumed() const
+  {
+    return d_consumed;
+  }
+
   void
   block_detail::consume_each(int how_many_items)
   {
+    d_consumed = how_many_items;
     if(how_many_items > 0) {
       for(int i = 0; i < ninputs (); i++) {
         d_input[i]->update_read_pointer(how_many_items);
diff --git a/gnuradio-runtime/lib/block_executor.cc 
b/gnuradio-runtime/lib/block_executor.cc
index ef2e494..585e65f 100644
--- a/gnuradio-runtime/lib/block_executor.cc
+++ b/gnuradio-runtime/lib/block_executor.cc
@@ -464,16 +464,6 @@ namespace gr {
         m->set_is_unaligned(m->unaligned() != 0);
       }
 
-      // For some blocks that can change their produce/consume ratio
-      // (the relative_rate), we might want to automatically update
-      // based on the amount of items written/read.
-      // In the block constructor, use enable_update_rate(true).
-      if(m->update_rate()) {
-        rrate = ((double)(m->nitems_written(0)+n)) / 
((double)m->nitems_read(0));
-        if(rrate > 0)
-          m->set_relative_rate(rrate);
-      }
-
       // Now propagate the tags based on the new relative rate
       if(!propagate_tags(m->tag_propagation_policy(), d,
                          d_start_nitems_read, m->relative_rate(),
@@ -486,6 +476,17 @@ namespace gr {
       if(n != block::WORK_CALLED_PRODUCE)
         d->produce_each(n);     // advance write pointers
 
+      // For some blocks that can change their produce/consume ratio
+      // (the relative_rate), we might want to automatically update
+      // based on the amount of items written/read.
+      // In the block constructor, use enable_update_rate(true).
+      if(m->update_rate()) {
+        //rrate = ((double)(m->nitems_written(0))) / 
((double)m->nitems_read(0));
+        rrate = (double)n / (double)d->consumed();
+        if(rrate > 0)
+          m->set_relative_rate(rrate);
+      }
+
       if(d->d_produce_or > 0)   // block produced something
         return READY;
 
diff --git a/gr-blocks/examples/tags/test_tag_prop.grc 
b/gr-blocks/examples/tags/test_tag_prop.grc
new file mode 100644
index 0000000..e9e9d03
--- /dev/null
+++ b/gr-blocks/examples/tags/test_tag_prop.grc
@@ -0,0 +1,1145 @@
+<?xml version='1.0' encoding='utf-8'?>
+<?grc format='1' created='3.7.9'?>
+<flow_graph>
+  <timestamp>Wed Nov 18 11:09:33 2015</timestamp>
+  <block>
+    <key>options</key>
+    <param>
+      <key>author</key>
+      <value></value>
+    </param>
+    <param>
+      <key>window_size</key>
+      <value></value>
+    </param>
+    <param>
+      <key>category</key>
+      <value>Custom</value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>description</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(8, 11)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>generate_options</key>
+      <value>qt_gui</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>test_tag_prop</value>
+    </param>
+    <param>
+      <key>max_nouts</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>qt_qss_theme</key>
+      <value></value>
+    </param>
+    <param>
+      <key>realtime_scheduling</key>
+      <value></value>
+    </param>
+    <param>
+      <key>run_command</key>
+      <value>{python} -u {filename}</value>
+    </param>
+    <param>
+      <key>run_options</key>
+      <value>prompt</value>
+    </param>
+    <param>
+      <key>run</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>thread_safe_setters</key>
+      <value></value>
+    </param>
+    <param>
+      <key>title</key>
+      <value></value>
+    </param>
+  </block>
+  <block>
+    <key>variable</key>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(176, 11)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>samp_rate</value>
+    </param>
+    <param>
+      <key>value</key>
+      <value>8000</value>
+    </param>
+  </block>
+  <block>
+    <key>variable_tag_object</key>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(8, 275)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>tag0</value>
+    </param>
+    <param>
+      <key>key</key>
+      <value>pmt.intern("mark")</value>
+    </param>
+    <param>
+      <key>offset</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>src</key>
+      <value>pmt.intern("src")</value>
+    </param>
+    <param>
+      <key>value</key>
+      <value>pmt.PMT_T</value>
+    </param>
+  </block>
+  <block>
+    <key>blocks_test_tag_variable_rate_ff</key>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(400, 99)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>blocks_test_tag_variable_rate_ff_0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>once</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>step</key>
+      <value>0.001</value>
+    </param>
+  </block>
+  <block>
+    <key>blocks_throttle</key>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(232, 107)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>blocks_throttle_0</value>
+    </param>
+    <param>
+      <key>ignoretag</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>samples_per_second</key>
+      <value>samp_rate</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>float</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+  </block>
+  <block>
+    <key>blocks_vector_source_x</key>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(8, 91)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>blocks_vector_source_x_0_0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>float</value>
+    </param>
+    <param>
+      <key>repeat</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>tags</key>
+      <value>[tag0, ]</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>vector</key>
+      <value>scipy.arange(-1, 1, 0.01)</value>
+    </param>
+  </block>
+  <block>
+    <key>blocks_vector_source_x</key>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(8, 171)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>blocks_vector_source_x_0_0_0</value>
+    </param>
+    <param>
+      <key>maxoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>minoutbuf</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>float</value>
+    </param>
+    <param>
+      <key>repeat</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>tags</key>
+      <value>[tag0, ]</value>
+    </param>
+    <param>
+      <key>vlen</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>vector</key>
+      <value>scipy.arange(-1, 1, 0.1)</value>
+    </param>
+  </block>
+  <block>
+    <key>import</key>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(272, 11)</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>import_scipy</value>
+    </param>
+    <param>
+      <key>import</key>
+      <value>import scipy</value>
+    </param>
+  </block>
+  <block>
+    <key>qtgui_time_sink_x</key>
+    <param>
+      <key>autoscale</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>ctrlpanel</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>entags</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(632, 91)</value>
+    </param>
+    <param>
+      <key>gui_hint</key>
+      <value>0,0,1,1</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>grid</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>qtgui_time_sink_x_0</value>
+    </param>
+    <param>
+      <key>legend</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>alpha1</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color1</key>
+      <value>"blue"</value>
+    </param>
+    <param>
+      <key>label1</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker1</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>style1</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width1</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha10</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color10</key>
+      <value>"blue"</value>
+    </param>
+    <param>
+      <key>label10</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker10</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style10</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width10</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha2</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color2</key>
+      <value>"red"</value>
+    </param>
+    <param>
+      <key>label2</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker2</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style2</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width2</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha3</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color3</key>
+      <value>"green"</value>
+    </param>
+    <param>
+      <key>label3</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker3</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style3</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width3</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha4</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color4</key>
+      <value>"black"</value>
+    </param>
+    <param>
+      <key>label4</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker4</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style4</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width4</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha5</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color5</key>
+      <value>"cyan"</value>
+    </param>
+    <param>
+      <key>label5</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker5</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style5</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width5</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha6</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color6</key>
+      <value>"magenta"</value>
+    </param>
+    <param>
+      <key>label6</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker6</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style6</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width6</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha7</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color7</key>
+      <value>"yellow"</value>
+    </param>
+    <param>
+      <key>label7</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker7</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style7</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width7</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha8</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color8</key>
+      <value>"dark red"</value>
+    </param>
+    <param>
+      <key>label8</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker8</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style8</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width8</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha9</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color9</key>
+      <value>"dark green"</value>
+    </param>
+    <param>
+      <key>label9</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker9</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style9</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width9</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>name</key>
+      <value>""</value>
+    </param>
+    <param>
+      <key>nconnections</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>size</key>
+      <value>500</value>
+    </param>
+    <param>
+      <key>srate</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>tr_chan</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>tr_delay</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>tr_level</key>
+      <value>0.0</value>
+    </param>
+    <param>
+      <key>tr_mode</key>
+      <value>qtgui.TRIG_MODE_FREE</value>
+    </param>
+    <param>
+      <key>tr_slope</key>
+      <value>qtgui.TRIG_SLOPE_POS</value>
+    </param>
+    <param>
+      <key>tr_tag</key>
+      <value>""</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>float</value>
+    </param>
+    <param>
+      <key>update_time</key>
+      <value>0.10</value>
+    </param>
+    <param>
+      <key>ylabel</key>
+      <value>Amplitude</value>
+    </param>
+    <param>
+      <key>yunit</key>
+      <value>""</value>
+    </param>
+    <param>
+      <key>ymax</key>
+      <value>1.5</value>
+    </param>
+    <param>
+      <key>ymin</key>
+      <value>-1.5</value>
+    </param>
+  </block>
+  <block>
+    <key>qtgui_time_sink_x</key>
+    <param>
+      <key>autoscale</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>alias</key>
+      <value></value>
+    </param>
+    <param>
+      <key>comment</key>
+      <value></value>
+    </param>
+    <param>
+      <key>ctrlpanel</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>affinity</key>
+      <value></value>
+    </param>
+    <param>
+      <key>entags</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_enabled</key>
+      <value>True</value>
+    </param>
+    <param>
+      <key>_coordinate</key>
+      <value>(400, 179)</value>
+    </param>
+    <param>
+      <key>gui_hint</key>
+      <value>1,0,1,1</value>
+    </param>
+    <param>
+      <key>_rotation</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>grid</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>id</key>
+      <value>qtgui_time_sink_x_0_0</value>
+    </param>
+    <param>
+      <key>legend</key>
+      <value>False</value>
+    </param>
+    <param>
+      <key>alpha1</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color1</key>
+      <value>"blue"</value>
+    </param>
+    <param>
+      <key>label1</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker1</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>style1</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width1</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha10</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color10</key>
+      <value>"blue"</value>
+    </param>
+    <param>
+      <key>label10</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker10</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style10</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width10</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha2</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color2</key>
+      <value>"red"</value>
+    </param>
+    <param>
+      <key>label2</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker2</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style2</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width2</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha3</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color3</key>
+      <value>"green"</value>
+    </param>
+    <param>
+      <key>label3</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker3</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style3</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width3</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha4</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color4</key>
+      <value>"black"</value>
+    </param>
+    <param>
+      <key>label4</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker4</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style4</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width4</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha5</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color5</key>
+      <value>"cyan"</value>
+    </param>
+    <param>
+      <key>label5</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker5</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style5</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width5</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha6</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color6</key>
+      <value>"magenta"</value>
+    </param>
+    <param>
+      <key>label6</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker6</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style6</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width6</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha7</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color7</key>
+      <value>"yellow"</value>
+    </param>
+    <param>
+      <key>label7</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker7</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style7</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width7</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha8</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color8</key>
+      <value>"dark red"</value>
+    </param>
+    <param>
+      <key>label8</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker8</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style8</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width8</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>alpha9</key>
+      <value>1.0</value>
+    </param>
+    <param>
+      <key>color9</key>
+      <value>"dark green"</value>
+    </param>
+    <param>
+      <key>label9</key>
+      <value></value>
+    </param>
+    <param>
+      <key>marker9</key>
+      <value>-1</value>
+    </param>
+    <param>
+      <key>style9</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>width9</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>name</key>
+      <value>""</value>
+    </param>
+    <param>
+      <key>nconnections</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>size</key>
+      <value>500</value>
+    </param>
+    <param>
+      <key>srate</key>
+      <value>1</value>
+    </param>
+    <param>
+      <key>tr_chan</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>tr_delay</key>
+      <value>0</value>
+    </param>
+    <param>
+      <key>tr_level</key>
+      <value>0.0</value>
+    </param>
+    <param>
+      <key>tr_mode</key>
+      <value>qtgui.TRIG_MODE_FREE</value>
+    </param>
+    <param>
+      <key>tr_slope</key>
+      <value>qtgui.TRIG_SLOPE_POS</value>
+    </param>
+    <param>
+      <key>tr_tag</key>
+      <value>""</value>
+    </param>
+    <param>
+      <key>type</key>
+      <value>float</value>
+    </param>
+    <param>
+      <key>update_time</key>
+      <value>0.10</value>
+    </param>
+    <param>
+      <key>ylabel</key>
+      <value>Amplitude</value>
+    </param>
+    <param>
+      <key>yunit</key>
+      <value>""</value>
+    </param>
+    <param>
+      <key>ymax</key>
+      <value>1.5</value>
+    </param>
+    <param>
+      <key>ymin</key>
+      <value>-1.5</value>
+    </param>
+  </block>
+  <connection>
+    <source_block_id>blocks_test_tag_variable_rate_ff_0</source_block_id>
+    <sink_block_id>qtgui_time_sink_x_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>blocks_throttle_0</source_block_id>
+    <sink_block_id>blocks_test_tag_variable_rate_ff_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>blocks_throttle_0</source_block_id>
+    <sink_block_id>qtgui_time_sink_x_0_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>blocks_vector_source_x_0_0</source_block_id>
+    <sink_block_id>blocks_throttle_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+  <connection>
+    <source_block_id>blocks_vector_source_x_0_0_0</source_block_id>
+    <sink_block_id>blocks_throttle_0</sink_block_id>
+    <source_key>0</source_key>
+    <sink_key>0</sink_key>
+  </connection>
+</flow_graph>
diff --git a/gr-blocks/grc/blocks_block_tree.xml 
b/gr-blocks/grc/blocks_block_tree.xml
index a9441a9..4a60160 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -66,6 +66,7 @@
       <block>blocks_message_strobe</block>
       <block>blocks_message_strobe_random</block>
       <block>blocks_tags_strobe</block>
+      <block>blocks_test_tag_variable_rate_ff</block>
    </cat>
    <cat>
       <name>File Operators</name>
@@ -196,6 +197,7 @@
       <block>blocks_tagged_stream_mux</block>
       <block>blocks_tagged_stream_align</block>
       <block>blocks_stream_to_tagged_stream</block>
+      <block>blocks_test_tag_variable_rate_ff</block>
    </cat>
    <cat>
       <name>Type Converters</name>
diff --git a/gr-blocks/grc/blocks_test_tag_variable_rate_ff.xml 
b/gr-blocks/grc/blocks_test_tag_variable_rate_ff.xml
new file mode 100644
index 0000000..2a6c4b5
--- /dev/null
+++ b/gr-blocks/grc/blocks_test_tag_variable_rate_ff.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+## Test tag variable rate
+###################################################
+-->
+
+<block>
+  <name>Test Tag Variable Rate</name>
+  <key>blocks_test_tag_variable_rate_ff</key>
+  <import>from gnuradio import blocks</import>
+  <make>blocks.test_tag_variable_rate_ff($once, $step)</make>
+
+  <param>
+    <name>Update Once</name>
+    <key>once</key>
+    <value>False</value>
+    <type>enum</type>
+    <option>
+      <name>True</name>
+      <key>True</key>
+    </option>
+    <option>
+      <name>False</name>
+      <key>False</key>
+    </option>
+  </param>
+
+  <param>
+    <name>Update Step</name>
+    <key>step</key>
+    <value>0.001</value>
+    <type>float</type>
+  </param>
+
+  <sink>
+    <name>in</name>
+    <type>float</type>
+    <nports>1</nports>
+  </sink>
+
+  <source>
+    <name>out</name>
+    <type>float</type>
+    <nports>1</nports>
+  </source>
+</block>
diff --git a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt 
b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
index 77771b2..56f2c48 100644
--- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
+++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
@@ -173,6 +173,7 @@ install(FILES
     tagged_stream_multiply_length.h
     tagged_stream_to_pdu.h
     tags_strobe.h
+    test_tag_variable_rate_ff.h
     threshold_ff.h
     throttle.h
     transcendental.h
diff --git a/gr-blocks/include/gnuradio/blocks/test_tag_variable_rate_ff.h 
b/gr-blocks/include/gnuradio/blocks/test_tag_variable_rate_ff.h
new file mode 100644
index 0000000..7894ad5
--- /dev/null
+++ b/gr-blocks/include/gnuradio/blocks/test_tag_variable_rate_ff.h
@@ -0,0 +1,79 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_TEST_TAG_VARIABLE_RATE_FF_H
+#define INCLUDED_GR_TEST_TAG_VARIABLE_RATE_FF_H
+
+#include <gnuradio/blocks/api.h>
+#include <gnuradio/block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief Used for testing tag propagation.
+     * \ingroup measurement_tools_blk
+     * \ingroup stream_tag_tools_blk
+     * \ingroup debug_tools_blk
+     *
+     * This block resamples the stream by a factor that starts at 0.5
+     * but varies around by some random walk. The relative rate of the
+     * block is initialized to 0.5 and the random number generator is
+     * seeded based on the time. For each input, if the random number
+     * is >= 0.5, the relative rate is increased by \p update_step;
+     * otherwise, it is decreased by \p update_step.
+     *
+     * The rate of the change of the resampling factor is set by the
+     * flag \p update_once. If this is set to true, then the rate is
+     * only updated once per work function. If it is set to false
+     * (default), then the rate is changed with every input sample.
+     *
+     * The block's ctor sets the propagation policy to TPP_DONT to
+     * stop tags from automatically propagating. Instead, we handle
+     * the tag propagation ourselves from within the work
+     * function. Because the relative_rate changes so fast, the tag
+     * placement cannot be based on a single factor after the call to
+     * work and must be handled when the samples are and based on the
+     * current resampling rate.
+     */
+    class BLOCKS_API test_tag_variable_rate_ff : virtual public block
+    {
+    public:
+      // gr::blocks::test_tag_variable_rate_ff::sptr
+      typedef boost::shared_ptr<test_tag_variable_rate_ff> sptr;
+
+      /*!
+       * Build a test_tag_variable_rate_ff block.
+       *
+       * \param update_once Update the resampling rate once per call
+       *        to work (default=false).
+       * \param update_step How much to adjust the resampling rate by
+       *        when the update occurs (default=0.001).
+       */
+      static sptr make(bool update_once=false,
+                       double update_step=0.001);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_TEST_TAG_VARIABLE_RATE_FF_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 7c8ea14..ecac1b4 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -193,6 +193,7 @@ list(APPEND gr_blocks_sources
     tagged_stream_to_pdu_impl.cc
     tagged_stream_multiply_length_impl.cc
     tags_strobe_impl.cc
+    test_tag_variable_rate_ff_impl.cc
     threshold_ff_impl.cc
     throttle_impl.cc
     transcendental_impl.cc
diff --git a/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc 
b/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc
new file mode 100644
index 0000000..4927cc1
--- /dev/null
+++ b/gr-blocks/lib/test_tag_variable_rate_ff_impl.cc
@@ -0,0 +1,139 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "test_tag_variable_rate_ff_impl.h"
+#include <gnuradio/io_signature.h>
+#include <string.h>
+#include <iostream>
+#include <iomanip>
+#include <stdexcept>
+
+using namespace pmt;
+
+namespace gr {
+  namespace blocks {
+
+    test_tag_variable_rate_ff::sptr
+    test_tag_variable_rate_ff::make(bool update_once, double update_step)
+    {
+      return gnuradio::get_initial_sptr
+        (new test_tag_variable_rate_ff_impl(update_once, update_step));
+    }
+
+    test_tag_variable_rate_ff_impl::test_tag_variable_rate_ff_impl(bool 
update_once, double update_step)
+      : block("test_tag_variable_rate_ff",
+              io_signature::make(1, 1, sizeof(float)),
+              io_signature::make(1, 1, sizeof(float))),
+      d_update_once(update_once), d_update_step(update_step)
+    {
+      set_tag_propagation_policy(TPP_DONT);
+      set_relative_rate(0.5);
+      d_accum = 0;
+      d_rrate = 0.5;
+      d_old_in = 0;
+      d_new_in = 0;
+      d_last_out = 0;
+
+      srand48(time(NULL));
+    }
+
+    test_tag_variable_rate_ff_impl::~test_tag_variable_rate_ff_impl()
+    {
+    }
+
+    int
+    test_tag_variable_rate_ff_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];
+      float *out = (float*)output_items[0];
+
+      GR_LOG_DEBUG(d_logger, "\n");
+      GR_LOG_DEBUG(d_logger, boost::format("ninput_items:  %1%") % 
ninput_items[0]);
+      GR_LOG_DEBUG(d_logger, boost::format("noutput_items: %1%") % 
noutput_items);
+
+      if(d_update_once) {
+        if(drand48() > 0.5) {
+          d_rrate += d_update_step;
+        }
+        else {
+          d_rrate -= d_update_step;
+          if(d_rrate < d_update_step)
+            d_rrate = d_update_step;
+        }
+      }
+
+      std::vector<tag_t> tags;
+      std::vector<tag_t>::iterator itags;
+
+      int i = 0, j = 0;
+      while(i < ninput_items[0]) {
+
+        if(!d_update_once) {
+          if(drand48() > 0.5) {
+            d_rrate += d_update_step;
+          }
+          else {
+            d_rrate -= d_update_step;
+            if(d_rrate < d_update_step)
+              d_rrate = d_update_step;
+          }
+        }
+
+        d_accum += d_rrate;
+        if(d_accum >= 1.0) {
+          out[j] = in[i];
+
+          // Manage Tags
+          d_new_in = nitems_read(0) + i;
+          get_tags_in_range(tags, 0, d_old_in, d_new_in);
+          for(itags = tags.begin(); itags != tags.end(); itags++) {
+            tag_t new_tag = *itags;
+            new_tag.offset = d_last_out;
+            add_item_tag(0, new_tag);
+          }
+          d_old_in = d_new_in;
+          d_last_out = nitems_written(0) + j;
+
+          // Book keeping
+          j++;
+          d_accum -= 1.0;
+        }
+        i++;
+      }
+
+      GR_LOG_DEBUG(d_logger, boost::format("consuming: %1%") % i);
+      GR_LOG_DEBUG(d_logger, boost::format("producing: %1%") % j);
+      GR_LOG_DEBUG(d_logger, boost::format("block's rel rate:  %1%") % 
d_rrate);
+
+      consume_each(i);
+      return j;
+    }
+
+  } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/test_tag_variable_rate_ff_impl.h 
b/gr-blocks/lib/test_tag_variable_rate_ff_impl.h
new file mode 100644
index 0000000..0335ab6
--- /dev/null
+++ b/gr-blocks/lib/test_tag_variable_rate_ff_impl.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2015 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3, or (at your option)
+ * any later version.
+ *
+ * GNU Radio is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GNU Radio; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_GR_TEST_TAG_VARIABLE_RATE_FF_IMPL_H
+#define INCLUDED_GR_TEST_TAG_VARIABLE_RATE_FF_IMPL_H
+
+#include <gnuradio/blocks/test_tag_variable_rate_ff.h>
+
+namespace gr {
+  namespace blocks {
+
+    class test_tag_variable_rate_ff_impl : public test_tag_variable_rate_ff
+    {
+    protected:
+      bool d_update_once;
+      double d_update_step;
+      double d_accum;
+      double d_rrate;
+      uint64_t d_old_in, d_new_in, d_last_out;
+
+    public:
+      test_tag_variable_rate_ff_impl(bool update_once=false,
+                                     double update_step=0.001);
+      ~test_tag_variable_rate_ff_impl();
+
+      //void setup_rpc();
+
+      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 */
+} /* namespace gr */
+
+#endif /* INCLUDED_GR_TEST_TAG_VARIABLE_RATE_FF_IMPL_H */
diff --git a/gr-blocks/swig/blocks_swig5.i b/gr-blocks/swig/blocks_swig5.i
index b35492c..51601a8 100644
--- a/gr-blocks/swig/blocks_swig5.i
+++ b/gr-blocks/swig/blocks_swig5.i
@@ -56,6 +56,7 @@
 #include "gnuradio/blocks/tagged_stream_multiply_length.h"
 #include "gnuradio/blocks/tagged_stream_to_pdu.h"
 #include "gnuradio/blocks/tags_strobe.h"
+#include "gnuradio/blocks/test_tag_variable_rate_ff.h"
 #include "gnuradio/blocks/threshold_ff.h"
 #include "gnuradio/blocks/transcendental.h"
 #include "gnuradio/blocks/tuntap_pdu.h"
@@ -99,6 +100,7 @@
 %include "gnuradio/blocks/tagged_stream_multiply_length.h"
 %include "gnuradio/blocks/tagged_stream_to_pdu.h"
 %include "gnuradio/blocks/tags_strobe.h"
+%include "gnuradio/blocks/test_tag_variable_rate_ff.h"
 %include "gnuradio/blocks/threshold_ff.h"
 %include "gnuradio/blocks/transcendental.h"
 %include "gnuradio/blocks/tuntap_pdu.h"
@@ -141,6 +143,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, tagged_stream_mux);
 GR_SWIG_BLOCK_MAGIC2(blocks, tagged_stream_multiply_length);
 GR_SWIG_BLOCK_MAGIC2(blocks, tagged_stream_to_pdu);
 GR_SWIG_BLOCK_MAGIC2(blocks, tags_strobe);
+GR_SWIG_BLOCK_MAGIC2(blocks, test_tag_variable_rate_ff);
 GR_SWIG_BLOCK_MAGIC2(blocks, threshold_ff);
 GR_SWIG_BLOCK_MAGIC2(blocks, transcendental);
 GR_SWIG_BLOCK_MAGIC2(blocks, tuntap_pdu);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]