Statistics
| Branch: | Tag: | Revision:

root / gnuradio-core / src / lib / filter / gr_interp_fir_filter_XXX.cc.t @ 0b5f6611

History | View | Annotate | Download (3.7 kB)

1
/* -*- c++ -*- */
2
/*
3
 * Copyright 2004,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_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 <@NAME@.h>
33
#include <@FIR_TYPE@.h>
34
#include <gr_fir_util.h>
35
#include <gr_io_signature.h>
36
#include <stdexcept>
37
#include <iostream>
38
39
@SPTR_NAME@ gr_make_@BASE_NAME@ (unsigned interpolation, const std::vector<@TAP_TYPE@> &taps)
40
{
41
  return gnuradio::get_initial_sptr (new @NAME@ (interpolation, taps));
42
}
43
44
45
@NAME@::@NAME@ (unsigned interpolation, const std::vector<@TAP_TYPE@> &taps)
46
  : gr_sync_interpolator ("@BASE_NAME@",
47
			  gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
48
			  gr_make_io_signature (1, 1, sizeof (@O_TYPE@)),
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<@TAP_TYPE@>	dummy_taps;
56
  
57
  for (unsigned i = 0; i < interpolation; i++)
58
    d_firs[i] = gr_fir_util::create_@FIR_TYPE@ (dummy_taps);
59
60
  set_taps (taps);
61
  install_taps(d_new_taps);
62
}
63
64
@NAME@::~@NAME@ ()
65
{
66
  int interp = interpolation ();
67
  for (int i = 0; i < interp; i++)
68
    delete d_firs[i];
69
}
70
71
void
72
@NAME@::set_taps (const std::vector<@TAP_TYPE@> &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
@NAME@::install_taps (const std::vector<@TAP_TYPE@> &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 <@TAP_TYPE@> > 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
@NAME@::work (int noutput_items,
125
		   gr_vector_const_void_star &input_items,
126
		   gr_vector_void_star &output_items)
127
{
128
  const @I_TYPE@ *in = (const @I_TYPE@ *) input_items[0];
129
  @O_TYPE@ *out = (@O_TYPE@ *) 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
}