From c989df7703fb0c2869dc1de7e18df311e2bf626a Mon Sep 17 00:00:00 2001
From: jcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Date: Fri, 11 Apr 2008 21:31:25 +0000
Subject: Adds gr.repeat(), an interpolating block to repeat a sample N times
 on the output.

git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8186 221aa14e-8319-0410-a670-987f0aec2ac5
---
 gnuradio-core/src/lib/general/Makefile.am         |  3 +
 gnuradio-core/src/lib/general/general.i           |  2 +
 gnuradio-core/src/lib/general/gr_repeat.cc        | 68 +++++++++++++++++++++++
 gnuradio-core/src/lib/general/gr_repeat.h         | 56 +++++++++++++++++++
 gnuradio-core/src/lib/general/gr_repeat.i         | 11 ++++
 gnuradio-core/src/python/gnuradio/gr/qa_repeat.py | 45 +++++++++++++++
 6 files changed, 185 insertions(+)
 create mode 100644 gnuradio-core/src/lib/general/gr_repeat.cc
 create mode 100644 gnuradio-core/src/lib/general/gr_repeat.h
 create mode 100644 gnuradio-core/src/lib/general/gr_repeat.i
 create mode 100755 gnuradio-core/src/python/gnuradio/gr/qa_repeat.py

(limited to 'gnuradio-core/src')

diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am
index 8a16692b05..ef5354cfe8 100644
--- a/gnuradio-core/src/lib/general/Makefile.am
+++ b/gnuradio-core/src/lib/general/Makefile.am
@@ -127,6 +127,7 @@ libgeneral_la_SOURCES = 		\
 	gr_random.cc			\
 	gr_regenerate_bb.cc		\
 	gr_remez.cc			\
+	gr_repeat.cc			\
 	gr_reverse.cc			\
 	gr_rms_cf.cc			\
 	gr_rms_ff.cc			\
@@ -272,6 +273,7 @@ grinclude_HEADERS = 			\
 	gr_random.h			\
 	gr_regenerate_bb.h		\
 	gr_remez.h			\
+	gr_repeat.h			\
 	gr_reverse.h			\
 	gr_rms_cf.h			\
 	gr_rms_ff.h			\
@@ -419,6 +421,7 @@ swiginclude_HEADERS =			\
 	gr_remez.i			\
 	gr_rms_cf.i			\
 	gr_rms_ff.i			\
+	gr_repeat.i			\
 	gr_short_to_float.i		\
 	gr_simple_correlator.i		\
 	gr_simple_framer.i		\
diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i
index 0eab24f1ad..64aa2d889b 100644
--- a/gnuradio-core/src/lib/general/general.i
+++ b/gnuradio-core/src/lib/general/general.i
@@ -129,6 +129,7 @@
 #include <gr_glfsr_source_b.h>
 #include <gr_glfsr_source_f.h>
 #include <gr_peak_detector2_fb.h>
+#include <gr_repeat.h>
 %}
 
 %include "gr_nop.i"
@@ -238,3 +239,4 @@
 %include "gr_glfsr_source_b.i"
 %include "gr_glfsr_source_f.i"
 %include "gr_peak_detector2_fb.i"
+%include "gr_repeat.i"
diff --git a/gnuradio-core/src/lib/general/gr_repeat.cc b/gnuradio-core/src/lib/general/gr_repeat.cc
new file mode 100644
index 0000000000..5d6f93b30e
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_repeat.cc
@@ -0,0 +1,68 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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 <gr_repeat.h>
+#include <gr_io_signature.h>
+
+gr_repeat_sptr 
+gr_make_repeat(size_t itemsize, int interp)
+{
+  return gr_repeat_sptr(new gr_repeat(itemsize, interp));
+}
+
+gr_repeat::gr_repeat(size_t itemsize, int interp)  
+  : gr_sync_interpolator("extend",
+			 gr_make_io_signature(1, 1, itemsize),
+			 gr_make_io_signature(1, 1, itemsize),
+			 interp),
+    d_interp(interp),
+    d_itemsize(itemsize)
+{
+}
+
+gr_repeat::~gr_repeat()
+{
+}
+
+int 
+gr_repeat::work(int noutput_items,
+		  gr_vector_const_void_star &input_items,
+		  gr_vector_void_star &output_items)
+{
+  const char *in = (const char *) input_items[0];
+  char *out = (char *)output_items[0];
+
+  for (int i = 0; i < noutput_items/d_interp; i++) {
+    for (int j = 0; j < d_interp; j++) {
+      memcpy(out, in, d_itemsize);
+      out += d_itemsize;
+    }
+
+    i += d_itemsize;
+  }
+
+  return noutput_items;
+}
diff --git a/gnuradio-core/src/lib/general/gr_repeat.h b/gnuradio-core/src/lib/general/gr_repeat.h
new file mode 100644
index 0000000000..62b397c54b
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_repeat.h
@@ -0,0 +1,56 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 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_REPEAT_H
+#define INCLUDED_GR_REPEAT_H
+
+#include <gr_sync_interpolator.h>
+
+class gr_repeat;
+
+typedef boost::shared_ptr<gr_repeat> gr_repeat_sptr;
+
+gr_repeat_sptr gr_make_repeat(size_t itemsize, int decim);
+
+/*!
+ * \brief Repeat a sample 'interp' times in output stream
+ * \ingroup converter
+ */
+
+class gr_repeat : public gr_sync_interpolator
+{
+private:
+  friend gr_repeat_sptr gr_make_repeat(size_t itemsize, int interp);
+						     
+  gr_repeat(size_t itemsize, int interp);
+
+  int d_interp;
+  int d_itemsize;
+
+ public:
+  ~gr_repeat();
+
+  int work(int noutput_items,
+	   gr_vector_const_void_star &input_items,
+	   gr_vector_void_star &output_items);
+};
+
+#endif /* INCLUDED_GR_REPEAT_H */
diff --git a/gnuradio-core/src/lib/general/gr_repeat.i b/gnuradio-core/src/lib/general/gr_repeat.i
new file mode 100644
index 0000000000..c657a4906f
--- /dev/null
+++ b/gnuradio-core/src/lib/general/gr_repeat.i
@@ -0,0 +1,11 @@
+/* -*- c++ -*- */
+
+GR_SWIG_BLOCK_MAGIC(gr,repeat);
+
+gr_repeat_sptr gr_make_repeat(size_t itemsize, int interp);
+
+class gr_repeat : public gr_sync_interpolator
+{
+private:
+  gr_repeat();
+};
diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_repeat.py b/gnuradio-core/src/python/gnuradio/gr/qa_repeat.py
new file mode 100755
index 0000000000..88dbae06e3
--- /dev/null
+++ b/gnuradio-core/src/python/gnuradio/gr/qa_repeat.py
@@ -0,0 +1,45 @@
+#!/usr/bin/env python
+#
+# Copyright 2008 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.
+# 
+
+from gnuradio import gr, gr_unittest
+import math
+
+class test_repeat (gr_unittest.TestCase):
+
+    def setUp (self):
+        self.tb = gr.top_block ()
+
+    def tearDown (self):
+        self.tb = None
+
+    def test_001_float(self):
+	src_data = [1.0, 2.0, 3.0]
+	dst_data = [1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0]
+	src = gr.vector_source_f(src_data)
+	rpt = gr.repeat(gr.sizeof_float, 3)
+	dst = gr.vector_sink_f()
+	self.tb.connect(src, rpt, dst)
+	self.tb.run()
+	self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6)	
+
+if __name__ == '__main__':
+    gr_unittest.main ()
-- 
cgit v1.2.3