add Vcs entries to control file
[debian/gnuradio] / gnuradio-core / src / lib / filter / gr_interp_fir_filter_fsf.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2004 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_filter_XXX.py
25  * Any changes made to this file will be overwritten.
26  */
27
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31
32 #include <gr_interp_fir_filter_fsf.h>
33 #include <gr_fir_fsf.h>
34 #include <gr_fir_util.h>
35 #include <gr_io_signature.h>
36 #include <stdexcept>
37 #include <iostream>
38
39 gr_interp_fir_filter_fsf_sptr gr_make_interp_fir_filter_fsf (unsigned interpolation, const std::vector<float> &taps)
40 {
41   return gr_interp_fir_filter_fsf_sptr (new gr_interp_fir_filter_fsf (interpolation, taps));
42 }
43
44
45 gr_interp_fir_filter_fsf::gr_interp_fir_filter_fsf (unsigned interpolation, const std::vector<float> &taps)
46   : gr_sync_interpolator ("interp_fir_filter_fsf",
47                           gr_make_io_signature (1, 1, sizeof (float)),
48                           gr_make_io_signature (1, 1, sizeof (short)),
49                           interpolation),
50     d_updated (false), d_firs (interpolation)
51 {
52   if (interpolation == 0)
53     throw std::out_of_range ("interpolation must be > 0");
54
55   std::vector<float>    dummy_taps;
56   
57   for (unsigned i = 0; i < interpolation; i++)
58     d_firs[i] = gr_fir_util::create_gr_fir_fsf (dummy_taps);
59
60   set_taps (taps);
61   install_taps(d_new_taps);
62 }
63
64 gr_interp_fir_filter_fsf::~gr_interp_fir_filter_fsf ()
65 {
66   int interp = interpolation ();
67   for (int i = 0; i < interp; i++)
68     delete d_firs[i];
69 }
70
71 void
72 gr_interp_fir_filter_fsf::set_taps (const std::vector<float> &taps)
73 {
74   d_new_taps = taps;
75   d_updated = true;
76
77   // round up length to a multiple of the interpolation factor
78   int n = taps.size () % interpolation ();
79   if (n > 0){
80     n = interpolation () - n;
81     while (n-- > 0)
82       d_new_taps.insert(d_new_taps.begin(), 0);
83   }
84
85   assert (d_new_taps.size () % interpolation () == 0);
86 }
87
88
89 void
90 gr_interp_fir_filter_fsf::install_taps (const std::vector<float> &taps)
91 {
92   int nfilters = interpolation ();
93   int nt = taps.size () / nfilters;
94
95   assert (nt * nfilters == (int) taps.size ());
96
97   std::vector< std::vector <float> > xtaps (nfilters);
98
99   for (int n = 0; n < nfilters; n++)
100     xtaps[n].resize (nt);  
101
102   for (int i = 0; i < (int) taps.size(); i++)
103     xtaps[i % nfilters][i / nfilters] = taps[i];
104
105   for (int n = 0; n < nfilters; n++)
106     d_firs[n]->set_taps (xtaps[n]);
107   
108   set_history (nt);
109   d_updated = false;
110
111 #if 0
112   for (int i = 0; i < nfilters; i++){
113     std::cout << "filter[" << i << "] = ";
114     for (int j = 0; j < nt; j++)
115       std::cout << xtaps[i][j] << " ";
116
117     std::cout << "\n";
118   }
119 #endif
120
121 }
122
123 int
124 gr_interp_fir_filter_fsf::work (int noutput_items,
125                    gr_vector_const_void_star &input_items,
126                    gr_vector_void_star &output_items)
127 {
128   const float *in = (const float *) input_items[0];
129   short *out = (short *) output_items[0];
130
131   if (d_updated) {
132     install_taps (d_new_taps);
133     return 0;                // history requirements may have changed.
134   }
135
136   int nfilters = interpolation ();
137   int ni = noutput_items / interpolation ();
138   
139   for (int i = 0; i < ni; i++){
140     for (int nf = 0; nf < nfilters; nf++)
141       out[nf] = d_firs[nf]->filter (&in[i]);
142     out += nfilters;
143   }
144
145   return noutput_items;
146 }