From: Tom Rondeau Date: Sat, 16 Oct 2010 22:28:53 +0000 (-0400) Subject: Using generators to make gri_fir_filter_with_buffer_XXX into all possible in/out... X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=eb7316ea486ab774c24cba1142a785080559e579;p=debian%2Fgnuradio Using generators to make gri_fir_filter_with_buffer_XXX into all possible in/out/tap types we support. --- diff --git a/gnuradio-core/src/lib/filter/.gitignore b/gnuradio-core/src/lib/filter/.gitignore index 2d009f15..4797b6b3 100644 --- a/gnuradio-core/src/lib/filter/.gitignore +++ b/gnuradio-core/src/lib/filter/.gitignore @@ -211,4 +211,14 @@ /gr_rational_resampler_base_scc.cc /gr_rational_resampler_base_scc.h /gr_rational_resampler_base_scc.i +/gri_fir_filter_with_buffer_ccc.cc +/gri_fir_filter_with_buffer_ccc.h +/gri_fir_filter_with_buffer_fcc.cc +/gri_fir_filter_with_buffer_fcc.h +/gri_fir_filter_with_buffer_fff.cc +/gri_fir_filter_with_buffer_fff.h +/gri_fir_filter_with_buffer_fsf.cc +/gri_fir_filter_with_buffer_fsf.h +/gri_fir_filter_with_buffer_scc.cc +/gri_fir_filter_with_buffer_scc.h /stamp-* diff --git a/gnuradio-core/src/lib/filter/Makefile.am b/gnuradio-core/src/lib/filter/Makefile.am index ff6c546f..31f919ba 100644 --- a/gnuradio-core/src/lib/filter/Makefile.am +++ b/gnuradio-core/src/lib/filter/Makefile.am @@ -44,6 +44,7 @@ code_generator = \ generate_gr_fir_sysconfig_generic.py \ generate_gr_fir_util.py \ generate_gr_freq_xlating_fir_filter_XXX.py \ + generate_gri_fir_filter_with_buffer_XXX.py \ generate_utils.py \ gr_fir_XXX.cc.t \ gr_fir_XXX.h.t \ @@ -60,7 +61,11 @@ code_generator = \ gr_rational_resampler_base_XXX.i.t \ gr_freq_xlating_fir_filter_XXX.cc.t \ gr_freq_xlating_fir_filter_XXX.h.t \ - gr_freq_xlating_fir_filter_XXX.i.t + gr_freq_xlating_fir_filter_XXX.i.t \ + gri_fir_filter_with_buffer_XXX.cc.t \ + gri_fir_filter_with_buffer_XXX.h.t \ + gri_fir_filter_with_buffer_XXX.i.t + # Source built by Python into $(builddir) BUILT_SOURCES = \ diff --git a/gnuradio-core/src/lib/filter/Makefile.gen b/gnuradio-core/src/lib/filter/Makefile.gen index 6809274f..909899c0 100644 --- a/gnuradio-core/src/lib/filter/Makefile.gen +++ b/gnuradio-core/src/lib/filter/Makefile.gen @@ -40,7 +40,14 @@ GENERATED_H = \ gr_rational_resampler_base_fcc.h \ gr_rational_resampler_base_fff.h \ gr_rational_resampler_base_fsf.h \ - gr_rational_resampler_base_scc.h + gr_rational_resampler_base_scc.h \ + gri_fir_filter_with_buffer_ccc.h \ + gri_fir_filter_with_buffer_ccf.h \ + gri_fir_filter_with_buffer_fcc.h \ + gri_fir_filter_with_buffer_fff.h \ + gri_fir_filter_with_buffer_fsf.h \ + gri_fir_filter_with_buffer_scc.h + GENERATED_I = \ gr_fir_filter_ccc.i \ @@ -107,5 +114,11 @@ GENERATED_CC = \ gr_rational_resampler_base_fcc.cc \ gr_rational_resampler_base_fff.cc \ gr_rational_resampler_base_fsf.cc \ - gr_rational_resampler_base_scc.cc + gr_rational_resampler_base_scc.cc \ + gri_fir_filter_with_buffer_ccc.cc \ + gri_fir_filter_with_buffer_ccf.cc \ + gri_fir_filter_with_buffer_fcc.cc \ + gri_fir_filter_with_buffer_fff.cc \ + gri_fir_filter_with_buffer_fsf.cc \ + gri_fir_filter_with_buffer_scc.cc diff --git a/gnuradio-core/src/lib/filter/generate_all.py b/gnuradio-core/src/lib/filter/generate_all.py index b34e13c7..ceed2b85 100755 --- a/gnuradio-core/src/lib/filter/generate_all.py +++ b/gnuradio-core/src/lib/filter/generate_all.py @@ -30,6 +30,7 @@ import generate_gr_fir_sysconfig_generic import generate_gr_fir_sysconfig import generate_gr_fir_util import generate_gr_fir_XXX +import generate_gri_fir_filter_with_buffer_XXX def generate_all(): generate_gr_fir_XXX.generate() @@ -40,6 +41,7 @@ def generate_all(): generate_gr_fir_sysconfig_generic.generate() generate_gr_fir_sysconfig.generate() generate_gr_fir_util.generate() + generate_gri_fir_filter_with_buffer_XXX.generate() output_glue('filter') if __name__ == '__main__': diff --git a/gnuradio-core/src/lib/filter/generate_gri_fir_filter_with_buffer_XXX.py b/gnuradio-core/src/lib/filter/generate_gri_fir_filter_with_buffer_XXX.py new file mode 100755 index 00000000..7252e26f --- /dev/null +++ b/gnuradio-core/src/lib/filter/generate_gri_fir_filter_with_buffer_XXX.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# -*- python -*- +# +# Copyright 2010 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +import re +from generate_utils import * + +roots = ['gri_fir_filter_with_buffer_XXX',] + +def code3_to_input_cast (code3): + if i_code (code3) == 's' and o_code (code3) == 'c': + return '(float)' + return '' + +def expand_h_cc (root, code3): + d = init_dict (root, code3) + expand_template (d, root + '.h.t') + expand_template (d, root + '.cc.t') + +def init_dict (root, code3): + name = re.sub ('X+', code3, root) + d = standard_dict (name, code3) + d['INPUT_CAST'] = code3_to_input_cast (code3) + return d + + +def generate (): + for r in roots: + for s in fir_signatures: + expand_h_cc (r, s) + + +if __name__ == '__main__': + generate () diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.cc.t b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.cc.t new file mode 100644 index 00000000..dd71a55f --- /dev/null +++ b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.cc.t @@ -0,0 +1,88 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include <@NAME@.h> + +@NAME@::@NAME@(const std::vector<@TAP_TYPE@> &taps) +{ + d_buffer = NULL; + set_taps(taps); +} + +@NAME@::~@NAME@() +{ + if(d_buffer != NULL) + free(d_buffer); +} + +void +@NAME@::set_taps (const std::vector<@TAP_TYPE@> &taps) +{ + d_taps = gr_reverse(taps); + + if(d_buffer != NULL) { + free(d_buffer); + d_buffer = NULL; + } + + // FIXME: memalign this to 16-byte boundaries for SIMD later + size_t t = sizeof(@I_TYPE@) * 2 * d_taps.size(); + d_buffer = (@I_TYPE@*)malloc(t); + memset(d_buffer, 0x00, t); + d_idx = 0; +} + +@O_TYPE@ +@NAME@::filter (@I_TYPE@ input) +{ + unsigned int i; + + d_buffer[d_idx] = input; + d_buffer[d_idx+ntaps()] = input; + + // using the later for the case when ntaps=0; + // profiling shows this doesn't make a difference + //d_idx = (d_idx + 1) % ntaps(); + d_idx++; + if(d_idx >= ntaps()) + d_idx = 0; + + @O_TYPE@ out = 0; + for(i = 0; i < ntaps(); i++) { + out += @INPUT_CAST@ d_buffer[d_idx + i] * d_taps[i]; + } + return out; +} + +void +@NAME@::filterN (@O_TYPE@ output[], + const @I_TYPE@ input[], + unsigned long n) +{ + for(unsigned long i = 0; i < n; i++) { + output[i] = filter(input[i]); + } +} diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.h.t b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.h.t new file mode 100644 index 00000000..d566b367 --- /dev/null +++ b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.h.t @@ -0,0 +1,119 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3, or (at your option) + * any later version. + * + * GNU Radio is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +/* + * WARNING: This file is automatically generated by generate_gri_fir_XXX.py + * Any changes made to this file will be overwritten. + */ + + +#ifndef @GUARD_NAME@ +#define @GUARD_NAME@ + +#include +#include +#include +#include +#include + +/*! + * \brief FIR with internal buffer for @I_TYPE@ input, + @O_TYPE@ output and @TAP_TYPE@ taps + * \ingroup filter + * + */ + +class @NAME@ { + +protected: + std::vector<@TAP_TYPE@> d_taps; // reversed taps + @I_TYPE@ *d_buffer; + unsigned int d_idx; + +public: + + // CONSTRUCTORS + + /*! + * \brief construct new FIR with given taps. + * + * Note that taps must be in forward order, e.g., coefficient 0 is + * stored in new_taps[0], coefficient 1 is stored in + * new_taps[1], etc. + */ + @NAME@ (const std::vector<@TAP_TYPE@> &taps); + + ~@NAME@ (); + + // MANIPULATORS + + /*! + * \brief compute a single output value. + * + * \p input must have ntaps() valid entries. + * input[0] .. input[ntaps() - 1] are referenced to compute the output value. + * + * \returns the filtered input value. + */ + @O_TYPE@ filter (@I_TYPE@ input); + + /*! + * \brief compute an array of N output values. + * + * \p input must have (n - 1 + ntaps()) valid entries. + * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values. + */ + void filterN (@O_TYPE@ output[], const @I_TYPE@ input[], + unsigned long n); + + /*! + * \brief compute an array of N output values, decimating the input + * + * \p input must have (decimate * (n - 1) + ntaps()) valid entries. + * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to + * compute the output values. + */ + void filterNdec (@O_TYPE@ output[], const @I_TYPE@ input[], + unsigned long n, unsigned decimate); + + /*! + * \brief install \p new_taps as the current taps. + */ + void set_taps (const std::vector<@TAP_TYPE@> &taps); + + // ACCESSORS + + /*! + * \return number of taps in filter. + */ + unsigned ntaps () const { return d_taps.size (); } + + /*! + * \return current taps + */ + const std::vector<@TAP_TYPE@> get_taps () const + { + return gr_reverse(d_taps); + } +}; + +#endif /* @GUARD_NAME@ */ diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc deleted file mode 100644 index 55e316d0..00000000 --- a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc +++ /dev/null @@ -1,71 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -gri_fir_filter_with_buffer_ccf::gri_fir_filter_with_buffer_ccf(const std::vector &taps) -{ - d_buffer = NULL; - set_taps(taps); -} - -gri_fir_filter_with_buffer_ccf::~gri_fir_filter_with_buffer_ccf() -{ - if(d_buffer != NULL) - free(d_buffer); -} - -gr_complex -gri_fir_filter_with_buffer_ccf::filter (gr_complex input) -{ - unsigned int i; - - d_buffer[d_idx] = input; - d_buffer[d_idx+ntaps()] = input; - - // using the later for the case when ntaps=0; - // profiling shows this doesn't make a difference - //d_idx = (d_idx + 1) % ntaps(); - d_idx++; - if(d_idx >= ntaps()) - d_idx = 0; - - gr_complex out = gr_complex(0,0); - for(i = 0; i < ntaps(); i++) { - out += d_buffer[d_idx + i]*d_taps[i]; - } - return out; -} - -void -gri_fir_filter_with_buffer_ccf::filterN (gr_complex output[], - const gr_complex input[], - unsigned long n) -{ - for(unsigned long i = 0; i < n; i++) { - output[i] = filter(input[i]); - } -} diff --git a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h b/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h deleted file mode 100644 index c91d7053..00000000 --- a/gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- c++ -*- */ -/* - * Copyright 2010 Free Software Foundation, Inc. - * - * This file is part of GNU Radio - * - * GNU Radio is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3, or (at your option) - * any later version. - * - * GNU Radio is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Radio; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 51 Franklin Street, - * Boston, MA 02110-1301, USA. - */ - -/* - * WARNING: This file is automatically generated by generate_gr_fir_XXX.py - * Any changes made to this file will be overwritten. - */ - - -#ifndef INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_H -#define INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_H - -#include -#include -#include -#include -#include - -/*! - * \brief FIR with internal buffer for gr_complex input, - gr_complex output and float taps - * \ingroup filter - * - */ - -class gri_fir_filter_with_buffer_ccf { - -protected: - std::vector d_taps; // reversed taps - gr_complex *d_buffer; - unsigned int d_idx; - -public: - - // CONSTRUCTORS - - /*! - * \brief construct new FIR with given taps. - * - * Note that taps must be in forward order, e.g., coefficient 0 is - * stored in new_taps[0], coefficient 1 is stored in - * new_taps[1], etc. - */ - gri_fir_filter_with_buffer_ccf (const std::vector &taps); - - ~gri_fir_filter_with_buffer_ccf (); - - // MANIPULATORS - - /*! - * \brief compute a single output value. - * - * \p input must have ntaps() valid entries. - * input[0] .. input[ntaps() - 1] are referenced to compute the output value. - * - * \returns the filtered input value. - */ - gr_complex filter (gr_complex input); - - /*! - * \brief compute an array of N output values. - * - * \p input must have (n - 1 + ntaps()) valid entries. - * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values. - */ - void filterN (gr_complex output[], const gr_complex input[], - unsigned long n); - - /*! - * \brief compute an array of N output values, decimating the input - * - * \p input must have (decimate * (n - 1) + ntaps()) valid entries. - * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to - * compute the output values. - */ - void filterNdec (gr_complex output[], const gr_complex input[], - unsigned long n, unsigned decimate); - - /*! - * \brief install \p new_taps as the current taps. - */ - void set_taps (const std::vector &taps) - { - d_taps = gr_reverse(taps); - - if(d_buffer != NULL) { - free(d_buffer); - d_buffer = NULL; - } - - // FIXME: memalign this to 16-byte boundaries for SIMD later - size_t t = sizeof(gr_complex) * 2 * d_taps.size(); - d_buffer = (gr_complex*)malloc(t); - memset(d_buffer, 0x00, t); - d_idx = 0; - } - - // ACCESSORS - - /*! - * \return number of taps in filter. - */ - unsigned ntaps () const { return d_taps.size (); } - - /*! - * \return current taps - */ - const std::vector get_taps () const - { - return gr_reverse(d_taps); - } -}; - -#endif /* INCLUDED_GR_GR_FIR_FILTER_WITH_BUFFER_CCF_H */