summaryrefslogtreecommitdiff
path: root/gr-blocks
diff options
context:
space:
mode:
Diffstat (limited to 'gr-blocks')
-rw-r--r--gr-blocks/grc/blocks_block_tree.xml1
-rw-r--r--gr-blocks/grc/blocks_short_to_char.xml28
-rw-r--r--gr-blocks/include/blocks/CMakeLists.txt3
-rw-r--r--gr-blocks/include/blocks/short_to_char.h51
-rw-r--r--gr-blocks/lib/CMakeLists.txt1
-rw-r--r--gr-blocks/lib/short_to_char_impl.cc69
-rw-r--r--gr-blocks/lib/short_to_char_impl.h47
-rwxr-xr-xgr-blocks/python/qa_type_conversions.py10
-rw-r--r--gr-blocks/swig/blocks_swig.i3
9 files changed, 212 insertions, 1 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 9a56d4c41..64af22cfd 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -55,5 +55,6 @@
<block>blocks_float_to_uchar</block>
<block>blocks_int_to_float</block>
<block>blocks_interleaved_short_to_complex</block>
+ <block>blocks_short_to_char</block>
</cat>
</cat>
diff --git a/gr-blocks/grc/blocks_short_to_char.xml b/gr-blocks/grc/blocks_short_to_char.xml
new file mode 100644
index 000000000..1951333d1
--- /dev/null
+++ b/gr-blocks/grc/blocks_short_to_char.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+<!--
+###################################################
+##Short to char:
+###################################################
+ -->
+<block>
+ <name>Short To Char</name>
+ <key>blocks_short_to_char</key>
+ <import>from gnuradio import blocks</import>
+ <make>blocks.short_to_char($vlen)</make>
+ <param>
+ <name>Vec Length</name>
+ <key>vlen</key>
+ <value>1</value>
+ <type>int</type>
+ </param>
+ <sink>
+ <name>in</name>
+ <type>short</type>
+ <vlen>$vlen</vlen>
+ </sink>
+ <source>
+ <name>out</name>
+ <type>byte</type>
+ <vlen>$vlen</vlen>
+ </source>
+</block>
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 9616db3a6..00df9511e 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -99,11 +99,12 @@ install(FILES
float_to_short.h
float_to_uchar.h
int_to_float.h
- interleaved_complex_to_short.h
+ interleaved_short_to_complex.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
multiply_const_ff.h
+ short_to_char.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/short_to_char.h b/gr-blocks/include/blocks/short_to_char.h
new file mode 100644
index 000000000..eeb053b0e
--- /dev/null
+++ b/gr-blocks/include/blocks/short_to_char.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_SHORT_TO_CHAR_H
+#define INCLUDED_BLOCKS_SHORT_TO_CHAR_H
+
+#include <blocks/api.h>
+#include <gr_sync_block.h>
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of shorts to a stream of chars
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ */
+ class BLOCKS_API short_to_char : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::short_to_char_ff::sptr
+ typedef boost::shared_ptr<short_to_char> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_SHORT_TO_CHAR_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 21b17d315..458a63221 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -141,6 +141,7 @@ list(APPEND gr_blocks_sources
multiply_ff_impl.cc
multiply_const_cc_impl.cc
multiply_const_ff_impl.cc
+ short_to_char_impl.cc
)
list(APPEND blocks_libs
diff --git a/gr-blocks/lib/short_to_char_impl.cc b/gr-blocks/lib/short_to_char_impl.cc
new file mode 100644
index 000000000..54875a2b3
--- /dev/null
+++ b/gr-blocks/lib/short_to_char_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 "short_to_char_impl.h"
+#include <gr_io_signature.h>
+#include <volk/volk.h>
+
+namespace gr {
+ namespace blocks {
+
+ short_to_char::sptr short_to_char::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new short_to_char_impl(vlen));
+ }
+
+ short_to_char_impl::short_to_char_impl(size_t vlen)
+ : gr_sync_block("short_to_char",
+ gr_make_io_signature (1, 1, sizeof(short)*vlen),
+ gr_make_io_signature (1, 1, sizeof(char)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(char);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ short_to_char_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const int16_t *in = (const int16_t *) input_items[0];
+ int8_t *out = (int8_t *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_16i_convert_8i_u(out, in, d_vlen*noutput_items);
+ }
+ else {
+ volk_16i_convert_8i_a(out, in, d_vlen*noutput_items);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/short_to_char_impl.h b/gr-blocks/lib/short_to_char_impl.h
new file mode 100644
index 000000000..37474094d
--- /dev/null
+++ b/gr-blocks/lib/short_to_char_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_SHORT_TO_CHAR_IMPL_H
+#define INCLUDED_SHORT_TO_CHAR_IMPL_H
+
+#include <blocks/short_to_char.h>
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API short_to_char_impl : public short_to_char
+ {
+ size_t d_vlen;
+
+ public:
+ short_to_char_impl(size_t vlen);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_SHORT_TO_CHAR_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 92e0a7ca4..ddb876b3d 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -271,6 +271,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_short_to_char(self):
+ src_data = (256, 512, 768, 1024, 1280)
+ expected_data = (1, 2, 3, 4, 5)
+ src = gr.vector_source_s(src_data)
+ op = blocks_swig.short_to_char()
+ dst = gr.vector_sink_b()
+ 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 0545a833c..6cb680314 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -72,6 +72,7 @@
#include "blocks/multiply_const_vii.h"
#include "blocks/multiply_const_vff.h"
#include "blocks/multiply_const_vcc.h"
+#include "blocks/short_to_char.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -122,6 +123,7 @@
%include "blocks/multiply_const_vii.h"
%include "blocks/multiply_const_vff.h"
%include "blocks/multiply_const_vcc.h"
+%include "blocks/short_to_char.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -171,6 +173,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vff);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_vcc);
+GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);