Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gr-atsc / src / lib / atsc_viterbi_decoder.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 2, 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_viterbi_decoder.h>
28 #include <gr_io_signature.h>
29 #include <atsc_consts.h>
30 #include <iostream.h>
31
32
33 atsc_viterbi_decoder_sptr
34 atsc_make_viterbi_decoder()
35 {
36   return atsc_viterbi_decoder_sptr(new atsc_viterbi_decoder());
37 }
38
39 atsc_viterbi_decoder::atsc_viterbi_decoder()
40   : gr_sync_block("atsc_viterbi_decoder",
41                   gr_make_io_signature(1, 1, sizeof(atsc_soft_data_segment)),
42                   gr_make_io_signature(1, 1, sizeof(atsc_mpeg_packet_rs_encoded))),
43                   last_start(-1)
44 {
45   set_output_multiple(atsci_viterbi_decoder::NCODERS);
46   reset();
47 }
48
49 int
50 atsc_viterbi_decoder::work (int noutput_items,
51                        gr_vector_const_void_star &input_items,
52                        gr_vector_void_star &output_items)
53 {
54   const atsc_soft_data_segment *in = (const atsc_soft_data_segment *) input_items[0];
55   atsc_mpeg_packet_rs_encoded *out = (atsc_mpeg_packet_rs_encoded *) output_items[0];
56
57   assert (noutput_items % atsci_viterbi_decoder::NCODERS == 0);
58
59   // find the first mod 12 boundary to begin decoding
60   int start;
61   for (start = 0; start < atsci_viterbi_decoder::NCODERS; start++){
62     assert (in[start].pli.regular_seg_p ());
63     if ((in[start].pli.segno () % atsci_viterbi_decoder::NCODERS) == 0)
64       break;
65   }
66
67   if (start == atsci_viterbi_decoder::NCODERS){
68     // we didn't find a mod 12 boundary.  There's some kind of problem
69     // upstream of us (not yet sync'd??)
70     cerr << "!!!atsc_viterbi_decoder: no mod-12 boundary found\7\n";
71     start = 0;
72   }
73   else if (start != last_start){
74     cerr << "atsc_viterbi_decoder: new starting offset = " << start
75          << endl;
76     last_start = start;
77   }
78
79   for (int i = 0; i < atsci_viterbi_decoder::NCODERS; i += atsci_viterbi_decoder::NCODERS){
80     d_viterbi_decoder.decode(&out[i], &in[i + start]);
81   }
82   return atsci_viterbi_decoder::NCODERS;
83 }
84