Adding a FIR filter implemented with its own internal buffer. This one keeps its...
[debian/gnuradio] / gnuradio-core / src / lib / filter / gri_fir_filter_with_buffer_ccf.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22
23 /*
24  * WARNING: This file is automatically generated by generate_gr_fir_XXX.py
25  * Any changes made to this file will be overwritten.
26  */
27
28
29 #ifndef INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_H
30 #define INCLUDED_GRI_FIR_FILTER_WITH_BUFFER_H
31
32 #include <vector>
33 #include <gr_types.h>
34 #include <gr_reverse.h>
35 #include <string.h>
36
37 /*!
38  * \brief FIR with internal buffer for gr_complex input, 
39           gr_complex output and float taps
40  * \ingroup filter
41  * 
42  */
43
44 class gri_fir_filter_with_buffer_ccf {
45
46 protected:
47   std::vector<float>    d_taps;         // reversed taps
48   gr_complex           *d_buffer;
49   unsigned int          d_idx;
50
51 public:
52
53   // CONSTRUCTORS
54
55   /*!
56    * \brief construct new FIR with given taps.
57    *
58    * Note that taps must be in forward order, e.g., coefficient 0 is
59    * stored in new_taps[0], coefficient 1 is stored in
60    * new_taps[1], etc.
61    */
62   gri_fir_filter_with_buffer_ccf (const std::vector<float> &taps);
63
64   ~gri_fir_filter_with_buffer_ccf ();
65
66   // MANIPULATORS
67
68   /*!
69    * \brief compute a single output value.
70    *
71    * \p input must have ntaps() valid entries.
72    * input[0] .. input[ntaps() - 1] are referenced to compute the output value.
73    *
74    * \returns the filtered input value.
75    */
76   gr_complex filter (gr_complex input);
77
78   /*!
79    * \brief compute an array of N output values.
80    *
81    * \p input must have (n - 1 + ntaps()) valid entries.
82    * input[0] .. input[n - 1 + ntaps() - 1] are referenced to compute the output values.
83    */
84   void filterN (gr_complex output[], const gr_complex input[],
85                 unsigned long n);
86
87   /*!
88    * \brief compute an array of N output values, decimating the input
89    *
90    * \p input must have (decimate * (n - 1) + ntaps()) valid entries.
91    * input[0] .. input[decimate * (n - 1) + ntaps() - 1] are referenced to 
92    * compute the output values.
93    */
94   void filterNdec (gr_complex output[], const gr_complex input[],
95                    unsigned long n, unsigned decimate);
96
97   /*!
98    * \brief install \p new_taps as the current taps.
99    */
100   void set_taps (const std::vector<float> &taps)
101   {
102     d_taps = gr_reverse(taps);
103     //d_taps = (taps);
104
105     if(d_buffer != NULL)
106       free(d_buffer);
107     
108     // FIXME: memalign this to 16-byte boundaries for SIMD later
109     d_buffer = (gr_complex*)malloc(sizeof(gr_complex) * 2 * d_taps.size());
110     memset(d_buffer, 0x00, sizeof(gr_complex) * 2 * d_taps.size());
111     d_idx = 0;
112   }
113
114   // ACCESSORS
115
116   /*!
117    * \return number of taps in filter.
118    */
119   unsigned ntaps () const { return d_taps.size (); }
120
121   /*!
122    * \return current taps
123    */
124   const std::vector<float> get_taps () const
125   {
126     return gr_reverse(d_taps);
127   }
128 };
129
130 #endif /* INCLUDED_GR_GR_FIR_FILTER_WITH_BUFFER_CCF_H */