diff options
author | Johnathan Corgan | 2012-07-19 07:02:45 -0700 |
---|---|---|
committer | Johnathan Corgan | 2012-07-19 07:02:45 -0700 |
commit | 66f49de1986dd531bee011299d4b1f7c62872d39 (patch) | |
tree | bf4dbc1730beb129c250fbf7e938c379c16d958e | |
parent | bbd91d7a08bfc0c229267e5dc848d1f57d629373 (diff) | |
download | gnuradio-66f49de1986dd531bee011299d4b1f7c62872d39.tar.gz gnuradio-66f49de1986dd531bee011299d4b1f7c62872d39.tar.bz2 gnuradio-66f49de1986dd531bee011299d4b1f7c62872d39.zip |
blocks: added gr::blocks::repeat
-rw-r--r-- | gr-blocks/grc/blocks_block_tree.xml | 1 | ||||
-rw-r--r-- | gr-blocks/grc/blocks_repeat.xml | 64 | ||||
-rw-r--r-- | gr-blocks/include/blocks/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/include/blocks/repeat.h | 51 | ||||
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-blocks/lib/repeat_impl.cc | 69 | ||||
-rw-r--r-- | gr-blocks/lib/repeat_impl.h | 47 | ||||
-rwxr-xr-x | gr-blocks/python/qa_repeat.py | 49 | ||||
-rw-r--r-- | gr-blocks/swig/blocks_swig.i | 3 |
9 files changed, 286 insertions, 0 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index c2e45b9eb..557bf64db 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -77,5 +77,6 @@ <block>blocks_interleave.xml</block> <block>blocks_keep_m_in_n.xml</block> <block>blocks_keep_one_in_n.xml</block> + <block>blocks_repeat.xml</block> </cat> </cat> diff --git a/gr-blocks/grc/blocks_repeat.xml b/gr-blocks/grc/blocks_repeat.xml new file mode 100644 index 000000000..c6c17c990 --- /dev/null +++ b/gr-blocks/grc/blocks_repeat.xml @@ -0,0 +1,64 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Repeat +################################################### + --> +<block> + <name>Repeat</name> + <key>blocks_repeat</key> + <import>from gnuradio import blocks</import> + <make>blocks.repeat($type.size*$vlen, $interp)</make> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>size:gr.sizeof_gr_complex</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>size:gr.sizeof_int</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>size:gr.sizeof_short</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + </param> + <param> + <name>Interpolation</name> + <key>interp</key> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 0db0eebd2..8c14d5a49 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -117,6 +117,7 @@ install(FILES multiply_const_cc.h multiply_const_ff.h nlog10_ff.h + repeat.h short_to_char.h short_to_float.h uchar_to_float.h diff --git a/gr-blocks/include/blocks/repeat.h b/gr-blocks/include/blocks/repeat.h new file mode 100644 index 000000000..3f9f8e6fc --- /dev/null +++ b/gr-blocks/include/blocks/repeat.h @@ -0,0 +1,51 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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_BLOCKS_REPEAT_H +#define INCLUDED_BLOCKS_REPEAT_H + +#include <blocks/api.h> +#include <gr_sync_interpolator.h> + +namespace gr { + namespace blocks { + + /*! + * \brief repeat each input 'interp' times + * \ingroup slicedice_blk + * \param itemsize stream itemsize + * \param interp number of times to repeat + */ + class BLOCKS_API repeat : virtual public gr_sync_interpolator + { + public: + + // gr::blocks::repeat::sptr + typedef boost::shared_ptr<repeat> sptr; + + static sptr make(size_t itemsize, int repeat); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_REPEAT_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index e4aca48f0..9b0043d4b 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -154,6 +154,7 @@ list(APPEND gr_blocks_sources multiply_const_cc_impl.cc multiply_const_ff_impl.cc nlog10_ff_impl.cc + repeat_impl.cc short_to_char_impl.cc short_to_float_impl.cc uchar_array_to_float.cc diff --git a/gr-blocks/lib/repeat_impl.cc b/gr-blocks/lib/repeat_impl.cc new file mode 100644 index 000000000..939a33b87 --- /dev/null +++ b/gr-blocks/lib/repeat_impl.cc @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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 "repeat_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + repeat::sptr repeat::make(size_t itemsize, int interp) + { + return gnuradio::get_initial_sptr(new repeat_impl(itemsize, interp)); + } + + repeat_impl::repeat_impl(size_t itemsize, int interp) + : gr_sync_interpolator("repeat", + gr_make_io_signature (1, 1, itemsize), + gr_make_io_signature (1, 1, itemsize), + interp), + d_itemsize(itemsize), + d_interp(interp) + { + } + + int + repeat_impl::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; + } + + in += d_itemsize; + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/repeat_impl.h b/gr-blocks/lib/repeat_impl.h new file mode 100644 index 000000000..6451d0d98 --- /dev/null +++ b/gr-blocks/lib/repeat_impl.h @@ -0,0 +1,47 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 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_REPEAT_IMPL_H +#define INCLUDED_REPEAT_IMPL_H + +#include <blocks/repeat.h> + +namespace gr { + namespace blocks { + + class BLOCKS_API repeat_impl : public repeat + { + size_t d_itemsize; + int d_interp; + + public: + repeat_impl(size_t itemsize, int d_interp); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_REPEAT_IMPL_H */ diff --git a/gr-blocks/python/qa_repeat.py b/gr-blocks/python/qa_repeat.py new file mode 100755 index 000000000..69fb3ef72 --- /dev/null +++ b/gr-blocks/python/qa_repeat.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python +# +# Copyright 2008,2010,2012 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 blocks_swig +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 = [n*1.0 for n in range(100)]; + dst_data = [] + for n in range(100): + dst_data += [1.0*n, 1.0*n, 1.0*n] + + src = gr.vector_source_f(src_data) + rpt = blocks_swig.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.run(test_repeat, "test_repeat.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 41c5081bb..3161dd773 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -95,6 +95,7 @@ #include "blocks/or_bb.h" #include "blocks/or_ss.h" #include "blocks/or_ii.h" +#include "blocks/repeat.h" #include "blocks/short_to_char.h" #include "blocks/short_to_float.h" #include "blocks/sub_ff.h" @@ -174,6 +175,7 @@ %include "blocks/or_bb.h" %include "blocks/or_ss.h" %include "blocks/or_ii.h" +%include "blocks/repeat.h" %include "blocks/short_to_char.h" %include "blocks/short_to_float.h" %include "blocks/sub_ff.h" @@ -252,6 +254,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, not_ii); GR_SWIG_BLOCK_MAGIC2(blocks, or_bb); GR_SWIG_BLOCK_MAGIC2(blocks, or_ss); GR_SWIG_BLOCK_MAGIC2(blocks, or_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, repeat); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff); |