- Timestamp:
- Apr 11, 2013, 2:31:40 AM (12 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- ac67de7
- Parents:
- e8bc8e9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/spectral/fft.c
re8bc8e9 r54dd945 25 25 #include "spectral/fft.h" 26 26 27 #ifdef HAVE_FFTW3 27 #ifdef HAVE_FFTW3 // using FFTW3 28 28 /* note that <complex.h> is not included here but only in aubio_priv.h, so that 29 29 * c++ projects can still use their own complex definition. */ … … 78 78 pthread_mutex_t aubio_fftw_mutex = PTHREAD_MUTEX_INITIALIZER; 79 79 80 #else 81 #ifdef HAVE_ACCELERATE // using ACCELERATE 82 // https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html 83 #include <Accelerate/Accelerate.h> 84 85 #else // using OOURA 86 // let's use ooura instead 87 extern void rdft(int, int, double *, int *, double *); 88 89 #endif /* HAVE_ACCELERATE */ 80 90 #endif /* HAVE_FFTW3 */ 81 91 … … 83 93 uint_t winsize; 84 94 uint_t fft_size; 85 #ifdef HAVE_FFTW3 95 #ifdef HAVE_FFTW3 // using FFTW3 86 96 real_t *in, *out; 87 97 fftw_plan pfw, pbw; 88 98 fft_data_t * specdata; /* complex spectral data */ 89 99 #else 100 #ifdef HAVE_ACCELERATE // using ACCELERATE 101 int log2fftsize; 102 FFTSetup fftSetup; 103 DSPSplitComplex spec; 104 float *in, *out; 105 #else // using OOURA 90 106 double *in, *out; 91 107 double *w; 92 108 int *ip; 109 #endif /* HAVE_ACCELERATE */ 93 110 #endif /* HAVE_FFTW3 */ 94 111 fvec_t * compspec; 95 112 }; 96 97 #ifndef HAVE_FFTW398 // let's use ooura instead99 extern void rdft(int, int, double *, int *, double *);100 #endif101 113 102 114 aubio_fft_t * new_aubio_fft (uint_t winsize) { … … 131 143 } 132 144 #else 145 #ifdef HAVE_ACCELERATE // using ACCELERATE 146 s->winsize = winsize; 147 s->fft_size = winsize; 148 s->compspec = new_fvec(winsize); 149 s->log2fftsize = (uint_t)log2f(s->fft_size); 150 s->in = AUBIO_ARRAY(float, s->fft_size); 151 s->out = AUBIO_ARRAY(float, s->fft_size); 152 s->spec.realp = AUBIO_ARRAY(float, s->fft_size/2); 153 s->spec.imagp = AUBIO_ARRAY(float, s->fft_size/2); 154 s->fftSetup = vDSP_create_fftsetup(s->log2fftsize, FFT_RADIX2); 155 #else // using OOURA 133 156 s->winsize = winsize; 134 157 s->fft_size = winsize / 2 + 1; … … 139 162 s->w = AUBIO_ARRAY(double, s->fft_size); 140 163 s->ip[0] = 0; 141 #endif 164 #endif /* HAVE_ACCELERATE */ 165 #endif /* HAVE_FFTW3 */ 142 166 return s; 143 167 } … … 146 170 /* destroy data */ 147 171 del_fvec(s->compspec); 148 #ifdef HAVE_FFTW3 172 #ifdef HAVE_FFTW3 // using FFTW3 149 173 fftw_destroy_plan(s->pfw); 150 174 fftw_destroy_plan(s->pbw); 151 175 fftw_free(s->specdata); 152 176 #else /* HAVE_FFTW3 */ 177 #ifdef HAVE_ACCELERATE // using ACCELERATE 178 AUBIO_FREE(s->spec.realp); 179 AUBIO_FREE(s->spec.imagp); 180 #else // using OOURA 153 181 AUBIO_FREE(s->w); 154 182 AUBIO_FREE(s->ip); 183 #endif /* HAVE_ACCELERATE */ 155 184 #endif /* HAVE_FFTW3 */ 156 185 AUBIO_FREE(s->out); … … 174 203 s->in[i] = input->data[i]; 175 204 } 176 #ifdef HAVE_FFTW3 205 #ifdef HAVE_FFTW3 // using FFTW3 177 206 fftw_execute(s->pfw); 178 207 #ifdef HAVE_COMPLEX_H … … 189 218 #endif /* HAVE_COMPLEX_H */ 190 219 #else /* HAVE_FFTW3 */ 220 #ifdef HAVE_ACCELERATE // using ACCELERATE 221 // convert real data to even/odd format used in vDSP 222 vDSP_ctoz((COMPLEX*)s->in, 2, &s->spec, 1, s->fft_size/2); 223 // compute the FFT 224 vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_FORWARD); 225 // convert from vDSP complex split to [ r0, r1, ..., rN, iN-1, .., i2, i1] 226 compspec->data[0] = s->spec.realp[0]; 227 compspec->data[s->fft_size / 2] = s->spec.imagp[0]; 228 for (i = 1; i < s->fft_size / 2; i++) { 229 compspec->data[i] = s->spec.realp[i]; 230 compspec->data[s->fft_size - i] = s->spec.imagp[i]; 231 } 232 // apply scaling 233 smpl_t scale = 1./2.; 234 vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size); 235 #else // using OOURA 191 236 rdft(s->winsize, 1, s->in, s->ip, s->w); 192 237 compspec->data[0] = s->in[0]; … … 196 241 compspec->data[s->winsize - i] = - s->in[2 * i + 1]; 197 242 } 243 #endif /* HAVE_ACCELERATE */ 198 244 #endif /* HAVE_FFTW3 */ 199 245 } … … 220 266 } 221 267 #else /* HAVE_FFTW3 */ 268 #ifdef HAVE_ACCELERATE // using ACCELERATE 269 // convert from real imag [ r0, r1, ..., rN, iN-1, .., i2, i1] 270 // to vDSP packed format [ r0, rN, r1, i1, ..., rN-1, iN-1 ] 271 s->out[0] = compspec->data[0]; 272 s->out[1] = compspec->data[s->winsize / 2]; 273 for (i = 1; i < s->fft_size / 2; i++) { 274 s->out[2 * i] = compspec->data[i]; 275 s->out[2 * i + 1] = compspec->data[s->winsize - i]; 276 } 277 // convert to split complex format used in vDSP 278 vDSP_ctoz((COMPLEX*)s->out, 2, &s->spec, 1, s->fft_size/2); 279 // compute the FFT 280 vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_INVERSE); 281 // convert result to real output 282 vDSP_ztoc(&s->spec, 1, (COMPLEX*)output->data, 2, s->fft_size/2); 283 // apply scaling 284 smpl_t scale = 1.0 / s->winsize; 285 vDSP_vsmul(output->data, 1, &scale, output->data, 1, s->fft_size); 286 #else // using OOURA 222 287 smpl_t scale = 2.0 / s->winsize; 223 288 s->out[0] = compspec->data[0]; … … 231 296 output->data[i] = s->out[i] * scale; 232 297 } 298 #endif /* HAVE_ACCELERATE */ 233 299 #endif /* HAVE_FFTW3 */ 234 300 }
Note: See TracChangeset
for help on using the changeset viewer.