From 630cd06cb33d628fa6426866f006580aad30f84b Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 5 May 2012 13:21:38 -0700
Subject: blocks: adds new top-level component gr-blocks with first block
gr::blocks::add_XX
---
CMakeLists.txt | 1 +
gnuradio-core/src/python/build_utils.py | 6 +-
gr-blocks/CMakeLists.txt | 104 +++++++++++++++++
gr-blocks/doc/CMakeLists.txt | 23 ++++
gr-blocks/doc/README.blocks | 12 ++
gr-blocks/doc/blocks.dox | 23 ++++
gr-blocks/gnuradio-blocks.pc.in | 11 ++
gr-blocks/grc/CMakeLists.txt | 22 ++++
gr-blocks/grc/blocks_add_xx.xml | 63 +++++++++++
gr-blocks/grc/blocks_block_tree.xml | 35 ++++++
gr-blocks/include/blocks/CMakeLists.txt | 82 ++++++++++++++
gr-blocks/include/blocks/add_XX.h.t | 53 +++++++++
gr-blocks/include/blocks/add_ff.h | 49 ++++++++
gr-blocks/include/blocks/api.h | 33 ++++++
gr-blocks/lib/CMakeLists.txt | 126 +++++++++++++++++++++
gr-blocks/lib/add_XX_impl.cc.t | 69 +++++++++++
gr-blocks/lib/add_XX_impl.h.t | 47 ++++++++
gr-blocks/lib/add_ff_impl.cc | 71 ++++++++++++
gr-blocks/lib/add_ff_impl.h | 46 ++++++++
gr-blocks/python/CMakeLists.txt | 47 ++++++++
gr-blocks/python/__init__.py | 28 +++++
gr-blocks/python/qa_add_and_friends.py | 195 ++++++++++++++++++++++++++++++++
gr-blocks/swig/CMakeLists.txt | 51 +++++++++
gr-blocks/swig/blocks_swig.i | 45 ++++++++
24 files changed, 1240 insertions(+), 2 deletions(-)
create mode 100644 gr-blocks/CMakeLists.txt
create mode 100644 gr-blocks/doc/CMakeLists.txt
create mode 100644 gr-blocks/doc/README.blocks
create mode 100644 gr-blocks/doc/blocks.dox
create mode 100644 gr-blocks/gnuradio-blocks.pc.in
create mode 100644 gr-blocks/grc/CMakeLists.txt
create mode 100644 gr-blocks/grc/blocks_add_xx.xml
create mode 100644 gr-blocks/grc/blocks_block_tree.xml
create mode 100644 gr-blocks/include/blocks/CMakeLists.txt
create mode 100644 gr-blocks/include/blocks/add_XX.h.t
create mode 100644 gr-blocks/include/blocks/add_ff.h
create mode 100644 gr-blocks/include/blocks/api.h
create mode 100644 gr-blocks/lib/CMakeLists.txt
create mode 100644 gr-blocks/lib/add_XX_impl.cc.t
create mode 100644 gr-blocks/lib/add_XX_impl.h.t
create mode 100644 gr-blocks/lib/add_ff_impl.cc
create mode 100644 gr-blocks/lib/add_ff_impl.h
create mode 100644 gr-blocks/python/CMakeLists.txt
create mode 100644 gr-blocks/python/__init__.py
create mode 100755 gr-blocks/python/qa_add_and_friends.py
create mode 100644 gr-blocks/swig/CMakeLists.txt
create mode 100644 gr-blocks/swig/blocks_swig.i
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dad398e8c..26d7cb009 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -245,6 +245,7 @@ add_subdirectory(gr-vocoder)
add_subdirectory(gr-fcd)
add_subdirectory(gr-wavelet)
add_subdirectory(gr-wxgui)
+add_subdirectory(gr-blocks)
#finalize cpack after subdirs processed
include(GrPackage)
diff --git a/gnuradio-core/src/python/build_utils.py b/gnuradio-core/src/python/build_utils.py
index ce0757912..5b73cfb5c 100644
--- a/gnuradio-core/src/python/build_utils.py
+++ b/gnuradio-core/src/python/build_utils.py
@@ -1,5 +1,5 @@
#
-# Copyright 2004,2009 Free Software Foundation, Inc.
+# Copyright 2004,2009,2012 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -179,7 +179,9 @@ def is_complex (code3):
def standard_dict (name, code3, package='gr'):
d = {}
d['NAME'] = name
- d['GUARD_NAME'] = 'INCLUDED_%s_H' % name.upper ()
+ d['NAME_IMPL'] = name+'_impl'
+ d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper())
+ d['GUARD_NAME_IMPL'] = 'INCLUDED_%s_%s_IMPL_H' % (package.upper(), name.upper())
d['BASE_NAME'] = re.sub ('^' + package + '_', '', name)
d['SPTR_NAME'] = '%s_sptr' % name
d['WARNING'] = 'WARNING: this file is machine generated. Edits will be over written'
diff --git a/gr-blocks/CMakeLists.txt b/gr-blocks/CMakeLists.txt
new file mode 100644
index 000000000..9c81ba6bf
--- /dev/null
+++ b/gr-blocks/CMakeLists.txt
@@ -0,0 +1,104 @@
+# 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.
+
+########################################################################
+# Setup dependencies
+########################################################################
+include(GrBoost)
+
+########################################################################
+# Register component
+########################################################################
+include(GrComponent)
+GR_REGISTER_COMPONENT("gr-blocks" ENABLE_GR_BLOCKS
+ Boost_FOUND
+ ENABLE_GR_CORE
+)
+
+GR_SET_GLOBAL(GR_BLOCKS_INCLUDE_DIRS
+ ${CMAKE_CURRENT_SOURCE_DIR}/lib
+ ${CMAKE_CURRENT_SOURCE_DIR}/include
+)
+
+########################################################################
+# Begin conditional configuration
+########################################################################
+if(ENABLE_GR_BLOCKS)
+
+########################################################################
+# Setup CPack components
+########################################################################
+include(GrPackage)
+CPACK_SET(CPACK_COMPONENT_GROUP_BLOCKS_DESCRIPTION "GNU Radio Basic Blocks")
+
+CPACK_COMPONENT("blocks_runtime"
+ GROUP "Blocks"
+ DISPLAY_NAME "Runtime"
+ DESCRIPTION "Runtime"
+ DEPENDS "core_runtime"
+)
+
+CPACK_COMPONENT("blocks_devel"
+ GROUP "Blocks"
+ DISPLAY_NAME "Development"
+ DESCRIPTION "C++ headers, package config, import libraries"
+ DEPENDS "core_devel"
+)
+
+CPACK_COMPONENT("blocks_python"
+ GROUP "Blocks"
+ DISPLAY_NAME "Python"
+ DESCRIPTION "Python modules for runtime; GRC xml files"
+ DEPENDS "core_python;blocks_runtime"
+)
+
+CPACK_COMPONENT("blocks_swig"
+ GROUP "Blocks"
+ DISPLAY_NAME "SWIG"
+ DESCRIPTION "SWIG development .i files"
+ DEPENDS "core_swig;blocks_python;blocks_devel"
+)
+
+########################################################################
+# Add subdirectories
+########################################################################
+add_subdirectory(include/blocks)
+add_subdirectory(lib)
+if(ENABLE_PYTHON)
+ add_subdirectory(python)
+ add_subdirectory(swig)
+ add_subdirectory(grc)
+ add_subdirectory(doc)
+endif(ENABLE_PYTHON)
+
+########################################################################
+# Create Pkg Config File
+########################################################################
+configure_file(
+ ${CMAKE_CURRENT_SOURCE_DIR}/gnuradio-blocks.pc.in
+ ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-blocks.pc
+@ONLY)
+
+install(
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/gnuradio-blocks.pc
+ DESTINATION ${GR_LIBRARY_DIR}/pkgconfig
+ COMPONENT "blocks_devel"
+)
+
+endif(ENABLE_GR_BLOCKS)
diff --git a/gr-blocks/doc/CMakeLists.txt b/gr-blocks/doc/CMakeLists.txt
new file mode 100644
index 000000000..c1397804b
--- /dev/null
+++ b/gr-blocks/doc/CMakeLists.txt
@@ -0,0 +1,23 @@
+# 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.
+
+install(
+ FILES README.blocks
+ DESTINATION ${GR_PKG_DOC_DIR}
+)
diff --git a/gr-blocks/doc/README.blocks b/gr-blocks/doc/README.blocks
new file mode 100644
index 000000000..418a06825
--- /dev/null
+++ b/gr-blocks/doc/README.blocks
@@ -0,0 +1,12 @@
+This is the gr-blocks package. It contains the basic blocks that are
+widely used in many different types of flowgraphs. To use these blocks,
+the Python namespace is in gnuradio.blocks, which would be normally
+imported as:
+
+ from gnuradio import blocks
+
+See the Doxygen documentation for details about the blocks available
+in this package. A quick listing of the details can be found in Python
+after importing by using:
+
+ help(blocks)
diff --git a/gr-blocks/doc/blocks.dox b/gr-blocks/doc/blocks.dox
new file mode 100644
index 000000000..110dcb677
--- /dev/null
+++ b/gr-blocks/doc/blocks.dox
@@ -0,0 +1,23 @@
+/*! \page page_digital Digital Modulation
+
+\section Introduction
+This is the gr-digital package. It contains all of the digital
+modulation blocks, utilities, and examples. To use the digital blocks,
+the Python namespaces is in gnuradio.digital, which would be normally
+imported as:
+
+\code
+ from gnuradio import digital
+\endcode
+
+See the Doxygen documentation for details about the blocks available
+in this package. The relevant blocks are listed in the \ref digital group.
+
+A quick listing of the details can be found in Python after importing
+by using:
+
+\code
+ help(digital)
+\endcode
+
+*/
diff --git a/gr-blocks/gnuradio-blocks.pc.in b/gr-blocks/gnuradio-blocks.pc.in
new file mode 100644
index 000000000..abcfe017b
--- /dev/null
+++ b/gr-blocks/gnuradio-blocks.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: gnuradio-blocks
+Description: GNU Radio basic block library
+Requires: gnuradio-core gnuradio-audio
+Version: @LIBVER@
+Libs: -L${libdir} -lgnuradio-blocks
+Cflags: -I${includedir}
diff --git a/gr-blocks/grc/CMakeLists.txt b/gr-blocks/grc/CMakeLists.txt
new file mode 100644
index 000000000..ed66d9e3b
--- /dev/null
+++ b/gr-blocks/grc/CMakeLists.txt
@@ -0,0 +1,22 @@
+# 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.
+
+########################################################################
+file(GLOB xml_files "*.xml")
+install(FILES ${xml_files} DESTINATION ${GRC_BLOCKS_DIR} COMPONENT "blocks_python")
diff --git a/gr-blocks/grc/blocks_add_xx.xml b/gr-blocks/grc/blocks_add_xx.xml
new file mode 100644
index 000000000..951dff5e5
--- /dev/null
+++ b/gr-blocks/grc/blocks_add_xx.xml
@@ -0,0 +1,63 @@
+
+
+
+ Add
+ blocks_add_xx
+ from gnuradio import blocks
+ blocks.add_v$(type.fcn)($vlen)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_inputs > 1
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+ $num_inputs
+
+
+
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
new file mode 100644
index 000000000..37ed367c6
--- /dev/null
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -0,0 +1,35 @@
+
+
+
+
+
+
+
+
+ Math Operations
+ blocks_add_xx
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
new file mode 100644
index 000000000..f11db5fc0
--- /dev/null
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -0,0 +1,82 @@
+# 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.
+
+########################################################################
+# generate helper scripts to expand templated files
+########################################################################
+include(GrPython)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py "
+#!${PYTHON_EXECUTABLE}
+
+import sys, os, re
+sys.path.append('${GR_CORE_PYTHONPATH}')
+os.environ['srcdir'] = '${CMAKE_CURRENT_SOURCE_DIR}'
+os.chdir('${CMAKE_CURRENT_BINARY_DIR}')
+
+if __name__ == '__main__':
+ import build_utils
+ root, inp = sys.argv[1:3]
+ for sig in sys.argv[3:]:
+ name = re.sub ('X+', sig, root)
+ d = build_utils.standard_dict(name, sig, 'blocks')
+ build_utils.expand_template(d, inp)
+
+")
+
+macro(expand_h root)
+ #make a list of all the generated files
+ unset(expanded_files_h)
+ foreach(sig ${ARGN})
+ string(REGEX REPLACE "X+" ${sig} name ${root})
+ list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/${name}.h)
+ endforeach(sig)
+
+ #create a command to generate the files
+ add_custom_command(
+ OUTPUT ${expanded_files_h}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}.h.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}.h.t ${ARGN}
+ )
+
+ #install rules for the generated h files
+ list(APPEND generated_includes ${expanded_files_h})
+endmacro(expand_h)
+
+########################################################################
+# Invoke macro to generate various sources
+########################################################################
+expand_h(add_XX ss ii cc)
+
+add_custom_target(blocks_generated_includes DEPENDS
+ ${generated_includes}
+)
+
+########################################################################
+# Install header files
+########################################################################
+install(FILES
+ ${generated_includes}
+ api.h
+ add_ff.h
+ DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
+ COMPONENT "blocks_devel"
+)
diff --git a/gr-blocks/include/blocks/add_XX.h.t b/gr-blocks/include/blocks/add_XX.h.t
new file mode 100644
index 000000000..607b82066
--- /dev/null
+++ b/gr-blocks/include/blocks/add_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = sum (input_0, input_1, ...)
+ * \ingroup math_blk
+ *
+ * Add across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/add_ff.h b/gr-blocks/include/blocks/add_ff.h
new file mode 100644
index 000000000..22d382c4a
--- /dev/null
+++ b/gr-blocks/include/blocks/add_ff.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_ADD_FF_H
+#define INCLUDED_BLOCKS_ADD_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API add_ff : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::add_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Add streams of complex values
+ * \ingroup math_blk
+ */
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_ADD_FF_H */
diff --git a/gr-blocks/include/blocks/api.h b/gr-blocks/include/blocks/api.h
new file mode 100644
index 000000000..45fbc0d21
--- /dev/null
+++ b/gr-blocks/include/blocks/api.h
@@ -0,0 +1,33 @@
+/*
+ * 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_API_H
+#define INCLUDED_BLOCKS_API_H
+
+#include
+
+#ifdef gnuradio_blocks_EXPORTS
+# define BLOCKS_API __GR_ATTR_EXPORT
+#else
+# define BLOCKS_API __GR_ATTR_IMPORT
+#endif
+
+#endif /* INCLUDED_BLOCKS_API_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
new file mode 100644
index 000000000..f5ed77f3b
--- /dev/null
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -0,0 +1,126 @@
+# 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.
+
+########################################################################
+# generate helper scripts to expand templated files
+########################################################################
+include(GrPython)
+
+file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py "
+#!${PYTHON_EXECUTABLE}
+
+import sys, os, re
+sys.path.append('${GR_CORE_PYTHONPATH}')
+os.environ['srcdir'] = '${CMAKE_CURRENT_SOURCE_DIR}'
+os.chdir('${CMAKE_CURRENT_BINARY_DIR}')
+
+if __name__ == '__main__':
+ import build_utils
+ root, inp = sys.argv[1:3]
+ for sig in sys.argv[3:]:
+ name = re.sub ('X+', sig, root)
+ d = build_utils.standard_dict(name, sig, 'blocks')
+ build_utils.expand_template(d, inp, '_impl')
+")
+
+macro(expand_cc_h_impl root)
+ #make a list of all the generated files
+ unset(expanded_files_cc)
+ unset(expanded_files_h)
+ foreach(sig ${ARGN})
+ string(REGEX REPLACE "X+" ${sig} name ${root})
+ list(APPEND expanded_files_cc_impl ${CMAKE_CURRENT_BINARY_DIR}/${name}_impl.cc)
+ list(APPEND expanded_files_h_impl ${CMAKE_CURRENT_BINARY_DIR}/${name}_impl.h)
+ list(APPEND expanded_files_h ${CMAKE_CURRENT_BINARY_DIR}/../include/${name}.h)
+ endforeach(sig)
+
+ #create a command to generate the _impl.cc files
+ add_custom_command(
+ OUTPUT ${expanded_files_cc_impl}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}_impl.cc.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}_impl.cc.t ${ARGN}
+ )
+
+ #create a command to generate the _impl.h files
+ add_custom_command(
+ OUTPUT ${expanded_files_h_impl}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${root}_impl.h.t
+ COMMAND ${PYTHON_EXECUTABLE} ${PYTHON_DASH_B}
+ ${CMAKE_CURRENT_BINARY_DIR}/generate_helper.py
+ ${root} ${root}_impl.h.t ${ARGN}
+ )
+
+ #make _impl.cc source files depend on headers to force generation
+ set_source_files_properties(${expanded_files_cc_impl}
+ PROPERTIES OBJECT_DEPENDS "${expanded_files_h_impl}"
+ )
+
+ #make _impl.h source files depend on headers to force generation
+ set_source_files_properties(${expanded_files_h_impl}
+ PROPERTIES OBJECT_DEPENDS "${expanded_files_h}"
+ )
+
+ #install rules for the generated cc files
+ list(APPEND generated_sources ${expanded_files_cc_impl})
+endmacro(expand_cc_h_impl)
+
+########################################################################
+# Invoke macro to generate various sources
+########################################################################
+expand_cc_h_impl(add_XX ss ii cc)
+
+########################################################################
+# Setup the include and linker paths
+########################################################################
+include_directories(
+ ${GNURADIO_CORE_INCLUDE_DIRS}
+ ${VOLK_INCLUDE_DIRS}
+ ${GR_BLOCKS_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_BINARY_DIR}/../include
+)
+
+include_directories(${BLOCKS_INCLUDE_DIRS})
+link_directories(${BLOCKS_LIBRARY_DIRS})
+
+include_directories(${Boost_INCLUDE_DIRS})
+link_directories(${Boost_LIBRARY_DIRS})
+
+########################################################################
+# Setup library
+########################################################################
+list(APPEND gr_blocks_sources
+ ${generated_sources}
+ add_ff_impl.cc
+)
+
+list(APPEND blocks_libs
+ gnuradio-core
+ ${Boost_LIBRARIES}
+ ${BLOCKS_LIBRARIES}
+)
+
+add_library(gnuradio-blocks SHARED ${gr_blocks_sources})
+add_dependencies(gnuradio-blocks blocks_generated_includes)
+
+target_link_libraries(gnuradio-blocks ${blocks_libs})
+GR_LIBRARY_FOO(gnuradio-blocks RUNTIME_COMPONENT "blocks_runtime" DEVEL_COMPONENT "blocks_devel")
diff --git a/gr-blocks/lib/add_XX_impl.cc.t b/gr-blocks/lib/add_XX_impl.cc.t
new file mode 100644
index 000000000..c528e2fbf
--- /dev/null
+++ b/gr-blocks/lib/add_XX_impl.cc.t
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc += ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/add_XX_impl.h.t b/gr-blocks/lib/add_XX_impl.h.t
new file mode 100644
index 000000000..78c62b5e1
--- /dev/null
+++ b/gr-blocks/lib/add_XX_impl.h.t
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/add_ff_impl.cc b/gr-blocks/lib/add_ff_impl.cc
new file mode 100644
index 000000000..754618d96
--- /dev/null
+++ b/gr-blocks/lib/add_ff_impl.cc
@@ -0,0 +1,71 @@
+/* -*- 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 "add_ff_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ add_ff::sptr add_ff::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new add_ff_impl(vlen));
+ }
+
+ add_ff_impl::add_ff_impl(size_t vlen)
+ : gr_sync_block("add_ff",
+ gr_make_io_signature (1, -1, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(alignment_multiple);
+ }
+
+ int
+ add_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ float *out = (float *) output_items[0];
+ int noi = d_vlen*noutput_items;
+
+ memcpy(out, input_items[0], noi*sizeof(float));
+ if(is_unaligned()) {
+ for(size_t i = 1; i < input_items.size(); i++)
+ volk_32f_x2_add_32f_u(out, out, (const float*)input_items[i], noi);
+ }
+ else {
+ for(size_t i = 1; i < input_items.size(); i++)
+ volk_32f_x2_add_32f_a(out, out, (const float*)input_items[i], noi);
+ }
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/add_ff_impl.h b/gr-blocks/lib/add_ff_impl.h
new file mode 100644
index 000000000..5ebf173d6
--- /dev/null
+++ b/gr-blocks/lib/add_ff_impl.h
@@ -0,0 +1,46 @@
+/* -*- 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_ADD_FF_IMPL_H
+#define INCLUDED_BLOCKS_ADD_FF_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API add_ff_impl : public add_ff
+ {
+ size_t d_vlen;
+
+ public:
+ add_ff_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_BLOCKS_ADD_FF_IMPL_H */
diff --git a/gr-blocks/python/CMakeLists.txt b/gr-blocks/python/CMakeLists.txt
new file mode 100644
index 000000000..a7f0e741a
--- /dev/null
+++ b/gr-blocks/python/CMakeLists.txt
@@ -0,0 +1,47 @@
+# 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.
+
+########################################################################
+include(GrPython)
+
+GR_PYTHON_INSTALL(
+ FILES
+ __init__.py
+ DESTINATION ${GR_PYTHON_DIR}/gnuradio/blocks
+ COMPONENT "blocks_python"
+)
+
+########################################################################
+# Handle the unit tests
+########################################################################
+if(ENABLE_TESTING)
+include(GrTest)
+file(GLOB py_qa_test_files "qa_*.py")
+foreach(py_qa_test_file ${py_qa_test_files})
+ get_filename_component(py_qa_test_name ${py_qa_test_file} NAME_WE)
+ set(GR_TEST_PYTHON_DIRS
+ ${CMAKE_BINARY_DIR}/gnuradio-core/src/python
+ ${CMAKE_BINARY_DIR}/gnuradio-core/src/lib/swig
+ ${CMAKE_BINARY_DIR}/gr-blocks/python
+ ${CMAKE_BINARY_DIR}/gr-blocks/swig
+ )
+ set(GR_TEST_TARGET_DEPS gruel gnuradio-core gnuradio-blocks)
+ GR_ADD_TEST(${py_qa_test_name} ${PYTHON_EXECUTABLE} ${py_qa_test_file})
+endforeach(py_qa_test_file)
+endif(ENABLE_TESTING)
diff --git a/gr-blocks/python/__init__.py b/gr-blocks/python/__init__.py
new file mode 100644
index 000000000..c786d3a22
--- /dev/null
+++ b/gr-blocks/python/__init__.py
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+'''
+This is the gr-blocks package. This package provides GNU Radio
+processing blocks common to many flowgraphs.
+'''
+
+from blocks_swig import *
+
diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py
new file mode 100755
index 000000000..7d008202b
--- /dev/null
+++ b/gr-blocks/python/qa_add_and_friends.py
@@ -0,0 +1,195 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,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
+
+class test_add_and_friends(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def help_ii(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_i(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_i()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_ss(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_s(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_s()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_ff(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_f(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_f()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_cc(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_c(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_c()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def test_add_ff(self):
+ src1_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src2_data = (8.0, -3.0, 4.0, 8.0, 2.0)
+ expected_result = (9.0, -1.0, 7.0, 12.0, 7.0)
+ op = blocks_swig.add_ff()
+ self.help_ff((src1_data, src2_data), expected_result, op)
+
+ def test_add_ss(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (9, -1, 7, 12, 7)
+ op = blocks_swig.add_ss()
+ self.help_ss((src1_data, src2_data), expected_result, op)
+
+ def test_add_ii(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (9, -1, 7, 12, 7)
+ op = blocks_swig.add_ii()
+ self.help_ii((src1_data, src2_data), expected_result, op)
+
+ def test_add_cc(self):
+ src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
+ src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j)
+ expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j)
+ op = blocks_swig.add_cc()
+ self.help_cc((src1_data, src2_data), expected_result, op)
+
+ """
+ def test_add_const_ii(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_result = (6, 7, 8, 9, 10)
+ op = gr.add_const_ii(5)
+ self.help_ii((src_data,), expected_result, op)
+
+ def test_add_const_cc(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
+ op = gr.add_const_cc(5j)
+ self.help_cc((src_data,), expected_result, op)
+
+ def test_mult_const_ii(self):
+ src_data = (-1, 0, 1, 2, 3)
+ expected_result = (-5, 0, 5, 10, 15)
+ op = gr.multiply_const_ii(5)
+ self.help_ii((src_data,), expected_result, op)
+
+ def test_mult_const_ff(self):
+ src_data = (-1, 0, 1, 2, 3)
+ expected_result = (-5, 0, 5, 10, 15)
+ op = gr.multiply_const_cc(5)
+ self.help_cc((src_data,), expected_result, op)
+
+ def test_mult_const_cc(self):
+ src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
+ expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j)
+ op = gr.multiply_const_cc(5)
+ self.help_cc((src_data,), expected_result, op)
+
+ def test_mult_const_cc2(self):
+ src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
+ expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j)
+ op = gr.multiply_const_cc(5+2j)
+ self.help_cc((src_data,), expected_result, op)
+
+ def test_mult_ii(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8, -6, 12, 32, 10)
+ op = gr.multiply_ii()
+ self.help_ii((src1_data, src2_data),
+ expected_result, op)
+
+ def test_mult_ff(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8, -6, 12, 32, 10)
+ op = gr.multiply_ff()
+ self.help_ff((src1_data, src2_data),
+ expected_result, op)
+
+ def test_mult_cc(self):
+ src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j)
+ op = gr.multiply_cc()
+ self.help_cc((src1_data, src2_data),
+ expected_result, op)
+
+ def test_sub_ii_1(self):
+ src1_data = (1, 2, 3, 4, 5)
+ expected_result = (-1, -2, -3, -4, -5)
+ op = gr.sub_ii()
+ self.help_ii((src1_data,),
+ expected_result, op)
+
+ def test_sub_ii_2(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (-7, 5, -1, -4, 3)
+ op = gr.sub_ii()
+ self.help_ii((src1_data, src2_data),
+ expected_result, op)
+
+ def test_div_ff_1(self):
+ src1_data = (1, 2, 4, -8)
+ expected_result = (1, 0.5, 0.25, -.125)
+ op = gr.divide_ff()
+ self.help_ff((src1_data,),
+ expected_result, op)
+
+ def test_div_ff_2(self):
+ src1_data = ( 5, 9, -15, 1024)
+ src2_data = (10, 3, -5, 64)
+ expected_result = (0.5, 3, 3, 16)
+ op = gr.divide_ff()
+ self.help_ff((src1_data, src2_data),
+ expected_result, op)
+ """
+
+if __name__ == '__main__':
+ gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml")
diff --git a/gr-blocks/swig/CMakeLists.txt b/gr-blocks/swig/CMakeLists.txt
new file mode 100644
index 000000000..fb29789f0
--- /dev/null
+++ b/gr-blocks/swig/CMakeLists.txt
@@ -0,0 +1,51 @@
+# 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.
+
+########################################################################
+# Setup swig generation
+########################################################################
+include(GrPython)
+include(GrSwig)
+
+set(GR_SWIG_INCLUDE_DIRS
+ ${GR_BLOCKS_INCLUDE_DIRS}
+ ${GNURADIO_CORE_SWIG_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_BINARY_DIR}/../include
+)
+
+set(GR_SWIG_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/blocks_swig_doc.i)
+set(GR_SWIG_DOC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../lib)
+
+set(GR_SWIG_LIBRARIES gnuradio-blocks)
+
+GR_SWIG_MAKE(blocks_swig blocks_swig.i)
+
+GR_SWIG_INSTALL(
+ TARGETS blocks_swig
+ DESTINATION ${GR_PYTHON_DIR}/gnuradio/blocks
+ COMPONENT "blocks_python"
+)
+
+install(
+ FILES
+ blocks_swig.i
+ ${CMAKE_CURRENT_BINARY_DIR}/blocks_swig_doc.i
+ DESTINATION ${GR_INCLUDE_DIR}/gnuradio/swig
+ COMPONENT "blocks_swig"
+)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
new file mode 100644
index 000000000..3ca8583f1
--- /dev/null
+++ b/gr-blocks/swig/blocks_swig.i
@@ -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.
+ */
+
+#define BLOCKS_API
+
+%include "gnuradio.i"
+
+//load generated python docstrings
+%include "blocks_swig_doc.i"
+
+%{
+#include "blocks/add_ff.h"
+#include "blocks/add_ss.h"
+#include "blocks/add_ii.h"
+#include "blocks/add_cc.h"
+%}
+
+%include "blocks/add_ff.h"
+%include "blocks/add_ss.h"
+%include "blocks/add_ii.h"
+%include "blocks/add_cc.h"
+
+GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_cc);
--
cgit
From 9752fabd851d05c77b0526e7a28c9c7099e54fc6 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 8 Jun 2012 14:48:46 -0700
Subject: blocks: added blocks_add_const_xx
---
gr-blocks/grc/blocks_add_const_xx.xml | 67 +++++++++++++++++++++++++++
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/include/blocks/CMakeLists.txt | 3 +-
gr-blocks/include/blocks/add_const_XX.h.t | 65 ++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 7 +--
gr-blocks/lib/add_const_XX_impl.cc.t | 77 +++++++++++++++++++++++++++++++
gr-blocks/lib/add_const_XX_impl.h.t | 50 ++++++++++++++++++++
gr-blocks/python/qa_add_and_friends.py | 7 ++-
gr-blocks/swig/blocks_swig.i | 12 +++++
9 files changed, 281 insertions(+), 8 deletions(-)
create mode 100644 gr-blocks/grc/blocks_add_const_xx.xml
create mode 100644 gr-blocks/include/blocks/add_const_XX.h.t
create mode 100644 gr-blocks/lib/add_const_XX_impl.cc.t
create mode 100644 gr-blocks/lib/add_const_XX_impl.h.t
diff --git a/gr-blocks/grc/blocks_add_const_xx.xml b/gr-blocks/grc/blocks_add_const_xx.xml
new file mode 100644
index 000000000..dc8ec1819
--- /dev/null
+++ b/gr-blocks/grc/blocks_add_const_xx.xml
@@ -0,0 +1,67 @@
+
+
+
+ Add Const
+ gr_add_const_vxx
+ from gnuradio import blocks
+ blocks.add_const_v$(type.fcn)($const)
+ set_k($const)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Constant
+ const
+ 0
+ $type.const_type
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ len($const) == $vlen
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 37ed367c6..b4834d06f 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -31,5 +31,6 @@
Math Operationsblocks_add_xx
+ blocks_add_const_xx
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index f11db5fc0..68002588b 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -64,7 +64,8 @@ endmacro(expand_h)
########################################################################
# Invoke macro to generate various sources
########################################################################
-expand_h(add_XX ss ii cc)
+expand_h(add_XX ss ii cc)
+expand_h(add_const_XX ss ii ff cc)
add_custom_target(blocks_generated_includes DEPENDS
${generated_includes}
diff --git a/gr-blocks/include/blocks/add_const_XX.h.t b/gr-blocks/include/blocks/add_const_XX.h.t
new file mode 100644
index 000000000..ab7952033
--- /dev/null
+++ b/gr-blocks/include/blocks/add_const_XX.h.t
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input + constant
+ * \ingroup math_blk
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ /*!
+ * \brief Create an instance of @NAME@
+ * \param k additive constant
+ */
+ static sptr make(@O_TYPE@ k);
+
+ /*!
+ * \brief Return additive constant
+ */
+ virtual @O_TYPE@ k() const = 0;
+
+ /*!
+ * \brief Set additive constant
+ */
+ virtual void set_k(@O_TYPE@ k) = 0;
+ };
+
+ }
+}
+
+#endif /* @GUARD_NAME */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index f5ed77f3b..334d18830 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -41,8 +41,8 @@ if __name__ == '__main__':
macro(expand_cc_h_impl root)
#make a list of all the generated files
- unset(expanded_files_cc)
- unset(expanded_files_h)
+ unset(expanded_files_cc_impl)
+ unset(expanded_files_h_impl)
foreach(sig ${ARGN})
string(REGEX REPLACE "X+" ${sig} name ${root})
list(APPEND expanded_files_cc_impl ${CMAKE_CURRENT_BINARY_DIR}/${name}_impl.cc)
@@ -85,7 +85,8 @@ endmacro(expand_cc_h_impl)
########################################################################
# Invoke macro to generate various sources
########################################################################
-expand_cc_h_impl(add_XX ss ii cc)
+expand_cc_h_impl(add_XX ss ii cc)
+expand_cc_h_impl(add_const_XX ss ii ff cc)
########################################################################
# Setup the include and linker paths
diff --git a/gr-blocks/lib/add_const_XX_impl.cc.t b/gr-blocks/lib/add_const_XX_impl.cc.t
new file mode 100644
index 000000000..7fa883f4b
--- /dev/null
+++ b/gr-blocks/lib/add_const_XX_impl.cc.t
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(@O_TYPE@ k)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(k));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(@O_TYPE@ k)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@))),
+ d_k(k)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@ *) input_items[0];
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int size = noutput_items;
+
+ while (size >= 8){
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ *optr++ = *iptr++ + d_k;
+ size -= 8;
+ }
+
+ while (size-- > 0)
+ *optr++ = *iptr++ + d_k;
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/add_const_XX_impl.h.t b/gr-blocks/lib/add_const_XX_impl.h.t
new file mode 100644
index 000000000..1b21480c1
--- /dev/null
+++ b/gr-blocks/lib/add_const_XX_impl.h.t
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ @O_TYPE@ d_k;
+
+ public:
+ @NAME_IMPL@(@O_TYPE@ k);
+
+ @O_TYPE@ k() const { return d_k; }
+ void set_k(@O_TYPE@ k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py
index 7d008202b..f38c135f2 100755
--- a/gr-blocks/python/qa_add_and_friends.py
+++ b/gr-blocks/python/qa_add_and_friends.py
@@ -99,19 +99,18 @@ class test_add_and_friends(gr_unittest.TestCase):
op = blocks_swig.add_cc()
self.help_cc((src1_data, src2_data), expected_result, op)
- """
def test_add_const_ii(self):
src_data = (1, 2, 3, 4, 5)
expected_result = (6, 7, 8, 9, 10)
- op = gr.add_const_ii(5)
+ op = blocks_swig.add_const_ii(5)
self.help_ii((src_data,), expected_result, op)
def test_add_const_cc(self):
src_data = (1, 2, 3, 4, 5)
expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
- op = gr.add_const_cc(5j)
+ op = blocks_swig.add_const_cc(5j)
self.help_cc((src_data,), expected_result, op)
-
+ """
def test_mult_const_ii(self):
src_data = (-1, 0, 1, 2, 3)
expected_result = (-5, 0, 5, 10, 15)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 3ca8583f1..7be0396f4 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -32,14 +32,26 @@
#include "blocks/add_ss.h"
#include "blocks/add_ii.h"
#include "blocks/add_cc.h"
+#include "blocks/add_const_ff.h"
+#include "blocks/add_const_ss.h"
+#include "blocks/add_const_ii.h"
+#include "blocks/add_const_cc.h"
%}
%include "blocks/add_ff.h"
%include "blocks/add_ss.h"
%include "blocks/add_ii.h"
%include "blocks/add_cc.h"
+%include "blocks/add_const_ff.h"
+%include "blocks/add_const_ss.h"
+%include "blocks/add_const_ii.h"
+%include "blocks/add_const_cc.h"
GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, add_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_cc);
--
cgit
From 1dcce62a400a5d6674482dea2e917631923764fa Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 8 Jun 2012 15:01:33 -0700
Subject: blocks: fix XML file in previous commit
---
gr-blocks/grc/blocks_add_const_xx.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gr-blocks/grc/blocks_add_const_xx.xml b/gr-blocks/grc/blocks_add_const_xx.xml
index dc8ec1819..5330f5dda 100644
--- a/gr-blocks/grc/blocks_add_const_xx.xml
+++ b/gr-blocks/grc/blocks_add_const_xx.xml
@@ -7,7 +7,7 @@
-->
Add Const
- gr_add_const_vxx
+ blocks_add_const_xxfrom gnuradio import blocksblocks.add_const_v$(type.fcn)($const)set_k($const)
--
cgit
From 6260c4263231718c81770916c2574f8d395d10d6 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sun, 10 Jun 2012 11:25:02 -0700
Subject: blocks: copy alignment fix from maint
---
gr-blocks/lib/add_ff_impl.cc | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/gr-blocks/lib/add_ff_impl.cc b/gr-blocks/lib/add_ff_impl.cc
index 754618d96..83359ef80 100644
--- a/gr-blocks/lib/add_ff_impl.cc
+++ b/gr-blocks/lib/add_ff_impl.cc
@@ -44,7 +44,7 @@ namespace gr {
{
const int alignment_multiple =
volk_get_alignment() / sizeof(float);
- set_alignment(alignment_multiple);
+ set_alignment(std::max(1, alignment_multiple));
}
int
--
cgit
From 6a2d514fab10f692d49f724d1d09afce1c603fa0 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 14 Jun 2012 10:09:14 -0700
Subject: blocks: added multiply_xx, some cleanup on add_xx
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_multiply_xx.xml | 63 ++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 3 ++
gr-blocks/include/blocks/add_ff.h | 3 +-
gr-blocks/include/blocks/multiply_XX.h.t | 53 ++++++++++++++++++++++++
gr-blocks/include/blocks/multiply_cc.h | 50 ++++++++++++++++++++++
gr-blocks/include/blocks/multiply_ff.h | 50 ++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 3 ++
gr-blocks/lib/add_XX_impl.h.t | 1 +
gr-blocks/lib/add_const_XX_impl.h.t | 1 +
gr-blocks/lib/add_ff_impl.h | 1 +
gr-blocks/lib/multiply_XX_impl.cc.t | 69 +++++++++++++++++++++++++++++++
gr-blocks/lib/multiply_XX_impl.h.t | 47 +++++++++++++++++++++
gr-blocks/lib/multiply_cc_impl.cc | 71 ++++++++++++++++++++++++++++++++
gr-blocks/lib/multiply_cc_impl.h | 47 +++++++++++++++++++++
gr-blocks/lib/multiply_ff_impl.cc | 71 ++++++++++++++++++++++++++++++++
gr-blocks/lib/multiply_ff_impl.h | 47 +++++++++++++++++++++
gr-blocks/python/qa_add_and_friends.py | 10 ++---
gr-blocks/swig/blocks_swig.i | 12 ++++++
19 files changed, 597 insertions(+), 6 deletions(-)
create mode 100644 gr-blocks/grc/blocks_multiply_xx.xml
create mode 100644 gr-blocks/include/blocks/multiply_XX.h.t
create mode 100644 gr-blocks/include/blocks/multiply_cc.h
create mode 100644 gr-blocks/include/blocks/multiply_ff.h
create mode 100644 gr-blocks/lib/multiply_XX_impl.cc.t
create mode 100644 gr-blocks/lib/multiply_XX_impl.h.t
create mode 100644 gr-blocks/lib/multiply_cc_impl.cc
create mode 100644 gr-blocks/lib/multiply_cc_impl.h
create mode 100644 gr-blocks/lib/multiply_ff_impl.cc
create mode 100644 gr-blocks/lib/multiply_ff_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index b4834d06f..125137d8b 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -32,5 +32,6 @@
Math Operationsblocks_add_xxblocks_add_const_xx
+ blocks_multiply_xx
diff --git a/gr-blocks/grc/blocks_multiply_xx.xml b/gr-blocks/grc/blocks_multiply_xx.xml
new file mode 100644
index 000000000..d1578ca11
--- /dev/null
+++ b/gr-blocks/grc/blocks_multiply_xx.xml
@@ -0,0 +1,63 @@
+
+
+
+ Multiply
+ blocks_multiply_xx
+ from gnuradio import blocks
+ gr.multiply_v$(type.fcn)($vlen)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_inputs > 1
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+ $num_inputs
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 68002588b..77dd91e28 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -66,6 +66,7 @@ endmacro(expand_h)
########################################################################
expand_h(add_XX ss ii cc)
expand_h(add_const_XX ss ii ff cc)
+expand_h(multiply_XX ss ii)
add_custom_target(blocks_generated_includes DEPENDS
${generated_includes}
@@ -78,6 +79,8 @@ install(FILES
${generated_includes}
api.h
add_ff.h
+ multiply_cc.h
+ multiply_ff.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/add_ff.h b/gr-blocks/include/blocks/add_ff.h
index 22d382c4a..1e7350c1b 100644
--- a/gr-blocks/include/blocks/add_ff.h
+++ b/gr-blocks/include/blocks/add_ff.h
@@ -37,7 +37,8 @@ namespace gr {
typedef boost::shared_ptr sptr;
/*!
- * \brief Add streams of complex values
+ * \brief Add streams of float values
+ * \param vlen Vector length
* \ingroup math_blk
*/
static sptr make(size_t vlen=1);
diff --git a/gr-blocks/include/blocks/multiply_XX.h.t b/gr-blocks/include/blocks/multiply_XX.h.t
new file mode 100644
index 000000000..47ed3746c
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004, 2009, 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = prod (input_0, input_1, ...)
+ * \ingroup math_blk
+ *
+ * Multiply across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/multiply_cc.h b/gr-blocks/include/blocks/multiply_cc.h
new file mode 100644
index 000000000..559fcda57
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_cc.h
@@ -0,0 +1,50 @@
+/* -*- 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_GR_MULTIPLY_CC_H
+#define INCLUDED_GR_MULTIPLY_CC_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_cc : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::multiply_cc::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Multiply streams of complex values
+ * \param vlen Vector length
+ * \ingroup math_blk
+ */
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_MULTIPLY_CC_H */
diff --git a/gr-blocks/include/blocks/multiply_ff.h b/gr-blocks/include/blocks/multiply_ff.h
new file mode 100644
index 000000000..683b540bb
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_ff.h
@@ -0,0 +1,50 @@
+/* -*- 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_GR_MULTIPLY_FF_H
+#define INCLUDED_GR_MULTIPLY_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_ff : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::multiply_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Multiply streams of float values
+ * \param vlen Vector length
+ * \ingroup math_blk
+ */
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_MULTIPLY_FF_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 334d18830..7894c34ea 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -87,6 +87,7 @@ endmacro(expand_cc_h_impl)
########################################################################
expand_cc_h_impl(add_XX ss ii cc)
expand_cc_h_impl(add_const_XX ss ii ff cc)
+expand_cc_h_impl(multiply_XX ss ii)
########################################################################
# Setup the include and linker paths
@@ -112,6 +113,8 @@ link_directories(${Boost_LIBRARY_DIRS})
list(APPEND gr_blocks_sources
${generated_sources}
add_ff_impl.cc
+ multiply_cc_impl.cc
+ multiply_ff_impl.cc
)
list(APPEND blocks_libs
diff --git a/gr-blocks/lib/add_XX_impl.h.t b/gr-blocks/lib/add_XX_impl.h.t
index 78c62b5e1..a1c486b85 100644
--- a/gr-blocks/lib/add_XX_impl.h.t
+++ b/gr-blocks/lib/add_XX_impl.h.t
@@ -41,6 +41,7 @@ namespace gr {
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
+
} /* namespace blocks */
} /* namespace gr */
diff --git a/gr-blocks/lib/add_const_XX_impl.h.t b/gr-blocks/lib/add_const_XX_impl.h.t
index 1b21480c1..cae5ca813 100644
--- a/gr-blocks/lib/add_const_XX_impl.h.t
+++ b/gr-blocks/lib/add_const_XX_impl.h.t
@@ -44,6 +44,7 @@ namespace gr {
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
+
} /* namespace blocks */
} /* namespace gr */
diff --git a/gr-blocks/lib/add_ff_impl.h b/gr-blocks/lib/add_ff_impl.h
index 5ebf173d6..77b90d079 100644
--- a/gr-blocks/lib/add_ff_impl.h
+++ b/gr-blocks/lib/add_ff_impl.h
@@ -39,6 +39,7 @@ namespace gr {
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
+
} /* namespace blocks */
} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_XX_impl.cc.t b/gr-blocks/lib/multiply_XX_impl.cc.t
new file mode 100644
index 000000000..bda4eac6a
--- /dev/null
+++ b/gr-blocks/lib/multiply_XX_impl.cc.t
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc *= ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_XX_impl.h.t b/gr-blocks/lib/multiply_XX_impl.h.t
new file mode 100644
index 000000000..78c62b5e1
--- /dev/null
+++ b/gr-blocks/lib/multiply_XX_impl.h.t
@@ -0,0 +1,47 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/multiply_cc_impl.cc b/gr-blocks/lib/multiply_cc_impl.cc
new file mode 100644
index 000000000..e5160a9d5
--- /dev/null
+++ b/gr-blocks/lib/multiply_cc_impl.cc
@@ -0,0 +1,71 @@
+/* -*- 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
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ multiply_cc::sptr multiply_cc::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new multiply_cc_impl(vlen));
+ }
+
+ multiply_cc_impl::multiply_cc_impl(size_t vlen)
+ : gr_sync_block("multiply_cc",
+ gr_make_io_signature (1, -1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ multiply_cc_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gr_complex *out = (gr_complex *) output_items[0];
+ int noi = d_vlen*noutput_items;
+
+ memcpy(out, input_items[0], noi*sizeof(gr_complex));
+ if(is_unaligned()) {
+ for(size_t i = 1; i < input_items.size(); i++)
+ volk_32fc_x2_multiply_32fc_u(out, out, (gr_complex*)input_items[i], noi);
+ }
+ else {
+ for(size_t i = 1; i < input_items.size(); i++)
+ volk_32fc_x2_multiply_32fc_a(out, out, (gr_complex*)input_items[i], noi);
+ }
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/multiply_cc_impl.h b/gr-blocks/lib/multiply_cc_impl.h
new file mode 100644
index 000000000..1595dc524
--- /dev/null
+++ b/gr-blocks/lib/multiply_cc_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_BLOCKS_MULTIPLY_CC_IMPL_H
+#define INCLUDED_BLOCKS_MULTIPLY_CC_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_cc_impl : public multiply_cc
+ {
+ size_t d_vlen;
+
+ public:
+ multiply_cc_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_BLOCKS_MULTIPLY_CC_IMPL_H */
diff --git a/gr-blocks/lib/multiply_ff_impl.cc b/gr-blocks/lib/multiply_ff_impl.cc
new file mode 100644
index 000000000..6e8f27711
--- /dev/null
+++ b/gr-blocks/lib/multiply_ff_impl.cc
@@ -0,0 +1,71 @@
+/* -*- 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
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ multiply_ff::sptr multiply_ff::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new multiply_ff_impl(vlen));
+ }
+
+ multiply_ff_impl::multiply_ff_impl(size_t vlen)
+ : gr_sync_block("multiply_ff",
+ gr_make_io_signature (1, -1, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ multiply_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ float *out = (float *) output_items[0];
+ int noi = d_vlen*noutput_items;
+
+ memcpy(out, input_items[0], noi*sizeof(float));
+ if(is_unaligned()) {
+ for(size_t i = 1; i < input_items.size(); i++)
+ volk_32f_x2_multiply_32f_u(out, out, (float*)input_items[i], noi);
+ }
+ else {
+ for(size_t i = 1; i < input_items.size(); i++)
+ volk_32f_x2_multiply_32f_a(out, out, (float*)input_items[i], noi);
+ }
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/multiply_ff_impl.h b/gr-blocks/lib/multiply_ff_impl.h
new file mode 100644
index 000000000..2c5325a98
--- /dev/null
+++ b/gr-blocks/lib/multiply_ff_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_BLOCKS_MULTIPLY_FF_IMPL_H
+#define INCLUDED_BLOCKS_MULTIPLY_FF_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_ff_impl : public multiply_ff
+ {
+ size_t d_vlen;
+
+ public:
+ multiply_ff_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_BLOCKS_MULTIPLY_FF_IMPL_H */
diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py
index f38c135f2..0c8a91ce9 100755
--- a/gr-blocks/python/qa_add_and_friends.py
+++ b/gr-blocks/python/qa_add_and_friends.py
@@ -134,12 +134,12 @@ class test_add_and_friends(gr_unittest.TestCase):
expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j)
op = gr.multiply_const_cc(5+2j)
self.help_cc((src_data,), expected_result, op)
-
+ """
def test_mult_ii(self):
src1_data = (1, 2, 3, 4, 5)
src2_data = (8, -3, 4, 8, 2)
expected_result = (8, -6, 12, 32, 10)
- op = gr.multiply_ii()
+ op = blocks_swig.multiply_ii()
self.help_ii((src1_data, src2_data),
expected_result, op)
@@ -147,7 +147,7 @@ class test_add_and_friends(gr_unittest.TestCase):
src1_data = (1, 2, 3, 4, 5)
src2_data = (8, -3, 4, 8, 2)
expected_result = (8, -6, 12, 32, 10)
- op = gr.multiply_ff()
+ op = blocks_swig.multiply_ff()
self.help_ff((src1_data, src2_data),
expected_result, op)
@@ -155,10 +155,10 @@ class test_add_and_friends(gr_unittest.TestCase):
src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
src2_data = (8, -3, 4, 8, 2)
expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j)
- op = gr.multiply_cc()
+ op = blocks_swig.multiply_cc()
self.help_cc((src1_data, src2_data),
expected_result, op)
-
+ """
def test_sub_ii_1(self):
src1_data = (1, 2, 3, 4, 5)
expected_result = (-1, -2, -3, -4, -5)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 7be0396f4..dc87f4f12 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -36,6 +36,10 @@
#include "blocks/add_const_ss.h"
#include "blocks/add_const_ii.h"
#include "blocks/add_const_cc.h"
+#include "blocks/multiply_ss.h"
+#include "blocks/multiply_ii.h"
+#include "blocks/multiply_ff.h"
+#include "blocks/multiply_cc.h"
%}
%include "blocks/add_ff.h"
@@ -46,6 +50,10 @@
%include "blocks/add_const_ss.h"
%include "blocks/add_const_ii.h"
%include "blocks/add_const_cc.h"
+%include "blocks/multiply_ss.h"
+%include "blocks/multiply_ii.h"
+%include "blocks/multiply_ff.h"
+%include "blocks/multiply_cc.h"
GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
@@ -55,3 +63,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_cc);
--
cgit
From 59f49f4663d5795adc7d7cc573d24c0747afad0f Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 16 Jun 2012 12:07:58 -0700
Subject: blocks: completed transition of add and multiply blocks
* gr::blocks::add_*
* gr::blocks::add_const_*
* gr::blocks::add_const_v*
* gr::blocks::multiply_*
* gr::blocks::multiply_const_*
* gr::blocks::multiply_const_v*
Each of these has ss, ii, ff, and cc versions, for a total of
24 blocks.
---
gr-blocks/grc/blocks_add_const_vxx.xml | 67 +++++
gr-blocks/grc/blocks_add_const_xx.xml | 67 -----
gr-blocks/grc/blocks_block_tree.xml | 3 +-
gr-blocks/grc/blocks_multiply_const_vxx.xml | 67 +++++
gr-blocks/grc/blocks_multiply_xx.xml | 2 +-
gr-blocks/include/blocks/CMakeLists.txt | 11 +-
gr-blocks/include/blocks/add_const_XX.h.t | 2 +-
gr-blocks/include/blocks/add_const_vXX.h.t | 66 +++++
gr-blocks/include/blocks/multiply_const_XX.h.t | 66 +++++
gr-blocks/include/blocks/multiply_const_cc.h | 66 +++++
gr-blocks/include/blocks/multiply_const_ff.h | 66 +++++
gr-blocks/include/blocks/multiply_const_vXX.h.t | 66 +++++
gr-blocks/lib/CMakeLists.txt | 11 +-
gr-blocks/lib/add_const_vXX_impl.cc.t | 66 +++++
gr-blocks/lib/add_const_vXX_impl.h.t | 51 ++++
gr-blocks/lib/multiply_const_XX_impl.cc.t | 77 +++++
gr-blocks/lib/multiply_const_XX_impl.h.t | 51 ++++
gr-blocks/lib/multiply_const_cc_impl.cc | 72 +++++
gr-blocks/lib/multiply_const_cc_impl.h | 52 ++++
gr-blocks/lib/multiply_const_ff_impl.cc | 72 +++++
gr-blocks/lib/multiply_const_ff_impl.h | 52 ++++
gr-blocks/lib/multiply_const_vXX_impl.cc.t | 66 +++++
gr-blocks/lib/multiply_const_vXX_impl.h.t | 51 ++++
gr-blocks/python/__init__.py | 9 +
gr-blocks/python/qa_add_and_friends.py | 194 -------------
gr-blocks/python/qa_add_mult_div_sub.py | 230 +++++++++++++++
gr-blocks/python/qa_add_mult_v.py | 360 ++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 36 +++
28 files changed, 1729 insertions(+), 270 deletions(-)
create mode 100644 gr-blocks/grc/blocks_add_const_vxx.xml
delete mode 100644 gr-blocks/grc/blocks_add_const_xx.xml
create mode 100644 gr-blocks/grc/blocks_multiply_const_vxx.xml
create mode 100644 gr-blocks/include/blocks/add_const_vXX.h.t
create mode 100644 gr-blocks/include/blocks/multiply_const_XX.h.t
create mode 100644 gr-blocks/include/blocks/multiply_const_cc.h
create mode 100644 gr-blocks/include/blocks/multiply_const_ff.h
create mode 100644 gr-blocks/include/blocks/multiply_const_vXX.h.t
create mode 100644 gr-blocks/lib/add_const_vXX_impl.cc.t
create mode 100644 gr-blocks/lib/add_const_vXX_impl.h.t
create mode 100644 gr-blocks/lib/multiply_const_XX_impl.cc.t
create mode 100644 gr-blocks/lib/multiply_const_XX_impl.h.t
create mode 100644 gr-blocks/lib/multiply_const_cc_impl.cc
create mode 100644 gr-blocks/lib/multiply_const_cc_impl.h
create mode 100644 gr-blocks/lib/multiply_const_ff_impl.cc
create mode 100644 gr-blocks/lib/multiply_const_ff_impl.h
create mode 100644 gr-blocks/lib/multiply_const_vXX_impl.cc.t
create mode 100644 gr-blocks/lib/multiply_const_vXX_impl.h.t
delete mode 100755 gr-blocks/python/qa_add_and_friends.py
create mode 100755 gr-blocks/python/qa_add_mult_div_sub.py
create mode 100755 gr-blocks/python/qa_add_mult_v.py
diff --git a/gr-blocks/grc/blocks_add_const_vxx.xml b/gr-blocks/grc/blocks_add_const_vxx.xml
new file mode 100644
index 000000000..96303acef
--- /dev/null
+++ b/gr-blocks/grc/blocks_add_const_vxx.xml
@@ -0,0 +1,67 @@
+
+
+
+ Add Const
+ blocks_add_const_vxx
+ from gnuradio import blocks
+ blocks.add_const_v$(type.fcn)($const)
+ set_k($const)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Constant
+ const
+ 0
+ $type.const_type
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ len($const) == $vlen
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/grc/blocks_add_const_xx.xml b/gr-blocks/grc/blocks_add_const_xx.xml
deleted file mode 100644
index 5330f5dda..000000000
--- a/gr-blocks/grc/blocks_add_const_xx.xml
+++ /dev/null
@@ -1,67 +0,0 @@
-
-
-
- Add Const
- blocks_add_const_xx
- from gnuradio import blocks
- blocks.add_const_v$(type.fcn)($const)
- set_k($const)
-
- IO Type
- type
- enum
-
-
-
-
-
-
- Constant
- const
- 0
- $type.const_type
-
-
- Vec Length
- vlen
- 1
- int
-
- len($const) == $vlen
- $vlen > 0
-
- in
- $type
- $vlen
-
-
-
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 125137d8b..c0ce7ec7a 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -31,7 +31,8 @@
Math Operationsblocks_add_xx
- blocks_add_const_xx
+ blocks_add_const_vxxblocks_multiply_xx
+ blocks_multiply_const_vxx
diff --git a/gr-blocks/grc/blocks_multiply_const_vxx.xml b/gr-blocks/grc/blocks_multiply_const_vxx.xml
new file mode 100644
index 000000000..6162621d3
--- /dev/null
+++ b/gr-blocks/grc/blocks_multiply_const_vxx.xml
@@ -0,0 +1,67 @@
+
+
+
+ Multiply Const
+ blocks_multiply_const_vxx
+ from gnuradio import blocks
+ blocks.multiply_const_v$(type.fcn)($const)
+ set_k($const)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Constant
+ const
+ 0
+ $type.const_type
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ len($const) == $vlen
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/grc/blocks_multiply_xx.xml b/gr-blocks/grc/blocks_multiply_xx.xml
index d1578ca11..15f024142 100644
--- a/gr-blocks/grc/blocks_multiply_xx.xml
+++ b/gr-blocks/grc/blocks_multiply_xx.xml
@@ -9,7 +9,7 @@
Multiplyblocks_multiply_xxfrom gnuradio import blocks
- gr.multiply_v$(type.fcn)($vlen)
+ blocks.multiply_v$(type.fcn)($vlen)IO Typetype
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 77dd91e28..79761e496 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -64,9 +64,12 @@ endmacro(expand_h)
########################################################################
# Invoke macro to generate various sources
########################################################################
-expand_h(add_XX ss ii cc)
-expand_h(add_const_XX ss ii ff cc)
-expand_h(multiply_XX ss ii)
+expand_h(add_XX ss ii cc)
+expand_h(add_const_XX ss ii ff cc)
+expand_h(add_const_vXX ss ii ff cc)
+expand_h(multiply_XX ss ii)
+expand_h(multiply_const_XX ss ii)
+expand_h(multiply_const_vXX ss ii ff cc)
add_custom_target(blocks_generated_includes DEPENDS
${generated_includes}
@@ -81,6 +84,8 @@ install(FILES
add_ff.h
multiply_cc.h
multiply_ff.h
+ multiply_const_cc.h
+ multiply_const_ff.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/add_const_XX.h.t b/gr-blocks/include/blocks/add_const_XX.h.t
index ab7952033..df968feac 100644
--- a/gr-blocks/include/blocks/add_const_XX.h.t
+++ b/gr-blocks/include/blocks/add_const_XX.h.t
@@ -62,4 +62,4 @@ namespace gr {
}
}
-#endif /* @GUARD_NAME */
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/add_const_vXX.h.t b/gr-blocks/include/blocks/add_const_vXX.h.t
new file mode 100644
index 000000000..c4cd49fa4
--- /dev/null
+++ b/gr-blocks/include/blocks/add_const_vXX.h.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input + constant vector
+ * \ingroup math_blk
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ /*!
+ * \brief Create an instance of @NAME@
+ * \param k additive constant vector
+ */
+ static sptr make(std::vector<@O_TYPE@> k);
+
+ /*!
+ * \brief Return additive constant vector
+ */
+ virtual std::vector<@O_TYPE@> k() const = 0;
+
+ /*!
+ * \brief Set additive constant vector
+ */
+ virtual void set_k(std::vector<@O_TYPE@> k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/multiply_const_XX.h.t b/gr-blocks/include/blocks/multiply_const_XX.h.t
new file mode 100644
index 000000000..a7cd3a858
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_const_XX.h.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input * constant
+ * \ingroup math_blk
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ /*!
+ * \brief Create an instance of @NAME@
+ * \param k multiplicative constant
+ */
+ static sptr make(@O_TYPE@ k);
+
+ /*!
+ * \brief Return multiplicative constant
+ */
+ virtual @O_TYPE@ k() const = 0;
+
+ /*!
+ * \brief Set multiplicative constant
+ */
+ virtual void set_k(@O_TYPE@ k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME */
diff --git a/gr-blocks/include/blocks/multiply_const_cc.h b/gr-blocks/include/blocks/multiply_const_cc.h
new file mode 100644
index 000000000..032a765a4
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_const_cc.h
@@ -0,0 +1,66 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef INCLUDED_MULTIPLY_CONST_CC_H
+#define INCLUDED_MULTIPLY_CONST_CC_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input * complex constant
+ * \ingroup math_blk
+ */
+ class BLOCKS_API multiply_const_cc : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::multiply_const_cc::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Create an instance of multiply_const_cc
+ * \param k complex multiplicative constant
+ */
+ static sptr make(gr_complex k, size_t vlen=1);
+
+ /*!
+ * \brief Return complex multiplicative constant
+ */
+ virtual gr_complex k() const = 0;
+
+ /*!
+ * \brief Set complex multiplicative constant
+ */
+ virtual void set_k(gr_complex k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_CONST_CC_H */
diff --git a/gr-blocks/include/blocks/multiply_const_ff.h b/gr-blocks/include/blocks/multiply_const_ff.h
new file mode 100644
index 000000000..e755f59bf
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_const_ff.h
@@ -0,0 +1,66 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef INCLUDED_MULTIPLY_CONST_FF_H
+#define INCLUDED_MULTIPLY_CONST_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input * real constant
+ * \ingroup math_blk
+ */
+ class BLOCKS_API multiply_const_ff : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::multiply_const_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Create an instance of multiply_const_ff
+ * \param k real multiplicative constant
+ */
+ static sptr make(float k, size_t vlen=1);
+
+ /*!
+ * \brief Return real multiplicative constant
+ */
+ virtual float k() const = 0;
+
+ /*!
+ * \brief Set real multiplicative constant
+ */
+ virtual void set_k(float k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_CONST_FF_H */
diff --git a/gr-blocks/include/blocks/multiply_const_vXX.h.t b/gr-blocks/include/blocks/multiply_const_vXX.h.t
new file mode 100644
index 000000000..4cd479f00
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_const_vXX.h.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input * constant vector (element-wise)
+ * \ingroup math_blk
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ /*!
+ * \brief Create an instance of @NAME@
+ * \param k multiplicative constant vector
+ */
+ static sptr make(std::vector<@O_TYPE@> k);
+
+ /*!
+ * \brief Return multiplicative constant vector
+ */
+ virtual std::vector<@O_TYPE@> k() const = 0;
+
+ /*!
+ * \brief Set multiplicative constant vector
+ */
+ virtual void set_k(std::vector<@O_TYPE@> k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 7894c34ea..8f433182c 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -85,9 +85,12 @@ endmacro(expand_cc_h_impl)
########################################################################
# Invoke macro to generate various sources
########################################################################
-expand_cc_h_impl(add_XX ss ii cc)
-expand_cc_h_impl(add_const_XX ss ii ff cc)
-expand_cc_h_impl(multiply_XX ss ii)
+expand_cc_h_impl(add_XX ss ii cc)
+expand_cc_h_impl(add_const_XX ss ii ff cc)
+expand_cc_h_impl(add_const_vXX ss ii ff cc)
+expand_cc_h_impl(multiply_XX ss ii)
+expand_cc_h_impl(multiply_const_XX ss ii)
+expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
########################################################################
# Setup the include and linker paths
@@ -115,6 +118,8 @@ list(APPEND gr_blocks_sources
add_ff_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
+ multiply_const_cc_impl.cc
+ multiply_const_ff_impl.cc
)
list(APPEND blocks_libs
diff --git a/gr-blocks/lib/add_const_vXX_impl.cc.t b/gr-blocks/lib/add_const_vXX_impl.cc.t
new file mode 100644
index 000000000..da76cfeef
--- /dev/null
+++ b/gr-blocks/lib/add_const_vXX_impl.cc.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(std::vector<@O_TYPE@> k)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(k));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(std::vector<@O_TYPE@> k)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)*k.size()),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*k.size())),
+ d_k(k)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@ *)input_items[0];
+ @O_TYPE@ *optr = (@O_TYPE@ *)output_items[0];
+
+ int nitems_per_block = output_signature()->sizeof_stream_item(0)/sizeof(@I_TYPE@);
+
+ for (int i = 0; i < noutput_items; i++)
+ for (int j = 0; j < nitems_per_block; j++)
+ *optr++ = *iptr++ + d_k[j];
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/add_const_vXX_impl.h.t b/gr-blocks/lib/add_const_vXX_impl.h.t
new file mode 100644
index 000000000..a7a619725
--- /dev/null
+++ b/gr-blocks/lib/add_const_vXX_impl.h.t
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ std::vector<@O_TYPE@> d_k;
+
+ public:
+ @NAME_IMPL@(std::vector<@O_TYPE@> k);
+
+ std::vector<@O_TYPE@> k() const { return d_k; }
+ void set_k(std::vector<@O_TYPE@> k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/multiply_const_XX_impl.cc.t b/gr-blocks/lib/multiply_const_XX_impl.cc.t
new file mode 100644
index 000000000..8ca79f6f3
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_XX_impl.cc.t
@@ -0,0 +1,77 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(@O_TYPE@ k)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(k));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(@O_TYPE@ k)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@))),
+ d_k(k)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@ *) input_items[0];
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int size = noutput_items;
+
+ while (size >= 8){
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ *optr++ = *iptr++ * d_k;
+ size -= 8;
+ }
+
+ while (size-- > 0)
+ *optr++ = *iptr++ * d_k;
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_const_XX_impl.h.t b/gr-blocks/lib/multiply_const_XX_impl.h.t
new file mode 100644
index 000000000..cae5ca813
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_XX_impl.h.t
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ @O_TYPE@ d_k;
+
+ public:
+ @NAME_IMPL@(@O_TYPE@ k);
+
+ @O_TYPE@ k() const { return d_k; }
+ void set_k(@O_TYPE@ k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/multiply_const_cc_impl.cc b/gr-blocks/lib/multiply_const_cc_impl.cc
new file mode 100644
index 000000000..7618150da
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_cc_impl.cc
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ multiply_const_cc::sptr multiply_const_cc::make(gr_complex k, size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new multiply_const_cc_impl(k, vlen));
+ }
+
+ multiply_const_cc_impl::multiply_const_cc_impl(gr_complex k, size_t vlen)
+ : gr_sync_block ("multiply_const_cc",
+ gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof (gr_complex)*vlen)),
+ d_k(k), d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ multiply_const_cc_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];
+ gr_complex *out = (gr_complex *) output_items[0];
+ int noi = d_vlen*noutput_items;
+
+ if(is_unaligned()) {
+ volk_32fc_s32fc_multiply_32fc_u(out, in, d_k, noi);
+ }
+ else {
+ volk_32fc_s32fc_multiply_32fc_a(out, in, d_k, noi);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_const_cc_impl.h b/gr-blocks/lib/multiply_const_cc_impl.h
new file mode 100644
index 000000000..81c8cc6da
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_cc_impl.h
@@ -0,0 +1,52 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef INCLUDED_MULTIPLY_CONST_CC_IMPL_H
+#define INCLUDED_MULTIPLY_CONST_CC_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_const_cc_impl : public multiply_const_cc
+ {
+ gr_complex d_k;
+ size_t d_vlen;
+
+ public:
+ multiply_const_cc_impl(gr_complex k, size_t vlen);
+
+ gr_complex k() const { return d_k; }
+ void set_k(gr_complex k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_CONST_CC_IMPL_H */
diff --git a/gr-blocks/lib/multiply_const_ff_impl.cc b/gr-blocks/lib/multiply_const_ff_impl.cc
new file mode 100644
index 000000000..e9cd34797
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_ff_impl.cc
@@ -0,0 +1,72 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ multiply_const_ff::sptr multiply_const_ff::make(float k, size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new multiply_const_ff_impl(k, vlen));
+ }
+
+ multiply_const_ff_impl::multiply_const_ff_impl(float k, size_t vlen)
+ : gr_sync_block ("multiply_const_ff",
+ gr_make_io_signature (1, 1, sizeof (float)*vlen),
+ gr_make_io_signature (1, 1, sizeof (float)*vlen)),
+ d_k(k), d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ multiply_const_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *) input_items[0];
+ float *out = (float *) output_items[0];
+ int noi = d_vlen*noutput_items;
+
+ if(is_unaligned()) {
+ volk_32f_s32f_multiply_32f_u(out, in, d_k, noi);
+ }
+ else {
+ volk_32f_s32f_multiply_32f_a(out, in, d_k, noi);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_const_ff_impl.h b/gr-blocks/lib/multiply_const_ff_impl.h
new file mode 100644
index 000000000..e63a3279a
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_ff_impl.h
@@ -0,0 +1,52 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef INCLUDED_MULTIPLY_CONST_FF_IMPL_H
+#define INCLUDED_MULTIPLY_CONST_FF_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_const_ff_impl : public multiply_const_ff
+ {
+ float d_k;
+ size_t d_vlen;
+
+ public:
+ multiply_const_ff_impl(float k, size_t vlen);
+
+ float k() const { return d_k; }
+ void set_k(float k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_MULTIPLY_CONST_FF_IMPL_H */
diff --git a/gr-blocks/lib/multiply_const_vXX_impl.cc.t b/gr-blocks/lib/multiply_const_vXX_impl.cc.t
new file mode 100644
index 000000000..dd20f2893
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_vXX_impl.cc.t
@@ -0,0 +1,66 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(std::vector<@O_TYPE@> k)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(k));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(std::vector<@O_TYPE@> k)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)*k.size()),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*k.size())),
+ d_k(k)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@ *)input_items[0];
+ @O_TYPE@ *optr = (@O_TYPE@ *)output_items[0];
+
+ int nitems_per_block = output_signature()->sizeof_stream_item(0)/sizeof(@I_TYPE@);
+
+ for (int i = 0; i < noutput_items; i++)
+ for (int j = 0; j < nitems_per_block; j++)
+ *optr++ = *iptr++ * d_k[j];
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/multiply_const_vXX_impl.h.t b/gr-blocks/lib/multiply_const_vXX_impl.h.t
new file mode 100644
index 000000000..a7a619725
--- /dev/null
+++ b/gr-blocks/lib/multiply_const_vXX_impl.h.t
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2006,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ std::vector<@O_TYPE@> d_k;
+
+ public:
+ @NAME_IMPL@(std::vector<@O_TYPE@> k);
+
+ std::vector<@O_TYPE@> k() const { return d_k; }
+ void set_k(std::vector<@O_TYPE@> k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/__init__.py b/gr-blocks/python/__init__.py
index c786d3a22..6577d933e 100644
--- a/gr-blocks/python/__init__.py
+++ b/gr-blocks/python/__init__.py
@@ -26,3 +26,12 @@ processing blocks common to many flowgraphs.
from blocks_swig import *
+#alias old gr_add_vXX and gr_multiply_vXX
+add_vcc = add_cc
+add_vff = add_ff
+add_vii = add_ii
+add_vss = add_ss
+multiply_vcc = multiply_cc
+multiply_vff = multiply_ff
+multiply_vii = multiply_ii
+multiply_vss = multiply_ss
diff --git a/gr-blocks/python/qa_add_and_friends.py b/gr-blocks/python/qa_add_and_friends.py
deleted file mode 100755
index 0c8a91ce9..000000000
--- a/gr-blocks/python/qa_add_and_friends.py
+++ /dev/null
@@ -1,194 +0,0 @@
-#!/usr/bin/env python
-#
-# Copyright 2004,2007,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
-
-class test_add_and_friends(gr_unittest.TestCase):
-
- def setUp(self):
- self.tb = gr.top_block()
-
- def tearDown(self):
- self.tb = None
-
- def help_ii(self, src_data, exp_data, op):
- for s in zip(range(len(src_data)), src_data):
- src = gr.vector_source_i(s[1])
- self.tb.connect(src, (op, s[0]))
- dst = gr.vector_sink_i()
- self.tb.connect(op, dst)
- self.tb.run()
- result_data = dst.data()
- self.assertEqual(exp_data, result_data)
-
- def help_ss(self, src_data, exp_data, op):
- for s in zip(range(len(src_data)), src_data):
- src = gr.vector_source_s(s[1])
- self.tb.connect(src, (op, s[0]))
- dst = gr.vector_sink_s()
- self.tb.connect(op, dst)
- self.tb.run()
- result_data = dst.data()
- self.assertEqual(exp_data, result_data)
-
- def help_ff(self, src_data, exp_data, op):
- for s in zip(range(len(src_data)), src_data):
- src = gr.vector_source_f(s[1])
- self.tb.connect(src, (op, s[0]))
- dst = gr.vector_sink_f()
- self.tb.connect(op, dst)
- self.tb.run()
- result_data = dst.data()
- self.assertEqual(exp_data, result_data)
-
- def help_cc(self, src_data, exp_data, op):
- for s in zip(range(len(src_data)), src_data):
- src = gr.vector_source_c(s[1])
- self.tb.connect(src, (op, s[0]))
- dst = gr.vector_sink_c()
- self.tb.connect(op, dst)
- self.tb.run()
- result_data = dst.data()
- self.assertEqual(exp_data, result_data)
-
- def test_add_ff(self):
- src1_data = (1.0, 2.0, 3.0, 4.0, 5.0)
- src2_data = (8.0, -3.0, 4.0, 8.0, 2.0)
- expected_result = (9.0, -1.0, 7.0, 12.0, 7.0)
- op = blocks_swig.add_ff()
- self.help_ff((src1_data, src2_data), expected_result, op)
-
- def test_add_ss(self):
- src1_data = (1, 2, 3, 4, 5)
- src2_data = (8, -3, 4, 8, 2)
- expected_result = (9, -1, 7, 12, 7)
- op = blocks_swig.add_ss()
- self.help_ss((src1_data, src2_data), expected_result, op)
-
- def test_add_ii(self):
- src1_data = (1, 2, 3, 4, 5)
- src2_data = (8, -3, 4, 8, 2)
- expected_result = (9, -1, 7, 12, 7)
- op = blocks_swig.add_ii()
- self.help_ii((src1_data, src2_data), expected_result, op)
-
- def test_add_cc(self):
- src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
- src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j)
- expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j)
- op = blocks_swig.add_cc()
- self.help_cc((src1_data, src2_data), expected_result, op)
-
- def test_add_const_ii(self):
- src_data = (1, 2, 3, 4, 5)
- expected_result = (6, 7, 8, 9, 10)
- op = blocks_swig.add_const_ii(5)
- self.help_ii((src_data,), expected_result, op)
-
- def test_add_const_cc(self):
- src_data = (1, 2, 3, 4, 5)
- expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
- op = blocks_swig.add_const_cc(5j)
- self.help_cc((src_data,), expected_result, op)
- """
- def test_mult_const_ii(self):
- src_data = (-1, 0, 1, 2, 3)
- expected_result = (-5, 0, 5, 10, 15)
- op = gr.multiply_const_ii(5)
- self.help_ii((src_data,), expected_result, op)
-
- def test_mult_const_ff(self):
- src_data = (-1, 0, 1, 2, 3)
- expected_result = (-5, 0, 5, 10, 15)
- op = gr.multiply_const_cc(5)
- self.help_cc((src_data,), expected_result, op)
-
- def test_mult_const_cc(self):
- src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
- expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j)
- op = gr.multiply_const_cc(5)
- self.help_cc((src_data,), expected_result, op)
-
- def test_mult_const_cc2(self):
- src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
- expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j)
- op = gr.multiply_const_cc(5+2j)
- self.help_cc((src_data,), expected_result, op)
- """
- def test_mult_ii(self):
- src1_data = (1, 2, 3, 4, 5)
- src2_data = (8, -3, 4, 8, 2)
- expected_result = (8, -6, 12, 32, 10)
- op = blocks_swig.multiply_ii()
- self.help_ii((src1_data, src2_data),
- expected_result, op)
-
- def test_mult_ff(self):
- src1_data = (1, 2, 3, 4, 5)
- src2_data = (8, -3, 4, 8, 2)
- expected_result = (8, -6, 12, 32, 10)
- op = blocks_swig.multiply_ff()
- self.help_ff((src1_data, src2_data),
- expected_result, op)
-
- def test_mult_cc(self):
- src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
- src2_data = (8, -3, 4, 8, 2)
- expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j)
- op = blocks_swig.multiply_cc()
- self.help_cc((src1_data, src2_data),
- expected_result, op)
- """
- def test_sub_ii_1(self):
- src1_data = (1, 2, 3, 4, 5)
- expected_result = (-1, -2, -3, -4, -5)
- op = gr.sub_ii()
- self.help_ii((src1_data,),
- expected_result, op)
-
- def test_sub_ii_2(self):
- src1_data = (1, 2, 3, 4, 5)
- src2_data = (8, -3, 4, 8, 2)
- expected_result = (-7, 5, -1, -4, 3)
- op = gr.sub_ii()
- self.help_ii((src1_data, src2_data),
- expected_result, op)
-
- def test_div_ff_1(self):
- src1_data = (1, 2, 4, -8)
- expected_result = (1, 0.5, 0.25, -.125)
- op = gr.divide_ff()
- self.help_ff((src1_data,),
- expected_result, op)
-
- def test_div_ff_2(self):
- src1_data = ( 5, 9, -15, 1024)
- src2_data = (10, 3, -5, 64)
- expected_result = (0.5, 3, 3, 16)
- op = gr.divide_ff()
- self.help_ff((src1_data, src2_data),
- expected_result, op)
- """
-
-if __name__ == '__main__':
- gr_unittest.run(test_add_and_friends, "test_add_and_friends.xml")
diff --git a/gr-blocks/python/qa_add_mult_div_sub.py b/gr-blocks/python/qa_add_mult_div_sub.py
new file mode 100755
index 000000000..05a3b2384
--- /dev/null
+++ b/gr-blocks/python/qa_add_mult_div_sub.py
@@ -0,0 +1,230 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,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
+
+class test_add_mult_div_sub(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def help_ii(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_i(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_i()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_ss(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_s(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_s()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_ff(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_f(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_f()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_cc(self, src_data, exp_data, op):
+ for s in zip(range(len(src_data)), src_data):
+ src = gr.vector_source_c(s[1])
+ self.tb.connect(src, (op, s[0]))
+ dst = gr.vector_sink_c()
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ # add_XX
+
+ def test_add_ss(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (9, -1, 7, 12, 7)
+ op = blocks_swig.add_ss()
+ self.help_ss((src1_data, src2_data), expected_result, op)
+
+ def test_add_ii(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (9, -1, 7, 12, 7)
+ op = blocks_swig.add_ii()
+ self.help_ii((src1_data, src2_data), expected_result, op)
+
+ def test_add_ff(self):
+ src1_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src2_data = (8.0, -3.0, 4.0, 8.0, 2.0)
+ expected_result = (9.0, -1.0, 7.0, 12.0, 7.0)
+ op = blocks_swig.add_ff()
+ self.help_ff((src1_data, src2_data), expected_result, op)
+
+ def test_add_cc(self):
+ src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
+ src2_data = (8+8j, -3-3j, 4+4j, 8+8j, 2+2j)
+ expected_result = (9+9j, -1-1j, 7+7j, 12+12j, 7+7j)
+ op = blocks_swig.add_cc()
+ self.help_cc((src1_data, src2_data), expected_result, op)
+
+ # add_const_XX
+
+ def test_add_const_ss(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_result = (6, 7, 8, 9, 10)
+ op = blocks_swig.add_const_ss(5)
+ self.help_ss((src_data,), expected_result, op)
+
+ def test_add_const_ii(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_result = (6, 7, 8, 9, 10)
+ op = blocks_swig.add_const_ii(5)
+ self.help_ii((src_data,), expected_result, op)
+
+ def test_add_const_ff(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_result = (6, 7, 8, 9, 10)
+ op = blocks_swig.add_const_ff(5)
+ self.help_ff((src_data,), expected_result, op)
+
+ def test_add_const_cc(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_result = (1+5j, 2+5j, 3+5j, 4+5j, 5+5j)
+ op = blocks_swig.add_const_cc(5j)
+ self.help_cc((src_data,), expected_result, op)
+
+ # multiply_XX
+
+ def test_multiply_ss(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8, -6, 12, 32, 10)
+ op = blocks_swig.multiply_ss()
+ self.help_ss((src1_data, src2_data),
+ expected_result, op)
+
+ def test_multiply_ii(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8, -6, 12, 32, 10)
+ op = blocks_swig.multiply_ii()
+ self.help_ii((src1_data, src2_data),
+ expected_result, op)
+
+ def test_multiply_ff(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8, -6, 12, 32, 10)
+ op = blocks_swig.multiply_ff()
+ self.help_ff((src1_data, src2_data),
+ expected_result, op)
+
+ def test_multiply_cc(self):
+ src1_data = (1+1j, 2+2j, 3+3j, 4+4j, 5+5j)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (8+8j, -6-6j, 12+12j, 32+32j, 10+10j)
+ op = blocks_swig.multiply_cc()
+ self.help_cc((src1_data, src2_data),
+ expected_result, op)
+
+ # multiply_const_XX
+
+ def test_multiply_const_ss(self):
+ src_data = (-1, 0, 1, 2, 3)
+ expected_result = (-5, 0, 5, 10, 15)
+ op = gr.multiply_const_ss(5)
+ self.help_ss((src_data,), expected_result, op)
+
+ def test_multiply_const_ii(self):
+ src_data = (-1, 0, 1, 2, 3)
+ expected_result = (-5, 0, 5, 10, 15)
+ op = gr.multiply_const_ii(5)
+ self.help_ii((src_data,), expected_result, op)
+
+ def test_multiply_const_ff(self):
+ src_data = (-1, 0, 1, 2, 3)
+ expected_result = (-5, 0, 5, 10, 15)
+ op = gr.multiply_const_ff(5)
+ self.help_ff((src_data,), expected_result, op)
+
+ def test_multiply_const_cc(self):
+ src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
+ expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j)
+ op = gr.multiply_const_cc(5)
+ self.help_cc((src_data,), expected_result, op)
+
+ def test_multiply_const_cc2(self):
+ src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
+ expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j)
+ op = gr.multiply_const_cc(5+2j)
+ self.help_cc((src_data,), expected_result, op)
+
+
+ """
+ def test_sub_ii_1(self):
+ src1_data = (1, 2, 3, 4, 5)
+ expected_result = (-1, -2, -3, -4, -5)
+ op = gr.sub_ii()
+ self.help_ii((src1_data,),
+ expected_result, op)
+
+ def test_sub_ii_2(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (8, -3, 4, 8, 2)
+ expected_result = (-7, 5, -1, -4, 3)
+ op = gr.sub_ii()
+ self.help_ii((src1_data, src2_data),
+ expected_result, op)
+
+ def test_div_ff_1(self):
+ src1_data = (1, 2, 4, -8)
+ expected_result = (1, 0.5, 0.25, -.125)
+ op = gr.divide_ff()
+ self.help_ff((src1_data,),
+ expected_result, op)
+
+ def test_div_ff_2(self):
+ src1_data = ( 5, 9, -15, 1024)
+ src2_data = (10, 3, -5, 64)
+ expected_result = (0.5, 3, 3, 16)
+ op = gr.divide_ff()
+ self.help_ff((src1_data, src2_data),
+ expected_result, op)
+ """
+
+if __name__ == '__main__':
+ gr_unittest.run(test_add_mult_div_sub, "test_add_mult_div_sub.xml")
diff --git a/gr-blocks/python/qa_add_mult_v.py b/gr-blocks/python/qa_add_mult_v.py
new file mode 100755
index 000000000..d362cb885
--- /dev/null
+++ b/gr-blocks/python/qa_add_mult_v.py
@@ -0,0 +1,360 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,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
+
+class test_add_mult_v(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def help_ss(self, size, src_data, exp_data, op):
+ for s in zip(range (len (src_data)), src_data):
+ src = gr.vector_source_s(s[1])
+ srcv = gr.stream_to_vector(gr.sizeof_short, size)
+ self.tb.connect(src, srcv)
+ self.tb.connect(srcv, (op, s[0]))
+ rhs = gr.vector_to_stream(gr.sizeof_short, size)
+ dst = gr.vector_sink_s()
+ self.tb.connect(op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_ii(self, size, src_data, exp_data, op):
+ for s in zip(range (len (src_data)), src_data):
+ src = gr.vector_source_i(s[1])
+ srcv = gr.stream_to_vector(gr.sizeof_int, size)
+ self.tb.connect(src, srcv)
+ self.tb.connect(srcv, (op, s[0]))
+ rhs = gr.vector_to_stream(gr.sizeof_int, size)
+ dst = gr.vector_sink_i()
+ self.tb.connect(op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_ff(self, size, src_data, exp_data, op):
+ for s in zip(range (len (src_data)), src_data):
+ src = gr.vector_source_f(s[1])
+ srcv = gr.stream_to_vector(gr.sizeof_float, size)
+ self.tb.connect(src, srcv)
+ self.tb.connect(srcv, (op, s[0]))
+ rhs = gr.vector_to_stream(gr.sizeof_float, size)
+ dst = gr.vector_sink_f()
+ self.tb.connect(op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_cc(self, size, src_data, exp_data, op):
+ for s in zip(range (len (src_data)), src_data):
+ src = gr.vector_source_c(s[1])
+ srcv = gr.stream_to_vector(gr.sizeof_gr_complex, size)
+ self.tb.connect(src, srcv)
+ self.tb.connect(srcv, (op, s[0]))
+ rhs = gr.vector_to_stream(gr.sizeof_gr_complex, size)
+ dst = gr.vector_sink_c()
+ self.tb.connect(op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_const_ss(self, src_data, exp_data, op):
+ src = gr.vector_source_s(src_data)
+ srcv = gr.stream_to_vector(gr.sizeof_short, len(src_data))
+ rhs = gr.vector_to_stream(gr.sizeof_short, len(src_data))
+ dst = gr.vector_sink_s()
+ self.tb.connect(src, srcv, op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_const_ii(self, src_data, exp_data, op):
+ src = gr.vector_source_i(src_data)
+ srcv = gr.stream_to_vector(gr.sizeof_int, len(src_data))
+ rhs = gr.vector_to_stream(gr.sizeof_int, len(src_data))
+ dst = gr.vector_sink_i()
+ self.tb.connect(src, srcv, op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_const_ff(self, src_data, exp_data, op):
+ src = gr.vector_source_f(src_data)
+ srcv = gr.stream_to_vector(gr.sizeof_float, len(src_data))
+ rhs = gr.vector_to_stream(gr.sizeof_float, len(src_data))
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, srcv, op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ def help_const_cc(self, src_data, exp_data, op):
+ src = gr.vector_source_c(src_data)
+ srcv = gr.stream_to_vector(gr.sizeof_gr_complex, len(src_data))
+ rhs = gr.vector_to_stream(gr.sizeof_gr_complex, len(src_data))
+ dst = gr.vector_sink_c()
+ self.tb.connect(src, srcv, op, rhs, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertEqual(exp_data, result_data)
+
+ # add_vXX
+
+ def test_add_vss_one(self):
+ src1_data = (1,)
+ src2_data = (2,)
+ src3_data = (3,)
+ expected_result = (6,)
+ op = blocks_swig.add_ss(1)
+ self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vss_five(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (6, 7, 8, 9, 10)
+ src3_data = (11, 12, 13, 14, 15)
+ expected_result = (18, 21, 24, 27, 30)
+ op = blocks_swig.add_ss(5)
+ self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vii_one(self):
+ src1_data = (1,)
+ src2_data = (2,)
+ src3_data = (3,)
+ expected_result = (6,)
+ op = blocks_swig.add_ii(1)
+ self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vii_five(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (6, 7, 8, 9, 10)
+ src3_data = (11, 12, 13, 14, 15)
+ expected_result = (18, 21, 24, 27, 30)
+ op = blocks_swig.add_ii(5)
+ self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vff_one(self):
+ src1_data = (1.0,)
+ src2_data = (2.0,)
+ src3_data = (3.0,)
+ expected_result = (6.0,)
+ op = blocks_swig.add_ff(1)
+ self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vff_five(self):
+ src1_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src2_data = (6.0, 7.0, 8.0, 9.0, 10.0)
+ src3_data = (11.0, 12.0, 13.0, 14.0, 15.0)
+ expected_result = (18.0, 21.0, 24.0, 27.0, 30.0)
+ op = blocks_swig.add_ff(5)
+ self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vcc_one(self):
+ src1_data = (1.0+2.0j,)
+ src2_data = (3.0+4.0j,)
+ src3_data = (5.0+6.0j,)
+ expected_result = (9.0+12j,)
+ op = blocks_swig.add_cc(1)
+ self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_add_vcc_five(self):
+ src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j)
+ src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)
+ src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j)
+ expected_result = (33.0+36.0j, 39.0+42.0j, 45.0+48.0j, 51.0+54.0j, 57.0+60.0j)
+ op = blocks_swig.add_cc(5)
+ self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ # add_const_vXX
+
+ def test_add_const_vss_one(self):
+ src_data = (1,)
+ op = blocks_swig.add_const_vss((2,))
+ exp_data = (3,)
+ self.help_const_ss(src_data, exp_data, op)
+
+ def test_add_const_vss_five(self):
+ src_data = (1, 2, 3, 4, 5)
+ op = blocks_swig.add_const_vss((6, 7, 8, 9, 10))
+ exp_data = (7, 9, 11, 13, 15)
+ self.help_const_ss(src_data, exp_data, op)
+
+ def test_add_const_vii_one(self):
+ src_data = (1,)
+ op = blocks_swig.add_const_vii((2,))
+ exp_data = (3,)
+ self.help_const_ii(src_data, exp_data, op)
+
+ def test_add_const_vii_five(self):
+ src_data = (1, 2, 3, 4, 5)
+ op = blocks_swig.add_const_vii((6, 7, 8, 9, 10))
+ exp_data = (7, 9, 11, 13, 15)
+ self.help_const_ii(src_data, exp_data, op)
+
+ def test_add_const_vff_one(self):
+ src_data = (1.0,)
+ op = blocks_swig.add_const_vff((2.0,))
+ exp_data = (3.0,)
+ self.help_const_ff(src_data, exp_data, op)
+
+ def test_add_const_vff_five(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ op = blocks_swig.add_const_vff((6.0, 7.0, 8.0, 9.0, 10.0))
+ exp_data = (7.0, 9.0, 11.0, 13.0, 15.0)
+ self.help_const_ff(src_data, exp_data, op)
+
+ def test_add_const_vcc_one(self):
+ src_data = (1.0+2.0j,)
+ op = blocks_swig.add_const_vcc((2.0+3.0j,))
+ exp_data = (3.0+5.0j,)
+ self.help_const_cc(src_data, exp_data, op)
+
+ def test_add_const_vcc_five(self):
+ src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j)
+ op = blocks_swig.add_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j))
+ exp_data = (12.0+14.0j, 16.0+18.0j, 20.0+22.0j, 24.0+26.0j, 28.0+30.0j)
+ self.help_const_cc(src_data, exp_data, op)
+
+ # multiply_vXX
+
+ def test_multiply_vss_one(self):
+ src1_data = (1,)
+ src2_data = (2,)
+ src3_data = (3,)
+ expected_result = (6,)
+ op = gr.multiply_vss(1)
+ self.help_ss(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vss_five(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (6, 7, 8, 9, 10)
+ src3_data = (11, 12, 13, 14, 15)
+ expected_result = (66, 168, 312, 504, 750)
+ op = gr.multiply_vss(5)
+ self.help_ss(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vii_one(self):
+ src1_data = (1,)
+ src2_data = (2,)
+ src3_data = (3,)
+ expected_result = (6,)
+ op = gr.multiply_vii(1)
+ self.help_ii(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vii_five(self):
+ src1_data = (1, 2, 3, 4, 5)
+ src2_data = (6, 7, 8, 9, 10)
+ src3_data = (11, 12, 13, 14, 15)
+ expected_result = (66, 168, 312, 504, 750)
+ op = gr.multiply_vii(5)
+ self.help_ii(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vff_one(self):
+ src1_data = (1.0,)
+ src2_data = (2.0,)
+ src3_data = (3.0,)
+ expected_result = (6.0,)
+ op = gr.multiply_vff(1)
+ self.help_ff(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vff_five(self):
+ src1_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src2_data = (6.0, 7.0, 8.0, 9.0, 10.0)
+ src3_data = (11.0, 12.0, 13.0, 14.0, 15.0)
+ expected_result = (66.0, 168.0, 312.0, 504.0, 750.0)
+ op = gr.multiply_vff(5)
+ self.help_ff(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vcc_one(self):
+ src1_data = (1.0+2.0j,)
+ src2_data = (3.0+4.0j,)
+ src3_data = (5.0+6.0j,)
+ expected_result = (-85+20j,)
+ op = gr.multiply_vcc(1)
+ self.help_cc(1, (src1_data, src2_data, src3_data), expected_result, op)
+
+ def test_multiply_vcc_five(self):
+ src1_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j)
+ src2_data = (11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j)
+ src3_data = (21.0+22.0j, 23.0+24.0j, 25.0+26.0j, 27.0+28.0j, 29.0+30.0j)
+ expected_result = (-1021.0+428.0j, -2647.0+1754.0j, -4945.0+3704.0j, -8011.0+6374.0j, -11941.0+9860.0j)
+ op = gr.multiply_vcc(5)
+ self.help_cc(5, (src1_data, src2_data, src3_data), expected_result, op)
+
+ # multiply_const_vXX
+
+ def test_multiply_const_vss_one(self):
+ src_data = (2,)
+ op = gr.multiply_const_vss((3,))
+ exp_data = (6,)
+ self.help_const_ss(src_data, exp_data, op)
+
+ def test_multiply_const_vss_five(self):
+ src_data = (1, 2, 3, 4, 5)
+ op = gr.multiply_const_vss((6, 7, 8, 9, 10))
+ exp_data = (6, 14, 24, 36, 50)
+ self.help_const_ss(src_data, exp_data, op)
+
+ def test_multiply_const_vii_one(self):
+ src_data = (2,)
+ op = gr.multiply_const_vii((3,))
+ exp_data = (6,)
+ self.help_const_ii(src_data, exp_data, op)
+
+ def test_multiply_const_vii_five(self):
+ src_data = (1, 2, 3, 4, 5)
+ op = gr.multiply_const_vii((6, 7, 8, 9, 10))
+ exp_data = (6, 14, 24, 36, 50)
+ self.help_const_ii(src_data, exp_data, op)
+
+ def test_multiply_const_vff_one(self):
+ src_data = (2.0,)
+ op = gr.multiply_const_vff((3.0,))
+ exp_data = (6.0,)
+ self.help_const_ff(src_data, exp_data, op)
+
+ def test_multiply_const_vff_five(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ op = gr.multiply_const_vff((6.0, 7.0, 8.0, 9.0, 10.0))
+ exp_data = (6.0, 14.0, 24.0, 36.0, 50.0)
+ self.help_const_ff(src_data, exp_data, op)
+
+ def test_multiply_const_vcc_one(self):
+ src_data = (1.0+2.0j,)
+ op = gr.multiply_const_vcc((2.0+3.0j,))
+ exp_data = (-4.0+7.0j,)
+ self.help_const_cc(src_data, exp_data, op)
+
+ def test_multiply_const_vcc_five(self):
+ src_data = (1.0+2.0j, 3.0+4.0j, 5.0+6.0j, 7.0+8.0j, 9.0+10.0j)
+ op = gr.multiply_const_vcc((11.0+12.0j, 13.0+14.0j, 15.0+16.0j, 17.0+18.0j, 19.0+20.0j))
+ exp_data = (-13.0+34.0j, -17.0+94.0j, -21.0+170.0j, -25.0+262.0j, -29.0+370.0j)
+ self.help_const_cc(src_data, exp_data, op)
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_add_mult_v, "test_add_mult_v.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index dc87f4f12..2cfcaaa43 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -36,10 +36,22 @@
#include "blocks/add_const_ss.h"
#include "blocks/add_const_ii.h"
#include "blocks/add_const_cc.h"
+#include "blocks/add_const_vff.h"
+#include "blocks/add_const_vss.h"
+#include "blocks/add_const_vii.h"
+#include "blocks/add_const_vcc.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
#include "blocks/multiply_cc.h"
+#include "blocks/multiply_const_ss.h"
+#include "blocks/multiply_const_ii.h"
+#include "blocks/multiply_const_ff.h"
+#include "blocks/multiply_const_cc.h"
+#include "blocks/multiply_const_vss.h"
+#include "blocks/multiply_const_vii.h"
+#include "blocks/multiply_const_vff.h"
+#include "blocks/multiply_const_vcc.h"
%}
%include "blocks/add_ff.h"
@@ -50,10 +62,22 @@
%include "blocks/add_const_ss.h"
%include "blocks/add_const_ii.h"
%include "blocks/add_const_cc.h"
+%include "blocks/add_const_vff.h"
+%include "blocks/add_const_vss.h"
+%include "blocks/add_const_vii.h"
+%include "blocks/add_const_vcc.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
%include "blocks/multiply_cc.h"
+%include "blocks/multiply_const_ss.h"
+%include "blocks/multiply_const_ii.h"
+%include "blocks/multiply_const_ff.h"
+%include "blocks/multiply_const_cc.h"
+%include "blocks/multiply_const_vss.h"
+%include "blocks/multiply_const_vii.h"
+%include "blocks/multiply_const_vff.h"
+%include "blocks/multiply_const_vcc.h"
GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
@@ -63,7 +87,19 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vff);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vii);
+GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_cc);
+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);
--
cgit
From 24962cd24c623c6822733fed4c911a4adabbdd57 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Mon, 18 Jun 2012 12:28:48 -0700
Subject: blocks: added div_XX and sub_XX blocks
---
gr-blocks/grc/blocks_block_tree.xml | 2 +
gr-blocks/grc/blocks_divide_XX.xml | 63 ++++++++++++++++++++++++++++++
gr-blocks/grc/blocks_sub_xx.xml | 63 ++++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 2 +
gr-blocks/include/blocks/divide_XX.h.t | 53 +++++++++++++++++++++++++
gr-blocks/include/blocks/sub_XX.h.t | 53 +++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 2 +
gr-blocks/lib/divide_XX_impl.cc.t | 69 +++++++++++++++++++++++++++++++++
gr-blocks/lib/divide_XX_impl.h.t | 48 +++++++++++++++++++++++
gr-blocks/lib/sub_XX_impl.cc.t | 69 +++++++++++++++++++++++++++++++++
gr-blocks/lib/sub_XX_impl.h.t | 48 +++++++++++++++++++++++
gr-blocks/python/qa_add_mult_div_sub.py | 38 +++++-------------
gr-blocks/swig/blocks_swig.i | 24 ++++++++++++
13 files changed, 506 insertions(+), 28 deletions(-)
create mode 100644 gr-blocks/grc/blocks_divide_XX.xml
create mode 100644 gr-blocks/grc/blocks_sub_xx.xml
create mode 100644 gr-blocks/include/blocks/divide_XX.h.t
create mode 100644 gr-blocks/include/blocks/sub_XX.h.t
create mode 100644 gr-blocks/lib/divide_XX_impl.cc.t
create mode 100644 gr-blocks/lib/divide_XX_impl.h.t
create mode 100644 gr-blocks/lib/sub_XX_impl.cc.t
create mode 100644 gr-blocks/lib/sub_XX_impl.h.t
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index c0ce7ec7a..b1680497b 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -32,7 +32,9 @@
Math Operationsblocks_add_xxblocks_add_const_vxx
+ blocks_divide_xxblocks_multiply_xxblocks_multiply_const_vxx
+ blocks_sub_xx
diff --git a/gr-blocks/grc/blocks_divide_XX.xml b/gr-blocks/grc/blocks_divide_XX.xml
new file mode 100644
index 000000000..d784d305d
--- /dev/null
+++ b/gr-blocks/grc/blocks_divide_XX.xml
@@ -0,0 +1,63 @@
+
+
+
+ Divide
+ blocks_divide_xx
+ from gnuradio import blocks
+ blocks.divide_$(type.fcn)($vlen)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+ $vlen > 0
+ $num_inputs >= 2
+
+ in
+ $type
+ $vlen
+ $num_inputs
+
+
+
diff --git a/gr-blocks/grc/blocks_sub_xx.xml b/gr-blocks/grc/blocks_sub_xx.xml
new file mode 100644
index 000000000..ae01cf74a
--- /dev/null
+++ b/gr-blocks/grc/blocks_sub_xx.xml
@@ -0,0 +1,63 @@
+
+
+
+ Subtract
+ blocks_sub_xx
+ from gnuradio import blocks
+ blocks.sub_$(type.fcn)($vlen)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+ $vlen > 0
+ $num_inputs >= 2
+
+ in
+ $type
+ $vlen
+ $num_inputs
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 79761e496..c54e10fac 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -67,9 +67,11 @@ endmacro(expand_h)
expand_h(add_XX ss ii cc)
expand_h(add_const_XX ss ii ff cc)
expand_h(add_const_vXX ss ii ff cc)
+expand_h(divide_XX ss ii ff cc)
expand_h(multiply_XX ss ii)
expand_h(multiply_const_XX ss ii)
expand_h(multiply_const_vXX ss ii ff cc)
+expand_h(sub_XX ss ii ff cc)
add_custom_target(blocks_generated_includes DEPENDS
${generated_includes}
diff --git a/gr-blocks/include/blocks/divide_XX.h.t b/gr-blocks/include/blocks/divide_XX.h.t
new file mode 100644
index 000000000..9a382e4a0
--- /dev/null
+++ b/gr-blocks/include/blocks/divide_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input_0 / input_1 / input_x ...)
+ * \ingroup math_blk
+ *
+ * Divide across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/include/blocks/sub_XX.h.t b/gr-blocks/include/blocks/sub_XX.h.t
new file mode 100644
index 000000000..8202ac54b
--- /dev/null
+++ b/gr-blocks/include/blocks/sub_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input_0 - input_1 - ...)
+ * \ingroup math_blk
+ *
+ * Subtract across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 8f433182c..6cdfdd03c 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -88,9 +88,11 @@ endmacro(expand_cc_h_impl)
expand_cc_h_impl(add_XX ss ii cc)
expand_cc_h_impl(add_const_XX ss ii ff cc)
expand_cc_h_impl(add_const_vXX ss ii ff cc)
+expand_cc_h_impl(divide_XX ss ii ff cc)
expand_cc_h_impl(multiply_XX ss ii)
expand_cc_h_impl(multiply_const_XX ss ii)
expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
+expand_cc_h_impl(sub_XX ss ii ff cc)
########################################################################
# Setup the include and linker paths
diff --git a/gr-blocks/lib/divide_XX_impl.cc.t b/gr-blocks/lib/divide_XX_impl.cc.t
new file mode 100644
index 000000000..223d6ad90
--- /dev/null
+++ b/gr-blocks/lib/divide_XX_impl.cc.t
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc /= ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/divide_XX_impl.h.t b/gr-blocks/lib/divide_XX_impl.h.t
new file mode 100644
index 000000000..a1c486b85
--- /dev/null
+++ b/gr-blocks/lib/divide_XX_impl.h.t
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/lib/sub_XX_impl.cc.t b/gr-blocks/lib/sub_XX_impl.cc.t
new file mode 100644
index 000000000..35ae31452
--- /dev/null
+++ b/gr-blocks/lib/sub_XX_impl.cc.t
@@ -0,0 +1,69 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc -= ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/sub_XX_impl.h.t b/gr-blocks/lib/sub_XX_impl.h.t
new file mode 100644
index 000000000..a1c486b85
--- /dev/null
+++ b/gr-blocks/lib/sub_XX_impl.h.t
@@ -0,0 +1,48 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_add_mult_div_sub.py b/gr-blocks/python/qa_add_mult_div_sub.py
index 05a3b2384..0aca03d3f 100755
--- a/gr-blocks/python/qa_add_mult_div_sub.py
+++ b/gr-blocks/python/qa_add_mult_div_sub.py
@@ -166,65 +166,47 @@ class test_add_mult_div_sub(gr_unittest.TestCase):
def test_multiply_const_ss(self):
src_data = (-1, 0, 1, 2, 3)
expected_result = (-5, 0, 5, 10, 15)
- op = gr.multiply_const_ss(5)
+ op = blocks_swig.multiply_const_ss(5)
self.help_ss((src_data,), expected_result, op)
def test_multiply_const_ii(self):
src_data = (-1, 0, 1, 2, 3)
expected_result = (-5, 0, 5, 10, 15)
- op = gr.multiply_const_ii(5)
+ op = blocks_swig.multiply_const_ii(5)
self.help_ii((src_data,), expected_result, op)
def test_multiply_const_ff(self):
src_data = (-1, 0, 1, 2, 3)
expected_result = (-5, 0, 5, 10, 15)
- op = gr.multiply_const_ff(5)
+ op = blocks_swig.multiply_const_ff(5)
self.help_ff((src_data,), expected_result, op)
def test_multiply_const_cc(self):
src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
expected_result = (-5-5j, 0+0j, 5+5j, 10+10j, 15+15j)
- op = gr.multiply_const_cc(5)
+ op = blocks_swig.multiply_const_cc(5)
self.help_cc((src_data,), expected_result, op)
def test_multiply_const_cc2(self):
src_data = (-1-1j, 0+0j, 1+1j, 2+2j, 3+3j)
expected_result = (-3-7j, 0+0j, 3+7j, 6+14j, 9+21j)
- op = gr.multiply_const_cc(5+2j)
+ op = blocks_swig.multiply_const_cc(5+2j)
self.help_cc((src_data,), expected_result, op)
-
- """
- def test_sub_ii_1(self):
- src1_data = (1, 2, 3, 4, 5)
- expected_result = (-1, -2, -3, -4, -5)
- op = gr.sub_ii()
- self.help_ii((src1_data,),
- expected_result, op)
-
- def test_sub_ii_2(self):
+ def test_sub_ii(self):
src1_data = (1, 2, 3, 4, 5)
src2_data = (8, -3, 4, 8, 2)
expected_result = (-7, 5, -1, -4, 3)
- op = gr.sub_ii()
+ op = blocks_swig.sub_ii()
self.help_ii((src1_data, src2_data),
expected_result, op)
- def test_div_ff_1(self):
- src1_data = (1, 2, 4, -8)
- expected_result = (1, 0.5, 0.25, -.125)
- op = gr.divide_ff()
- self.help_ff((src1_data,),
- expected_result, op)
-
- def test_div_ff_2(self):
+ def test_div_ff(self):
src1_data = ( 5, 9, -15, 1024)
src2_data = (10, 3, -5, 64)
expected_result = (0.5, 3, 3, 16)
- op = gr.divide_ff()
- self.help_ff((src1_data, src2_data),
- expected_result, op)
- """
+ op = blocks_swig.divide_ff()
+ self.help_ff((src1_data, src2_data), expected_result, op)
if __name__ == '__main__':
gr_unittest.run(test_add_mult_div_sub, "test_add_mult_div_sub.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 2cfcaaa43..b0be1ae0d 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -40,6 +40,10 @@
#include "blocks/add_const_vss.h"
#include "blocks/add_const_vii.h"
#include "blocks/add_const_vcc.h"
+#include "blocks/divide_ff.h"
+#include "blocks/divide_ss.h"
+#include "blocks/divide_ii.h"
+#include "blocks/divide_cc.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -52,6 +56,10 @@
#include "blocks/multiply_const_vii.h"
#include "blocks/multiply_const_vff.h"
#include "blocks/multiply_const_vcc.h"
+#include "blocks/sub_ff.h"
+#include "blocks/sub_ss.h"
+#include "blocks/sub_ii.h"
+#include "blocks/sub_cc.h"
%}
%include "blocks/add_ff.h"
@@ -66,6 +74,10 @@
%include "blocks/add_const_vss.h"
%include "blocks/add_const_vii.h"
%include "blocks/add_const_vcc.h"
+%include "blocks/divide_ff.h"
+%include "blocks/divide_ss.h"
+%include "blocks/divide_ii.h"
+%include "blocks/divide_cc.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -78,6 +90,10 @@
%include "blocks/multiply_const_vii.h"
%include "blocks/multiply_const_vff.h"
%include "blocks/multiply_const_vcc.h"
+%include "blocks/sub_ff.h"
+%include "blocks/sub_ss.h"
+%include "blocks/sub_ii.h"
+%include "blocks/sub_cc.h"
GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
@@ -91,6 +107,10 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vii);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc);
+GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, divide_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
@@ -103,3 +123,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, sub_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc);
--
cgit
From 439b427e80ebc767db6e4e732213d89c2a6febd4 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 19 Jun 2012 10:00:28 -0700
Subject: blocks: added gr::blocks::char_to_float
---
gr-blocks/grc/blocks_block_tree.xml | 5 +++
gr-blocks/grc/blocks_char_to_float.xml | 35 +++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/char_to_float.h | 62 ++++++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/char_to_float_impl.cc | 65 ++++++++++++++++++++++++++++++++
gr-blocks/lib/char_to_float_impl.h | 51 +++++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 55 +++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 278 insertions(+)
create mode 100644 gr-blocks/grc/blocks_char_to_float.xml
create mode 100644 gr-blocks/include/blocks/char_to_float.h
create mode 100644 gr-blocks/lib/char_to_float_impl.cc
create mode 100644 gr-blocks/lib/char_to_float_impl.h
create mode 100755 gr-blocks/python/qa_type_conversions.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index b1680497b..ae540d3b1 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -37,4 +37,9 @@
blocks_multiply_const_vxxblocks_sub_xx
+
+ Type Conversions
+ blocks_char_to_float
+
+
diff --git a/gr-blocks/grc/blocks_char_to_float.xml b/gr-blocks/grc/blocks_char_to_float.xml
new file mode 100644
index 000000000..5d367d719
--- /dev/null
+++ b/gr-blocks/grc/blocks_char_to_float.xml
@@ -0,0 +1,35 @@
+
+
+
+ Char To Float
+ blocks_char_to_float
+ from gnuradio import blocks
+ blocks.char_to_float($vlen, $scale)
+ set_scale($scale)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Scale
+ scale
+ 1
+ real
+
+
+ in
+ byte
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index c54e10fac..bfdde9701 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -84,6 +84,7 @@ install(FILES
${generated_includes}
api.h
add_ff.h
+ char_to_float.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/char_to_float.h b/gr-blocks/include/blocks/char_to_float.h
new file mode 100644
index 000000000..92a2dbf80
--- /dev/null
+++ b/gr-blocks/include/blocks/char_to_float.h
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_CHAR_TO_FLOAT_H
+#define INCLUDED_BLOCKS_CHAR_TO_FLOAT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of chars to a stream of float
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ * \param scale a scalar divider to change the output signal scale.
+ */
+ class BLOCKS_API char_to_float : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::char_to_float_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1, float scale=1.0);
+
+ /*!
+ * Get the scalar divider value.
+ */
+ virtual float scale() const = 0;
+
+ /*!
+ * Set the scalar divider value.
+ */
+ virtual void set_scale(float scale) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_CHAR_TO_FLOAT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 6cdfdd03c..a3bb67e4d 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -118,6 +118,7 @@ link_directories(${Boost_LIBRARY_DIRS})
list(APPEND gr_blocks_sources
${generated_sources}
add_ff_impl.cc
+ char_to_float_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/char_to_float_impl.cc b/gr-blocks/lib/char_to_float_impl.cc
new file mode 100644
index 000000000..22c5d2e25
--- /dev/null
+++ b/gr-blocks/lib/char_to_float_impl.cc
@@ -0,0 +1,65 @@
+/* -*- 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 "char_to_float_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ char_to_float::sptr char_to_float::make(size_t vlen, float scale)
+ {
+ return gnuradio::get_initial_sptr(new char_to_float_impl(vlen, scale));
+ }
+
+ char_to_float_impl::char_to_float_impl(size_t vlen, float scale)
+ : gr_sync_block("char_to_float",
+ gr_make_io_signature (1, -1, sizeof(char)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen), d_scale(scale)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ char_to_float_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const int8_t *in = (const int8_t *) input_items[0];
+ float *out = (float *) output_items[0];
+
+ // Note: the unaligned benchmarked much faster than the aligned
+ volk_8i_s32f_convert_32f_u(out, in, d_scale, d_vlen*noutput_items);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/char_to_float_impl.h b/gr-blocks/lib/char_to_float_impl.h
new file mode 100644
index 000000000..620d7e737
--- /dev/null
+++ b/gr-blocks/lib/char_to_float_impl.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_CHAR_TO_FLOAT_IMPL_H
+#define INCLUDED_CHAR_TO_FLOAT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API char_to_float_impl : public char_to_float
+ {
+ size_t d_vlen;
+ float d_scale;
+
+ public:
+ char_to_float_impl(size_t vlen, float scale);
+
+ virtual float scale() const { return d_scale; }
+ virtual void set_scale(float scale) { d_scale = scale; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_CHAR_TO_FLOAT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
new file mode 100755
index 000000000..bc65a2781
--- /dev/null
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig
+
+class test_type_conversions(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_char_to_float_identity(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src = gr.vector_source_b(src_data)
+ op = blocks_swig.char_to_float()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+
+ def test_char_to_float_scale(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (0.5, 1.0, 1.5, 2.0, 2.5)
+ src = gr.vector_source_b(src_data)
+ op = blocks_swig.char_to_float(scale=2.0)
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(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 b0be1ae0d..6eb10a688 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -40,6 +40,7 @@
#include "blocks/add_const_vss.h"
#include "blocks/add_const_vii.h"
#include "blocks/add_const_vcc.h"
+#include "blocks/char_to_float.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -74,6 +75,7 @@
%include "blocks/add_const_vss.h"
%include "blocks/add_const_vii.h"
%include "blocks/add_const_vcc.h"
+%include "blocks/char_to_float.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -107,6 +109,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss);
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, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From 75f11771a9ee4b2854297fdb2c9db5761bde1c45 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 22 Jun 2012 16:58:50 -0700
Subject: blocks: added gr::blocks:char_to_short
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_char_to_short.xml | 28 +++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/char_to_short.h | 51 +++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/char_to_short_impl.cc | 69 ++++++++++++++++++++++++++++++++
gr-blocks/lib/char_to_short_impl.h | 47 ++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 11 +++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 212 insertions(+)
create mode 100644 gr-blocks/grc/blocks_char_to_short.xml
create mode 100644 gr-blocks/include/blocks/char_to_short.h
create mode 100644 gr-blocks/lib/char_to_short_impl.cc
create mode 100644 gr-blocks/lib/char_to_short_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index ae540d3b1..6fe209db9 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -40,6 +40,7 @@
Type Conversionsblocks_char_to_float
+ blocks_char_to_short
diff --git a/gr-blocks/grc/blocks_char_to_short.xml b/gr-blocks/grc/blocks_char_to_short.xml
new file mode 100644
index 000000000..b19fdb46a
--- /dev/null
+++ b/gr-blocks/grc/blocks_char_to_short.xml
@@ -0,0 +1,28 @@
+
+
+
+ Char To Short
+ blocks_char_to_short
+ from gnuradio import blocks
+ blocks.char_to_short($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ in
+ byte
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index bfdde9701..7f29e5a7b 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -85,6 +85,7 @@ install(FILES
api.h
add_ff.h
char_to_float.h
+ char_to_short.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/char_to_short.h b/gr-blocks/include/blocks/char_to_short.h
new file mode 100644
index 000000000..e2bb3a859
--- /dev/null
+++ b/gr-blocks/include/blocks/char_to_short.h
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_CHAR_TO_SHORT_H
+#define INCLUDED_BLOCKS_CHAR_TO_SHORT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of chars to a stream of short
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ */
+ class BLOCKS_API char_to_short : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::char_to_short_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_CHAR_TO_SHORT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index a3bb67e4d..501529dd9 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -119,6 +119,7 @@ list(APPEND gr_blocks_sources
${generated_sources}
add_ff_impl.cc
char_to_float_impl.cc
+ char_to_short_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/char_to_short_impl.cc b/gr-blocks/lib/char_to_short_impl.cc
new file mode 100644
index 000000000..a86a928b5
--- /dev/null
+++ b/gr-blocks/lib/char_to_short_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 "char_to_short_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ char_to_short::sptr char_to_short::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new char_to_short_impl(vlen));
+ }
+
+ char_to_short_impl::char_to_short_impl(size_t vlen)
+ : gr_sync_block("char_to_short",
+ gr_make_io_signature (1, -1, sizeof(char)*vlen),
+ gr_make_io_signature (1, 1, sizeof(short)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(short);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ char_to_short_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const int8_t *in = (const int8_t *) input_items[0];
+ int16_t *out = (int16_t *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_8i_convert_16i_u(out, in, d_vlen*noutput_items);
+ }
+ else {
+ volk_8i_convert_16i_a(out, in, d_vlen*noutput_items);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/char_to_short_impl.h b/gr-blocks/lib/char_to_short_impl.h
new file mode 100644
index 000000000..efd3ab3a8
--- /dev/null
+++ b/gr-blocks/lib/char_to_short_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_CHAR_TO_SHORT_IMPL_H
+#define INCLUDED_CHAR_TO_SHORT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API char_to_short_impl : public char_to_short
+ {
+ size_t d_vlen;
+
+ public:
+ char_to_short_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_CHAR_TO_SHORT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index bc65a2781..ff2e5c609 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -51,5 +51,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+ def test_char_to_short(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (256, 512, 768, 1024, 1280)
+ src = gr.vector_source_b(src_data)
+ op = blocks_swig.char_to_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 6eb10a688..579917014 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -41,6 +41,7 @@
#include "blocks/add_const_vii.h"
#include "blocks/add_const_vcc.h"
#include "blocks/char_to_float.h"
+#include "blocks/char_to_short.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -76,6 +77,7 @@
%include "blocks/add_const_vii.h"
%include "blocks/add_const_vcc.h"
%include "blocks/char_to_float.h"
+%include "blocks/char_to_short.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -110,6 +112,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss);
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, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
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 Conversionsblocks_char_to_floatblocks_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
+
+
+
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
From 6eb1447df04883af78ed78eb8449378e67d67bf6 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 23 Jun 2012 08:12:30 -0700
Subject: blocks: added gr::blocks::complex_to_float
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_complex_to_float.xml | 36 +++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/complex_to_float.h | 50 +++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/complex_to_float_impl.cc | 94 +++++++++++++++++++++++++++++
gr-blocks/lib/complex_to_float_impl.h | 47 +++++++++++++++
gr-blocks/python/qa_type_conversions.py | 26 ++++++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 259 insertions(+)
create mode 100644 gr-blocks/grc/blocks_complex_to_float.xml
create mode 100644 gr-blocks/include/blocks/complex_to_float.h
create mode 100644 gr-blocks/lib/complex_to_float_impl.cc
create mode 100644 gr-blocks/lib/complex_to_float_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 523ee1b7c..a1ef71b5c 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -42,5 +42,6 @@
blocks_char_to_floatblocks_char_to_shortblocks_complex_to_interleaved_short
+ blocks_complex_to_float
diff --git a/gr-blocks/grc/blocks_complex_to_float.xml b/gr-blocks/grc/blocks_complex_to_float.xml
new file mode 100644
index 000000000..7acf3fccb
--- /dev/null
+++ b/gr-blocks/grc/blocks_complex_to_float.xml
@@ -0,0 +1,36 @@
+
+
+
+ Complex To Float
+ blocks_complex_to_float
+ from gnuradio import blocks
+ blocks.complex_to_float($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ complex
+ $vlen
+
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 783680253..d26512a39 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -87,6 +87,7 @@ install(FILES
char_to_float.h
char_to_short.h
complex_to_interleaved_short.h
+ complex_to_float.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/complex_to_float.h b/gr-blocks/include/blocks/complex_to_float.h
new file mode 100644
index 000000000..322f67b62
--- /dev/null
+++ b/gr-blocks/include/blocks/complex_to_float.h
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_FLOAT_H
+#define INCLUDED_BLOCKS_COMPLEX_TO_FLOAT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief convert a stream of gr_complex to 1 or 2 streams of float
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API complex_to_float : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::complex_to_float_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_COMPLEX_TO_FLOAT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 907ad672e..0adf3c9f7 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -121,6 +121,7 @@ list(APPEND gr_blocks_sources
char_to_float_impl.cc
char_to_short_impl.cc
complex_to_interleaved_short_impl.cc
+ complex_to_float_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/complex_to_float_impl.cc b/gr-blocks/lib/complex_to_float_impl.cc
new file mode 100644
index 000000000..3c1109de5
--- /dev/null
+++ b/gr-blocks/lib/complex_to_float_impl.cc
@@ -0,0 +1,94 @@
+/* -*- 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_float_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ complex_to_float::sptr complex_to_float::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new complex_to_float_impl(vlen));
+ }
+
+ complex_to_float_impl::complex_to_float_impl(size_t vlen)
+ : gr_sync_block("complex_to_float",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 2, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ complex_to_float_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];
+ float *out0 = (float *) output_items[0];
+ float* out1;
+ int noi = noutput_items * d_vlen;
+
+ switch (output_items.size ()){
+ case 1:
+ if(is_unaligned()) {
+ for (int i = 0; i < noi; i++){
+ out0[i] = in[i].real ();
+ }
+ }
+ else {
+ volk_32fc_deinterleave_real_32f_a(out0, in, noi);
+ }
+ break;
+
+ case 2:
+ out1 = (float *) output_items[1];
+ if(is_unaligned()) {
+ for (int i = 0; i < noi; i++){
+ out0[i] = in[i].real ();
+ out1[i] = in[i].imag ();
+ }
+ }
+ else {
+ volk_32fc_deinterleave_32f_x2_a(out0, out1, in, noi);
+ }
+ break;
+
+ default:
+ abort ();
+
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/complex_to_float_impl.h b/gr-blocks/lib/complex_to_float_impl.h
new file mode 100644
index 000000000..d90ac28d5
--- /dev/null
+++ b/gr-blocks/lib/complex_to_float_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_COMPLEX_TO_FLOAT_IMPL_H
+#define INCLUDED_COMPLEX_TO_FLOAT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API complex_to_float_impl : public complex_to_float
+ {
+ size_t d_vlen;
+
+ public:
+ complex_to_float_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_COMPLEX_TO_FLOAT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index b03103bfe..5d477eef1 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -71,5 +71,31 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_complex_to_float_1(self):
+ src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ expected_data = (1.0, 3.0, 5.0, 7.0, 9.0)
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_float()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+
+ def test_complex_to_float_2(self):
+ src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ expected_data1 = (1.0, 3.0, 5.0, 7.0, 9.0)
+ expected_data2 = (2.0, 4.0, 6.0, 8.0, 10.0)
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_float()
+ dst1 = gr.vector_sink_f()
+ dst2 = gr.vector_sink_f()
+ self.tb.connect(src, op)
+ self.tb.connect((op, 0), dst1)
+ self.tb.connect((op, 1), dst2)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data())
+ self.assertFloatTuplesAlmostEqual(expected_data2, dst2.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 16572633f..9cd672891 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -43,6 +43,7 @@
#include "blocks/char_to_float.h"
#include "blocks/char_to_short.h"
#include "blocks/complex_to_interleaved_short.h"
+#include "blocks/complex_to_float.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -80,6 +81,7 @@
%include "blocks/char_to_float.h"
%include "blocks/char_to_short.h"
%include "blocks/complex_to_interleaved_short.h"
+%include "blocks/complex_to_float.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -116,6 +118,7 @@ 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, complex_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From 11a702b94a43cac127c146654f5fc10415f2bb6e Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 23 Jun 2012 08:32:59 -0700
Subject: blocks: added gr::blocks::complex_to_real
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_complex_to_real.xml | 36 +++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/complex_to_real.h | 50 +++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/complex_to_real_impl.cc | 72 ++++++++++++++++++++++++++++++
gr-blocks/lib/complex_to_real_impl.h | 47 +++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 +++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 221 insertions(+)
create mode 100644 gr-blocks/grc/blocks_complex_to_real.xml
create mode 100644 gr-blocks/include/blocks/complex_to_real.h
create mode 100644 gr-blocks/lib/complex_to_real_impl.cc
create mode 100644 gr-blocks/lib/complex_to_real_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index a1ef71b5c..4a520828b 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -43,5 +43,6 @@
blocks_char_to_shortblocks_complex_to_interleaved_shortblocks_complex_to_float
+ blocks_complex_to_real
diff --git a/gr-blocks/grc/blocks_complex_to_real.xml b/gr-blocks/grc/blocks_complex_to_real.xml
new file mode 100644
index 000000000..7acf3fccb
--- /dev/null
+++ b/gr-blocks/grc/blocks_complex_to_real.xml
@@ -0,0 +1,36 @@
+
+
+
+ Complex To Float
+ blocks_complex_to_float
+ from gnuradio import blocks
+ blocks.complex_to_float($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ complex
+ $vlen
+
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index d26512a39..9967273b3 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -88,6 +88,7 @@ install(FILES
char_to_short.h
complex_to_interleaved_short.h
complex_to_float.h
+ complex_to_real.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/complex_to_real.h b/gr-blocks/include/blocks/complex_to_real.h
new file mode 100644
index 000000000..a891c2e08
--- /dev/null
+++ b/gr-blocks/include/blocks/complex_to_real.h
@@ -0,0 +1,50 @@
+/* -*- 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_REAL_H
+#define INCLUDED_BLOCKS_COMPLEX_TO_REAL_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief complex in, real out (float)
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API complex_to_real : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::complex_to_real_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_COMPLEX_TO_REAL_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 0adf3c9f7..8622e7b67 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -122,6 +122,7 @@ list(APPEND gr_blocks_sources
char_to_short_impl.cc
complex_to_interleaved_short_impl.cc
complex_to_float_impl.cc
+ complex_to_real_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/complex_to_real_impl.cc b/gr-blocks/lib/complex_to_real_impl.cc
new file mode 100644
index 000000000..6f053b669
--- /dev/null
+++ b/gr-blocks/lib/complex_to_real_impl.cc
@@ -0,0 +1,72 @@
+/* -*- 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_real_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ complex_to_real::sptr complex_to_real::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new complex_to_real_impl(vlen));
+ }
+
+ complex_to_real_impl::complex_to_real_impl(size_t vlen)
+ : gr_sync_block("complex_to_real",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ complex_to_real_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];
+ float *out = (float *) output_items[0];
+ int noi = noutput_items * d_vlen;
+
+ if(is_unaligned()) {
+ for (int i = 0; i < noi; i++){
+ out[i] = in[i].real ();
+ }
+ }
+ else {
+ volk_32fc_deinterleave_real_32f_a(out, in, noi);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/complex_to_real_impl.h b/gr-blocks/lib/complex_to_real_impl.h
new file mode 100644
index 000000000..7d4d4306f
--- /dev/null
+++ b/gr-blocks/lib/complex_to_real_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_COMPLEX_TO_REAL_IMPL_H
+#define INCLUDED_COMPLEX_TO_REAL_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API complex_to_real_impl : public complex_to_real
+ {
+ size_t d_vlen;
+
+ public:
+ complex_to_real_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_COMPLEX_TO_REAL_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 5d477eef1..7c27a9c51 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -96,6 +96,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.assertFloatTuplesAlmostEqual(expected_data1, dst1.data())
self.assertFloatTuplesAlmostEqual(expected_data2, dst2.data())
+ def test_complex_to_real(self):
+ src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ expected_data = (1.0, 3.0, 5.0, 7.0, 9.0)
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_real()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(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 9cd672891..7e40120a7 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -44,6 +44,7 @@
#include "blocks/char_to_short.h"
#include "blocks/complex_to_interleaved_short.h"
#include "blocks/complex_to_float.h"
+#include "blocks/complex_to_real.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -82,6 +83,7 @@
%include "blocks/char_to_short.h"
%include "blocks/complex_to_interleaved_short.h"
%include "blocks/complex_to_float.h"
+%include "blocks/complex_to_real.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -119,6 +121,7 @@ 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, complex_to_float);
+GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_real);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From ed0dffa3c1a84a4b8f3201969896f61af39b86a3 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 23 Jun 2012 08:44:47 -0700
Subject: blocks: added gr::blocks::complex_to_imag
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_complex_to_imag.xml | 29 ++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/complex_to_imag.h | 50 +++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/complex_to_imag_impl.cc | 72 ++++++++++++++++++++++++++++++
gr-blocks/lib/complex_to_imag_impl.h | 47 +++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 +++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 214 insertions(+)
create mode 100644 gr-blocks/grc/blocks_complex_to_imag.xml
create mode 100644 gr-blocks/include/blocks/complex_to_imag.h
create mode 100644 gr-blocks/lib/complex_to_imag_impl.cc
create mode 100644 gr-blocks/lib/complex_to_imag_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 4a520828b..2739919d2 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -43,6 +43,7 @@
blocks_char_to_shortblocks_complex_to_interleaved_shortblocks_complex_to_float
+ blocks_complex_to_imagblocks_complex_to_real
diff --git a/gr-blocks/grc/blocks_complex_to_imag.xml b/gr-blocks/grc/blocks_complex_to_imag.xml
new file mode 100644
index 000000000..cb2c2019f
--- /dev/null
+++ b/gr-blocks/grc/blocks_complex_to_imag.xml
@@ -0,0 +1,29 @@
+
+
+
+ Complex to Imag
+ blocks_complex_to_imag
+ from gnuradio import blocks
+ blocks.complex_to_imag($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ complex
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 9967273b3..d0929cfbc 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -88,6 +88,7 @@ install(FILES
char_to_short.h
complex_to_interleaved_short.h
complex_to_float.h
+ complex_to_imag.h
complex_to_real.h
multiply_cc.h
multiply_ff.h
diff --git a/gr-blocks/include/blocks/complex_to_imag.h b/gr-blocks/include/blocks/complex_to_imag.h
new file mode 100644
index 000000000..71353a94a
--- /dev/null
+++ b/gr-blocks/include/blocks/complex_to_imag.h
@@ -0,0 +1,50 @@
+/* -*- 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_IMAG_H
+#define INCLUDED_BLOCKS_COMPLEX_TO_IMAG_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief complex in, imag out (float)
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API complex_to_imag : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::complex_to_imag_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_COMPLEX_TO_IMAG_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 8622e7b67..612a56de0 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -123,6 +123,7 @@ list(APPEND gr_blocks_sources
complex_to_interleaved_short_impl.cc
complex_to_float_impl.cc
complex_to_real_impl.cc
+ complex_to_imag_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/complex_to_imag_impl.cc b/gr-blocks/lib/complex_to_imag_impl.cc
new file mode 100644
index 000000000..760440cc9
--- /dev/null
+++ b/gr-blocks/lib/complex_to_imag_impl.cc
@@ -0,0 +1,72 @@
+/* -*- 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_imag_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ complex_to_imag::sptr complex_to_imag::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new complex_to_imag_impl(vlen));
+ }
+
+ complex_to_imag_impl::complex_to_imag_impl(size_t vlen)
+ : gr_sync_block("complex_to_imag",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ complex_to_imag_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];
+ float *out = (float *) output_items[0];
+ int noi = noutput_items * d_vlen;
+
+ if(is_unaligned()) {
+ for (int i = 0; i < noi; i++){
+ out[i] = in[i].imag ();
+ }
+ }
+ else {
+ volk_32fc_deinterleave_imag_32f_a(out, in, noi);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/complex_to_imag_impl.h b/gr-blocks/lib/complex_to_imag_impl.h
new file mode 100644
index 000000000..e647e6773
--- /dev/null
+++ b/gr-blocks/lib/complex_to_imag_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_COMPLEX_TO_IMAG_IMPL_H
+#define INCLUDED_COMPLEX_TO_IMAG_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API complex_to_imag_impl : public complex_to_imag
+ {
+ size_t d_vlen;
+
+ public:
+ complex_to_imag_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_COMPLEX_TO_IMAG_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 7c27a9c51..1faf83ad8 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -106,6 +106,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+ def test_complex_to_imag(self):
+ src_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ expected_data = (2.0, 4.0, 6.0, 8.0, 10.0)
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_imag()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(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 7e40120a7..af445b919 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -45,6 +45,7 @@
#include "blocks/complex_to_interleaved_short.h"
#include "blocks/complex_to_float.h"
#include "blocks/complex_to_real.h"
+#include "blocks/complex_to_imag.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -84,6 +85,7 @@
%include "blocks/complex_to_interleaved_short.h"
%include "blocks/complex_to_float.h"
%include "blocks/complex_to_real.h"
+%include "blocks/complex_to_imag.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -122,6 +124,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, char_to_short);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_interleaved_short);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_real);
+GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_imag);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From 48ba99044710dc69c0ebdd3fbe97798622713a9f Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 23 Jun 2012 09:06:19 -0700
Subject: blocks: added gr::blocks::complex_to_mag
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_complex_to_mag.xml | 29 ++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/complex_to_mag.h | 50 +++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/complex_to_mag_impl.cc | 66 +++++++++++++++++++++++++++++++
gr-blocks/lib/complex_to_mag_impl.h | 47 ++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 11 ++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 209 insertions(+)
create mode 100644 gr-blocks/grc/blocks_complex_to_mag.xml
create mode 100644 gr-blocks/include/blocks/complex_to_mag.h
create mode 100644 gr-blocks/lib/complex_to_mag_impl.cc
create mode 100644 gr-blocks/lib/complex_to_mag_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 2739919d2..0f68ee0d1 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -45,5 +45,6 @@
blocks_complex_to_floatblocks_complex_to_imagblocks_complex_to_real
+ blocks_complex_to_mag
diff --git a/gr-blocks/grc/blocks_complex_to_mag.xml b/gr-blocks/grc/blocks_complex_to_mag.xml
new file mode 100644
index 000000000..2aa4faee7
--- /dev/null
+++ b/gr-blocks/grc/blocks_complex_to_mag.xml
@@ -0,0 +1,29 @@
+
+
+
+ Complex to Mag
+ blocks_complex_to_mag
+ from gnuradio import blocks
+ blocks.complex_to_mag($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ complex
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index d0929cfbc..c8f837d68 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -90,6 +90,7 @@ install(FILES
complex_to_float.h
complex_to_imag.h
complex_to_real.h
+ complex_to_mag.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/complex_to_mag.h b/gr-blocks/include/blocks/complex_to_mag.h
new file mode 100644
index 000000000..7e03c1cac
--- /dev/null
+++ b/gr-blocks/include/blocks/complex_to_mag.h
@@ -0,0 +1,50 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_MAG_H
+#define INCLUDED_BLOCKS_COMPLEX_TO_MAG_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief complex in, magnitude out (float)
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API complex_to_mag : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::complex_to_mag_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_COMPLEX_TO_MAG_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 612a56de0..3c757fc0c 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -124,6 +124,7 @@ list(APPEND gr_blocks_sources
complex_to_float_impl.cc
complex_to_real_impl.cc
complex_to_imag_impl.cc
+ complex_to_mag_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/complex_to_mag_impl.cc b/gr-blocks/lib/complex_to_mag_impl.cc
new file mode 100644
index 000000000..419bc53eb
--- /dev/null
+++ b/gr-blocks/lib/complex_to_mag_impl.cc
@@ -0,0 +1,66 @@
+/* -*- 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_mag_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ complex_to_mag::sptr complex_to_mag::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new complex_to_mag_impl(vlen));
+ }
+
+ complex_to_mag_impl::complex_to_mag_impl(size_t vlen)
+ : gr_sync_block("complex_to_mag",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ complex_to_mag_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];
+ float *out = (float *) output_items[0];
+ int noi = noutput_items * d_vlen;
+
+ // turned out to be faster than aligned/unaligned switching
+ volk_32fc_magnitude_32f_u(out, in, noi);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/complex_to_mag_impl.h b/gr-blocks/lib/complex_to_mag_impl.h
new file mode 100644
index 000000000..fe6da3f15
--- /dev/null
+++ b/gr-blocks/lib/complex_to_mag_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_COMPLEX_TO_MAG_IMPL_H
+#define INCLUDED_COMPLEX_TO_MAG_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API complex_to_mag_impl : public complex_to_mag
+ {
+ size_t d_vlen;
+
+ public:
+ complex_to_mag_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_COMPLEX_TO_MAG_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 1faf83ad8..92590feac 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -22,6 +22,7 @@
from gnuradio import gr, gr_unittest
import blocks_swig
+import math
class test_type_conversions(gr_unittest.TestCase):
@@ -116,6 +117,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+ def test_complex_to_mag(self):
+ src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j)
+ expected_data = (math.sqrt(5), math.sqrt(25), math.sqrt(61), math.sqrt(113), math.sqrt(181))
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_mag()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5)
+
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 af445b919..226c98e7c 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -46,6 +46,7 @@
#include "blocks/complex_to_float.h"
#include "blocks/complex_to_real.h"
#include "blocks/complex_to_imag.h"
+#include "blocks/complex_to_mag.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -86,6 +87,7 @@
%include "blocks/complex_to_float.h"
%include "blocks/complex_to_real.h"
%include "blocks/complex_to_imag.h"
+%include "blocks/complex_to_mag.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -125,6 +127,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_interleaved_short);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_real);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_imag);
+GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From 737b3dc0c41a867ea38c1475a3877bc0fb6f3ee2 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 23 Jun 2012 09:25:42 -0700
Subject: blocks: added gr::blocks::complex_to_mag_squared
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_complex_to_mag_squared.xml | 29 ++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/complex_to_mag_squared.h | 50 ++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/complex_to_mag_squared_impl.cc | 70 +++++++++++++++++++++++
gr-blocks/lib/complex_to_mag_squared_impl.h | 47 +++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 ++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 212 insertions(+)
create mode 100644 gr-blocks/grc/blocks_complex_to_mag_squared.xml
create mode 100644 gr-blocks/include/blocks/complex_to_mag_squared.h
create mode 100644 gr-blocks/lib/complex_to_mag_squared_impl.cc
create mode 100644 gr-blocks/lib/complex_to_mag_squared_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 0f68ee0d1..d83c99488 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -46,5 +46,6 @@
blocks_complex_to_imagblocks_complex_to_realblocks_complex_to_mag
+ blocks_complex_to_mag_squared
diff --git a/gr-blocks/grc/blocks_complex_to_mag_squared.xml b/gr-blocks/grc/blocks_complex_to_mag_squared.xml
new file mode 100644
index 000000000..ee2270fec
--- /dev/null
+++ b/gr-blocks/grc/blocks_complex_to_mag_squared.xml
@@ -0,0 +1,29 @@
+
+
+
+ Complex to Mag^2
+ blocks_complex_to_mag_squared
+ from gnuradio import blocks
+ blocks.complex_to_mag_squared($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ complex
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index c8f837d68..59cf455a1 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -91,6 +91,7 @@ install(FILES
complex_to_imag.h
complex_to_real.h
complex_to_mag.h
+ complex_to_mag_squared.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/complex_to_mag_squared.h b/gr-blocks/include/blocks/complex_to_mag_squared.h
new file mode 100644
index 000000000..9e122b4b1
--- /dev/null
+++ b/gr-blocks/include/blocks/complex_to_mag_squared.h
@@ -0,0 +1,50 @@
+/* -*- 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_MAG_SQUARED_H
+#define INCLUDED_BLOCKS_COMPLEX_TO_MAG_SQUARED_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief complex in, magnitude squared out (float)
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API complex_to_mag_squared : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::complex_to_mag_squared_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_COMPLEX_TO_MAG_SQUARED_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 3c757fc0c..ebaec1837 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -125,6 +125,7 @@ list(APPEND gr_blocks_sources
complex_to_real_impl.cc
complex_to_imag_impl.cc
complex_to_mag_impl.cc
+ complex_to_mag_squared_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/complex_to_mag_squared_impl.cc b/gr-blocks/lib/complex_to_mag_squared_impl.cc
new file mode 100644
index 000000000..a3b48b153
--- /dev/null
+++ b/gr-blocks/lib/complex_to_mag_squared_impl.cc
@@ -0,0 +1,70 @@
+/* -*- 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_mag_squared_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ complex_to_mag_squared::sptr complex_to_mag_squared::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new complex_to_mag_squared_impl(vlen));
+ }
+
+ complex_to_mag_squared_impl::complex_to_mag_squared_impl(size_t vlen)
+ : gr_sync_block("complex_to_mag_squared",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ complex_to_mag_squared_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];
+ float *out = (float *) output_items[0];
+ int noi = noutput_items * d_vlen;
+
+ if(is_unaligned()) {
+ volk_32fc_magnitude_squared_32f_u(out, in, noi);
+ }
+ else {
+ volk_32fc_magnitude_squared_32f_a(out, in, noi);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/complex_to_mag_squared_impl.h b/gr-blocks/lib/complex_to_mag_squared_impl.h
new file mode 100644
index 000000000..01851d266
--- /dev/null
+++ b/gr-blocks/lib/complex_to_mag_squared_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_COMPLEX_TO_MAG_SQUARED_IMPL_H
+#define INCLUDED_COMPLEX_TO_MAG_SQUARED_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API complex_to_mag_squared_impl : public complex_to_mag_squared
+ {
+ size_t d_vlen;
+
+ public:
+ complex_to_mag_squared_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_COMPLEX_TO_MAG_SQUARED_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 92590feac..4b8904f0e 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -127,6 +127,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 5)
+ def test_complex_to_mag_squared(self):
+ src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j)
+ expected_data = (5.0, 25.0, 61.0, 113.0, 181.0)
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_mag_squared()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(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 226c98e7c..f017f91d1 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -47,6 +47,7 @@
#include "blocks/complex_to_real.h"
#include "blocks/complex_to_imag.h"
#include "blocks/complex_to_mag.h"
+#include "blocks/complex_to_mag_squared.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -88,6 +89,7 @@
%include "blocks/complex_to_real.h"
%include "blocks/complex_to_imag.h"
%include "blocks/complex_to_mag.h"
+%include "blocks/complex_to_mag_squared.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -128,6 +130,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_real);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_imag);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag);
+GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag_squared);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From 80aa560bbb59cad4d4d351a1e9c8c1fb56897397 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 23 Jun 2012 09:57:06 -0700
Subject: blocks: added gr::blocks::complex_to_arg
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_complex_to_arg.xml | 29 +++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/complex_to_arg.h | 50 ++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/complex_to_arg_impl.cc | 70 +++++++++++++++++++++++++++++++
gr-blocks/lib/complex_to_arg_impl.h | 47 +++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 14 ++++++-
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 214 insertions(+), 2 deletions(-)
create mode 100644 gr-blocks/grc/blocks_complex_to_arg.xml
create mode 100644 gr-blocks/include/blocks/complex_to_arg.h
create mode 100644 gr-blocks/lib/complex_to_arg_impl.cc
create mode 100644 gr-blocks/lib/complex_to_arg_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index d83c99488..537de92cc 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -47,5 +47,6 @@
blocks_complex_to_realblocks_complex_to_magblocks_complex_to_mag_squared
+ blocks_complex_to_arg
diff --git a/gr-blocks/grc/blocks_complex_to_arg.xml b/gr-blocks/grc/blocks_complex_to_arg.xml
new file mode 100644
index 000000000..83140501d
--- /dev/null
+++ b/gr-blocks/grc/blocks_complex_to_arg.xml
@@ -0,0 +1,29 @@
+
+
+
+ Complex to Arg
+ blocks_complex_to_arg
+ from gnuradio import blocks
+ blocks.complex_to_arg($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ complex
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 59cf455a1..3593a9d27 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -92,6 +92,7 @@ install(FILES
complex_to_real.h
complex_to_mag.h
complex_to_mag_squared.h
+ complex_to_arg.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/complex_to_arg.h b/gr-blocks/include/blocks/complex_to_arg.h
new file mode 100644
index 000000000..5d38161d4
--- /dev/null
+++ b/gr-blocks/include/blocks/complex_to_arg.h
@@ -0,0 +1,50 @@
+/* -*- 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_ARG_H
+#define INCLUDED_BLOCKS_COMPLEX_TO_ARG_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief complex in, arg out (float)
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API complex_to_arg : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::complex_to_arg_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_COMPLEX_TO_ARG_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index ebaec1837..59419e202 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -126,6 +126,7 @@ list(APPEND gr_blocks_sources
complex_to_imag_impl.cc
complex_to_mag_impl.cc
complex_to_mag_squared_impl.cc
+ complex_to_arg_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/complex_to_arg_impl.cc b/gr-blocks/lib/complex_to_arg_impl.cc
new file mode 100644
index 000000000..87ac9966f
--- /dev/null
+++ b/gr-blocks/lib/complex_to_arg_impl.cc
@@ -0,0 +1,70 @@
+/* -*- 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_arg_impl.h"
+#include
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ complex_to_arg::sptr complex_to_arg::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new complex_to_arg_impl(vlen));
+ }
+
+ complex_to_arg_impl::complex_to_arg_impl(size_t vlen)
+ : gr_sync_block("complex_to_arg",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ complex_to_arg_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];
+ float *out = (float *) output_items[0];
+ int noi = noutput_items * d_vlen;
+
+ // The fast_atan2f is faster than Volk
+ for (int i = 0; i < noi; i++){
+ // out[i] = std::arg (in[i]);
+ out[i] = gr_fast_atan2f(in[i]);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/complex_to_arg_impl.h b/gr-blocks/lib/complex_to_arg_impl.h
new file mode 100644
index 000000000..9ccfba05a
--- /dev/null
+++ b/gr-blocks/lib/complex_to_arg_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_COMPLEX_TO_ARG_IMPL_H
+#define INCLUDED_COMPLEX_TO_ARG_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API complex_to_arg_impl : public complex_to_arg
+ {
+ size_t d_vlen;
+
+ public:
+ complex_to_arg_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_COMPLEX_TO_ARG_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 4b8904f0e..579ce2246 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -22,7 +22,7 @@
from gnuradio import gr, gr_unittest
import blocks_swig
-import math
+from math import sqrt, atan2
class test_type_conversions(gr_unittest.TestCase):
@@ -119,7 +119,7 @@ class test_type_conversions(gr_unittest.TestCase):
def test_complex_to_mag(self):
src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j)
- expected_data = (math.sqrt(5), math.sqrt(25), math.sqrt(61), math.sqrt(113), math.sqrt(181))
+ expected_data = (sqrt(5), sqrt(25), sqrt(61), sqrt(113), sqrt(181))
src = gr.vector_source_c(src_data)
op = blocks_swig.complex_to_mag()
dst = gr.vector_sink_f()
@@ -137,6 +137,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+ def test_complex_to_arg(self):
+ src_data = (1+2j, 3-4j, 5+6j, 7-8j, -9+10j)
+ expected_data = (atan2(2, 1), atan2(-4,3), atan2(6, 5), atan2(-8, 7), atan2(10,-9))
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.complex_to_arg()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2)
+ print 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 f017f91d1..a5cb721c4 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -48,6 +48,7 @@
#include "blocks/complex_to_imag.h"
#include "blocks/complex_to_mag.h"
#include "blocks/complex_to_mag_squared.h"
+#include "blocks/complex_to_arg.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -90,6 +91,7 @@
%include "blocks/complex_to_imag.h"
%include "blocks/complex_to_mag.h"
%include "blocks/complex_to_mag_squared.h"
+%include "blocks/complex_to_arg.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -131,6 +133,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_real);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_imag);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag_squared);
+GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_arg);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From b48716fe0b666cf2be605c0c7d79111c6caf96c5 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sun, 24 Jun 2012 11:20:03 -0700
Subject: blocks: added gr::blocks::float_to_char
---
gr-blocks/grc/blocks_block_tree.xml | 3 +-
gr-blocks/grc/blocks_float_to_char.xml | 35 ++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/float_to_char.h | 62 ++++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/float_to_char_impl.cc | 69 ++++++++++++++++++++++++++++++++
gr-blocks/lib/float_to_char_impl.h | 51 +++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 21 +++++++++-
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 244 insertions(+), 2 deletions(-)
create mode 100644 gr-blocks/grc/blocks_float_to_char.xml
create mode 100644 gr-blocks/include/blocks/float_to_char.h
create mode 100644 gr-blocks/lib/float_to_char_impl.cc
create mode 100644 gr-blocks/lib/float_to_char_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 537de92cc..eb0cdd79c 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -23,7 +23,7 @@
@@ -48,5 +48,6 @@
blocks_complex_to_magblocks_complex_to_mag_squaredblocks_complex_to_arg
+ float_to_char
diff --git a/gr-blocks/grc/blocks_float_to_char.xml b/gr-blocks/grc/blocks_float_to_char.xml
new file mode 100644
index 000000000..e3854fc4e
--- /dev/null
+++ b/gr-blocks/grc/blocks_float_to_char.xml
@@ -0,0 +1,35 @@
+
+
+
+ Float To Char
+ blocks_float_to_char
+ from gnuradio import blocks
+ blocks.float_to_char($vlen, $scale)
+ set_scale($scale)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Scale
+ scale
+ 1
+ real
+
+
+ in
+ float
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 3593a9d27..374ecadf5 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -93,6 +93,7 @@ install(FILES
complex_to_mag.h
complex_to_mag_squared.h
complex_to_arg.h
+ float_to_char.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/float_to_char.h b/gr-blocks/include/blocks/float_to_char.h
new file mode 100644
index 000000000..de9ea85e3
--- /dev/null
+++ b/gr-blocks/include/blocks/float_to_char.h
@@ -0,0 +1,62 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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_FLOAT_TO_CHAR_H
+#define INCLUDED_BLOCKS_FLOAT_TO_CHAR_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of floats to a stream of char
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ * \param scale a scalar multiplier to change the output signal scale.
+ */
+ class BLOCKS_API float_to_char : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::float_to_char_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1, float scale=1.0);
+
+ /*!
+ * Get the scalar multiplier value.
+ */
+ virtual float scale() const = 0;
+
+ /*!
+ * Set the scalar multiplier value.
+ */
+ virtual void set_scale(float scale) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_FLOAT_TO_CHAR_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 59419e202..0d2385251 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -127,6 +127,7 @@ list(APPEND gr_blocks_sources
complex_to_mag_impl.cc
complex_to_mag_squared_impl.cc
complex_to_arg_impl.cc
+ float_to_char_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/float_to_char_impl.cc b/gr-blocks/lib/float_to_char_impl.cc
new file mode 100644
index 000000000..c37522dc9
--- /dev/null
+++ b/gr-blocks/lib/float_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 "float_to_char_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ float_to_char::sptr float_to_char::make(size_t vlen, float scale)
+ {
+ return gnuradio::get_initial_sptr(new float_to_char_impl(vlen, scale));
+ }
+
+ float_to_char_impl::float_to_char_impl(size_t vlen, float scale)
+ : gr_sync_block("float_to_char",
+ gr_make_io_signature (1, 1, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(char)*vlen)),
+ d_vlen(vlen), d_scale(scale)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(char);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ float_to_char_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *) input_items[0];
+ int8_t *out = (int8_t *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_32f_s32f_convert_8i_u(out, in, d_scale, d_vlen*noutput_items);
+ }
+ else {
+ volk_32f_s32f_convert_8i_a(out, in, d_scale, d_vlen*noutput_items);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/float_to_char_impl.h b/gr-blocks/lib/float_to_char_impl.h
new file mode 100644
index 000000000..2644f3e70
--- /dev/null
+++ b/gr-blocks/lib/float_to_char_impl.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_FLOAT_TO_CHAR_IMPL_H
+#define INCLUDED_FLOAT_TO_CHAR_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API float_to_char_impl : public float_to_char
+ {
+ size_t d_vlen;
+ float d_scale;
+
+ public:
+ float_to_char_impl(size_t vlen, float scale);
+
+ virtual float scale() const { return d_scale; }
+ virtual void set_scale(float scale) { d_scale = scale; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_FLOAT_TO_CHAR_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 579ce2246..2caa283d2 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -146,7 +146,26 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.connect(src, op, dst)
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data(), 2)
- print dst.data()
+
+ def test_float_to_char_identity(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ expected_data = (1, 2, 3, 4, 5)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_char()
+ dst = gr.vector_sink_b()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(expected_data, dst.data())
+
+ def test_float_to_char_scale(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ expected_data = (5, 10, 15, 20, 25)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_char(1, 5)
+ 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 a5cb721c4..db30a6706 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -53,6 +53,7 @@
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
#include "blocks/divide_cc.h"
+#include "blocks/float_to_char.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -96,6 +97,7 @@
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
%include "blocks/divide_cc.h"
+%include "blocks/float_to_char.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -138,6 +140,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, float_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From 8c23d9f9ebfe04b60d59efc636c6d5b02baacc99 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sun, 24 Jun 2012 11:42:20 -0700
Subject: blocks: added gr::blocks::float_to_complex
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_float_to_complex.xml | 36 +++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/float_to_complex.h | 50 ++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/float_to_complex_impl.cc | 78 +++++++++++++++++++++++++++++
gr-blocks/lib/float_to_complex_impl.h | 47 +++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 25 +++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 242 insertions(+)
create mode 100644 gr-blocks/grc/blocks_float_to_complex.xml
create mode 100644 gr-blocks/include/blocks/float_to_complex.h
create mode 100644 gr-blocks/lib/float_to_complex_impl.cc
create mode 100644 gr-blocks/lib/float_to_complex_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index eb0cdd79c..29cc2634d 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -49,5 +49,6 @@
blocks_complex_to_mag_squaredblocks_complex_to_argfloat_to_char
+ float_to_complex
diff --git a/gr-blocks/grc/blocks_float_to_complex.xml b/gr-blocks/grc/blocks_float_to_complex.xml
new file mode 100644
index 000000000..6120d5887
--- /dev/null
+++ b/gr-blocks/grc/blocks_float_to_complex.xml
@@ -0,0 +1,36 @@
+
+
+
+ Float To Complex
+ blocks_float_to_complex
+ from gnuradio import blocks
+ blocks.float_to_complex($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ re
+ float
+ $vlen
+
+
+ im
+ float
+ $vlen
+ 1
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 374ecadf5..96f42a699 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -94,6 +94,7 @@ install(FILES
complex_to_mag_squared.h
complex_to_arg.h
float_to_char.h
+ float_to_complex.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/float_to_complex.h b/gr-blocks/include/blocks/float_to_complex.h
new file mode 100644
index 000000000..48c5b6ead
--- /dev/null
+++ b/gr-blocks/include/blocks/float_to_complex.h
@@ -0,0 +1,50 @@
+/* -*- 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_FLOAT_TO_COMPLEX_H
+#define INCLUDED_BLOCKS_FLOAT_TO_COMPLEX_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief one or two floats in, complex out
+ * \ingroup converter_blk
+ * \param vlen vector len (default 1)
+ */
+ class BLOCKS_API float_to_complex : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::float_to_complex_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_FLOAT_TO_COMPLEX_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 0d2385251..f1d04622d 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -128,6 +128,7 @@ list(APPEND gr_blocks_sources
complex_to_mag_squared_impl.cc
complex_to_arg_impl.cc
float_to_char_impl.cc
+ float_to_complex_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/float_to_complex_impl.cc b/gr-blocks/lib/float_to_complex_impl.cc
new file mode 100644
index 000000000..709aa420c
--- /dev/null
+++ b/gr-blocks/lib/float_to_complex_impl.cc
@@ -0,0 +1,78 @@
+/* -*- 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 "float_to_complex_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ float_to_complex::sptr float_to_complex::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new float_to_complex_impl(vlen));
+ }
+
+ float_to_complex_impl::float_to_complex_impl(size_t vlen)
+ : gr_sync_block("float_to_complex",
+ gr_make_io_signature (1, 2, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1,alignment_multiple));
+ }
+
+ int
+ float_to_complex_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ float *r = (float *)input_items[0];
+ float *i = (float *)input_items[1];
+ gr_complex *out = (gr_complex *) output_items[0];
+
+ switch (input_items.size ()){
+ case 1:
+ for (size_t j = 0; j < noutput_items*d_vlen; j++)
+ out[j] = gr_complex (r[j], 0);
+ break;
+
+ case 2:
+ for (size_t j = 0; j < noutput_items*d_vlen; j++)
+ out[j] = gr_complex (r[j], i[j]);
+ break;
+
+ default:
+ assert (0);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/float_to_complex_impl.h b/gr-blocks/lib/float_to_complex_impl.h
new file mode 100644
index 000000000..859c5bf96
--- /dev/null
+++ b/gr-blocks/lib/float_to_complex_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_FLOAT_TO_COMPLEX_IMPL_H
+#define INCLUDED_FLOAT_TO_COMPLEX_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API float_to_complex_impl : public float_to_complex
+ {
+ size_t d_vlen;
+
+ public:
+ float_to_complex_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_FLOAT_TO_COMPLEX_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 2caa283d2..4daf5f602 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -167,5 +167,30 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_float_to_complex_1(self):
+ src_data = (1.0, 3.0, 5.0, 7.0, 9.0)
+ expected_data = (1+0j, 3+0j, 5+0j, 7+0j, 9+0j)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_complex()
+ dst = gr.vector_sink_c()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+
+ def test_float_to_complex_2(self):
+ src1_data = (1.0, 3.0, 5.0, 7.0, 9.0)
+ src2_data = (2.0, 4.0, 6.0, 8.0, 10.0)
+ expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ src1 = gr.vector_source_f(src1_data)
+ src2 = gr.vector_source_f(src2_data)
+ op = blocks_swig.float_to_complex()
+ dst = gr.vector_sink_c()
+ self.tb.connect(src1, (op, 0))
+ self.tb.connect(src2, (op, 1))
+ self.tb.connect(op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(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 db30a6706..e15b5eb02 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -54,6 +54,7 @@
#include "blocks/divide_ii.h"
#include "blocks/divide_cc.h"
#include "blocks/float_to_char.h"
+#include "blocks/float_to_complex.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -98,6 +99,7 @@
%include "blocks/divide_ii.h"
%include "blocks/divide_cc.h"
%include "blocks/float_to_char.h"
+%include "blocks/float_to_complex.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -141,6 +143,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_char);
+GR_SWIG_BLOCK_MAGIC2(blocks, float_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From 31c61c16e2073f0c3f54a8d0523d8c4f10ca5dd2 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Mon, 25 Jun 2012 06:25:04 -0700
Subject: blocks: added gr::blocks::float_to_int
---
gr-blocks/grc/blocks_block_tree.xml | 7 +--
gr-blocks/grc/blocks_float_to_int.xml | 35 ++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/float_to_int.h | 62 ++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 4 +-
gr-blocks/lib/float_array_to_int.cc | 46 ++++++++++++++++++
gr-blocks/lib/float_array_to_int.h | 33 +++++++++++++
gr-blocks/lib/float_to_int_impl.cc | 83 +++++++++++++++++++++++++++++++++
gr-blocks/lib/float_to_int_impl.h | 51 ++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 20 ++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
11 files changed, 341 insertions(+), 4 deletions(-)
create mode 100644 gr-blocks/grc/blocks_float_to_int.xml
create mode 100644 gr-blocks/include/blocks/float_to_int.h
create mode 100644 gr-blocks/lib/float_array_to_int.cc
create mode 100644 gr-blocks/lib/float_array_to_int.h
create mode 100644 gr-blocks/lib/float_to_int_impl.cc
create mode 100644 gr-blocks/lib/float_to_int_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 29cc2634d..169533d34 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -38,7 +38,7 @@
blocks_sub_xx
- Type Conversions
+ Stream Type Conversionsblocks_char_to_floatblocks_char_to_shortblocks_complex_to_interleaved_short
@@ -48,7 +48,8 @@
blocks_complex_to_magblocks_complex_to_mag_squaredblocks_complex_to_arg
- float_to_char
- float_to_complex
+ blocks_float_to_char
+ blocks_float_to_complex
+ blocks_float_to_int
diff --git a/gr-blocks/grc/blocks_float_to_int.xml b/gr-blocks/grc/blocks_float_to_int.xml
new file mode 100644
index 000000000..0ff5d9cdf
--- /dev/null
+++ b/gr-blocks/grc/blocks_float_to_int.xml
@@ -0,0 +1,35 @@
+
+
+
+ Float To Int
+ blocks_float_to_int
+ from gnuradio import blocks
+ blocks.float_to_int($vlen, $scale)
+ set_scale($scale)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Scale
+ scale
+ 1
+ real
+
+
+ in
+ float
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 96f42a699..3171a4d02 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -95,6 +95,7 @@ install(FILES
complex_to_arg.h
float_to_char.h
float_to_complex.h
+ float_to_int.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/float_to_int.h b/gr-blocks/include/blocks/float_to_int.h
new file mode 100644
index 000000000..95c62e516
--- /dev/null
+++ b/gr-blocks/include/blocks/float_to_int.h
@@ -0,0 +1,62 @@
+/* -*- 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_FLOAT_TO_INT_H
+#define INCLUDED_BLOCKS_FLOAT_TO_INT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of floats to a stream of char
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ * \param scale a scalar multiplier to change the output signal scale.
+ */
+ class BLOCKS_API float_to_int : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::float_to_int_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1, float scale=1.0);
+
+ /*!
+ * Get the scalar multiplier value.
+ */
+ virtual float scale() const = 0;
+
+ /*!
+ * Set the scalar multiplier value.
+ */
+ virtual void set_scale(float scale) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_FLOAT_TO_INT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index f1d04622d..e443d5488 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -77,7 +77,7 @@ macro(expand_cc_h_impl root)
set_source_files_properties(${expanded_files_h_impl}
PROPERTIES OBJECT_DEPENDS "${expanded_files_h}"
)
-
+
#install rules for the generated cc files
list(APPEND generated_sources ${expanded_files_cc_impl})
endmacro(expand_cc_h_impl)
@@ -129,6 +129,8 @@ list(APPEND gr_blocks_sources
complex_to_arg_impl.cc
float_to_char_impl.cc
float_to_complex_impl.cc
+ float_array_to_int.cc
+ float_to_int_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/float_array_to_int.cc b/gr-blocks/lib/float_array_to_int.cc
new file mode 100644
index 000000000..66b112c06
--- /dev/null
+++ b/gr-blocks/lib/float_array_to_int.cc
@@ -0,0 +1,46 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011-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
+#endif
+
+#define _ISOC9X_SOURCE
+#include
+#include
+#include
+
+static const int64_t MAX_INT = 2147483647; // (2^31)-1
+static const int64_t MIN_INT = -2147483647; // -(2^31)-1
+
+void
+float_array_to_int(const float *in, int *out, float scale, int nsamples)
+{
+ for (int i = 0; i < nsamples; i++){
+ int64_t r = llrintf(scale * in[i]);
+ if (r < MIN_INT)
+ r = MIN_INT;
+ else if (r > MAX_INT)
+ r = MAX_INT;
+ out[i] = static_cast(r);
+ }
+}
diff --git a/gr-blocks/lib/float_array_to_int.h b/gr-blocks/lib/float_array_to_int.h
new file mode 100644
index 000000000..943736d7e
--- /dev/null
+++ b/gr-blocks/lib/float_array_to_int.h
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2011-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_FLOAT_ARRAY_TO_INT_H
+#define INCLUDED_BLOCKS_FLOAT_ARRAY_TO_INT_H
+
+#include
+
+/*!
+ * convert array of floats to int with rounding and saturation.
+ */
+BLOCKS_API void float_array_to_int (const float *in, int *out, float scale, int nsamples);
+
+#endif /* INCLUDED_BLOCKS_FLOAT_ARRAY_TO_INT_H */
diff --git a/gr-blocks/lib/float_to_int_impl.cc b/gr-blocks/lib/float_to_int_impl.cc
new file mode 100644
index 000000000..24218ab68
--- /dev/null
+++ b/gr-blocks/lib/float_to_int_impl.cc
@@ -0,0 +1,83 @@
+/* -*- 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 "float_to_int_impl.h"
+#include "float_array_to_int.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ float_to_int::sptr float_to_int::make(size_t vlen, float scale)
+ {
+ return gnuradio::get_initial_sptr(new float_to_int_impl(vlen, scale));
+ }
+
+ float_to_int_impl::float_to_int_impl(size_t vlen, float scale)
+ : gr_sync_block("float_to_int",
+ gr_make_io_signature (1, 1, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(int)*vlen)),
+ d_vlen(vlen), d_scale(scale)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(int);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ float_to_int_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ // Disable the Volk for now. There is a problem for large 32-bit ints that
+ // are not properly represented by the precisions of a single float, which
+ // can cause wrapping from large, positive numbers to negative.
+ // In gri_float_to_int, the value is first promoted to a 64-bit
+ // value, clipped, then converted to a float.
+#if 0
+ const float *in = (const float *) input_items[0];
+ int32_t *out = (int32_t *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_32f_s32f_convert_32i_u(out, in, d_scale, d_vlen*noutput_items);
+ }
+ else {
+ volk_32f_s32f_convert_32i_a(out, in, d_scale, d_vlen*noutput_items);
+ }
+#else
+ const float *in = (const float *) input_items[0];
+ int *out = (int *) output_items[0];
+
+ float_array_to_int (in, out, d_scale, d_vlen*noutput_items);
+
+#endif
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/float_to_int_impl.h b/gr-blocks/lib/float_to_int_impl.h
new file mode 100644
index 000000000..71775fcb1
--- /dev/null
+++ b/gr-blocks/lib/float_to_int_impl.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_FLOAT_TO_INT_IMPL_H
+#define INCLUDED_FLOAT_TO_INT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API float_to_int_impl : public float_to_int
+ {
+ size_t d_vlen;
+ float d_scale;
+
+ public:
+ float_to_int_impl(size_t vlen, float scale);
+
+ virtual float scale() const { return d_scale; }
+ virtual void set_scale(float scale) { d_scale = scale; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_FLOAT_TO_INT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 4daf5f602..fba38ab00 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -191,6 +191,26 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+ def test_float_to_int_identity(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ expected_data = (1, 2, 3, 4, 5)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_int()
+ dst = gr.vector_sink_i()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(expected_data, dst.data())
+
+ def test_float_to_int_scale(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ expected_data = (5, 10, 15, 20, 25)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_int(1, 5)
+ dst = gr.vector_sink_i()
+ 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 e15b5eb02..593b7ad2d 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -55,6 +55,7 @@
#include "blocks/divide_cc.h"
#include "blocks/float_to_char.h"
#include "blocks/float_to_complex.h"
+#include "blocks/float_to_int.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -100,6 +101,7 @@
%include "blocks/divide_cc.h"
%include "blocks/float_to_char.h"
%include "blocks/float_to_complex.h"
+%include "blocks/float_to_int.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -144,6 +146,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_complex);
+GR_SWIG_BLOCK_MAGIC2(blocks, float_to_int);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From 86f15ba3488cde9eededa2af5af8dcadc01e9e47 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 26 Jun 2012 06:47:26 -0700
Subject: blocks: added gr::blocks::float_to_short
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_float_to_short.xml | 35 ++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/float_to_short.h | 62 +++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/float_to_short_impl.cc | 69 +++++++++++++++++++++++++++++++
gr-blocks/lib/float_to_short_impl.h | 51 +++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 20 +++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 243 insertions(+)
create mode 100644 gr-blocks/grc/blocks_float_to_short.xml
create mode 100644 gr-blocks/include/blocks/float_to_short.h
create mode 100644 gr-blocks/lib/float_to_short_impl.cc
create mode 100644 gr-blocks/lib/float_to_short_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 169533d34..f73c634a7 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -51,5 +51,6 @@
blocks_float_to_charblocks_float_to_complexblocks_float_to_int
+ blocks_float_to_short
diff --git a/gr-blocks/grc/blocks_float_to_short.xml b/gr-blocks/grc/blocks_float_to_short.xml
new file mode 100644
index 000000000..986e68ec4
--- /dev/null
+++ b/gr-blocks/grc/blocks_float_to_short.xml
@@ -0,0 +1,35 @@
+
+
+
+ Float To Short
+ blocks_float_to_short
+ from gnuradio import blocks
+ blocks.float_to_short($vlen, $scale)
+ set_scale($scale)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Scale
+ scale
+ 1
+ real
+
+
+ in
+ float
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 3171a4d02..bf7ea230a 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -96,6 +96,7 @@ install(FILES
float_to_char.h
float_to_complex.h
float_to_int.h
+ float_to_short.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/float_to_short.h b/gr-blocks/include/blocks/float_to_short.h
new file mode 100644
index 000000000..5f1ab3f95
--- /dev/null
+++ b/gr-blocks/include/blocks/float_to_short.h
@@ -0,0 +1,62 @@
+/* -*- 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_FLOAT_TO_SHORT_H
+#define INCLUDED_BLOCKS_FLOAT_TO_SHORT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of floats to a stream of shorts
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ * \param scale a scalar multiplier to change the output signal scale.
+ */
+ class BLOCKS_API float_to_short : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::float_to_short_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1, float scale=1.0);
+
+ /*!
+ * Get the scalar multiplier value.
+ */
+ virtual float scale() const = 0;
+
+ /*!
+ * Set the scalar multiplier value.
+ */
+ virtual void set_scale(float scale) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_FLOAT_TO_SHORT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index e443d5488..f0f20fb5d 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -131,6 +131,7 @@ list(APPEND gr_blocks_sources
float_to_complex_impl.cc
float_array_to_int.cc
float_to_int_impl.cc
+ float_to_short_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/float_to_short_impl.cc b/gr-blocks/lib/float_to_short_impl.cc
new file mode 100644
index 000000000..2807ae192
--- /dev/null
+++ b/gr-blocks/lib/float_to_short_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 "float_to_short_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ float_to_short::sptr float_to_short::make(size_t vlen, float scale)
+ {
+ return gnuradio::get_initial_sptr(new float_to_short_impl(vlen, scale));
+ }
+
+ float_to_short_impl::float_to_short_impl(size_t vlen, float scale)
+ : gr_sync_block("float_to_short",
+ gr_make_io_signature (1, 1, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(short)*vlen)),
+ d_vlen(vlen), d_scale(scale)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(short);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ float_to_short_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *) input_items[0];
+ short *out = (short *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_32f_s32f_convert_16i_u(out, in, d_scale, d_vlen*noutput_items);
+ }
+ else {
+ volk_32f_s32f_convert_16i_a(out, in, d_scale, d_vlen*noutput_items);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/float_to_short_impl.h b/gr-blocks/lib/float_to_short_impl.h
new file mode 100644
index 000000000..5427862b3
--- /dev/null
+++ b/gr-blocks/lib/float_to_short_impl.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_FLOAT_TO_SHORT_IMPL_H
+#define INCLUDED_FLOAT_TO_SHORT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API float_to_short_impl : public float_to_short
+ {
+ size_t d_vlen;
+ float d_scale;
+
+ public:
+ float_to_short_impl(size_t vlen, float scale);
+
+ virtual float scale() const { return d_scale; }
+ virtual void set_scale(float scale) { d_scale = scale; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_FLOAT_TO_SHORT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index fba38ab00..d41fe690d 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -211,6 +211,26 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_float_to_short_identity(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ expected_data = (1, 2, 3, 4, 5)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_short()
+ dst = gr.vector_sink_s()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(expected_data, dst.data())
+
+ def test_float_to_short_scale(self):
+ src_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ expected_data = (5, 10, 15, 20, 25)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_short(1, 5)
+ 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 593b7ad2d..a0f3039bc 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -56,6 +56,7 @@
#include "blocks/float_to_char.h"
#include "blocks/float_to_complex.h"
#include "blocks/float_to_int.h"
+#include "blocks/float_to_short.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -102,6 +103,7 @@
%include "blocks/float_to_char.h"
%include "blocks/float_to_complex.h"
%include "blocks/float_to_int.h"
+%include "blocks/float_to_short.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -147,6 +149,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, divide_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_int);
+GR_SWIG_BLOCK_MAGIC2(blocks, float_to_short);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From 0b7655a76e5c73b8f5a8310909cf038f12cbb869 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 26 Jun 2012 07:06:53 -0700
Subject: blocks: added gr::blocks::float_to_uchar
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_float_uchar.xml | 20 +++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/float_to_uchar.h | 49 +++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 2 ++
gr-blocks/lib/float_array_to_uchar.cc | 45 +++++++++++++++++++++++
gr-blocks/lib/float_array_to_uchar.h | 33 +++++++++++++++++
gr-blocks/lib/float_to_uchar_impl.cc | 60 +++++++++++++++++++++++++++++++
gr-blocks/lib/float_to_uchar_impl.h | 45 +++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 ++++++
gr-blocks/swig/blocks_swig.i | 3 ++
11 files changed, 269 insertions(+)
create mode 100644 gr-blocks/grc/blocks_float_uchar.xml
create mode 100644 gr-blocks/include/blocks/float_to_uchar.h
create mode 100644 gr-blocks/lib/float_array_to_uchar.cc
create mode 100644 gr-blocks/lib/float_array_to_uchar.h
create mode 100644 gr-blocks/lib/float_to_uchar_impl.cc
create mode 100644 gr-blocks/lib/float_to_uchar_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index f73c634a7..32a81c07a 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -52,5 +52,6 @@
blocks_float_to_complexblocks_float_to_intblocks_float_to_short
+ blocks_float_to_uchar
diff --git a/gr-blocks/grc/blocks_float_uchar.xml b/gr-blocks/grc/blocks_float_uchar.xml
new file mode 100644
index 000000000..d190eafcf
--- /dev/null
+++ b/gr-blocks/grc/blocks_float_uchar.xml
@@ -0,0 +1,20 @@
+
+
+
+ Float To UChar
+ blocks_float_to_uchar
+ from gnuradio import blocks
+ blocks.float_to_uchar()
+
+ in
+ float
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index bf7ea230a..a688168d0 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -97,6 +97,7 @@ install(FILES
float_to_complex.h
float_to_int.h
float_to_short.h
+ float_to_uchar.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/float_to_uchar.h b/gr-blocks/include/blocks/float_to_uchar.h
new file mode 100644
index 000000000..b5d0d08f7
--- /dev/null
+++ b/gr-blocks/include/blocks/float_to_uchar.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_FLOAT_TO_UCHAR_H
+#define INCLUDED_BLOCKS_FLOAT_TO_UCHAR_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of floats to a stream of unsigned chars
+ * \ingroup converter_blk
+ */
+ class BLOCKS_API float_to_uchar : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::float_to_uchar_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make();
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_FLOAT_TO_UCHAR_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index f0f20fb5d..a6894f256 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -132,6 +132,8 @@ list(APPEND gr_blocks_sources
float_array_to_int.cc
float_to_int_impl.cc
float_to_short_impl.cc
+ float_array_to_uchar.cc
+ float_to_uchar_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/float_array_to_uchar.cc b/gr-blocks/lib/float_array_to_uchar.cc
new file mode 100644
index 000000000..06688e7b0
--- /dev/null
+++ b/gr-blocks/lib/float_array_to_uchar.cc
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002,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
+#endif
+
+#define _ISOC9X_SOURCE
+#include
+#include
+
+static const int MIN_UCHAR = 0;
+static const int MAX_UCHAR = 255;
+
+void
+float_array_to_uchar(const float *in, unsigned char *out, int nsamples)
+{
+ for (int i = 0; i < nsamples; i++){
+ long int r = (long int) rint (in[i]);
+ if (r < MIN_UCHAR)
+ r = MIN_UCHAR;
+ else if (r > MAX_UCHAR)
+ r = MAX_UCHAR;
+ out[i] = r;
+ }
+}
diff --git a/gr-blocks/lib/float_array_to_uchar.h b/gr-blocks/lib/float_array_to_uchar.h
new file mode 100644
index 000000000..defed8e3e
--- /dev/null
+++ b/gr-blocks/lib/float_array_to_uchar.h
@@ -0,0 +1,33 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002,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_FLOAT_ARRAY_TO_UCHAR_H
+#define INCLUDED_FLOAT_ARRAY_TO_UCHAR_H
+
+#include
+
+/*!
+ * convert array of floats to unsigned chars with rounding and saturation.
+ */
+BLOCKS_API void float_array_to_uchar (const float *in, unsigned char *out, int nsamples);
+
+#endif /* INCLUDED_FLOAT_ARRAY_TO_UCHAR_H */
diff --git a/gr-blocks/lib/float_to_uchar_impl.cc b/gr-blocks/lib/float_to_uchar_impl.cc
new file mode 100644
index 000000000..22d0527b1
--- /dev/null
+++ b/gr-blocks/lib/float_to_uchar_impl.cc
@@ -0,0 +1,60 @@
+/* -*- 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 "float_to_uchar_impl.h"
+#include "float_array_to_uchar.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ float_to_uchar::sptr float_to_uchar::make()
+ {
+ return gnuradio::get_initial_sptr(new float_to_uchar_impl());
+ }
+
+ float_to_uchar_impl::float_to_uchar_impl()
+ : gr_sync_block("float_to_uchar",
+ gr_make_io_signature (1, 1, sizeof(float)),
+ gr_make_io_signature (1, 1, sizeof(unsigned char)))
+ {
+ }
+
+ int
+ float_to_uchar_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *)input_items[0];
+ unsigned char *out = (unsigned char *)output_items[0];
+
+ float_array_to_uchar(in, out, noutput_items);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/float_to_uchar_impl.h b/gr-blocks/lib/float_to_uchar_impl.h
new file mode 100644
index 000000000..effd66c5c
--- /dev/null
+++ b/gr-blocks/lib/float_to_uchar_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_FLOAT_TO_UCHAR_IMPL_H
+#define INCLUDED_FLOAT_TO_UCHAR_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API float_to_uchar_impl : public float_to_uchar
+ {
+ public:
+ float_to_uchar_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_FLOAT_TO_UCHAR_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index d41fe690d..a97203566 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -231,6 +231,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_float_to_uchar(self):
+ src_data = (1.0, -2.0, 3.0, -4.0, 256.0)
+ expected_data = (1, 0, 3, 0, 255)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.float_to_uchar()
+ 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 a0f3039bc..acf0fe26f 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -57,6 +57,7 @@
#include "blocks/float_to_complex.h"
#include "blocks/float_to_int.h"
#include "blocks/float_to_short.h"
+#include "blocks/float_to_uchar.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -104,6 +105,7 @@
%include "blocks/float_to_complex.h"
%include "blocks/float_to_int.h"
%include "blocks/float_to_short.h"
+%include "blocks/float_to_uchar.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -150,6 +152,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, float_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_int);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_short);
+GR_SWIG_BLOCK_MAGIC2(blocks, float_to_uchar);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From 3de0c77ed91e417c0b54972a78ffbad62f4bbb87 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 26 Jun 2012 19:43:01 -0700
Subject: blocks: added gr::blocks::float_to_int
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_int_to_float.xml | 35 +++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/int_to_float.h | 62 ++++++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/int_to_float_impl.cc | 68 +++++++++++++++++++++++++++++++++
gr-blocks/lib/int_to_float_impl.h | 51 +++++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 20 ++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 242 insertions(+)
create mode 100644 gr-blocks/grc/blocks_int_to_float.xml
create mode 100644 gr-blocks/include/blocks/int_to_float.h
create mode 100644 gr-blocks/lib/int_to_float_impl.cc
create mode 100644 gr-blocks/lib/int_to_float_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 32a81c07a..68135b924 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -53,5 +53,6 @@
blocks_float_to_intblocks_float_to_shortblocks_float_to_uchar
+ blocks_int_to_float
diff --git a/gr-blocks/grc/blocks_int_to_float.xml b/gr-blocks/grc/blocks_int_to_float.xml
new file mode 100644
index 000000000..2bb25d8be
--- /dev/null
+++ b/gr-blocks/grc/blocks_int_to_float.xml
@@ -0,0 +1,35 @@
+
+
+
+ Int To Float
+ blocks_int_to_float
+ from gnuradio import blocks
+ blocks.int_to_float($vlen, $scale)
+ set_scale($scale)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Scale
+ scale
+ 1
+ real
+
+
+ in
+ int
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index a688168d0..e56c7b87c 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -98,6 +98,7 @@ install(FILES
float_to_int.h
float_to_short.h
float_to_uchar.h
+ int_to_float.h
multiply_cc.h
multiply_ff.h
multiply_const_cc.h
diff --git a/gr-blocks/include/blocks/int_to_float.h b/gr-blocks/include/blocks/int_to_float.h
new file mode 100644
index 000000000..ebee1c3c9
--- /dev/null
+++ b/gr-blocks/include/blocks/int_to_float.h
@@ -0,0 +1,62 @@
+/* -*- 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_INT_TO_FLOAT_H
+#define INCLUDED_BLOCKS_INT_TO_FLOAT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of ints to a stream of floats
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ * \param scale a scalar divider to change the output signal scale.
+ */
+ class BLOCKS_API int_to_float : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::int_to_float_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1, float scale=1.0);
+
+ /*!
+ * Get the scalar divider value.
+ */
+ virtual float scale() const = 0;
+
+ /*!
+ * Set the scalar divider value.
+ */
+ virtual void set_scale(float scale) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_INT_TO_FLOAT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index a6894f256..16656dafc 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -134,6 +134,7 @@ list(APPEND gr_blocks_sources
float_to_short_impl.cc
float_array_to_uchar.cc
float_to_uchar_impl.cc
+ int_to_float_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/int_to_float_impl.cc b/gr-blocks/lib/int_to_float_impl.cc
new file mode 100644
index 000000000..0190d7ccb
--- /dev/null
+++ b/gr-blocks/lib/int_to_float_impl.cc
@@ -0,0 +1,68 @@
+/* -*- 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 "int_to_float_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ int_to_float::sptr int_to_float::make(size_t vlen, float scale)
+ {
+ return gnuradio::get_initial_sptr(new int_to_float_impl(vlen, scale));
+ }
+
+ int_to_float_impl::int_to_float_impl(size_t vlen, float scale)
+ : gr_sync_block("int_to_float",
+ gr_make_io_signature (1, 1, sizeof(int32_t)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen), d_scale(scale)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ int_to_float_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const int32_t *in = (const int32_t *) input_items[0];
+ float *out = (float *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_32i_s32f_convert_32f_u(out, in, d_scale, d_vlen*noutput_items);
+ }
+ else {
+ volk_32i_s32f_convert_32f_a(out, in, d_scale, d_vlen*noutput_items);
+ }
+
+ return noutput_items;
+ }
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/int_to_float_impl.h b/gr-blocks/lib/int_to_float_impl.h
new file mode 100644
index 000000000..7498a0bb1
--- /dev/null
+++ b/gr-blocks/lib/int_to_float_impl.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_INT_TO_FLOAT_IMPL_H
+#define INCLUDED_INT_TO_FLOAT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API int_to_float_impl : public int_to_float
+ {
+ size_t d_vlen;
+ float d_scale;
+
+ public:
+ int_to_float_impl(size_t vlen, float scale);
+
+ virtual float scale() const { return d_scale; }
+ virtual void set_scale(float scale) { d_scale = scale; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_INT_TO_FLOAT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index a97203566..354cf9392 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -241,6 +241,26 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_int_to_float_identity(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src = gr.vector_source_i(src_data)
+ op = blocks_swig.int_to_float()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+
+ def test_int_to_float_scale(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (0.2, 0.4, 0.6, 0.8, 1.0)
+ src = gr.vector_source_i(src_data)
+ op = blocks_swig.int_to_float(1, 5)
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(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 acf0fe26f..1a903e128 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -58,6 +58,7 @@
#include "blocks/float_to_int.h"
#include "blocks/float_to_short.h"
#include "blocks/float_to_uchar.h"
+#include "blocks/int_to_float.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -106,6 +107,7 @@
%include "blocks/float_to_int.h"
%include "blocks/float_to_short.h"
%include "blocks/float_to_uchar.h"
+%include "blocks/int_to_float.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -153,6 +155,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, float_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_int);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_short);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_uchar);
+GR_SWIG_BLOCK_MAGIC2(blocks, int_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From be1219b0623bbceb5bca6a6f6774f0669f52bdde Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Wed, 27 Jun 2012 06:50:22 -0700
Subject: blocks: added gr::blocks::interleaved_short_to_complex
---
gr-blocks/grc/blocks_block_tree.xml | 5 +-
.../grc/blocks_interleaved_short_to_complex.xml | 20 +++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
.../include/blocks/complex_to_interleaved_short.h | 2 +-
.../include/blocks/interleaved_short_to_complex.h | 49 +++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 2 +
.../lib/interleaved_short_array_to_complex.cc | 39 ++++++++++++++
gr-blocks/lib/interleaved_short_array_to_complex.h | 36 +++++++++++++
gr-blocks/lib/interleaved_short_to_complex_impl.cc | 61 ++++++++++++++++++++++
gr-blocks/lib/interleaved_short_to_complex_impl.h | 45 ++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 ++++
gr-blocks/swig/blocks_swig.i | 3 ++
12 files changed, 270 insertions(+), 3 deletions(-)
create mode 100644 gr-blocks/grc/blocks_interleaved_short_to_complex.xml
create mode 100644 gr-blocks/include/blocks/interleaved_short_to_complex.h
create mode 100644 gr-blocks/lib/interleaved_short_array_to_complex.cc
create mode 100644 gr-blocks/lib/interleaved_short_array_to_complex.h
create mode 100644 gr-blocks/lib/interleaved_short_to_complex_impl.cc
create mode 100644 gr-blocks/lib/interleaved_short_to_complex_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 68135b924..9a56d4c41 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -29,7 +29,7 @@
- Math Operations
+ Math Operations (New) blocks_add_xxblocks_add_const_vxxblocks_divide_xx
@@ -38,7 +38,7 @@
blocks_sub_xx
- Stream Type Conversions
+ Stream Type Conversions (New) blocks_char_to_floatblocks_char_to_shortblocks_complex_to_interleaved_short
@@ -54,5 +54,6 @@
blocks_float_to_shortblocks_float_to_ucharblocks_int_to_float
+ blocks_interleaved_short_to_complex
diff --git a/gr-blocks/grc/blocks_interleaved_short_to_complex.xml b/gr-blocks/grc/blocks_interleaved_short_to_complex.xml
new file mode 100644
index 000000000..e44113e74
--- /dev/null
+++ b/gr-blocks/grc/blocks_interleaved_short_to_complex.xml
@@ -0,0 +1,20 @@
+
+
+
+ IShort To Complex
+ blocks_interleaved_short_to_complex
+ from gnuradio import blocks
+ blocks.interleaved_short_to_complex()
+
+ in
+ short
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index e56c7b87c..9616db3a6 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -99,6 +99,7 @@ install(FILES
float_to_short.h
float_to_uchar.h
int_to_float.h
+ interleaved_complex_to_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
index 33cbddf6b..f5e91123c 100644
--- a/gr-blocks/include/blocks/complex_to_interleaved_short.h
+++ b/gr-blocks/include/blocks/complex_to_interleaved_short.h
@@ -37,7 +37,7 @@ namespace gr {
{
public:
- // gr::blocks::complex_to_interleaved_short_ff::sptr
+ // gr::blocks::complex_to_interleaved_short::sptr
typedef boost::shared_ptr sptr;
static sptr make();
diff --git a/gr-blocks/include/blocks/interleaved_short_to_complex.h b/gr-blocks/include/blocks/interleaved_short_to_complex.h
new file mode 100644
index 000000000..40e96fc46
--- /dev/null
+++ b/gr-blocks/include/blocks/interleaved_short_to_complex.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_INTERLEAVED_SHORT_TO_COMPLEX_H
+#define INCLUDED_BLOCKS_INTERLEAVED_SHORT_TO_COMPLEX_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of interleaved shorts to a stream of complex
+ * \ingroup converter_blk
+ */
+ class BLOCKS_API interleaved_short_to_complex : virtual public gr_sync_decimator
+ {
+ public:
+
+ // gr::blocks::interleaved_short_to_complex::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make();
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_INTERLEAVED_SHORT_TO_COMPLEX_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 16656dafc..21b17d315 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -135,6 +135,8 @@ list(APPEND gr_blocks_sources
float_array_to_uchar.cc
float_to_uchar_impl.cc
int_to_float_impl.cc
+ interleaved_short_array_to_complex.cc
+ interleaved_short_to_complex_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_const_cc_impl.cc
diff --git a/gr-blocks/lib/interleaved_short_array_to_complex.cc b/gr-blocks/lib/interleaved_short_array_to_complex.cc
new file mode 100644
index 000000000..eb6431b7a
--- /dev/null
+++ b/gr-blocks/lib/interleaved_short_array_to_complex.cc
@@ -0,0 +1,39 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2002,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 "interleaved_short_array_to_complex.h"
+#include
+
+void
+interleaved_short_array_to_complex (const short *in,
+ gr_complex *out, int nsamples)
+{
+ assert (nsamples % 2 == 0);
+
+ for (int i = 0; i < nsamples/2; i++){
+ out[i] = gr_complex (in[i*2 + 0], in[i*2 + 1]);
+ }
+}
diff --git a/gr-blocks/lib/interleaved_short_array_to_complex.h b/gr-blocks/lib/interleaved_short_array_to_complex.h
new file mode 100644
index 000000000..3f20fdb98
--- /dev/null
+++ b/gr-blocks/lib/interleaved_short_array_to_complex.h
@@ -0,0 +1,36 @@
+/* -*- 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_INTERLEAVED_SHORT_ARRAY_TO_COMPLEX_H
+#define INCLUDED_INTERLEAVED_SHORT_ARRAY_TO_COMPLEX_H
+
+#include
+#include
+
+/*
+ * convert array of interleaved shorts to complex.
+ * the shorts contains real, imaginary, real, imaginary...
+ * nsamples is the number of shorts; it must be even.
+ */
+BLOCKS_API void interleaved_short_array_to_complex (const short *in, gr_complex *out, int nsamples);
+
+#endif /* INCLUDED_INTERLEAVED_SHORT_ARRAY_TO_COMPLEX_H */
diff --git a/gr-blocks/lib/interleaved_short_to_complex_impl.cc b/gr-blocks/lib/interleaved_short_to_complex_impl.cc
new file mode 100644
index 000000000..1be6fdc9d
--- /dev/null
+++ b/gr-blocks/lib/interleaved_short_to_complex_impl.cc
@@ -0,0 +1,61 @@
+/* -*- 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 "interleaved_short_to_complex_impl.h"
+#include "interleaved_short_array_to_complex.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ interleaved_short_to_complex::sptr interleaved_short_to_complex::make()
+ {
+ return gnuradio::get_initial_sptr(new interleaved_short_to_complex_impl());
+ }
+
+ interleaved_short_to_complex_impl::interleaved_short_to_complex_impl()
+ : gr_sync_decimator("interleaved_short_to_complex",
+ gr_make_io_signature (1, 1, sizeof(short)),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)),
+ 2)
+ {
+ }
+
+ int
+ interleaved_short_to_complex_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const short *in = (const short *) input_items[0];
+ gr_complex *out = (gr_complex *) output_items[0];
+
+ interleaved_short_array_to_complex (in, out, 2 * noutput_items);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/interleaved_short_to_complex_impl.h b/gr-blocks/lib/interleaved_short_to_complex_impl.h
new file mode 100644
index 000000000..62a1db308
--- /dev/null
+++ b/gr-blocks/lib/interleaved_short_to_complex_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_INTERLEAVED_SHORT_TO_COMPLEX_IMPL_H
+#define INCLUDED_INTERLEAVED_SHORT_TO_COMPLEX_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API interleaved_short_to_complex_impl : public interleaved_short_to_complex
+ {
+ public:
+ interleaved_short_to_complex_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_INTERLEAVED_SHORT_TO_COMPLEX_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index 354cf9392..92e0a7ca4 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -261,6 +261,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertFloatTuplesAlmostEqual(expected_data, dst.data())
+ def test_interleaved_short_to_complex(self):
+ src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ expected_data = (1+2j, 3+4j, 5+6j, 7+8j, 9+10j)
+ src = gr.vector_source_s(src_data)
+ op = blocks_swig.interleaved_short_to_complex()
+ dst = gr.vector_sink_c()
+ 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 1a903e128..0545a833c 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -59,6 +59,7 @@
#include "blocks/float_to_short.h"
#include "blocks/float_to_uchar.h"
#include "blocks/int_to_float.h"
+#include "blocks/interleaved_short_to_complex.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -108,6 +109,7 @@
%include "blocks/float_to_short.h"
%include "blocks/float_to_uchar.h"
%include "blocks/int_to_float.h"
+%include "blocks/interleaved_short_to_complex.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -156,6 +158,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, float_to_int);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_short);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_uchar);
GR_SWIG_BLOCK_MAGIC2(blocks, int_to_float);
+GR_SWIG_BLOCK_MAGIC2(blocks, interleaved_short_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From c128e5aee66838c849ffc2ac45217ff1efab42e8 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 28 Jun 2012 09:02:58 -0700
Subject: blocks: added gr::blocks::short_to_char
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_short_to_char.xml | 28 +++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 3 +-
gr-blocks/include/blocks/short_to_char.h | 51 +++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/short_to_char_impl.cc | 69 ++++++++++++++++++++++++++++++++
gr-blocks/lib/short_to_char_impl.h | 47 ++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 +++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 212 insertions(+), 1 deletion(-)
create mode 100644 gr-blocks/grc/blocks_short_to_char.xml
create mode 100644 gr-blocks/include/blocks/short_to_char.h
create mode 100644 gr-blocks/lib/short_to_char_impl.cc
create mode 100644 gr-blocks/lib/short_to_char_impl.h
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 @@
blocks_float_to_ucharblocks_int_to_floatblocks_interleaved_short_to_complex
+ blocks_short_to_char
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 @@
+
+
+
+ Short To Char
+ blocks_short_to_char
+ from gnuradio import blocks
+ blocks.short_to_char($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ in
+ short
+ $vlen
+
+
+
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
+#include
+
+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 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
+#include
+
+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
+
+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);
--
cgit
From 9482c8986d0a7bd4772a78972880a9e574531052 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 28 Jun 2012 09:27:59 -0700
Subject: blocks: added gr::blocks::short_to_float
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_short_to_float.xml | 35 ++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/short_to_float.h | 62 ++++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/short_to_float_impl.cc | 68 +++++++++++++++++++++++++++++++
gr-blocks/lib/short_to_float_impl.h | 51 +++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 20 +++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 242 insertions(+)
create mode 100644 gr-blocks/grc/blocks_short_to_float.xml
create mode 100644 gr-blocks/include/blocks/short_to_float.h
create mode 100644 gr-blocks/lib/short_to_float_impl.cc
create mode 100644 gr-blocks/lib/short_to_float_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 64af22cfd..f277706f6 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -56,5 +56,6 @@
blocks_int_to_floatblocks_interleaved_short_to_complexblocks_short_to_char
+ blocks_short_to_float
diff --git a/gr-blocks/grc/blocks_short_to_float.xml b/gr-blocks/grc/blocks_short_to_float.xml
new file mode 100644
index 000000000..23ea019bc
--- /dev/null
+++ b/gr-blocks/grc/blocks_short_to_float.xml
@@ -0,0 +1,35 @@
+
+
+
+ Short To Float
+ blocks_short_to_float
+ from gnuradio import blocks
+ blocks.short_to_float($vlen, $scale)
+ set_scale($scale)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+
+ Scale
+ scale
+ 1
+ real
+
+
+ in
+ short
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 00df9511e..8c39acb81 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -105,6 +105,7 @@ install(FILES
multiply_const_cc.h
multiply_const_ff.h
short_to_char.h
+ short_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/short_to_float.h b/gr-blocks/include/blocks/short_to_float.h
new file mode 100644
index 000000000..c26addcd0
--- /dev/null
+++ b/gr-blocks/include/blocks/short_to_float.h
@@ -0,0 +1,62 @@
+/* -*- 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_FLOAT_H
+#define INCLUDED_BLOCKS_SHORT_TO_FLOAT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of shorts to a stream of floats
+ * \ingroup converter_blk
+ *
+ * \param vlen vector length of data streams.
+ * \param scale a scalar divider to change the output signal scale.
+ */
+ class BLOCKS_API short_to_float : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::short_to_float_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t vlen=1, float scale=1.0);
+
+ /*!
+ * Get the scalar divider value.
+ */
+ virtual float scale() const = 0;
+
+ /*!
+ * Set the scalar divider value.
+ */
+ virtual void set_scale(float scale) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_SHORT_TO_FLOAT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 458a63221..4551baeca 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -142,6 +142,7 @@ list(APPEND gr_blocks_sources
multiply_const_cc_impl.cc
multiply_const_ff_impl.cc
short_to_char_impl.cc
+ short_to_float_impl.cc
)
list(APPEND blocks_libs
diff --git a/gr-blocks/lib/short_to_float_impl.cc b/gr-blocks/lib/short_to_float_impl.cc
new file mode 100644
index 000000000..618601816
--- /dev/null
+++ b/gr-blocks/lib/short_to_float_impl.cc
@@ -0,0 +1,68 @@
+/* -*- 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_float_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ short_to_float::sptr short_to_float::make(size_t vlen, float scale)
+ {
+ return gnuradio::get_initial_sptr(new short_to_float_impl(vlen, scale));
+ }
+
+ short_to_float_impl::short_to_float_impl(size_t vlen, float scale)
+ : gr_sync_block("short_to_float",
+ gr_make_io_signature (1, 1, sizeof(short)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_vlen(vlen), d_scale(scale)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(float);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ short_to_float_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const short *in = (const short *) input_items[0];
+ float *out = (float *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_16i_s32f_convert_32f_u(out, in, d_scale, d_vlen*noutput_items);
+ }
+ else {
+ volk_16i_s32f_convert_32f_a(out, in, d_scale, d_vlen*noutput_items);
+ }
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/short_to_float_impl.h b/gr-blocks/lib/short_to_float_impl.h
new file mode 100644
index 000000000..c36b42a8c
--- /dev/null
+++ b/gr-blocks/lib/short_to_float_impl.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_SHORT_TO_FLOAT_IMPL_H
+#define INCLUDED_SHORT_TO_FLOAT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API short_to_float_impl : public short_to_float
+ {
+ size_t d_vlen;
+ float d_scale;
+
+ public:
+ short_to_float_impl(size_t vlen, float scale);
+
+ virtual float scale() const { return d_scale; }
+ virtual void set_scale(float scale) { d_scale = scale; }
+
+ 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_FLOAT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index ddb876b3d..a77fe8af5 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -281,6 +281,26 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_short_to_float_identity(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src = gr.vector_source_s(src_data)
+ op = blocks_swig.short_to_float()
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(expected_data, dst.data())
+
+ def test_short_to_float_scale(self):
+ src_data = (5, 10, 15, 20, 25)
+ expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src = gr.vector_source_s(src_data)
+ op = blocks_swig.short_to_float(1, 5)
+ dst = gr.vector_sink_f()
+ 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 6cb680314..62ee25742 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -73,6 +73,7 @@
#include "blocks/multiply_const_vff.h"
#include "blocks/multiply_const_vcc.h"
#include "blocks/short_to_char.h"
+#include "blocks/short_to_float.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -124,6 +125,7 @@
%include "blocks/multiply_const_vff.h"
%include "blocks/multiply_const_vcc.h"
%include "blocks/short_to_char.h"
+%include "blocks/short_to_float.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -174,6 +176,7 @@ 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, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit
From a3b74a25fcba67f61bf3cabb25286201f1263b0a Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 28 Jun 2012 09:46:38 -0700
Subject: blocks: added gr::blocks::uchar_to_float
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_uchar_to_float.xml | 20 +++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/uchar_to_float.h | 49 +++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 2 ++
gr-blocks/lib/uchar_array_to_float.cc | 40 +++++++++++++++++++++
gr-blocks/lib/uchar_array_to_float.h | 34 ++++++++++++++++++
gr-blocks/lib/uchar_to_float_impl.cc | 60 +++++++++++++++++++++++++++++++
gr-blocks/lib/uchar_to_float_impl.h | 45 +++++++++++++++++++++++
gr-blocks/python/qa_type_conversions.py | 10 ++++++
gr-blocks/swig/blocks_swig.i | 3 ++
11 files changed, 265 insertions(+)
create mode 100644 gr-blocks/grc/blocks_uchar_to_float.xml
create mode 100644 gr-blocks/include/blocks/uchar_to_float.h
create mode 100644 gr-blocks/lib/uchar_array_to_float.cc
create mode 100644 gr-blocks/lib/uchar_array_to_float.h
create mode 100644 gr-blocks/lib/uchar_to_float_impl.cc
create mode 100644 gr-blocks/lib/uchar_to_float_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index f277706f6..d32147987 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -57,5 +57,6 @@
blocks_interleaved_short_to_complexblocks_short_to_charblocks_short_to_float
+ blocks_uchar_to_float
diff --git a/gr-blocks/grc/blocks_uchar_to_float.xml b/gr-blocks/grc/blocks_uchar_to_float.xml
new file mode 100644
index 000000000..eb2b5505e
--- /dev/null
+++ b/gr-blocks/grc/blocks_uchar_to_float.xml
@@ -0,0 +1,20 @@
+
+
+
+ UChar To Float
+ blocks_uchar_to_float
+ from gnuradio import blocks
+ blocks.uchar_to_float()
+
+ in
+ byte
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 8c39acb81..7cd8a5483 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -106,6 +106,7 @@ install(FILES
multiply_const_ff.h
short_to_char.h
short_to_float.h
+ uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/uchar_to_float.h b/gr-blocks/include/blocks/uchar_to_float.h
new file mode 100644
index 000000000..033037e49
--- /dev/null
+++ b/gr-blocks/include/blocks/uchar_to_float.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_UCHAR_TO_FLOAT_H
+#define INCLUDED_BLOCKS_UCHAR_TO_FLOAT_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert stream of unsigned chars to a stream of floats
+ * \ingroup converter_blk
+ */
+ class BLOCKS_API uchar_to_float : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::uchar_to_float_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make();
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_UCHAR_TO_FLOAT_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 4551baeca..6974e7e92 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -143,6 +143,8 @@ list(APPEND gr_blocks_sources
multiply_const_ff_impl.cc
short_to_char_impl.cc
short_to_float_impl.cc
+ uchar_array_to_float.cc
+ uchar_to_float_impl.cc
)
list(APPEND blocks_libs
diff --git a/gr-blocks/lib/uchar_array_to_float.cc b/gr-blocks/lib/uchar_array_to_float.cc
new file mode 100644
index 000000000..90cc0fca3
--- /dev/null
+++ b/gr-blocks/lib/uchar_array_to_float.cc
@@ -0,0 +1,40 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,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.
+ */
+
+#include
+
+void
+uchar_array_to_float (const unsigned char *in, float *out, int nsamples)
+{
+ while (nsamples >= 4){
+ out[0] = in[0];
+ out[1] = in[1];
+ out[2] = in[2];
+ out[3] = in[3];
+ out += 4;
+ in += 4;
+ nsamples -= 4;
+ }
+
+ while (nsamples-- > 0)
+ *out++ = *in++;
+}
diff --git a/gr-blocks/lib/uchar_array_to_float.h b/gr-blocks/lib/uchar_array_to_float.h
new file mode 100644
index 000000000..e6772c2a8
--- /dev/null
+++ b/gr-blocks/lib/uchar_array_to_float.h
@@ -0,0 +1,34 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005, 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_UCHAR_ARRAY_TO_FLOAT_H
+#define INCLUDED_UCHAR_ARRAY_TO_FLOAT_H
+
+#include
+
+/*
+ * convert array of unsigned chars to floats
+ */
+BLOCKS_API void uchar_array_to_float (const unsigned char *in, float *out, int nsamples);
+
+
+#endif /* INCLUDED_UCHAR_ARRAY_TO_FLOAT_H */
diff --git a/gr-blocks/lib/uchar_to_float_impl.cc b/gr-blocks/lib/uchar_to_float_impl.cc
new file mode 100644
index 000000000..608c05ad4
--- /dev/null
+++ b/gr-blocks/lib/uchar_to_float_impl.cc
@@ -0,0 +1,60 @@
+/* -*- 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 "uchar_to_float_impl.h"
+#include "uchar_array_to_float.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ uchar_to_float::sptr uchar_to_float::make()
+ {
+ return gnuradio::get_initial_sptr(new uchar_to_float_impl());
+ }
+
+ uchar_to_float_impl::uchar_to_float_impl()
+ : gr_sync_block("uchar_to_float",
+ gr_make_io_signature (1, 1, sizeof(unsigned char)),
+ gr_make_io_signature (1, 1, sizeof(float)))
+ {
+ }
+
+ int
+ uchar_to_float_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const unsigned char *in = (const unsigned char *) input_items[0];
+ float *out = (float *) output_items[0];
+
+ uchar_array_to_float (in, out, noutput_items);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/uchar_to_float_impl.h b/gr-blocks/lib/uchar_to_float_impl.h
new file mode 100644
index 000000000..250dc2c86
--- /dev/null
+++ b/gr-blocks/lib/uchar_to_float_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_UCHAR_TO_FLOAT_IMPL_H
+#define INCLUDED_UCHAR_TO_FLOAT_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API uchar_to_float_impl : public uchar_to_float
+ {
+ public:
+ uchar_to_float_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_UCHAR_TO_FLOAT_IMPL_H */
diff --git a/gr-blocks/python/qa_type_conversions.py b/gr-blocks/python/qa_type_conversions.py
index a77fe8af5..eb1b42b63 100755
--- a/gr-blocks/python/qa_type_conversions.py
+++ b/gr-blocks/python/qa_type_conversions.py
@@ -301,6 +301,16 @@ class test_type_conversions(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_data, dst.data())
+ def test_uchar_to_float(self):
+ src_data = (1, 2, 3, 4, 5)
+ expected_data = (1.0, 2.0, 3.0, 4.0, 5.0)
+ src = gr.vector_source_b(src_data)
+ op = blocks_swig.uchar_to_float()
+ dst = gr.vector_sink_f()
+ 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 62ee25742..097f8be70 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -78,6 +78,7 @@
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
#include "blocks/sub_cc.h"
+#include "blocks/uchar_to_float.h"
%}
%include "blocks/add_ff.h"
@@ -130,6 +131,7 @@
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
%include "blocks/sub_cc.h"
+%include "blocks/uchar_to_float.h"
GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
@@ -181,3 +183,4 @@ GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float);
--
cgit
From f2e815329402f170231c054e108b531094d046be Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 29 Jun 2012 08:10:15 -0700
Subject: blocks: added gr::blocks::conjugate_cc
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_conjugate_cc.xml | 20 ++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/conjugate_cc.h | 49 ++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/conjugate_cc_impl.cc | 68 +++++++++++++++++++++++++++++++++
gr-blocks/lib/conjugate_cc_impl.h | 44 +++++++++++++++++++++
gr-blocks/python/qa_conjugate.py | 54 ++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 241 insertions(+)
create mode 100644 gr-blocks/grc/blocks_conjugate_cc.xml
create mode 100644 gr-blocks/include/blocks/conjugate_cc.h
create mode 100644 gr-blocks/lib/conjugate_cc_impl.cc
create mode 100644 gr-blocks/lib/conjugate_cc_impl.h
create mode 100644 gr-blocks/python/qa_conjugate.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index d32147987..197daa0f6 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -36,6 +36,7 @@
blocks_multiply_xxblocks_multiply_const_vxxblocks_sub_xx
+ blocks_conjugate_ccStream Type Conversions (New)
diff --git a/gr-blocks/grc/blocks_conjugate_cc.xml b/gr-blocks/grc/blocks_conjugate_cc.xml
new file mode 100644
index 000000000..152f797b2
--- /dev/null
+++ b/gr-blocks/grc/blocks_conjugate_cc.xml
@@ -0,0 +1,20 @@
+
+
+
+ Complex Conjugate
+ blocks_conjugate_cc
+ from gnuradio import blocks
+ blocks.conjugate_cc()
+
+ in
+ complex
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 7cd8a5483..3110e2abb 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -93,6 +93,7 @@ install(FILES
complex_to_mag.h
complex_to_mag_squared.h
complex_to_arg.h
+ conjugate_cc.h
float_to_char.h
float_to_complex.h
float_to_int.h
diff --git a/gr-blocks/include/blocks/conjugate_cc.h b/gr-blocks/include/blocks/conjugate_cc.h
new file mode 100644
index 000000000..02297c56e
--- /dev/null
+++ b/gr-blocks/include/blocks/conjugate_cc.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_CONJUGATE_CC_H
+#define INCLUDED_BLOCKS_CONJUGATE_CC_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = complex conjugate of input
+ * \ingroup math_blk
+ */
+ class BLOCKS_API conjugate_cc : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::conjugate_cc_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make();
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_CONJUGATE_CC_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 6974e7e92..8d433801d 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -127,6 +127,7 @@ list(APPEND gr_blocks_sources
complex_to_mag_impl.cc
complex_to_mag_squared_impl.cc
complex_to_arg_impl.cc
+ conjugate_cc_impl.cc
float_to_char_impl.cc
float_to_complex_impl.cc
float_array_to_int.cc
diff --git a/gr-blocks/lib/conjugate_cc_impl.cc b/gr-blocks/lib/conjugate_cc_impl.cc
new file mode 100644
index 000000000..3d46bef68
--- /dev/null
+++ b/gr-blocks/lib/conjugate_cc_impl.cc
@@ -0,0 +1,68 @@
+/* -*- 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 "conjugate_cc_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ conjugate_cc::sptr conjugate_cc::make()
+ {
+ return gnuradio::get_initial_sptr(new conjugate_cc_impl());
+ }
+
+ conjugate_cc_impl::conjugate_cc_impl()
+ : gr_sync_block("conjugate_cc",
+ gr_make_io_signature (1, 1, sizeof(gr_complex)),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)))
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ conjugate_cc_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gr_complex *iptr = (gr_complex *) input_items[0];
+ gr_complex *optr = (gr_complex *) output_items[0];
+
+ if(is_unaligned()) {
+ volk_32fc_conjugate_32fc_u(optr, iptr, noutput_items);
+ }
+ else {
+ volk_32fc_conjugate_32fc_a(optr, iptr, noutput_items);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/conjugate_cc_impl.h b/gr-blocks/lib/conjugate_cc_impl.h
new file mode 100644
index 000000000..448e7b318
--- /dev/null
+++ b/gr-blocks/lib/conjugate_cc_impl.h
@@ -0,0 +1,44 @@
+/* -*- 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_CONJUGATE_CC_IMPL_H
+#define INCLUDED_CONJUGATE_CC_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API conjugate_cc_impl : public conjugate_cc
+ {
+ public:
+ conjugate_cc_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_CONJUGATE_CC_IMPL_H */
diff --git a/gr-blocks/python/qa_conjugate.py b/gr-blocks/python/qa_conjugate.py
new file mode 100644
index 000000000..1808aa9c0
--- /dev/null
+++ b/gr-blocks/python/qa_conjugate.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig
+
+class test_conjugate (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def test_000 (self):
+ src_data = (-2-2j, -1-1j, -2+2j, -1+1j,
+ 2-2j, 1-1j, 2+2j, 1+1j,
+ 0+0j)
+
+ exp_data = (-2+2j, -1+1j, -2-2j, -1-1j,
+ 2+2j, 1+1j, 2-2j, 1-1j,
+ 0-0j)
+
+ src = gr.vector_source_c(src_data)
+ op = blocks_swig.conjugate_cc ()
+ dst = gr.vector_sink_c ()
+
+ self.tb.connect(src, op)
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data ()
+ self.assertEqual (exp_data, result_data)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_conjugate, "test_conjugate.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 097f8be70..cfd9d9db1 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -49,6 +49,7 @@
#include "blocks/complex_to_mag.h"
#include "blocks/complex_to_mag_squared.h"
#include "blocks/complex_to_arg.h"
+#include "blocks/conjugate_cc.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -102,6 +103,7 @@
%include "blocks/complex_to_mag.h"
%include "blocks/complex_to_mag_squared.h"
%include "blocks/complex_to_arg.h"
+%include "blocks/conjugate_cc.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -154,6 +156,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_imag);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag_squared);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_arg);
+GR_SWIG_BLOCK_MAGIC2(blocks, conjugate_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From bfcc9dc634cc8d7da77b109a7ad9cd90714fd768 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 29 Jun 2012 08:30:23 -0700
Subject: blocks: added gr::blocks::integrate_XX with ss ii ff cc
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_integrate_xx.xml | 50 ++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/integrate_XX.h.t | 51 +++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/integrate_XX_impl.cc.t | 68 +++++++++++++++++++++++++++
gr-blocks/lib/integrate_XX_impl.h.t | 49 ++++++++++++++++++++
gr-blocks/python/qa_integrate.py | 76 +++++++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 12 +++++
9 files changed, 309 insertions(+)
create mode 100644 gr-blocks/grc/blocks_integrate_xx.xml
create mode 100644 gr-blocks/include/blocks/integrate_XX.h.t
create mode 100644 gr-blocks/lib/integrate_XX_impl.cc.t
create mode 100644 gr-blocks/lib/integrate_XX_impl.h.t
create mode 100755 gr-blocks/python/qa_integrate.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 197daa0f6..d7cbbeb55 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -37,6 +37,7 @@
blocks_multiply_const_vxxblocks_sub_xxblocks_conjugate_cc
+ blocks_integrate_xxStream Type Conversions (New)
diff --git a/gr-blocks/grc/blocks_integrate_xx.xml b/gr-blocks/grc/blocks_integrate_xx.xml
new file mode 100644
index 000000000..13c2ec3c8
--- /dev/null
+++ b/gr-blocks/grc/blocks_integrate_xx.xml
@@ -0,0 +1,50 @@
+
+
+
+ Integrate
+ blocks_integrate_xx
+ from gnuradio import blocks
+ blocks.integrate_$(type.fcn)($decim)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+ Decimation
+ decim
+ int
+
+
+ in
+ $type
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 3110e2abb..9f1af046d 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -68,6 +68,7 @@ expand_h(add_XX ss ii cc)
expand_h(add_const_XX ss ii ff cc)
expand_h(add_const_vXX ss ii ff cc)
expand_h(divide_XX ss ii ff cc)
+expand_h(integrate_XX ss ii ff cc)
expand_h(multiply_XX ss ii)
expand_h(multiply_const_XX ss ii)
expand_h(multiply_const_vXX ss ii ff cc)
diff --git a/gr-blocks/include/blocks/integrate_XX.h.t b/gr-blocks/include/blocks/integrate_XX.h.t
new file mode 100644
index 000000000..8a313a0ba
--- /dev/null
+++ b/gr-blocks/include/blocks/integrate_XX.h.t
@@ -0,0 +1,51 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Integrate successive samples and decimate
+ * \ingroup math_blk
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_decimator
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(int decim);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 8d433801d..e3a40dfc8 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -89,6 +89,7 @@ expand_cc_h_impl(add_XX ss ii cc)
expand_cc_h_impl(add_const_XX ss ii ff cc)
expand_cc_h_impl(add_const_vXX ss ii ff cc)
expand_cc_h_impl(divide_XX ss ii ff cc)
+expand_cc_h_impl(integrate_XX ss ii ff cc)
expand_cc_h_impl(multiply_XX ss ii)
expand_cc_h_impl(multiply_const_XX ss ii)
expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
diff --git a/gr-blocks/lib/integrate_XX_impl.cc.t b/gr-blocks/lib/integrate_XX_impl.cc.t
new file mode 100644
index 000000000..4c82729e3
--- /dev/null
+++ b/gr-blocks/lib/integrate_XX_impl.cc.t
@@ -0,0 +1,68 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(int decim)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(decim));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(int decim)
+ : gr_sync_decimator("@NAME@",
+ gr_make_io_signature(1, 1, sizeof (@I_TYPE@)),
+ gr_make_io_signature(1, 1, sizeof (@O_TYPE@)),
+ decim),
+ d_decim(decim),
+ d_count(0)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const @I_TYPE@ *in = (const @I_TYPE@ *)input_items[0];
+ @O_TYPE@ *out = (@O_TYPE@ *)output_items[0];
+
+ for (int i = 0; i < noutput_items; i++) {
+ out[i] = (@O_TYPE@)0;
+ for (int j = 0; j < d_decim; j++)
+ out[i] += in[i*d_decim+j];
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/integrate_XX_impl.h.t b/gr-blocks/lib/integrate_XX_impl.h.t
new file mode 100644
index 000000000..9fc333388
--- /dev/null
+++ b/gr-blocks/lib/integrate_XX_impl.h.t
@@ -0,0 +1,49 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2004,2009,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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ int d_decim;
+ int d_count;
+
+ public:
+ @NAME_IMPL@(int decim);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_integrate.py b/gr-blocks/python/qa_integrate.py
new file mode 100755
index 000000000..c404f1b30
--- /dev/null
+++ b/gr-blocks/python/qa_integrate.py
@@ -0,0 +1,76 @@
+#!/usr/bin/env python
+#
+# Copyright 2008,2010 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_integrate (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def test_000_ss(self):
+ src_data = (1, 2, 3, 4, 5, 6)
+ dst_data = (6, 15)
+ src = gr.vector_source_s(src_data)
+ itg = blocks_swig.integrate_ss(3)
+ dst = gr.vector_sink_s()
+ self.tb.connect(src, itg, dst)
+ self.tb.run()
+ self.assertEqual(dst_data, dst.data())
+
+ def test_001_ii(self):
+ src_data = (1, 2, 3, 4, 5, 6)
+ dst_data = (6, 15)
+ src = gr.vector_source_i(src_data)
+ itg = blocks_swig.integrate_ii(3)
+ dst = gr.vector_sink_i()
+ self.tb.connect(src, itg, dst)
+ self.tb.run()
+ self.assertEqual(dst_data, dst.data())
+
+ def test_002_ff(self):
+ src_data = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
+ dst_data = [6.0, 15.0]
+ src = gr.vector_source_f(src_data)
+ itg = blocks_swig.integrate_ff(3)
+ dst = gr.vector_sink_f()
+ self.tb.connect(src, itg, dst)
+ self.tb.run()
+ self.assertFloatTuplesAlmostEqual(dst_data, dst.data(), 6)
+
+ def test_003_cc(self):
+ src_data = [1.0+1.0j, 2.0+2.0j, 3.0+3.0j, 4.0+4.0j, 5.0+5.0j, 6.0+6.0j]
+ dst_data = [6.0+6.0j, 15.0+15.0j]
+ src = gr.vector_source_c(src_data)
+ itg = blocks_swig.integrate_cc(3)
+ dst = gr.vector_sink_c()
+ self.tb.connect(src, itg, dst)
+ self.tb.run()
+ self.assertComplexTuplesAlmostEqual(dst_data, dst.data(), 6)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_integrate, "test_integrate.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index cfd9d9db1..fe2745da0 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -60,6 +60,10 @@
#include "blocks/float_to_short.h"
#include "blocks/float_to_uchar.h"
#include "blocks/int_to_float.h"
+#include "blocks/integrate_ss.h"
+#include "blocks/integrate_ii.h"
+#include "blocks/integrate_ff.h"
+#include "blocks/integrate_cc.h"
#include "blocks/interleaved_short_to_complex.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
@@ -114,6 +118,10 @@
%include "blocks/float_to_short.h"
%include "blocks/float_to_uchar.h"
%include "blocks/int_to_float.h"
+%include "blocks/integrate_ss.h"
+%include "blocks/integrate_ii.h"
+%include "blocks/integrate_ff.h"
+%include "blocks/integrate_cc.h"
%include "blocks/interleaved_short_to_complex.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
@@ -167,6 +175,10 @@ GR_SWIG_BLOCK_MAGIC2(blocks, float_to_int);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_short);
GR_SWIG_BLOCK_MAGIC2(blocks, float_to_uchar);
GR_SWIG_BLOCK_MAGIC2(blocks, int_to_float);
+GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, integrate_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, interleaved_short_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
--
cgit
From ee1a53b4a971e4b9623f504628231a273157f462 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 30 Jun 2012 08:26:58 -0700
Subject: blocks: aded gr::blocks::multiply_conjugate_cc
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_multiply_conjugate_cc.xml | 35 ++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/multiply_conjugate_cc.h | 50 +++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/multiply_conjugate_cc_impl.cc | 71 ++++++++++++++++++++++++
gr-blocks/lib/multiply_conjugate_cc_impl.h | 47 ++++++++++++++++
gr-blocks/python/qa_multiply_conjugate.py | 58 +++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 267 insertions(+)
create mode 100644 gr-blocks/grc/blocks_multiply_conjugate_cc.xml
create mode 100644 gr-blocks/include/blocks/multiply_conjugate_cc.h
create mode 100644 gr-blocks/lib/multiply_conjugate_cc_impl.cc
create mode 100644 gr-blocks/lib/multiply_conjugate_cc_impl.h
create mode 100644 gr-blocks/python/qa_multiply_conjugate.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index d7cbbeb55..638fb5941 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -35,6 +35,7 @@
blocks_divide_xxblocks_multiply_xxblocks_multiply_const_vxx
+ blocks_multiply_conjugate_ccblocks_sub_xxblocks_conjugate_ccblocks_integrate_xx
diff --git a/gr-blocks/grc/blocks_multiply_conjugate_cc.xml b/gr-blocks/grc/blocks_multiply_conjugate_cc.xml
new file mode 100644
index 000000000..cf0acf4d8
--- /dev/null
+++ b/gr-blocks/grc/blocks_multiply_conjugate_cc.xml
@@ -0,0 +1,35 @@
+
+
+
+ Multiply Conjugate
+ blocks_multiply_conjugate_cc
+ from gnuradio import blocks
+ blocks.multiply_conjugate_cc($vlen)
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in0
+ complex
+ $vlen
+
+
+ in1
+ complex
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 9f1af046d..f8e775397 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -104,6 +104,7 @@ install(FILES
interleaved_short_to_complex.h
multiply_cc.h
multiply_ff.h
+ multiply_conjugate_cc.h
multiply_const_cc.h
multiply_const_ff.h
short_to_char.h
diff --git a/gr-blocks/include/blocks/multiply_conjugate_cc.h b/gr-blocks/include/blocks/multiply_conjugate_cc.h
new file mode 100644
index 000000000..fc587ae2f
--- /dev/null
+++ b/gr-blocks/include/blocks/multiply_conjugate_cc.h
@@ -0,0 +1,50 @@
+/* -*- 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_GR_MULTIPLY_CONJUGATE_CC_H
+#define INCLUDED_GR_MULTIPLY_CONJUGATE_CC_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_conjugate_cc : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::multiply_conjugate_cc::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Multiplies a streams by the conjugate of a second stream
+ * \param vlen Vector length
+ * \ingroup math_blk
+ */
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_MULTIPLY_CONJUGATE_CC_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index e3a40dfc8..b73bf2994 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -141,6 +141,7 @@ list(APPEND gr_blocks_sources
interleaved_short_to_complex_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
+ multiply_conjugate_cc_impl.cc
multiply_const_cc_impl.cc
multiply_const_ff_impl.cc
short_to_char_impl.cc
diff --git a/gr-blocks/lib/multiply_conjugate_cc_impl.cc b/gr-blocks/lib/multiply_conjugate_cc_impl.cc
new file mode 100644
index 000000000..7a4356c45
--- /dev/null
+++ b/gr-blocks/lib/multiply_conjugate_cc_impl.cc
@@ -0,0 +1,71 @@
+/* -*- 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
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ multiply_conjugate_cc::sptr multiply_conjugate_cc::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new multiply_conjugate_cc_impl(vlen));
+ }
+
+ multiply_conjugate_cc_impl::multiply_conjugate_cc_impl(size_t vlen)
+ : gr_sync_block("multiply_conjugate_cc",
+ gr_make_io_signature (2, 2, sizeof(gr_complex)*vlen),
+ gr_make_io_signature (1, 1, sizeof(gr_complex)*vlen)),
+ d_vlen(vlen)
+ {
+ const int alignment_multiple =
+ volk_get_alignment() / sizeof(gr_complex);
+ set_alignment(std::max(1, alignment_multiple));
+ }
+
+ int
+ multiply_conjugate_cc_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ gr_complex *in0 = (gr_complex *) input_items[0];
+ gr_complex *in1 = (gr_complex *) input_items[1];
+ gr_complex *out = (gr_complex *) output_items[0];
+ int noi = d_vlen*noutput_items;
+
+ if(is_unaligned()) {
+ volk_32fc_x2_multiply_conjugate_32fc_u(out, in0, in1, noi);
+ }
+ else {
+ volk_32fc_x2_multiply_conjugate_32fc_a(out, in0, in1, noi);
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/multiply_conjugate_cc_impl.h b/gr-blocks/lib/multiply_conjugate_cc_impl.h
new file mode 100644
index 000000000..66e7ec55b
--- /dev/null
+++ b/gr-blocks/lib/multiply_conjugate_cc_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_BLOCKS_MULTIPLY_CONJUGATE_CC_IMPL_H
+#define INCLUDED_BLOCKS_MULTIPLY_CONJUGATE_CC_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API multiply_conjugate_cc_impl : public multiply_conjugate_cc
+ {
+ size_t d_vlen;
+
+ public:
+ multiply_conjugate_cc_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_BLOCKS_MULTIPLY_CONJUGATE_CC_IMPL_H */
diff --git a/gr-blocks/python/qa_multiply_conjugate.py b/gr-blocks/python/qa_multiply_conjugate.py
new file mode 100644
index 000000000..f51563f85
--- /dev/null
+++ b/gr-blocks/python/qa_multiply_conjugate.py
@@ -0,0 +1,58 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig
+
+class test_multiply_conjugate (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def test_000 (self):
+ src_data0 = (-2-2j, -1-1j, -2+2j, -1+1j,
+ 2-2j, 1-1j, 2+2j, 1+1j,
+ 0+0j)
+ src_data1 = (-3-3j, -4-4j, -3+3j, -4+4j,
+ 3-3j, 4-4j, 3+3j, 4+4j,
+ 0+0j)
+
+ exp_data = (12+0j, 8+0j, 12+0j, 8+0j,
+ 12+0j, 8+0j, 12+0j, 8+0j,
+ 0+0j)
+ src0 = gr.vector_source_c(src_data0)
+ src1 = gr.vector_source_c(src_data1)
+ op = blocks_swig.multiply_conjugate_cc ()
+ dst = gr.vector_sink_c ()
+
+ self.tb.connect(src0, (op,0))
+ self.tb.connect(src1, (op,1))
+ self.tb.connect(op, dst)
+ self.tb.run()
+ result_data = dst.data ()
+ self.assertEqual (exp_data, result_data)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_multiply_conjugate, "test_multiply_conjugate.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index fe2745da0..43225a732 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -69,6 +69,7 @@
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
#include "blocks/multiply_cc.h"
+#include "blocks/multiply_conjugate_cc.h"
#include "blocks/multiply_const_ss.h"
#include "blocks/multiply_const_ii.h"
#include "blocks/multiply_const_ff.h"
@@ -127,6 +128,7 @@
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
%include "blocks/multiply_cc.h"
+%include "blocks/multiply_conjugate_cc.h"
%include "blocks/multiply_const_ss.h"
%include "blocks/multiply_const_ii.h"
%include "blocks/multiply_const_ff.h"
@@ -184,6 +186,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, multiply_conjugate_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_const_ff);
--
cgit
From 70d89e2051264876055fe9f73cbcb2823806b3ee Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sun, 1 Jul 2012 09:15:14 -0700
Subject: blocks: added gr::blocks::nlog10_ff
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_nlog10_ff.xml | 42 ++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/nlog10_ff.h | 55 ++++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/nlog10_ff_impl.cc | 64 +++++++++++++++++++++++++++++++++
gr-blocks/lib/nlog10_ff_impl.h | 49 +++++++++++++++++++++++++
gr-blocks/python/qa_nlog10.py | 48 +++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 264 insertions(+)
create mode 100644 gr-blocks/grc/blocks_nlog10_ff.xml
create mode 100644 gr-blocks/include/blocks/nlog10_ff.h
create mode 100644 gr-blocks/lib/nlog10_ff_impl.cc
create mode 100644 gr-blocks/lib/nlog10_ff_impl.h
create mode 100755 gr-blocks/python/qa_nlog10.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 638fb5941..721a6d238 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -39,6 +39,7 @@
blocks_sub_xxblocks_conjugate_ccblocks_integrate_xx
+ blocks_nlog10_ffStream Type Conversions (New)
diff --git a/gr-blocks/grc/blocks_nlog10_ff.xml b/gr-blocks/grc/blocks_nlog10_ff.xml
new file mode 100644
index 000000000..884f4a444
--- /dev/null
+++ b/gr-blocks/grc/blocks_nlog10_ff.xml
@@ -0,0 +1,42 @@
+
+
+
+ Log10
+ blocks_nlog10_ff
+ from gnuradio import blocks
+ blocks.nlog10_ff($n, $vlen, $k)
+
+ n
+ n
+ 1
+ real
+
+
+ k
+ k
+ 0
+ real
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen >= 1
+
+ in
+ float
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index f8e775397..b816544be 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -107,6 +107,7 @@ install(FILES
multiply_conjugate_cc.h
multiply_const_cc.h
multiply_const_ff.h
+ nlog10_ff.h
short_to_char.h
short_to_float.h
uchar_to_float.h
diff --git a/gr-blocks/include/blocks/nlog10_ff.h b/gr-blocks/include/blocks/nlog10_ff.h
new file mode 100644
index 000000000..cedd620fa
--- /dev/null
+++ b/gr-blocks/include/blocks/nlog10_ff.h
@@ -0,0 +1,55 @@
+/* -*- 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_NLOG10_FF_H
+#define INCLUDED_BLOCKS_NLOG10_FF_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = n*log10(input) + k
+ * \ingroup math_blk
+ */
+ class BLOCKS_API nlog10_ff : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::nlog10_ff::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Make an instance of an nlog10_ff block.
+ * \param n Scalar multiplicative constant
+ * \param vlen Input vector length
+ * \param k Scalar additive constant
+ */
+ static sptr make(float n=1.0, size_t vlen=1, float k=0.0);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_NLOG10_FF_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index b73bf2994..cd07cef2f 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -144,6 +144,7 @@ list(APPEND gr_blocks_sources
multiply_conjugate_cc_impl.cc
multiply_const_cc_impl.cc
multiply_const_ff_impl.cc
+ nlog10_ff_impl.cc
short_to_char_impl.cc
short_to_float_impl.cc
uchar_array_to_float.cc
diff --git a/gr-blocks/lib/nlog10_ff_impl.cc b/gr-blocks/lib/nlog10_ff_impl.cc
new file mode 100644
index 000000000..f662b8fd5
--- /dev/null
+++ b/gr-blocks/lib/nlog10_ff_impl.cc
@@ -0,0 +1,64 @@
+/* -*- 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 "nlog10_ff_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ nlog10_ff::sptr nlog10_ff::make(float n, size_t vlen, float k)
+ {
+ return gnuradio::get_initial_sptr(new nlog10_ff_impl(n, vlen, k));
+ }
+
+ nlog10_ff_impl::nlog10_ff_impl(float n, size_t vlen, float k)
+ : gr_sync_block("nlog10_ff",
+ gr_make_io_signature (1, 1, sizeof(float)*vlen),
+ gr_make_io_signature (1, 1, sizeof(float)*vlen)),
+ d_n(n), d_vlen(vlen), d_k(k)
+ {
+ }
+
+ int
+ nlog10_ff_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ const float *in = (const float *) input_items[0];
+ float *out = (float *) output_items[0];
+ int noi = noutput_items * d_vlen;
+ float n = d_n;
+ float k = d_k;
+
+ for (int i = 0; i < noi; i++)
+ out[i] = n * log10(std::max(in[i], (float) 1e-18)) + k;
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+}/* namespace gr */
diff --git a/gr-blocks/lib/nlog10_ff_impl.h b/gr-blocks/lib/nlog10_ff_impl.h
new file mode 100644
index 000000000..3789bc317
--- /dev/null
+++ b/gr-blocks/lib/nlog10_ff_impl.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_NLOG10_FF_IMPL_H
+#define INCLUDED_NLOG10_FF_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API nlog10_ff_impl : public nlog10_ff
+ {
+ float d_n;
+ size_t d_vlen;
+ float d_k;
+
+ public:
+ nlog10_ff_impl(float n, size_t vlen, float k);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_NLOG10_FF_IMPL_H */
diff --git a/gr-blocks/python/qa_nlog10.py b/gr-blocks/python/qa_nlog10.py
new file mode 100755
index 000000000..cc2a3e8cc
--- /dev/null
+++ b/gr-blocks/python/qa_nlog10.py
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2007,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
+
+class test_nlog10(gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def test_001(self):
+ src_data = (-10, 0, 10, 100, 1000, 10000, 100000)
+ expected_result = (-180, -180, 10, 20, 30, 40, 50)
+ src = gr.vector_source_f(src_data)
+ op = blocks_swig.nlog10_ff(10)
+ dst = gr.vector_sink_f()
+ self.tb.connect (src, op, dst)
+ self.tb.run()
+ result_data = dst.data()
+ self.assertFloatTuplesAlmostEqual (expected_result, result_data)
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_nlog10, "test_nlog10.xml")
+
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 43225a732..f70e536b2 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -78,6 +78,7 @@
#include "blocks/multiply_const_vii.h"
#include "blocks/multiply_const_vff.h"
#include "blocks/multiply_const_vcc.h"
+#include "blocks/nlog10_ff.h"
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
#include "blocks/sub_ff.h"
@@ -137,6 +138,7 @@
%include "blocks/multiply_const_vii.h"
%include "blocks/multiply_const_vff.h"
%include "blocks/multiply_const_vcc.h"
+%include "blocks/nlog10_ff.h"
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
%include "blocks/sub_ff.h"
@@ -195,6 +197,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, nlog10_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
--
cgit
From cc085e128901a9f3e8bfcc45d1834a62d747726c Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Mon, 2 Jul 2012 08:36:46 -0700
Subject: blocks: added gr::blocks::add_XX (bb ss ii)
---
gr-blocks/grc/blocks_and_xx.xml | 48 +++++++++
gr-blocks/grc/blocks_block_tree.xml | 6 +-
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/and_XX.h.t | 53 ++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/and_XX_impl.cc.t | 69 +++++++++++++
gr-blocks/lib/and_XX_impl.h.t | 48 +++++++++
gr-blocks/python/qa_boolean_operators.py | 163 +++++++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 9 ++
9 files changed, 397 insertions(+), 1 deletion(-)
create mode 100644 gr-blocks/grc/blocks_and_xx.xml
create mode 100644 gr-blocks/include/blocks/and_XX.h.t
create mode 100644 gr-blocks/lib/and_XX_impl.cc.t
create mode 100644 gr-blocks/lib/and_XX_impl.h.t
create mode 100755 gr-blocks/python/qa_boolean_operators.py
diff --git a/gr-blocks/grc/blocks_and_xx.xml b/gr-blocks/grc/blocks_and_xx.xml
new file mode 100644
index 000000000..317a0f645
--- /dev/null
+++ b/gr-blocks/grc/blocks_and_xx.xml
@@ -0,0 +1,48 @@
+
+
+
+ And
+ blocks_and_xx
+ from gnuradio import blocks
+ blocks.and_$(type.fcn)()
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+ $num_inputs >= 2
+
+ in
+ $type
+ $num_inputs
+
+
+
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 721a6d238..3aed8dc22 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -27,7 +27,7 @@
###################################################
-->
-
+ Math Operations (New) blocks_add_xx
@@ -41,6 +41,10 @@
blocks_integrate_xxblocks_nlog10_ff
+
+ Boolean Operations (New)
+ blocks_and_xx.xml
+ Stream Type Conversions (New) blocks_char_to_float
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index b816544be..1db3eab2f 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -67,6 +67,7 @@ endmacro(expand_h)
expand_h(add_XX ss ii cc)
expand_h(add_const_XX ss ii ff cc)
expand_h(add_const_vXX ss ii ff cc)
+expand_h(and_XX bb ss ii)
expand_h(divide_XX ss ii ff cc)
expand_h(integrate_XX ss ii ff cc)
expand_h(multiply_XX ss ii)
diff --git a/gr-blocks/include/blocks/and_XX.h.t b/gr-blocks/include/blocks/and_XX.h.t
new file mode 100644
index 000000000..68ddcc33d
--- /dev/null
+++ b/gr-blocks/include/blocks/and_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input_0 & input_1 & , ... & input_N)
+ * \ingroup math_blk
+ *
+ * bitwise boolean and across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index cd07cef2f..4aa737b6f 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -88,6 +88,7 @@ endmacro(expand_cc_h_impl)
expand_cc_h_impl(add_XX ss ii cc)
expand_cc_h_impl(add_const_XX ss ii ff cc)
expand_cc_h_impl(add_const_vXX ss ii ff cc)
+expand_cc_h_impl(and_XX bb ss ii)
expand_cc_h_impl(divide_XX ss ii ff cc)
expand_cc_h_impl(integrate_XX ss ii ff cc)
expand_cc_h_impl(multiply_XX ss ii)
diff --git a/gr-blocks/lib/and_XX_impl.cc.t b/gr-blocks/lib/and_XX_impl.cc.t
new file mode 100644
index 000000000..3218a8c74
--- /dev/null
+++ b/gr-blocks/lib/and_XX_impl.cc.t
@@ -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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc &= ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/and_XX_impl.h.t b/gr-blocks/lib/and_XX_impl.h.t
new file mode 100644
index 000000000..25f0da0c8
--- /dev/null
+++ b/gr-blocks/lib/and_XX_impl.h.t
@@ -0,0 +1,48 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py
new file mode 100755
index 000000000..5bd1e7550
--- /dev/null
+++ b/gr-blocks/python/qa_boolean_operators.py
@@ -0,0 +1,163 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,2008,2010 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
+
+class test_boolean_operators (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def help_ss (self, src_data, exp_data, op):
+ for s in zip (range (len (src_data)), src_data):
+ src = gr.vector_source_s (s[1])
+ self.tb.connect (src, (op, s[0]))
+ dst = gr.vector_sink_s ()
+ self.tb.connect (op, dst)
+ self.tb.run ()
+ result_data = dst.data ()
+ self.assertEqual (exp_data, result_data)
+
+ def help_bb (self, src_data, exp_data, op):
+ for s in zip (range (len (src_data)), src_data):
+ src = gr.vector_source_b (s[1])
+ self.tb.connect (src, (op, s[0]))
+ dst = gr.vector_sink_b ()
+ self.tb.connect (op, dst)
+ self.tb.run ()
+ result_data = dst.data ()
+ self.assertEqual (exp_data, result_data)
+
+ def help_ii (self, src_data, exp_data, op):
+ for s in zip (range (len (src_data)), src_data):
+ src = gr.vector_source_i (s[1])
+ self.tb.connect (src, (op, s[0]))
+ dst = gr.vector_sink_i ()
+ self.tb.connect (op, dst)
+ self.tb.run ()
+ result_data = dst.data ()
+ self.assertEqual (exp_data, result_data)
+ """
+ def test_xor_ss (self):
+ src1_data = (1, 2, 3, 0x5004, 0x1150)
+ src2_data = (8, 2, 1 , 0x0508, 0x1105)
+ expected_result = (9, 0, 2, 0x550C, 0x0055)
+ op = gr.xor_ss ()
+ self.help_ss ((src1_data, src2_data),
+ expected_result, op)
+
+ def test_xor_bb (self):
+ src1_data = (1, 2, 3, 4, 0x50)
+ src2_data = (8, 2, 1 , 8, 0x05)
+ expected_result = (9, 0, 2, 0xC, 0x55)
+ op = gr.xor_bb ()
+ self.help_bb ((src1_data, src2_data),
+ expected_result, op)
+
+
+ def test_xor_ii (self):
+ src1_data = (1, 2, 3, 0x5000004, 0x11000050)
+ src2_data = (8, 2, 1 , 0x0500008, 0x11000005)
+ expected_result = (9, 0, 2, 0x550000C, 0x00000055)
+ op = gr.xor_ii ()
+ self.help_ii ((src1_data, src2_data),
+ expected_result, op)
+ """
+ def test_and_ss (self):
+ src1_data = (1, 2, 3, 0x5004, 0x1150)
+ src2_data = (8, 2, 1 , 0x0508, 0x1105)
+ expected_result = (0, 2, 1, 0x0000, 0x1100)
+ op = blocks_swig.and_ss ()
+ self.help_ss ((src1_data, src2_data),
+ expected_result, op)
+
+ def test_and_bb (self):
+ src1_data = (1, 2, 2, 3, 0x04, 0x50)
+ src2_data = (8, 2, 2, 1, 0x08, 0x05)
+ src3_data = (8, 2, 1, 1, 0x08, 0x05)
+ expected_result = (0, 2, 0, 1, 0x00, 0x00)
+ op = blocks_swig.and_bb ()
+ self.help_bb ((src1_data, src2_data, src3_data),
+ expected_result, op)
+
+ def test_and_ii (self):
+ src1_data = (1, 2, 3, 0x50005004, 0x11001150)
+ src2_data = (8, 2, 1 , 0x05000508, 0x11001105)
+ expected_result = (0, 2, 1, 0x00000000, 0x11001100)
+ op = blocks_swig.and_ii ()
+ self.help_ii ((src1_data, src2_data),
+ expected_result, op)
+ """
+ def test_or_ss (self):
+ src1_data = (1, 2, 3, 0x5004, 0x1150)
+ src2_data = (8, 2, 1 , 0x0508, 0x1105)
+ expected_result = (9, 2, 3, 0x550C, 0x1155)
+ op = gr.or_ss ()
+ self.help_ss ((src1_data, src2_data),
+ expected_result, op)
+
+ def test_or_bb (self):
+ src1_data = (1, 2, 2, 3, 0x04, 0x50)
+ src2_data = (8, 2, 2, 1 , 0x08, 0x05)
+ src3_data = (8, 2, 1, 1 , 0x08, 0x05)
+ expected_result = (9, 2, 3, 3, 0x0C, 0x55)
+ op = gr.or_bb ()
+ self.help_bb ((src1_data, src2_data, src3_data),
+ expected_result, op)
+
+ def test_or_ii (self):
+ src1_data = (1, 2, 3, 0x50005004, 0x11001150)
+ src2_data = (8, 2, 1 , 0x05000508, 0x11001105)
+ expected_result = (9, 2, 3, 0x5500550C, 0x11001155)
+ op = gr.or_ii ()
+ self.help_ii ((src1_data, src2_data),
+ expected_result, op)
+
+ def test_not_ss (self):
+ src1_data = (1, 2, 3, 0x5004, 0x1150)
+ expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150)
+ op = gr.not_ss ()
+ self.help_ss ((((src1_data),)),
+ expected_result, op)
+
+ def test_not_bb (self):
+ src1_data = (1, 2, 2, 3, 0x04, 0x50)
+ expected_result = (0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF)
+ op = gr.not_bb ()
+ self.help_bb (((src1_data), ),
+ expected_result, op)
+
+ def test_not_ii (self):
+ src1_data = (1, 2, 3, 0x50005004, 0x11001150)
+ expected_result = (~1 , ~2, ~3, ~0x50005004, ~0x11001150)
+ op = gr.not_ii ()
+ self.help_ii (((src1_data),),
+ expected_result, op)
+ """
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_boolean_operators, "test_boolean_operators.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index f70e536b2..f4612f5d8 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -40,6 +40,9 @@
#include "blocks/add_const_vss.h"
#include "blocks/add_const_vii.h"
#include "blocks/add_const_vcc.h"
+#include "blocks/and_bb.h"
+#include "blocks/and_ss.h"
+#include "blocks/and_ii.h"
#include "blocks/char_to_float.h"
#include "blocks/char_to_short.h"
#include "blocks/complex_to_interleaved_short.h"
@@ -100,6 +103,9 @@
%include "blocks/add_const_vss.h"
%include "blocks/add_const_vii.h"
%include "blocks/add_const_vcc.h"
+%include "blocks/and_bb.h"
+%include "blocks/and_ss.h"
+%include "blocks/and_ii.h"
%include "blocks/char_to_float.h"
%include "blocks/char_to_short.h"
%include "blocks/complex_to_interleaved_short.h"
@@ -159,6 +165,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vss);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vii);
GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_ii);
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);
--
cgit
From 025f323d9857715a31a1117693c5debd19393a46 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Mon, 2 Jul 2012 09:13:13 -0700
Subject: blocks: added gr::blocks::and_const_XX (bb ss ii)
---
gr-blocks/grc/blocks_and_const_xx.xml | 48 +++++++++++++++++++
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/and_const_XX.h.t | 68 +++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/and_const_XX_impl.cc.t | 77 +++++++++++++++++++++++++++++++
gr-blocks/lib/and_const_XX_impl.h.t | 51 ++++++++++++++++++++
gr-blocks/python/qa_boolean_operators.py | 33 +++++++++++++
gr-blocks/swig/blocks_swig.i | 9 ++++
9 files changed, 289 insertions(+)
create mode 100644 gr-blocks/grc/blocks_and_const_xx.xml
create mode 100644 gr-blocks/include/blocks/and_const_XX.h.t
create mode 100644 gr-blocks/lib/and_const_XX_impl.cc.t
create mode 100644 gr-blocks/lib/and_const_XX_impl.h.t
diff --git a/gr-blocks/grc/blocks_and_const_xx.xml b/gr-blocks/grc/blocks_and_const_xx.xml
new file mode 100644
index 000000000..d0abbfe51
--- /dev/null
+++ b/gr-blocks/grc/blocks_and_const_xx.xml
@@ -0,0 +1,48 @@
+
+
+
+ And Const
+ blocks_and_const_xx
+ from gnuradio import blocks
+ blocks.and_const_$(type.fcn)($const)
+ set_k($const)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+ Constant
+ const
+ 0
+ int
+
+
+ in
+ $type
+
+
+
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 3aed8dc22..e5566ee43 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -44,6 +44,7 @@
Boolean Operations (New) blocks_and_xx.xml
+ blocks_and_const_xx.xmlStream Type Conversions (New)
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 1db3eab2f..5b29219cc 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -68,6 +68,7 @@ expand_h(add_XX ss ii cc)
expand_h(add_const_XX ss ii ff cc)
expand_h(add_const_vXX ss ii ff cc)
expand_h(and_XX bb ss ii)
+expand_h(and_const_XX bb ss ii)
expand_h(divide_XX ss ii ff cc)
expand_h(integrate_XX ss ii ff cc)
expand_h(multiply_XX ss ii)
diff --git a/gr-blocks/include/blocks/and_const_XX.h.t b/gr-blocks/include/blocks/and_const_XX.h.t
new file mode 100644
index 000000000..945a1f48b
--- /dev/null
+++ b/gr-blocks/include/blocks/and_const_XX.h.t
@@ -0,0 +1,68 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output_N = input_N & value
+ * \ingroup math_blk
+ *
+ * bitwise boolean and of const to the data stream.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ /*!
+ * \brief Create an instance of @NAME@
+ * \param k AND constant
+ */
+ static sptr make(@O_TYPE@ k);
+
+ /*!
+ * \brief Return AND constant
+ */
+ virtual @O_TYPE@ k() const = 0;
+
+ /*!
+ * \brief Set AND constant
+ */
+ virtual void set_k(@O_TYPE@ k) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 4aa737b6f..9c67c7b03 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -89,6 +89,7 @@ expand_cc_h_impl(add_XX ss ii cc)
expand_cc_h_impl(add_const_XX ss ii ff cc)
expand_cc_h_impl(add_const_vXX ss ii ff cc)
expand_cc_h_impl(and_XX bb ss ii)
+expand_cc_h_impl(and_const_XX bb ss ii)
expand_cc_h_impl(divide_XX ss ii ff cc)
expand_cc_h_impl(integrate_XX ss ii ff cc)
expand_cc_h_impl(multiply_XX ss ii)
diff --git a/gr-blocks/lib/and_const_XX_impl.cc.t b/gr-blocks/lib/and_const_XX_impl.cc.t
new file mode 100644
index 000000000..8ff5ac371
--- /dev/null
+++ b/gr-blocks/lib/and_const_XX_impl.cc.t
@@ -0,0 +1,77 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(@O_TYPE@ k)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(k));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(@O_TYPE@ k)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@))),
+ d_k(k)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @I_TYPE@ *iptr = (@I_TYPE@ *) input_items[0];
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int size = noutput_items;
+
+ while (size >= 8){
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ *optr++ = *iptr++ & d_k;
+ size -= 8;
+ }
+
+ while (size-- > 0)
+ *optr++ = *iptr++ & d_k;
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/and_const_XX_impl.h.t b/gr-blocks/lib/and_const_XX_impl.h.t
new file mode 100644
index 000000000..2c379feb8
--- /dev/null
+++ b/gr-blocks/lib/and_const_XX_impl.h.t
@@ -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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ @O_TYPE@ d_k;
+
+ public:
+ @NAME_IMPL@(@O_TYPE@ k);
+
+ @O_TYPE@ k() const { return d_k; }
+ void set_k(@O_TYPE@ k) { d_k = k; }
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py
index 5bd1e7550..8dad41a92 100755
--- a/gr-blocks/python/qa_boolean_operators.py
+++ b/gr-blocks/python/qa_boolean_operators.py
@@ -110,6 +110,39 @@ class test_boolean_operators (gr_unittest.TestCase):
op = blocks_swig.and_ii ()
self.help_ii ((src1_data, src2_data),
expected_result, op)
+
+ def test_and_const_ss (self):
+ src_data = (1, 2, 3, 0x5004, 0x1150)
+ expected_result = (0, 2, 2, 0x5000, 0x1100)
+ src = gr.vector_source_s(src_data)
+ op = blocks_swig.and_const_ss (0x55AA)
+ dst = gr.vector_sink_s()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(dst.data(), expected_result)
+
+ def test_and_const_bb (self):
+ src_data = (1, 2, 3, 0x50, 0x11)
+ expected_result = (0, 2, 2, 0x00, 0x00)
+ src = gr.vector_source_b(src_data)
+ op = blocks_swig.and_const_bb (0xAA)
+ dst = gr.vector_sink_b()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(dst.data(), expected_result)
+
+
+ def test_and_const_ii (self):
+ src_data = (1, 2, 3, 0x5004, 0x1150)
+ expected_result = (0, 2, 2, 0x5000, 0x1100)
+ src = gr.vector_source_i(src_data)
+ op = blocks_swig.and_const_ii (0x55AA)
+ dst = gr.vector_sink_i()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(dst.data(), expected_result)
+
+
"""
def test_or_ss (self):
src1_data = (1, 2, 3, 0x5004, 0x1150)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index f4612f5d8..4482757ec 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -43,6 +43,9 @@
#include "blocks/and_bb.h"
#include "blocks/and_ss.h"
#include "blocks/and_ii.h"
+#include "blocks/and_const_bb.h"
+#include "blocks/and_const_ss.h"
+#include "blocks/and_const_ii.h"
#include "blocks/char_to_float.h"
#include "blocks/char_to_short.h"
#include "blocks/complex_to_interleaved_short.h"
@@ -106,6 +109,9 @@
%include "blocks/and_bb.h"
%include "blocks/and_ss.h"
%include "blocks/and_ii.h"
+%include "blocks/and_const_bb.h"
+%include "blocks/and_const_ss.h"
+%include "blocks/and_const_ii.h"
%include "blocks/char_to_float.h"
%include "blocks/char_to_short.h"
%include "blocks/complex_to_interleaved_short.h"
@@ -168,6 +174,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, add_const_vcc);
GR_SWIG_BLOCK_MAGIC2(blocks, and_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, and_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, and_ii);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_const_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, and_const_ii);
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);
--
cgit
From 84f9822b4a8fe4290e971c09b2bd99f1bf59517b Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 3 Jul 2012 09:49:20 -0700
Subject: blocks: added gr::blocks::not_XX (bb ss ii)
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_not_xx.xml | 40 ++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/not_XX.h.t | 53 ++++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/not_XX_impl.cc.t | 65 ++++++++++++++++++++++++++++++++
gr-blocks/lib/not_XX_impl.h.t | 48 +++++++++++++++++++++++
gr-blocks/python/qa_boolean_operators.py | 8 ++--
gr-blocks/swig/blocks_swig.i | 9 +++++
9 files changed, 222 insertions(+), 4 deletions(-)
create mode 100644 gr-blocks/grc/blocks_not_xx.xml
create mode 100644 gr-blocks/include/blocks/not_XX.h.t
create mode 100644 gr-blocks/lib/not_XX_impl.cc.t
create mode 100644 gr-blocks/lib/not_XX_impl.h.t
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index e5566ee43..bc2a6fa4e 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -45,6 +45,7 @@
Boolean Operations (New) blocks_and_xx.xmlblocks_and_const_xx.xml
+ blocks_not_xx.xmlStream Type Conversions (New)
diff --git a/gr-blocks/grc/blocks_not_xx.xml b/gr-blocks/grc/blocks_not_xx.xml
new file mode 100644
index 000000000..fe8916d8b
--- /dev/null
+++ b/gr-blocks/grc/blocks_not_xx.xml
@@ -0,0 +1,40 @@
+
+
+
+ Not
+ blocks_not_xx
+ from gnuradio import blocks
+ blocks.not_$(type.fcn)()
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+ in
+ $type
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 5b29219cc..f6be20235 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -74,6 +74,7 @@ expand_h(integrate_XX ss ii ff cc)
expand_h(multiply_XX ss ii)
expand_h(multiply_const_XX ss ii)
expand_h(multiply_const_vXX ss ii ff cc)
+expand_h(not_XX bb ss ii)
expand_h(sub_XX ss ii ff cc)
add_custom_target(blocks_generated_includes DEPENDS
diff --git a/gr-blocks/include/blocks/not_XX.h.t b/gr-blocks/include/blocks/not_XX.h.t
new file mode 100644
index 000000000..e406c82dc
--- /dev/null
+++ b/gr-blocks/include/blocks/not_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = ~input
+ * \ingroup math_blk
+ *
+ * bitwise boolean not of input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 9c67c7b03..3bf1db750 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -95,6 +95,7 @@ expand_cc_h_impl(integrate_XX ss ii ff cc)
expand_cc_h_impl(multiply_XX ss ii)
expand_cc_h_impl(multiply_const_XX ss ii)
expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
+expand_cc_h_impl(not_XX bb ss ii)
expand_cc_h_impl(sub_XX ss ii ff cc)
########################################################################
diff --git a/gr-blocks/lib/not_XX_impl.cc.t b/gr-blocks/lib/not_XX_impl.cc.t
new file mode 100644
index 000000000..b491a4ccc
--- /dev/null
+++ b/gr-blocks/lib/not_XX_impl.cc.t
@@ -0,0 +1,65 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, 1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+ const @I_TYPE@ *inptr = (const @I_TYPE@ *) input_items[0];
+
+ int noi = noutput_items*d_vlen;
+
+ for (int i = 0; i < noi; i++)
+ *optr++ = ~(inptr[i]);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/not_XX_impl.h.t b/gr-blocks/lib/not_XX_impl.h.t
new file mode 100644
index 000000000..25f0da0c8
--- /dev/null
+++ b/gr-blocks/lib/not_XX_impl.h.t
@@ -0,0 +1,48 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py
index 8dad41a92..dc011c14e 100755
--- a/gr-blocks/python/qa_boolean_operators.py
+++ b/gr-blocks/python/qa_boolean_operators.py
@@ -169,27 +169,27 @@ class test_boolean_operators (gr_unittest.TestCase):
self.help_ii ((src1_data, src2_data),
expected_result, op)
+ """
def test_not_ss (self):
src1_data = (1, 2, 3, 0x5004, 0x1150)
expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150)
- op = gr.not_ss ()
+ op = blocks_swig.not_ss ()
self.help_ss ((((src1_data),)),
expected_result, op)
def test_not_bb (self):
src1_data = (1, 2, 2, 3, 0x04, 0x50)
expected_result = (0xFE, 0xFD, 0xFD, 0xFC, 0xFB, 0xAF)
- op = gr.not_bb ()
+ op = blocks_swig.not_bb ()
self.help_bb (((src1_data), ),
expected_result, op)
def test_not_ii (self):
src1_data = (1, 2, 3, 0x50005004, 0x11001150)
expected_result = (~1 , ~2, ~3, ~0x50005004, ~0x11001150)
- op = gr.not_ii ()
+ op = blocks_swig.not_ii ()
self.help_ii (((src1_data),),
expected_result, op)
- """
if __name__ == '__main__':
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 4482757ec..38e815a98 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -85,6 +85,9 @@
#include "blocks/multiply_const_vff.h"
#include "blocks/multiply_const_vcc.h"
#include "blocks/nlog10_ff.h"
+#include "blocks/not_bb.h"
+#include "blocks/not_ss.h"
+#include "blocks/not_ii.h"
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
#include "blocks/sub_ff.h"
@@ -151,6 +154,9 @@
%include "blocks/multiply_const_vff.h"
%include "blocks/multiply_const_vcc.h"
%include "blocks/nlog10_ff.h"
+%include "blocks/not_bb.h"
+%include "blocks/not_ss.h"
+%include "blocks/not_ii.h"
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
%include "blocks/sub_ff.h"
@@ -216,6 +222,9 @@ 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, nlog10_ff);
+GR_SWIG_BLOCK_MAGIC2(blocks, not_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, not_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, not_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
--
cgit
From 312de88604d052142f91ae4eb292ccd25fac7963 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 3 Jul 2012 18:02:10 -0700
Subject: blocks: apply swig fix
---
gr-blocks/swig/CMakeLists.txt | 2 ++
1 file changed, 2 insertions(+)
diff --git a/gr-blocks/swig/CMakeLists.txt b/gr-blocks/swig/CMakeLists.txt
index fb29789f0..cd2748547 100644
--- a/gr-blocks/swig/CMakeLists.txt
+++ b/gr-blocks/swig/CMakeLists.txt
@@ -23,6 +23,8 @@
include(GrPython)
include(GrSwig)
+set(GR_SWIG_TARGET_DEPS core_swig)
+
set(GR_SWIG_INCLUDE_DIRS
${GR_BLOCKS_INCLUDE_DIRS}
${GNURADIO_CORE_SWIG_INCLUDE_DIRS}
--
cgit
From 4c85f46aee089432b090b988dedbc42091084ba3 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Wed, 4 Jul 2012 07:11:51 -0700
Subject: blocks: added gr::blocks::or_XX (bb ss ii)
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_or_xx.xml | 48 ++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/or_XX.h.t | 53 ++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/or_XX_impl.cc.t | 69 ++++++++++++++++++++++++++++++++
gr-blocks/lib/or_XX_impl.h.t | 48 ++++++++++++++++++++++
gr-blocks/python/qa_boolean_operators.py | 8 ++--
gr-blocks/swig/blocks_swig.i | 9 +++++
9 files changed, 233 insertions(+), 5 deletions(-)
create mode 100644 gr-blocks/grc/blocks_or_xx.xml
create mode 100644 gr-blocks/include/blocks/or_XX.h.t
create mode 100644 gr-blocks/lib/or_XX_impl.cc.t
create mode 100644 gr-blocks/lib/or_XX_impl.h.t
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index bc2a6fa4e..e2658a373 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -46,6 +46,7 @@
blocks_and_xx.xmlblocks_and_const_xx.xmlblocks_not_xx.xml
+ blocks_or_xx.xmlStream Type Conversions (New)
diff --git a/gr-blocks/grc/blocks_or_xx.xml b/gr-blocks/grc/blocks_or_xx.xml
new file mode 100644
index 000000000..400c09389
--- /dev/null
+++ b/gr-blocks/grc/blocks_or_xx.xml
@@ -0,0 +1,48 @@
+
+
+
+ Or
+ blocks_or_xx
+ from gnuradio import blocks
+ blocks.or_$(type.fcn)()
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+ $num_inputs >= 2
+
+ in
+ $type
+ $num_inputs
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index f6be20235..434fb2944 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -75,6 +75,7 @@ expand_h(multiply_XX ss ii)
expand_h(multiply_const_XX ss ii)
expand_h(multiply_const_vXX ss ii ff cc)
expand_h(not_XX bb ss ii)
+expand_h(or_XX bb ss ii)
expand_h(sub_XX ss ii ff cc)
add_custom_target(blocks_generated_includes DEPENDS
diff --git a/gr-blocks/include/blocks/or_XX.h.t b/gr-blocks/include/blocks/or_XX.h.t
new file mode 100644
index 000000000..8bc9a080f
--- /dev/null
+++ b/gr-blocks/include/blocks/or_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input_0 | input_1 | , ... | input_N)
+ * \ingroup math_blk
+ *
+ * Bitwise boolean or across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 3bf1db750..3e3650d67 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -96,6 +96,7 @@ expand_cc_h_impl(multiply_XX ss ii)
expand_cc_h_impl(multiply_const_XX ss ii)
expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
expand_cc_h_impl(not_XX bb ss ii)
+expand_cc_h_impl(or_XX bb ss ii)
expand_cc_h_impl(sub_XX ss ii ff cc)
########################################################################
diff --git a/gr-blocks/lib/or_XX_impl.cc.t b/gr-blocks/lib/or_XX_impl.cc.t
new file mode 100644
index 000000000..15f6fa0b8
--- /dev/null
+++ b/gr-blocks/lib/or_XX_impl.cc.t
@@ -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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc |= ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/or_XX_impl.h.t b/gr-blocks/lib/or_XX_impl.h.t
new file mode 100644
index 000000000..25f0da0c8
--- /dev/null
+++ b/gr-blocks/lib/or_XX_impl.h.t
@@ -0,0 +1,48 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py
index dc011c14e..43de72a89 100755
--- a/gr-blocks/python/qa_boolean_operators.py
+++ b/gr-blocks/python/qa_boolean_operators.py
@@ -143,12 +143,11 @@ class test_boolean_operators (gr_unittest.TestCase):
self.assertEqual(dst.data(), expected_result)
- """
def test_or_ss (self):
src1_data = (1, 2, 3, 0x5004, 0x1150)
src2_data = (8, 2, 1 , 0x0508, 0x1105)
expected_result = (9, 2, 3, 0x550C, 0x1155)
- op = gr.or_ss ()
+ op = blocks_swig.or_ss ()
self.help_ss ((src1_data, src2_data),
expected_result, op)
@@ -157,7 +156,7 @@ class test_boolean_operators (gr_unittest.TestCase):
src2_data = (8, 2, 2, 1 , 0x08, 0x05)
src3_data = (8, 2, 1, 1 , 0x08, 0x05)
expected_result = (9, 2, 3, 3, 0x0C, 0x55)
- op = gr.or_bb ()
+ op = blocks_swig.or_bb ()
self.help_bb ((src1_data, src2_data, src3_data),
expected_result, op)
@@ -165,11 +164,10 @@ class test_boolean_operators (gr_unittest.TestCase):
src1_data = (1, 2, 3, 0x50005004, 0x11001150)
src2_data = (8, 2, 1 , 0x05000508, 0x11001105)
expected_result = (9, 2, 3, 0x5500550C, 0x11001155)
- op = gr.or_ii ()
+ op = blocks_swig.or_ii ()
self.help_ii ((src1_data, src2_data),
expected_result, op)
- """
def test_not_ss (self):
src1_data = (1, 2, 3, 0x5004, 0x1150)
expected_result = (~1, ~2, ~3, ~0x5004, ~0x1150)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 38e815a98..9cb48191c 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -88,6 +88,9 @@
#include "blocks/not_bb.h"
#include "blocks/not_ss.h"
#include "blocks/not_ii.h"
+#include "blocks/or_bb.h"
+#include "blocks/or_ss.h"
+#include "blocks/or_ii.h"
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
#include "blocks/sub_ff.h"
@@ -157,6 +160,9 @@
%include "blocks/not_bb.h"
%include "blocks/not_ss.h"
%include "blocks/not_ii.h"
+%include "blocks/or_bb.h"
+%include "blocks/or_ss.h"
+%include "blocks/or_ii.h"
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
%include "blocks/sub_ff.h"
@@ -225,6 +231,9 @@ GR_SWIG_BLOCK_MAGIC2(blocks, nlog10_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, not_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, not_ss);
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, short_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
--
cgit
From a76cd7d47576054d7fac37710a8f79b908d18b00 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Wed, 4 Jul 2012 07:22:49 -0700
Subject: blocks: added gr::blocks::xor_XX (bb ss ii)
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_xor_xx.xml | 48 ++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/xor_XX.h.t | 53 ++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/xor_XX_impl.cc.t | 69 ++++++++++++++++++++++++++++++++
gr-blocks/lib/xor_XX_impl.h.t | 48 ++++++++++++++++++++++
gr-blocks/python/qa_boolean_operators.py | 11 ++---
gr-blocks/swig/blocks_swig.i | 9 +++++
9 files changed, 236 insertions(+), 5 deletions(-)
create mode 100644 gr-blocks/grc/blocks_xor_xx.xml
create mode 100644 gr-blocks/include/blocks/xor_XX.h.t
create mode 100644 gr-blocks/lib/xor_XX_impl.cc.t
create mode 100644 gr-blocks/lib/xor_XX_impl.h.t
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index e2658a373..853086858 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -47,6 +47,7 @@
blocks_and_const_xx.xmlblocks_not_xx.xmlblocks_or_xx.xml
+ blocks_xor_xx.xmlStream Type Conversions (New)
diff --git a/gr-blocks/grc/blocks_xor_xx.xml b/gr-blocks/grc/blocks_xor_xx.xml
new file mode 100644
index 000000000..d2886a4e0
--- /dev/null
+++ b/gr-blocks/grc/blocks_xor_xx.xml
@@ -0,0 +1,48 @@
+
+
+
+ Xor
+ blocks_xor_xx
+ from gnuradio import blocks
+ blocks.xor_$(type.fcn)()
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+ $num_inputs >= 2
+
+ in
+ $type
+ $num_inputs
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 434fb2944..523ac2bb3 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -77,6 +77,7 @@ expand_h(multiply_const_vXX ss ii ff cc)
expand_h(not_XX bb ss ii)
expand_h(or_XX bb ss ii)
expand_h(sub_XX ss ii ff cc)
+expand_h(xor_XX bb ss ii)
add_custom_target(blocks_generated_includes DEPENDS
${generated_includes}
diff --git a/gr-blocks/include/blocks/xor_XX.h.t b/gr-blocks/include/blocks/xor_XX.h.t
new file mode 100644
index 000000000..ba0c508f6
--- /dev/null
+++ b/gr-blocks/include/blocks/xor_XX.h.t
@@ -0,0 +1,53 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME@
+#define @GUARD_NAME@
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief output = input_0 ^ input_1 ^ , ... ^ input_N)
+ * \ingroup math_blk
+ *
+ * Bitwise boolean xor across all input streams.
+ */
+ class BLOCKS_API @NAME@ : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::@NAME@::sptr
+ typedef boost::shared_ptr<@NAME@> sptr;
+
+ static sptr make(size_t vlen=1);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* @GUARD_NAME@ */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 3e3650d67..77f0c6eca 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -98,6 +98,7 @@ expand_cc_h_impl(multiply_const_vXX ss ii ff cc)
expand_cc_h_impl(not_XX bb ss ii)
expand_cc_h_impl(or_XX bb ss ii)
expand_cc_h_impl(sub_XX ss ii ff cc)
+expand_cc_h_impl(xor_XX bb ss ii)
########################################################################
# Setup the include and linker paths
diff --git a/gr-blocks/lib/xor_XX_impl.cc.t b/gr-blocks/lib/xor_XX_impl.cc.t
new file mode 100644
index 000000000..eea926512
--- /dev/null
+++ b/gr-blocks/lib/xor_XX_impl.cc.t
@@ -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.
+ */
+
+// @WARNING@
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <@NAME_IMPL@.h>
+#include
+
+namespace gr {
+ namespace blocks {
+
+ @NAME@::sptr @NAME@::make(size_t vlen)
+ {
+ return gnuradio::get_initial_sptr(new @NAME_IMPL@(vlen));
+ }
+
+ @NAME_IMPL@::@NAME_IMPL@(size_t vlen)
+ : gr_sync_block ("@NAME@",
+ gr_make_io_signature (1, -1, sizeof (@I_TYPE@)*vlen),
+ gr_make_io_signature (1, 1, sizeof (@O_TYPE@)*vlen)),
+ d_vlen(vlen)
+ {
+ }
+
+ int
+ @NAME_IMPL@::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ @O_TYPE@ *optr = (@O_TYPE@ *) output_items[0];
+
+ int ninputs = input_items.size ();
+
+ for (size_t i = 0; i < noutput_items*d_vlen; i++){
+ @I_TYPE@ acc = ((@I_TYPE@ *) input_items[0])[i];
+ for (int j = 1; j < ninputs; j++)
+ acc ^= ((@I_TYPE@ *) input_items[j])[i];
+
+ *optr++ = (@O_TYPE@) acc;
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/xor_XX_impl.h.t b/gr-blocks/lib/xor_XX_impl.h.t
new file mode 100644
index 000000000..25f0da0c8
--- /dev/null
+++ b/gr-blocks/lib/xor_XX_impl.h.t
@@ -0,0 +1,48 @@
+/* -*- 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.
+ */
+
+// @WARNING@
+
+#ifndef @GUARD_NAME_IMPL@
+#define @GUARD_NAME_IMPL@
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API @NAME_IMPL@ : public @NAME@
+ {
+ size_t d_vlen;
+
+ public:
+ @NAME_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 /* @GUARD_NAME_IMPL@ */
diff --git a/gr-blocks/python/qa_boolean_operators.py b/gr-blocks/python/qa_boolean_operators.py
index 43de72a89..5572f60ac 100755
--- a/gr-blocks/python/qa_boolean_operators.py
+++ b/gr-blocks/python/qa_boolean_operators.py
@@ -60,12 +60,12 @@ class test_boolean_operators (gr_unittest.TestCase):
self.tb.run ()
result_data = dst.data ()
self.assertEqual (exp_data, result_data)
- """
+
def test_xor_ss (self):
src1_data = (1, 2, 3, 0x5004, 0x1150)
src2_data = (8, 2, 1 , 0x0508, 0x1105)
expected_result = (9, 0, 2, 0x550C, 0x0055)
- op = gr.xor_ss ()
+ op = blocks_swig.xor_ss ()
self.help_ss ((src1_data, src2_data),
expected_result, op)
@@ -73,7 +73,7 @@ class test_boolean_operators (gr_unittest.TestCase):
src1_data = (1, 2, 3, 4, 0x50)
src2_data = (8, 2, 1 , 8, 0x05)
expected_result = (9, 0, 2, 0xC, 0x55)
- op = gr.xor_bb ()
+ op = blocks_swig.xor_bb ()
self.help_bb ((src1_data, src2_data),
expected_result, op)
@@ -82,10 +82,11 @@ class test_boolean_operators (gr_unittest.TestCase):
src1_data = (1, 2, 3, 0x5000004, 0x11000050)
src2_data = (8, 2, 1 , 0x0500008, 0x11000005)
expected_result = (9, 0, 2, 0x550000C, 0x00000055)
- op = gr.xor_ii ()
+ op = blocks_swig.xor_ii ()
self.help_ii ((src1_data, src2_data),
expected_result, op)
- """
+
+
def test_and_ss (self):
src1_data = (1, 2, 3, 0x5004, 0x1150)
src2_data = (8, 2, 1 , 0x0508, 0x1105)
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 9cb48191c..4405b91b7 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -98,6 +98,9 @@
#include "blocks/sub_ii.h"
#include "blocks/sub_cc.h"
#include "blocks/uchar_to_float.h"
+#include "blocks/xor_bb.h"
+#include "blocks/xor_ss.h"
+#include "blocks/xor_ii.h"
%}
%include "blocks/add_ff.h"
@@ -170,6 +173,9 @@
%include "blocks/sub_ii.h"
%include "blocks/sub_cc.h"
%include "blocks/uchar_to_float.h"
+%include "blocks/xor_bb.h"
+%include "blocks/xor_ss.h"
+%include "blocks/xor_ii.h"
GR_SWIG_BLOCK_MAGIC2(blocks, add_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, add_ss);
@@ -241,3 +247,6 @@ GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float);
+GR_SWIG_BLOCK_MAGIC2(blocks, xor_bb);
+GR_SWIG_BLOCK_MAGIC2(blocks, xor_ss);
+GR_SWIG_BLOCK_MAGIC2(blocks, xor_ii);
--
cgit
From 44647064669928517b233ca26bd97cd87847a235 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 5 Jul 2012 09:25:29 -0700
Subject: blocks: added gr::blocks::deinterleave
---
gr-blocks/grc/blocks_block_tree.xml | 4 ++
gr-blocks/grc/blocks_deinterleave.xml | 67 ++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/deinterleave.h | 50 ++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/deinterleave_impl.cc | 76 ++++++++++++++++++++++++++++++
gr-blocks/lib/deinterleave_impl.h | 49 +++++++++++++++++++
gr-blocks/python/qa_interleave.py | 83 +++++++++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 334 insertions(+)
create mode 100644 gr-blocks/grc/blocks_deinterleave.xml
create mode 100644 gr-blocks/include/blocks/deinterleave.h
create mode 100644 gr-blocks/lib/deinterleave_impl.cc
create mode 100644 gr-blocks/lib/deinterleave_impl.h
create mode 100755 gr-blocks/python/qa_interleave.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 853086858..e4aed9809 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -71,4 +71,8 @@
blocks_short_to_floatblocks_uchar_to_float
+
+ Stream Operations (New)
+ blocks_deinterleave.xml
+
diff --git a/gr-blocks/grc/blocks_deinterleave.xml b/gr-blocks/grc/blocks_deinterleave.xml
new file mode 100644
index 000000000..103091324
--- /dev/null
+++ b/gr-blocks/grc/blocks_deinterleave.xml
@@ -0,0 +1,67 @@
+
+
+
+ Deinterleave
+ blocks_deinterleave
+ from gnuradio import blocks
+ blocks.deinterleave($type.size*$vlen)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Streams
+ num_streams
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_streams > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 523ac2bb3..c3ad9d033 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -100,6 +100,7 @@ install(FILES
complex_to_mag_squared.h
complex_to_arg.h
conjugate_cc.h
+ deinterleave.h
float_to_char.h
float_to_complex.h
float_to_int.h
diff --git a/gr-blocks/include/blocks/deinterleave.h b/gr-blocks/include/blocks/deinterleave.h
new file mode 100644
index 000000000..24074d2fc
--- /dev/null
+++ b/gr-blocks/include/blocks/deinterleave.h
@@ -0,0 +1,50 @@
+/* -*- 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_DEINTERLEAVE_H
+#define INCLUDED_BLOCKS_DEINTERLEAVE_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief deinterleave a single input into N outputs
+ * \ingroup slicedice_blk
+ * \param itemsize stream itemsize
+ */
+ class BLOCKS_API deinterleave : virtual public gr_sync_decimator
+ {
+ public:
+
+ // gr::blocks::deinterleave::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_DEINTERLEAVE_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 77f0c6eca..081064629 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -134,6 +134,7 @@ list(APPEND gr_blocks_sources
complex_to_mag_squared_impl.cc
complex_to_arg_impl.cc
conjugate_cc_impl.cc
+ deinterleave_impl.cc
float_to_char_impl.cc
float_to_complex_impl.cc
float_array_to_int.cc
diff --git a/gr-blocks/lib/deinterleave_impl.cc b/gr-blocks/lib/deinterleave_impl.cc
new file mode 100644
index 000000000..badf4973a
--- /dev/null
+++ b/gr-blocks/lib/deinterleave_impl.cc
@@ -0,0 +1,76 @@
+/* -*- 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 "deinterleave_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ deinterleave::sptr deinterleave::make(size_t itemsize)
+ {
+ return gnuradio::get_initial_sptr(new deinterleave_impl(itemsize));
+ }
+
+ deinterleave_impl::deinterleave_impl(size_t itemsize)
+ : gr_sync_decimator("deinterleave",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (1, gr_io_signature::IO_INFINITE, itemsize),
+ 1),
+ d_itemsize(itemsize)
+ {
+ }
+
+ bool
+ deinterleave_impl::check_topology(int ninputs, int noutputs)
+ {
+ set_decimation(noutputs);
+ return true;
+ }
+
+ int
+ deinterleave_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t nchan = output_items.size();
+ size_t itemsize = d_itemsize;
+ const char *in = (const char *)input_items[0];
+ char **out = (char **)&output_items[0];
+
+ for (int i = 0; i < noutput_items; i++){
+ for (unsigned int n = 0; n < nchan; n++){
+ memcpy(out[n], in, itemsize);
+ out[n] += itemsize;
+ in += itemsize;
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/deinterleave_impl.h b/gr-blocks/lib/deinterleave_impl.h
new file mode 100644
index 000000000..762c9d5fe
--- /dev/null
+++ b/gr-blocks/lib/deinterleave_impl.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_DEINTERLEAVE_IMPL_H
+#define INCLUDED_DEINTERLEAVE_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API deinterleave_impl : public deinterleave
+ {
+ size_t d_itemsize;
+
+ public:
+ deinterleave_impl(size_t itemsize);
+
+ bool check_topology(int ninputs, int noutputs);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_DEINTERLEAVE_IMPL_H */
diff --git a/gr-blocks/python/qa_interleave.py b/gr-blocks/python/qa_interleave.py
new file mode 100755
index 000000000..56c8bdfdf
--- /dev/null
+++ b/gr-blocks/python/qa_interleave.py
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2007,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_interleave (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ """
+ def test_int_001 (self):
+ lenx = 64
+ src0 = gr.vector_source_f (range (0, lenx, 4))
+ src1 = gr.vector_source_f (range (1, lenx, 4))
+ src2 = gr.vector_source_f (range (2, lenx, 4))
+ src3 = gr.vector_source_f (range (3, lenx, 4))
+ op = gr.interleave (gr.sizeof_float)
+ dst = gr.vector_sink_f ()
+
+ self.tb.connect (src0, (op, 0))
+ self.tb.connect (src1, (op, 1))
+ self.tb.connect (src2, (op, 2))
+ self.tb.connect (src3, (op, 3))
+ self.tb.connect (op, dst)
+ self.tb.run ()
+ expected_result = tuple (range (lenx))
+ result_data = dst.data ()
+ self.assertFloatTuplesAlmostEqual (expected_result, result_data)
+ """
+ def test_deint_001 (self):
+ lenx = 64
+ src = gr.vector_source_f (range (lenx))
+ op = blocks_swig.deinterleave (gr.sizeof_float)
+ dst0 = gr.vector_sink_f ()
+ dst1 = gr.vector_sink_f ()
+ dst2 = gr.vector_sink_f ()
+ dst3 = gr.vector_sink_f ()
+
+ self.tb.connect (src, op)
+ self.tb.connect ((op, 0), dst0)
+ self.tb.connect ((op, 1), dst1)
+ self.tb.connect ((op, 2), dst2)
+ self.tb.connect ((op, 3), dst3)
+ self.tb.run ()
+
+ expected_result0 = tuple (range (0, lenx, 4))
+ expected_result1 = tuple (range (1, lenx, 4))
+ expected_result2 = tuple (range (2, lenx, 4))
+ expected_result3 = tuple (range (3, lenx, 4))
+
+ self.assertFloatTuplesAlmostEqual (expected_result0, dst0.data ())
+ self.assertFloatTuplesAlmostEqual (expected_result1, dst1.data ())
+ self.assertFloatTuplesAlmostEqual (expected_result2, dst2.data ())
+ self.assertFloatTuplesAlmostEqual (expected_result3, dst3.data ())
+
+if __name__ == '__main__':
+ gr_unittest.run(test_interleave, "test_interleave.xml")
+
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 4405b91b7..4bd87db3f 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -56,6 +56,7 @@
#include "blocks/complex_to_mag_squared.h"
#include "blocks/complex_to_arg.h"
#include "blocks/conjugate_cc.h"
+#include "blocks/deinterleave.h"
#include "blocks/divide_ff.h"
#include "blocks/divide_ss.h"
#include "blocks/divide_ii.h"
@@ -131,6 +132,7 @@
%include "blocks/complex_to_mag_squared.h"
%include "blocks/complex_to_arg.h"
%include "blocks/conjugate_cc.h"
+%include "blocks/deinterleave.h"
%include "blocks/divide_ff.h"
%include "blocks/divide_ss.h"
%include "blocks/divide_ii.h"
@@ -205,6 +207,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag_squared);
GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_arg);
GR_SWIG_BLOCK_MAGIC2(blocks, conjugate_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, deinterleave);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii);
--
cgit
From 27694edd168bc1260ff04950e837a6580afc49ab Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Fri, 6 Jul 2012 08:17:40 -0700
Subject: blocks: added gr::blocks::interleave
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_interleave.xml | 67 +++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/interleave.h | 50 ++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/interleave_impl.cc | 76 +++++++++++++++++++++++++++++++++
gr-blocks/lib/interleave_impl.h | 49 +++++++++++++++++++++
gr-blocks/python/qa_interleave.py | 5 +--
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 250 insertions(+), 3 deletions(-)
create mode 100644 gr-blocks/grc/blocks_interleave.xml
create mode 100644 gr-blocks/include/blocks/interleave.h
create mode 100644 gr-blocks/lib/interleave_impl.cc
create mode 100644 gr-blocks/lib/interleave_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index e4aed9809..dfbe88b05 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -74,5 +74,6 @@
Stream Operations (New) blocks_deinterleave.xml
+ blocks_interleave.xml
diff --git a/gr-blocks/grc/blocks_interleave.xml b/gr-blocks/grc/blocks_interleave.xml
new file mode 100644
index 000000000..f01a3be6d
--- /dev/null
+++ b/gr-blocks/grc/blocks_interleave.xml
@@ -0,0 +1,67 @@
+
+
+
+ Interleave
+ blocks_interleave
+ from gnuradio import blocks
+ blocks.interleave($type.size*$vlen)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Streams
+ num_streams
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_streams > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+ $num_streams
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index c3ad9d033..a8a1c5a62 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -107,6 +107,7 @@ install(FILES
float_to_short.h
float_to_uchar.h
int_to_float.h
+ interleave.h
interleaved_short_to_complex.h
multiply_cc.h
multiply_ff.h
diff --git a/gr-blocks/include/blocks/interleave.h b/gr-blocks/include/blocks/interleave.h
new file mode 100644
index 000000000..e98d01df9
--- /dev/null
+++ b/gr-blocks/include/blocks/interleave.h
@@ -0,0 +1,50 @@
+/* -*- 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_INTERLEAVE_H
+#define INCLUDED_BLOCKS_INTERLEAVE_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief interleave N inputs into a single output
+ * \ingroup slicedice_blk
+ * \param itemsize stream itemsize
+ */
+ class BLOCKS_API interleave : virtual public gr_sync_interpolator
+ {
+ public:
+
+ // gr::blocks::interleave::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_INTERLEAVE_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 081064629..f224330d4 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -143,6 +143,7 @@ list(APPEND gr_blocks_sources
float_array_to_uchar.cc
float_to_uchar_impl.cc
int_to_float_impl.cc
+ interleave_impl.cc
interleaved_short_array_to_complex.cc
interleaved_short_to_complex_impl.cc
multiply_cc_impl.cc
diff --git a/gr-blocks/lib/interleave_impl.cc b/gr-blocks/lib/interleave_impl.cc
new file mode 100644
index 000000000..df37ed26d
--- /dev/null
+++ b/gr-blocks/lib/interleave_impl.cc
@@ -0,0 +1,76 @@
+/* -*- 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 "interleave_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ interleave::sptr interleave::make(size_t itemsize)
+ {
+ return gnuradio::get_initial_sptr(new interleave_impl(itemsize));
+ }
+
+ interleave_impl::interleave_impl(size_t itemsize)
+ : gr_sync_interpolator("interleave",
+ gr_make_io_signature (1, gr_io_signature::IO_INFINITE, itemsize),
+ gr_make_io_signature (1, 1, itemsize),
+ 1),
+ d_itemsize(itemsize)
+ {
+ }
+
+ bool
+ interleave_impl::check_topology(int ninputs, int noutputs)
+ {
+ set_interpolation(ninputs);
+ return true;
+ }
+
+ int
+ interleave_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t nchan = input_items.size();
+ size_t itemsize = d_itemsize;
+ const char **in = (const char **)&input_items[0];
+ char *out = (char *)output_items[0];
+
+ for (int i = 0; i < noutput_items; i += nchan) {
+ for (unsigned int n = 0; n < nchan; n++) {
+ memcpy (out, in[n], itemsize);
+ out += itemsize;
+ in[n] += itemsize;
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/interleave_impl.h b/gr-blocks/lib/interleave_impl.h
new file mode 100644
index 000000000..a02517e3e
--- /dev/null
+++ b/gr-blocks/lib/interleave_impl.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_INTERLEAVE_IMPL_H
+#define INCLUDED_INTERLEAVE_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API interleave_impl : public interleave
+ {
+ size_t d_itemsize;
+
+ public:
+ interleave_impl(size_t itemsize);
+
+ bool check_topology(int ninputs, int noutputs);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_INTERLEAVE_IMPL_H */
diff --git a/gr-blocks/python/qa_interleave.py b/gr-blocks/python/qa_interleave.py
index 56c8bdfdf..376d487b1 100755
--- a/gr-blocks/python/qa_interleave.py
+++ b/gr-blocks/python/qa_interleave.py
@@ -32,14 +32,13 @@ class test_interleave (gr_unittest.TestCase):
def tearDown (self):
self.tb = None
- """
def test_int_001 (self):
lenx = 64
src0 = gr.vector_source_f (range (0, lenx, 4))
src1 = gr.vector_source_f (range (1, lenx, 4))
src2 = gr.vector_source_f (range (2, lenx, 4))
src3 = gr.vector_source_f (range (3, lenx, 4))
- op = gr.interleave (gr.sizeof_float)
+ op = blocks_swig.interleave (gr.sizeof_float)
dst = gr.vector_sink_f ()
self.tb.connect (src0, (op, 0))
@@ -51,7 +50,7 @@ class test_interleave (gr_unittest.TestCase):
expected_result = tuple (range (lenx))
result_data = dst.data ()
self.assertFloatTuplesAlmostEqual (expected_result, result_data)
- """
+
def test_deint_001 (self):
lenx = 64
src = gr.vector_source_f (range (lenx))
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 4bd87db3f..108232e0f 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -71,6 +71,7 @@
#include "blocks/integrate_ii.h"
#include "blocks/integrate_ff.h"
#include "blocks/integrate_cc.h"
+#include "blocks/interleave.h"
#include "blocks/interleaved_short_to_complex.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
@@ -147,6 +148,7 @@
%include "blocks/integrate_ii.h"
%include "blocks/integrate_ff.h"
%include "blocks/integrate_cc.h"
+%include "blocks/interleave.h"
%include "blocks/interleaved_short_to_complex.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
@@ -222,6 +224,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, integrate_cc);
+GR_SWIG_BLOCK_MAGIC2(blocks, interleave);
GR_SWIG_BLOCK_MAGIC2(blocks, interleaved_short_to_complex);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
--
cgit
From 4e06f35f611aff2e1d4983327da54cf63e5b9ada Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Sat, 7 Jul 2012 07:06:51 -0700
Subject: blocks: added gr::blocks::keep_one_in_n
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_keep_one_in_n.xml | 67 +++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/keep_one_in_n.h | 51 +++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/keep_one_in_n_impl.cc | 109 +++++++++++++++++++++++++++++++
gr-blocks/lib/keep_one_in_n_impl.h | 53 +++++++++++++++
gr-blocks/python/qa_keep_one_in_n.py | 46 +++++++++++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 332 insertions(+)
create mode 100644 gr-blocks/grc/blocks_keep_one_in_n.xml
create mode 100644 gr-blocks/include/blocks/keep_one_in_n.h
create mode 100644 gr-blocks/lib/keep_one_in_n_impl.cc
create mode 100644 gr-blocks/lib/keep_one_in_n_impl.h
create mode 100755 gr-blocks/python/qa_keep_one_in_n.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index dfbe88b05..37cd2fc4d 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -75,5 +75,6 @@
Stream Operations (New) blocks_deinterleave.xmlblocks_interleave.xml
+ blocks_keep_one_in_n.xml
diff --git a/gr-blocks/grc/blocks_keep_one_in_n.xml b/gr-blocks/grc/blocks_keep_one_in_n.xml
new file mode 100644
index 000000000..4289a984f
--- /dev/null
+++ b/gr-blocks/grc/blocks_keep_one_in_n.xml
@@ -0,0 +1,67 @@
+
+
+
+ Keep 1 in N
+ blocks_keep_one_in_n
+ from gnuradio import blocks
+ blocks.keep_one_in_n($type.size*$vlen, $n)
+ set_n($n)
+
+ Type
+ type
+ enum
+
+
+
+
+
+
+
+ N
+ n
+ 1
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $n > 0
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index a8a1c5a62..5b4c0e437 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -109,6 +109,7 @@ install(FILES
int_to_float.h
interleave.h
interleaved_short_to_complex.h
+ keep_one_in_n.h
multiply_cc.h
multiply_ff.h
multiply_conjugate_cc.h
diff --git a/gr-blocks/include/blocks/keep_one_in_n.h b/gr-blocks/include/blocks/keep_one_in_n.h
new file mode 100644
index 000000000..c48784994
--- /dev/null
+++ b/gr-blocks/include/blocks/keep_one_in_n.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_KEEP_ONE_IN_N_H
+#define INCLUDED_BLOCKS_KEEP_ONE_IN_N_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief decimate a stream, keeping one item out of every n.
+ * \ingroup slicedice_blk
+ */
+ class BLOCKS_API keep_one_in_n : virtual public gr_block
+ {
+ public:
+
+ // gr::blocks::keep_one_in_n::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, int n);
+
+ virtual void set_n(int n) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_KEEP_ONE_IN_N_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index f224330d4..1e34b544f 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -146,6 +146,7 @@ list(APPEND gr_blocks_sources
interleave_impl.cc
interleaved_short_array_to_complex.cc
interleaved_short_to_complex_impl.cc
+ keep_one_in_n_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
multiply_conjugate_cc_impl.cc
diff --git a/gr-blocks/lib/keep_one_in_n_impl.cc b/gr-blocks/lib/keep_one_in_n_impl.cc
new file mode 100644
index 000000000..7ab6dc14d
--- /dev/null
+++ b/gr-blocks/lib/keep_one_in_n_impl.cc
@@ -0,0 +1,109 @@
+/* -*- 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 "keep_one_in_n_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ keep_one_in_n::sptr keep_one_in_n::make(size_t itemsize, int n)
+ {
+ return gnuradio::get_initial_sptr(new keep_one_in_n_impl(itemsize, n));
+ }
+
+ keep_one_in_n_impl::keep_one_in_n_impl(size_t itemsize, int n)
+ : gr_block("keep_one_in_n",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (1, 1, itemsize)),
+ d_count(n)
+ {
+ // To avoid bad behavior with using set_relative_rate in this block with
+ // VERY large values of n, we will keep track of things ourselves. Using
+ // this to turn off automatic tag propagation, which will be handled
+ // locally in general_work().
+ set_tag_propagation_policy(TPP_DONT);
+
+ set_n(n);
+ }
+
+ void
+ keep_one_in_n_impl::set_n(int n)
+ {
+ if (n < 1)
+ n = 1;
+
+ d_n = n;
+ d_count = n;
+
+ // keep our internal understanding of the relative rate of this block
+ // don't set the relative rate, though, and we will handle our own
+ // tag propagation.
+ d_decim_rate = 1.0/(float)d_n;
+ }
+
+ int
+ keep_one_in_n_impl::general_work(int noutput_items,
+ gr_vector_int &ninput_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];
+
+ size_t item_size = input_signature ()->sizeof_stream_item (0);
+ int ni = 0;
+ int no = 0;
+
+ while (ni < ninput_items[0] && no < noutput_items){
+ d_count--;
+ if (d_count <= 0){
+ memcpy (out, in, item_size); // copy 1 item
+ out += item_size;
+ no++;
+ d_count = d_n;
+ }
+ in += item_size;
+ ni++;
+ }
+
+ // Because we have set TPP_DONT, we have to propagate the tags here manually.
+ // Adjustment of the tag sample value is done using the float d_decim_rate.
+ std::vector tags;
+ std::vector::iterator t;
+ get_tags_in_range(tags, 0, nitems_read(0), nitems_read(0)+ni);
+ for(t = tags.begin(); t != tags.end(); t++) {
+ gr_tag_t new_tag = *t;
+ new_tag.offset *= d_decim_rate;
+ add_item_tag(0, new_tag);
+ }
+
+ consume_each (ni);
+ return no;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/keep_one_in_n_impl.h b/gr-blocks/lib/keep_one_in_n_impl.h
new file mode 100644
index 000000000..1588fb1a6
--- /dev/null
+++ b/gr-blocks/lib/keep_one_in_n_impl.h
@@ -0,0 +1,53 @@
+
+/* -*- 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_KEEP_ONE_IN_N_IMPL_H
+#define INCLUDED_KEEP_ONE_IN_N_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API keep_one_in_n_impl : public keep_one_in_n
+ {
+ int d_n;
+ int d_count;
+ float d_decim_rate;
+
+ public:
+ keep_one_in_n_impl(size_t itemsize,int n);
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ void set_n(int n);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_KEEP_ONE_IN_N_IMPL_H */
diff --git a/gr-blocks/python/qa_keep_one_in_n.py b/gr-blocks/python/qa_keep_one_in_n.py
new file mode 100755
index 000000000..8c5f44b84
--- /dev/null
+++ b/gr-blocks/python/qa_keep_one_in_n.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+#
+# 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.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig
+
+class test_keep_one_in_n(gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def test_001(self):
+ src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
+ expected_data = (5, 10)
+ src = gr.vector_source_b(src_data);
+ op = blocks_swig.keep_one_in_n(gr.sizeof_char, 5)
+ dst = gr.vector_sink_b()
+ self.tb.connect(src, op, dst)
+ self.tb.run()
+ self.assertEqual(dst.data(), expected_data)
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_keep_one_in_n, "test_integrate.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 108232e0f..ea3071805 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -73,6 +73,7 @@
#include "blocks/integrate_cc.h"
#include "blocks/interleave.h"
#include "blocks/interleaved_short_to_complex.h"
+#include "blocks/keep_one_in_n.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
#include "blocks/multiply_ff.h"
@@ -150,6 +151,7 @@
%include "blocks/integrate_cc.h"
%include "blocks/interleave.h"
%include "blocks/interleaved_short_to_complex.h"
+%include "blocks/keep_one_in_n.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
%include "blocks/multiply_ff.h"
@@ -226,6 +228,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, integrate_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, interleave);
GR_SWIG_BLOCK_MAGIC2(blocks, interleaved_short_to_complex);
+GR_SWIG_BLOCK_MAGIC2(blocks, keep_one_in_n);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ff);
--
cgit
From bbd91d7a08bfc0c229267e5dc848d1f57d629373 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 19 Jul 2012 06:27:19 -0700
Subject: blocks: added gr::blocks::keep_m_in_n
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_keep_m_in_n.xml | 76 ++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/keep_m_in_n.h | 53 ++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/keep_m_in_n_impl.cc | 87 +++++++++++++++++++++++++++++++++
gr-blocks/lib/keep_m_in_n_impl.h | 58 ++++++++++++++++++++++
gr-blocks/python/qa_keep_m_in_n.py | 59 ++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 339 insertions(+)
create mode 100644 gr-blocks/grc/blocks_keep_m_in_n.xml
create mode 100644 gr-blocks/include/blocks/keep_m_in_n.h
create mode 100644 gr-blocks/lib/keep_m_in_n_impl.cc
create mode 100644 gr-blocks/lib/keep_m_in_n_impl.h
create mode 100755 gr-blocks/python/qa_keep_m_in_n.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 37cd2fc4d..c2e45b9eb 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -75,6 +75,7 @@
Stream Operations (New) blocks_deinterleave.xmlblocks_interleave.xml
+ blocks_keep_m_in_n.xmlblocks_keep_one_in_n.xml
diff --git a/gr-blocks/grc/blocks_keep_m_in_n.xml b/gr-blocks/grc/blocks_keep_m_in_n.xml
new file mode 100644
index 000000000..9e861749b
--- /dev/null
+++ b/gr-blocks/grc/blocks_keep_m_in_n.xml
@@ -0,0 +1,76 @@
+
+
+
+ Keep M in N
+ blocks_keep_m_in_n
+ from gnuradio import blocks
+ blocks.keep_m_in_n($type.size, $m, $n, $offset)
+ set_offset($offset)
+ set_m($m)
+ set_n($n)
+
+ Type
+ type
+ enum
+
+
+
+
+
+
+
+ M
+ m
+ 1
+ int
+
+
+ N
+ n
+ 2
+ int
+
+
+ initial offset
+ offset
+ 0
+ int
+
+ $n > 0
+ $m > 0
+ $m < $n
+
+ in
+ $type
+ 1
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 5b4c0e437..0db0eebd2 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -109,6 +109,7 @@ install(FILES
int_to_float.h
interleave.h
interleaved_short_to_complex.h
+ keep_m_in_n.h
keep_one_in_n.h
multiply_cc.h
multiply_ff.h
diff --git a/gr-blocks/include/blocks/keep_m_in_n.h b/gr-blocks/include/blocks/keep_m_in_n.h
new file mode 100644
index 000000000..806ec3de5
--- /dev/null
+++ b/gr-blocks/include/blocks/keep_m_in_n.h
@@ -0,0 +1,53 @@
+/* -*- 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_KEEP_M_IN_N_H
+#define INCLUDED_BLOCKS_KEEP_M_IN_N_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief decimate a stream, keeping one item out of every n.
+ * \ingroup slicedice_blk
+ */
+ class BLOCKS_API keep_m_in_n : virtual public gr_block
+ {
+ public:
+
+ // gr::blocks::keep_m_in_n::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, int m, int n, int offset);
+
+ virtual void set_m(int m) = 0;
+ virtual void set_n(int n) = 0;
+ virtual void set_offset(int offset) = 0;
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_KEEP_M_IN_N_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 1e34b544f..e4aca48f0 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -146,6 +146,7 @@ list(APPEND gr_blocks_sources
interleave_impl.cc
interleaved_short_array_to_complex.cc
interleaved_short_to_complex_impl.cc
+ keep_m_in_n_impl.cc
keep_one_in_n_impl.cc
multiply_cc_impl.cc
multiply_ff_impl.cc
diff --git a/gr-blocks/lib/keep_m_in_n_impl.cc b/gr-blocks/lib/keep_m_in_n_impl.cc
new file mode 100644
index 000000000..b3efdd962
--- /dev/null
+++ b/gr-blocks/lib/keep_m_in_n_impl.cc
@@ -0,0 +1,87 @@
+/* -*- 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 "keep_m_in_n_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ keep_m_in_n::sptr keep_m_in_n::make(size_t itemsize, int m, int n, int offset)
+ {
+ return gnuradio::get_initial_sptr(new keep_m_in_n_impl(itemsize, m, n, offset));
+ }
+
+ keep_m_in_n_impl::keep_m_in_n_impl(size_t itemsize, int m, int n, int offset)
+ : gr_block("keep_m_in_n",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (1, 1, itemsize)),
+ d_itemsize(itemsize),
+ d_m(m),
+ d_n(n),
+ d_offset(offset)
+ {
+ // sanity checking
+ assert(d_m > 0);
+ assert(d_n > 0);
+ assert(d_m <= d_n);
+ assert(d_offset <= (d_n-d_m));
+
+ set_output_multiple(m);
+ }
+
+ void
+ keep_m_in_n_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required)
+ {
+ ninput_items_required[0] = d_n*(noutput_items/d_m);
+ }
+
+ int
+ keep_m_in_n_impl::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ uint8_t* out = (uint8_t*)output_items[0];
+ const uint8_t* in = (const uint8_t*)input_items[0];
+
+ // iterate over data blocks of size {n, input : m, output}
+ int blks = std::min(noutput_items/d_m, ninput_items[0]/d_n);
+
+ for(int i=0; i
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API keep_m_in_n_impl : public keep_m_in_n
+ {
+ int d_n;
+ int d_m;
+ int d_count;
+ int d_offset;
+ int d_itemsize;
+
+ void forecast(int noutput_items, gr_vector_int &ninput_items_required);
+
+ public:
+ keep_m_in_n_impl(size_t itemsize, int m, int n, int offset);
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+
+ void set_m(int m) { d_m = m; }
+ void set_n(int n) { d_n = n; }
+ void set_offset(int offset) { d_offset = offset; }
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+
+#endif /* INCLUDED_KEEP_M_IN_N_IMPL_H */
diff --git a/gr-blocks/python/qa_keep_m_in_n.py b/gr-blocks/python/qa_keep_m_in_n.py
new file mode 100755
index 000000000..0898217ba
--- /dev/null
+++ b/gr-blocks/python/qa_keep_m_in_n.py
@@ -0,0 +1,59 @@
+#!/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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+
+from gnuradio import gr, gr_unittest
+import blocks_swig
+import sys
+import random
+
+class test_keep_m_in_n(gr_unittest.TestCase):
+
+ def setUp(self):
+ pass
+
+ def tearDown(self):
+ pass
+
+ def test_001(self):
+ self.maxDiff = None;
+ tb = gr.top_block()
+ src = gr.vector_source_b( range(0,100) )
+
+ # itemsize, M, N, offset
+ km2 = blocks_swig.keep_m_in_n( 1, 1, 2, 0 );
+ km3 = blocks_swig.keep_m_in_n( 1, 1, 3, 1 );
+ km7 = blocks_swig.keep_m_in_n( 1, 1, 7, 2 );
+ snk2 = gr.vector_sink_b();
+ snk3 = gr.vector_sink_b();
+ snk7 = gr.vector_sink_b();
+ tb.connect(src,km2,snk2);
+ tb.connect(src,km3,snk3);
+ tb.connect(src,km7,snk7);
+ tb.run();
+
+ self.assertEqual(range(0,100,2), list(snk2.data()));
+ self.assertEqual(range(1,100,3), list(snk3.data()));
+ self.assertEqual(range(2,100,7), list(snk7.data()));
+
+
+if __name__ == '__main__':
+ gr_unittest.run(test_keep_m_in_n, "test_keep_m_in_n.xml")
+
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index ea3071805..41c5081bb 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -73,6 +73,7 @@
#include "blocks/integrate_cc.h"
#include "blocks/interleave.h"
#include "blocks/interleaved_short_to_complex.h"
+#include "blocks/keep_m_in_n.h"
#include "blocks/keep_one_in_n.h"
#include "blocks/multiply_ss.h"
#include "blocks/multiply_ii.h"
@@ -151,6 +152,7 @@
%include "blocks/integrate_cc.h"
%include "blocks/interleave.h"
%include "blocks/interleaved_short_to_complex.h"
+%include "blocks/keep_m_in_n.h"
%include "blocks/keep_one_in_n.h"
%include "blocks/multiply_ss.h"
%include "blocks/multiply_ii.h"
@@ -228,6 +230,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, integrate_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, integrate_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, interleave);
GR_SWIG_BLOCK_MAGIC2(blocks, interleaved_short_to_complex);
+GR_SWIG_BLOCK_MAGIC2(blocks, keep_m_in_n);
GR_SWIG_BLOCK_MAGIC2(blocks, keep_one_in_n);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, multiply_ii);
--
cgit
From 66f49de1986dd531bee011299d4b1f7c62872d39 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 19 Jul 2012 07:02:45 -0700
Subject: blocks: added gr::blocks::repeat
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_repeat.xml | 64 ++++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/repeat.h | 51 ++++++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/repeat_impl.cc | 69 +++++++++++++++++++++++++++++++++
gr-blocks/lib/repeat_impl.h | 47 ++++++++++++++++++++++
gr-blocks/python/qa_repeat.py | 49 +++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 286 insertions(+)
create mode 100644 gr-blocks/grc/blocks_repeat.xml
create mode 100644 gr-blocks/include/blocks/repeat.h
create mode 100644 gr-blocks/lib/repeat_impl.cc
create mode 100644 gr-blocks/lib/repeat_impl.h
create mode 100755 gr-blocks/python/qa_repeat.py
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 @@
blocks_interleave.xmlblocks_keep_m_in_n.xmlblocks_keep_one_in_n.xml
+ blocks_repeat.xml
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 @@
+
+
+
+ Repeat
+ blocks_repeat
+ from gnuradio import blocks
+ blocks.repeat($type.size*$vlen, $interp)
+
+ Type
+ type
+ enum
+
+
+
+
+
+
+
+ Interpolation
+ interp
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+
+
+
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
+#include
+
+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 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
+
+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
+
+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);
--
cgit
From 0a5bb996ca4f4bb350cf91b00b4c3db5a5c4eb75 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Wed, 29 Aug 2012 09:29:50 -0700
Subject: blocks: added gr::blocks::stream_mux
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_stream_mux.xml | 75 ++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/stream_mux.h | 69 +++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/stream_mux_impl.cc | 126 ++++++++++++++++++++++++
gr-blocks/lib/stream_mux_impl.h | 55 +++++++++++
gr-blocks/python/qa_stream_mux.py | 169 ++++++++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 500 insertions(+)
create mode 100644 gr-blocks/grc/blocks_stream_mux.xml
create mode 100644 gr-blocks/include/blocks/stream_mux.h
create mode 100644 gr-blocks/lib/stream_mux_impl.cc
create mode 100644 gr-blocks/lib/stream_mux_impl.h
create mode 100755 gr-blocks/python/qa_stream_mux.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 557bf64db..8f98f15e0 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -78,5 +78,6 @@
blocks_keep_m_in_n.xmlblocks_keep_one_in_n.xmlblocks_repeat.xml
+ stream_mux.xml
diff --git a/gr-blocks/grc/blocks_stream_mux.xml b/gr-blocks/grc/blocks_stream_mux.xml
new file mode 100644
index 000000000..5e56a65d9
--- /dev/null
+++ b/gr-blocks/grc/blocks_stream_mux.xml
@@ -0,0 +1,75 @@
+
+
+
+ Stream Mux
+ blocks_stream_mux
+ from gnuradio import blocks
+ blocks.stream_mux($type.size*$vlen, $lengths)
+
+ Type
+ type
+ enum
+
+
+
+
+
+
+
+ Lengths
+ lengths
+ 1, 1
+ int_vector
+
+
+ Num Inputs
+ num_inputs
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_inputs > 0
+ $num_inputs == len($lengths)
+ $vlen > 0
+
+ in
+ $type
+ $vlen
+ $num_inputs
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 8c14d5a49..7ec0524ae 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -120,6 +120,7 @@ install(FILES
repeat.h
short_to_char.h
short_to_float.h
+ stream_mux.h
uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
diff --git a/gr-blocks/include/blocks/stream_mux.h b/gr-blocks/include/blocks/stream_mux.h
new file mode 100644
index 000000000..905ea3c9f
--- /dev/null
+++ b/gr-blocks/include/blocks/stream_mux.h
@@ -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.
+ */
+
+#ifndef INCLUDED_BLOCKS_STREAM_MUX_H
+#define INCLUDED_BLOCKS_STREAM_MUX_H
+
+#include
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Stream muxing block to multiplex many streams into
+ * one with a specified format.
+ *
+ * Muxes N streams together producing an output stream that
+ * contains N0 items from the first stream, N1 items from the second,
+ * etc. and repeats:
+ *
+ * [N0, N1, N2, ..., Nm, N0, N1, ...]
+ */
+ class BLOCKS_API stream_mux : virtual public gr_block
+ {
+ public:
+
+ // gr::blocks::stream_mux::sptr
+ typedef boost::shared_ptr sptr;
+
+ /*!
+ * \brief Creates a stream muxing block to multiplex many streams into
+ * one with a specified format.
+ * \ingroup converter_blk
+ *
+ * \param itemsize the item size of the stream
+ * \param length a vector (list/tuple) specifying the number of
+ * items from each stream the mux together.
+ * Warning: this requires that at least as many items
+ * per stream are available or the system will wait
+ * indefinitely for the items.
+ *
+ */
+ static sptr make(size_t itemsize, const std::vector &lengths);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_STREAM_MUX_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 9b0043d4b..72e09d5f9 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -157,6 +157,7 @@ list(APPEND gr_blocks_sources
repeat_impl.cc
short_to_char_impl.cc
short_to_float_impl.cc
+ stream_mux_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
)
diff --git a/gr-blocks/lib/stream_mux_impl.cc b/gr-blocks/lib/stream_mux_impl.cc
new file mode 100644
index 000000000..214734c4b
--- /dev/null
+++ b/gr-blocks/lib/stream_mux_impl.cc
@@ -0,0 +1,126 @@
+/* -*- 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 "stream_mux_impl.h"
+#include
+#include
+#include
+
+#define VERBOSE 0
+
+namespace gr {
+ namespace blocks {
+
+ stream_mux::sptr stream_mux::make(size_t itemsize, const std::vector &lengths)
+ {
+ return gnuradio::get_initial_sptr(new stream_mux_impl(itemsize, lengths));
+ }
+
+ stream_mux_impl::stream_mux_impl(size_t itemsize, const std::vector &lengths)
+ : gr_block("stream_mux",
+ gr_make_io_signature (1, -1, itemsize),
+ gr_make_io_signature (1, 1, itemsize)),
+ d_itemsize(itemsize),
+ d_stream(0),
+ d_residual(0),
+ d_lengths(lengths)
+ {
+ if(d_lengths[d_stream] == 0) {
+ increment_stream();
+ }
+ d_residual = d_lengths[d_stream];
+ }
+
+ void
+ stream_mux_impl::forecast(int noutput_items, gr_vector_int &ninput_items_required)
+ {
+ unsigned ninputs = ninput_items_required.size ();
+ for (unsigned i = 0; i < ninputs; i++)
+ ninput_items_required[i] = (d_lengths[i] == 0 ? 0 : 1);
+ }
+
+ void
+ stream_mux_impl::increment_stream()
+ {
+ do {
+ d_stream = (d_stream+1) % d_lengths.size();
+ } while(d_lengths[d_stream] == 0);
+
+ d_residual = d_lengths[d_stream];
+ }
+
+
+ int
+ stream_mux_impl::general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ char *out = (char *) output_items[0];
+ const char *in;
+ int out_index = 0;
+ std::vector input_index(d_lengths.size(), 0);
+
+ if(VERBOSE) {
+ printf("mux: nouput_items: %d d_stream: %d\n", noutput_items, d_stream);
+ for(size_t i = 0; i < d_lengths.size(); i++)
+ printf("\tninput_items[%zu]: %d\n", i, ninput_items[i]);
+ }
+
+ while (1) {
+ int r = std::min(noutput_items - out_index,
+ std::min(d_residual,
+ ninput_items[d_stream] - input_index[d_stream]));
+ if(VERBOSE) {
+ printf("mux: r=%d\n", r);
+ printf("\tnoutput_items - out_index: %d\n",
+ noutput_items - out_index);
+ printf("\td_residual: %d\n",
+ d_residual);
+ printf("\tninput_items[d_stream] - input_index[d_stream]: %d\n",
+ ninput_items[d_stream] - input_index[d_stream]);
+ }
+
+ if(r <= 0) {
+ return out_index;
+ }
+
+ in = (const char *) input_items[d_stream] + input_index[d_stream]*d_itemsize;
+
+ memcpy(&out[out_index*d_itemsize], in, r*d_itemsize);
+ out_index += r;
+ input_index[d_stream] += r;
+ d_residual -= r;
+
+ consume(d_stream, r);
+
+ if(d_residual == 0) {
+ increment_stream();
+ }
+ }
+ }
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/stream_mux_impl.h b/gr-blocks/lib/stream_mux_impl.h
new file mode 100644
index 000000000..7b2dac95c
--- /dev/null
+++ b/gr-blocks/lib/stream_mux_impl.h
@@ -0,0 +1,55 @@
+/* -*- 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_STREAM_MUX_IMPL_H
+#define INCLUDED_STREAM_MUX_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API stream_mux_impl : public stream_mux
+ {
+ private:
+ size_t d_itemsize;
+ unsigned int d_stream; // index of currently selected stream
+ int d_residual; // number if items left to put into current stream
+ gr_vector_int d_lengths; // number if items to pack per stream
+
+ void increment_stream();
+
+ void forecast(int noutput_items, gr_vector_int &ninput_items_required);
+
+ public:
+ stream_mux_impl(size_t itemsize, const std::vector &lengths);
+
+ int general_work(int noutput_items,
+ gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_STREAM_MUX_IMPL_H */
diff --git a/gr-blocks/python/qa_stream_mux.py b/gr-blocks/python/qa_stream_mux.py
new file mode 100755
index 000000000..f21a9bbbc
--- /dev/null
+++ b/gr-blocks/python/qa_stream_mux.py
@@ -0,0 +1,169 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2005,2007,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
+
+class test_stream_mux (gr_unittest.TestCase):
+
+ def setUp (self):
+ self.tb = gr.top_block ()
+
+ def tearDown (self):
+ self.tb = None
+
+ def help_stream_2ff(self, N, stream_sizes):
+ v0 = gr.vector_source_f(N*[1,], False)
+ v1 = gr.vector_source_f(N*[2,], False)
+
+ mux = blocks_swig.stream_mux(gr.sizeof_float, stream_sizes)
+
+ dst = gr.vector_sink_f ()
+
+ self.tb.connect (v0, (mux,0))
+ self.tb.connect (v1, (mux,1))
+ self.tb.connect (mux, dst)
+ self.tb.run ()
+
+ return dst.data ()
+
+ def help_stream_ramp_2ff(self, N, stream_sizes):
+ r1 = range(N)
+ r2 = range(N)
+ r2.reverse()
+
+ v0 = gr.vector_source_f(r1, False)
+ v1 = gr.vector_source_f(r2, False)
+
+ mux = blocks_swig.stream_mux(gr.sizeof_float, stream_sizes)
+
+ dst = gr.vector_sink_f ()
+
+ self.tb.connect (v0, (mux,0))
+ self.tb.connect (v1, (mux,1))
+ self.tb.connect (mux, dst)
+ self.tb.run ()
+
+ return dst.data ()
+
+ def test_stream_2NN_ff(self):
+ N = 40
+ stream_sizes = [10, 10]
+ result_data = self.help_stream_2ff(N, stream_sizes)
+
+ exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0)
+ self.assertEqual (exp_data, result_data)
+
+ def test_stream_ramp_2NN_ff(self):
+ N = 40
+ stream_sizes = [10, 10]
+ result_data = self.help_stream_ramp_2ff(N, stream_sizes)
+
+ exp_data = ( 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0,
+ 39.0, 38.0, 37.0, 36.0, 35.0, 34.0, 33.0, 32.0, 31.0, 30.0,
+ 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0,
+ 29.0, 28.0, 27.0, 26.0, 25.0, 24.0, 23.0, 22.0, 21.0, 20.0,
+ 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0, 27.0, 28.0, 29.0,
+ 19.0, 18.0, 17.0, 16.0, 15.0, 14.0, 13.0, 12.0, 11.0, 10.0,
+ 30.0, 31.0, 32.0, 33.0, 34.0, 35.0, 36.0, 37.0, 38.0, 39.0,
+ 9.0, 8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0)
+ self.assertEqual (exp_data, result_data)
+
+ def test_stream_2NM_ff(self):
+ N = 40
+ stream_sizes = [7, 9]
+ self.help_stream_2ff(N, stream_sizes)
+
+ result_data = self.help_stream_2ff(N, stream_sizes)
+
+ exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0)
+
+ self.assertEqual (exp_data, result_data)
+
+
+ def test_stream_2MN_ff(self):
+ N = 37
+ stream_sizes = [7, 9]
+ self.help_stream_2ff(N, stream_sizes)
+
+ result_data = self.help_stream_2ff(N, stream_sizes)
+
+ exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 2.0)
+
+ self.assertEqual (exp_data, result_data)
+
+ def test_stream_2N0_ff(self):
+ N = 30
+ stream_sizes = [7, 0]
+ self.help_stream_2ff(N, stream_sizes)
+
+ result_data = self.help_stream_2ff(N, stream_sizes)
+
+ exp_data = (1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ 1.0, 1.0)
+
+ self.assertEqual (exp_data, result_data)
+
+ def test_stream_20N_ff(self):
+ N = 30
+ stream_sizes = [0, 9]
+ self.help_stream_2ff(N, stream_sizes)
+
+ result_data = self.help_stream_2ff(N, stream_sizes)
+
+ exp_data = (2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0,
+ 2.0, 2.0, 2.0)
+
+ self.assertEqual (exp_data, result_data)
+
+if __name__ == '__main__':
+ gr_unittest.run(test_stream_mux, "test_stream_mux.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 3161dd773..a99d90d4f 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -98,6 +98,7 @@
#include "blocks/repeat.h"
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
+#include "blocks/stream_mux.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -178,6 +179,7 @@
%include "blocks/repeat.h"
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
+%include "blocks/stream_mux.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -257,6 +259,7 @@ 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, stream_mux);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit
From b434b7329301fee49ab82a81ac68517f8ab042eb Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Thu, 30 Aug 2012 14:29:28 -0700
Subject: blocks: added gr::blocks::stream_to_streams
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_stream_to_streams.xml | 67 +++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/stream_to_streams.h | 52 ++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/stream_to_streams_impl.cc | 70 ++++++++++++++
gr-blocks/lib/stream_to_streams_impl.h | 44 +++++++++
gr-blocks/python/qa_pipe_fittings.py | 138 +++++++++++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 +
9 files changed, 377 insertions(+)
create mode 100644 gr-blocks/grc/blocks_stream_to_streams.xml
create mode 100644 gr-blocks/include/blocks/stream_to_streams.h
create mode 100644 gr-blocks/lib/stream_to_streams_impl.cc
create mode 100644 gr-blocks/lib/stream_to_streams_impl.h
create mode 100755 gr-blocks/python/qa_pipe_fittings.py
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 8f98f15e0..076c1b221 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -79,5 +79,6 @@
blocks_keep_one_in_n.xmlblocks_repeat.xmlstream_mux.xml
+ stream_to_streams.xml
diff --git a/gr-blocks/grc/blocks_stream_to_streams.xml b/gr-blocks/grc/blocks_stream_to_streams.xml
new file mode 100644
index 000000000..c164e477b
--- /dev/null
+++ b/gr-blocks/grc/blocks_stream_to_streams.xml
@@ -0,0 +1,67 @@
+
+
+
+ Stream to Streams
+ blocks_stream_to_streams
+ from gnuradio import blocks
+ blocks.stream_to_streams($type.size*$vlen, $num_streams)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Streams
+ num_streams
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_streams > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 7ec0524ae..191f15031 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -121,6 +121,7 @@ install(FILES
short_to_char.h
short_to_float.h
stream_mux.h
+ stream_to_streams.h
uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
diff --git a/gr-blocks/include/blocks/stream_to_streams.h b/gr-blocks/include/blocks/stream_to_streams.h
new file mode 100644
index 000000000..fc39f1687
--- /dev/null
+++ b/gr-blocks/include/blocks/stream_to_streams.h
@@ -0,0 +1,52 @@
+/* -*- 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_STREAM_TO_STREAMS_H
+#define INCLUDED_BLOCKS_STREAM_TO_STREAMS_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief convert a stream of items into a N streams of items
+ * \ingroup slicedice_blk
+ *
+ * Converts a stream of N items into N streams of 1 item.
+ * Repeat ad infinitum.
+ */
+ class BLOCKS_API stream_to_streams : virtual public gr_sync_decimator
+ {
+ public:
+
+ // gr::blocks::stream_to_streams::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, size_t nstreams);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_STREAM_TO_STREAMS_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 72e09d5f9..4cb3bc995 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -158,6 +158,7 @@ list(APPEND gr_blocks_sources
short_to_char_impl.cc
short_to_float_impl.cc
stream_mux_impl.cc
+ stream_to_streams_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
)
diff --git a/gr-blocks/lib/stream_to_streams_impl.cc b/gr-blocks/lib/stream_to_streams_impl.cc
new file mode 100644
index 000000000..9e9052e7d
--- /dev/null
+++ b/gr-blocks/lib/stream_to_streams_impl.cc
@@ -0,0 +1,70 @@
+/* -*- 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 "stream_to_streams_impl.h"
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ stream_to_streams::sptr stream_to_streams::make(size_t itemsize, size_t nstreams)
+ {
+ return gnuradio::get_initial_sptr(new stream_to_streams_impl(itemsize, nstreams));
+ }
+
+ stream_to_streams_impl::stream_to_streams_impl(size_t itemsize, size_t nstreams)
+ : gr_sync_decimator("stream_to_streams",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (nstreams, nstreams, itemsize),
+ nstreams)
+ {
+ }
+
+ int
+ stream_to_streams_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t item_size = output_signature()->sizeof_stream_item(0);
+
+ const char *in = (const char *)input_items[0];
+ char **outv = (char **)&output_items[0];
+ int nstreams = output_items.size();
+
+ for (int i = 0; i < noutput_items; i++) {
+ for (int j = 0; j < nstreams; j++) {
+ memcpy(outv[j], in, item_size);
+ outv[j] += item_size;
+ in += item_size;
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/stream_to_streams_impl.h b/gr-blocks/lib/stream_to_streams_impl.h
new file mode 100644
index 000000000..9a96983ff
--- /dev/null
+++ b/gr-blocks/lib/stream_to_streams_impl.h
@@ -0,0 +1,44 @@
+/* -*- 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_STREAM_TO_STREAMS_IMPL_H
+#define INCLUDED_STREAM_TO_STREAMS_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API stream_to_streams_impl : public stream_to_streams
+ {
+ public:
+ stream_to_streams_impl(size_t itemsize, size_t nstreams);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_STREAM_TO_STREAMS_IMPL_H */
diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py
new file mode 100755
index 000000000..097856867
--- /dev/null
+++ b/gr-blocks/python/qa_pipe_fittings.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2007,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
+
+def calc_expected_result(src_data, n):
+ assert (len(src_data) % n) == 0
+ result = [list() for x in range(n)]
+ #print "len(result) =", len(result)
+ for i in xrange(len(src_data)):
+ (result[i % n]).append(src_data[i])
+ return [tuple(x) for x in result]
+
+
+class test_pipe_fittings(gr_unittest.TestCase):
+
+ def setUp(self):
+ self.tb = gr.top_block ()
+
+ def tearDown(self):
+ self.tb = None
+
+ def test_001(self):
+ """
+ Test stream_to_streams.
+ """
+ n = 8
+ src_len = n * 8
+ src_data = range(src_len)
+
+ expected_results = calc_expected_result(src_data, n)
+ #print "expected results: ", expected_results
+ src = gr.vector_source_i(src_data)
+ op = gr.stream_to_streams(gr.sizeof_int, n)
+ self.tb.connect(src, op)
+
+ dsts = []
+ for i in range(n):
+ dst = gr.vector_sink_i()
+ self.tb.connect((op, i), (dst, 0))
+ dsts.append(dst)
+
+ self.tb.run()
+
+ for d in range(n):
+ self.assertEqual(expected_results[d], dsts[d].data())
+ """
+ def test_002(self):
+
+ # Test streams_to_stream (using stream_to_streams).
+
+ n = 8
+ src_len = n * 8
+ src_data = tuple(range(src_len))
+ expected_results = src_data
+
+ src = gr.vector_source_i(src_data)
+ op1 = gr.stream_to_streams(gr.sizeof_int, n)
+ op2 = gr.streams_to_stream(gr.sizeof_int, n)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1)
+ for i in range(n):
+ self.tb.connect((op1, i), (op2, i))
+ self.tb.connect(op2, dst)
+
+ self.tb.run()
+ self.assertEqual(expected_results, dst.data())
+
+ def test_003(self):
+
+ #Test streams_to_vector (using stream_to_streams & vector_to_stream).
+
+ n = 8
+ src_len = n * 8
+ src_data = tuple(range(src_len))
+ expected_results = src_data
+
+ src = gr.vector_source_i(src_data)
+ op1 = gr.stream_to_streams(gr.sizeof_int, n)
+ op2 = gr.streams_to_vector(gr.sizeof_int, n)
+ op3 = gr.vector_to_stream(gr.sizeof_int, n)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1)
+ for i in range(n):
+ self.tb.connect((op1, i), (op2, i))
+ self.tb.connect(op2, op3, dst)
+
+ self.tb.run()
+ self.assertEqual(expected_results, dst.data())
+
+ def test_004(self):
+
+ #Test vector_to_streams.
+
+ n = 8
+ src_len = n * 8
+ src_data = tuple(range(src_len))
+ expected_results = src_data
+
+ src = gr.vector_source_i(src_data)
+ op1 = gr.stream_to_vector(gr.sizeof_int, n)
+ op2 = gr.vector_to_streams(gr.sizeof_int, n)
+ op3 = gr.streams_to_stream(gr.sizeof_int, n)
+ dst = gr.vector_sink_i()
+
+ self.tb.connect(src, op1, op2)
+ for i in range(n):
+ self.tb.connect((op2, i), (op3, i))
+ self.tb.connect(op3, dst)
+
+ self.tb.run()
+ self.assertEqual(expected_results, dst.data())
+ """
+
+if __name__ == '__main__':
+ gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml")
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index a99d90d4f..903f56550 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -99,6 +99,7 @@
#include "blocks/short_to_char.h"
#include "blocks/short_to_float.h"
#include "blocks/stream_mux.h"
+#include "blocks/stream_to_streams.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -180,6 +181,7 @@
%include "blocks/short_to_char.h"
%include "blocks/short_to_float.h"
%include "blocks/stream_mux.h"
+%include "blocks/stream_to_streams.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -260,6 +262,7 @@ 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, stream_mux);
+GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit
From 0aec5b7f568b0cfc320a202631757efc247aca6e Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 4 Sep 2012 15:21:35 -0700
Subject: blocks: added gr::blocks::stream_to_vector
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_stream_to_vector.xml | 66 +++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/stream_to_vector.h | 49 +++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/stream_to_vector_impl.cc | 62 +++++++++++++++++++++++++++
gr-blocks/lib/stream_to_vector_impl.h | 44 +++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
8 files changed, 227 insertions(+)
create mode 100644 gr-blocks/grc/blocks_stream_to_vector.xml
create mode 100644 gr-blocks/include/blocks/stream_to_vector.h
create mode 100644 gr-blocks/lib/stream_to_vector_impl.cc
create mode 100644 gr-blocks/lib/stream_to_vector_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 076c1b221..6bd39c4f4 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -80,5 +80,6 @@
blocks_repeat.xmlstream_mux.xmlstream_to_streams.xml
+ stream_to_vector.xml
diff --git a/gr-blocks/grc/blocks_stream_to_vector.xml b/gr-blocks/grc/blocks_stream_to_vector.xml
new file mode 100644
index 000000000..8965dfbfe
--- /dev/null
+++ b/gr-blocks/grc/blocks_stream_to_vector.xml
@@ -0,0 +1,66 @@
+
+
+
+ Stream to Vector
+ blocks_stream_to_vector
+ from gnuradio import blocks
+ blocks.stream_to_vector($type.size*$vlen, $num_items)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Items
+ num_items
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_items > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 191f15031..1612ea7ec 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -122,6 +122,7 @@ install(FILES
short_to_float.h
stream_mux.h
stream_to_streams.h
+ stream_to_vector.h
uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
diff --git a/gr-blocks/include/blocks/stream_to_vector.h b/gr-blocks/include/blocks/stream_to_vector.h
new file mode 100644
index 000000000..8311eb350
--- /dev/null
+++ b/gr-blocks/include/blocks/stream_to_vector.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_STREAM_TO_VECTOR_H
+#define INCLUDED_BLOCKS_STREAM_TO_VECTOR_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief convert a stream of items into a stream of blocks containing nitems_per_block
+ * \ingroup slicedice_blk
+ */
+ class BLOCKS_API stream_to_vector : virtual public gr_sync_decimator
+ {
+ public:
+
+ // gr::blocks::stream_to_vector::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, size_t nitems_per_block);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_STREAM_TO_VECTOR_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 4cb3bc995..df0fa87af 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -159,6 +159,7 @@ list(APPEND gr_blocks_sources
short_to_float_impl.cc
stream_mux_impl.cc
stream_to_streams_impl.cc
+ stream_to_vector_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
)
diff --git a/gr-blocks/lib/stream_to_vector_impl.cc b/gr-blocks/lib/stream_to_vector_impl.cc
new file mode 100644
index 000000000..80ced5a74
--- /dev/null
+++ b/gr-blocks/lib/stream_to_vector_impl.cc
@@ -0,0 +1,62 @@
+/* -*- 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 "stream_to_vector_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ stream_to_vector::sptr stream_to_vector::make(size_t itemsize, size_t nitems_per_block)
+ {
+ return gnuradio::get_initial_sptr(new stream_to_vector_impl(itemsize, nitems_per_block));
+ }
+
+ stream_to_vector_impl::stream_to_vector_impl(size_t itemsize, size_t nitems_per_block)
+ : gr_sync_decimator ("stream_to_vector",
+ gr_make_io_signature (1, 1, itemsize),
+ gr_make_io_signature (1, 1, itemsize * nitems_per_block),
+ nitems_per_block)
+ {
+ }
+
+ int
+ stream_to_vector_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t block_size = output_signature()->sizeof_stream_item (0);
+
+ const char *in = (const char *) input_items[0];
+ char *out = (char *) output_items[0];
+
+ memcpy (out, in, noutput_items * block_size);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/stream_to_vector_impl.h b/gr-blocks/lib/stream_to_vector_impl.h
new file mode 100644
index 000000000..f8031f005
--- /dev/null
+++ b/gr-blocks/lib/stream_to_vector_impl.h
@@ -0,0 +1,44 @@
+/* -*- 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_STREAM_TO_VECTOR_IMPL_H
+#define INCLUDED_STREAM_TO_VECTOR_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API stream_to_vector_impl : public stream_to_vector
+ {
+ public:
+ stream_to_vector_impl(size_t itemsize, size_t nitems_per_block);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_STREAM_TO_VECTOR_IMPL_H */
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 903f56550..64996f2b2 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -100,6 +100,7 @@
#include "blocks/short_to_float.h"
#include "blocks/stream_mux.h"
#include "blocks/stream_to_streams.h"
+#include "blocks/stream_to_vector.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -182,6 +183,7 @@
%include "blocks/short_to_float.h"
%include "blocks/stream_mux.h"
%include "blocks/stream_to_streams.h"
+%include "blocks/stream_to_vector.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -263,6 +265,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char);
GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams);
+GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_vector);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit
From 2065177207d9f504fdcd374ed6567379c51c7a06 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 4 Sep 2012 15:38:17 -0700
Subject: blocks: added gr::blocks::streams_to_stream
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_streams_to_stream.xml | 67 ++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/streams_to_stream.h | 52 ++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/streams_to_stream_impl.cc | 72 ++++++++++++++++++++++++++++
gr-blocks/lib/streams_to_stream_impl.h | 44 +++++++++++++++++
gr-blocks/python/qa_pipe_fittings.py | 3 +-
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 243 insertions(+), 1 deletion(-)
create mode 100644 gr-blocks/grc/blocks_streams_to_stream.xml
create mode 100644 gr-blocks/include/blocks/streams_to_stream.h
create mode 100644 gr-blocks/lib/streams_to_stream_impl.cc
create mode 100644 gr-blocks/lib/streams_to_stream_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 6bd39c4f4..1bcf672b9 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -81,5 +81,6 @@
stream_mux.xmlstream_to_streams.xmlstream_to_vector.xml
+ streams_to_stream.xml
diff --git a/gr-blocks/grc/blocks_streams_to_stream.xml b/gr-blocks/grc/blocks_streams_to_stream.xml
new file mode 100644
index 000000000..2aa17dbe2
--- /dev/null
+++ b/gr-blocks/grc/blocks_streams_to_stream.xml
@@ -0,0 +1,67 @@
+
+
+
+ Streams to Stream
+ blocks_streams_to_stream
+ from gnuradio import blocks
+ blocks.streams_to_stream($type.size*$vlen, $num_streams)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Streams
+ num_streams
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_streams > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+ $num_streams
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index 1612ea7ec..d7d13c4e0 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -123,6 +123,7 @@ install(FILES
stream_mux.h
stream_to_streams.h
stream_to_vector.h
+ streams_to_stream.h
uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
diff --git a/gr-blocks/include/blocks/streams_to_stream.h b/gr-blocks/include/blocks/streams_to_stream.h
new file mode 100644
index 000000000..01dcd1be3
--- /dev/null
+++ b/gr-blocks/include/blocks/streams_to_stream.h
@@ -0,0 +1,52 @@
+/* -*- 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_STREAMS_TO_STREAM_H
+#define INCLUDED_BLOCKS_STREAMS_TO_STREAM_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief Convert N streams of 1 item into a 1 stream of N items
+ * \ingroup slicedice_blk
+ *
+ * Convert N streams of 1 item into 1 stream of N items.
+ * Repeat ad infinitum.
+ */
+ class BLOCKS_API streams_to_stream : virtual public gr_sync_interpolator
+ {
+ public:
+
+ // gr::blocks::streams_to_stream::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, size_t nstreams);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_STREAMS_TO_STREAM_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index df0fa87af..504aafaa2 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -160,6 +160,7 @@ list(APPEND gr_blocks_sources
stream_mux_impl.cc
stream_to_streams_impl.cc
stream_to_vector_impl.cc
+ streams_to_stream_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
)
diff --git a/gr-blocks/lib/streams_to_stream_impl.cc b/gr-blocks/lib/streams_to_stream_impl.cc
new file mode 100644
index 000000000..09c593e81
--- /dev/null
+++ b/gr-blocks/lib/streams_to_stream_impl.cc
@@ -0,0 +1,72 @@
+/* -*- 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 "streams_to_stream_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ streams_to_stream::sptr streams_to_stream::make(size_t itemsize, size_t nstreams)
+ {
+ return gnuradio::get_initial_sptr(new streams_to_stream_impl(itemsize, nstreams));
+ }
+
+ streams_to_stream_impl::streams_to_stream_impl(size_t itemsize, size_t nstreams)
+ : gr_sync_interpolator ("streams_to_stream",
+ gr_make_io_signature (nstreams, nstreams, itemsize),
+ gr_make_io_signature (1, 1, itemsize),
+ nstreams)
+ {
+ }
+
+ int
+ streams_to_stream_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t itemsize = output_signature()->sizeof_stream_item (0);
+
+ const char **inv = (const char **) &input_items[0];
+ char *out = (char *) output_items[0];
+ int nstreams = input_items.size();
+
+ assert (noutput_items % nstreams == 0);
+ int ni = noutput_items / nstreams;
+
+ for (int i = 0; i < ni; i++){
+ for (int j = 0; j < nstreams; j++){
+ memcpy(out, inv[j], itemsize);
+ out += itemsize;
+ inv[j] += itemsize;
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/streams_to_stream_impl.h b/gr-blocks/lib/streams_to_stream_impl.h
new file mode 100644
index 000000000..6f686172c
--- /dev/null
+++ b/gr-blocks/lib/streams_to_stream_impl.h
@@ -0,0 +1,44 @@
+/* -*- 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_STREAMS_TO_STREAM_IMPL_H
+#define INCLUDED_STREAMS_TO_STREAM_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API streams_to_stream_impl : public streams_to_stream
+ {
+ public:
+ streams_to_stream_impl(size_t itemsize, size_t nstreams);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_STREAMS_TO_STREAM_IMPL_H */
diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py
index 097856867..e5335e979 100755
--- a/gr-blocks/python/qa_pipe_fittings.py
+++ b/gr-blocks/python/qa_pipe_fittings.py
@@ -64,7 +64,7 @@ class test_pipe_fittings(gr_unittest.TestCase):
for d in range(n):
self.assertEqual(expected_results[d], dsts[d].data())
- """
+
def test_002(self):
# Test streams_to_stream (using stream_to_streams).
@@ -87,6 +87,7 @@ class test_pipe_fittings(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_results, dst.data())
+ """
def test_003(self):
#Test streams_to_vector (using stream_to_streams & vector_to_stream).
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 64996f2b2..d0c97a2d1 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -101,6 +101,7 @@
#include "blocks/stream_mux.h"
#include "blocks/stream_to_streams.h"
#include "blocks/stream_to_vector.h"
+#include "blocks/streams_to_stream.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -184,6 +185,7 @@
%include "blocks/stream_mux.h"
%include "blocks/stream_to_streams.h"
%include "blocks/stream_to_vector.h"
+%include "blocks/streams_to_stream.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -266,6 +268,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_vector);
+GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_stream);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit
From 14a6b7beb247128408a98acd77cef66eaef2b4c3 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 4 Sep 2012 16:01:42 -0700
Subject: blocks: added gr::blocks::streams_to_vector
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_streams_to_vector.xml | 67 +++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/streams_to_vector.h | 49 ++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/streams_to_vector_impl.cc | 68 ++++++++++++++++++++++++++++
gr-blocks/lib/streams_to_vector_impl.h | 44 ++++++++++++++++++
gr-blocks/swig/blocks_swig.i | 3 ++
8 files changed, 234 insertions(+)
create mode 100644 gr-blocks/grc/blocks_streams_to_vector.xml
create mode 100644 gr-blocks/include/blocks/streams_to_vector.h
create mode 100644 gr-blocks/lib/streams_to_vector_impl.cc
create mode 100644 gr-blocks/lib/streams_to_vector_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 1bcf672b9..6be3a21ef 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -82,5 +82,6 @@
stream_to_streams.xmlstream_to_vector.xmlstreams_to_stream.xml
+ streams_to_vector.xml
diff --git a/gr-blocks/grc/blocks_streams_to_vector.xml b/gr-blocks/grc/blocks_streams_to_vector.xml
new file mode 100644
index 000000000..dc371f021
--- /dev/null
+++ b/gr-blocks/grc/blocks_streams_to_vector.xml
@@ -0,0 +1,67 @@
+
+
+
+ Streams to Vector
+ blocks_streams_to_vector
+ from gnuradio import blocks
+ blocks.streams_to_vector($type.size*$vlen, $num_streams)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Streams
+ num_streams
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_streams > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen
+ $num_streams
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index d7d13c4e0..fbd47aceb 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -124,6 +124,7 @@ install(FILES
stream_to_streams.h
stream_to_vector.h
streams_to_stream.h
+ streams_to_vector.h
uchar_to_float.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
diff --git a/gr-blocks/include/blocks/streams_to_vector.h b/gr-blocks/include/blocks/streams_to_vector.h
new file mode 100644
index 000000000..ad55ac31f
--- /dev/null
+++ b/gr-blocks/include/blocks/streams_to_vector.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_STREAMS_TO_VECTOR_H
+#define INCLUDED_BLOCKS_STREAMS_TO_VECTOR_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief convert N streams of items to 1 stream of vector length N
+ * \ingroup slicedice_blk
+ */
+ class BLOCKS_API streams_to_vector : virtual public gr_sync_block
+ {
+ public:
+
+ // gr::blocks::streams_to_vector::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, size_t nstreams);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_STREAMS_TO_VECTOR_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 504aafaa2..64436c07f 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -161,6 +161,7 @@ list(APPEND gr_blocks_sources
stream_to_streams_impl.cc
stream_to_vector_impl.cc
streams_to_stream_impl.cc
+ streams_to_vector_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
)
diff --git a/gr-blocks/lib/streams_to_vector_impl.cc b/gr-blocks/lib/streams_to_vector_impl.cc
new file mode 100644
index 000000000..c524a78e4
--- /dev/null
+++ b/gr-blocks/lib/streams_to_vector_impl.cc
@@ -0,0 +1,68 @@
+/* -*- 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 "streams_to_vector_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ streams_to_vector::sptr streams_to_vector::make(size_t itemsize, size_t nstreams)
+ {
+ return gnuradio::get_initial_sptr(new streams_to_vector_impl(itemsize, nstreams));
+ }
+
+ streams_to_vector_impl::streams_to_vector_impl(size_t itemsize, size_t nstreams)
+ : gr_sync_block ("streams_to_vector",
+ gr_make_io_signature (nstreams, nstreams, itemsize),
+ gr_make_io_signature (1, 1, nstreams * itemsize))
+ {
+ }
+
+ int
+ streams_to_vector_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t itemsize = input_signature()->sizeof_stream_item(0);
+ int nstreams = input_items.size();
+
+ const char **inv = (const char **) &input_items[0];
+ char *out = (char *) output_items[0];
+
+ for (int i = 0; i < noutput_items; i++){
+ for (int j = 0; j < nstreams; j++){
+ memcpy(out, inv[j], itemsize);
+ inv[j] += itemsize;
+ out += itemsize;
+ }
+ }
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/streams_to_vector_impl.h b/gr-blocks/lib/streams_to_vector_impl.h
new file mode 100644
index 000000000..4a14e9d4f
--- /dev/null
+++ b/gr-blocks/lib/streams_to_vector_impl.h
@@ -0,0 +1,44 @@
+/* -*- 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_STREAMS_TO_VECTOR_IMPL_H
+#define INCLUDED_STREAMS_TO_VECTOR_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API streams_to_vector_impl : public streams_to_vector
+ {
+ public:
+ streams_to_vector_impl(size_t itemsize, size_t nstreams);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_STREAMS_TO_VECTOR_IMPL_H */
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index d0c97a2d1..69374e19d 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -102,6 +102,7 @@
#include "blocks/stream_to_streams.h"
#include "blocks/stream_to_vector.h"
#include "blocks/streams_to_stream.h"
+#include "blocks/streams_to_vector.h"
#include "blocks/sub_ff.h"
#include "blocks/sub_ss.h"
#include "blocks/sub_ii.h"
@@ -186,6 +187,7 @@
%include "blocks/stream_to_streams.h"
%include "blocks/stream_to_vector.h"
%include "blocks/streams_to_stream.h"
+%include "blocks/streams_to_vector.h"
%include "blocks/sub_ff.h"
%include "blocks/sub_ss.h"
%include "blocks/sub_ii.h"
@@ -269,6 +271,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams);
GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_vector);
GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_stream);
+GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_vector);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
--
cgit
From 73d59860c4cc0e2b22c21d56cd5cdfcb969263eb Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 4 Sep 2012 16:25:00 -0700
Subject: blocks: added gr::blocks::vector_to_stream
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_vector_to_stream.xml | 66 +++++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/vector_to_stream.h | 49 +++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/vector_to_stream_impl.cc | 62 +++++++++++++++++++++++++++
gr-blocks/lib/vector_to_stream_impl.h | 44 +++++++++++++++++++
gr-blocks/python/qa_pipe_fittings.py | 3 +-
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 228 insertions(+), 2 deletions(-)
create mode 100644 gr-blocks/grc/blocks_vector_to_stream.xml
create mode 100644 gr-blocks/include/blocks/vector_to_stream.h
create mode 100644 gr-blocks/lib/vector_to_stream_impl.cc
create mode 100644 gr-blocks/lib/vector_to_stream_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 6be3a21ef..3d66110e5 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -83,5 +83,6 @@
stream_to_vector.xmlstreams_to_stream.xmlstreams_to_vector.xml
+ vector_to_stream.xml
diff --git a/gr-blocks/grc/blocks_vector_to_stream.xml b/gr-blocks/grc/blocks_vector_to_stream.xml
new file mode 100644
index 000000000..a4a77bef8
--- /dev/null
+++ b/gr-blocks/grc/blocks_vector_to_stream.xml
@@ -0,0 +1,66 @@
+
+
+
+ Vector to Stream
+ blocks_vector_to_stream
+ from gnuradio import blocks
+ blocks.vector_to_stream($type.size*$vlen, $num_items)
+
+ IO Type
+ type
+ enum
+
+
+
+
+
+
+
+ Num Items
+ num_items
+ 2
+ int
+
+
+ Vec Length
+ vlen
+ 1
+ int
+
+ $num_items > 0
+ $vlen >= 1
+
+ in
+ $type
+ $vlen*$num_items
+
+
+
diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt
index fbd47aceb..df69ae4b0 100644
--- a/gr-blocks/include/blocks/CMakeLists.txt
+++ b/gr-blocks/include/blocks/CMakeLists.txt
@@ -126,6 +126,7 @@ install(FILES
streams_to_stream.h
streams_to_vector.h
uchar_to_float.h
+ vector_to_stream.h
DESTINATION ${GR_INCLUDE_DIR}/gnuradio/blocks
COMPONENT "blocks_devel"
)
diff --git a/gr-blocks/include/blocks/vector_to_stream.h b/gr-blocks/include/blocks/vector_to_stream.h
new file mode 100644
index 000000000..1e72f6d50
--- /dev/null
+++ b/gr-blocks/include/blocks/vector_to_stream.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_VECTOR_TO_STREAM_H
+#define INCLUDED_BLOCKS_VECTOR_TO_STREAM_H
+
+#include
+#include
+
+namespace gr {
+ namespace blocks {
+
+ /*!
+ * \brief convert a stream of blocks of nitems_per_block items into a stream of items
+ * \ingroup slicedice_blk
+ */
+ class BLOCKS_API vector_to_stream : virtual public gr_sync_interpolator
+ {
+ public:
+
+ // gr::blocks::vector_to_stream::sptr
+ typedef boost::shared_ptr sptr;
+
+ static sptr make(size_t itemsize, size_t nitems_per_block);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_BLOCKS_VECTOR_TO_STREAM_H */
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 64436c07f..cdacd60c2 100644
--- a/gr-blocks/lib/CMakeLists.txt
+++ b/gr-blocks/lib/CMakeLists.txt
@@ -164,6 +164,7 @@ list(APPEND gr_blocks_sources
streams_to_vector_impl.cc
uchar_array_to_float.cc
uchar_to_float_impl.cc
+ vector_to_stream_impl.cc
)
list(APPEND blocks_libs
diff --git a/gr-blocks/lib/vector_to_stream_impl.cc b/gr-blocks/lib/vector_to_stream_impl.cc
new file mode 100644
index 000000000..fa833a3ec
--- /dev/null
+++ b/gr-blocks/lib/vector_to_stream_impl.cc
@@ -0,0 +1,62 @@
+/* -*- 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 "vector_to_stream_impl.h"
+#include
+
+namespace gr {
+ namespace blocks {
+
+ vector_to_stream::sptr vector_to_stream::make(size_t itemsize, size_t nitems_per_block)
+ {
+ return gnuradio::get_initial_sptr(new vector_to_stream_impl(itemsize, nitems_per_block));
+ }
+
+ vector_to_stream_impl::vector_to_stream_impl(size_t itemsize, size_t nitems_per_block)
+ : gr_sync_interpolator ("vector_to_stream",
+ gr_make_io_signature (1, 1, itemsize * nitems_per_block),
+ gr_make_io_signature (1, 1, itemsize),
+ nitems_per_block)
+ {
+ }
+
+ int
+ vector_to_stream_impl::work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items)
+ {
+ size_t block_size = output_signature()->sizeof_stream_item (0);
+
+ const char *in = (const char *) input_items[0];
+ char *out = (char *) output_items[0];
+
+ memcpy (out, in, noutput_items * block_size);
+
+ return noutput_items;
+ }
+
+ } /* namespace blocks */
+} /* namespace gr */
diff --git a/gr-blocks/lib/vector_to_stream_impl.h b/gr-blocks/lib/vector_to_stream_impl.h
new file mode 100644
index 000000000..4128f6090
--- /dev/null
+++ b/gr-blocks/lib/vector_to_stream_impl.h
@@ -0,0 +1,44 @@
+/* -*- 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_VECTOR_TO_STREAM_IMPL_H
+#define INCLUDED_VECTOR_TO_STREAM_IMPL_H
+
+#include
+
+namespace gr {
+ namespace blocks {
+
+ class BLOCKS_API vector_to_stream_impl : public vector_to_stream
+ {
+ public:
+ vector_to_stream_impl(size_t itemsize, size_t nitems_per_block);
+
+ int work(int noutput_items,
+ gr_vector_const_void_star &input_items,
+ gr_vector_void_star &output_items);
+ };
+
+ } /* namespace blocks */
+} /* namespace gr */
+
+#endif /* INCLUDED_VECTOR_TO_STREAM_IMPL_H */
diff --git a/gr-blocks/python/qa_pipe_fittings.py b/gr-blocks/python/qa_pipe_fittings.py
index e5335e979..6a4ba8b3a 100755
--- a/gr-blocks/python/qa_pipe_fittings.py
+++ b/gr-blocks/python/qa_pipe_fittings.py
@@ -87,7 +87,6 @@ class test_pipe_fittings(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_results, dst.data())
- """
def test_003(self):
#Test streams_to_vector (using stream_to_streams & vector_to_stream).
@@ -110,7 +109,7 @@ class test_pipe_fittings(gr_unittest.TestCase):
self.tb.run()
self.assertEqual(expected_results, dst.data())
-
+ """
def test_004(self):
#Test vector_to_streams.
diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i
index 69374e19d..4d2268bea 100644
--- a/gr-blocks/swig/blocks_swig.i
+++ b/gr-blocks/swig/blocks_swig.i
@@ -108,6 +108,7 @@
#include "blocks/sub_ii.h"
#include "blocks/sub_cc.h"
#include "blocks/uchar_to_float.h"
+#include "blocks/vector_to_stream.h"
#include "blocks/xor_bb.h"
#include "blocks/xor_ss.h"
#include "blocks/xor_ii.h"
@@ -193,6 +194,7 @@
%include "blocks/sub_ii.h"
%include "blocks/sub_cc.h"
%include "blocks/uchar_to_float.h"
+%include "blocks/vector_to_stream.h"
%include "blocks/xor_bb.h"
%include "blocks/xor_ss.h"
%include "blocks/xor_ii.h"
@@ -277,6 +279,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii);
GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc);
GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float);
+GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_stream);
GR_SWIG_BLOCK_MAGIC2(blocks, xor_bb);
GR_SWIG_BLOCK_MAGIC2(blocks, xor_ss);
GR_SWIG_BLOCK_MAGIC2(blocks, xor_ii);
--
cgit
From c5ddf4c26bf8bc049622b2e9ffcdcdba3265b580 Mon Sep 17 00:00:00 2001
From: Johnathan Corgan
Date: Tue, 4 Sep 2012 16:39:30 -0700
Subject: blocks: added gr::blocks::vector_to_streams
---
gr-blocks/grc/blocks_block_tree.xml | 1 +
gr-blocks/grc/blocks_vector_to_streams.xml | 67 +++++++++++++++++++++++++++
gr-blocks/include/blocks/CMakeLists.txt | 1 +
gr-blocks/include/blocks/vector_to_streams.h | 49 ++++++++++++++++++++
gr-blocks/lib/CMakeLists.txt | 1 +
gr-blocks/lib/vector_to_streams_impl.cc | 68 ++++++++++++++++++++++++++++
gr-blocks/lib/vector_to_streams_impl.h | 44 ++++++++++++++++++
gr-blocks/python/qa_pipe_fittings.py | 4 +-
gr-blocks/swig/blocks_swig.i | 3 ++
9 files changed, 236 insertions(+), 2 deletions(-)
create mode 100644 gr-blocks/grc/blocks_vector_to_streams.xml
create mode 100644 gr-blocks/include/blocks/vector_to_streams.h
create mode 100644 gr-blocks/lib/vector_to_streams_impl.cc
create mode 100644 gr-blocks/lib/vector_to_streams_impl.h
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml
index 3d66110e5..94d09e9eb 100644
--- a/gr-blocks/grc/blocks_block_tree.xml
+++ b/gr-blocks/grc/blocks_block_tree.xml
@@ -84,5 +84,6 @@
streams_to_stream.xmlstreams_to_vector.xmlvector_to_stream.xml
+ vector_to_streams.xml
diff --git a/gr-blocks/grc/blocks_vector_to_streams.xml b/gr-blocks/grc/blocks_vector_to_streams.xml
new file mode 100644
index 000000000..6a246b98d
--- /dev/null
+++ b/gr-blocks/grc/blocks_vector_to_streams.xml
@@ -0,0 +1,67 @@
+
+
+
+ Vector to Streams
+ blocks_vector_to_streams
+ from gnuradio import blocks
+ blocks.vector_to_streams($type.size*$vlen, $num_streams)
+
+ IO Type
+ type
+ enum
+