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

VrSkippingSink.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 _VRSKIPPINGSINK_H_ 00039 #define _VRSKIPPINGSINK_H_ 00040 00041 #include <VrSink.h> 00042 #include <stdio.h> 00043 #include <assert.h> 00044 00045 //This sink uses a history-size chunk of data every increment units of data 00046 // (i.e. skips over increment-history units of data) 00047 // Each unit requested from the sink's work() procecure will operation 00048 // on a _block_ (history-size) of data. 00049 template<class iType> 00050 class VrSkippingSink : public VrSink<iType> { 00051 protected: 00052 unsigned int history; 00053 unsigned int increment; 00054 public: 00055 00056 // FIXME history and increment should be arguments to constructor 00057 00058 VrSkippingSink() : history(1), increment(1) { 00059 setOptimalSize(1); /*forces size of 1 to allow skipping*/ 00060 } 00061 00062 virtual void pre_initialize () { 00063 if (increment <= 0) { 00064 fprintf (stderr, "[%s:%d] initialize() invalid value for increment=%d\n", 00065 __FILE__, __LINE__, increment); 00066 abort (); 00067 } 00068 00069 if (increment == 1){ 00070 fprintf (stderr, "### Warning: increment == 1 in pre_initialize of %s. Are you sure?\n", 00071 name ()); 00072 } 00073 00074 setSamplingFrequency(getInputSamplingFrequencyN (0) / increment); 00075 } 00076 00077 virtual int forecast(VrSampleRange output, 00078 VrSampleRange inputs[]); 00079 00080 virtual float averageInputUse(int n) { 00081 if(increment>history) return (float) history/(float) increment; 00082 else return 1.0; 00083 } 00084 00085 virtual unsigned int mapSizeUp(int i, unsigned int size) { 00086 return (unsigned int) (size * averageInputUse(i) * 00087 (getUpstreamModuleN(i)->getSamplingFrequency() 00088 /getSamplingFrequency())); 00089 } 00090 00091 virtual ~VrSkippingSink() {} 00092 }; 00093 00094 template<class iType> int 00095 VrSkippingSink<iType>::forecast(VrSampleRange output, 00096 VrSampleRange inputs[]) { 00097 /* 1:history with increment skipping */ 00098 /* size should always be 1 */ 00099 assert (output.size == 1); 00100 00101 for(unsigned int i=0;i<numberInputs;i++) { 00102 inputs[i].index=output.index*increment; /* ! do not subtract history ! */ 00103 inputs[i].size=history; 00104 } 00105 return 0; 00106 } 00107 00108 #endif 00109 00110 00111 00112 00113 00114 00115 00116 00117 00118 00119 00120 00121 00122 00123 00124 00125 00126 00127

Generated on Wed Aug 4 02:22:06 2004 for GNU Radio by doxygen 1.3.8