- Timestamp:
- Nov 17, 2011, 2:29:35 AM (13 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:
- cfaa3c4
- Parents:
- e298138
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
re298138 r729a3c0 59 59 spectral/phasevoc.c \ 60 60 spectral/fft.c \ 61 spectral/ooura_fft8g.c \ 61 62 spectral/tss.c \ 62 63 spectral/specdesc.c \ -
src/mathutils.c
re298138 r729a3c0 512 512 aubio_cleanup (void) 513 513 { 514 #if HAVE_FFTW3 514 #ifdef HAVE_FFTW3F 515 fftwf_cleanup (); 516 #else 517 #ifdef HAVE_FFTW3 515 518 fftw_cleanup (); 516 #else517 #if HAVE_FFTW3F518 fftwf_cleanup ();519 519 #endif 520 520 #endif -
src/spectral/fft.c
re298138 r729a3c0 25 25 #include "spectral/fft.h" 26 26 27 #ifdef HAVE_FFTW3 27 28 /* note that <complex.h> is not included here but only in aubio_priv.h, so that 28 29 * c++ projects can still use their own complex definition. */ … … 31 32 32 33 #ifdef HAVE_COMPLEX_H 33 #if HAVE_FFTW3F34 #ifdef HAVE_FFTW3F 34 35 /** fft data type with complex.h and fftw3f */ 35 36 #define FFTW_TYPE fftwf_complex … … 39 40 #endif 40 41 #else 41 #if HAVE_FFTW3F42 #ifdef HAVE_FFTW3F 42 43 /** fft data type without complex.h and with fftw3f */ 43 44 #define FFTW_TYPE float … … 51 52 typedef FFTW_TYPE fft_data_t; 52 53 53 #if HAVE_FFTW3F54 #ifdef HAVE_FFTW3F 54 55 #define fftw_malloc fftwf_malloc 55 56 #define fftw_free fftwf_free … … 62 63 #endif 63 64 64 #if HAVE_FFTW3F65 #if HAVE_AUBIO_DOUBLE65 #ifdef HAVE_FFTW3F 66 #ifdef HAVE_AUBIO_DOUBLE 66 67 #warning "Using aubio in double precision with fftw3 in single precision" 67 68 #endif /* HAVE_AUBIO_DOUBLE */ 68 69 #define real_t float 69 70 #else /* HAVE_FFTW3F */ 70 #if !HAVE_AUBIO_DOUBLE71 #ifndef HAVE_AUBIO_DOUBLE 71 72 #warning "Using aubio in single precision with fftw3 in double precision" 72 73 #endif /* HAVE_AUBIO_DOUBLE */ … … 77 78 pthread_mutex_t aubio_fftw_mutex = PTHREAD_MUTEX_INITIALIZER; 78 79 80 #endif /* HAVE_FFTW3 */ 81 79 82 struct _aubio_fft_t { 80 83 uint_t winsize; 81 84 uint_t fft_size; 85 #ifdef HAVE_FFTW3 82 86 real_t *in, *out; 83 87 fftw_plan pfw, pbw; 84 88 fft_data_t * specdata; /* complex spectral data */ 89 #else 90 double *in, *out; 91 double *w; 92 int *ip; 93 #endif /* HAVE_FFTW3 */ 85 94 fvec_t * compspec; 86 95 }; 87 96 88 aubio_fft_t * new_aubio_fft(uint_t winsize) { 97 #ifndef HAVE_FFTW3 98 // let's use ooura instead 99 extern void rdft(int, int, double *, int *, double *); 100 #endif 101 102 aubio_fft_t * new_aubio_fft (uint_t winsize) { 89 103 aubio_fft_t * s = AUBIO_NEW(aubio_fft_t); 90 104 uint_t i; 105 #ifdef HAVE_FFTW3 91 106 s->winsize = winsize; 92 107 /* allocate memory */ … … 115 130 s->specdata[i] = 0.; 116 131 } 132 #else 133 s->winsize = winsize; 134 s->fft_size = winsize / 2 + 1; 135 s->compspec = new_fvec(winsize); 136 s->in = AUBIO_ARRAY(double, s->fft_size); 137 s->out = AUBIO_ARRAY(double, s->fft_size); 138 s->ip = AUBIO_ARRAY(int , s->fft_size); 139 s->w = AUBIO_ARRAY(double, s->fft_size); 140 s->ip[0] = 0; 141 #endif 117 142 return s; 118 143 } … … 121 146 /* destroy data */ 122 147 del_fvec(s->compspec); 148 #ifdef HAVE_FFTW3 123 149 fftw_destroy_plan(s->pfw); 124 150 fftw_destroy_plan(s->pbw); 125 151 fftw_free(s->specdata); 152 #else /* HAVE_FFTW3 */ 153 AUBIO_FREE(s->w); 154 AUBIO_FREE(s->ip); 155 #endif /* HAVE_FFTW3 */ 126 156 AUBIO_FREE(s->out); 127 AUBIO_FREE(s->in 157 AUBIO_FREE(s->in); 128 158 AUBIO_FREE(s); 129 159 } … … 140 170 141 171 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) { 142 uint_t j; 143 for (j=0; j < s->winsize; j++) { 144 s->in[j] = input->data[j]; 145 } 172 uint_t i; 173 for (i=0; i < s->winsize; i++) { 174 s->in[i] = input->data[i]; 175 } 176 #ifdef HAVE_FFTW3 146 177 fftw_execute(s->pfw); 147 178 #ifdef HAVE_COMPLEX_H 148 179 compspec->data[0] = REAL(s->specdata[0]); 149 for ( j = 1; j < s->fft_size -1 ; j++) {150 compspec->data[ j] = REAL(s->specdata[j]);151 compspec->data[compspec->length - j] = IMAG(s->specdata[j]);180 for (i = 1; i < s->fft_size -1 ; i++) { 181 compspec->data[i] = REAL(s->specdata[i]); 182 compspec->data[compspec->length - i] = IMAG(s->specdata[i]); 152 183 } 153 184 compspec->data[s->fft_size-1] = REAL(s->specdata[s->fft_size-1]); 154 #else 155 for (j = 0; j < s->fft_size; j++) { 156 compspec->data[j] = s->specdata[j]; 157 } 158 #endif 185 #else /* HAVE_COMPLEX_H */ 186 for (i = 0; i < s->fft_size; i++) { 187 compspec->data[i] = s->specdata[i]; 188 } 189 #endif /* HAVE_COMPLEX_H */ 190 #else /* HAVE_FFTW3 */ 191 rdft(s->winsize, 1, s->in, s->ip, s->w); 192 compspec->data[0] = s->in[0]; 193 compspec->data[s->winsize / 2] = s->in[1]; 194 for (i = 1; i < s->fft_size - 1; i++) { 195 compspec->data[i] = s->in[2 * i]; 196 compspec->data[s->winsize - i] = - s->in[2 * i + 1]; 197 } 198 #endif /* HAVE_FFTW3 */ 159 199 } 160 200 161 201 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) { 162 uint_t j; 202 uint_t i; 203 #ifdef HAVE_FFTW3 163 204 const smpl_t renorm = 1./(smpl_t)s->winsize; 164 205 #ifdef HAVE_COMPLEX_H 165 206 s->specdata[0] = compspec->data[0]; 166 for ( j=1; j < s->fft_size - 1; j++) {167 s->specdata[ j] = compspec->data[j] +168 I * compspec->data[compspec->length - j];207 for (i=1; i < s->fft_size - 1; i++) { 208 s->specdata[i] = compspec->data[i] + 209 I * compspec->data[compspec->length - i]; 169 210 } 170 211 s->specdata[s->fft_size - 1] = compspec->data[s->fft_size - 1]; 171 212 #else 172 for ( j=0; j < s->fft_size; j++) {173 s->specdata[ j] = compspec->data[j];213 for (i=0; i < s->fft_size; i++) { 214 s->specdata[i] = compspec->data[i]; 174 215 } 175 216 #endif 176 217 fftw_execute(s->pbw); 177 for (j = 0; j < output->length; j++) { 178 output->data[j] = s->out[j]*renorm; 179 } 218 for (i = 0; i < output->length; i++) { 219 output->data[i] = s->out[i]*renorm; 220 } 221 #else /* HAVE_FFTW3 */ 222 smpl_t scale = 2.0 / s->winsize; 223 s->out[0] = compspec->data[0]; 224 s->out[1] = compspec->data[s->winsize / 2]; 225 for (i = 1; i < s->fft_size - 1; i++) { 226 s->out[2 * i] = compspec->data[i]; 227 s->out[2 * i + 1] = - compspec->data[s->winsize - i]; 228 } 229 rdft(s->winsize, -1, s->out, s->ip, s->w); 230 for (i=0; i < s->winsize; i++) { 231 output->data[i] = s->out[i] * scale; 232 } 233 #endif /* HAVE_FFTW3 */ 180 234 } 181 235 … … 191 245 192 246 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) { 193 uint_t j;247 uint_t i; 194 248 if (compspec->data[0] < 0) { 195 249 spectrum->phas[0] = PI; … … 197 251 spectrum->phas[0] = 0.; 198 252 } 199 for ( j=1; j < spectrum->length - 1; j++) {200 spectrum->phas[ j] = ATAN2(compspec->data[compspec->length-j],201 compspec->data[ j]);253 for (i=1; i < spectrum->length - 1; i++) { 254 spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i], 255 compspec->data[i]); 202 256 } 203 257 if (compspec->data[compspec->length/2] < 0) { … … 209 263 210 264 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) { 211 uint_t j= 0;265 uint_t i = 0; 212 266 spectrum->norm[0] = ABS(compspec->data[0]); 213 for ( j=1; j < spectrum->length - 1; j++) {214 spectrum->norm[ j] = SQRT(SQR(compspec->data[j])215 + SQR(compspec->data[compspec->length - j]) );216 } 217 spectrum->norm[spectrum->length-1] = 267 for (i=1; i < spectrum->length - 1; i++) { 268 spectrum->norm[i] = SQRT(SQR(compspec->data[i]) 269 + SQR(compspec->data[compspec->length - i]) ); 270 } 271 spectrum->norm[spectrum->length-1] = 218 272 ABS(compspec->data[compspec->length/2]); 219 273 } 220 274 221 275 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) { 222 uint_t j;223 for ( j = 1; j < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; j++) {224 compspec->data[compspec->length - j] =225 spectrum->norm[ j]*SIN(spectrum->phas[j]);276 uint_t i; 277 for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) { 278 compspec->data[compspec->length - i] = 279 spectrum->norm[i]*SIN(spectrum->phas[i]); 226 280 } 227 281 } 228 282 229 283 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) { 230 uint_t j;231 for ( j = 0; j < compspec->length / 2 + 1; j++) {232 compspec->data[ j] =233 spectrum->norm[ j]*COS(spectrum->phas[j]);234 } 235 } 284 uint_t i; 285 for (i = 0; i < compspec->length / 2 + 1; i++) { 286 compspec->data[i] = 287 spectrum->norm[i]*COS(spectrum->phas[i]); 288 } 289 } -
src/wscript_build
re298138 r729a3c0 1 uselib = ['SAMPLERATE'] 2 if 'HAVE_FFTW3' in conf.get_env(): 3 source = bld.path.ant_glob('*.c **/*.c', excl = ['**/ooura_fft8g.c']) 4 uselib += ['FFTW3', 'FFTW3F'] 5 else: 6 source = bld.path.ant_glob('*.c **/*.c') 7 1 8 # build libaubio 2 libaubio = bld.new_task_gen( 3 features = 'c cshlib', 9 bld.shlib( 4 10 includes = ['.'], 5 source = bld.path.ant_glob('*.c **/*.c'),11 source = source, 6 12 target = 'aubio', 7 uselib = ['FFTW3', 'FFTW3F', 'SAMPLERATE'], 13 lib = 'm', 14 uselib = uselib, 8 15 vnum = bld.env['LIB_VERSION']) 9 16
Note: See TracChangeset
for help on using the changeset viewer.