diff options
Diffstat (limited to 'gnuradio-core')
59 files changed, 1699 insertions, 166 deletions
diff --git a/gnuradio-core/CMakeLists.txt b/gnuradio-core/CMakeLists.txt index 767f828689..5f26216d35 100644 --- a/gnuradio-core/CMakeLists.txt +++ b/gnuradio-core/CMakeLists.txt @@ -110,7 +110,7 @@ CPACK_COMPONENT("core_swig" install( FILES gnuradio-core.conf - DESTINATION ${GR_PKG_CONF_DIR} + DESTINATION ${GR_PREFSDIR} COMPONENT "core_runtime" ) diff --git a/gnuradio-core/src/lib/filter/CMakeLists.txt b/gnuradio-core/src/lib/filter/CMakeLists.txt index 02a72191cf..facaff764d 100644 --- a/gnuradio-core/src/lib/filter/CMakeLists.txt +++ b/gnuradio-core/src/lib/filter/CMakeLists.txt @@ -195,6 +195,9 @@ elseif(CMAKE_SYSTEM_PROCESSOR_x86 AND "${CMAKE_SYSTEM_PROCESSOR_x86}" STREQUAL " ${CMAKE_CURRENT_SOURCE_DIR}/short_dotprod_mmx.S ) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") + if(CMAKE_COMPILER_IS_GNUCXX) + add_definitions(-maltivec) + endif() list(APPEND gnuradio_core_sources ${CMAKE_CURRENT_SOURCE_DIR}/sysconfig_powerpc.cc ${CMAKE_CURRENT_SOURCE_DIR}/gr_fir_sysconfig_powerpc.cc diff --git a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc index cb7c939626..a8cb849e27 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_channelizer_ccf.cc @@ -96,6 +96,7 @@ gr_pfb_channelizer_ccf::gr_pfb_channelizer_ccf (unsigned int numchans, gr_pfb_channelizer_ccf::~gr_pfb_channelizer_ccf () { + delete d_fft; delete [] d_idxlut; for(unsigned int i = 0; i < d_numchans; i++) { diff --git a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc index c973daf829..e563daa513 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_decimator_ccf.cc @@ -69,6 +69,7 @@ gr_pfb_decimator_ccf::gr_pfb_decimator_ccf (unsigned int decim, gr_pfb_decimator_ccf::~gr_pfb_decimator_ccf () { + delete d_fft; for(unsigned int i = 0; i < d_rate; i++) { delete d_filters[i]; } diff --git a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc index 9910a18510..cd01aaff5c 100644 --- a/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc +++ b/gnuradio-core/src/lib/filter/gr_pfb_synthesizer_ccf.cc @@ -74,6 +74,7 @@ gr_pfb_synthesizer_ccf::gr_pfb_synthesizer_ccf gr_pfb_synthesizer_ccf::~gr_pfb_synthesizer_ccf () { + delete d_fft; for(unsigned int i = 0; i < d_twox*d_numchans; i++) { delete d_filters[i]; } diff --git a/gnuradio-core/src/lib/general/CMakeLists.txt b/gnuradio-core/src/lib/general/CMakeLists.txt index 038ac25078..f521bdf680 100644 --- a/gnuradio-core/src/lib/general/CMakeLists.txt +++ b/gnuradio-core/src/lib/general/CMakeLists.txt @@ -48,9 +48,6 @@ message(STATUS "Loading build date ${BUILD_DATE} into gr_constants...") message(STATUS "Loading version ${VERSION} into gr_constants...") -file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${GR_CONF_DIR}" SYSCONFDIR) -file(TO_NATIVE_PATH "${CMAKE_INSTALL_PREFIX}/${GR_PKG_CONF_DIR}" GR_PREFSDIR) - #double escape for windows backslash path separators string(REPLACE "\\" "\\\\" prefix ${prefix}) string(REPLACE "\\" "\\\\" SYSCONFDIR ${SYSCONFDIR}) @@ -229,6 +226,7 @@ set(gr_core_general_triple_threats gr_interleaved_short_to_complex gr_iqcomp_cc gr_keep_one_in_n + gr_keep_m_in_n gr_kludge_copy gr_lfsr_32k_source_s gr_map_bb @@ -282,16 +280,20 @@ set(gr_core_general_triple_threats gr_transcendental gr_uchar_to_float gr_vco_f + gr_vector_map gr_vector_to_stream gr_vector_to_streams gr_unpack_k_bits_bb + gr_pack_k_bits_bb gr_descrambler_bb gr_scrambler_bb gr_probe_density_b gr_annotator_alltoall gr_annotator_1to1 + gr_annotator_raw gr_burst_tagger gr_correlate_access_code_tag_bb + gr_tag_debug ) foreach(file_tt ${gr_core_general_triple_threats}) diff --git a/gnuradio-core/src/lib/general/general.i b/gnuradio-core/src/lib/general/general.i index 7e4e47d326..31acaefb8d 100644 --- a/gnuradio-core/src/lib/general/general.i +++ b/gnuradio-core/src/lib/general/general.i @@ -37,6 +37,7 @@ #include <gr_stream_to_vector.h> #include <gr_vector_to_stream.h> #include <gr_keep_one_in_n.h> +#include <gr_keep_m_in_n.h> #include <gr_fft_vcc.h> #include <gr_fft_vfc.h> #include <gr_float_to_int.h> @@ -100,6 +101,7 @@ #include <gr_test_types.h> #include <gr_test.h> #include <gr_unpack_k_bits_bb.h> +#include <gr_pack_k_bits_bb.h> #include <gr_diff_phasor_cc.h> #include <gr_diff_encoder_bb.h> #include <gr_diff_decoder_bb.h> @@ -133,10 +135,13 @@ #include <complex_vec_test.h> #include <gr_annotator_alltoall.h> #include <gr_annotator_1to1.h> +#include <gr_annotator_raw.h> #include <gr_burst_tagger.h> #include <gr_cpm.h> #include <gr_correlate_access_code_tag_bb.h> #include <gr_add_ff.h> +#include <gr_vector_map.h> +#include <gr_tag_debug.h> %} %include "gri_control_loop.i" @@ -154,6 +159,7 @@ %include "gr_stream_to_vector.i" %include "gr_vector_to_stream.i" %include "gr_keep_one_in_n.i" +%include "gr_keep_m_in_n.i" %include "gr_fft_vcc.i" %include "gr_fft_vfc.i" %include "gr_float_to_int.i" @@ -217,6 +223,7 @@ %include "gr_test_types.h" %include "gr_test.i" %include "gr_unpack_k_bits_bb.i" +%include "gr_pack_k_bits_bb.i" %include "gr_diff_phasor_cc.i" %include "gr_diff_encoder_bb.i" %include "gr_diff_decoder_bb.i" @@ -250,8 +257,11 @@ %include "complex_vec_test.i" %include "gr_annotator_alltoall.i" %include "gr_annotator_1to1.i" +%include "gr_annotator_raw.i" %include "gr_burst_tagger.i" %include "gr_cpm.i" %include "gr_correlate_access_code_tag_bb.i" %include "gr_add_ff.i" +%include "gr_vector_map.i" +%include "gr_tag_debug.i" %include "gr_block_gateway.i" diff --git a/gnuradio-core/src/lib/general/gr_add_ff.cc b/gnuradio-core/src/lib/general/gr_add_ff.cc index 2e45673d3b..5f6676bb7b 100644 --- a/gnuradio-core/src/lib/general/gr_add_ff.cc +++ b/gnuradio-core/src/lib/general/gr_add_ff.cc @@ -42,7 +42,7 @@ gr_add_ff::gr_add_ff (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.cc b/gnuradio-core/src/lib/general/gr_annotator_raw.cc new file mode 100644 index 0000000000..e1ae73efb6 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.cc @@ -0,0 +1,106 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_annotator_raw.h> +#include <gr_io_signature.h> +#include <string.h> +#include <iostream> +#include <iomanip> +#include <stdexcept> + +using namespace pmt; + +gr_annotator_raw_sptr +gr_make_annotator_raw(size_t sizeof_stream_item) +{ + return gnuradio::get_initial_sptr(new gr_annotator_raw + (sizeof_stream_item)); +} + +gr_annotator_raw::gr_annotator_raw(size_t sizeof_stream_item) + : gr_sync_block("annotator_raw", + gr_make_io_signature(1, 1, sizeof_stream_item), + gr_make_io_signature(1, 1, sizeof_stream_item)), + d_itemsize(sizeof_stream_item) +{ + set_tag_propagation_policy(TPP_ONE_TO_ONE); + set_relative_rate(1.0); +} + +void gr_annotator_raw::add_tag(uint64_t offset, pmt_t key, pmt_t val) +{ + gruel::scoped_lock l(d_mutex); + + gr_tag_t tag; + tag.srcid = pmt::pmt_intern(d_name); + tag.key = key; + tag.value = val; + tag.offset = offset; + + // add our new tag + d_queued_tags.push_back(tag); + // make sure our tags are in offset order + std::sort(d_queued_tags.begin(), d_queued_tags.end(), + gr_tag_t::offset_compare); + // make sure we are not adding an item in the past! + if(tag.offset > nitems_read(0)) { + throw std::runtime_error("gr_annotator_raw::add_tag: item added too far in the past\n."); + } +} + +gr_annotator_raw::~gr_annotator_raw() +{ +} + +int +gr_annotator_raw::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + gruel::scoped_lock l(d_mutex); + + const char *in = (const char*)input_items[0]; + char *out = (char*)output_items[0]; + + uint64_t start_N = nitems_read(0); + uint64_t end_N = start_N + (uint64_t)(noutput_items); + + // locate queued tags that fall in this range and insert them when appropriate + std::vector<gr_tag_t>::iterator i = d_queued_tags.begin(); + while( i != d_queued_tags.end() ) { + if( (*i).offset >= start_N && (*i).offset < end_N) { + add_item_tag(0, (*i).offset,(*i).key, (*i).value, (*i).srcid); + i = d_queued_tags.erase(i); + } + else { + break; + } + } + + // copy data across + memcpy(out, in, noutput_items*d_itemsize); + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.h b/gnuradio-core/src/lib/general/gr_annotator_raw.h new file mode 100644 index 0000000000..8a6c3f6c02 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.h @@ -0,0 +1,69 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_ANNOTATOR_RAW_H +#define INCLUDED_GR_ANNOTATOR_RAW_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> +#include <gruel/pmt.h> +#include <gruel/thread.h> + +class gr_annotator_raw; +typedef boost::shared_ptr<gr_annotator_raw> gr_annotator_raw_sptr; + +// public constructor +GR_CORE_API gr_annotator_raw_sptr +gr_make_annotator_raw(size_t sizeof_stream_item); + +/*! + * \brief raw stream annotator testing block. + * + * This block creates arbitrary tags to be sent downstream + * blocks to be sent are set manually via accessor methods and are sent only once. + * + * This block is intended for testing of tag related blocks + */ +class GR_CORE_API gr_annotator_raw : public gr_sync_block +{ + public: + ~gr_annotator_raw(); + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + // insert a tag to be added + void add_tag(uint64_t offset, pmt::pmt_t key, pmt::pmt_t val); + +protected: + gr_annotator_raw(size_t sizeof_stream_item); + + private: + size_t d_itemsize; + std::vector<gr_tag_t> d_queued_tags; + gruel::mutex d_mutex; + + friend GR_CORE_API gr_annotator_raw_sptr + gr_make_annotator_raw(size_t sizeof_stream_item); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_annotator_raw.i b/gnuradio-core/src/lib/general/gr_annotator_raw.i new file mode 100644 index 0000000000..85777ef5d4 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_annotator_raw.i @@ -0,0 +1,26 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010-2011 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +GR_SWIG_BLOCK_MAGIC(gr,annotator_raw); + +%include <pmt_swig.i> +%include <gr_annotator_raw.h> diff --git a/gnuradio-core/src/lib/general/gr_char_to_float.cc b/gnuradio-core/src/lib/general/gr_char_to_float.cc index aec7ad8522..f63aa5b169 100644 --- a/gnuradio-core/src/lib/general/gr_char_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_char_to_float.cc @@ -42,7 +42,7 @@ gr_char_to_float::gr_char_to_float (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_char_to_short.cc b/gnuradio-core/src/lib/general/gr_char_to_short.cc index c20d6cd888..bb9bd8909e 100644 --- a/gnuradio-core/src/lib/general/gr_char_to_short.cc +++ b/gnuradio-core/src/lib/general/gr_char_to_short.cc @@ -42,7 +42,7 @@ gr_char_to_short::gr_char_to_short (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(char); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc index 3b1fbf9acd..cdf6d7f3a6 100644 --- a/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc +++ b/gnuradio-core/src/lib/general/gr_complex_to_xxx.cc @@ -45,7 +45,7 @@ gr_complex_to_float::gr_complex_to_float (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -106,7 +106,7 @@ gr_complex_to_real::gr_complex_to_real (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -146,7 +146,7 @@ gr_complex_to_imag::gr_complex_to_imag (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -186,7 +186,7 @@ gr_complex_to_mag::gr_complex_to_mag (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -220,7 +220,7 @@ gr_complex_to_mag_squared::gr_complex_to_mag_squared (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int @@ -258,7 +258,7 @@ gr_complex_to_arg::gr_complex_to_arg (unsigned int vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_conjugate_cc.cc b/gnuradio-core/src/lib/general/gr_conjugate_cc.cc index aaa7f490c7..94ac3e162b 100644 --- a/gnuradio-core/src/lib/general/gr_conjugate_cc.cc +++ b/gnuradio-core/src/lib/general/gr_conjugate_cc.cc @@ -43,7 +43,7 @@ gr_conjugate_cc::gr_conjugate_cc () { const int alignment_multiple = volk_get_alignment() / sizeof(gr_complex); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_float_to_char.cc b/gnuradio-core/src/lib/general/gr_float_to_char.cc index 3602ad7453..d67ded3ea6 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_char.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_char.cc @@ -42,7 +42,7 @@ gr_float_to_char::gr_float_to_char (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(char); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_float_to_int.cc b/gnuradio-core/src/lib/general/gr_float_to_int.cc index bd3cd6a3b3..43b8518956 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_int.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_int.cc @@ -43,7 +43,7 @@ gr_float_to_int::gr_float_to_int (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(int); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_float_to_short.cc b/gnuradio-core/src/lib/general/gr_float_to_short.cc index 07995c99aa..ab720168bf 100644 --- a/gnuradio-core/src/lib/general/gr_float_to_short.cc +++ b/gnuradio-core/src/lib/general/gr_float_to_short.cc @@ -42,7 +42,7 @@ gr_float_to_short::gr_float_to_short (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(short); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_head.h b/gnuradio-core/src/lib/general/gr_head.h index 17dd737f0b..48415892dd 100644 --- a/gnuradio-core/src/lib/general/gr_head.h +++ b/gnuradio-core/src/lib/general/gr_head.h @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -51,6 +51,7 @@ class GR_CORE_API gr_head : public gr_sync_block gr_vector_void_star &output_items); void reset() { d_ncopied_items = 0; } + void set_length(int nitems) { d_nitems = nitems; } }; GR_CORE_API gr_head_sptr diff --git a/gnuradio-core/src/lib/general/gr_head.i b/gnuradio-core/src/lib/general/gr_head.i index 73feaf181c..11f3331d47 100644 --- a/gnuradio-core/src/lib/general/gr_head.i +++ b/gnuradio-core/src/lib/general/gr_head.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2009 Free Software Foundation, Inc. + * Copyright 2004,2009,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -28,5 +28,6 @@ class gr_head : public gr_block { gr_head(); public: void reset(); + void set_length(int nitems); }; diff --git a/gnuradio-core/src/lib/general/gr_int_to_float.cc b/gnuradio-core/src/lib/general/gr_int_to_float.cc index a284853055..a7fb24dc69 100644 --- a/gnuradio-core/src/lib/general/gr_int_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_int_to_float.cc @@ -42,7 +42,7 @@ gr_int_to_float::gr_int_to_float (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc new file mode 100644 index 0000000000..1becbfa116 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.cc @@ -0,0 +1,98 @@ +/* -*- 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 <gr_keep_m_in_n.h> +#include <gr_io_signature.h> +#include <string.h> +#include <stdio.h> + +gr_keep_m_in_n_sptr +gr_make_keep_m_in_n(size_t item_size, int m, int n, int offset) +{ + return gnuradio::get_initial_sptr(new gr_keep_m_in_n(item_size, m, n, offset)); +} + + +/* +* +* offset = 0, starts with 0th item +* offset = 1, starts with 1st item, etc... +* +* we take m items out of each n +*/ +gr_keep_m_in_n::gr_keep_m_in_n(size_t item_size, int m, int n, int offset) + : gr_block("keep_m_in_n", + gr_make_io_signature(1, 1, item_size), + gr_make_io_signature(1, 1, item_size)), + d_n(n), + d_m(m), + d_offset(offset), + d_itemsize(item_size) +{ + // 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 +gr_keep_m_in_n::forecast(int noutput_items, gr_vector_int &ninput_items_required) +{ + ninput_items_required[0] = d_n*(noutput_items/d_m); +} + +void +gr_keep_m_in_n::set_offset(int offset) +{ + d_offset = offset; +} + +int +gr_keep_m_in_n::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<blks; i++) { + // set up copy pointers + const uint8_t* iptr = &in[(i*d_n + d_offset)*d_itemsize]; + uint8_t* optr = &out[i*d_m*d_itemsize]; + // perform copy + memcpy( optr, iptr, d_m*d_itemsize ); + } + + consume_each(d_n); + return d_m; +} diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.h b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h new file mode 100644 index 0000000000..c6bf40ecf2 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.h @@ -0,0 +1,67 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_KEEP_M_IN_N_H +#define INCLUDED_GR_KEEP_M_IN_N_H + +#include <gr_core_api.h> +#include <gr_block.h> + +class gr_keep_m_in_n; +typedef boost::shared_ptr<gr_keep_m_in_n> gr_keep_m_in_n_sptr; + +GR_CORE_API gr_keep_m_in_n_sptr +gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); + + +/*! + * \brief decimate a stream, keeping one item out of every n. + * \ingroup slicedice_blk + */ +class GR_CORE_API gr_keep_m_in_n : public gr_block +{ + friend GR_CORE_API gr_keep_m_in_n_sptr + gr_make_keep_m_in_n (size_t item_size, int m, int n, int offset); + + int d_n; + int d_m; + int d_count; + int d_offset; + int d_itemsize; + + protected: + gr_keep_m_in_n (size_t item_size, int m, int n, int offset); + void forecast (int noutput_items, gr_vector_int &ninput_items_required); + + public: + 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_offset(int offset); + void set_n(int n){ d_n = n; } + void set_m(int m){ d_m = m; } + +}; + +#endif /* INCLUDED_GR_KEEP_M_IN_N_H */ diff --git a/gnuradio-core/src/lib/general/gr_keep_m_in_n.i b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i new file mode 100644 index 0000000000..f280c0248a --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_keep_m_in_n.i @@ -0,0 +1,35 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,keep_m_in_n) + +gr_keep_m_in_n_sptr +gr_make_keep_m_in_n (size_t itemsize, int m, int n, int offset); + +class gr_keep_m_in_n : public gr_sync_block +{ + protected: + gr_keep_m_in_n (size_t itemsize, int m, int n, int offset); + public: + void set_offset(int offset); + +}; diff --git a/gnuradio-core/src/lib/general/gr_multiply_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_cc.cc index 32c44a19e4..4a3751419f 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_cc.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_cc.cc @@ -40,9 +40,9 @@ gr_multiply_cc::gr_multiply_cc (size_t 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(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc index 53ede2eeda..0c5fb4a926 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_conjugate_cc.cc @@ -40,9 +40,9 @@ gr_multiply_conjugate_cc::gr_multiply_conjugate_cc (size_t 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(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc index 359ab6ba05..bd4511937f 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_const_cc.cc @@ -40,9 +40,9 @@ gr_multiply_const_cc::gr_multiply_const_cc (gr_complex k, size_t 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(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(gr_complex); + set_alignment(std::max(1,alignment_multiple)); } gr_complex diff --git a/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc b/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc index 263f066106..16ba39df93 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_const_ff.cc @@ -40,9 +40,9 @@ gr_multiply_const_ff::gr_multiply_const_ff (float k, size_t 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(alignment_multiple); + const int alignment_multiple = + volk_get_alignment() / sizeof(float); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_multiply_ff.cc b/gnuradio-core/src/lib/general/gr_multiply_ff.cc index f764a71e8f..bb7bd07550 100644 --- a/gnuradio-core/src/lib/general/gr_multiply_ff.cc +++ b/gnuradio-core/src/lib/general/gr_multiply_ff.cc @@ -42,7 +42,7 @@ gr_multiply_ff::gr_multiply_ff (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.cc new file mode 100644 index 0000000000..0ea0c9e388 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gr_pack_k_bits_bb.h> +#include <gr_io_signature.h> +#include <stdexcept> +#include <iostream> + +gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb(unsigned k) +{ + return gnuradio::get_initial_sptr(new gr_pack_k_bits_bb(k)); +} + + +gr_pack_k_bits_bb::gr_pack_k_bits_bb (unsigned k) + : gr_sync_decimator("pack_k_bits_bb", + gr_make_io_signature (1, 1, sizeof(unsigned char)), + gr_make_io_signature (1, 1, sizeof(unsigned char)), + k), + d_k (k) +{ + if (d_k == 0) + throw std::out_of_range("interpolation must be > 0"); +} + +gr_pack_k_bits_bb::~gr_pack_k_bits_bb() +{ +} + +int +gr_pack_k_bits_bb::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]; + unsigned char *out = (unsigned char *)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + out[i] = 0x00; + for(unsigned int j = 0; j < d_k; j++) { + out[i] |= (0x01 & in[i*d_k+j])<<(d_k-j-1); + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h new file mode 100644 index 0000000000..8e1508c78b --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_PACK_K_BITS_BB_H +#define INCLUDED_GR_PACK_K_BITS_BB_H + +#include <gr_core_api.h> +#include <gr_sync_decimator.h> + +class gr_pack_k_bits_bb; +typedef boost::shared_ptr<gr_pack_k_bits_bb> gr_pack_k_bits_bb_sptr; +GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); + +class gr_pack_k_bits_bb; + +/*! + * \brief Converts a stream of bytes with 1 bit in the LSB to a byte with k relevent bits. + * \ingroup converter_blk + */ +class GR_CORE_API gr_pack_k_bits_bb : public gr_sync_decimator +{ + private: + friend GR_CORE_API gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (unsigned k); + + gr_pack_k_bits_bb (unsigned k); + + unsigned d_k; // number of relevent bits to pack from k input bytes + + public: + ~gr_pack_k_bits_bb (); + + int work (int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif diff --git a/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i new file mode 100644 index 0000000000..6ae2095ec7 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_pack_k_bits_bb.i @@ -0,0 +1,34 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,pack_k_bits_bb) + +gr_pack_k_bits_bb_sptr gr_make_pack_k_bits_bb (int k) throw(std::exception); + +class gr_pack_k_bits_bb : public gr_sync_decimator +{ + private: + gr_pack_k_bits_bb (int k); + + public: + ~gr_pack_k_bits_bb (); +}; diff --git a/gnuradio-core/src/lib/general/gr_short_to_char.cc b/gnuradio-core/src/lib/general/gr_short_to_char.cc index 9d6c41406e..8c146a351d 100644 --- a/gnuradio-core/src/lib/general/gr_short_to_char.cc +++ b/gnuradio-core/src/lib/general/gr_short_to_char.cc @@ -42,7 +42,7 @@ gr_short_to_char::gr_short_to_char (size_t vlen) { const int alignment_multiple = volk_get_alignment() / sizeof(char); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } int diff --git a/gnuradio-core/src/lib/general/gr_short_to_float.cc b/gnuradio-core/src/lib/general/gr_short_to_float.cc index 960cf644d1..093d6024fa 100644 --- a/gnuradio-core/src/lib/general/gr_short_to_float.cc +++ b/gnuradio-core/src/lib/general/gr_short_to_float.cc @@ -42,7 +42,7 @@ gr_short_to_float::gr_short_to_float (size_t vlen, float scale) { const int alignment_multiple = volk_get_alignment() / sizeof(float); - set_alignment(alignment_multiple); + set_alignment(std::max(1,alignment_multiple)); } float diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.cc b/gnuradio-core/src/lib/general/gr_tag_debug.cc new file mode 100644 index 0000000000..c4031f438d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_tag_debug.cc @@ -0,0 +1,100 @@ +/* -*- 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 <gr_tag_debug.h> +#include <gr_io_signature.h> +#include <iostream> +#include <iomanip> + +gr_tag_debug_sptr +gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name) +{ + return gnuradio::get_initial_sptr + (new gr_tag_debug(sizeof_stream_item, name)); +} + +gr_tag_debug::gr_tag_debug(size_t sizeof_stream_item, const std::string &name) + : gr_sync_block("tag_debug", + gr_make_io_signature(1, -1, sizeof_stream_item), + gr_make_io_signature(0, 0, 0)), + d_name(name), d_display(true) +{ +} + +std::vector<gr_tag_t> +gr_tag_debug::current_tags() +{ + gruel::scoped_lock l(d_mutex); + return d_tags; +} + +void +gr_tag_debug::set_display(bool d) +{ + gruel::scoped_lock l(d_mutex); + d_display = d; +} + +int +gr_tag_debug::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + gruel::scoped_lock l(d_mutex); + + if(d_display) { + std::cout << std::endl + << "----------------------------------------------------------------------"; + std::cout << std::endl << "Tag Debug: " << d_name << std::endl; + } + + uint64_t abs_N, end_N; + for(size_t i = 0; i < input_items.size(); i++) { + abs_N = nitems_read(i); + end_N = abs_N + (uint64_t)(noutput_items); + + d_tags.clear(); + get_tags_in_range(d_tags, i, abs_N, end_N); + + if(d_display) { + std::cout << "Input Stream: " << i << std::endl; + for(d_tags_itr = d_tags.begin(); d_tags_itr != d_tags.end(); d_tags_itr++) { + std::cout << std::setw(10) << "Offset: " << d_tags_itr->offset + << std::setw(10) << "Source: " << pmt::pmt_symbol_to_string(d_tags_itr->srcid) + << std::setw(10) << "Key: " << pmt::pmt_symbol_to_string(d_tags_itr->key) + << std::setw(10) << "Value: "; + pmt::pmt_print(d_tags_itr->value); + } + } + } + + if(d_display) { + std::cout << "----------------------------------------------------------------------"; + std::cout << std::endl; + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.h b/gnuradio-core/src/lib/general/gr_tag_debug.h new file mode 100644 index 0000000000..57578884a8 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_tag_debug.h @@ -0,0 +1,85 @@ +/* -*- c++ -*- */ +/* + * Copyright 2012 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_GR_TAG_DEBUG_H +#define INCLUDED_GR_TAG_DEBUG_H + +#include <gr_core_api.h> +#include <gr_sync_block.h> +#include <gruel/thread.h> +#include <stddef.h> + +class gr_tag_debug; +typedef boost::shared_ptr<gr_tag_debug> gr_tag_debug_sptr; + +GR_CORE_API gr_tag_debug_sptr +gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name); + +/*! + * \brief Bit bucket that prints out any tag received. + * \ingroup sink_blk + * + * This block collects all tags sent to it on all input ports and + * displays them to stdout in a formatted way. The \p name parameter + * is used to identify which debug sink generated the tag, so when + * connecting a block to this debug sink, an appropriate name is + * something that identifies the input block. + * + * This block otherwise acts as a NULL sink in that items from the + * input stream are ignored. It is designed to be able to attach to + * any block and watch all tags streaming out of that block for + * debugging purposes. + * + * The tags from the last call to this work function are stored and + * can be retrieved using the function 'current_tags'. + */ +class GR_CORE_API gr_tag_debug : public gr_sync_block +{ + private: + friend GR_CORE_API gr_tag_debug_sptr + gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name); + gr_tag_debug(size_t sizeof_stream_item, const std::string &name); + + std::string d_name; + std::vector<gr_tag_t> d_tags; + std::vector<gr_tag_t>::iterator d_tags_itr; + bool d_display; + gruel::mutex d_mutex; + + public: + /*! + * \brief Returns a vector of gr_tag_t items as of the last call to + * work. + */ + std::vector<gr_tag_t> current_tags(); + + /*! + * \brief Set the display of tags to stdout on/off. + */ + void set_display(bool d); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); +}; + +#endif /* INCLUDED_GR_TAG_DEBUG_H */ diff --git a/gnuradio-core/src/lib/general/gr_tag_debug.i b/gnuradio-core/src/lib/general/gr_tag_debug.i new file mode 100644 index 0000000000..3af1bdcfef --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_tag_debug.i @@ -0,0 +1,35 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr,tag_debug) + +%include <gr_tags.i> + +gr_tag_debug_sptr +gr_make_tag_debug(size_t sizeof_stream_item, const std::string &name); + +class gr_tag_debug : public gr_sync_block +{ +public: + std::vector<gr_tag_t> current_tags(); + void set_display(bool d); +}; diff --git a/gnuradio-core/src/lib/general/gr_vector_map.cc b/gnuradio-core/src/lib/general/gr_vector_map.cc new file mode 100644 index 0000000000..2a13efb06d --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_vector_map.cc @@ -0,0 +1,117 @@ +/* -*- 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 <gr_vector_map.h> +#include <gr_io_signature.h> +#include <string.h> + +std::vector<int> +get_in_sizeofs(size_t item_size, std::vector<size_t> in_vlens) +{ + std::vector<int> in_sizeofs; + for(unsigned int i = 0; i < in_vlens.size(); i++) { + in_sizeofs.push_back(in_vlens[i]*item_size); + } + return in_sizeofs; +} + +std::vector<int> +get_out_sizeofs(size_t item_size, + std::vector< std::vector< std::vector<size_t> > > mapping) +{ + std::vector<int> out_sizeofs; + for(unsigned int i = 0; i < mapping.size(); i++) { + out_sizeofs.push_back(mapping[i].size()*item_size); + } + return out_sizeofs; +} + +gr_vector_map_sptr +gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) +{ + return gnuradio::get_initial_sptr(new gr_vector_map(item_size, + in_vlens, + mapping)); +} + +gr_vector_map::gr_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping) + : gr_sync_block("vector_map", + gr_make_io_signaturev(in_vlens.size(), in_vlens.size(), + get_in_sizeofs(item_size, in_vlens)), + gr_make_io_signaturev(mapping.size(), mapping.size(), + get_out_sizeofs(item_size, mapping))), + d_item_size(item_size), d_in_vlens(in_vlens) +{ + set_mapping(mapping); +} + +void +gr_vector_map::set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping) { + // Make sure the contents of the mapping vectors are possible. + for(unsigned int i=0; i<mapping.size(); i++) { + for(unsigned int j=0; j<mapping[i].size(); j++) { + if(mapping[i][j].size() != 2) { + throw std::runtime_error("Mapping must be of the form (out_mapping_stream1, out_mapping_stream2, ...), where out_mapping_stream1 is of the form (mapping_element1, mapping_element2, ...), where mapping_element1 is of the form (input_stream, input_element). This error is raised because a mapping_element vector does not contain exactly 2 items."); + } + unsigned int s = mapping[i][j][0]; + unsigned int index = mapping[i][j][1]; + if(s >= d_in_vlens.size()) { + throw std::runtime_error("Stream numbers in mapping must be less than the number of input streams."); + } + if((index < 0) || (index >= d_in_vlens[s])) { + throw std::runtime_error ("Indices in mapping must be greater than 0 and less than the input vector lengths."); + } + } + } + gruel::scoped_lock guard(d_mutex); + d_mapping = mapping; +} + +int +gr_vector_map::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + const char **inv = (const char **) &input_items[0]; + char **outv = (char **) &output_items[0]; + + for(unsigned int n = 0; n < (unsigned int)(noutput_items); n++) { + for(unsigned int i = 0; i < d_mapping.size(); i++) { + unsigned int out_vlen = d_mapping[i].size(); + for(unsigned int j = 0; j < out_vlen; j++) { + unsigned int s = d_mapping[i][j][0]; + unsigned int k = d_mapping[i][j][1]; + memcpy(outv[i] + out_vlen*d_item_size*n + + d_item_size*j, inv[s] + d_in_vlens[s]*d_item_size*n + + k*d_item_size, d_item_size); + } + } + } + + return noutput_items; +} diff --git a/gnuradio-core/src/lib/general/gr_vector_map.h b/gnuradio-core/src/lib/general/gr_vector_map.h new file mode 100644 index 0000000000..f5492b1e3a --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_vector_map.h @@ -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. + */ + +#ifndef INCLUDED_GR_VECTOR_MAP_H +#define INCLUDED_GR_VECTOR_MAP_H + +#include <vector> +#include <gr_core_api.h> +#include <gr_sync_interpolator.h> +#include <gruel/thread.h> + +class gr_vector_map; +typedef boost::shared_ptr<gr_vector_map> gr_vector_map_sptr; + +GR_CORE_API gr_vector_map_sptr +gr_make_vector_map (size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + +/*! + * \brief Maps elements from a set of input vectors to a set of output vectors. + * + * If in[i] is the input vector in the i'th stream then the output + * vector in the j'th stream is: + * + * out[j][k] = in[mapping[j][k][0]][mapping[j][k][1]] + * + * That is mapping is of the form (out_stream1_mapping, + * out_stream2_mapping, ...) and out_stream1_mapping is of the form + * (element1_mapping, element2_mapping, ...) and element1_mapping is + * of the form (in_stream, in_element). + * + * \param item_size (integer) size of vector elements + * + * \param in_vlens (vector of integers) number of elements in each + * input vector + * + * \param mapping (vector of vectors of vectors of integers) how to + * map elements from input to output vectors + * + * \ingroup slicedice_blk + */ +class GR_CORE_API gr_vector_map : public gr_sync_block +{ + friend GR_CORE_API gr_vector_map_sptr + gr_make_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + size_t d_item_size; + std::vector<size_t> d_in_vlens; + std::vector< std::vector< std::vector<size_t> > > d_mapping; + gruel::mutex d_mutex; // mutex to protect set/work access + + protected: + gr_vector_map(size_t item_size, std::vector<size_t> in_vlens, + std::vector< std::vector< std::vector<size_t> > > mapping); + + public: + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + void set_mapping(std::vector< std::vector< std::vector<size_t> > > mapping); +}; + +#endif /* INCLUDED_GR_VECTOR_MAP_H */ diff --git a/gnuradio-core/src/lib/general/gr_vector_map.i b/gnuradio-core/src/lib/general/gr_vector_map.i new file mode 100644 index 0000000000..e9fa3f27e5 --- /dev/null +++ b/gnuradio-core/src/lib/general/gr_vector_map.i @@ -0,0 +1,28 @@ +/* -*- 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. + */ + +GR_SWIG_BLOCK_MAGIC(gr, vector_map); + +%template() std::vector<size_t>; +%template() std::vector< std::vector< std::vector<size_t> > >; + +%include "gr_vector_map.h" diff --git a/gnuradio-core/src/lib/gengen/CMakeLists.txt b/gnuradio-core/src/lib/gengen/CMakeLists.txt index d137769907..b44a470750 100644 --- a/gnuradio-core/src/lib/gengen/CMakeLists.txt +++ b/gnuradio-core/src/lib/gengen/CMakeLists.txt @@ -82,13 +82,14 @@ endmacro(expand_h_cc_i) # Invoke macro to generate various sources ######################################################################## expand_h_cc_i(gr_vector_source_X b s i f c) +expand_h_cc_i(gr_vector_insert_X b) expand_h_cc_i(gr_vector_sink_X b s i f c) expand_h_cc_i(gr_noise_source_X s i f c) expand_h_cc_i(gr_sig_source_X s i f c) expand_h_cc_i(gr_probe_signal_X b s i f c) expand_h_cc_i(gr_probe_signal_vX b s i f c) -expand_h_cc_i(gr_add_const_XX ss ii ff cc sf) +expand_h_cc_i(gr_add_const_XX bb ss ii ff cc sf) expand_h_cc_i(gr_multiply_const_XX ss ii) expand_h_cc_i(gr_add_XX ss ii cc) expand_h_cc_i(gr_sub_XX ss ii ff cc) diff --git a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t index bdd0e810a7..6959eac824 100644 --- a/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t +++ b/gnuradio-core/src/lib/gengen/gr_sig_source_X.cc.t @@ -29,6 +29,7 @@ #include <algorithm> #include <gr_io_signature.h> #include <stdexcept> +#include <algorithm> #include <gr_complex.h> @@ -64,8 +65,7 @@ int case GR_CONST_WAVE: t = (gr_complex) d_ampl + d_offset; - for (int i = 0; i < noutput_items; i++) // FIXME unroll - optr[i] = t; + std::fill_n(optr, noutput_items, t); break; case GR_SIN_WAVE: @@ -142,8 +142,7 @@ int case GR_CONST_WAVE: t = (@TYPE@) d_ampl + d_offset; - for (int i = 0; i < noutput_items; i++) // FIXME unroll - optr[i] = t; + std::fill_n(optr, noutput_items, t); break; case GR_SIN_WAVE: diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t new file mode 100644 index 0000000000..37963cdfee --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.cc.t @@ -0,0 +1,100 @@ +/* -*- 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@.h> +#include <algorithm> +#include <gr_io_signature.h> +#include <stdexcept> + +#include <stdio.h> + +@NAME@::@NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset) + : gr_block("@BASE_NAME@", + gr_make_io_signature (1, 1, sizeof(@TYPE@)), + gr_make_io_signature (1, 1, sizeof(@TYPE@))), + d_data(data), + d_offset(offset), + d_periodicity(periodicity) +{ + //printf("INITIAL: periodicity = %d, offset = %d\n", periodicity, offset); + // some sanity checks + assert(offset < periodicity); + assert(offset >= 0); + assert(periodicity > data.size()); +} + +int +@NAME@::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) +{ + @TYPE@ *out = (@TYPE@ *)output_items[0]; + const @TYPE@ *in = (const @TYPE@ *)input_items[0]; + + int ii(0), oo(0); + + while((oo < noutput_items) && (ii < ninput_items[0])) { + + //printf("oo = %d, ii = %d, d_offset = %d, noutput_items = %d, ninput_items[0] = %d", oo, ii, d_offset, noutput_items, ninput_items[0]); + //printf(", d_periodicity = %d\n", d_periodicity); + + if(d_offset >= ((int)d_data.size())) { // if we are in the copy region + int max_copy = std::min( std::min( noutput_items - oo, ninput_items[0] - ii ), d_periodicity - d_offset ); + //printf("copy %d from input\n", max_copy); + memcpy( &out[oo], &in[ii], sizeof(@TYPE@)*max_copy ); + //printf(" * memcpy returned.\n"); + ii += max_copy; + oo += max_copy; + d_offset = (d_offset + max_copy)%d_periodicity; + + } + else { // if we are in the insertion region + int max_copy = std::min( noutput_items - oo, ((int)d_data.size()) - d_offset ); + //printf("copy %d from d_data[%d] to out[%d]\n", max_copy, d_offset, oo); + memcpy( &out[oo], &d_data[d_offset], sizeof(@TYPE@)*max_copy ); + //printf(" * memcpy returned.\n"); + oo += max_copy; + d_offset = (d_offset + max_copy)%d_periodicity; + //printf(" ## (inelse) oo = %d, d_offset = %d\n", oo, d_offset); + } + + //printf(" # exit else, on to next loop.\n"); + } + //printf(" # got out of loop\n"); + + //printf("consume = %d, produce = %d\n", ii, oo); + consume_each(ii); + return oo; +} + +@NAME@_sptr +gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset) +{ + return gnuradio::get_initial_sptr(new @NAME@ (data, periodicity, offset)); +} + diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t new file mode 100644 index 0000000000..26f851700d --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.h.t @@ -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. + */ + +// @WARNING@ + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include <gr_core_api.h> +#include <gr_block.h> + +class GR_CORE_API @NAME@; +typedef boost::shared_ptr<@NAME@> @NAME@_sptr; + +/*! + * \brief source of @TYPE@'s that gets its data from a vector + * \ingroup source_blk + */ + +class @NAME@ : public gr_block { + friend GR_CORE_API @NAME@_sptr + gr_make_@BASE_NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset); + + std::vector<@TYPE@> d_data; + int d_offset; + int d_periodicity; + + @NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset); + + public: + void rewind() {d_offset=0;} + virtual 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_data(const std::vector<@TYPE@> &data){ d_data = data; rewind(); } +}; + +GR_CORE_API @NAME@_sptr +gr_make_@BASE_NAME@(const std::vector<@TYPE@> &data, int periodicity, int offset=0); + +#endif diff --git a/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t new file mode 100644 index 0000000000..f3341eec4f --- /dev/null +++ b/gnuradio-core/src/lib/gengen/gr_vector_insert_X.i.t @@ -0,0 +1,37 @@ +/* -*- 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@ + +GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@); + +@NAME@_sptr +gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset = 0) + throw(std::invalid_argument); + +class @NAME@ : public gr_block { + public: + void rewind(); + void set_data(const std::vector<@TYPE@> &data); + private: + @NAME@ (const std::vector<@TYPE@> &data, int periodicity, int offset = 0); +}; diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t index fe0a77f818..fe02c1346f 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.h.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -52,6 +52,7 @@ class @NAME@ : public gr_sync_block { virtual int work (int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); + void set_data(const std::vector<@TYPE@> &data){ d_data = data; rewind(); } }; GR_CORE_API @NAME@_sptr diff --git a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t index 6c20539ac8..4986c68a35 100644 --- a/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t +++ b/gnuradio-core/src/lib/gengen/gr_vector_source_X.i.t @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -30,7 +30,8 @@ gr_make_@BASE_NAME@ (const std::vector<@TYPE@> &data, bool repeat = false, int v class @NAME@ : public gr_sync_block { public: - void rewind() {d_offset=0;} + void rewind(); + void set_data(const std::vector<@TYPE@> &data); private: @NAME@ (const std::vector<@TYPE@> &data, int vlen); }; diff --git a/gnuradio-core/src/lib/io/gri_wavfile.cc b/gnuradio-core/src/lib/io/gri_wavfile.cc index e316a08254..277e6b7b0e 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.cc +++ b/gnuradio-core/src/lib/io/gri_wavfile.cc @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2008 Free Software Foundation, Inc. + * Copyright 2004,2008,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,110 +27,45 @@ #include <gri_wavfile.h> #include <cstring> #include <stdint.h> +#include <boost/detail/endian.hpp> //BOOST_BIG_ENDIAN # define VALID_COMPRESSION_TYPE 0x0001 -// WAV files are always little-endian, so we need some byte switching macros - -// FIXME: Use libgruel versions - -#ifdef WORDS_BIGENDIAN - -#ifdef HAVE_BYTESWAP_H -#include <byteswap.h> -#else -#warning Using non-portable code (likely wrong other than ILP32). - -static inline short int -bswap_16 (unsigned short int x) -{ - return ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8)); -} - -static inline unsigned int -bswap_32 (unsigned int x) -{ - return ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ - | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); -} -#endif // HAVE_BYTESWAP_H - -static inline uint32_t -host_to_wav(uint32_t x) -{ - return bswap_32(x); -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return bswap_16(x); -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return bswap_16(x); -} +// Basically, this is the opposite of htonx() and ntohx() +// Define host to/from worknet (little endian) short and long +#ifdef BOOST_BIG_ENDIAN -static inline uint32_t -wav_to_host(uint32_t x) -{ - return bswap_32(x); -} + static inline uint16_t __gri_wav_bs16(uint16_t x) + { + return (x>>8) | (x<<8); + } -static inline uint16_t -wav_to_host(uint16_t x) -{ - return bswap_16(x); -} + static inline uint32_t __gri_wav_bs32(uint32_t x) + { + return (uint32_t(__gri_wav_bs16(uint16_t(x&0xfffful)))<<16) | (__gri_wav_bs16(uint16_t(x>>16))); + } -static inline int16_t -wav_to_host(int16_t x) -{ - return bswap_16(x); -} + #define htowl(x) __gri_wav_bs32(x) + #define wtohl(x) __gri_wav_bs32(x) + #define htows(x) __gri_wav_bs16(x) + #define wtohs(x) __gri_wav_bs16(x) #else -static inline uint32_t -host_to_wav(uint32_t x) -{ - return x; -} - -static inline uint16_t -host_to_wav(uint16_t x) -{ - return x; -} - -static inline int16_t -host_to_wav(int16_t x) -{ - return x; -} - -static inline uint32_t -wav_to_host(uint32_t x) -{ - return x; -} - -static inline uint16_t -wav_to_host(uint16_t x) -{ - return x; -} - -static inline int16_t -wav_to_host(int16_t x) -{ - return x; -} + #define htowl(x) uint32_t(x) + #define wtohl(x) uint32_t(x) + #define htows(x) uint16_t(x) + #define wtohs(x) uint16_t(x) -#endif // WORDS_BIGENDIAN +#endif // BOOST_BIG_ENDIAN +// WAV files are always little-endian, so we need some byte switching macros +static inline uint32_t host_to_wav(uint32_t x) { return htowl(x); } +static inline uint16_t host_to_wav(uint16_t x) { return htows(x); } +static inline int16_t host_to_wav(int16_t x) { return htows(x); } +static inline uint32_t wav_to_host(uint32_t x) { return wtohl(x); } +static inline uint16_t wav_to_host(uint16_t x) { return wtohs(x); } +static inline int16_t wav_to_host(int16_t x) { return wtohs(x); } bool gri_wavheader_parse(FILE *fp, @@ -225,12 +160,15 @@ gri_wavheader_parse(FILE *fp, short int gri_wav_read_sample(FILE *fp, int bytes_per_sample) { - int16_t buf = 0; - size_t fresult; + int16_t buf_16bit; - fresult = fread(&buf, bytes_per_sample, 1, fp); - - return (short) wav_to_host(buf); + if(!fread(&buf_16bit, bytes_per_sample, 1, fp)) { + return 0; + } + if(bytes_per_sample == 1) { + return (short) buf_16bit; + } + return (short)wav_to_host(buf_16bit); } diff --git a/gnuradio-core/src/lib/io/gri_wavfile.h b/gnuradio-core/src/lib/io/gri_wavfile.h index c757be26bc..16280e34a9 100644 --- a/gnuradio-core/src/lib/io/gri_wavfile.h +++ b/gnuradio-core/src/lib/io/gri_wavfile.h @@ -29,20 +29,15 @@ /*! * \brief Read signal information from a given WAV file. * - * \p fp File pointer to an opened, empty file. - * \p sample_rate Stores the sample rate [S/s] - * \p nchans Number of channels - * \p bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding to - * 8 or 16 bit samples, respectively) - * \p first_sample_pos Number of the first byte containing a sample. Use this - * with fseek() to jump from the end of the file to the first sample - * when in repeat mode. - * \p samples_per_chan Number of samples per channel - * \p normalize_fac The normalization factor with which you need to divide the - * integer values of the samples to get them within [-1;1] - * \p normalize_shift The value by which the sample values need to be shifted - * after normalization (reason being, 8-bit WAV files store samples as - * unsigned char and 16-bit as signed short int) + * \param[in] fp File pointer to an opened, empty file. + * \param[out] sample_rate Stores the sample rate [S/s] + * \param[out] nchans Number of channels + * \param[out] bytes_per_sample Bytes per sample, can either be 1 or 2 (corresponding o + * 8 or 16 bit samples, respectively) + * \param[out] first_sample_pos Number of the first byte containing a sample. Use this + * with fseek() to jump from the end of the file to the + * first sample when in repeat mode. + * \param[out] samples_per_chan Number of samples per channel * \return True on a successful read, false if the file could not be read or is * not a valid WAV file. */ @@ -94,8 +89,8 @@ gri_wav_write_sample(FILE *fp, short int sample, int bytes_per_sample); * shouldn't happen), you need to fseek() to the end of the file (or * whereever). * - * \p fp File pointer to an open WAV file with a blank header - * \p byte_count Length of all samples written to the file in bytes. + * \param[in] fp File pointer to an open WAV file with a blank header + * \param[in] byte_count Length of all samples written to the file in bytes. */ bool gri_wavheader_complete(FILE *fp, unsigned int byte_count); diff --git a/gnuradio-core/src/lib/runtime/gr_top_block.i b/gnuradio-core/src/lib/runtime/gr_top_block.i index 80a1b82aea..6ae4c65a99 100644 --- a/gnuradio-core/src/lib/runtime/gr_top_block.i +++ b/gnuradio-core/src/lib/runtime/gr_top_block.i @@ -20,8 +20,6 @@ * Boston, MA 02110-1301, USA. */ -%include <gr_top_block.i> - class gr_top_block; typedef boost::shared_ptr<gr_top_block> gr_top_block_sptr; %template(gr_top_block_sptr) boost::shared_ptr<gr_top_block>; diff --git a/gnuradio-core/src/lib/swig/gnuradio.i b/gnuradio-core/src/lib/swig/gnuradio.i index 2392238512..3a421ad5d6 100644 --- a/gnuradio-core/src/lib/swig/gnuradio.i +++ b/gnuradio-core/src/lib/swig/gnuradio.i @@ -20,6 +20,9 @@ * Boston, MA 02110-1301, USA. */ +// Disable warning about base class types +#pragma SWIG nowarn=401 + //////////////////////////////////////////////////////////////////////// // gnuradio.i // SWIG interface definition diff --git a/gnuradio-core/src/lib/swig/gr_swig_block_magic.i b/gnuradio-core/src/lib/swig/gr_swig_block_magic.i index cdc9fbe494..4016ae7727 100644 --- a/gnuradio-core/src/lib/swig/gr_swig_block_magic.i +++ b/gnuradio-core/src/lib/swig/gr_swig_block_magic.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2004,2010 Free Software Foundation, Inc. + * Copyright 2004,2010,2012 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -40,3 +40,11 @@ FULL_NAME ## _sptr.__repr__ = lambda self: "<gr_block %s (%d)>" % (self.name(), %} %enddef #endif + +%define GR_SWIG_BLOCK_MAGIC2(PKG, BASE_NAME) +%template(BASE_NAME ## _sptr) boost::shared_ptr<gr:: ## PKG ## :: ## BASE_NAME>; +%pythoncode %{ +BASE_NAME ## _sptr.__repr__ = lambda self: "<gr_block %s (%d)>" % (self.name(), self.unique_id()) +BASE_NAME = BASE_NAME.make; +%} +%enddef diff --git a/gnuradio-core/src/python/build_utils.py b/gnuradio-core/src/python/build_utils.py index 0660941d57..77bf0607a3 100644 --- a/gnuradio-core/src/python/build_utils.py +++ b/gnuradio-core/src/python/build_utils.py @@ -176,13 +176,13 @@ def is_complex (code3): return '0' -def standard_dict (name, code3): +def standard_dict (name, code3, package='gr'): d = {} d['NAME'] = name d['GUARD_NAME'] = 'INCLUDED_%s_H' % name.upper () - d['BASE_NAME'] = re.sub ('^gr_', '', name) + d['BASE_NAME'] = re.sub ('^' + package + '_', '', name) d['SPTR_NAME'] = '%s_sptr' % name - d['WARNING'] = 'WARNING: this file is machine generated. Edits will be over written' + d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' d['COPYRIGHT'] = copyright d['TYPE'] = i_type (code3) d['I_TYPE'] = i_type (code3) @@ -190,3 +190,35 @@ def standard_dict (name, code3): d['TAP_TYPE'] = tap_type (code3) d['IS_COMPLEX'] = is_complex (code3) return d + + +def standard_dict2 (name, code3, package): + d = {} + d['NAME'] = name + d['BASE_NAME'] = name + d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) + d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' + d['COPYRIGHT'] = copyright + d['TYPE'] = i_type (code3) + d['I_TYPE'] = i_type (code3) + d['O_TYPE'] = o_type (code3) + d['TAP_TYPE'] = tap_type (code3) + d['IS_COMPLEX'] = is_complex (code3) + return d + +def standard_impl_dict2 (name, code3, package): + d = {} + d['NAME'] = name + d['IMPL_NAME'] = name + d['BASE_NAME'] = name.rstrip("_impl") + d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) + d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' + d['COPYRIGHT'] = copyright + d['FIR_TYPE'] = "fir_filter_" + code3 + d['CFIR_TYPE'] = "fir_filter_" + code3[0:2] + 'c' + d['TYPE'] = i_type (code3) + d['I_TYPE'] = i_type (code3) + d['O_TYPE'] = o_type (code3) + d['TAP_TYPE'] = tap_type (code3) + d['IS_COMPLEX'] = is_complex (code3) + return d diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_dc_blocker.py b/gnuradio-core/src/python/gnuradio/gr/qa_dc_blocker.py index 0f6fa86f56..1757358676 100755 --- a/gnuradio-core/src/python/gnuradio/gr/qa_dc_blocker.py +++ b/gnuradio-core/src/python/gnuradio/gr/qa_dc_blocker.py @@ -46,7 +46,7 @@ class test_dc_blocker(gr_unittest.TestCase): # only test samples around 2D-2 result_data = dst.data()[60:65] - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertComplexTuplesAlmostEqual (expected_result, result_data) def test_002(self): ''' Test impulse response - short form, cc ''' @@ -64,7 +64,7 @@ class test_dc_blocker(gr_unittest.TestCase): # only test samples around D-1 result_data = dst.data()[29:34] - self.assertFloatTuplesAlmostEqual (expected_result, result_data) + self.assertComplexTuplesAlmostEqual (expected_result, result_data) def test_003(self): diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py new file mode 100755 index 0000000000..922671d024 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_keep_m_in_n.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2008,2010 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +from gnuradio import gr, gr_unittest +import sys +import random + +class test_keep_m_in_n(gr_unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self): + pass + + def test_001(self): + self.maxDiff = None; + tb = gr.top_block() + src = gr.vector_source_b( range(0,100) ) + + # itemsize, M, N, offset + km2 = gr.keep_m_in_n( 1, 1, 2, 0 ); + km3 = gr.keep_m_in_n( 1, 1, 3, 1 ); + km7 = gr.keep_m_in_n( 1, 1, 7, 2 ); + snk2 = gr.vector_sink_b(); + snk3 = gr.vector_sink_b(); + snk7 = gr.vector_sink_b(); + tb.connect(src,km2,snk2); + tb.connect(src,km3,snk3); + tb.connect(src,km7,snk7); + tb.run(); + + self.assertEqual(range(0,100,2), list(snk2.data())); + self.assertEqual(range(1,100,3), list(snk3.data())); + self.assertEqual(range(2,100,7), list(snk7.data())); + + +if __name__ == '__main__': + gr_unittest.run(test_keep_m_in_n, "test_keep_m_in_n.xml") + diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py b/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py new file mode 100755 index 0000000000..25fc5e9fcc --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_pack_k_bits.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# Copyright 2006,2010 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import random + +class test_pack(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (1,0,1,1,0,1,1,0) + expected_results = (1,0,1,1,0,1,1,0) + src = gr.vector_source_b(src_data,False) + op = gr.pack_k_bits_bb(1) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (1,0,1,1,0,0,0,1) + expected_results = ( 2, 3, 0, 1) + src = gr.vector_source_b(src_data,False) + op = gr.pack_k_bits_bb(2) + dst = gr.vector_sink_b() + self.tb.connect(src, op, dst) + self.tb.run() + #self.assertEqual(expected_results, dst.data()) + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = expected_results = map(lambda x: random.randint(0,3), range(10)); + src = gr.vector_source_b( src_data ); + pack = gr.pack_k_bits_bb(2); + unpack = gr.unpack_k_bits_bb(2); + snk = gr.vector_sink_b(); + self.tb.connect(src,unpack,pack,snk); + self.tb.run() + self.assertEqual(list(expected_results), list(snk.data())); + +if __name__ == '__main__': + gr_unittest.run(test_pack, "test_pack.xml") + diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py b/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py new file mode 100755 index 0000000000..81babca048 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_tag_debug.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest + +class test_tag_debug(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_001(self): + # Just run some data through and make sure it doesn't puke. + src_data = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) + src = gr.vector_source_i(src_data) + op = gr.tag_debug(gr.sizeof_int, "tag QA") + self.tb.connect(src, op) + self.tb.run() + x = op.current_tags() + +if __name__ == '__main__': + gr_unittest.run(test_tag_debug, "test_tag_debug.xml") diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py new file mode 100755 index 0000000000..acc06dfded --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_insert.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import math + +class test_vector_insert(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block () + + def tearDown (self): + self.tb = None + + def test_001(self): + src_data = [float(x) for x in range(16)] + expected_result = tuple(src_data) + + period = 9177; + offset = 0; + + src = gr.null_source(1) + head = gr.head(1, 10000000); + ins = gr.vector_insert_b([1], period, offset); + dst = gr.vector_sink_b() + + self.tb.connect(src, head, ins, dst) + self.tb.run() + result_data = dst.data() + + for i in range(10000): + if(i%period == offset): + self.assertEqual(1, result_data[i]) + else: + self.assertEqual(0, result_data[i]) + +if __name__ == '__main__': + gr_unittest.run(test_vector_insert, "test_vector_insert.xml") + diff --git a/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py new file mode 100644 index 0000000000..12f4be5898 --- /dev/null +++ b/gnuradio-core/src/python/gnuradio/gr/qa_vector_map.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import math + +class test_vector_map(gr_unittest.TestCase): + + def setUp (self): + self.tb = gr.top_block() + + def tearDown (self): + self.tb = None + + def test_reversing(self): + # Chunk data in blocks of N and reverse the block contents. + N = 5 + src_data = range(0, 20) + expected_result = [] + for i in range(N-1, len(src_data), N): + for j in range(0, N): + expected_result.append(1.0*(i-j)) + mapping = [list(reversed([(0, i) for i in range(0, N)]))] + src = gr.vector_source_f(src_data, False, N) + vmap = gr.vector_map(gr.sizeof_float, (N, ), mapping) + dst = gr.vector_sink_f(N) + self.tb.connect(src, vmap, dst) + self.tb.run() + result_data = list(dst.data()) + self.assertEqual(expected_result, result_data) + + def test_vector_to_streams(self): + # Split an input vector into N streams. + N = 5 + M = 20 + src_data = range(0, M) + expected_results = [] + for n in range(0, N): + expected_results.append(range(n, M, N)) + mapping = [[(0, n)] for n in range(0, N)] + src = gr.vector_source_f(src_data, False, N) + vmap = gr.vector_map(gr.sizeof_float, (N, ), mapping) + dsts = [gr.vector_sink_f(1) for n in range(0, N)] + self.tb.connect(src, vmap) + for n in range(0, N): + self.tb.connect((vmap, n), dsts[n]) + self.tb.run() + for n in range(0, N): + result_data = list(dsts[n].data()) + self.assertEqual(expected_results[n], result_data) + + def test_interleaving(self): + # Takes 3 streams (a, b and c) + # Outputs 2 streams. + # First (d) is interleaving of a and b. + # Second (e) is interleaving of a and b and c. c is taken in + # chunks of 2 which are reversed. + A = (1, 2, 3, 4, 5) + B = (11, 12, 13, 14, 15) + C = (99, 98, 97, 96, 95, 94, 93, 92, 91, 90) + expected_D = (1, 11, 2, 12, 3, 13, 4, 14, 5, 15) + expected_E = (1, 11, 98, 99, 2, 12, 96, 97, 3, 13, 94, 95, + 4, 14, 92, 93, 5, 15, 90, 91) + mapping = [[(0, 0), (1, 0)], # mapping to produce D + [(0, 0), (1, 0), (2, 1), (2, 0)], # mapping to produce E + ] + srcA = gr.vector_source_f(A, False, 1) + srcB = gr.vector_source_f(B, False, 1) + srcC = gr.vector_source_f(C, False, 2) + vmap = gr.vector_map(gr.sizeof_int, (1, 1, 2), mapping) + dstD = gr.vector_sink_f(2) + dstE = gr.vector_sink_f(4) + self.tb.connect(srcA, (vmap, 0)) + self.tb.connect(srcB, (vmap, 1)) + self.tb.connect(srcC, (vmap, 2)) + self.tb.connect((vmap, 0), dstD) + self.tb.connect((vmap, 1), dstE) + self.tb.run() + self.assertEqual(expected_D, dstD.data()) + self.assertEqual(expected_E, dstE.data()) + + + +if __name__ == '__main__': + gr_unittest.run(test_vector_map, "test_vector_map.xml") + |