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/lib | |
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/lib')
-rw-r--r-- | gr-blocks/lib/CMakeLists.txt | 10 | ||||
-rw-r--r-- | gr-blocks/lib/delay_impl.cc | 141 | ||||
-rw-r--r-- | gr-blocks/lib/delay_impl.h | 58 | ||||
-rw-r--r-- | gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t | 147 | ||||
-rw-r--r-- | gr-blocks/lib/packed_to_unpacked_XX_impl.h.t | 59 | ||||
-rw-r--r-- | gr-blocks/lib/peak_detector2_fb_impl.cc | 118 | ||||
-rw-r--r-- | gr-blocks/lib/peak_detector2_fb_impl.h | 64 | ||||
-rw-r--r-- | gr-blocks/lib/regenerate_bb_impl.cc | 103 | ||||
-rw-r--r-- | gr-blocks/lib/regenerate_bb_impl.h | 57 | ||||
-rw-r--r-- | gr-blocks/lib/rms_cf_impl.cc | 77 | ||||
-rw-r--r-- | gr-blocks/lib/rms_cf_impl.h | 56 | ||||
-rw-r--r-- | gr-blocks/lib/rms_ff_impl.cc | 77 | ||||
-rw-r--r-- | gr-blocks/lib/rms_ff_impl.h | 55 | ||||
-rw-r--r-- | gr-blocks/lib/stretch_ff_impl.cc | 84 | ||||
-rw-r--r-- | gr-blocks/lib/stretch_ff_impl.h | 53 | ||||
-rw-r--r-- | gr-blocks/lib/threshold_ff_impl.cc | 78 | ||||
-rw-r--r-- | gr-blocks/lib/threshold_ff_impl.h | 57 | ||||
-rw-r--r-- | gr-blocks/lib/throttle_impl.cc | 97 | ||||
-rw-r--r-- | gr-blocks/lib/throttle_impl.h | 54 | ||||
-rw-r--r-- | gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t | 143 | ||||
-rw-r--r-- | gr-blocks/lib/unpacked_to_packed_XX_impl.h.t | 59 |
21 files changed, 1647 insertions, 0 deletions
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@ */ |