Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gr-atsc / src / lib / atsc_equalizer.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <atsc_equalizer.h>
28 #include <create_atsci_equalizer.h>
29 #include <gr_io_signature.h>
30 #include <atsc_consts.h>
31 #include <atsci_syminfo.h>
32
33
34 atsc_equalizer_sptr
35 atsc_make_equalizer()
36 {
37   return atsc_equalizer_sptr(new atsc_equalizer());
38 }
39
40 // had atsc_equalizer(atsci_equalizer *equalizer)
41 atsc_equalizer::atsc_equalizer()
42   : gr_sync_block("atsc_equalizer",
43                   gr_make_io_signature(2, 2, sizeof(float)),
44                   gr_make_io_signature(2, 2, sizeof(float)))
45 {
46   d_equalizer = create_atsci_equalizer_lms();
47 }
48
49 atsc_equalizer::~atsc_equalizer ()
50 {
51   // Anything that isn't automatically cleaned up...
52
53   delete d_equalizer;
54 }
55
56
57 void
58 atsc_equalizer::forecast (int noutput_items, gr_vector_int &ninput_items_required)
59 {
60
61   int ntaps = d_equalizer->ntaps ();
62
63   unsigned ninputs = ninput_items_required.size();
64   for (unsigned i = 0; i < ninputs; i++)
65     ninput_items_required[i] = fixed_rate_noutput_to_ninput (noutput_items + ntaps);
66
67
68 }
69
70
71
72 int
73 atsc_equalizer::work (int noutput_items,
74                        gr_vector_const_void_star &input_items,
75                        gr_vector_void_star &output_items)
76 {
77   const float *in = (const float *) input_items[0];
78   const atsc::syminfo *in_tags = (const atsc::syminfo *) input_items[1];
79   float *out = (float *) output_items[0];
80   atsc::syminfo *out_tags = (atsc::syminfo *) output_items[1];
81
82   assert(sizeof(float) == sizeof(atsc::syminfo));
83
84   int ntaps = d_equalizer->ntaps ();
85   int npretaps = d_equalizer->npretaps ();
86
87   assert (ntaps >= 1);
88   assert (npretaps >= 0 && npretaps < ntaps);
89
90   int offset = ntaps - npretaps - 1;
91   assert (offset >= 0 && offset < ntaps);
92
93
94   // peform the actual equalization
95
96   d_equalizer->filter (in, in_tags + offset,
97                        out, noutput_items);
98
99   // write the output tags
100
101   for (int i = 0; i < noutput_items; i++)
102     out_tags[i] = in_tags[i + offset];
103
104   return noutput_items;
105 }