Statistics
| Branch: | Tag: | Revision:

root / gr-atsc / src / lib / GrAtscTrellisEncoder.cc @ 42d9c6f4

History | View | Annotate | Download (4.6 kB)

1 5d69a524 jcorgan
/* -*- c++ -*- */
2 5d69a524 jcorgan
/*
3 5d69a524 jcorgan
 * Copyright 2002 Free Software Foundation, Inc.
4 5d69a524 jcorgan
 * 
5 5d69a524 jcorgan
 * This file is part of GNU Radio
6 5d69a524 jcorgan
 * 
7 5d69a524 jcorgan
 * GNU Radio is free software; you can redistribute it and/or modify
8 5d69a524 jcorgan
 * it under the terms of the GNU General Public License as published by
9 937b719d eb
 * the Free Software Foundation; either version 3, or (at your option)
10 5d69a524 jcorgan
 * any later version.
11 5d69a524 jcorgan
 * 
12 5d69a524 jcorgan
 * GNU Radio is distributed in the hope that it will be useful,
13 5d69a524 jcorgan
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 5d69a524 jcorgan
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 5d69a524 jcorgan
 * GNU General Public License for more details.
16 5d69a524 jcorgan
 * 
17 5d69a524 jcorgan
 * You should have received a copy of the GNU General Public License
18 5d69a524 jcorgan
 * along with GNU Radio; see the file COPYING.  If not, write to
19 86f5c924 eb
 * the Free Software Foundation, Inc., 51 Franklin Street,
20 86f5c924 eb
 * Boston, MA 02110-1301, USA.
21 5d69a524 jcorgan
 */
22 5d69a524 jcorgan
23 5d69a524 jcorgan
#include <GrAtscTrellisEncoder.h>
24 5d69a524 jcorgan
25 5d69a524 jcorgan
// typedefs for fundamental i/o types
26 5d69a524 jcorgan
27 5d69a524 jcorgan
typedef atsc_mpeg_packet_rs_encoded        iType;
28 5d69a524 jcorgan
typedef atsc_data_segment                oType;
29 5d69a524 jcorgan
30 5d69a524 jcorgan
static const int NUMBER_OF_OUTPUTS = 1;        // # of output streams (almost always one)
31 5d69a524 jcorgan
32 5d69a524 jcorgan
33 5d69a524 jcorgan
GrAtscTrellisEncoder::GrAtscTrellisEncoder ()
34 5d69a524 jcorgan
  : VrHistoryProc<iType,oType> (NUMBER_OF_OUTPUTS), last_start(-1)
35 5d69a524 jcorgan
{
36 5d69a524 jcorgan
  // 1 + number of extra input elements at which we look.  This is
37 5d69a524 jcorgan
  // used by the superclass's forecast routine to get us the correct
38 5d69a524 jcorgan
  // range on our inputs.
39 5d69a524 jcorgan
  //
40 5d69a524 jcorgan
  // We need our input to be aligned on a 12-segment boundary,
41 5d69a524 jcorgan
  // to ensure satisfaction, ask for 11 more
42 5d69a524 jcorgan
  history = 1 + (atsci_trellis_encoder::NCODERS - 1);
43 5d69a524 jcorgan
44 5d69a524 jcorgan
  // any other init here.
45 5d69a524 jcorgan
46 5d69a524 jcorgan
  // Let the bottom end know we must produce output in multiples of 12 segments.  
47 5d69a524 jcorgan
  setOutputSize (atsci_trellis_encoder::NCODERS);
48 5d69a524 jcorgan
}
49 5d69a524 jcorgan
50 5d69a524 jcorgan
GrAtscTrellisEncoder::~GrAtscTrellisEncoder ()
51 5d69a524 jcorgan
{
52 5d69a524 jcorgan
  // Anything that isn't automatically cleaned up...
53 5d69a524 jcorgan
}
54 5d69a524 jcorgan
55 5d69a524 jcorgan
/*
56 5d69a524 jcorgan
 * This is the real work horse.  In general this interface can handle
57 5d69a524 jcorgan
 * multiple streams of input and output, but we almost always
58 5d69a524 jcorgan
 * use a single input and output stream.
59 5d69a524 jcorgan
 */
60 5d69a524 jcorgan
61 5d69a524 jcorgan
int 
62 5d69a524 jcorgan
GrAtscTrellisEncoder::work (VrSampleRange output, void *ao[],
63 5d69a524 jcorgan
                            VrSampleRange inputs[], void *ai[])
64 5d69a524 jcorgan
{
65 5d69a524 jcorgan
  // If we have state that persists across invocations (e.g., we have
66 5d69a524 jcorgan
  // instance variables that we modify), we must use the sync method
67 5d69a524 jcorgan
  // to indicate to the scheduler that our output must be computed in
68 5d69a524 jcorgan
  // order.  This doesn't keep other things from being run in
69 5d69a524 jcorgan
  // parallel, it just means that at any given time, there is only a
70 5d69a524 jcorgan
  // single thread working this code, and that the scheduler will
71 5d69a524 jcorgan
  // ensure that we are asked to produce output that is contiguous and
72 5d69a524 jcorgan
  // that will be presented to us in order of increasing time.
73 5d69a524 jcorgan
74 5d69a524 jcorgan
  // We have state, the current state of the encoders, hence
75 5d69a524 jcorgan
  // we must use sync.
76 5d69a524 jcorgan
77 5d69a524 jcorgan
  sync (output.index);
78 5d69a524 jcorgan
79 5d69a524 jcorgan
  // construct some nicer i/o pointers to work with.
80 5d69a524 jcorgan
81 5d69a524 jcorgan
  iType *in  = ((iType **) ai)[0];
82 5d69a524 jcorgan
  oType *out = ((oType **) ao)[0];
83 5d69a524 jcorgan
84 5d69a524 jcorgan
85 5d69a524 jcorgan
#if 0
86 5d69a524 jcorgan
  cerr << "@@@ GrAtscTrellisEncoder: output.index = " << output.index
87 5d69a524 jcorgan
       << " output.size = " << output.size
88 5d69a524 jcorgan
       << " sum = " << output.index + output.size
89 5d69a524 jcorgan
       << " \t[in  = " << in << "]"
90 5d69a524 jcorgan
       << endl;
91 5d69a524 jcorgan
#endif  
92 5d69a524 jcorgan
93 5d69a524 jcorgan
  assert (output.size % atsci_trellis_encoder::NCODERS == 0);
94 5d69a524 jcorgan
95 5d69a524 jcorgan
96 5d69a524 jcorgan
  // find the first mod 12 boundary to begin decoding
97 5d69a524 jcorgan
  int start;
98 5d69a524 jcorgan
  for (start = 0; start < atsci_trellis_encoder::NCODERS; start++){
99 5d69a524 jcorgan
    plinfo::sanity_check (in[start].pli);
100 5d69a524 jcorgan
    assert (in[start].pli.regular_seg_p ());
101 5d69a524 jcorgan
    if ((in[start].pli.segno () % atsci_trellis_encoder::NCODERS) == 0)
102 5d69a524 jcorgan
      break;
103 5d69a524 jcorgan
  }
104 5d69a524 jcorgan
105 5d69a524 jcorgan
  if (start == atsci_trellis_encoder::NCODERS){
106 5d69a524 jcorgan
    // we didn't find a mod 12 boundary.  There's some kind of problem
107 5d69a524 jcorgan
    // upstream of us (not yet sync'd??)
108 5d69a524 jcorgan
    cerr << "!!!GrAtscTrellisEncoder: no mod-12 boundary found\7\n";
109 5d69a524 jcorgan
    start = 0;
110 5d69a524 jcorgan
  }
111 5d69a524 jcorgan
  else if (start != last_start){
112 5d69a524 jcorgan
    cerr << "GrAtscTrellisEncoder: new starting offset = " << start
113 5d69a524 jcorgan
         << " output.index = " << output.index << endl;
114 5d69a524 jcorgan
    last_start = start;
115 5d69a524 jcorgan
  }
116 5d69a524 jcorgan
117 5d69a524 jcorgan
118 5d69a524 jcorgan
  // FIXME paranoid check for problem
119 5d69a524 jcorgan
  for (unsigned int i = 0; i < output.size; i++){
120 5d69a524 jcorgan
    plinfo::sanity_check (in[i + start].pli);
121 5d69a524 jcorgan
  }
122 5d69a524 jcorgan
123 5d69a524 jcorgan
  // We must produce output.size units of output.
124 5d69a524 jcorgan
125 5d69a524 jcorgan
  for (unsigned int i = 0; i < output.size; i += atsci_trellis_encoder::NCODERS){
126 5d69a524 jcorgan
    // primitive does 12 segments at a time.
127 5d69a524 jcorgan
    // pipeline info is handled in the primitive.
128 5d69a524 jcorgan
    encoder.encode (&out[i], &in[i + start]);
129 5d69a524 jcorgan
  }
130 5d69a524 jcorgan
131 5d69a524 jcorgan
#if 0
132 5d69a524 jcorgan
  // FIXME paranoid check for problem
133 5d69a524 jcorgan
  for (unsigned int i = 0; i < output.size; i++){
134 5d69a524 jcorgan
    plinfo::sanity_check (out[i].pli);
135 5d69a524 jcorgan
    assert (out[i].pli.regular_seg_p ());
136 5d69a524 jcorgan
  }
137 5d69a524 jcorgan
#endif
138 5d69a524 jcorgan
139 5d69a524 jcorgan
  // Return the number of units we produced.
140 5d69a524 jcorgan
  // Note that for all intents and purposes, it is an error to
141 5d69a524 jcorgan
  // produce less than you are asked for.
142 5d69a524 jcorgan
143 5d69a524 jcorgan
  return output.size;        
144 5d69a524 jcorgan
}