Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

VrDecimatingSigProc.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 /*
00003  * Copyright 2001 Free Software Foundation, Inc.
00004  * 
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2, or (at your option)
00010  * any later version.
00011  * 
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  * 
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 /*
00023  *  Copyright 1997 Massachusetts Institute of Technology
00024  * 
00025  *  Permission to use, copy, modify, distribute, and sell this software and its
00026  *  documentation for any purpose is hereby granted without fee, provided that
00027  *  the above copyright notice appear in all copies and that both that
00028  *  copyright notice and this permission notice appear in supporting
00029  *  documentation, and that the name of M.I.T. not be used in advertising or
00030  *  publicity pertaining to distribution of the software without specific,
00031  *  written prior permission.  M.I.T. makes no representations about the
00032  *  suitability of this software for any purpose.  It is provided "as is"
00033  *  without express or implied warranty.
00034  * 
00035  */
00036 
00037 
00038 #ifndef _VRDECIMATINGSIGPROC_H_
00039 #define _VRDECIMATINGSIGPROC_H_
00040 
00041 #include <VrHistoryProc.h>
00042 
00043 template<class iType, class oType> 
00044 class VrDecimatingSigProc : public VrHistoryProc<iType,oType> {
00045 protected:
00046   int decimation;
00047 public: 
00048   VrDecimatingSigProc() : decimation(1) {}
00049   VrDecimatingSigProc(int outputs) : VrHistoryProc<iType, oType>(outputs), decimation(1) {}
00050   VrDecimatingSigProc(int outputs, int dec) : VrHistoryProc<iType, oType>(outputs), decimation(dec) {}
00051 
00052   virtual void pre_initialize ();
00053   
00054   virtual int forecast(VrSampleRange output,
00055                        VrSampleRange inputs[]);
00056 
00057   virtual float averageInputUse(int n) {
00058     if(decimation>(int) history) return (float)history/(float)decimation;
00059     else return 1.0;
00060   }
00061 
00062   virtual unsigned int mapSizeUp(int i, unsigned int size);
00063 
00064   virtual int checkOutputSamplingFrequency(float sf) {
00065     if (fabs (sf - getUpstreamModuleN(0)->getSamplingFrequency()/decimation)
00066         > 0.001 * getUpstreamModuleN(0)->getSamplingFrequency()/decimation){
00067       cerr << "sf: " << sf
00068            << " gsf/dec: "
00069            << getUpstreamModuleN(0)->getSamplingFrequency()/decimation << endl;
00070       return -1;
00071     }
00072     else
00073       return 0;
00074   }
00075 
00076 #if 0   // BAD IDEA: See below
00077   int work(VrSampleRange output, void *ao[], VrSampleRange inputs[], void *ai[]);
00078 #endif
00079 
00080   virtual ~VrDecimatingSigProc() {}
00081 };
00082 
00083 template<class iType,class oType> int
00084 VrDecimatingSigProc<iType,oType>::forecast(VrSampleRange output,
00085                                            VrSampleRange inputs[]) {
00086   /* dec:1 ratio with history */
00087   for(unsigned int i=0;i<numberInputs;i++) {
00088     inputs[i].index=output.index*decimation; /* ! do not subtract history ! */
00089     inputs[i].size=output.size*decimation + history-1;
00090   }
00091   return 0;
00092 }  
00093 
00094 template<class iType,class oType> unsigned int
00095 VrDecimatingSigProc<iType,oType>::mapSizeUp(int i, unsigned int size) {
00096   if(size==1) return history;
00097   else return size * decimation+history-1;
00098 }
00099 
00100 template<class iType,class oType> void 
00101 VrDecimatingSigProc<iType,oType>::pre_initialize (){
00102   assert (decimation >= 1);
00103 #if 0
00104   if (decimation == 1){
00105     fprintf (stderr, "### Warning: decimation == 1 in pre_initialize of %s.  Are you sure?\n",
00106              name ());
00107   }
00108 #endif
00109   if (getSamplingFrequency () == 0.0)
00110     setSamplingFrequency (getInputSamplingFrequencyN (0) / decimation);
00111 }
00112 
00113 #if 0
00114 // This is now disabled, because in general, it's not possible
00115 // to cast from iType to oType in the assignment in the body of the loop.
00116 // The specific example that chokes some compilers is:
00117 //   iType = float, oType = atsc_soft_data_segment
00118 //
00119 // This gets triggered in GrAtscFieldSyncDemux.  It's not clear to me whether
00120 // this is a bug, or just a different interpretation of how to instantiate
00121 // templates. 
00122 
00123 template<class iType,class oType> int
00124 VrDecimatingSigProc<iType,oType>::work(VrSampleRange output, void *ao[],
00125                                 VrSampleRange inputs[], void *ai[])
00126 {
00127   iType **i = (iType **)ai;
00128   oType **o = (oType **)ao;
00129   int size = output.size;
00130 
00131   for(int insamp=0; insamp < size*decimation; insamp += decimation)
00132     {
00133           *o[0]++ = (oType) i[0][insamp];
00134     }
00135   return output.size;
00136 }
00137 #endif
00138 
00139 #endif

Generated on Tue Mar 30 21:31:51 2004 for GNU Radio by doxygen 1.3.2