]> git.gag.com Git - debian/gnuradio/commitdiff
Adds gr.repeat(), an interpolating block to repeat a sample N times on the output.
authorjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Apr 2008 21:31:25 +0000 (21:31 +0000)
committerjcorgan <jcorgan@221aa14e-8319-0410-a670-987f0aec2ac5>
Fri, 11 Apr 2008 21:31:25 +0000 (21:31 +0000)
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@8186 221aa14e-8319-0410-a670-987f0aec2ac5

gnuradio-core/src/lib/general/Makefile.am
gnuradio-core/src/lib/general/general.i
gnuradio-core/src/lib/general/gr_repeat.cc [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_repeat.h [new file with mode: 0644]
gnuradio-core/src/lib/general/gr_repeat.i [new file with mode: 0644]
gnuradio-core/src/python/gnuradio/gr/qa_repeat.py [new file with mode: 0755]

index 8a16692b0559149aefdcf2b8d6b4d0f6df668c33..ef5354cfe872fd68afad9e0f902b033e2fa4a220 100644 (file)
@@ -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              \
index 0eab24f1ad653bd0d62367713c70186657f71627..64aa2d889b8ef6831c27def699bc73c6dd195065 100644 (file)
 #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"
 %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 (file)
index 0000000..5d6f93b
--- /dev/null
@@ -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 (file)
index 0000000..62b397c
--- /dev/null
@@ -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 (file)
index 0000000..c657a49
--- /dev/null
@@ -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 (executable)
index 0000000..88dbae0
--- /dev/null
@@ -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 ()