3 * Copyright 2002 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.
23 #include <GrAtscViterbiDecoder.h>
26 // typedefs for fundamental i/o types
28 typedef atsc_soft_data_segment iType;
29 typedef atsc_mpeg_packet_rs_encoded oType;
31 static const int NUMBER_OF_OUTPUTS = 1; // # of output streams (almost always one)
34 GrAtscViterbiDecoder::GrAtscViterbiDecoder ()
35 : VrHistoryProc<iType,oType> (NUMBER_OF_OUTPUTS), last_start(-1)
37 // 1 + number of extra input elements at which we look. This is
38 // used by the superclass's forecast routine to get us the correct
39 // range on our inputs.
41 // We need our input to be aligned on a 12-segment boundary,
42 // to ensure satisfaction, ask for 11 more
43 history = 1 + (atsci_viterbi_decoder::NCODERS - 1);
45 // any other init here.
47 // Let the bottom end know we must produce output in multiples of 12 segments.
48 setOutputSize (atsci_viterbi_decoder::NCODERS);
51 GrAtscViterbiDecoder::~GrAtscViterbiDecoder ()
53 // Anything that isn't automatically cleaned up...
57 * This is the real work horse. In general this interface can handle
58 * multiple streams of input and output, but we almost always
59 * use a single input and output stream.
63 GrAtscViterbiDecoder::work (VrSampleRange output, void *ao[],
64 VrSampleRange inputs[], void *ai[])
66 // If we have state that persists across invocations (e.g., we have
67 // instance variables that we modify), we must use the sync method
68 // to indicate to the scheduler that our output must be computed in
69 // order. This doesn't keep other things from being run in
70 // parallel, it just means that at any given time, there is only a
71 // single thread working this code, and that the scheduler will
72 // ensure that we are asked to produce output that is contiguous and
73 // that will be presented to us in order of increasing time.
75 // We have state, the current state of the decoder, hence
80 // construct some nicer i/o pointers to work with.
82 iType *in = ((iType **) ai)[0];
83 oType *out = ((oType **) ao)[0];
86 assert (output.size % atsci_viterbi_decoder::NCODERS == 0);
88 // find the first mod 12 boundary to begin decoding
90 for (start = 0; start < atsci_viterbi_decoder::NCODERS; start++){
91 assert (in[start].pli.regular_seg_p ());
92 if ((in[start].pli.segno () % atsci_viterbi_decoder::NCODERS) == 0)
96 if (start == atsci_viterbi_decoder::NCODERS){
97 // we didn't find a mod 12 boundary. There's some kind of problem
98 // upstream of us (not yet sync'd??)
99 cerr << "!!!GrAtscViterbiDecoder: no mod-12 boundary found\7\n";
102 else if (start != last_start){
103 cerr << "GrAtscViterbiDecoder: new starting offset = " << start
104 << " output.index = " << output.index << endl;
108 // We must produce output.size units of output.
110 for (unsigned int i = 0; i < output.size; i += atsci_viterbi_decoder::NCODERS){
111 // primitive does 12 segments at a time.
112 // pipeline info is handled in the primitive.
113 decoder.decode (&out[i], &in[i + start]);
117 // FIXME paranoid check...
118 for (unsigned int i = 0; i < output.size; i++){
119 plinfo::sanity_check (out[i].pli);
120 assert (out[i].pli.regular_seg_p ());
125 cerr << "@@@ GrAtscViterbiDecoder: output.index = " << output.index
126 << " output.size = " << output.size
127 << " sum = " << output.index + output.size << endl;
130 // Return the number of units we produced.
131 // Note that for all intents and purposes, it is an error to
132 // produce less than you are asked for.