summaryrefslogtreecommitdiff
path: root/gr-blocks/lib
diff options
context:
space:
mode:
authorTom Rondeau2013-02-21 18:24:02 -0500
committerTom Rondeau2013-02-21 18:24:02 -0500
commitf42ef36d60348965936ede158886c1847670f774 (patch)
tree5ad8364c11c7b8f9444a939b92322c5179fd5ab5 /gr-blocks/lib
parent61b90a54cd5b5d452585669498ad2bf692b6e543 (diff)
downloadgnuradio-f42ef36d60348965936ede158886c1847670f774.tar.gz
gnuradio-f42ef36d60348965936ede158886c1847670f774.tar.bz2
gnuradio-f42ef36d60348965936ede158886c1847670f774.zip
blocks: converting blocks to v3.7 style in gr-blocks.
delay, rms, unpacked_to_packed, packed_to_unpacked
Diffstat (limited to 'gr-blocks/lib')
-rw-r--r--gr-blocks/lib/CMakeLists.txt5
-rw-r--r--gr-blocks/lib/delay_impl.cc141
-rw-r--r--gr-blocks/lib/delay_impl.h58
-rw-r--r--gr-blocks/lib/packed_to_unpacked_XX_impl.cc.t147
-rw-r--r--gr-blocks/lib/packed_to_unpacked_XX_impl.h.t59
-rw-r--r--gr-blocks/lib/rms_cf_impl.cc77
-rw-r--r--gr-blocks/lib/rms_cf_impl.h56
-rw-r--r--gr-blocks/lib/rms_ff_impl.cc77
-rw-r--r--gr-blocks/lib/rms_ff_impl.h55
-rw-r--r--gr-blocks/lib/unpacked_to_packed_XX_impl.cc.t143
-rw-r--r--gr-blocks/lib/unpacked_to_packed_XX_impl.h.t59
11 files changed, 877 insertions, 0 deletions
diff --git a/gr-blocks/lib/CMakeLists.txt b/gr-blocks/lib/CMakeLists.txt
index 560a55d57..9b076f696 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
@@ -163,6 +166,8 @@ list(APPEND gr_blocks_sources
nlog10_ff_impl.cc
patterned_interleaver_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
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/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/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@ */