diff options
author | Martin Braun | 2013-02-26 13:44:12 +0100 |
---|---|---|
committer | Martin Braun | 2013-02-26 13:44:12 +0100 |
commit | 7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557 (patch) | |
tree | aec6e881cdd825c39a084ce7aa16a87c045a4fae /gr-blocks | |
parent | d7766c2c8d12bbfaf29b83cfea5ff95475b45d86 (diff) | |
parent | a54dc5bab6cc38513e9732be9f5c2670145b160f (diff) | |
download | gnuradio-7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557.tar.gz gnuradio-7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557.tar.bz2 gnuradio-7bb8c89e224e7b2c9ddbc5b4f50c79ffb0da2557.zip |
Merge branch 'master' of git://github.com/gnuradio/gnuradio into grmodtool
Diffstat (limited to 'gr-blocks')
53 files changed, 3705 insertions, 4 deletions
diff --git a/gr-blocks/grc/blocks_block_tree.xml b/gr-blocks/grc/blocks_block_tree.xml index 797b3dbc5..6ab84c94e 100644 --- a/gr-blocks/grc/blocks_block_tree.xml +++ b/gr-blocks/grc/blocks_block_tree.xml @@ -49,6 +49,7 @@ <block>blocks_conjugate_cc</block> <block>blocks_integrate_xx</block> <block>blocks_nlog10_ff</block> + <block>blocks_rms_xx</block> </cat> <cat> <name>Boolean Operations (New) </name> @@ -82,7 +83,10 @@ </cat> <cat> <name>Stream Operations (New) </name> - <block>blocks_deinterleave</block> + <block>blocks_delay</block> + <block>blocks_packed_to_unpacked_xx</block> + <block>blocks_unpacked_to_packed_xx</block> + <block>blocks_deinterleave</block> <block>blocks_interleave</block> <block>blocks_keep_m_in_n</block> <block>blocks_keep_one_in_n</block> @@ -94,5 +98,13 @@ <block>blocks_streams_to_vector</block> <block>blocks_vector_to_stream</block> <block>blocks_vector_to_streams</block> + <block>blocks_peak_detector2_fb</block> + <block>blocks_regenerate_bb</block> + <block>blocks_stretch_ff</block> + <block>blocks_threadhold_ff</block> + </cat> + <cat> + <name>Misc (New) </name> + <block>blocks_throttle</block> </cat> </cat> diff --git a/gr-blocks/grc/blocks_delay.xml b/gr-blocks/grc/blocks_delay.xml new file mode 100644 index 000000000..a7c48c4dc --- /dev/null +++ b/gr-blocks/grc/blocks_delay.xml @@ -0,0 +1,75 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Delay +################################################### + --> +<block> + <name>Delay</name> + <key>blocks_delay</key> + <import>from gnuradio import blocks</import> + <make>blocks.delay($type.size*$vlen, $delay)</make> + <callback>set_dly($delay)</callback> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>size:gr.sizeof_gr_complex</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>size:gr.sizeof_int</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>size:gr.sizeof_short</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + </param> + <param> + <name>Delay</name> + <key>delay</key> + <value>0</value> + <type>int</type> + </param> + <param> + <name>Num Ports</name> + <key>num_ports</key> + <value>1</value> + <type>int</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$num_ports > 0</check> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_ports</nports> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + <nports>$num_ports</nports> + </source> +</block> diff --git a/gr-blocks/grc/blocks_packed_to_unpacked_xx.xml b/gr-blocks/grc/blocks_packed_to_unpacked_xx.xml new file mode 100644 index 000000000..b236a38db --- /dev/null +++ b/gr-blocks/grc/blocks_packed_to_unpacked_xx.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Packed to Unpacked +################################################### + --> +<block> + <name>Packed to Unpacked</name> + <key>blocks_packed_to_unpacked_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.packed_to_unpacked_$(type.fcn)($bits_per_chunk, $endianness)</make> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:ii</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:ss</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>fcn:bb</opt> + </option> + </param> + <param> + <name>Bits per Chunk</name> + <key>bits_per_chunk</key> + <value>2</value> + <type>int</type> + </param> + <param> + <name>Endianness</name> + <key>endianness</key> + <type>int</type> + <option> + <name>MSB</name> + <key>gr.GR_MSB_FIRST</key> + </option> + <option> + <name>LSB</name> + <key>gr.GR_LSB_FIRST</key> + </option> + </param> + <param> + <name>Num Ports</name> + <key>num_ports</key> + <value>1</value> + <type>int</type> + </param> + <check>$num_ports > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <nports>$num_ports</nports> + </sink> + <source> + <name>out</name> + <type>$type</type> + <nports>$num_ports</nports> + </source> +</block> diff --git a/gr-blocks/grc/blocks_peak_detector2_fb.xml b/gr-blocks/grc/blocks_peak_detector2_fb.xml new file mode 100644 index 000000000..584e7a1fb --- /dev/null +++ b/gr-blocks/grc/blocks_peak_detector2_fb.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Peak Detector2 +################################################### + --> +<block> + <name>Peak Detector2</name> + <key>blocks_peak_detector2_fb</key> + <import>from gnuradio import blocks</import> + <make>blocks.peak_detector2_fb($threshold_factor_rise, $look_ahead, $alpha)</make> + <callback>set_threshold_factor_rise($threshold_factor_rise)</callback> + <callback>set_look_ahead($look_ahead)</callback> + <callback>set_alpha($alpha)</callback> + <param> + <name>TH Factor Rise</name> + <key>threshold_factor_rise</key> + <value>7</value> + <type>real</type> + </param> + <param> + <name>Look Ahead</name> + <key>look_ahead</key> + <value>1000</value> + <type>int</type> + </param> + <param> + <name>Alpha</name> + <key>alpha</key> + <value>0.001</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>float</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_regenerate_bb.xml b/gr-blocks/grc/blocks_regenerate_bb.xml new file mode 100644 index 000000000..bbee53387 --- /dev/null +++ b/gr-blocks/grc/blocks_regenerate_bb.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Regenerate Block: +## char in/ char out +################################################### + --> +<block> + <name>Regenerate</name> + <key>blocks_regenerate_bb</key> + <import>from gnuradio import blocks</import> + <make>blocks.regenerate_bb($period, $max_regen)</make> + <param> + <name>Period</name> + <key>period</key> + <type>int</type> + </param> + <param> + <name>Max Regen Count</name> + <key>max_regen</key> + <value>500</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>byte</type> + </sink> + <source> + <name>out</name> + <type>byte</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_rms_xx.xml b/gr-blocks/grc/blocks_rms_xx.xml new file mode 100644 index 000000000..0ae09139a --- /dev/null +++ b/gr-blocks/grc/blocks_rms_xx.xml @@ -0,0 +1,42 @@ +<?xml version="1.0"?> +<!-- +################################################### +##RMS +################################################### + --> +<block> + <name>RMS</name> + <key>blocks_rms_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.rms_$(type.fcn)f($alpha)</make> + <callback>set_alpha($alpha)</callback> + <param> + <name>Input Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>fcn:c</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>fcn:f</opt> + </option> + </param> + <param> + <name>Alpha</name> + <key>alpha</key> + <value>0.0001</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>$type</type> + </sink> + <source> + <name>out</name> + <type>float</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_stretch_ff.xml b/gr-blocks/grc/blocks_stretch_ff.xml new file mode 100644 index 000000000..00a67602b --- /dev/null +++ b/gr-blocks/grc/blocks_stretch_ff.xml @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Stretch Block: +## float in / float out +################################################### + --> +<block> + <name>Stretch</name> + <key>blocks_stretch_ff</key> + <import>from gnuradio import blocks</import> + <make>blocks.stretch_ff($lo, $vlen)</make> + <param> + <name>Low</name> + <key>lo</key> + <type>real</type> + </param> + <param> + <name>Vec. Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <sink> + <name>in</name> + <type>float</type> + <vlen>$vlen</vlen> + </sink> + <source> + <name>out</name> + <type>float</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/grc/blocks_threshold_ff.xml b/gr-blocks/grc/blocks_threshold_ff.xml new file mode 100644 index 000000000..0da4157fc --- /dev/null +++ b/gr-blocks/grc/blocks_threshold_ff.xml @@ -0,0 +1,40 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Threshold +################################################### + --> +<block> + <name>Threshold</name> + <key>blocks_threshold_ff</key> + <import>from gnuradio import blocks</import> + <make>blocks.threshold_ff($low, $high, $init)</make> + <callback>set_hi($high)</callback> + <callback>set_lo($low)</callback> + <param> + <name>Low</name> + <key>low</key> + <value>-100</value> + <type>real</type> + </param> + <param> + <name>High</name> + <key>high</key> + <value>100</value> + <type>real</type> + </param> + <param> + <name>Initial State</name> + <key>init</key> + <value>0</value> + <type>real</type> + </param> + <sink> + <name>in</name> + <type>float</type> + </sink> + <source> + <name>out</name> + <type>float</type> + </source> +</block> diff --git a/gr-blocks/grc/blocks_throttle.xml b/gr-blocks/grc/blocks_throttle.xml new file mode 100644 index 000000000..8293cbde9 --- /dev/null +++ b/gr-blocks/grc/blocks_throttle.xml @@ -0,0 +1,67 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Throttle +################################################### + --> +<block> + <name>Throttle</name> + <key>blocks_throttle</key> + <throttle>1</throttle> + <import>from gnuradio import blocks</import> + <make>blocks.throttle($type.size*$vlen, $samples_per_second)</make> + <callback>set_sample_rate($samples_per_second)</callback> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>size:gr.sizeof_gr_complex</opt> + </option> + <option> + <name>Float</name> + <key>float</key> + <opt>size:gr.sizeof_float</opt> + </option> + <option> + <name>Int</name> + <key>int</key> + <opt>size:gr.sizeof_int</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>size:gr.sizeof_short</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>size:gr.sizeof_char</opt> + </option> + </param> + <param> + <name>Sample Rate</name> + <key>samples_per_second</key> + <value>samp_rate</value> + <type>real</type> + </param> + <param> + <name>Vec Length</name> + <key>vlen</key> + <value>1</value> + <type>int</type> + </param> + <check>$vlen > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <vlen>$vlen</vlen> + </sink> + <source> + <name>out</name> + <type>$type</type> + <vlen>$vlen</vlen> + </source> +</block> diff --git a/gr-blocks/grc/blocks_unpacked_to_packed_xx.xml b/gr-blocks/grc/blocks_unpacked_to_packed_xx.xml new file mode 100644 index 000000000..d27dc9bfc --- /dev/null +++ b/gr-blocks/grc/blocks_unpacked_to_packed_xx.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Unpacked to Packed +################################################### + --> +<block> + <name>Unpacked to Packed</name> + <key>blocks_unpacked_to_packed_xx</key> + <import>from gnuradio import blocks</import> + <make>blocks.unpacked_to_packed_$(type.fcn)($bits_per_chunk, $endianness)</make> + <param> + <name>Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Int</name> + <key>int</key> + <opt>fcn:ii</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>fcn:ss</opt> + </option> + <option> + <name>Byte</name> + <key>byte</key> + <opt>fcn:bb</opt> + </option> + </param> + <param> + <name>Bits per Chunk</name> + <key>bits_per_chunk</key> + <value>2</value> + <type>int</type> + </param> + <param> + <name>Endianness</name> + <key>endianness</key> + <type>int</type> + <option> + <name>MSB</name> + <key>gr.GR_MSB_FIRST</key> + </option> + <option> + <name>LSB</name> + <key>gr.GR_LSB_FIRST</key> + </option> + </param> + <param> + <name>Num Ports</name> + <key>num_ports</key> + <value>1</value> + <type>int</type> + </param> + <check>$num_ports > 0</check> + <sink> + <name>in</name> + <type>$type</type> + <nports>$num_ports</nports> + </sink> + <source> + <name>out</name> + <type>$type</type> + <nports>$num_ports</nports> + </source> +</block> diff --git a/gr-blocks/include/blocks/CMakeLists.txt b/gr-blocks/include/blocks/CMakeLists.txt index 37790b7cf..8d5fe9b13 100644 --- a/gr-blocks/include/blocks/CMakeLists.txt +++ b/gr-blocks/include/blocks/CMakeLists.txt @@ -78,6 +78,8 @@ expand_h(not_XX bb ss ii) expand_h(or_XX bb ss ii) expand_h(sub_XX ss ii ff cc) expand_h(xor_XX bb ss ii) +expand_h(packed_to_unpacked_XX bb ss ii) +expand_h(unpacked_to_packed_XX bb ss ii) add_custom_target(blocks_generated_includes DEPENDS ${generated_includes} @@ -90,6 +92,7 @@ install(FILES ${generated_includes} api.h count_bits.h + log2_const.h add_ff.h char_to_float.h char_to_short.h @@ -102,6 +105,7 @@ install(FILES complex_to_arg.h conjugate_cc.h deinterleave.h + delay.h file_source.h file_meta_sink.h file_meta_source.h @@ -122,7 +126,11 @@ install(FILES multiply_const_ff.h nlog10_ff.h patterned_interleaver.h + peak_detector2_fb.h + regenerate_bb.h repeat.h + rms_cf.h + rms_ff.h short_to_char.h short_to_float.h stream_mux.h @@ -130,6 +138,9 @@ install(FILES stream_to_vector.h streams_to_stream.h streams_to_vector.h + stretch_ff.h + threshold_ff.h + throttle.h uchar_to_float.h vector_to_stream.h vector_to_streams.h diff --git a/gr-blocks/include/blocks/delay.h b/gr-blocks/include/blocks/delay.h new file mode 100644 index 000000000..2a59fa0fc --- /dev/null +++ b/gr-blocks/include/blocks/delay.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_DELAY_H +#define INCLUDED_BLOCKS_DELAY_H + +#include <blocks/api.h> +#include <gr_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief delay the input by a certain number of samples + * \ingroup misc_blk + */ + class BLOCKS_API delay : virtual public gr_block + { + public: + // gr::blocks::delay::sptr + typedef boost::shared_ptr<delay> sptr; + + /*! + * \brief Make a delay block. + * \param itemsize size of the data items. + * \param delay number of samples to delay stream. + */ + static sptr make(size_t itemsize, int delay); + + virtual int dly() const = 0; + virtual void set_dly(int d) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_DELAY_H */ + diff --git a/gr-blocks/include/blocks/log2_const.h b/gr-blocks/include/blocks/log2_const.h new file mode 100644 index 000000000..67d63810f --- /dev/null +++ b/gr-blocks/include/blocks/log2_const.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +/* + * a bit of template hackery... + */ +#ifndef INCLUDED_BLOCKS_LOG2_CONST_H +#define INCLUDED_BLOCKS_LOG2_CONST_H + +#include <blocks/api.h> +#include <assert.h> + +namespace gr { + namespace blocks { + + template<unsigned int k> static inline int log2_const() { assert(0); return 0; } + + template<> inline int log2_const<1>() { return 0; } + template<> inline int log2_const<2>() { return 1; } + template<> inline int log2_const<4>() { return 2; } + template<> inline int log2_const<8>() { return 3; } + template<> inline int log2_const<16>() { return 4; } + template<> inline int log2_const<32>() { return 5; } + template<> inline int log2_const<64>() { return 6; } + template<> inline int log2_const<128>() { return 7; } + template<> inline int log2_const<256>() { return 8; } + template<> inline int log2_const<512>() { return 9; } + template<> inline int log2_const<1024>(){ return 10; } + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_LOG2_CONST_H */ diff --git a/gr-blocks/include/blocks/packed_to_unpacked_XX.h.t b/gr-blocks/include/blocks/packed_to_unpacked_XX.h.t new file mode 100644 index 000000000..9ab8b8bdf --- /dev/null +++ b/gr-blocks/include/blocks/packed_to_unpacked_XX.h.t @@ -0,0 +1,73 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 <blocks/api.h> +#include <gr_block.h> +#include <gr_endianness.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Convert a stream of packed bytes or shorts to stream of unpacked bytes or shorts. + * \ingroup converter_blk + * + * input: stream of @I_TYPE@; output: stream of @O_TYPE@ + * + * This is the inverse of gr::blocks::unpacked_to_packed_XX. + * + * The bits in the bytes or shorts input stream are grouped into + * chunks of \p bits_per_chunk bits and each resulting chunk is + * written right- justified to the output stream of bytes or + * shorts. All b or 16 bits of the each input bytes or short are + * processed. The right thing is done if bits_per_chunk is not a + * power of two. + * + * The combination of gr_packed_to_unpacked_XX_ followed by + * gr_chunks_to_symbols_Xf or gr_chunks_to_symbols_Xc handles the + * general case of mapping from a stream of bytes or shorts into + * arbitrary float or complex symbols. + * + * \sa gr::blocks::packed_to_unpacked_bb, gr::blocks::unpacked_to_packed_bb, + * \sa gr::blocks::packed_to_unpacked_ss, gr::blocks::unpacked_to_packed_ss, + * \sa gr::blocks::chunks_to_symbols_bf, gr::blocks::chunks_to_symbols_bc. + * \sa gr::blocks::chunks_to_symbols_sf, gr::blocks::chunks_to_symbols_sc. + */ + class BLOCKS_API @NAME@ : virtual public gr_block + { + public: + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + static sptr make(unsigned int bits_per_chunk, + gr_endianness_t endianness); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/include/blocks/peak_detector2_fb.h b/gr-blocks/include/blocks/peak_detector2_fb.h new file mode 100644 index 000000000..71afc3287 --- /dev/null +++ b/gr-blocks/include/blocks/peak_detector2_fb.h @@ -0,0 +1,91 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_PEAK_DETECTOR2_FB_H +#define INCLUDED_GR_PEAK_DETECTOR2_FB_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Detect the peak of a signal + * \ingroup level_blk + * + * If a peak is detected, this block outputs a 1, or it outputs + * 0's. A separate debug output may be connected, to view the + * internal EWMA described below. + * + * \param threshold_factor_rise The threshold factor determins + * when a peak is present. An EWMA average of the signal is + * calculated and when the value of the signal goes over + * threshold_factor_rise*average, we call the peak. + * \param look_ahead The look-ahead value is used when the + * threshold is found to locate the peak within this range. + * \param alpha The gain value of a single-pole moving average filter. + */ + class BLOCKS_API peak_detector2_fb : virtual public gr_sync_block + { + public: + // gr::blocks::peak_detector2_fb::sptr + typedef boost::shared_ptr<peak_detector2_fb> sptr; + + static sptr make(float threshold_factor_rise=7, + int look_ahead=1000, float alpha=0.001); + + /*! \brief Set the threshold factor value for the rise time + * \param thr new threshold factor + */ + virtual void set_threshold_factor_rise(float thr) = 0; + + /*! \brief Set the look-ahead factor + * \param look new look-ahead factor + */ + virtual void set_look_ahead(int look) = 0; + + /*! \brief Set the running average alpha + * \param alpha new alpha for running average + */ + virtual void set_alpha(int alpha) = 0; + + /*! \brief Get the threshold factor value for the rise time + * \return threshold factor + */ + virtual float threshold_factor_rise() = 0; + + /*! \brief Get the look-ahead factor value + * \return look-ahead factor + */ + virtual int look_ahead() = 0; + + /*! \brief Get the alpha value of the running average + * \return alpha + */ + virtual float alpha() = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PEAK_DETECTOR2_FB_H */ diff --git a/gr-blocks/include/blocks/regenerate_bb.h b/gr-blocks/include/blocks/regenerate_bb.h new file mode 100644 index 000000000..3063e70a7 --- /dev/null +++ b/gr-blocks/include/blocks/regenerate_bb.h @@ -0,0 +1,80 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_REGENERATE_BB_H +#define INCLUDED_GR_REGENERATE_BB_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Detect the peak of a signal and repeat every period samples + * \ingroup level_blk + * + * If a peak is detected, this block outputs a 1 repeated every + * period samples until reset by detection of another 1 on the + * input or stopped after max_regen regenerations have occurred. + * + * Note that if max_regen=(-1)/ULONG_MAX then the regeneration + * will run forever. + */ + class BLOCKS_API regenerate_bb : virtual public gr_sync_block + { + public: + // gr::blocks::regenerate_bb::sptr + typedef boost::shared_ptr<regenerate_bb> sptr; + + /*! + * \brief Make a regenerate block + * \param period The number of samples between regenerations + * \param max_regen The maximum number of regenerations to + * perform; if set to ULONG_MAX, it will regenerate + * continuously. + */ + static sptr make(int period, unsigned int max_regen=500); + + /*! \brief Reset the maximum regeneration count; this will reset + the current regen. + */ + virtual void set_max_regen(unsigned int regen) = 0; + + /*! \brief Reset the period of regenerations; this will reset + the current regen. + */ + virtual void set_period(int period) = 0; + + /*! \brief return the maximum regeneration count. + */ + virtual unsigned int max_regen() const = 0; + + /*! \brief return the regeneration period. + */ + virtual int period() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_REGENERATE_BB_H */ diff --git a/gr-blocks/include/blocks/rms_cf.h b/gr-blocks/include/blocks/rms_cf.h new file mode 100644 index 000000000..e73be6923 --- /dev/null +++ b/gr-blocks/include/blocks/rms_cf.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_RMS_CF_H +#define INCLUDED_BLOCKS_RMS_CF_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief RMS average power + * \ingroup math_blk + */ + class BLOCKS_API rms_cf : virtual public gr_sync_block + { + public: + // gr::blocks::rms_cf::sptr + typedef boost::shared_ptr<rms_cf> sptr; + + /*! + * \brief Make an RMS calc. block. + * \param alpha gain for running average filter. + */ + static sptr make(double alpha = 0.0001); + + virtual void set_alpha(double alpha) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_RMS_CF_H */ diff --git a/gr-blocks/include/blocks/rms_ff.h b/gr-blocks/include/blocks/rms_ff.h new file mode 100644 index 000000000..19fb0016d --- /dev/null +++ b/gr-blocks/include/blocks/rms_ff.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_RMS_FF_H +#define INCLUDED_BLOCKS_RMS_FF_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief RMS average power + * \ingroup math_blk + */ + class BLOCKS_API rms_ff : virtual public gr_sync_block + { + public: + // gr::blocks::rms_ff::sptr + typedef boost::shared_ptr<rms_ff> sptr; + + /*! + * \brief Make an RMS calc. block. + * \param alpha gain for running average filter. + */ + static sptr make(double alpha = 0.0001); + + virtual void set_alpha(double alpha) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_BLOCKS_RMS_FF_H */ diff --git a/gr-blocks/include/blocks/stretch_ff.h b/gr-blocks/include/blocks/stretch_ff.h new file mode 100644 index 000000000..5f98452a4 --- /dev/null +++ b/gr-blocks/include/blocks/stretch_ff.h @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_STRETCH_FF_H +#define INCLUDED_GR_STRETCH_FF_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief adjust y-range of an input vector by mapping to range + * (max-of-input, stipulated-min). Primarily for spectral + * signature matching by normalizing spectrum dynamic ranges. + * \ingroup misc_blk + */ + class BLOCKS_API stretch_ff : virtual public gr_sync_block + { + public: + // gr::blocks::stretch_ff::sptr + typedef boost::shared_ptr<stretch_ff> sptr; + + /*! + * \brief Make a stretch block. + * \param lo Set low value for range. + * \param vlen vector length of input stream. + */ + static sptr make(float lo, size_t vlen=1); + + virtual float lo() const = 0; + virtual void set_lo(float lo) = 0; + virtual size_t vlen() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_STRETCH_FF_H */ diff --git a/gr-blocks/include/blocks/threshold_ff.h b/gr-blocks/include/blocks/threshold_ff.h new file mode 100644 index 000000000..900e5c5bd --- /dev/null +++ b/gr-blocks/include/blocks/threshold_ff.h @@ -0,0 +1,66 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_THRESHOLD_FF_H +#define INCLUDED_GR_THRESHOLD_FF_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Output a 1 or zero based on a threshold value. + * \ingroup misc_blk + * + * Test the incoming signal against a threshold. If the signal + * excedes the \p hi value, it will output a 1 until the signal + * falls below the \p lo value. + */ + class BLOCKS_API threshold_ff : virtual public gr_sync_block + { + public: + // gr::blocks::threshold_ff::sptr + typedef boost::shared_ptr<threshold_ff> sptr; + + /* \brief Create a threadshold block. + * \param lo Threshold input signal needs to drop below to + * change state to 0. + * \param hi Threshold input signal needs to rise above to + * change state to 1. + * \param initial_state Initial state of the block (0 or 1). + */ + static sptr make(float lo, float hi, float initial_state=0); + + virtual float lo () const = 0; + virtual void set_lo (float lo) = 0; + virtual float hi () const = 0; + virtual void set_hi (float hi) = 0; + virtual float last_state () const = 0; + virtual void set_last_state (float last_state) = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_THRESHOLD_FF_H */ diff --git a/gr-blocks/include/blocks/throttle.h b/gr-blocks/include/blocks/throttle.h new file mode 100644 index 000000000..20d8037e1 --- /dev/null +++ b/gr-blocks/include/blocks/throttle.h @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005-2011,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_THROTTLE_H +#define INCLUDED_GR_THROTTLE_H + +#include <blocks/api.h> +#include <gr_sync_block.h> + +namespace gr { + namespace blocks { + + /*! + * \brief throttle flow of samples such that the average rate does + * not exceed samples_per_sec. + * \ingroup misc_blk + * + * input: one stream of itemsize; output: one stream of itemsize + * + * N.B. this should only be used in GUI apps where there is no + * other rate limiting block. It is not intended nor effective at + * precisely controlling the rate of samples. That should be + * controlled by a source or sink tied to sample clock. E.g., a + * USRP or audio card. + */ + class BLOCKS_API throttle : virtual public gr_sync_block + { + public: + typedef boost::shared_ptr<throttle> sptr; + + static sptr make(size_t itemsize, double samples_per_sec); + + //! Sets the sample rate in samples per second. + virtual void set_sample_rate(double rate) = 0; + + //! Get the sample rate in samples per second. + virtual double sample_rate() const = 0; + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_THROTTLE_H */ diff --git a/gr-blocks/include/blocks/unpacked_to_packed_XX.h.t b/gr-blocks/include/blocks/unpacked_to_packed_XX.h.t new file mode 100644 index 000000000..749f0e00f --- /dev/null +++ b/gr-blocks/include/blocks/unpacked_to_packed_XX.h.t @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 <blocks/api.h> +#include <gr_block.h> +#include <gr_endianness.h> + +namespace gr { + namespace blocks { + + /*! + * \brief Convert a stream of unpacked bytes or shorts into a stream of packed bytes or shorts. + * \ingroup converter_blk + * + * input: stream of @I_TYPE@; output: stream of @O_TYPE@ + * + * This is the inverse of gr::blocks::packed_to_unpacked_XX. + * + * The low \p bits_per_chunk bits are extracted from each input + * byte or short. These bits are then packed densely into the + * output bytes or shorts, such that all 8 or 16 bits of the + * output bytes or shorts are filled with valid input bits. The + * right thing is done if bits_per_chunk is not a power of two. + * + * The combination of gr_packed_to_unpacked_XX followed by + * gr_chunks_to_symbols_Xf or gr_chunks_to_symbols_Xc handles the + * general case of mapping from a stream of bytes or shorts into + * arbitrary float or complex symbols. + * + * \sa gr::blocks::packed_to_unpacked_bb, gr::blocks::unpacked_to_packed_bb, + * \sa gr::blocks::packed_to_unpacked_ss, gr::blocks::unpacked_to_packed_ss, + * \sa gr::blocks::chunks_to_symbols_bf, gr::blocks::chunks_to_symbols_bc. + * \sa gr::blocks::chunks_to_symbols_sf, gr::blocks::chunks_to_symbols_sc. + */ + class BLOCKS_API @NAME@ : virtual public gr_block + { + public: + // gr::blocks::@NAME@::sptr + typedef boost::shared_ptr<@NAME@> sptr; + + static sptr make(unsigned int bits_per_chunk, + gr_endianness_t endianness); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME@ */ diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt index 560a55d57..e1b9b4f00 100644 --- a/gr-blocks/lib/CMakeLists.txt +++ b/gr-blocks/lib/CMakeLists.txt @@ -104,6 +104,8 @@ 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) +expand_cc_h_impl(packed_to_unpacked_XX bb ss ii) +expand_cc_h_impl(unpacked_to_packed_XX bb ss ii) ######################################################################## # Setup the include and linker paths @@ -139,6 +141,7 @@ list(APPEND gr_blocks_sources complex_to_arg_impl.cc conjugate_cc_impl.cc deinterleave_impl.cc + delay_impl.cc file_source_impl.cc file_meta_sink_impl.cc file_meta_source_impl.cc @@ -162,7 +165,11 @@ list(APPEND gr_blocks_sources multiply_const_ff_impl.cc nlog10_ff_impl.cc patterned_interleaver_impl.cc + peak_detector2_fb_impl.cc + regenerate_bb_impl.cc repeat_impl.cc + rms_cf_impl.cc + rms_ff_impl.cc short_to_char_impl.cc short_to_float_impl.cc stream_mux_impl.cc @@ -170,6 +177,9 @@ list(APPEND gr_blocks_sources stream_to_vector_impl.cc streams_to_stream_impl.cc streams_to_vector_impl.cc + stretch_ff_impl.cc + threshold_ff_impl.cc + throttle_impl.cc uchar_array_to_float.cc uchar_to_float_impl.cc vector_to_stream_impl.cc diff --git a/gr-blocks/lib/delay_impl.cc b/gr-blocks/lib/delay_impl.cc new file mode 100644 index 000000000..67449aca2 --- /dev/null +++ b/gr-blocks/lib/delay_impl.cc @@ -0,0 +1,141 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "delay_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + delay::sptr + delay::make(size_t itemsize, int delay) + { + return gnuradio::get_initial_sptr + (new delay_impl(itemsize, delay)); + } + + delay_impl::delay_impl(size_t itemsize, int delay) + : gr_block("delay", + gr_make_io_signature(1, -1, itemsize), + gr_make_io_signature(1, -1, itemsize)), + d_itemsize(itemsize) + { + set_dly(delay); + d_delta = 0; + } + + delay_impl::~delay_impl() + { + } + + void + delay_impl::forecast(int noutput_items, + gr_vector_int &ninput_items_required) + { + // make sure all inputs have noutput_items available + unsigned ninputs = ninput_items_required.size(); + for(unsigned i = 0; i < ninputs; i++) + ninput_items_required[i] = noutput_items; + } + + void + delay_impl::set_dly(int d) + { + // only set a new delta if there is a change in the delay; this + // protects from quickly-repeated calls to this function that + // would end with d_delta=0. + if(d != dly()) { + gruel::scoped_lock l(d_mutex_delay); + int old = dly(); + set_history(d+1); + d_delta += dly() - old; + } + } + + int + delay_impl::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + gruel::scoped_lock l(d_mutex_delay); + assert(input_items.size() == output_items.size()); + + const char *iptr; + char *optr; + int cons, ret; + + // No change in delay; just memcpy ins to outs + if(d_delta == 0) { + for(size_t i = 0; i < input_items.size(); i++) { + iptr = (const char *)input_items[i]; + optr = (char *)output_items[i]; + std::memcpy(optr, iptr, noutput_items*d_itemsize); + } + cons = noutput_items; + ret = noutput_items; + } + + // Skip over d_delta items on the input + else if(d_delta < 0) { + int n_to_copy, n_adj; + int delta = -d_delta; + n_to_copy = std::max(0, noutput_items-delta); + n_adj = std::min(delta, noutput_items); + for(size_t i = 0; i < input_items.size(); i++) { + iptr = (const char *) input_items[i]; + optr = (char *) output_items[i]; + std::memcpy(optr, iptr+delta*d_itemsize, n_to_copy*d_itemsize); + } + cons = noutput_items; + ret = n_to_copy; + delta -= n_adj; + d_delta = -delta; + } + + //produce but not consume (inserts zeros) + else { // d_delta > 0 + int n_from_input, n_padding; + n_from_input = std::max(0, noutput_items-d_delta); + n_padding = std::min(d_delta, noutput_items); + for(size_t i = 0; i < input_items.size(); i++) { + iptr = (const char *) input_items[i]; + optr = (char *) output_items[i]; + std::memset(optr, 0, n_padding*d_itemsize); + std::memcpy(optr, iptr, n_from_input*d_itemsize); + } + cons = n_from_input; + ret = noutput_items; + d_delta -= n_padding; + } + + consume_each(cons); + return ret; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/delay_impl.h b/gr-blocks/lib/delay_impl.h new file mode 100644 index 000000000..56d971b11 --- /dev/null +++ b/gr-blocks/lib/delay_impl.h @@ -0,0 +1,58 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_DELAY_IMPL_H +#define INCLUDED_GR_DELAY_IMPL_H + +#include <blocks/delay.h> +#include <gruel/thread.h> + +namespace gr { + namespace blocks { + + class delay_impl : public delay + { + private: + void forecast(int noutput_items, + gr_vector_int &ninput_items_required); + + size_t d_itemsize; + int d_delta; + gruel::mutex d_mutex_delay; + + public: + delay_impl(size_t itemsize, int delay); + ~delay_impl(); + + int dly() const { return history()-1; } + void set_dly(int d); + + 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_GR_DELAY_IMPL_H */ diff --git a/gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t b/gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t new file mode 100644 index 000000000..4f34d8347 --- /dev/null +++ b/gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t @@ -0,0 +1,147 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 <gr_io_signature.h> +#include <blocks/log2_const.h> +#include <assert.h> + +namespace gr { + namespace blocks { + + static const unsigned int BITS_PER_TYPE = sizeof(@I_TYPE@) * 8; + static const unsigned int LOG2_L_TYPE = log2_const<sizeof(@I_TYPE@) * 8>(); + + @NAME@::sptr + @NAME@::make(unsigned int bits_per_chunk, + gr_endianness_t endianness) + { + return gnuradio::get_initial_sptr + (new @NAME_IMPL@(bits_per_chunk, endianness)); + } + + @NAME_IMPL@::@NAME_IMPL@(unsigned int bits_per_chunk, + gr_endianness_t endianness) + : gr_block("@NAME@", + gr_make_io_signature(1, -1, sizeof(@I_TYPE@)), + gr_make_io_signature(1, -1, sizeof(@O_TYPE@))), + d_bits_per_chunk(bits_per_chunk), d_endianness(endianness), d_index(0) + { + assert(bits_per_chunk <= BITS_PER_TYPE); + assert(bits_per_chunk > 0); + + set_relative_rate((1.0 * BITS_PER_TYPE) / bits_per_chunk); + } + + @NAME_IMPL@::~@NAME_IMPL@() + { + } + + void + @NAME_IMPL@::forecast(int noutput_items, + gr_vector_int &ninput_items_required) + { + int input_required = (int)ceil((d_index + noutput_items * d_bits_per_chunk) + / (1.0 * BITS_PER_TYPE)); + unsigned ninputs = ninput_items_required.size(); + for(unsigned int i = 0; i < ninputs; i++) { + ninput_items_required[i] = input_required; + //printf("Forecast wants %d needs %d\n",noutput_items,ninput_items_required[i]); + } + } + + unsigned int + get_bit_le(const @I_TYPE@ *in_vector, unsigned int bit_addr) + { + @I_TYPE@ x = in_vector[bit_addr >> LOG2_L_TYPE]; + return (x >> (bit_addr & (BITS_PER_TYPE-1))) & 1; + } + + unsigned int + get_bit_be(const @I_TYPE@ *in_vector, unsigned int bit_addr) + { + @I_TYPE@ x = in_vector[bit_addr >> LOG2_L_TYPE]; + return (x >> ((BITS_PER_TYPE-1) - (bit_addr & (BITS_PER_TYPE-1)))) & 1; + } + + int + @NAME_IMPL@::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + unsigned int index_tmp = d_index; + + assert(input_items.size() == output_items.size()); + int nstreams = input_items.size(); + + for (int m=0; m < nstreams; m++){ + const @I_TYPE@ *in = (@I_TYPE@ *)input_items[m]; + @O_TYPE@ *out = (@O_TYPE@ *)output_items[m]; + index_tmp = d_index; + + // per stream processing + + switch(d_endianness) { + case GR_MSB_FIRST: + for(int i = 0; i < noutput_items; i++) { + //printf("here msb %d\n",i); + @O_TYPE@ x = 0; + for(unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++) + x = (x<<1) | get_bit_be(in, index_tmp); + out[i] = x; + } + break; + + case GR_LSB_FIRST: + for(int i = 0; i < noutput_items; i++) { + //printf("here lsb %d\n",i); + @O_TYPE@ x = 0; + for(unsigned int j = 0; j < d_bits_per_chunk; j++, index_tmp++) + x = (x<<1) | get_bit_le(in, index_tmp); + out[i] = x; + } + break; + + default: + assert(0); + } + + //printf("almost got to end\n"); + assert(ninput_items[m] >= (int)((d_index+(BITS_PER_TYPE-1)) >> LOG2_L_TYPE)); + } + + d_index = index_tmp; + consume_each(d_index >> LOG2_L_TYPE); + d_index = d_index & (BITS_PER_TYPE-1); + //printf("got to end\n"); + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/packed_to_unpacked_XX_impl.h.t b/gr-blocks/lib/packed_to_unpacked_XX_impl.h.t new file mode 100644 index 000000000..f83496fa7 --- /dev/null +++ b/gr-blocks/lib/packed_to_unpacked_XX_impl.h.t @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class @NAME_IMPL@ : public @NAME@ + { + private: + unsigned int d_bits_per_chunk; + gr_endianness_t d_endianness; + unsigned int d_index; + + public: + @NAME_IMPL@(unsigned int bits_per_chunk, + gr_endianness_t endianness); + ~@NAME_IMPL@(); + + void forecast(int noutput_items, + gr_vector_int &ninput_items_required); + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + bool check_topology(int ninputs, int noutputs) + { return ninputs == noutputs; } + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ diff --git a/gr-blocks/lib/peak_detector2_fb_impl.cc b/gr-blocks/lib/peak_detector2_fb_impl.cc new file mode 100644 index 000000000..0d375c3ba --- /dev/null +++ b/gr-blocks/lib/peak_detector2_fb_impl.cc @@ -0,0 +1,118 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "peak_detector2_fb_impl.h" +#include <gr_io_signature.h> +#include <string.h> + +namespace gr { + namespace blocks { + + peak_detector2_fb::sptr + peak_detector2_fb::make(float threshold_factor_rise, + int look_ahead, float alpha) + { + return gnuradio::get_initial_sptr + (new peak_detector2_fb_impl(threshold_factor_rise, + look_ahead, alpha)); + } + + peak_detector2_fb_impl::peak_detector2_fb_impl(float threshold_factor_rise, + int look_ahead, float alpha) + : gr_sync_block("peak_detector2_fb", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature2(1, 2, sizeof(char), sizeof(float))), + d_threshold_factor_rise(threshold_factor_rise), + d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false) + { + } + + peak_detector2_fb_impl::~peak_detector2_fb_impl() + { + } + + int + peak_detector2_fb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + float *iptr = (float *)input_items[0]; + char *optr = (char *)output_items[0]; + + assert(noutput_items >= 2); + + memset(optr, 0, noutput_items*sizeof(char)); + + for(int i = 0; i < noutput_items; i++) { + if(!d_found) { + // Have not yet detected presence of peak + if(iptr[i] > d_avg * (1.0f + d_threshold_factor_rise)) { + d_found = true; + d_look_ahead_remaining = d_look_ahead; + d_peak_val = -(float)INFINITY; + } + else { + d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg; + } + } + else { + // Detected presence of peak + if(iptr[i] > d_peak_val) { + d_peak_val = iptr[i]; + d_peak_ind = i; + } + else if(d_look_ahead_remaining <= 0) { + optr[d_peak_ind] = 1; + d_found = false; + d_avg = iptr[i]; + } + + // Have not yet located peak, loop and keep searching. + d_look_ahead_remaining--; + } + + // Every iteration of the loop, write debugging signal out if + // connected: + if(output_items.size() == 2) { + float *sigout = (float *)output_items[1]; + sigout[i] = d_avg; + } + } // loop + + if(!d_found) + return noutput_items; + + // else if detected presence, keep searching during the next call to work. + int tmp = d_peak_ind; + d_peak_ind = 1; + + return tmp - 1; + } + + } /* namespace blocks */ +} /* namespace gr */ + + diff --git a/gr-blocks/lib/peak_detector2_fb_impl.h b/gr-blocks/lib/peak_detector2_fb_impl.h new file mode 100644 index 000000000..f03dd36a8 --- /dev/null +++ b/gr-blocks/lib/peak_detector2_fb_impl.h @@ -0,0 +1,64 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_PEAK_DETECTOR2_FB_IMPL_H +#define INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H + +#include <blocks/peak_detector2_fb.h> + +namespace gr { + namespace blocks { + + class peak_detector2_fb_impl : public peak_detector2_fb + { + private: + float d_threshold_factor_rise; + int d_look_ahead; + int d_look_ahead_remaining; + int d_peak_ind; + float d_peak_val; + float d_alpha; + float d_avg; + bool d_found; + + public: + peak_detector2_fb_impl(float threshold_factor_rise, + int look_ahead, float alpha); + ~peak_detector2_fb_impl(); + + void set_threshold_factor_rise(float thr) { d_threshold_factor_rise = thr; } + void set_look_ahead(int look) { d_look_ahead = look; } + void set_alpha(int alpha) { d_alpha = alpha; } + + float threshold_factor_rise() { return d_threshold_factor_rise; } + int look_ahead() { return d_look_ahead; } + float alpha() { return d_alpha; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_PEAK_DETECTOR2_FB_IMPL_H */ diff --git a/gr-blocks/lib/regenerate_bb_impl.cc b/gr-blocks/lib/regenerate_bb_impl.cc new file mode 100644 index 000000000..4472efb6d --- /dev/null +++ b/gr-blocks/lib/regenerate_bb_impl.cc @@ -0,0 +1,103 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "regenerate_bb_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + regenerate_bb::sptr + regenerate_bb::make(int period, unsigned int max_regen) + { + return gnuradio::get_initial_sptr + (new regenerate_bb_impl(period, max_regen)); + } + + regenerate_bb_impl::regenerate_bb_impl(int period, unsigned int max_regen) + : gr_sync_block("regenerate_bb", + gr_make_io_signature(1, 1, sizeof(char)), + gr_make_io_signature(1, 1, sizeof(char))), + d_period(period), + d_countdown(0), + d_max_regen(max_regen), + d_regen_count(max_regen) + { + } + + regenerate_bb_impl::~regenerate_bb_impl() + { + } + + void + regenerate_bb_impl::set_max_regen(unsigned int regen) + { + d_max_regen = regen; + d_countdown = 0; + d_regen_count = d_max_regen; + } + + void + regenerate_bb_impl::set_period(int period) + { + d_period = period; + d_countdown = 0; + d_regen_count = d_max_regen; + } + + int + regenerate_bb_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const char *iptr = (const char *)input_items[0]; + char *optr = (char *)output_items[0]; + + for(int i = 0; i < noutput_items; i++) { + optr[i] = 0; + + if(d_regen_count < d_max_regen) { + d_countdown--; + + if(d_countdown == 0) { + optr[i] = 1; + d_countdown = d_period; + d_regen_count++; + } + } + + if(iptr[i] == 1) { + d_countdown = d_period; + optr[i] = 1; + d_regen_count = 0; + } + + } + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/regenerate_bb_impl.h b/gr-blocks/lib/regenerate_bb_impl.h new file mode 100644 index 000000000..bcfa18391 --- /dev/null +++ b/gr-blocks/lib/regenerate_bb_impl.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2007,2012-2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_REGENERATE_BB_H +#define INCLUDED_GR_REGENERATE_BB_IMPL_H + +#include <blocks/regenerate_bb.h> + +namespace gr { + namespace blocks { + + class regenerate_bb_impl : public regenerate_bb + { + private: + int d_period; + int d_countdown; + unsigned int d_max_regen; + unsigned int d_regen_count; + + public: + regenerate_bb_impl(int period, unsigned int max_regen=500); + ~regenerate_bb_impl(); + + void set_max_regen(unsigned int regen); + void set_period(int period); + + unsigned int max_regen() const { return d_max_regen; }; + int period() const { return d_period; }; + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_REGENERATE_BB_IMPL_H */ diff --git a/gr-blocks/lib/rms_cf_impl.cc b/gr-blocks/lib/rms_cf_impl.cc new file mode 100644 index 000000000..d956b45f1 --- /dev/null +++ b/gr-blocks/lib/rms_cf_impl.cc @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "rms_cf_impl.h" +#include <gr_io_signature.h> +#include <cmath> + +namespace gr { + namespace blocks { + + rms_cf::sptr + rms_cf::make(double alpha) + { + return gnuradio::get_initial_sptr + (new rms_cf_impl(alpha)); + } + + rms_cf_impl::rms_cf_impl (double alpha) + : gr_sync_block("rms_cf", + gr_make_io_signature(1, 1, sizeof(gr_complex)), + gr_make_io_signature(1, 1, sizeof(float))), + d_iir(alpha) + { + } + + rms_cf_impl::~rms_cf_impl() + { + } + + void + rms_cf_impl::set_alpha(double alpha) + { + d_iir.set_taps(alpha); + } + + int + rms_cf_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]; + + for(int i = 0; i < noutput_items; i++) { + double mag_sqrd = in[i].real()*in[i].real() + in[i].imag()*in[i].imag(); + double f = d_iir.filter(mag_sqrd); + out[i] = sqrt(f); + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/rms_cf_impl.h b/gr-blocks/lib/rms_cf_impl.h new file mode 100644 index 000000000..438b8549d --- /dev/null +++ b/gr-blocks/lib/rms_cf_impl.h @@ -0,0 +1,56 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_RMS_CF_IMPL_H +#define INCLUDED_BLOCKS_RMS_CF_IMPL_H + +#include <blocks/rms_cf.h> +#include <gr_single_pole_iir.h> + +namespace gr { + namespace blocks { + + /*! + * \brief RMS average power + * \ingroup math_blk + */ + class rms_cf_impl : public rms_cf + { + private: + gr_single_pole_iir<double,double,double> d_iir; + + public: + rms_cf_impl(double alpha = 0.0001); + ~rms_cf_impl(); + + void set_alpha(double alpha); + + 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_RMS_CF_IMPL_H */ diff --git a/gr-blocks/lib/rms_ff_impl.cc b/gr-blocks/lib/rms_ff_impl.cc new file mode 100644 index 000000000..2b8cdc34e --- /dev/null +++ b/gr-blocks/lib/rms_ff_impl.cc @@ -0,0 +1,77 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "rms_ff_impl.h" +#include <gr_io_signature.h> +#include <cmath> + +namespace gr { + namespace blocks { + + rms_ff::sptr + rms_ff::make(double alpha) + { + return gnuradio::get_initial_sptr + (new rms_ff_impl(alpha)); + } + + rms_ff_impl::rms_ff_impl(double alpha) + : gr_sync_block("rms_ff", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(1, 1, sizeof(float))), + d_iir(alpha) + { + } + + rms_ff_impl::~rms_ff_impl() + { + } + + void + rms_ff_impl::set_alpha(double alpha) + { + d_iir.set_taps(alpha); + } + + int + rms_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]; + + for(int i = 0; i < noutput_items; i++) { + double mag_sqrd = in[i]*in[i]; + double f = d_iir.filter(mag_sqrd); + out[i] = sqrt(f); + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/rms_ff_impl.h b/gr-blocks/lib/rms_ff_impl.h new file mode 100644 index 000000000..82ecbda52 --- /dev/null +++ b/gr-blocks/lib/rms_ff_impl.h @@ -0,0 +1,55 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_RMS_FF_IMPL_H +#define INCLUDED_BLOCKS_RMS_FF_IMPL_H + +#include <blocks/rms_ff.h> +#include <gr_single_pole_iir.h> + +namespace gr { + namespace blocks { + + /*! + * \brief RMS average power + * \ingroup math_blk + */ + class rms_ff_impl : public rms_ff + { + private: + gr_single_pole_iir<double,double,double> d_iir; + + public: + rms_ff_impl(double alpha = 0.0001); + ~rms_ff_impl(); + + void set_alpha(double alpha); + + 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_RMS_FF_IMPL_H */ diff --git a/gr-blocks/lib/stretch_ff_impl.cc b/gr-blocks/lib/stretch_ff_impl.cc new file mode 100644 index 000000000..90bbc7ee5 --- /dev/null +++ b/gr-blocks/lib/stretch_ff_impl.cc @@ -0,0 +1,84 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "stretch_ff_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + stretch_ff::sptr + stretch_ff::make(float lo, size_t vlen) + { + return gnuradio::get_initial_sptr + (new stretch_ff_impl(lo, vlen)); + } + + stretch_ff_impl::stretch_ff_impl(float lo, size_t vlen) + : gr_sync_block("stretch_ff", + gr_make_io_signature(1, 1, vlen * sizeof(float)), + gr_make_io_signature(1, 1, vlen * sizeof(float))), + d_lo(lo), d_vlen(vlen) + { + } + + stretch_ff_impl::~stretch_ff_impl() + { + } + + int + stretch_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]; + + for(int count = 0; count < noutput_items; count++) { + float vmax = in[0] - d_lo; + + for(unsigned int i = 1; i < d_vlen; i++) { + float vtmp = in[i] - d_lo; + if(vtmp > vmax) + vmax = vtmp; + } + + if(vmax != 0.0) + for(unsigned int i = 0; i < d_vlen; i++) + out[i] = d_lo * (1.0 - (in[i] - d_lo) / vmax); + else + for(unsigned int i = 0; i < d_vlen; i++) + out[i] = in[i]; + + in += d_vlen; + out += d_vlen; + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/stretch_ff_impl.h b/gr-blocks/lib/stretch_ff_impl.h new file mode 100644 index 000000000..af69d835a --- /dev/null +++ b/gr-blocks/lib/stretch_ff_impl.h @@ -0,0 +1,53 @@ +/* -*- c++ -*- */ +/* + * Copyright 2008,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_STRETCH_FF_IMPL_H +#define INCLUDED_GR_STRETCH_FF_IMPL_H + +#include <blocks/stretch_ff.h> + +namespace gr { + namespace blocks { + + class stretch_ff_impl : public stretch_ff + { + private: + float d_lo; // the constant + size_t d_vlen; + + public: + stretch_ff_impl(float lo, size_t vlen); + ~stretch_ff_impl(); + + float lo() const { return d_lo; } + void set_lo(float lo) { d_lo = lo; } + size_t vlen() const { return d_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_GR_STRETCH_FF_IMPL_H */ diff --git a/gr-blocks/lib/threshold_ff_impl.cc b/gr-blocks/lib/threshold_ff_impl.cc new file mode 100644 index 000000000..477f2b1c8 --- /dev/null +++ b/gr-blocks/lib/threshold_ff_impl.cc @@ -0,0 +1,78 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2010,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 "threshold_ff_impl.h" +#include <gr_io_signature.h> + +namespace gr { + namespace blocks { + + threshold_ff::sptr + threshold_ff::make(float lo, float hi, float initial_state) + { + return gnuradio::get_initial_sptr + (new threshold_ff_impl(lo, hi, initial_state)); + } + + threshold_ff_impl::threshold_ff_impl(float lo, float hi, + float initial_state) + : gr_sync_block("threshold_ff", + gr_make_io_signature(1, 1, sizeof(float)), + gr_make_io_signature(1, 1, sizeof(float))), + d_lo(lo), d_hi(hi), d_last_state(initial_state) + { + } + + threshold_ff_impl::~threshold_ff_impl() + { + } + + int + threshold_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]; + + for(int i = 0; i < noutput_items; i++) { + if(in[i] > d_hi) { + out[i] = 1.0; + d_last_state = 1.0; + } + else if(in[i] < d_lo) { + out[i] = 0.0; + d_last_state = 0.0; + } + else + out[i] = d_last_state; + } + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/threshold_ff_impl.h b/gr-blocks/lib/threshold_ff_impl.h new file mode 100644 index 000000000..41afaa52a --- /dev/null +++ b/gr-blocks/lib/threshold_ff_impl.h @@ -0,0 +1,57 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_THRESHOLD_FF_IMPL_H +#define INCLUDED_GR_THRESHOLD_FF_IMPL_H + +#include <blocks/threshold_ff.h> + +namespace gr { + namespace blocks { + + class threshold_ff_impl : public threshold_ff + { + private: + float d_lo, d_hi; // the constant + float d_last_state; + + public: + threshold_ff_impl(float lo, float hi, + float initial_state=0); + ~threshold_ff_impl(); + + float lo() const { return d_lo; } + void set_lo(float lo) { d_lo = lo; } + float hi() const { return d_hi; } + void set_hi(float hi) { d_hi = hi; } + float last_state() const { return d_last_state; } + void set_last_state(float last_state) { d_last_state = last_state; } + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_THRESHOLD_FF_IMPL_H */ diff --git a/gr-blocks/lib/throttle_impl.cc b/gr-blocks/lib/throttle_impl.cc new file mode 100644 index 000000000..49743e3f2 --- /dev/null +++ b/gr-blocks/lib/throttle_impl.cc @@ -0,0 +1,97 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005-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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "throttle_impl.h" +#include <gr_io_signature.h> +#include <cstring> +#include <boost/thread/thread.hpp> + +namespace gr { + namespace blocks { + + throttle::sptr + throttle::make(size_t itemsize, double samples_per_sec) + { + return gnuradio::get_initial_sptr + (new throttle_impl(itemsize, samples_per_sec)); + } + + throttle_impl::throttle_impl(size_t itemsize, + double samples_per_second) + : gr_sync_block("throttle", + gr_make_io_signature(1, 1, itemsize), + gr_make_io_signature(1, 1, itemsize)), + d_itemsize(itemsize) + { + set_sample_rate(samples_per_second); + } + + throttle_impl::~throttle_impl() + { + } + + void + throttle_impl::set_sample_rate(double rate) + { + //changing the sample rate performs a reset of state params + d_start = boost::get_system_time(); + d_total_samples = 0; + d_samps_per_tick = rate/boost::posix_time::time_duration::ticks_per_second(); + d_samps_per_us = rate/1e6; + } + + double + throttle_impl::sample_rate() const + { + return d_samps_per_us * 1e6; + } + + int + throttle_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + //calculate the expected number of samples to have passed through + boost::system_time now = boost::get_system_time(); + boost::int64_t ticks = (now - d_start).ticks(); + uint64_t expected_samps = uint64_t(d_samps_per_tick*ticks); + + //if the expected samples was less, we need to throttle back + if(d_total_samples > expected_samps) { + boost::this_thread::sleep(boost::posix_time::microseconds + (long((d_total_samples - expected_samps)/d_samps_per_us))); + } + + //copy all samples output[i] <= input[i] + const char *in = (const char *)input_items[0]; + char *out = (char *)output_items[0]; + std::memcpy(out, in, noutput_items * d_itemsize); + d_total_samples += noutput_items; + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/throttle_impl.h b/gr-blocks/lib/throttle_impl.h new file mode 100644 index 000000000..86dbef2ac --- /dev/null +++ b/gr-blocks/lib/throttle_impl.h @@ -0,0 +1,54 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005-2011,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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_THROTTLE_IMPL_H +#define INCLUDED_GR_THROTTLE_IMPL_H + +#include <blocks/throttle.h> + +namespace gr { + namespace blocks { + + class throttle_impl : public throttle + { + private: + boost::system_time d_start; + size_t d_itemsize; + uint64_t d_total_samples; + double d_samps_per_tick, d_samps_per_us; + + public: + throttle_impl(size_t itemsize, double samples_per_sec); + ~throttle_impl(); + + void set_sample_rate(double rate); + double sample_rate() const; + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* INCLUDED_GR_THROTTLE_IMPL_H */ diff --git a/gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t b/gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t new file mode 100644 index 000000000..3a7428fd8 --- /dev/null +++ b/gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t @@ -0,0 +1,143 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 <gr_io_signature.h> +#include <assert.h> + +namespace gr { + namespace blocks { + + static const unsigned int BITS_PER_TYPE = sizeof(@O_TYPE@) * 8; + + @NAME@::sptr + @NAME@::make(unsigned int bits_per_chunk, + gr_endianness_t endianness) + { + return gnuradio::get_initial_sptr + (new @NAME_IMPL@(bits_per_chunk, endianness)); + } + + @NAME_IMPL@::@NAME_IMPL@(unsigned int bits_per_chunk, + gr_endianness_t endianness) + : gr_block("@NAME@", + gr_make_io_signature(1, -1, sizeof(@I_TYPE@)), + gr_make_io_signature(1, -1, sizeof(@O_TYPE@))), + d_bits_per_chunk(bits_per_chunk), d_endianness(endianness), d_index(0) + { + assert(bits_per_chunk <= BITS_PER_TYPE); + assert(bits_per_chunk > 0); + + set_relative_rate(bits_per_chunk/(1.0 * BITS_PER_TYPE)); + } + + @NAME_IMPL@::~@NAME_IMPL@() + { + } + + void + @NAME_IMPL@::forecast(int noutput_items, + gr_vector_int &ninput_items_required) + { + int input_required = (int)ceil((d_index+noutput_items * 1.0 * BITS_PER_TYPE) + / d_bits_per_chunk); + unsigned ninputs = ninput_items_required.size(); + for(unsigned int i = 0; i < ninputs; i++) { + ninput_items_required[i] = input_required; + } + } + + unsigned int + get_bit_be1(const @I_TYPE@ *in_vector, unsigned int bit_addr, + unsigned int bits_per_chunk) + { + unsigned int byte_addr = (int)bit_addr/bits_per_chunk; + @I_TYPE@ x = in_vector[byte_addr]; + unsigned int residue = bit_addr - byte_addr * bits_per_chunk; + //printf("Bit addr %d byte addr %d residue %d val %d\n",bit_addr,byte_addr,residue,(x>>(bits_per_chunk-1-residue))&1); + return (x >> (bits_per_chunk-1-residue)) & 1; + } + + int + @NAME_IMPL@::general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + unsigned int index_tmp = d_index; + + assert(input_items.size() == output_items.size()); + int nstreams = input_items.size(); + + for(int m=0; m< nstreams; m++) { + const @I_TYPE@ *in = (@I_TYPE@ *)input_items[m]; + @O_TYPE@ *out = (@O_TYPE@ *)output_items[m]; + index_tmp=d_index; + + // per stream processing + + //assert((ninput_items[m]-d_index)*d_bits_per_chunk >= noutput_items*BITS_PER_TYPE); + + switch(d_endianness) { + + case GR_MSB_FIRST: + for(int i = 0; i < noutput_items; i++) { + @O_TYPE@ tmp=0; + for(unsigned int j = 0; j < BITS_PER_TYPE; j++) { + tmp = (tmp<<1) | get_bit_be1(in, index_tmp, d_bits_per_chunk); + index_tmp++; + } + out[i] = tmp; + } + break; + + case GR_LSB_FIRST: + for(int i = 0; i < noutput_items; i++) { + unsigned long tmp=0; + for(unsigned int j = 0; j < BITS_PER_TYPE; j++) { + tmp = (tmp>>1) | (get_bit_be1(in, index_tmp, d_bits_per_chunk) << (BITS_PER_TYPE-1)); + index_tmp++; + } + out[i] = tmp; + } + break; + + default: + assert(0); + } + } + + d_index = index_tmp; + consume_each((int)(d_index/d_bits_per_chunk)); + d_index = d_index%d_bits_per_chunk; + + return noutput_items; + } + + } /* namespace blocks */ +} /* namespace gr */ diff --git a/gr-blocks/lib/unpacked_to_packed_XX_impl.h.t b/gr-blocks/lib/unpacked_to_packed_XX_impl.h.t new file mode 100644 index 000000000..c8f414c55 --- /dev/null +++ b/gr-blocks/lib/unpacked_to_packed_XX_impl.h.t @@ -0,0 +1,59 @@ +/* -*- c++ -*- */ +/* + * Copyright 2006.2013 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along 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 <blocks/@NAME@.h> + +namespace gr { + namespace blocks { + + class @NAME_IMPL@ : public @NAME@ + { + private: + unsigned int d_bits_per_chunk; + gr_endianness_t d_endianness; + unsigned int d_index; + + public: + @NAME_IMPL@(unsigned int bits_per_chunk, + gr_endianness_t endianness); + ~@NAME_IMPL@(); + + void forecast(int noutput_items, + gr_vector_int &ninput_items_required); + int general_work(int noutput_items, + gr_vector_int &ninput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + bool check_topology(int ninputs, int noutputs) + { return ninputs == noutputs; } + }; + + } /* namespace blocks */ +} /* namespace gr */ + +#endif /* @GUARD_NAME_IMPL@ */ diff --git a/gr-blocks/python/qa_delay.py b/gr-blocks/python/qa_delay.py new file mode 100755 index 000000000..031cadb2d --- /dev/null +++ b/gr-blocks/python/qa_delay.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# +# Copyright 2004,2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_delay(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_000(self): + delta_t = 0 + tb = self.tb + src_data = [float(x) for x in range(0, 100)] + expected_result = tuple(delta_t*[0.0] + src_data) + + src = gr.vector_source_f(src_data) + op = blocks.delay(gr.sizeof_float, delta_t) + dst = gr.vector_sink_f() + + tb.connect(src, op, dst) + tb.run() + dst_data = dst.data() + self.assertEqual(expected_result, dst_data) + + def test_010(self): + delta_t = 10 + tb = self.tb + src_data = [float(x) for x in range(0, 100)] + expected_result = tuple(delta_t*[0.0] + src_data) + + src = gr.vector_source_f(src_data) + op = blocks.delay(gr.sizeof_float, delta_t) + dst = gr.vector_sink_f() + + tb.connect(src, op, dst) + tb.run() + dst_data = dst.data() + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_delay, "test_delay.xml") diff --git a/gr-blocks/python/qa_file_metadata.py b/gr-blocks/python/qa_file_metadata.py index 29ed0d1c8..c7826b1d3 100644 --- a/gr-blocks/python/qa_file_metadata.py +++ b/gr-blocks/python/qa_file_metadata.py @@ -28,8 +28,8 @@ import os, math def sig_source_c(samp_rate, freq, amp, N): t = map(lambda x: float(x)/samp_rate, xrange(N)) - y = map(lambda x: math.cos(2.*math.pi*freq*x) + \ - 1j*math.sin(2.*math.pi*freq*x), t) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \ + 1j*amp*math.sin(2.*math.pi*freq*x), t) return y class test_file_metadata(gr_unittest.TestCase): diff --git a/gr-blocks/python/qa_packed_to_unpacked.py b/gr-blocks/python/qa_packed_to_unpacked.py new file mode 100755 index 000000000..d84f5dbd3 --- /dev/null +++ b/gr-blocks/python/qa_packed_to_unpacked.py @@ -0,0 +1,344 @@ +#!/usr/bin/env python +# +# Copyright 2005,2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import random + +class test_packing(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block () + + def tearDown(self): + self.tb = None + + def test_001(self): + src_data = (0x80,) + expected_results = (1,0,0,0,0,0,0,0) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_002(self): + src_data = (0x80,) + expected_results = (0,0,0,0,0,0,0,1) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_003(self): + src_data = (0x11,) + expected_results = (4, 2) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(3, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_004(self): + src_data = (0x11,) + expected_results = (0, 4) + src = gr.vector_source_b(src_data, False) + op = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_005(self): + src_data = (1,0,0,0,0,0,1,0,0,1,0,1,1,0,1,0) + expected_results = (0x82, 0x5a) + src = gr.vector_source_b(src_data, False) + op = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_006(self): + src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0) + expected_results = (0x82, 0x5a) + src = gr.vector_source_b(src_data, False) + op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_007(self): + src_data = (4, 2, 0,0,0) + expected_results = (0x11,) + src = gr.vector_source_b(src_data, False) + op = blocks.unpacked_to_packed_bb(3, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_008(self): + src_data = (0, 4, 2,0,0) + expected_results = (0x11,) + src = gr.vector_source_b(src_data,False) + op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op) + self.tb.connect(op, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_009(self): + random.seed(0) + src_data = [] + for i in xrange(202): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + + src = gr.vector_source_b(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_bb(3, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + def test_010(self): + random.seed(0) + src_data = [] + for i in xrange(56): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_b(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_bb(7, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(7, gr.GR_MSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + def test_011(self): + random.seed(0) + src_data = [] + for i in xrange(56): + src_data.append((random.randint(0,255))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_b(tuple(src_data),False) + op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST) + dst = gr.vector_sink_b() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results[0:201], dst.data()) + + + # tests on shorts + def test_100a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(1, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_100b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(1, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_101a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(8, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(8, gr.GR_MSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_101b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**15,2**15-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_s(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST) + dst = gr.vector_sink_s() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + + # tests on ints + def test_200a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(1, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(1, gr.GR_MSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_200b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(1, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(1, gr.GR_LSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_201a(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(8, gr.GR_MSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(8, gr.GR_MSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + + def test_201b(self): + random.seed(0) + src_data = [] + for i in xrange(100): + src_data.append((random.randint(-2**31,2**31-1))) + src_data = tuple(src_data) + expected_results = src_data + src = gr.vector_source_i(tuple(src_data), False) + op1 = blocks.packed_to_unpacked_ii(8, gr.GR_LSB_FIRST) + op2 = blocks.unpacked_to_packed_ii(8, gr.GR_LSB_FIRST) + dst = gr.vector_sink_i() + + self.tb.connect(src, op1, op2) + self.tb.connect(op2, dst) + self.tb.run() + + self.assertEqual(expected_results, dst.data()) + +if __name__ == '__main__': + gr_unittest.run(test_packing, "test_packing.xml") + diff --git a/gr-blocks/python/qa_peak_detector2.py b/gr-blocks/python/qa_peak_detector2.py new file mode 100644 index 000000000..4b864e4d7 --- /dev/null +++ b/gr-blocks/python/qa_peak_detector2.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_peak_detector2(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, + 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + + expected_result = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + + src = gr.vector_source_f(data, False) + regen = blocks.peak_detector2_fb() + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + print dst_data + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_peak_detector2, "test_peak_detector2.xml") diff --git a/gr-blocks/python/qa_regenerate.py b/gr-blocks/python/qa_regenerate.py new file mode 100755 index 000000000..a57eeba2b --- /dev/null +++ b/gr-blocks/python/qa_regenerate.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python +# +# Copyright 2007,2010,2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_regenerate(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_regen1(self): + tb = self.tb + + data = [0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] + + expected_result = (0, 0, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) + + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(5, 2) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + + def test_regen2(self): + tb = self.tb + + data = 200*[0,] + data[9] = 1 + data[99] = 1 + + expected_result = 200*[0,] + expected_result[9] = 1 + expected_result[19] = 1 + expected_result[29] = 1 + expected_result[39] = 1 + + expected_result[99] = 1 + expected_result[109] = 1 + expected_result[119] = 1 + expected_result[129] = 1 + + src = gr.vector_source_b(data, False) + regen = blocks.regenerate_bb(10, 3) + dst = gr.vector_sink_b() + + tb.connect(src, regen) + tb.connect(regen, dst) + tb.run () + + dst_data = dst.data() + + self.assertEqual(tuple(expected_result), dst_data) + + +if __name__ == '__main__': + gr_unittest.run(test_regenerate, "test_regenerate.xml") diff --git a/gr-blocks/python/qa_rms.py b/gr-blocks/python/qa_rms.py new file mode 100644 index 000000000..f3386668a --- /dev/null +++ b/gr-blocks/python/qa_rms.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks +import math + +def sig_source_f(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x), t) + return y + +def sig_source_c(samp_rate, freq, amp, N): + t = map(lambda x: float(x)/samp_rate, xrange(N)) + y = map(lambda x: amp*math.cos(2.*math.pi*freq*x) + \ + 1j*amp*math.sin(2.*math.pi*freq*x), t) + return y + +class test_rms(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_ff(self): + amp = 2 + src_data = sig_source_f(1, 0.01, amp, 200) + N = 750000 + + expected_data = amp/math.sqrt(2.0) + + src = gr.vector_source_f(src_data, True) + head = gr.head(gr.sizeof_float, N) + op = blocks.rms_ff(0.0001) + dst = gr.vector_sink_f() + + self.tb.connect(src, head, op, dst) + self.tb.run() + + dst_data = dst.data() + self.assertAlmostEqual(dst_data[-1], expected_data, 4) + + def test_cf(self): + amp = 4 + src_data = sig_source_c(1, 0.01, amp, 200) + N = 750000 + + expected_data = amp + + src = gr.vector_source_c(src_data, True) + head = gr.head(gr.sizeof_gr_complex, N) + op = blocks.rms_cf(0.0001) + dst = gr.vector_sink_f() + + self.tb.connect(src, head, op, dst) + self.tb.run() + + dst_data = dst.data() + self.assertAlmostEqual(dst_data[-1], expected_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_rms, "test_rms.xml") diff --git a/gr-blocks/python/qa_stretch.py b/gr-blocks/python/qa_stretch.py new file mode 100755 index 000000000..013d878a8 --- /dev/null +++ b/gr-blocks/python/qa_stretch.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_stretch(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_stretch_01(self): + tb = self.tb + + data = 10*[1,] + data0 = map(lambda x: x/20.0, data) + data1 = map(lambda x: x/10.0, data) + + expected_result0 = 10*[0.05,] + expected_result1 = 10*[0.1,] + + src0 = gr.vector_source_f(data0, False) + src1 = gr.vector_source_f(data1, False) + inter = gr.streams_to_vector(gr.sizeof_float, 2) + op = blocks.stretch_ff(0.1, 2) + deinter = gr.vector_to_streams(gr.sizeof_float, 2) + dst0 = gr.vector_sink_f() + dst1 = gr.vector_sink_f() + + tb.connect(src0, (inter,0)) + tb.connect(src1, (inter,1)) + tb.connect(inter, op) + tb.connect(op, deinter) + tb.connect((deinter,0), dst0) + tb.connect((deinter,1), dst1) + tb.run() + + dst0_data = dst0.data() + dst1_data = dst1.data() + + self.assertFloatTuplesAlmostEqual(expected_result0, dst0_data, 4) + self.assertFloatTuplesAlmostEqual(expected_result1, dst1_data, 4) + +if __name__ == '__main__': + gr_unittest.run(test_stretch, "test_stretch.xml") diff --git a/gr-blocks/python/qa_threshold.py b/gr-blocks/python/qa_threshold.py new file mode 100644 index 000000000..f91af739a --- /dev/null +++ b/gr-blocks/python/qa_threshold.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_threshold(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + tb = self.tb + + data = [0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2] + + expected_result = (0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1) + + src = gr.vector_source_f(data, False) + op = blocks.threshold_ff(1, 1) + dst = gr.vector_sink_f() + + tb.connect(src, op) + tb.connect(op, dst) + tb.run() + + dst_data = dst.data() + + self.assertEqual(expected_result, dst_data) + +if __name__ == '__main__': + gr_unittest.run(test_threshold, "test_threshold.xml") diff --git a/gr-blocks/python/qa_throttle.py b/gr-blocks/python/qa_throttle.py new file mode 100755 index 000000000..5d462f2c9 --- /dev/null +++ b/gr-blocks/python/qa_throttle.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# +# Copyright 2013 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr, gr_unittest +import blocks_swig as blocks + +class test_throttle(gr_unittest.TestCase): + + def setUp(self): + self.tb = gr.top_block() + + def tearDown(self): + self.tb = None + + def test_01(self): + # Test that we can make the block + op = blocks.throttle(gr.sizeof_gr_complex, 1) + +if __name__ == '__main__': + gr_unittest.run(test_throttle, "test_throttle.xml") diff --git a/gr-blocks/swig/blocks_swig.i b/gr-blocks/swig/blocks_swig.i index 53eea818f..6407421b1 100644 --- a/gr-blocks/swig/blocks_swig.i +++ b/gr-blocks/swig/blocks_swig.i @@ -1,6 +1,6 @@ /* -*- c++ -*- */ /* - * Copyright 2012 Free Software Foundation, Inc. + * Copyright 2012-2013 Free Software Foundation, Inc. * * This file is part of GNU Radio * @@ -27,6 +27,8 @@ //load generated python docstrings %include "blocks_swig_doc.i" +%include <gr_endianness.h> + %{ #include "blocks/add_ff.h" #include "blocks/add_ss.h" @@ -57,6 +59,7 @@ #include "blocks/complex_to_arg.h" #include "blocks/conjugate_cc.h" #include "blocks/deinterleave.h" +#include "blocks/delay.h" #include "blocks/divide_ff.h" #include "blocks/divide_ss.h" #include "blocks/divide_ii.h" @@ -96,10 +99,17 @@ #include "blocks/not_ss.h" #include "blocks/not_ii.h" #include "blocks/patterned_interleaver.h" +#include "blocks/packed_to_unpacked_bb.h" +#include "blocks/packed_to_unpacked_ss.h" +#include "blocks/packed_to_unpacked_ii.h" +#include "blocks/peak_detector2_fb.h" #include "blocks/or_bb.h" #include "blocks/or_ss.h" #include "blocks/or_ii.h" +#include "blocks/regenerate_bb.h" #include "blocks/repeat.h" +#include "blocks/rms_cf.h" +#include "blocks/rms_ff.h" #include "blocks/short_to_char.h" #include "blocks/short_to_float.h" #include "blocks/stream_mux.h" @@ -107,11 +117,17 @@ #include "blocks/stream_to_vector.h" #include "blocks/streams_to_stream.h" #include "blocks/streams_to_vector.h" +#include "blocks/stretch_ff.h" #include "blocks/sub_ff.h" #include "blocks/sub_ss.h" #include "blocks/sub_ii.h" #include "blocks/sub_cc.h" +#include "blocks/threshold_ff.h" +#include "blocks/throttle.h" #include "blocks/uchar_to_float.h" +#include "blocks/unpacked_to_packed_bb.h" +#include "blocks/unpacked_to_packed_ss.h" +#include "blocks/unpacked_to_packed_ii.h" #include "blocks/vector_to_stream.h" #include "blocks/vector_to_streams.h" #include "blocks/xor_bb.h" @@ -148,6 +164,7 @@ %include "blocks/complex_to_arg.h" %include "blocks/conjugate_cc.h" %include "blocks/deinterleave.h" +%include "blocks/delay.h" %include "blocks/file_source.h" %include "blocks/file_meta_sink.h" %include "blocks/file_meta_source.h" @@ -187,10 +204,17 @@ %include "blocks/not_ss.h" %include "blocks/not_ii.h" %include "blocks/patterned_interleaver.h" +%include "blocks/packed_to_unpacked_bb.h" +%include "blocks/packed_to_unpacked_ss.h" +%include "blocks/packed_to_unpacked_ii.h" +%include "blocks/peak_detector2_fb.h" %include "blocks/or_bb.h" %include "blocks/or_ss.h" %include "blocks/or_ii.h" +%include "blocks/regenerate_bb.h" %include "blocks/repeat.h" +%include "blocks/rms_cf.h" +%include "blocks/rms_ff.h" %include "blocks/short_to_char.h" %include "blocks/short_to_float.h" %include "blocks/stream_mux.h" @@ -198,11 +222,17 @@ %include "blocks/stream_to_vector.h" %include "blocks/streams_to_stream.h" %include "blocks/streams_to_vector.h" +%include "blocks/stretch_ff.h" %include "blocks/sub_ff.h" %include "blocks/sub_ss.h" %include "blocks/sub_ii.h" %include "blocks/sub_cc.h" +%include "blocks/threshold_ff.h" +%include "blocks/throttle.h" %include "blocks/uchar_to_float.h" +%include "blocks/unpacked_to_packed_bb.h" +%include "blocks/unpacked_to_packed_ss.h" +%include "blocks/unpacked_to_packed_ii.h" %include "blocks/vector_to_stream.h" %include "blocks/vector_to_streams.h" %include "blocks/xor_bb.h" @@ -238,6 +268,7 @@ GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_mag_squared); GR_SWIG_BLOCK_MAGIC2(blocks, complex_to_arg); GR_SWIG_BLOCK_MAGIC2(blocks, conjugate_cc); GR_SWIG_BLOCK_MAGIC2(blocks, deinterleave); +GR_SWIG_BLOCK_MAGIC2(blocks, delay); GR_SWIG_BLOCK_MAGIC2(blocks, divide_ff); GR_SWIG_BLOCK_MAGIC2(blocks, divide_ss); GR_SWIG_BLOCK_MAGIC2(blocks, divide_ii); @@ -277,10 +308,17 @@ GR_SWIG_BLOCK_MAGIC2(blocks, not_bb); GR_SWIG_BLOCK_MAGIC2(blocks, not_ss); GR_SWIG_BLOCK_MAGIC2(blocks, not_ii); GR_SWIG_BLOCK_MAGIC2(blocks, patterned_interleaver); +GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_bb); +GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ss); +GR_SWIG_BLOCK_MAGIC2(blocks, packed_to_unpacked_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, peak_detector2_fb); GR_SWIG_BLOCK_MAGIC2(blocks, or_bb); GR_SWIG_BLOCK_MAGIC2(blocks, or_ss); GR_SWIG_BLOCK_MAGIC2(blocks, or_ii); +GR_SWIG_BLOCK_MAGIC2(blocks, regenerate_bb); GR_SWIG_BLOCK_MAGIC2(blocks, repeat); +GR_SWIG_BLOCK_MAGIC2(blocks, rms_cf); +GR_SWIG_BLOCK_MAGIC2(blocks, rms_ff); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_char); GR_SWIG_BLOCK_MAGIC2(blocks, short_to_float); GR_SWIG_BLOCK_MAGIC2(blocks, stream_mux); @@ -288,11 +326,17 @@ GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_streams); GR_SWIG_BLOCK_MAGIC2(blocks, stream_to_vector); GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_stream); GR_SWIG_BLOCK_MAGIC2(blocks, streams_to_vector); +GR_SWIG_BLOCK_MAGIC2(blocks, stretch_ff); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ff); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ss); GR_SWIG_BLOCK_MAGIC2(blocks, sub_ii); GR_SWIG_BLOCK_MAGIC2(blocks, sub_cc); +GR_SWIG_BLOCK_MAGIC2(blocks, threshold_ff); +GR_SWIG_BLOCK_MAGIC2(blocks, throttle); GR_SWIG_BLOCK_MAGIC2(blocks, uchar_to_float); +GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_bb); +GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ss); +GR_SWIG_BLOCK_MAGIC2(blocks, unpacked_to_packed_ii); GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_stream); GR_SWIG_BLOCK_MAGIC2(blocks, vector_to_streams); GR_SWIG_BLOCK_MAGIC2(blocks, xor_bb); |