3 * Copyright 2004 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
24 * WARNING: This file is automatically generated by
25 * generate_gr_rational_resampler_base_XXX.py Any changes made to this
26 * file will be overwritten.
33 #include <gr_rational_resampler_base_fcc.h>
34 #include <gr_fir_fcc.h>
35 #include <gr_fir_util.h>
36 #include <gr_io_signature.h>
40 gr_rational_resampler_base_fcc_sptr
41 gr_make_rational_resampler_base_fcc (unsigned interpolation,
43 const std::vector<gr_complex> &taps)
45 return gr_rational_resampler_base_fcc_sptr (new gr_rational_resampler_base_fcc (interpolation, decimation, taps));
48 gr_rational_resampler_base_fcc::gr_rational_resampler_base_fcc (unsigned interpolation, unsigned decimation,
49 const std::vector<gr_complex> &taps)
50 : gr_block ("rational_resampler_base_fcc",
51 gr_make_io_signature (1, 1, sizeof (float)),
52 gr_make_io_signature (1, 1, sizeof (gr_complex))),
54 d_interpolation(interpolation), d_decimation(decimation),
55 d_ctr(0), d_updated(false),
58 if (interpolation == 0)
59 throw std::out_of_range ("interpolation must be > 0");
61 throw std::out_of_range ("decimation must be > 0");
63 set_relative_rate (1.0 * interpolation / decimation);
64 set_output_multiple (1);
66 std::vector<gr_complex> dummy_taps;
68 for (unsigned i = 0; i < interpolation; i++)
69 d_firs[i] = gr_fir_util::create_gr_fir_fcc (dummy_taps);
72 install_taps (d_new_taps);
75 gr_rational_resampler_base_fcc::~gr_rational_resampler_base_fcc ()
77 int interp = interpolation();
78 for (int i = 0; i < interp; i++)
83 gr_rational_resampler_base_fcc::set_taps (const std::vector<gr_complex> &taps)
88 // round up length to a multiple of the interpolation factor
89 int n = taps.size () % interpolation ();
91 n = interpolation () - n;
93 d_new_taps.insert(d_new_taps.begin(), 0);
96 assert (d_new_taps.size () % interpolation () == 0);
101 gr_rational_resampler_base_fcc::install_taps (const std::vector<gr_complex> &taps)
103 int nfilters = interpolation ();
104 int nt = taps.size () / nfilters;
106 assert (nt * nfilters == (int) taps.size ());
108 std::vector< std::vector <gr_complex> > xtaps (nfilters);
110 for (int n = 0; n < nfilters; n++)
111 xtaps[n].resize (nt);
113 for (int i = 0; i < (int) taps.size(); i++)
114 xtaps[i % nfilters][i / nfilters] = taps[i];
116 for (int n = 0; n < nfilters; n++)
117 d_firs[n]->set_taps (xtaps[n]);
123 for (int i = 0; i < nfilters; i++){
124 std::cout << "filter[" << i << "] = ";
125 for (int j = 0; j < nt; j++)
126 std::cout << xtaps[i][j] << " ";
135 gr_rational_resampler_base_fcc::forecast (int noutput_items, gr_vector_int &ninput_items_required)
137 int nreqd = std::max((unsigned)1, (int)((double) (noutput_items+1) * decimation() / interpolation()) + history() - 1);
138 unsigned ninputs = ninput_items_required.size ();
139 for (unsigned i = 0; i < ninputs; i++)
140 ninput_items_required[i] = nreqd;
144 gr_rational_resampler_base_fcc::general_work (int noutput_items,
145 gr_vector_int &ninput_items,
146 gr_vector_const_void_star &input_items,
147 gr_vector_void_star &output_items)
149 const float *in = (const float *) input_items[0];
150 gr_complex *out = (gr_complex *) output_items[0];
153 install_taps (d_new_taps);
154 return 0; // history requirement may have increased.
157 unsigned int ctr = d_ctr;
160 while (i < noutput_items){
161 out[i++] = d_firs[ctr]->filter(in);
163 while (ctr >= interpolation()){
164 ctr -= interpolation();
170 consume_each(in - (float *) input_items[0]);