From c16e6eba638ebe3bdf5ee4770ce409481c8e1c7a Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Sat, 23 Jun 2012 07:46:42 -0700 Subject: blocks: added gr::blocks::complex_to_interleaved_short --- gr-blocks/grc/blocks_block_tree.xml | 2 +- .../grc/blocks_complex_to_interleaved_short.xml | 20 +++++++ gr-blocks/include/blocks/CMakeLists.txt | 1 + .../include/blocks/complex_to_interleaved_short.h | 49 +++++++++++++++++ gr-blocks/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_interleaved_short_impl.cc | 63 ++++++++++++++++++++++ gr-blocks/lib/complex_to_interleaved_short_impl.h | 45 ++++++++++++++++ gr-blocks/python/qa_type_conversions.py | 9 ++++ gr-blocks/swig/blocks_swig.i | 3 ++ 9 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 gr-blocks/grc/blocks_complex_to_interleaved_short.xml create mode 100644 gr-blocks/include/blocks/complex_to_interleaved_short.h create mode 100644 gr-blocks/lib/complex_to_interleaved_short_impl.cc create mode 100644 gr-blocks/lib/complex_to_interleaved_short_impl.h diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 6fe209db9..523ee1b7c 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -41,6 +41,6 @@ Type Conversions blocks_char_to_float blocks_char_to_short + blocks_complex_to_interleaved_short - diff --git a/gr-blocks/grc/blocks_complex_to_interleaved_short.xml b/gr-blocks/grc/blocks_complex_to_interleaved_short.xml new file mode 100644 index 000000000..43b55f32a --- /dev/null +++ b/gr-blocks/grc/blocks_complex_to_interleaved_short.xml @@ -0,0 +1,20 @@ + + + + Complex To IShort + blocks_complex_to_interleaved_short + from gnuradio import blocks + blocks.complex_to_interleaved_short() + + in + complex + + + out + short + + diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 7f29e5a7b..783680253 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -86,6 +86,7 @@ install(FILES add_ff.h char_to_float.h char_to_short.h + complex_to_interleaved_short.h multiply_cc.h multiply_ff.h multiply_const_cc.h diff --git a/gr-blocks/include/blocks/complex_to_interleaved_short.h b/gr-blocks/include/blocks/complex_to_interleaved_short.h new file mode 100644 index 000000000..33cbddf6b --- /dev/null +++ b/gr-blocks/include/blocks/complex_to_interleaved_short.h @@ -0,0 +1,49 @@ +/* -*- 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_COMPLEX_TO_INTERLEAVED_SHORT_H +#define INCLUDED_BLOCKS_COMPLEX_TO_INTERLEAVED_SHORT_H + +#include +#include + +namespace gr { + namespace blocks { + + /*! + * \brief Convert stream of complex to a stream of interleaved shorts + * \ingroup converter_blk + */ + class BLOCKS_API complex_to_interleaved_short : virtual public gr_sync_interpolator + { + public: + + // gr::blocks::complex_to_interleaved_short_ff::sptr + typedef boost::shared_ptr sptr; + + static sptr make(); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_COMPLEX_TO_INTERLEAVED_SHORT_H */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 501529dd9..907ad672e 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -120,6 +120,7 @@ list(APPEND gr_blocks_sources add_ff_impl.cc char_to_float_impl.cc char_to_short_impl.cc + complex_to_interleaved_short_impl.cc multiply_cc_impl.cc multiply_ff_impl.cc multiply_const_cc_impl.cc diff --git a/gr-blocks/lib/complex_to_interleaved_short_impl.cc b/gr-blocks/lib/complex_to_interleaved_short_impl.cc new file mode 100644 index 000000000..2f2ea6e00 --- /dev/null +++ b/gr-blocks/lib/complex_to_interleaved_short_impl.cc @@ -0,0 +1,63 @@ +/* -*- 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 "complex_to_interleaved_short_impl.h" +#include + +namespace gr { + namespace blocks { + + complex_to_interleaved_short::sptr complex_to_interleaved_short::make() + { + return gnuradio::get_initial_sptr(new complex_to_interleaved_short_impl()); + } + + complex_to_interleaved_short_impl::complex_to_interleaved_short_impl() + : gr_sync_interpolator("complex_to_interleaved_short", + gr_make_io_signature (1, 1, sizeof(gr_complex)), + gr_make_io_signature (1, 1, sizeof(short)), + 2) + { + } + + int + complex_to_interleaved_short_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const gr_complex *in = (const gr_complex *) input_items[0]; + short *out = (short *) output_items[0]; + + for (int i = 0; i < noutput_items/2; i++){ + *out++ = (short) lrintf(in[i].real()); // FIXME saturate? + *out++ = (short) lrintf(in[i].imag()); + } + + return noutput_items; + } + + } /* namespace blocks */ +}/* namespace gr */ diff --git a/gr-blocks/lib/complex_to_interleaved_short_impl.h b/gr-blocks/lib/complex_to_interleaved_short_impl.h new file mode 100644 index 000000000..9a09d1ff9 --- /dev/null +++ b/gr-blocks/lib/complex_to_interleaved_short_impl.h @@ -0,0 +1,45 @@ +/* -*- 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_COMPLEX_TO_INTERLEAVED_SHORT_IMPL_H +#define INCLUDED_COMPLEX_TO_INTERLEAVED_SHORT_IMPL_H + +#include + +namespace gr { + namespace blocks { + + class BLOCKS_API complex_to_interleaved_short_impl : public complex_to_interleaved_short + { + public: + complex_to_interleaved_short_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + + +#endif /* INCLUDED_COMPLEX_TO_INTERLEAVED_SHORT_IMPL_H */ diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py index ff2e5c609..b03103bfe 100755 --- a/gr-blocks/python/qa_type_conversions.py +++ b/gr-blocks/python/qa_type_conversions.py @@ -61,6 +61,15 @@ class test_type_conversions(gr_unittest.TestCase): self.tb.run() self.assertEqual(expected_data, dst.data()) + def test_complex_to_interleaved_short(self): + src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j) + expected_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + src = gr.vector_source_c(src_data) + op = blocks_swig.complex_to_interleaved_short() + dst = gr.vector_sink_s() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_data, dst.data()) if __name__ == '__main__': gr_unittest.run(test_type_conversions, "test_type_conversions.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 579917014..16572633f 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -42,6 +42,7 @@ #include "blocks/add_const_vcc.h" #include "blocks/char_to_float.h" #include "blocks/char_to_short.h" +#include "blocks/complex_to_interleaved_short.h" #include "blocks/divide_ff.h" #include "blocks/divide_ss.h" #include "blocks/divide_ii.h" @@ -78,6 +79,7 @@ %include "blocks/add_const_vcc.h" %include "blocks/char_to_float.h" %include "blocks/char_to_short.h" +%include "blocks/complex_to_interleaved_short.h" %include "blocks/divide_ff.h" %include "blocks/divide_ss.h" %include "blocks/divide_ii.h" @@ -113,6 +115,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vii); GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, char_to_short); +GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_interleaved_short); GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff); GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss); GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii); -- cgit