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