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 <GrAtscFieldSyncMux.h>
24 #include <atsci_pnXXX.h>
27 // typedefs for fundamental i/o types
29 typedef atsc_data_segment iType;
30 typedef atsc_data_segment oType;
32 static const int NUMBER_OF_OUTPUTS = 1; // # of output streams (almost always one)
34 static const int N_SAVED_SYMBOLS = GrAtscFieldSyncMux::N_SAVED_SYMBOLS;
37 init_field_sync_common (unsigned char *p, int mask,
38 const unsigned char saved_symbols[N_SAVED_SYMBOLS])
40 static const unsigned char bin_map[2] = { 1, 6 }; // map binary values to 1 of 8 levels
44 p[i++] = bin_map[1]; // data segment sync pulse
49 for (int j = 0; j < 511; j++) // PN511
50 p[i++] = bin_map[atsc_pn511[j]];
52 for (int j = 0; j < 63; j++) // PN63
53 p[i++] = bin_map[atsc_pn63[j]];
55 for (int j = 0; j < 63; j++) // PN63, toggled on field 2
56 p[i++] = bin_map[atsc_pn63[j] ^ mask];
58 for (int j = 0; j < 63; j++) // PN63
59 p[i++] = bin_map[atsc_pn63[j]];
61 p[i++] = bin_map[0]; // 24 bits of VSB8 mode identifiera
92 for (int j = 0; j < 92; j++) // 92 more bits
93 p[i++] = bin_map[atsc_pn63[j % 63]];
95 // now copy the last 12 symbols of the previous segment
97 for (int j = 0; j < N_SAVED_SYMBOLS; j++)
98 p[i++] = saved_symbols[j];
100 assert (i == ATSC_DATA_SEGMENT_LENGTH);
104 init_field_sync_1 (atsc_data_segment *s,
105 const unsigned char saved_symbols[N_SAVED_SYMBOLS])
107 init_field_sync_common (&s->data[0], 0, saved_symbols);
111 init_field_sync_2 (atsc_data_segment *s,
112 const unsigned char saved_symbols[N_SAVED_SYMBOLS])
115 init_field_sync_common (&s->data[0], 1, saved_symbols);
119 save_last_symbols (unsigned char saved_symbols[N_SAVED_SYMBOLS],
120 const atsc_data_segment &seg)
122 for (int i = 0; i < N_SAVED_SYMBOLS; i++)
123 saved_symbols[i] = seg.data[i + ATSC_DATA_SEGMENT_LENGTH - N_SAVED_SYMBOLS];
128 last_regular_seg_p (const plinfo &pli)
130 return pli.regular_seg_p () && (pli.segno () == ATSC_DSEGS_PER_FIELD - 1);
134 GrAtscFieldSyncMux::GrAtscFieldSyncMux ()
135 : VrHistoryProc<iType,oType> (NUMBER_OF_OUTPUTS),
136 d_current_index (0), d_already_output_field_sync (false)
138 // 1 + number of extra input elements at which we look. This is
139 // used by the superclass's forecast routine to get us the correct
140 // range on our inputs.
143 // any other init here.
146 GrAtscFieldSyncMux::~GrAtscFieldSyncMux ()
148 // Anything that isn't automatically cleaned up...
152 GrAtscFieldSyncMux::pre_initialize ()
154 // we jack our output sampling frequency up to account for inserted field syncs
155 setSamplingFrequency (getInputSamplingFrequencyN (0) * 313./312.);
159 * we need a non-standard version of forecast because our output isn't
160 * exactly 1:1 with our input.
164 GrAtscFieldSyncMux::forecast (VrSampleRange output, VrSampleRange inputs[])
166 for(unsigned int i = 0; i < numberInputs; i++) {
167 inputs[i].index = d_current_index;
168 inputs[i].size = output.size;
174 * This is the real work horse. In general this interface can handle
175 * multiple streams of input and output, but we almost always
176 * use a single input and output stream.
179 GrAtscFieldSyncMux::work (VrSampleRange output, void *ao[],
180 VrSampleRange inputs[], void *ai[])
182 // If we have state that persists across invocations (e.g., we have
183 // instance variables that we modify), we must use the sync method
184 // to indicate to the scheduler that our output must be computed in
185 // order. This doesn't keep other things from being run in
186 // parallel, it just means that at any given time, there is only a
187 // single thread working this code, and that the scheduler will
188 // ensure that we are asked to produce output that is contiguous and
189 // that will be presented to us in order of increasing time.
191 // We have state, hence we must use sync.
195 // construct some nicer i/o pointers to work with.
197 iType *in = ((iType **) ai)[0];
198 oType *out = ((oType **) ao)[0];
201 // We must produce output.size units of output.
203 unsigned int index = 0;
204 for (unsigned int outdex = 0; outdex < output.size; outdex++){
206 assert (in[index].pli.regular_seg_p ());
208 if (!in[index].pli.first_regular_seg_p ()){
209 out[outdex] = in[index]; // just copy in to out
211 if (last_regular_seg_p (in[index].pli))
212 save_last_symbols (d_saved_symbols, in[index]);
216 else { // first_regular_seg_p
217 if (!d_already_output_field_sync){
218 // write out field sync...
219 atsc_data_segment field_sync;
221 if (in[index].pli.in_field1_p ())
222 init_field_sync_1 (&field_sync, d_saved_symbols);
224 init_field_sync_2 (&field_sync, d_saved_symbols);
226 // note that index doesn't advance in this branch
227 out[outdex] = field_sync;
228 d_already_output_field_sync = true;
231 // already output field sync, now output first regular segment
232 out[outdex] = in[index];
234 d_already_output_field_sync = false;
239 d_current_index += index;
241 // Return the number of units we produced.
242 // Note that for all intents and purposes, it is an error to
243 // produce less than you are asked for.