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

VrSink.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 #ifndef _VRSINK_H_ 00038 #define _VRSINK_H_ 00039 00040 #include <VrSigProc.h> 00041 00042 template<class iType> 00043 class VrSink : public VrSigProc { 00044 private: 00045 unsigned int optimalSize; 00046 00047 public: 00048 virtual const char *name() { return "VrSink"; } 00049 00050 //set this if you want the sink to use smaller chunks 00051 // than the maxLatency would dictate 00052 void setOptimalSize(unsigned int s) { optimalSize = s;} 00053 00054 virtual void setup(); 00055 void setup_upstream(); 00056 00057 virtual int work(VrSampleRange output, void *o[], 00058 VrSampleRange inputs[], void *i[]) { 00059 return work3 (output, inputs, i); 00060 }; 00061 00062 virtual int work3(VrSampleRange output, 00063 VrSampleRange inputs[], void *i[]) = 0; 00064 00065 VrSink() : VrSigProc(0, sizeof(iType), 0), 00066 optimalSize(0x70000000){ } 00067 }; 00068 00069 template <class iType> void 00070 VrSink<iType>::setup() 00071 { 00072 VrSink<iType>::setup_upstream(); 00073 } 00074 00075 template <class iType> void 00076 VrSink<iType>::setup_upstream() 00077 { 00078 float m = memoryTouched(); //returns memory accesses / second of chain 00079 00080 //Compute a globally optimal size to run on for the whole chain 00081 //(every input and output stays in cache for entire length of chain) 00082 unsigned int cachedSize = (int) (cacheSize * (getSamplingFrequency() / m)); 00083 00084 fprintf(stderr,"%s cachedSize = %d\n",name(),cachedSize); 00085 if(cachedSize/getSamplingFrequency() > maxLatency) { 00086 fprintf(stderr," reducing latency from %f",cachedSize/getSamplingFrequency()); 00087 cachedSize = (unsigned int) (getSamplingFrequency() * maxLatency); 00088 fprintf(stderr," to %f seconds\n",cachedSize/getSamplingFrequency()); 00089 } 00090 if(optimalSize < cachedSize) { 00091 fprintf(stderr," manually specified optimalSize of %d (%f sec)\n",optimalSize,optimalSize/getSamplingFrequency()); 00092 cachedSize=optimalSize; 00093 } 00094 //round down 00095 if((cachedSize % getOutputSize()) != 0) { 00096 cachedSize = (cachedSize/getOutputSize()) * getOutputSize(); 00097 } 00098 if(cachedSize==0) cachedSize=getOutputSize(); 00099 maxDSReadSize=optimalSize=cachedSize; 00100 00101 VrSigProc::setup_upstream(); 00102 } 00103 00104 #endif 00105

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