Updated license from GPL version 2 or later to GPL version 3 or later.
[debian/gnuradio] / gr-atsc / src / lib / GrAtscDataSegToSoftDataSeg.cc
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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 3, 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 #include <GrAtscDataSegToSoftDataSeg.h>
24
25 // typedefs for fundamental i/o types
26
27 typedef atsc_data_segment               iType;
28 typedef atsc_soft_data_segment          oType;
29
30 static const int NUMBER_OF_OUTPUTS = 1; // # of output streams (almost always one)
31
32
33 #define NELEM(x) (sizeof (x) / sizeof (x[0]))
34
35 static void
36 map_to_soft_symbols (atsc_soft_data_segment &out,
37                      const atsc_data_segment &in)
38 {
39   for (unsigned int i = 0; i < NELEM (in.data); i++){
40     out.data[i] = in.data[i] * 2 - 7;
41   }
42 }
43
44
45 GrAtscDataSegToSoftDataSeg::GrAtscDataSegToSoftDataSeg ()
46   : VrHistoryProc<iType,oType> (NUMBER_OF_OUTPUTS)
47 {
48   // 1 + number of extra input elements at which we look.  This is
49   // used by the superclass's forecast routine to get us the correct
50   // range on our inputs.
51   // We're one-to-one input-to-output so set it to 1.
52   history = 1;  
53
54   // any other init here.
55 }
56
57 GrAtscDataSegToSoftDataSeg::~GrAtscDataSegToSoftDataSeg ()
58 {
59   // Anything that isn't automatically cleaned up...
60 }
61
62 /*
63  * This is the real work horse.  In general this interface can handle
64  * multiple streams of input and output, but we almost always
65  * use a single input and output stream.
66  */
67
68 int 
69 GrAtscDataSegToSoftDataSeg::work (VrSampleRange output, void *ao[],
70                                   VrSampleRange inputs[], void *ai[])
71 {
72   // If we have state that persists across invocations (e.g., we have
73   // instance variables that we modify), we must use the sync method
74   // to indicate to the scheduler that our output must be computed in
75   // order.  This doesn't keep other things from being run in
76   // parallel, it just means that at any given time, there is only a
77   // single thread working this code, and that the scheduler will
78   // ensure that we are asked to produce output that is contiguous and
79   // that will be presented to us in order of increasing time.
80
81   // sync (output.index);
82
83   // construct some nicer i/o pointers to work with.
84
85   iType *in  = ((iType **) ai)[0];
86   oType *out = ((oType **) ao)[0];
87
88
89   // We must produce output.size units of output.
90
91   for (unsigned int i = 0; i < output.size; i++){
92     map_to_soft_symbols (out[i], in[i]);
93     out[i].pli = in[i].pli;
94   }
95
96   // Return the number of units we produced.
97   // Note that for all intents and purposes, it is an error to
98   // produce less than you are asked for.
99
100   return output.size;
101 }