Changeset 01d4d19
 Timestamp:
 Nov 15, 2018, 3:07:48 AM (15 months ago)
 Branches:
 feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master
 Children:
 5999ff2
 Parents:
 9ef3c6e
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

python/tests/test_fft.py
r9ef3c6e r01d4d19 143 143 assert_almost_equal ( r[1:], 0) 144 144 145 class aubio_fft_odd_sizes(TestCase): 146 147 def test_reconstruct_with_odd_size(self): 148 win_s = 29 149 self.recontruct(win_s, 'odd sizes not supported') 150 151 def test_reconstruct_with_radix15(self): 152 win_s = 2 ** 4 * 15 153 self.recontruct(win_s, 'radix 15 supported') 154 155 def test_reconstruct_with_radix5(self): 156 win_s = 2 ** 4 * 5 157 self.recontruct(win_s, 'radix 5 supported') 158 159 def test_reconstruct_with_radix3(self): 160 win_s = 2 ** 4 * 3 161 self.recontruct(win_s, 'radix 3 supported') 162 163 def recontruct(self, win_s, skipMessage): 164 try: 165 f = fft(win_s) 166 except RuntimeError: 167 self.skipTest(skipMessage) 168 input_signal = fvec(win_s) 169 input_signal[win_s//2] = 1 170 c = f(input_signal) 171 output_signal = f.rdo(c) 172 assert_almost_equal(input_signal, output_signal) 173 174 class aubio_fft_wrong_params(TestCase): 175 145 176 def test_large_input_timegrain(self): 146 177 win_s = 1024 … … 170 201 with self.assertRaises(ValueError): 171 202 f.rdo(s) 172 173 class aubio_fft_wrong_params(TestCase):174 203 175 204 def test_wrong_buf_size(self): … … 177 206 with self.assertRaises(ValueError): 178 207 fft(win_s) 179 180 def test_buf_size_not_power_of_two(self):181 # when compiled with fftw3, aubio supports non power of two fft sizes182 win_s = 320183 try:184 with self.assertRaises(RuntimeError):185 fft(win_s)186 except AssertionError:187 self.skipTest('creating aubio.fft with size %d did not fail' % win_s)188 208 189 209 def test_buf_size_too_small(self): 
src/spectral/fft.c
r9ef3c6e r01d4d19 90 90 #define aubio_vDSP_vsadd vDSP_vsadd 91 91 #define aubio_vDSP_vsmul vDSP_vsmul 92 #define aubio_vDSP_create_fftsetup vDSP_create_fftsetup93 #define aubio_vDSP_destroy_fftsetup vDSP_destroy_fftsetup94 92 #define aubio_DSPComplex DSPComplex 95 93 #define aubio_DSPSplitComplex DSPSplitComplex 96 #define aubio_FFTSetup FFTSetup 94 #define aubio_vDSP_DFT_Setup vDSP_DFT_Setup 95 #define aubio_vDSP_DFT_zrop_CreateSetup vDSP_DFT_zrop_CreateSetup 96 #define aubio_vDSP_DFT_Execute vDSP_DFT_Execute 97 #define aubio_vDSP_DFT_DestroySetup vDSP_DFT_DestroySetup 97 98 #define aubio_vvsqrt vvsqrtf 98 99 #else … … 104 105 #define aubio_vDSP_vsadd vDSP_vsaddD 105 106 #define aubio_vDSP_vsmul vDSP_vsmulD 106 #define aubio_vDSP_create_fftsetup vDSP_create_fftsetupD107 #define aubio_vDSP_destroy_fftsetup vDSP_destroy_fftsetupD108 107 #define aubio_DSPComplex DSPDoubleComplex 109 108 #define aubio_DSPSplitComplex DSPDoubleSplitComplex 110 #define aubio_FFTSetup FFTSetupD 109 #define aubio_vDSP_DFT_Setup vDSP_DFT_SetupD 110 #define aubio_vDSP_DFT_zrop_CreateSetup vDSP_DFT_zrop_CreateSetupD 111 #define aubio_vDSP_DFT_Execute vDSP_DFT_ExecuteD 112 #define aubio_vDSP_DFT_DestroySetup vDSP_DFT_DestroySetupD 111 113 #define aubio_vvsqrt vvsqrt 112 114 #endif /* HAVE_AUBIO_DOUBLE */ … … 153 155 154 156 #elif defined HAVE_ACCELERATE // using ACCELERATE 155 int log2fftsize;156 aubio_ FFTSetup fftSetup;157 aubio_vDSP_DFT_Setup fftSetupFwd; 158 aubio_vDSP_DFT_Setup fftSetupBwd; 157 159 aubio_DSPSplitComplex spec; 158 160 smpl_t *in, *out; … … 211 213 212 214 #elif defined HAVE_ACCELERATE // using ACCELERATE 215 { 216 uint_t radix = winsize; 217 uint_t order = 0; 218 while ((radix / 2) * 2 == radix) { 219 radix /= 2; 220 order++; 221 } 222 if (order < 4  (radix != 1 && radix != 3 && radix != 5 && radix != 15)) { 223 AUBIO_ERR("fft: vDSP/Accelerate supports FFT with sizes = " 224 "f * 2 ** n, where n > 4 and f in [1, 3, 5, 15], but requested %d. " 225 "Use the closest power of two, or try recompiling aubio with " 226 "enablefftw3.\n", winsize); 227 goto beach; 228 } 229 } 213 230 s>winsize = winsize; 214 231 s>fft_size = winsize; 215 232 s>compspec = new_fvec(winsize); 216 s>log2fftsize = aubio_power_of_two_order(s>fft_size);217 233 s>in = AUBIO_ARRAY(smpl_t, s>fft_size); 218 234 s>out = AUBIO_ARRAY(smpl_t, s>fft_size); 219 235 s>spec.realp = AUBIO_ARRAY(smpl_t, s>fft_size/2); 220 236 s>spec.imagp = AUBIO_ARRAY(smpl_t, s>fft_size/2); 221 s>fftSetup = aubio_vDSP_create_fftsetup(s>log2fftsize, FFT_RADIX2); 237 s>fftSetupFwd = aubio_vDSP_DFT_zrop_CreateSetup(NULL, 238 s>fft_size, vDSP_DFT_FORWARD); 239 s>fftSetupBwd = aubio_vDSP_DFT_zrop_CreateSetup(s>fftSetupFwd, 240 s>fft_size, vDSP_DFT_INVERSE); 222 241 223 242 #elif defined HAVE_INTEL_IPP // using Intel IPP … … 293 312 AUBIO_FREE(s>spec.realp); 294 313 AUBIO_FREE(s>spec.imagp); 295 aubio_vDSP_destroy_fftsetup(s>fftSetup); 314 aubio_vDSP_DFT_DestroySetup(s>fftSetupBwd); 315 aubio_vDSP_DFT_DestroySetup(s>fftSetupFwd); 296 316 297 317 #elif defined HAVE_INTEL_IPP // using Intel IPP … … 351 371 aubio_vDSP_ctoz((aubio_DSPComplex*)s>in, 2, &s>spec, 1, s>fft_size/2); 352 372 // compute the FFT 353 aubio_vDSP_fft_zrip(s>fftSetup, &s>spec, 1, s>log2fftsize, FFT_FORWARD); 373 aubio_vDSP_DFT_Execute(s>fftSetupFwd, s>spec.realp, s>spec.imagp, 374 s>spec.realp, s>spec.imagp); 354 375 // convert from vDSP complex split to [ r0, r1, ..., rN, iN1, .., i2, i1] 355 376 compspec>data[0] = s>spec.realp[0]; … … 419 440 aubio_vDSP_ctoz((aubio_DSPComplex*)s>out, 2, &s>spec, 1, s>fft_size/2); 420 441 // compute the FFT 421 aubio_vDSP_fft_zrip(s>fftSetup, &s>spec, 1, s>log2fftsize, FFT_INVERSE); 442 aubio_vDSP_DFT_Execute(s>fftSetupBwd, s>spec.realp, s>spec.imagp, 443 s>spec.realp, s>spec.imagp); 422 444 // convert result to real output 423 445 aubio_vDSP_ztoc(&s>spec, 1, (aubio_DSPComplex*)output>data, 2, s>fft_size/2); … … 494 516 } 495 517 #endif 496 if (compspec>data[compspec>length/2] < 0) { 497 spectrum>phas[spectrum>length  1] = PI; 518 #ifdef HAVE_FFTW3 519 // for even length only, make sure last element is 0 or PI 520 if (2 * (compspec>length / 2) == compspec>length) { 521 #endif 522 if (compspec>data[compspec>length/2] < 0) { 523 spectrum>phas[spectrum>length  1] = PI; 524 } else { 525 spectrum>phas[spectrum>length  1] = 0.; 526 } 527 #ifdef HAVE_FFTW3 498 528 } else { 499 spectrum>phas[spectrum>length  1] = 0.; 500 } 529 i = spectrum>length  1; 530 spectrum>phas[i] = ATAN2(compspec>data[compspec>lengthi], 531 compspec>data[i]); 532 } 533 #endif 501 534 } 502 535 … … 508 541 + SQR(compspec>data[compspec>length  i]) ); 509 542 } 510 spectrum>norm[spectrum>length1] = 511 ABS(compspec>data[compspec>length/2]); 543 #ifdef HAVE_FFTW3 544 // for even length, make sure last element is > 0 545 if (2 * (compspec>length / 2) == compspec>length) { 546 #endif 547 spectrum>norm[spectrum>length1] = 548 ABS(compspec>data[compspec>length/2]); 549 #ifdef HAVE_FFTW3 550 } else { 551 i = spectrum>length  1; 552 spectrum>norm[i] = SQRT(SQR(compspec>data[i]) 553 + SQR(compspec>data[compspec>length  i]) ); 554 } 555 #endif 512 556 } 513 557
Note: See TracChangeset
for help on using the changeset viewer.