commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 27/28: basic: added dynamic delay block


From: git
Subject: [Commit-gnuradio] [gnuradio] 27/28: basic: added dynamic delay block
Date: Mon, 15 Aug 2016 00:47:08 +0000 (UTC)

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

nwest pushed a commit to annotated tag gr_basic_work
in repository gnuradio.

commit abcba722efcf3647952be9fe96f0b66477acb300
Author: Josh Blum <address@hidden>
Date:   Tue Nov 15 22:24:48 2011 -0800

    basic: added dynamic delay block
---
 gr-basic/grc/basic_block_tree.xml                  |  1 +
 gr-basic/grc/basic_delay.xml                       | 37 +++++++++
 gr-basic/include/CMakeLists.txt                    |  1 +
 .../basic_swig.i => include/gr_basic_delay.h}      | 30 ++++----
 gr-basic/lib/CMakeLists.txt                        |  1 +
 gr-basic/lib/gr_basic_delay.cc                     | 89 ++++++++++++++++++++++
 gr-basic/swig/CMakeLists.txt                       |  2 +
 gr-basic/swig/{basic_swig.i => basic_delay.i}      | 19 ++---
 gr-basic/swig/basic_swig.i                         |  2 +
 9 files changed, 158 insertions(+), 24 deletions(-)

diff --git a/gr-basic/grc/basic_block_tree.xml 
b/gr-basic/grc/basic_block_tree.xml
index 6833b7d..61d3e00 100644
--- a/gr-basic/grc/basic_block_tree.xml
+++ b/gr-basic/grc/basic_block_tree.xml
@@ -32,6 +32,7 @@
         <name>Basic</name>
         <block>basic_sig_source</block>
         <block>basic_stream_selector</block>
+        <block>basic_delay</block>
         <block>basic_add</block>
         <block>basic_add_const</block>
         <block>basic_subtract</block>
diff --git a/gr-basic/grc/basic_delay.xml b/gr-basic/grc/basic_delay.xml
new file mode 100644
index 0000000..084cb15
--- /dev/null
+++ b/gr-basic/grc/basic_delay.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+## Basic delay block
+###################################################
+ -->
+<block>
+    <name>Delay</name>
+    <key>basic_delay</key>
+    <import>from gnuradio import basic</import>
+    <make>basic.delay($item_size)
+self.$(id).set_delay($delay)
+</make>
+    <callback>self.$(id).set_delay($delay)</callback>
+    <param>
+        <name>Item Size</name>
+        <key>item_size</key>
+        <value>1</value>
+        <type>int</type>
+    </param>
+    <param>
+        <name>Delay</name>
+        <key>delay</key>
+        <value>0</value>
+        <type>int</type>
+    </param>
+    <sink>
+        <name>in</name>
+        <type>byte</type>
+        <vlen>$item_size</vlen>
+    </sink>
+    <source>
+        <name>out</name>
+        <type>byte</type>
+        <vlen>$item_size</vlen>
+    </source>
+</block>
diff --git a/gr-basic/include/CMakeLists.txt b/gr-basic/include/CMakeLists.txt
index 0a60365..dab70ba 100644
--- a/gr-basic/include/CMakeLists.txt
+++ b/gr-basic/include/CMakeLists.txt
@@ -24,6 +24,7 @@ install(FILES
     gr_basic_api.h
     gr_basic_add.h
     gr_basic_add_const.h
+    gr_basic_delay.h
     gr_basic_divide.h
     gr_basic_multiply.h
     gr_basic_multiply_const.h
diff --git a/gr-basic/swig/basic_swig.i b/gr-basic/include/gr_basic_delay.h
similarity index 60%
copy from gr-basic/swig/basic_swig.i
copy to gr-basic/include/gr_basic_delay.h
index ff71849..05b6958 100644
--- a/gr-basic/swig/basic_swig.i
+++ b/gr-basic/include/gr_basic_delay.h
@@ -18,20 +18,24 @@
  * the Free Software Foundation, Inc., 51 Franklin Street,
  * Boston, MA 02110-1301, USA.
  */
+#ifndef INCLUDED_GR_BASIC_DELAY_H
+#define INCLUDED_GR_BASIC_DELAY_H
 
-#define GR_BASIC_API
+#include <gr_basic_api.h>
+#include <gr_block.h>
 
-%ignore gr_sync_block;
-%ignore gr_hier_block2;
+/*!
+ * This block delays a stream by a selectable number of items.
+ */
+class GR_BASIC_API gr_basic_delay : virtual public gr_block{
+public:
+    typedef boost::shared_ptr<gr_basic_delay> sptr;
+
+    //! Make a new delay block
+    static sptr make(const size_t itemsize);
 
-////////////////////////////////////////////////////////////////////////
-// standard includes
-////////////////////////////////////////////////////////////////////////
-%include <gnuradio.i>
+    //! Change the number of items worth of delay
+    virtual void set_delay(const int nitems) = 0;
+};
 
-////////////////////////////////////////////////////////////////////////
-// block includes
-////////////////////////////////////////////////////////////////////////
-%include <basic_ops.i>
-%include <basic_sig_source.i>
-%include <basic_stream_selector.i>
+#endif /* INCLUDED_GR_BASIC_DELAY_H */
diff --git a/gr-basic/lib/CMakeLists.txt b/gr-basic/lib/CMakeLists.txt
index c46891a..0a73d39 100644
--- a/gr-basic/lib/CMakeLists.txt
+++ b/gr-basic/lib/CMakeLists.txt
@@ -35,6 +35,7 @@ link_directories(${Boost_LIBRARY_DIRS})
 list(APPEND gr_basic_sources
     gr_basic_add.cc
     gr_basic_add_const.cc
+    gr_basic_delay.cc
     gr_basic_divide.cc
     gr_basic_multiply.cc
     gr_basic_multiply_const.cc
diff --git a/gr-basic/lib/gr_basic_delay.cc b/gr-basic/lib/gr_basic_delay.cc
new file mode 100644
index 0000000..52c3576
--- /dev/null
+++ b/gr-basic/lib/gr_basic_delay.cc
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2011 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.
+ */
+
+#include <gr_basic_delay.h>
+#include <gr_io_signature.h>
+#include <cstring> //memcpy
+#include <gruel/thread.h>
+
+/***********************************************************************
+ * Generic delay implementation
+ **********************************************************************/
+class gr_basic_delay_impl : public gr_basic_delay{
+public:
+    gr_basic_delay_impl(const size_t itemsize):
+        gr_block(
+            "basic delay block",
+            gr_make_io_signature (1, 1, itemsize),
+            gr_make_io_signature (1, 1, itemsize)
+        ),
+        _itemsize(itemsize)
+    {
+        this->set_delay(0);
+    }
+
+    void set_delay(const int nitems){
+        gruel::scoped_lock l(_delay_mutex);
+        _delay_items = nitems;
+    }
+
+    int general_work(
+        int noutput_items,
+        gr_vector_int &ninput_items,
+        gr_vector_const_void_star &input_items,
+        gr_vector_void_star &output_items
+    ){
+        gruel::scoped_lock l(_delay_mutex);
+        const int delta = int64_t(nitems_read(0)) - int64_t(nitems_written(0)) 
- _delay_items;
+
+        //consume but not produce (drops samples)
+        if (delta < 0){
+            const int num_consume = std::min(ninput_items[0], -delta);
+            consume_each(num_consume);
+            return 0;
+        }
+
+        //produce but not consume (inserts zeros)
+        if (delta > 0){
+            noutput_items = std::min(noutput_items, delta);
+            std::memset(output_items[0], 0, noutput_items*_itemsize);
+            return noutput_items;
+        }
+
+        //otherwise just memcpy
+        noutput_items = std::min(noutput_items, ninput_items[0]);
+        std::memcpy(output_items[0], input_items[0], noutput_items*_itemsize);
+        consume_each(noutput_items);
+        return noutput_items;
+    }
+
+private:
+    int _delay_items;
+    const size_t _itemsize;
+    gruel::mutex _delay_mutex;
+};
+
+/***********************************************************************
+ * Delay factory function
+ **********************************************************************/
+gr_basic_delay::sptr gr_basic_delay::make(const size_t itemsize){
+    return sptr(new gr_basic_delay_impl(itemsize));
+}
diff --git a/gr-basic/swig/CMakeLists.txt b/gr-basic/swig/CMakeLists.txt
index c1ce280..022479e 100644
--- a/gr-basic/swig/CMakeLists.txt
+++ b/gr-basic/swig/CMakeLists.txt
@@ -41,7 +41,9 @@ GR_SWIG_INSTALL(
 install(
     FILES
     basic_swig.i
+    basic_delay.i
     basic_sig_source.i
+    basic_stream_selector.i
     basic_ops.i
     DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig
     COMPONENT "basic_swig"
diff --git a/gr-basic/swig/basic_swig.i b/gr-basic/swig/basic_delay.i
similarity index 83%
copy from gr-basic/swig/basic_swig.i
copy to gr-basic/swig/basic_delay.i
index ff71849..6284736 100644
--- a/gr-basic/swig/basic_swig.i
+++ b/gr-basic/swig/basic_delay.i
@@ -19,19 +19,16 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#define GR_BASIC_API
-
-%ignore gr_sync_block;
-%ignore gr_hier_block2;
-
 ////////////////////////////////////////////////////////////////////////
-// standard includes
+// block headers
 ////////////////////////////////////////////////////////////////////////
-%include <gnuradio.i>
+%{
+#include <gr_basic_delay.h>
+%}
+
+%include <gr_basic_delay.h>
 
 ////////////////////////////////////////////////////////////////////////
-// block includes
+// block magic
 ////////////////////////////////////////////////////////////////////////
-%include <basic_ops.i>
-%include <basic_sig_source.i>
-%include <basic_stream_selector.i>
+GR_SWIG_BLOCK_MAGIC2(gr_basic,delay)
diff --git a/gr-basic/swig/basic_swig.i b/gr-basic/swig/basic_swig.i
index ff71849..f417247 100644
--- a/gr-basic/swig/basic_swig.i
+++ b/gr-basic/swig/basic_swig.i
@@ -21,6 +21,7 @@
 
 #define GR_BASIC_API
 
+%ignore gr_block;
 %ignore gr_sync_block;
 %ignore gr_hier_block2;
 
@@ -33,5 +34,6 @@
 // block includes
 ////////////////////////////////////////////////////////////////////////
 %include <basic_ops.i>
+%include <basic_delay.i>
 %include <basic_sig_source.i>
 %include <basic_stream_selector.i>



reply via email to

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