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
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
00087
for(
unsigned int i=0;i<numberInputs;i++) {
00088 inputs[i].
index=output.
index*
decimation;
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
00115
00116
00117
00118
00119
00120
00121
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