commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 02/06: blocks: Add `multiply tag by value'


From: git
Subject: [Commit-gnuradio] [gnuradio] 02/06: blocks: Add `multiply tag by value' and `test tag variable rate' blocks
Date: Wed, 15 Jun 2016 04:11:15 +0000 (UTC)

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

jcorgan pushed a commit to branch packet3
in repository gnuradio.

commit e2004886d012076e3835b148462d1c52480a6e88
Author: Tom Rondeau <address@hidden>
Date:   Tue Jun 14 10:51:15 2016 -0700

    blocks: Add `multiply tag by value' and `test tag variable rate' blocks
---
 gr-blocks/grc/blocks_block_tree.xml                |   3 +
 gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml  |  32 +++++
 gr-blocks/grc/blocks_test_tag_variable_rate_ff.xml |  47 +++++++
 gr-blocks/include/gnuradio/blocks/CMakeLists.txt   |   2 +
 .../gnuradio/blocks/multiply_by_tag_value_cc.h     |  69 ++++++++++
 .../gnuradio/blocks/test_tag_variable_rate_ff.h    |  79 ++++++++++++
 gr-blocks/lib/CMakeLists.txt                       |   2 +
 gr-blocks/lib/multiply_by_tag_value_cc_impl.cc     | 128 +++++++++++++++++++
 gr-blocks/lib/multiply_by_tag_value_cc_impl.h      |  56 +++++++++
 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_swig3.i                      |   3 +
 gr-blocks/swig/blocks_swig5.i                      |   3 +
 13 files changed, 619 insertions(+)

diff --git a/gr-blocks/grc/blocks_block_tree.xml 
b/gr-blocks/grc/blocks_block_tree.xml
index a9441a9..c4857f3 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>
@@ -96,6 +97,7 @@
       <block>blocks_multiply_const_vxx</block>
       <block>blocks_multiply_conjugate_cc</block>
       <block>blocks_multiply_matrix_xx</block>
+      <block>blocks_multiply_by_tag_value_cc</block>
       <block>blocks_sub_xx</block>
       <block>blocks_conjugate_cc</block>
       <block>blocks_integrate_xx</block>
@@ -196,6 +198,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_multiply_by_tag_value_cc.xml 
b/gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml
new file mode 100644
index 0000000..cedca12
--- /dev/null
+++ b/gr-blocks/grc/blocks_multiply_by_tag_value_cc.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+
+<block>
+  <name>Multiply by Tag Value</name>
+  <key>blocks_multiply_by_tag_value_cc</key>
+  <import>from gnuradio import blocks</import>
+  <make>blocks.multiply_by_tag_value_cc($tagname, $vlen)</make>
+
+  <param>
+    <name>Tag Name</name>
+    <key>tagname</key>
+    <type>string</type>
+  </param>
+
+  <param>
+    <name>Vec Length</name>
+    <key>vlen</key>
+    <value>1</value>
+    <type>int</type>
+  </param>
+
+  <sink>
+    <name>in</name>
+    <type>complex</type>
+  </sink>
+
+  <source>
+    <name>out</name>
+    <type>complex</type>
+  </source>
+
+</block>
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..38c79d6 100644
--- a/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
+++ b/gr-blocks/include/gnuradio/blocks/CMakeLists.txt
@@ -132,6 +132,7 @@ install(FILES
     multiply_const_vcc.h
     multiply_const_ff.h
     multiply_const_vff.h
+    multiply_by_tag_value_cc.h
     nlog10_ff.h
     nop.h
     null_sink.h
@@ -173,6 +174,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/multiply_by_tag_value_cc.h 
b/gr-blocks/include/gnuradio/blocks/multiply_by_tag_value_cc.h
new file mode 100644
index 0000000..f4aba9d
--- /dev/null
+++ b/gr-blocks/include/gnuradio/blocks/multiply_by_tag_value_cc.h
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2016 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * This 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.
+ *
+ * This software 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 this software; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_H
+#define INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_H
+
+#include <gnuradio/blocks/api.h>
+#include <gnuradio/sync_block.h>
+
+namespace gr {
+  namespace blocks {
+
+    /*!
+     * \brief output = input * complex constant
+     * \ingroup math_operators_blk
+     *
+     * \details
+     * The complex constant used by this block is found from a tag
+     * with the name specified by \p tag_name. The tag must contain a
+     * float/double or complex PMT value that will be converted into a
+     * gr_complex value. All input data is multiplied by this
+     * value until a new tag with an update value is found. The block
+     * starts with a value of '1.0' for the multiplier constant.
+     */
+    class BLOCKS_API multiply_by_tag_value_cc : virtual public sync_block
+    {
+    public:
+      // gr::blocks::multiply_by_tag_value_cc::sptr
+      typedef boost::shared_ptr<multiply_by_tag_value_cc> sptr;
+
+      /*!
+       * \brief Create an instance of multiply_by_tag_value_cc
+       * \param tag_name Tag's key that it will use to get the
+       *                 multiplicative constant.
+       * \param vlen Vector length of incoming stream
+       */
+      static sptr make(const std::string& tag_name,
+                       size_t vlen=1);
+
+      /*!
+       * Get the current multiplicative constant.
+       * This block does not allow external setters.
+       */
+      virtual gr_complex k() const = 0;
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_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..643190c 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -154,6 +154,7 @@ list(APPEND gr_blocks_sources
     multiply_const_vff_impl.cc
     multiply_matrix_cc_impl.cc
     multiply_matrix_ff_impl.cc
+    multiply_by_tag_value_cc_impl.cc
     nlog10_ff_impl.cc
     nop_impl.cc
     null_sink_impl.cc
@@ -193,6 +194,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/multiply_by_tag_value_cc_impl.cc 
b/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc
new file mode 100644
index 0000000..456d57d
--- /dev/null
+++ b/gr-blocks/lib/multiply_by_tag_value_cc_impl.cc
@@ -0,0 +1,128 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2016 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 <multiply_by_tag_value_cc_impl.h>
+#include <gnuradio/io_signature.h>
+#include <volk/volk.h>
+
+namespace gr {
+  namespace blocks {
+
+    multiply_by_tag_value_cc::sptr
+    multiply_by_tag_value_cc::make(const std::string& tag_name,
+                                   size_t vlen)
+    {
+      return gnuradio::get_initial_sptr
+        (new multiply_by_tag_value_cc_impl(tag_name, vlen));
+    }
+
+    multiply_by_tag_value_cc_impl::multiply_by_tag_value_cc_impl(const 
std::string& tag_name,
+                                                                 size_t vlen)
+      : sync_block("multiply_by_tag_value_cc",
+                   io_signature::make (1, 1, sizeof (gr_complex)*vlen),
+                   io_signature::make (1, 1, sizeof (gr_complex)*vlen)),
+       d_vlen(vlen), d_k(gr_complex(1,0))
+    {
+      d_tag_key = pmt::intern(tag_name);
+
+      const int alignment_multiple =
+       volk_get_alignment() / sizeof(gr_complex);
+      set_alignment(std::max(1,alignment_multiple));
+    }
+
+    multiply_by_tag_value_cc_impl::~multiply_by_tag_value_cc_impl()
+    {
+    }
+
+    gr_complex
+    multiply_by_tag_value_cc_impl::k() const
+    {
+      return d_k;
+    }
+
+    int
+    multiply_by_tag_value_cc_impl::work(int noutput_items,
+                                        gr_vector_const_void_star &input_items,
+                                        gr_vector_void_star &output_items)
+    {
+      const gr_complex *in = (const gr_complex *) input_items[0];
+      gr_complex *out = (gr_complex *) output_items[0];
+
+      std::vector<tag_t> tags;
+      get_tags_in_window(tags, 0, 0, noutput_items, d_tag_key);
+
+      std::vector<tag_t>::iterator itag = tags.begin();
+
+      int start = 0, end;
+      while(itag != tags.end()) {
+        end = itag->offset - nitems_read(0);
+        end *= d_vlen;
+
+        // Multiply based on the current value of k from 'start' to 'end'
+        volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k, 
(end-start));
+        start = end;
+
+        // Extract new value of k
+        pmt::pmt_t k = itag->value;
+        if(pmt::is_complex(k)) {
+          d_k = pmt::to_complex(k);
+        }
+        else if(pmt::is_number(k)) {
+          d_k = gr_complex(pmt::to_double(k), 0);
+        }
+        else {
+          GR_LOG_WARN(d_logger,
+                      boost::format("Got key '%1%' with incompatible value of 
'%2%'") \
+                      % pmt::write_string(d_tag_key) % pmt::write_string(k));
+        }
+
+        itag++;
+      }
+
+      volk_32fc_s32fc_multiply_32fc(&out[start], &in[start], d_k,
+                                    (d_vlen*noutput_items-start));
+
+      return noutput_items;
+    }
+
+    void
+    multiply_by_tag_value_cc_impl::setup_rpc()
+    {
+#ifdef GR_CTRLPORT
+      add_rpc_variable(
+        rpcbasic_sptr(new rpcbasic_register_get<multiply_by_tag_value_cc, 
gr_complex>(
+         alias(), "Constant",
+         &multiply_by_tag_value_cc::k,
+         pmt::from_complex(-1024.0f, 0.0f),
+          pmt::from_complex(1024.0f, 0.0f),
+          pmt::from_complex(0.0f, 0.0f),
+         "", "Constant to multiply", RPC_PRIVLVL_MIN,
+          DISPTIME | DISPOPTCPLX | DISPOPTSTRIP)));
+#endif /* GR_CTRLPORT */
+    }
+
+  } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_by_tag_value_cc_impl.h 
b/gr-blocks/lib/multiply_by_tag_value_cc_impl.h
new file mode 100644
index 0000000..23adcc9
--- /dev/null
+++ b/gr-blocks/lib/multiply_by_tag_value_cc_impl.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2016 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_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H
+#define INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H
+
+#include <gnuradio/blocks/multiply_by_tag_value_cc.h>
+
+namespace gr {
+  namespace blocks {
+
+    class BLOCKS_API multiply_by_tag_value_cc_impl
+      : public multiply_by_tag_value_cc
+    {
+    private:
+      size_t d_vlen;
+      pmt::pmt_t d_tag_key;
+      gr_complex d_k;
+
+    public:
+      multiply_by_tag_value_cc_impl(const std::string& tag_name,
+                                    size_t vlen);
+      ~multiply_by_tag_value_cc_impl();
+
+      gr_complex k() const;
+
+      void setup_rpc();
+
+      int work(int noutput_items,
+              gr_vector_const_void_star &input_items,
+              gr_vector_void_star &output_items);
+    };
+
+  } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_BY_TAG_VALUE_CC_IMPL_H */
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_swig3.i b/gr-blocks/swig/blocks_swig3.i
index 61a959b..629ada5 100644
--- a/gr-blocks/swig/blocks_swig3.i
+++ b/gr-blocks/swig/blocks_swig3.i
@@ -70,6 +70,7 @@
 #include "gnuradio/blocks/multiply_const_vcc.h"
 #include "gnuradio/blocks/multiply_matrix_cc.h"
 #include "gnuradio/blocks/multiply_matrix_ff.h"
+#include "gnuradio/blocks/multiply_by_tag_value_cc.h"
 #include "gnuradio/blocks/mute_ss.h"
 #include "gnuradio/blocks/mute_ii.h"
 #include "gnuradio/blocks/mute_ff.h"
@@ -118,6 +119,7 @@
 %include "gnuradio/blocks/multiply_const_vcc.h"
 %include "gnuradio/blocks/multiply_matrix_cc.h"
 %include "gnuradio/blocks/multiply_matrix_ff.h"
+%include "gnuradio/blocks/multiply_by_tag_value_cc.h"
 %include "gnuradio/blocks/mute_ss.h"
 %include "gnuradio/blocks/mute_ii.h"
 %include "gnuradio/blocks/mute_ff.h"
@@ -165,6 +167,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vff);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vcc);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_matrix_cc);
 GR_SWIG_BLOCK_MAGIC2(blocks, multiply_matrix_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_by_tag_value_cc);
 GR_SWIG_BLOCK_MAGIC2(blocks, mute_ss);
 GR_SWIG_BLOCK_MAGIC2(blocks, mute_ii);
 GR_SWIG_BLOCK_MAGIC2(blocks, mute_ff);
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]