00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef _VRSIGPROC_H_
00038 #define _VRSIGPROC_H_
00039
00040 #include <VrTypes.h>
00041 #include <VrPerfGraph.h>
00042
00043 extern unsigned int cacheSize;
00044 extern float maxLatency;
00045 class VrBuffer;
00046 class VrConnect;
00047 class VrMultiTask;
00048
00049 struct writerLL {
00050
00051 VrSampleIndex maxValid;
00052 struct writerLL *next;
00053 };
00054
00055 struct readerLL {
00056 VrSampleIndex index;
00057 struct readerLL *next;
00058 };
00059
00061
00067 class VrSigProc {
00068 friend class VrMultiTask;
00069
00070 private:
00071
00072
00073
00074
00075 int uses_sync;
00076 double proc_samplingFrequency;
00077
00079 volatile VrSampleIndex WP;
00080
00082 volatile VrSampleIndex markedWP;
00083
00085
00090 unsigned int maxOutSize;
00091
00092
00093 #ifdef PERFMON
00094 VrCycleCount *cycles;
00095 #endif
00096
00097 VrConnect ** inputConn;
00098 unsigned int setupCalled;
00099 unsigned int outputSize;
00100 unsigned int type_size;
00101 unsigned int itype_size;
00102 unsigned int initializeCalled;
00103 #ifdef THREADS
00104 pthread_key_t myMarkedData;
00105 pthread_key_t inputs_forecasted;
00106 pthread_key_t myWriterLL;
00107 pthread_key_t myReaderLLs;
00108 #else
00109 VrSampleRange myMarkedData;
00110 VrSampleRange *inputs_forecasted;
00111 writerLL *myWriterLL;
00112 readerLL *myReaderLLs;
00113 #endif
00114
00115
00116
00117 volatile writerLL *first, *last;
00118 MUTEX_DECLARE(mutex);
00119 void attach_writer(writerLL *r);
00120 void detach_writer(writerLL *r);
00121
00127 void init_base();
00128
00140 virtual void pre_initialize();
00141
00143 virtual void initialize() {};
00144
00145 virtual bool isConnectedToSource();
00146
00147 int minwritespace(VrSampleIndex newWP, unsigned int desired);
00148
00149
00150
00151 void initOutputBuffers(int n);
00152 virtual void initOutputBuffer(int n);
00153 void initMarkedData();
00154 virtual unsigned int mapSizeUp(int i, unsigned int size);
00155
00157 virtual bool dataMarked(VrSampleRange r);
00158
00159
00161 virtual int markData(VrSampleRange r);
00162 static const int MARK_ALREADY = 2;
00163 static const int MARK_READY = 1;
00164 static const int MARK_READY_NO_MARK = 0;
00165
00166 static const int MARK_NO_READY = -1;
00167 static const int MARK_THREAD = -2;
00168 static const int MARK_continue = -3;
00169
00170 virtual int VrSigProc::markDataUpstream (VrSampleRange *inputs,
00171 bool *dataMarkedUpstream);
00173 virtual bool compute();
00174
00175 protected:
00176
00177 VrBuffer** outBuffer;
00178
00180 unsigned int maxDSReadSize;
00181
00182 unsigned int numberInputs;
00183 unsigned int numberOutputs;
00184 virtual VrSigProc *getUpstreamModuleN(port p);
00185 double getInputSamplingFrequencyN(port p);
00186
00188 void setOutputSize(int o) { outputSize=o; }
00189 unsigned int getOutputSize() {return outputSize;}
00190
00191 void setup_upstream();
00192 int getNumberInputs() {return numberInputs;}
00193
00198 bool is_synced (VrSampleIndex arg_index) {
00199 return WP >= arg_index;
00200 }
00201
00203 void sync (VrSampleIndex arg_index);
00204
00205 VrSampleIndex proc_minRP();
00206
00207 public:
00208 VrSigProc(int number_of_outputs, unsigned int arg_itype_size, unsigned int arg_type_size);
00209 virtual ~VrSigProc();
00210
00212 bool connect_proc(VrSigProc* proc, port n);
00213
00214
00215
00216
00217
00219
00220 virtual const char *name() { return "VrSigProc"; }
00221
00223
00224
00225 virtual int forecast(VrSampleRange output, VrSampleRange inputs[]);
00226
00233 virtual float memoryTouched();
00234
00246 virtual int work(VrSampleRange output, void *o[],
00247 VrSampleRange inputs[], void *i[]) = 0;
00248
00249
00250
00251
00252
00253
00254
00255 virtual float averageInputUse(int n) {return 1.0;}
00256
00257 virtual int checkOutputSamplingFrequency(float) { return 0;}
00258
00260 bool isSink ();
00261
00262
00263
00264
00265 virtual int setSamplingFrequency(double sf);
00266
00267
00268 virtual bool dataReady(VrSampleRange r);
00269 virtual void size_setup(unsigned int size);
00270 virtual void setup();
00271 VrSampleIndex getMarkedWP() {return markedWP;}
00272
00273 #ifdef PERFMON
00274
00275 unsigned int num_print_stats;
00276 long long getTotalCycles();
00277 long long getTotalCycles(int m);
00278 long getTotalSamples();
00279 long long getCyclesPerSample();
00280 long long getCyclesPerSample(int m);
00281 void addToGraph(VrPerfGraph *g);
00282 void print_stats();
00283 #endif
00284 unsigned int getMaxOutputSize() {return maxOutSize;}
00285 VrSampleIndex getWP() {return WP;}
00286 double getSamplingFrequency() { return proc_samplingFrequency; }
00287 virtual int callback(int attribute_number, float value) { return 0; }
00288 };
00289
00290
00291
00292
00293
00294
00295
00296 static inline void
00297 NWO_CONNECTN (VrSigProc *src, int n, VrSigProc *dst)
00298 {
00299 dst->connect_proc (src, n);
00300 }
00301
00302 static inline void
00303 NWO_CONNECT (VrSigProc *src, VrSigProc *dst)
00304 {
00305 NWO_CONNECTN (src, 0, dst);
00306 }
00307
00308
00309
00310 #define CONNECTN(a, b, n, sf, bps) NWO_CONNECTN (b, n, a)
00311 #define CONNECT(a, b, sf, bps) NWO_CONNECT (b, a)
00312
00313 #endif