Changeset 729a3c0
- 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
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
configure.ac
re298138 r729a3c0 174 174 dnl Check for fftw3 (required) 175 175 dnl if we compile in double precsion, default to fftw3, else fftw3f 176 177 AC_ARG_ENABLE(fftw3, 178 AC_HELP_STRING([--enable-fftw3],[compile with fftw3 [[default=auto]]]), 179 [with_fftw3=$enableval], 180 with_fftw3="yes") 181 176 182 if test "$with_double_precision" = "yes"; then 177 183 default_fftw3f="no" 178 184 else 179 default_fftw3f="yes" 180 fi 185 default_fftw3f=$with_fftw3 186 fi 187 181 188 AC_ARG_ENABLE(fftw3f, 182 189 AC_HELP_STRING([--enable-fftw3f],[compile with fftw3f [[default=auto]]]), 183 190 [with_fftw3f=$enableval], 184 191 [with_fftw3f=$default_fftw3f]) 192 193 # check if we have fftw3f 185 194 if test "$with_fftw3f" = "yes"; then 186 195 PKG_CHECK_MODULES(FFTWLIB, fftw3f >= 3.0.0, HAVE_FFTW3F=1, HAVE_FFTW3F=0) 187 196 else 188 PKG_CHECK_MODULES(FFTWLIB, fftw3 >= 3.0.0, HAVE_FFTW3=1) 189 fi 190 if test "${HAVE_FFTW3F}" = "0"; then 191 PKG_CHECK_MODULES(FFTWLIB, fftw3 >= 3.0.0, HAVE_FFTW3=1) 192 fi 197 # check if we have fftw3 198 if test "$with_fftw3" = "yes"; then 199 PKG_CHECK_MODULES(FFTWLIB, fftw3 >= 3.0.0, HAVE_FFTW3=1, HAVE_FFTW3=0) 200 fi 201 fi 202 193 203 if test "${HAVE_FFTW3}" = "1"; then 194 204 AC_DEFINE(HAVE_FFTW3,1,[Define to enable fftw3 support]) 195 205 fi 196 206 if test "${HAVE_FFTW3F}" = "1"; then 207 AC_DEFINE(HAVE_FFTW3,1,[Define to enable fftw3 support]) 197 208 AC_DEFINE(HAVE_FFTW3F,1,[Define to enable fftw3f support]) 198 209 fi … … 264 275 echo "Summary:" 265 276 if test "${HAVE_FFTW3F}" = "1"; then 266 echo "F ftw3: yes (using fftw3f)"277 echo "FFT: using fftw3f" 267 278 else 268 279 if test "${HAVE_FFTW3}" = "1"; then 269 echo "Fft w3: yes (not using fftw3f)"270 else 271 echo "Fft w3: no (that should not happen)"280 echo "Fft: using fftw3" 281 else 282 echo "Fft: using ooura" 272 283 fi 273 284 fi -
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 -
wscript
re298138 r729a3c0 31 31 opt.add_option('--enable-double', action='store_true', default=False, 32 32 help='compile aubio in double precision mode') 33 opt.add_option('--disable-fftw', action='store_true', default=False, 34 help='compile with ooura instead of fftw') 33 35 opt.add_option('--disable-fftw3f', action='store_true', default=False, 34 36 help='compile with fftw3 instead of fftw3f') … … 86 88 conf.define('HAVE_AUBIO_DOUBLE', 0) 87 89 88 # one of fftwf or fftw3f 89 if (Options.options.disable_fftw3f == True): 90 conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0', 91 args = '--cflags --libs') 92 else: 93 # fftw3f not disabled, take most sensible one according to enable_double 94 if (Options.options.enable_double == True): 90 if (Options.options.disable_fftw == False): 91 # one of fftwf or fftw3f 92 if (Options.options.disable_fftw3f == True): 95 93 conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0', 96 94 args = '--cflags --libs') 97 95 else: 98 conf.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', 99 args = '--cflags --libs') 96 # fftw3f not disabled, take most sensible one according to enable_double 97 if (Options.options.enable_double == True): 98 conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0', 99 args = '--cflags --libs') 100 else: 101 conf.check_cfg(package = 'fftw3f', atleast_version = '3.0.0', 102 args = '--cflags --libs') 103 conf.define('HAVE_FFTW3', 1) 104 else: 105 # fftw disabled, use ooura 106 pass 100 107 101 108 # optional dependancies … … 192 199 if str(target_name).endswith('test-phasevoc-jack.c'): 193 200 this_target.includes = ['src', 'examples'] 194 this_target.use = ['aubio']195 201 this_target.uselib = ['JACK'] 196 202 this_target.target += ' examples/jackio.c'
Note: See TracChangeset
for help on using the changeset viewer.