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