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 --- 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 +++++++++++++++ 5 files changed, 359 insertions(+) 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 (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 7 ++-- gr-blocks/lib/add_const_XX_impl.cc.t | 77 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/add_const_XX_impl.h.t | 50 +++++++++++++++++++++++ 3 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 gr-blocks/lib/add_const_XX_impl.cc.t create mode 100644 gr-blocks/lib/add_const_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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(-) (limited to 'gr-blocks/lib') 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/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 ++++++++++++++++++++++++ 10 files changed, 358 insertions(+) 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 (limited to 'gr-blocks/lib') 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 */ -- 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/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 ++++++++++++++++++++ 11 files changed, 618 insertions(+), 3 deletions(-) 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 (limited to 'gr-blocks/lib') 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@ */ -- 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/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 +++++++++++++++++++++++++++ 5 files changed, 236 insertions(+) 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 (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/char_to_float_impl.cc | 65 +++++++++++++++++++++++++++++++++++++ gr-blocks/lib/char_to_float_impl.h | 51 +++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 gr-blocks/lib/char_to_float_impl.cc create mode 100644 gr-blocks/lib/char_to_float_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/char_to_short_impl.cc | 69 +++++++++++++++++++++++++++++++++++++ gr-blocks/lib/char_to_short_impl.h | 47 +++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 gr-blocks/lib/char_to_short_impl.cc create mode 100644 gr-blocks/lib/char_to_short_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_interleaved_short_impl.cc | 63 ++++++++++++++++++++++ gr-blocks/lib/complex_to_interleaved_short_impl.h | 45 ++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 gr-blocks/lib/complex_to_interleaved_short_impl.cc create mode 100644 gr-blocks/lib/complex_to_interleaved_short_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_float_impl.cc | 94 ++++++++++++++++++++++++++++++++++ gr-blocks/lib/complex_to_float_impl.h | 47 +++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 gr-blocks/lib/complex_to_float_impl.cc create mode 100644 gr-blocks/lib/complex_to_float_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_real_impl.cc | 72 +++++++++++++++++++++++++++++++++++ gr-blocks/lib/complex_to_real_impl.h | 47 +++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 gr-blocks/lib/complex_to_real_impl.cc create mode 100644 gr-blocks/lib/complex_to_real_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_imag_impl.cc | 72 +++++++++++++++++++++++++++++++++++ gr-blocks/lib/complex_to_imag_impl.h | 47 +++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 gr-blocks/lib/complex_to_imag_impl.cc create mode 100644 gr-blocks/lib/complex_to_imag_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_mag_impl.cc | 66 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/complex_to_mag_impl.h | 47 +++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 gr-blocks/lib/complex_to_mag_impl.cc create mode 100644 gr-blocks/lib/complex_to_mag_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_mag_squared_impl.cc | 70 ++++++++++++++++++++++++++++ gr-blocks/lib/complex_to_mag_squared_impl.h | 47 +++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 gr-blocks/lib/complex_to_mag_squared_impl.cc create mode 100644 gr-blocks/lib/complex_to_mag_squared_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/complex_to_arg_impl.cc | 70 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/complex_to_arg_impl.h | 47 ++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 gr-blocks/lib/complex_to_arg_impl.cc create mode 100644 gr-blocks/lib/complex_to_arg_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/float_to_char_impl.cc | 69 +++++++++++++++++++++++++++++++++++++ gr-blocks/lib/float_to_char_impl.h | 51 +++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 gr-blocks/lib/float_to_char_impl.cc create mode 100644 gr-blocks/lib/float_to_char_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/float_to_complex_impl.cc | 78 ++++++++++++++++++++++++++++++++++ gr-blocks/lib/float_to_complex_impl.h | 47 ++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 gr-blocks/lib/float_to_complex_impl.cc create mode 100644 gr-blocks/lib/float_to_complex_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/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 +++++++++++++++++++++++ 5 files changed, 216 insertions(+), 1 deletion(-) 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 (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/float_to_short_impl.cc | 69 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/float_to_short_impl.h | 51 ++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 gr-blocks/lib/float_to_short_impl.cc create mode 100644 gr-blocks/lib/float_to_short_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/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 ++++++++++++++++++++++++++ 5 files changed, 185 insertions(+) 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 (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/int_to_float_impl.cc | 68 ++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/int_to_float_impl.h | 51 ++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 gr-blocks/lib/int_to_float_impl.cc create mode 100644 gr-blocks/lib/int_to_float_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/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 ++++++++++++++++ 5 files changed, 183 insertions(+) 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 (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/short_to_char_impl.cc | 69 +++++++++++++++++++++++++++++++++++++ gr-blocks/lib/short_to_char_impl.h | 47 +++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 gr-blocks/lib/short_to_char_impl.cc create mode 100644 gr-blocks/lib/short_to_char_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/short_to_float_impl.cc | 68 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/short_to_float_impl.h | 51 +++++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 gr-blocks/lib/short_to_float_impl.cc create mode 100644 gr-blocks/lib/short_to_float_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/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 ++++++++++++++++++++++++++ 5 files changed, 181 insertions(+) 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 (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/conjugate_cc_impl.cc | 68 ++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/conjugate_cc_impl.h | 44 ++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 gr-blocks/lib/conjugate_cc_impl.cc create mode 100644 gr-blocks/lib/conjugate_cc_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/integrate_XX_impl.cc.t | 68 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/integrate_XX_impl.h.t | 49 ++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 gr-blocks/lib/integrate_XX_impl.cc.t create mode 100644 gr-blocks/lib/integrate_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/multiply_conjugate_cc_impl.cc | 71 +++++++++++++++++++++++++++++ gr-blocks/lib/multiply_conjugate_cc_impl.h | 47 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 gr-blocks/lib/multiply_conjugate_cc_impl.cc create mode 100644 gr-blocks/lib/multiply_conjugate_cc_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/nlog10_ff_impl.cc | 64 +++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/nlog10_ff_impl.h | 49 +++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 gr-blocks/lib/nlog10_ff_impl.cc create mode 100644 gr-blocks/lib/nlog10_ff_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/and_XX_impl.cc.t | 69 ++++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/and_XX_impl.h.t | 48 +++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 gr-blocks/lib/and_XX_impl.cc.t create mode 100644 gr-blocks/lib/and_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/and_const_XX_impl.cc.t | 77 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/and_const_XX_impl.h.t | 51 ++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 gr-blocks/lib/and_const_XX_impl.cc.t create mode 100644 gr-blocks/lib/and_const_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/not_XX_impl.cc.t | 65 ++++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/not_XX_impl.h.t | 48 +++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 gr-blocks/lib/not_XX_impl.cc.t create mode 100644 gr-blocks/lib/not_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/or_XX_impl.cc.t | 69 +++++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/or_XX_impl.h.t | 48 ++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 gr-blocks/lib/or_XX_impl.cc.t create mode 100644 gr-blocks/lib/or_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/xor_XX_impl.cc.t | 69 ++++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/xor_XX_impl.h.t | 48 +++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) create mode 100644 gr-blocks/lib/xor_XX_impl.cc.t create mode 100644 gr-blocks/lib/xor_XX_impl.h.t (limited to 'gr-blocks/lib') 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@ */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/deinterleave_impl.cc | 76 ++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/deinterleave_impl.h | 49 ++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 gr-blocks/lib/deinterleave_impl.cc create mode 100644 gr-blocks/lib/deinterleave_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/interleave_impl.cc | 76 ++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/interleave_impl.h | 49 ++++++++++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 gr-blocks/lib/interleave_impl.cc create mode 100644 gr-blocks/lib/interleave_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/keep_one_in_n_impl.cc | 109 ++++++++++++++++++++++++++++++++++++ gr-blocks/lib/keep_one_in_n_impl.h | 53 ++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 gr-blocks/lib/keep_one_in_n_impl.cc create mode 100644 gr-blocks/lib/keep_one_in_n_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/keep_m_in_n_impl.cc | 87 +++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/keep_m_in_n_impl.h | 58 ++++++++++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 gr-blocks/lib/keep_m_in_n_impl.cc create mode 100644 gr-blocks/lib/keep_m_in_n_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/repeat_impl.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/repeat_impl.h | 47 ++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 gr-blocks/lib/repeat_impl.cc create mode 100644 gr-blocks/lib/repeat_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/stream_mux_impl.cc | 126 +++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/stream_mux_impl.h | 55 +++++++++++++++++ 3 files changed, 182 insertions(+) create mode 100644 gr-blocks/lib/stream_mux_impl.cc create mode 100644 gr-blocks/lib/stream_mux_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/stream_to_streams_impl.cc | 70 +++++++++++++++++++++++++++++++++ gr-blocks/lib/stream_to_streams_impl.h | 44 +++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 gr-blocks/lib/stream_to_streams_impl.cc create mode 100644 gr-blocks/lib/stream_to_streams_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/stream_to_vector_impl.cc | 62 ++++++++++++++++++++++++++++++++++ gr-blocks/lib/stream_to_vector_impl.h | 44 ++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 gr-blocks/lib/stream_to_vector_impl.cc create mode 100644 gr-blocks/lib/stream_to_vector_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/streams_to_stream_impl.cc | 72 +++++++++++++++++++++++++++++++++ gr-blocks/lib/streams_to_stream_impl.h | 44 ++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 gr-blocks/lib/streams_to_stream_impl.cc create mode 100644 gr-blocks/lib/streams_to_stream_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/streams_to_vector_impl.cc | 68 +++++++++++++++++++++++++++++++++ gr-blocks/lib/streams_to_vector_impl.h | 44 +++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 gr-blocks/lib/streams_to_vector_impl.cc create mode 100644 gr-blocks/lib/streams_to_vector_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/vector_to_stream_impl.cc | 62 ++++++++++++++++++++++++++++++++++ gr-blocks/lib/vector_to_stream_impl.h | 44 ++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 gr-blocks/lib/vector_to_stream_impl.cc create mode 100644 gr-blocks/lib/vector_to_stream_impl.h (limited to 'gr-blocks/lib') 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 */ -- 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/lib/CMakeLists.txt | 1 + gr-blocks/lib/vector_to_streams_impl.cc | 68 +++++++++++++++++++++++++++++++++ gr-blocks/lib/vector_to_streams_impl.h | 44 +++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 gr-blocks/lib/vector_to_streams_impl.cc create mode 100644 gr-blocks/lib/vector_to_streams_impl.h (limited to 'gr-blocks/lib') diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index cdacd60c2..7db4d118c 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -165,6 +165,7 @@ list(APPEND gr_blocks_sources uchar_array_to_float.cc uchar_to_float_impl.cc vector_to_stream_impl.cc + vector_to_streams_impl.cc ) list(APPEND blocks_libs diff --git a/gr-blocks/lib/vector_to_streams_impl.cc b/gr-blocks/lib/vector_to_streams_impl.cc new file mode 100644 index 000000000..09d32c5c5 --- /dev/null +++ b/gr-blocks/lib/vector_to_streams_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 "vector_to_streams_impl.h" +#include + +namespace gr { + namespace blocks { + + vector_to_streams::sptr vector_to_streams::make(size_t itemsize, size_t nstreams) + { + return gnuradio::get_initial_sptr(new vector_to_streams_impl(itemsize, nstreams)); + } + + vector_to_streams_impl::vector_to_streams_impl(size_t itemsize, size_t nstreams) + : gr_sync_block ("vector_to_streams", + gr_make_io_signature (1, 1, nstreams * itemsize), + gr_make_io_signature (nstreams, nstreams, itemsize)) + + { + } + + int + vector_to_streams_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); + int nstreams = output_items.size(); + + const char *in = (const char *) input_items[0]; + char **outv = (char **) &output_items[0]; + + for (int i = 0; i < noutput_items; i++){ + for (int j = 0; j < nstreams; j++){ + memcpy(outv[j], in, itemsize); + outv[j] += itemsize; + in += itemsize; + } + } + + return noutput_items; + } + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/vector_to_streams_impl.h b/gr-blocks/lib/vector_to_streams_impl.h new file mode 100644 index 000000000..81bcfd076 --- /dev/null +++ b/gr-blocks/lib/vector_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_VECTOR_TO_STREAMS_IMPL_H +#define INCLUDED_VECTOR_TO_STREAMS_IMPL_H + +#include + +namespace gr { + namespace blocks { + + class BLOCKS_API vector_to_streams_impl : public vector_to_streams + { + public: + vector_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_VECTOR_TO_STREAMS_IMPL_H */ -- cgit From 2d2afd3b387bd3426cc30239f679d48cefe9eb93 Mon Sep 17 00:00:00 2001 From: Johnathan Corgan Date: Wed, 5 Sep 2012 12:42:10 -0700 Subject: blocks: added gr::blocks::file_source --- gr-blocks/lib/CMakeLists.txt | 1 + gr-blocks/lib/file_source_impl.cc | 136 ++++++++++++++++++++++++++++++++++++++ gr-blocks/lib/file_source_impl.h | 52 +++++++++++++++ 3 files changed, 189 insertions(+) create mode 100644 gr-blocks/lib/file_source_impl.cc create mode 100644 gr-blocks/lib/file_source_impl.h (limited to 'gr-blocks/lib') diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 7db4d118c..b06f46675 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -135,6 +135,7 @@ list(APPEND gr_blocks_sources complex_to_arg_impl.cc conjugate_cc_impl.cc deinterleave_impl.cc + file_source_impl.cc float_to_char_impl.cc float_to_complex_impl.cc float_array_to_int.cc diff --git a/gr-blocks/lib/file_source_impl.cc b/gr-blocks/lib/file_source_impl.cc new file mode 100644 index 000000000..0d20827b7 --- /dev/null +++ b/gr-blocks/lib/file_source_impl.cc @@ -0,0 +1,136 @@ +/* -*- 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 "file_source_impl.h" +#include +#include +#include +#include +#include +#include +#include + +// win32 (mingw/msvc) specific +#ifdef HAVE_IO_H +#include +#endif +#ifdef O_BINARY +#define OUR_O_BINARY O_BINARY +#else +#define OUR_O_BINARY 0 +#endif +// should be handled via configure +#ifdef O_LARGEFILE +#define OUR_O_LARGEFILE O_LARGEFILE +#else +#define OUR_O_LARGEFILE 0 +#endif + +namespace gr { + namespace blocks { + + file_source::sptr file_source::make(size_t itemsize, const char *filename, bool repeat) + { + return gnuradio::get_initial_sptr(new file_source_impl(itemsize, filename, repeat)); + } + + file_source_impl::file_source_impl(size_t itemsize, const char *filename, bool repeat) + : gr_sync_block("file_source", + gr_make_io_signature(0, 0, 0), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize), d_fp (0), d_repeat(repeat) + { + // we use "open" to use to the O_LARGEFILE flag + + int fd; + + if ((fd = open (filename, O_RDONLY | OUR_O_LARGEFILE | OUR_O_BINARY)) < 0){ + perror (filename); + throw std::runtime_error ("can't open file"); + } + + if ((d_fp = fdopen (fd, "rb")) == NULL) { + perror(filename); + throw std::runtime_error("can't open file"); + } + } + + file_source_impl::~file_source_impl() + { + fclose ((FILE *) d_fp); + } + + bool + file_source_impl::seek(long seek_point, int whence) + { + return fseek ((FILE *) d_fp, seek_point *d_itemsize, whence) == 0; + } + + int + file_source_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + char *o = (char *) output_items[0]; + int i; + int size = noutput_items; + + while (size) { + i = fread(o, d_itemsize, size, (FILE *) d_fp); + + size -= i; + o += i * d_itemsize; + + if (size == 0) // done + break; + + if (i > 0) // short read, try again + continue; + + // We got a zero from fread. This is either EOF or error. In + // any event, if we're in repeat mode, seek back to the beginning + // of the file and try again, else break + + if (!d_repeat) + break; + + if (fseek ((FILE *) d_fp, 0, SEEK_SET) == -1) { + fprintf(stderr, "[%s] fseek failed\n", __FILE__); + exit(-1); + } + } + + if (size > 0) { // EOF or error + if (size == noutput_items) // we didn't read anything; say we're done + return -1; + return noutput_items - size; // else return partial result + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/file_source_impl.h b/gr-blocks/lib/file_source_impl.h new file mode 100644 index 000000000..c35d563d1 --- /dev/null +++ b/gr-blocks/lib/file_source_impl.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_FILE_SOURCE_IMPL_H +#define INCLUDED_BLOCKS_FILE_SOURCE_IMPL_H + +#include + +namespace gr { + namespace blocks { + + class BLOCKS_API file_source_impl : public file_source + { + private: + size_t d_itemsize; + void *d_fp; + bool d_repeat; + + public: + file_source_impl(size_t itemsize, const char *filename, bool repeat); + ~file_source_impl(); + + bool seek(long seek_point, int whence); + + 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_FILE_SOURCE_IMPL_H */ -- cgit