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 <GrAtscTrellisEncoder.h>
25 // typedefs for fundamental i/o types
27 typedef atsc_mpeg_packet_rs_encoded iType;
28 typedef atsc_data_segment oType;
30 static const int NUMBER_OF_OUTPUTS = 1; // # of output streams (almost always one)
33 GrAtscTrellisEncoder::GrAtscTrellisEncoder ()
34 : VrHistoryProc<iType,oType> (NUMBER_OF_OUTPUTS), last_start(-1)
36 // 1 + number of extra input elements at which we look. This is
37 // used by the superclass's forecast routine to get us the correct
38 // range on our inputs.
40 // We need our input to be aligned on a 12-segment boundary,
41 // to ensure satisfaction, ask for 11 more
42 history = 1 + (atsci_trellis_encoder::NCODERS - 1);
44 // any other init here.
46 // Let the bottom end know we must produce output in multiples of 12 segments.
47 setOutputSize (atsci_trellis_encoder::NCODERS);
50 GrAtscTrellisEncoder::~GrAtscTrellisEncoder ()
52 // Anything that isn't automatically cleaned up...
56 * This is the real work horse. In general this interface can handle
57 * multiple streams of input and output, but we almost always
58 * use a single input and output stream.
62 GrAtscTrellisEncoder::work (VrSampleRange output, void *ao[],
63 VrSampleRange inputs[], void *ai[])
65 // If we have state that persists across invocations (e.g., we have
66 // instance variables that we modify), we must use the sync method
67 // to indicate to the scheduler that our output must be computed in
68 // order. This doesn't keep other things from being run in
69 // parallel, it just means that at any given time, there is only a
70 // single thread working this code, and that the scheduler will
71 // ensure that we are asked to produce output that is contiguous and
72 // that will be presented to us in order of increasing time.
74 // We have state, the current state of the encoders, hence
79 // construct some nicer i/o pointers to work with.
81 iType *in = ((iType **) ai)[0];
82 oType *out = ((oType **) ao)[0];
86 cerr << "@@@ GrAtscTrellisEncoder: output.index = " << output.index
87 << " output.size = " << output.size
88 << " sum = " << output.index + output.size
89 << " \t[in = " << in << "]"
93 assert (output.size % atsci_trellis_encoder::NCODERS == 0);
96 // find the first mod 12 boundary to begin decoding
98 for (start = 0; start < atsci_trellis_encoder::NCODERS; start++){
99 plinfo::sanity_check (in[start].pli);
100 assert (in[start].pli.regular_seg_p ());
101 if ((in[start].pli.segno () % atsci_trellis_encoder::NCODERS) == 0)
105 if (start == atsci_trellis_encoder::NCODERS){
106 // we didn't find a mod 12 boundary. There's some kind of problem
107 // upstream of us (not yet sync'd??)
108 cerr << "!!!GrAtscTrellisEncoder: no mod-12 boundary found\7\n";
111 else if (start != last_start){
112 cerr << "GrAtscTrellisEncoder: new starting offset = " << start
113 << " output.index = " << output.index << endl;
118 // FIXME paranoid check for problem
119 for (unsigned int i = 0; i < output.size; i++){
120 plinfo::sanity_check (in[i + start].pli);
123 // We must produce output.size units of output.
125 for (unsigned int i = 0; i < output.size; i += atsci_trellis_encoder::NCODERS){
126 // primitive does 12 segments at a time.
127 // pipeline info is handled in the primitive.
128 encoder.encode (&out[i], &in[i + start]);
132 // FIXME paranoid check for problem
133 for (unsigned int i = 0; i < output.size; i++){
134 plinfo::sanity_check (out[i].pli);
135 assert (out[i].pli.regular_seg_p ());
139 // Return the number of units we produced.
140 // Note that for all intents and purposes, it is an error to
141 // produce less than you are asked for.