Changeset 14e300e for src


Ignore:
Timestamp:
Oct 1, 2017, 6:11:46 PM (2 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master
Children:
b701179
Parents:
ce54752
Message:

src/spectral/fft.{c,h}: revert changes to fft.h, use ippsAtan2

Location:
src/spectral
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/fft.c

    rce54752 r14e300e  
    118118#define aubio_IppComplex               Ipp32fc
    119119#define aubio_FFTSpec                  FFTSpec_R_32f
    120 #define aubio_ippsPhas                 ippsPhase_32fc
    121120#define aubio_ippsMalloc_complex       ippsMalloc_32fc
    122121#define aubio_ippsFFTInit_R            ippsFFTInit_R_32f
     
    124123#define aubio_ippsFFTInv_CCSToR        ippsFFTInv_CCSToR_32f
    125124#define aubio_ippsFFTFwd_RToCCS        ippsFFTFwd_RToCCS_32f
     125#define aubio_ippsAtan2                ippsAtan2_32f_A21
    126126#else /* HAVE_AUBIO_DOUBLE */
    127127#define aubio_IppFloat                 Ipp64f
    128128#define aubio_IppComplex               Ipp64fc
    129129#define aubio_FFTSpec                  FFTSpec_R_64f
    130 #define aubio_ippsPhas                 ippsPhase_64fc
    131130#define aubio_ippsMalloc_complex       ippsMalloc_64fc
    132131#define aubio_ippsFFTInit_R            ippsFFTInit_R_64f
     
    134133#define aubio_ippsFFTInv_CCSToR        ippsFFTInv_CCSToR_64f
    135134#define aubio_ippsFFTFwd_RToCCS        ippsFFTFwd_RToCCS_64f
     135#define aubio_ippsAtan2                ippsAtan2_64f_A50
    136136#endif
    137137
     
    159159 
    160160#elif defined HAVE_INTEL_IPP  // using Intel IPP
    161   // mark FFT impl as Intel IPP
    162   #define INTEL_IPP_FFT 1
    163161  smpl_t *in, *out;
    164162  Ipp8u* memSpec;
     
    316314void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) {
    317315  aubio_fft_do_complex(s, input, s->compspec);
    318   aubio_fft_get_spectrum(s, s->compspec, spectrum);
     316  aubio_fft_get_spectrum(s->compspec, spectrum);
    319317}
    320318
    321319void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) {
    322   aubio_fft_get_realimag(s, spectrum, s->compspec);
     320  aubio_fft_get_realimag(spectrum, s->compspec);
    323321  aubio_fft_rdo_complex(s, s->compspec, output);
    324322}
     
    459457}
    460458
    461 void aubio_fft_get_spectrum(aubio_fft_t *s, const fvec_t * compspec, cvec_t * spectrum) {
    462   aubio_fft_get_phas(s, compspec, spectrum);
    463   aubio_fft_get_norm(s, compspec, spectrum);
    464 }
    465 
    466 void aubio_fft_get_realimag(aubio_fft_t *s, const cvec_t * spectrum, fvec_t * compspec) {
    467   aubio_fft_get_imag(s, spectrum, compspec);
    468   aubio_fft_get_real(s, spectrum, compspec);
    469 }
    470 
    471 void aubio_fft_get_phas(aubio_fft_t *s, const fvec_t * compspec, cvec_t * spectrum) {
    472 
    473 #ifdef INTEL_IPP_FFT // using Intel IPP FFT
    474   uint_t i;
    475 
    476   // convert from real imag  [ r0, 0, ..., rN, iN-1, .., i2, i1, iN-1] to complex format
    477   s->complexOut[0].re = compspec->data[0];
    478   s->complexOut[0].im = 0;
    479   s->complexOut[s->fft_size / 2].re = compspec->data[s->fft_size / 2];
    480   s->complexOut[s->fft_size / 2].im = 0.0;
    481   for (i = 1; i < spectrum->length - 1; i++) {
    482     s->complexOut[i].re = compspec->data[i];
    483     s->complexOut[i].im = compspec->data[compspec->length - i];
    484   }
    485 
    486   IppStatus status = aubio_ippsPhas(s->complexOut, spectrum->phas, spectrum->length);
    487   if (status != ippStsNoErr) {
    488     AUBIO_ERR("fft: failed to extract phase from fft. IPP error: %d\n", status);
    489   }
    490 
    491 #else                 // NOT using Intel IPP
     459void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum) {
     460  aubio_fft_get_phas(compspec, spectrum);
     461  aubio_fft_get_norm(compspec, spectrum);
     462}
     463
     464void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec) {
     465  aubio_fft_get_imag(spectrum, compspec);
     466  aubio_fft_get_real(spectrum, compspec);
     467}
     468
     469void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) {
    492470  uint_t i;
    493471  if (compspec->data[0] < 0) {
     
    496474    spectrum->phas[0] = 0.;
    497475  }
     476#if defined(HAVE_INTEL_IPP)
     477  // convert from real imag  [ r0, r1, ..., rN, iN-1, ..., i2, i1, i0]
     478  //                     to  [ r0, r1, ..., rN, i0, i1, i2, ..., iN-1]
     479  for (i = 1; i < spectrum->length / 2; i++) {
     480    ELEM_SWAP(compspec->data[compspec->length - i],
     481        compspec->data[spectrum->length + i - 1]);
     482  }
     483  aubio_ippsAtan2(compspec->data + spectrum->length,
     484      compspec->data + 1, spectrum->phas + 1, spectrum->length - 1);
     485  // revert the imaginary part back again
     486  for (i = 1; i < spectrum->length / 2; i++) {
     487    ELEM_SWAP(compspec->data[spectrum->length + i - 1],
     488        compspec->data[compspec->length - i]);
     489  }
     490#else
    498491  for (i=1; i < spectrum->length - 1; i++) {
    499492    spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i],
    500493        compspec->data[i]);
    501494  }
     495#endif
    502496  if (compspec->data[compspec->length/2] < 0) {
    503497    spectrum->phas[spectrum->length - 1] = PI;
     
    505499    spectrum->phas[spectrum->length - 1] = 0.;
    506500  }
    507 #endif
    508 }
    509 
    510 void aubio_fft_get_norm(aubio_fft_t *s, const fvec_t * compspec, cvec_t * spectrum) {
     501}
     502
     503void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) {
    511504  uint_t i = 0;
    512505  spectrum->norm[0] = ABS(compspec->data[0]);
     
    519512}
    520513
    521 void aubio_fft_get_imag(aubio_fft_t *s, const cvec_t * spectrum, fvec_t * compspec) {
     514void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) {
    522515  uint_t i;
    523516  for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) {
     
    527520}
    528521
    529 void aubio_fft_get_real(aubio_fft_t *s, const cvec_t * spectrum, fvec_t * compspec) {
     522void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec) {
    530523  uint_t i;
    531524  for (i = 0; i < compspec->length / 2 + 1; i++) {
  • src/spectral/fft.h

    rce54752 r14e300e  
    9999
    100100*/
    101 void aubio_fft_get_spectrum(aubio_fft_t *s, const fvec_t * compspec, cvec_t * spectrum);
     101void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum);
    102102/** convert real/imag spectrum to norm/phas spectrum
    103103
     
    106106
    107107*/
    108 void aubio_fft_get_realimag(aubio_fft_t *s, const cvec_t * spectrum, fvec_t * compspec);
     108void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec);
    109109
    110110/** compute phas spectrum from real/imag parts
     
    114114
    115115*/
    116 void aubio_fft_get_phas(aubio_fft_t *s, const fvec_t * compspec, cvec_t * spectrum);
     116void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum);
    117117/** compute imaginary part from the norm/phas cvec
    118118
     
    121121
    122122*/
    123 void aubio_fft_get_imag(aubio_fft_t *s, const cvec_t * spectrum, fvec_t * compspec);
     123void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec);
    124124
    125125/** compute norm component from real/imag parts
     
    129129
    130130*/
    131 void aubio_fft_get_norm(aubio_fft_t *s, const fvec_t * compspec, cvec_t * spectrum);
     131void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum);
    132132/** compute real part from norm/phas components
    133133
     
    136136
    137137*/
    138 void aubio_fft_get_real(aubio_fft_t *s, const cvec_t * spectrum, fvec_t * compspec);
     138void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec);
    139139
    140140#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.