[459] | 1 | #include "fftserver.h"
|
---|
| 2 | #include <iostream.h>
|
---|
| 3 |
|
---|
| 4 | extern "C" {
|
---|
| 5 | int rffti_(int *n, float *wsave);
|
---|
| 6 | int rfftf_(int *n, float *r__, float *wsave);
|
---|
| 7 | int rfftb_(int *n, float *r__, float *wsave);
|
---|
| 8 | int dffti_(int *n, double *wsave);
|
---|
| 9 | int dfftf_(int *n, double *r__, double *wsave);
|
---|
| 10 | int dfftb_(int *n, double *r__, double *wsave);
|
---|
| 11 | int cffti_(int *n, float *wsave);
|
---|
| 12 | int cfftf_(int *n, float *c__, float *wsave);
|
---|
| 13 | int cfftb_(int *n, float *c__, float *wsave);
|
---|
| 14 | int cdffti_(int *n, double *wsave);
|
---|
| 15 | int cdfftf_(int *n, double *c__, double *wsave);
|
---|
| 16 | int cdfftb_(int *n, double *c__, double *wsave);
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | FFTServer::FFTServer()
|
---|
| 20 | {
|
---|
| 21 | sz_rfft = 0;
|
---|
| 22 | ws_rfft = NULL;
|
---|
| 23 | sz_cfft = 0;
|
---|
| 24 | ws_cfft = NULL;
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | FFTServer::~FFTServer()
|
---|
| 28 | {
|
---|
| 29 | if (ws_rfft) delete[] ws_rfft;
|
---|
| 30 | if (ws_cfft) delete[] ws_cfft;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | void FFTServer::checkint_rfft(int l)
|
---|
| 34 | {
|
---|
| 35 | if (sz_rfft == l) return;
|
---|
| 36 |
|
---|
| 37 | if (ws_rfft) delete[] ws_rfft;
|
---|
| 38 | sz_rfft = l;
|
---|
| 39 | ws_rfft = new float[2*l+15];
|
---|
| 40 | rffti_(&l, ws_rfft);
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | void FFTServer::checkint_cfft(int l)
|
---|
| 44 | {
|
---|
| 45 | if (sz_cfft == l) return;
|
---|
| 46 |
|
---|
| 47 | if (ws_cfft) delete[] ws_cfft;
|
---|
| 48 | sz_cfft = l;
|
---|
| 49 | ws_cfft = new float[4*l+15];
|
---|
| 50 | cffti_(&l, ws_cfft);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | void FFTServer::checkint_dfft(int l)
|
---|
| 54 | {
|
---|
| 55 | if (sz_dfft == l) return;
|
---|
| 56 |
|
---|
| 57 | if (ws_dfft) delete[] ws_dfft;
|
---|
| 58 | sz_dfft = l;
|
---|
| 59 | ws_dfft = new double[2*l+15];
|
---|
| 60 | dffti_(&l, ws_dfft);
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void FFTServer::checkint_cdfft(int l)
|
---|
| 64 | {
|
---|
| 65 | if (sz_cdfft == l) return;
|
---|
| 66 |
|
---|
| 67 | if (ws_cdfft) delete[] ws_cdfft;
|
---|
| 68 | sz_cdfft = l;
|
---|
| 69 | ws_cdfft = new double[4*l+15];
|
---|
| 70 | cdffti_(&l, ws_cdfft);
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | void FFTServer::fftf(int l, float* inout)
|
---|
| 74 | {
|
---|
| 75 | checkint_rfft(l);
|
---|
| 76 | rfftf_(&l, inout, ws_rfft);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | void FFTServer::fftf(int l, double* inout)
|
---|
| 80 | {
|
---|
| 81 | checkint_dfft(l);
|
---|
| 82 | dfftf_(&l, inout, ws_dfft);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | void FFTServer::fftf(int l, complex<float>* inout)
|
---|
| 86 | {
|
---|
| 87 | checkint_cfft(l);
|
---|
| 88 | float* foo = new float[2*l];
|
---|
| 89 | for (int i=0;i<l;i++){
|
---|
| 90 | foo[2*i]=inout[i].real();
|
---|
| 91 | foo[2*i+1]=inout[i].imag();
|
---|
| 92 | }
|
---|
| 93 | cfftf_(&l, foo, ws_cfft);
|
---|
| 94 | for (int i=0;i<l;i++) inout[i]= complex<float> (foo[2*i], foo[2*i+1]);
|
---|
| 95 | delete[] foo;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | void FFTServer::fftf(int l, complex<double>* inout)
|
---|
| 99 | {
|
---|
| 100 | checkint_cdfft(l);
|
---|
| 101 | double* foo = new double[2*l];
|
---|
| 102 | for (int i=0;i<l;i++){
|
---|
| 103 | foo[2*i]=inout[i].real();
|
---|
| 104 | foo[2*i+1]=inout[i].imag();
|
---|
| 105 | }
|
---|
| 106 | cdfftf_(&l, foo, ws_cdfft);
|
---|
| 107 | for (int i=0;i<l;i++) inout[i]= complex<double> (foo[2*i],foo[2*i+1]);
|
---|
| 108 | delete[] foo;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | void FFTServer::fftb(int l, float* inout)
|
---|
| 112 | {
|
---|
| 113 | checkint_rfft(l);
|
---|
| 114 | rfftb_(&l, inout, ws_rfft);
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 | void FFTServer::fftb(int l, double* inout)
|
---|
| 118 | {
|
---|
| 119 | checkint_dfft(l);
|
---|
| 120 | dfftb_(&l, inout, ws_dfft);
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | void FFTServer::fftb(int l, complex<float>* inout)
|
---|
| 124 | {
|
---|
| 125 | checkint_cfft(l);
|
---|
| 126 | float* foo = new float[2*l];
|
---|
| 127 | for (int i=0;i<l;i++){
|
---|
| 128 | foo[2*i]=inout[i].real();
|
---|
| 129 | foo[2*i+1]=inout[i].imag();
|
---|
| 130 | }
|
---|
| 131 | cfftb_(&l, foo, ws_cfft);
|
---|
| 132 | for (int i=0;i<l;i++) inout[i]=complex<float> (foo[2*i],foo[2*i+1]);
|
---|
| 133 | delete[] foo;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | void FFTServer::fftb(int l, complex<double>* inout)
|
---|
| 137 | {
|
---|
| 138 | checkint_cdfft(l);
|
---|
| 139 | double* foo = new double[2*l];
|
---|
| 140 | for (int i=0;i<l;i++){
|
---|
| 141 | foo[2*i]=inout[i].real();
|
---|
| 142 | foo[2*i+1]=inout[i].imag();
|
---|
| 143 | }
|
---|
| 144 | cdfftb_(&l, foo, ws_cdfft);
|
---|
| 145 | for (int i=0;i<l;i++) inout[i]=complex<double> (foo[2*i],foo[2*i+1]);
|
---|
| 146 | delete[] foo;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | void FFTServer::fftf(Vector& in, Vector& out)
|
---|
| 150 | {
|
---|
| 151 | int l = in.NElts();
|
---|
| 152 | /* ----- Si c'etait un Vector<float> on aurait ecrit comme ca
|
---|
| 153 | Pour le moment Vector est double, on passe donc par un tableau
|
---|
| 154 | intermediare
|
---|
| 155 | // La transformee sur le tableau de flaot se fait en place,
|
---|
| 156 | // on utilise donc out comme in-out
|
---|
| 157 | out = in;
|
---|
| 158 | fftf_float(l, out.Data() );
|
---|
| 159 | ------------------------------------------------------------- */
|
---|
| 160 | float * inout = new float[l];
|
---|
| 161 | int i;
|
---|
| 162 | for(i=0; i<l; i++) inout[i] = in(i);
|
---|
| 163 | fftf(l, inout);
|
---|
| 164 | out.Realloc(l);
|
---|
| 165 | for(i=0; i<l; i++) out(i) = inout[i];
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void FFTServer::fftb(Vector& in, Vector& out)
|
---|
| 169 | {
|
---|
| 170 | int l = in.NElts();
|
---|
| 171 | /* ----- Si c'etait un Vector<float> on aurait ecrit comme ca
|
---|
| 172 | Pour le moment Vector est double, on passe donc par un tableau
|
---|
| 173 | intermediare
|
---|
| 174 | // La transformee sur le tableau de flaot se fait en place,
|
---|
| 175 | // on utilise donc out comme in-out
|
---|
| 176 | out = in;
|
---|
| 177 | fftf_float(l, out.Data() );
|
---|
| 178 | ------------------------------------------------------------- */
|
---|
| 179 | float * inout = new float[l];
|
---|
| 180 | int i;
|
---|
| 181 | for(i=0; i<l; i++) inout[i] = in(i);
|
---|
| 182 | fftb(l, inout);
|
---|
| 183 | out.Realloc(l);
|
---|
| 184 | for(i=0; i<l; i++) out(i) = inout[i];
|
---|
| 185 | }
|
---|
| 186 |
|
---|