00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _GRINTERPOLATOR_H_
00024 #define _GRINTERPOLATOR_H_
00025
00026 #include <GrFractionalInterpolatingSigProc.h>
00027 #include <stdlib.h>
00028 #include <gr_mmse_fir_interpolator.h>
00029
00038 template<class iType, class oType>
00039 class GrInterpolator : public GrFractionalInterpolatingSigProc<iType,oType>
00040 {
00041 public:
00043 GrInterpolator (int N, int M, int phase = 0);
00044 ~GrInterpolator () {};
00045
00046 const char *name () { return "GrInterpolator"; }
00047 int work (VrSampleRange output, void *ao[], VrSampleRange inputs[], void *ai[]);
00048
00049 protected:
00050 int phase;
00051 gr_mmse_fir_interpolator intr;
00052 };
00053
00054 template<class iType,class oType>
00055 GrInterpolator<iType,oType>::GrInterpolator (int N, int M, int _phase = 0)
00056 : GrFractionalInterpolatingSigProc<iType,oType>(N, M), phase (_phase)
00057 {
00058 if (N != 10){
00059 cerr << "GrInterpolator: N must be 10\n";
00060 exit (1);
00061 }
00062 if (M < 0 || M > 10){
00063 cerr << "GrInterpolator: M must be in [1, 10]\n";
00064 exit (1);
00065 }
00066 if (phase < 0 || phase > N){
00067 cerr << "GrInterpolator: phase must be in [0, N]\n";
00068 exit (1);
00069 }
00070
00071 history = intr.ntaps () + 1;
00072 }
00073
00074 template<class iType,class oType>
00075 int
00076 GrInterpolator<iType,oType>::work (VrSampleRange output, void *ao[],
00077 VrSampleRange inputs[], void *ai[])
00078 {
00079 iType *in = ((iType **) ai)[0];
00080 oType *out = ((oType **) ao)[0];
00081
00082 assert ((output.size % iratio) == 0);
00083
00084 float mu = (float) phase / N;
00085 float mu_inc = (float) M / N;
00086
00087 unsigned ii = 0;
00088 unsigned oo = 0;
00089
00090 while (oo < output.size){
00091 out[oo++] = intr.interpolate (&in[ii], 1.0 - mu);
00092
00093
00094
00095 float s = mu + mu_inc;
00096 float f = floor (s);
00097 int incr = (int) f;
00098 mu = s - f;
00099 ii += incr;
00100 }
00101
00102 assert (mu == ((float) phase / N));
00103
00104 return output.size;
00105 }
00106
00107
00108 #endif