Using generators to make gri_fir_filter_with_buffer_XXX into all possible in/out...
authorTom Rondeau <trondeau@vt.edu>
Sat, 16 Oct 2010 22:28:53 +0000 (18:28 -0400)
committerTom Rondeau <trondeau@vt.edu>
Sat, 16 Oct 2010 22:28:53 +0000 (18:28 -0400)
gnuradio-core/src/lib/filter/.gitignore
gnuradio-core/src/lib/filter/Makefile.am
gnuradio-core/src/lib/filter/Makefile.gen
gnuradio-core/src/lib/filter/generate_all.py
gnuradio-core/src/lib/filter/generate_gri_fir_filter_with_buffer_XXX.py [new file with mode: 0755]
gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.cc.t [new file with mode: 0644]
gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_XXX.h.t [new file with mode: 0644]
gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.cc [deleted file]
gnuradio-core/src/lib/filter/gri_fir_filter_with_buffer_ccf.h [deleted file]

index 2d009f15451b06e8159c0fae0ae4d21ca635a26c..4797b6b3a31a14eee5465fb976a7706afb15b734 100644 (file)
 /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-*
index ff6c546fdb8426337f1dc55486b19336f91c6295..31f919ba7745c1eb33f781208f2edee113198738 100644 (file)
@@ -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 =                        \
index 6809274fa9328d57c32ce713aab7e3ecc75142ad..909899c054b06de1d24702f928397cc90ee10674 100644 (file)
@@ -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
 
index b34e13c73e2ac4ccdc1ab42caa667184f486b97f..ceed2b8510d42349e8bd7a37a3849a6f5544f1e3 100755 (executable)
@@ -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 (executable)
index 0000000..7252e26
--- /dev/null
@@ -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 (file)
index 0000000..dd71a55
--- /dev/null
@@ -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 <config.h>
+#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 (file)
index 0000000..d566b36
--- /dev/null
@@ -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 <vector>
+#include <gr_types.h>
+#include <gr_reverse.h>
+#include <string.h>
+#include <cstdio>
+
+/*!
+ * \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 (file)
index 55e316d..0000000
+++ /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 <config.h>
-#endif
-
-#include <gri_fir_filter_with_buffer_ccf.h>
-
-gri_fir_filter_with_buffer_ccf::gri_fir_filter_with_buffer_ccf(const std::vector<float> &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 (file)
index c91d705..0000000
+++ /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 <vector>
-#include <gr_types.h>
-#include <gr_reverse.h>
-#include <string.h>
-#include <cstdio>
-
-/*!
- * \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<float>   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<float> &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<float> &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<float> get_taps () const
-  {
-    return gr_reverse(d_taps);
-  }
-};
-
-#endif /* INCLUDED_GR_GR_FIR_FILTER_WITH_BUFFER_CCF_H */