summaryrefslogtreecommitdiff
path: root/gnuradio-core
diff options
context:
space:
mode:
authorjcorgan2008-04-11 21:31:25 +0000
committerjcorgan2008-04-11 21:31:25 +0000
commitc989df7703fb0c2869dc1de7e18df311e2bf626a (patch)
tree2b4f504ae311ed1912ba7ce59af048767ecf8be0 /gnuradio-core
parenta761af14ad4a589637658f20ed3e58fcf7131bdd (diff)
downloadgnuradio-c989df7703fb0c2869dc1de7e18df311e2bf626a.tar.gz
gnuradio-c989df7703fb0c2869dc1de7e18df311e2bf626a.tar.bz2
gnuradio-c989df7703fb0c2869dc1de7e18df311e2bf626a.zip
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
Diffstat (limited to 'gnuradio-core')
-rw-r--r--gnuradio-core/src/lib/general/Makefile.am3
-rw-r--r--gnuradio-core/src/lib/general/general.i2
-rw-r--r--gnuradio-core/src/lib/general/gr_repeat.cc68
-rw-r--r--gnuradio-core/src/lib/general/gr_repeat.h56
-rw-r--r--gnuradio-core/src/lib/general/gr_repeat.i11
-rwxr-xr-xgnuradio-core/src/python/gnuradio/gr/qa_repeat.py45
6 files changed, 185 insertions, 0 deletions
diff --git a/gnuradio-core/src/lib/general/Makefile.am b/gnuradio-core/src/lib/general/Makefile.am
index 8a16692b0..ef5354cfe 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 0eab24f1a..64aa2d889 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 000000000..5d6f93b30
--- /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 000000000..62b397c54
--- /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 000000000..c657a4906
--- /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 000000000..88dbae06e
--- /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 ()