Changeset 695e171 for src/spectral


Ignore:
Timestamp:
Sep 6, 2015, 10:40:14 AM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
Children:
3d30b90
Parents:
65c352e (diff), 827267b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'develop' into awhitening

Location:
src/spectral
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/spectral/fft.c

    r65c352e r695e171  
    6767#warning "Using aubio in double precision with fftw3 in single precision"
    6868#endif /* HAVE_AUBIO_DOUBLE */
    69 #define real_t float 
     69#define real_t float
    7070#else /* HAVE_FFTW3F */
    7171#if !HAVE_AUBIO_DOUBLE
    7272#warning "Using aubio in single precision with fftw3 in double precision"
    7373#endif /* HAVE_AUBIO_DOUBLE */
    74 #define real_t double 
     74#define real_t double
    7575#endif /* HAVE_FFTW3F */
    7676
     
    8282// https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html
    8383#include <Accelerate/Accelerate.h>
     84
     85#if !HAVE_AUBIO_DOUBLE
     86#define aubio_vDSP_ctoz                vDSP_ctoz
     87#define aubio_vDSP_fft_zrip            vDSP_fft_zrip
     88#define aubio_vDSP_ztoc                vDSP_ztoc
     89#define aubio_vDSP_zvmags              vDSP_zvmags
     90#define aubio_vDSP_zvphas              vDSP_zvphas
     91#define aubio_vDSP_vsadd               vDSP_vsadd
     92#define aubio_vDSP_vsmul               vDSP_vsmul
     93#define aubio_vDSP_create_fftsetup     vDSP_create_fftsetup
     94#define aubio_vDSP_destroy_fftsetup    vDSP_destroy_fftsetup
     95#define aubio_DSPComplex               DSPComplex
     96#define aubio_DSPSplitComplex          DSPSplitComplex
     97#define aubio_FFTSetup                 FFTSetup
     98#define aubio_vvsqrt                   vvsqrtf
     99#else
     100#define aubio_vDSP_ctoz                vDSP_ctozD
     101#define aubio_vDSP_fft_zrip            vDSP_fft_zripD
     102#define aubio_vDSP_ztoc                vDSP_ztocD
     103#define aubio_vDSP_zvmags              vDSP_zvmagsD
     104#define aubio_vDSP_zvphas              vDSP_zvphasD
     105#define aubio_vDSP_vsadd               vDSP_vsaddD
     106#define aubio_vDSP_vsmul               vDSP_vsmulD
     107#define aubio_vDSP_create_fftsetup     vDSP_create_fftsetupD
     108#define aubio_vDSP_destroy_fftsetup    vDSP_destroy_fftsetupD
     109#define aubio_DSPComplex               DSPDoubleComplex
     110#define aubio_DSPSplitComplex          DSPDoubleSplitComplex
     111#define aubio_FFTSetup                 FFTSetupD
     112#define aubio_vvsqrt                   vvsqrt
     113#endif /* HAVE_AUBIO_DOUBLE */
    84114
    85115#else                         // using OOURA
     
    96126  real_t *in, *out;
    97127  fftw_plan pfw, pbw;
    98   fft_data_t * specdata;     /* complex spectral data */
     128  fft_data_t * specdata;      /* complex spectral data */
    99129#else
    100130#ifdef HAVE_ACCELERATE        // using ACCELERATE
    101131  int log2fftsize;
    102 #if !HAVE_AUBIO_DOUBLE
    103   FFTSetup fftSetup;
    104   DSPSplitComplex spec;
    105   float *in, *out;
    106 #else
    107   FFTSetupD fftSetup;
    108   DSPDoubleSplitComplex spec;
    109   double *in, *out;
    110 #endif
     132  aubio_FFTSetup fftSetup;
     133  aubio_DSPSplitComplex spec;
     134  smpl_t *in, *out;
    111135#else                         // using OOURA
    112136  smpl_t *in, *out;
     
    120144aubio_fft_t * new_aubio_fft (uint_t winsize) {
    121145  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
     146  if ((sint_t)winsize < 1) {
     147    AUBIO_ERR("fft: got winsize %d, but can not be < 1\n", winsize);
     148    goto beach;
     149  }
    122150#ifdef HAVE_FFTW3
    123151  uint_t i;
     
    154182  s->compspec = new_fvec(winsize);
    155183  s->log2fftsize = (uint_t)log2f(s->fft_size);
    156 #if !HAVE_AUBIO_DOUBLE
    157   s->in = AUBIO_ARRAY(float, s->fft_size);
    158   s->out = AUBIO_ARRAY(float, s->fft_size);
    159   s->spec.realp = AUBIO_ARRAY(float, s->fft_size/2);
    160   s->spec.imagp = AUBIO_ARRAY(float, s->fft_size/2);
    161   s->fftSetup = vDSP_create_fftsetup(s->log2fftsize, FFT_RADIX2);
    162 #else
    163   s->in = AUBIO_ARRAY(double, s->fft_size);
    164   s->out = AUBIO_ARRAY(double, s->fft_size);
    165   s->spec.realp = AUBIO_ARRAY(double, s->fft_size/2);
    166   s->spec.imagp = AUBIO_ARRAY(double, s->fft_size/2);
    167   s->fftSetup = vDSP_create_fftsetupD(s->log2fftsize, FFT_RADIX2);
    168 #endif
    169 #else                         // using OOURA
     184  s->in = AUBIO_ARRAY(smpl_t, s->fft_size);
     185  s->out = AUBIO_ARRAY(smpl_t, s->fft_size);
     186  s->spec.realp = AUBIO_ARRAY(smpl_t, s->fft_size/2);
     187  s->spec.imagp = AUBIO_ARRAY(smpl_t, s->fft_size/2);
     188  s->fftSetup = aubio_vDSP_create_fftsetup(s->log2fftsize, FFT_RADIX2);
     189#else                         // using OOURA
     190  if (aubio_is_power_of_two(winsize) != 1) {
     191    AUBIO_ERR("fft: can only create with sizes power of two,"
     192              " requested %d\n", winsize);
     193    goto beach;
     194  }
    170195  s->winsize = winsize;
    171196  s->fft_size = winsize / 2 + 1;
     
    179204#endif /* HAVE_FFTW3 */
    180205  return s;
     206beach:
     207  AUBIO_FREE(s);
     208  return NULL;
    181209}
    182210
     
    192220  AUBIO_FREE(s->spec.realp);
    193221  AUBIO_FREE(s->spec.imagp);
    194 #if !HAVE_AUBIO_DOUBLE
    195   vDSP_destroy_fftsetup(s->fftSetup);
    196 #else
    197   vDSP_destroy_fftsetupD(s->fftSetup);
    198 #endif
     222  aubio_vDSP_destroy_fftsetup(s->fftSetup);
    199223#else                         // using OOURA
    200224  AUBIO_FREE(s->w);
     
    219243void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
    220244  uint_t i;
     245#ifndef HAVE_MEMCPY_HACKS
    221246  for (i=0; i < s->winsize; i++) {
    222247    s->in[i] = input->data[i];
    223248  }
     249#else
     250  memcpy(s->in, input->data, s->winsize * sizeof(smpl_t));
     251#endif /* HAVE_MEMCPY_HACKS */
    224252#ifdef HAVE_FFTW3             // using FFTW3
    225253  fftw_execute(s->pfw);
     
    238266#else /* HAVE_FFTW3 */
    239267#ifdef HAVE_ACCELERATE        // using ACCELERATE
    240 #if !HAVE_AUBIO_DOUBLE
    241268  // convert real data to even/odd format used in vDSP
    242   vDSP_ctoz((DSPComplex*)s->in, 2, &s->spec, 1, s->fft_size/2);
     269  aubio_vDSP_ctoz((aubio_DSPComplex*)s->in, 2, &s->spec, 1, s->fft_size/2);
    243270  // compute the FFT
    244   vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_FORWARD);
    245 #else
    246   // convert real data to even/odd format used in vDSP
    247   vDSP_ctozD((DSPDoubleComplex*)s->in, 2, &s->spec, 1, s->fft_size/2);
    248   // compute the FFT
    249   vDSP_fft_zripD(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_FORWARD);
    250 #endif
     271  aubio_vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_FORWARD);
    251272  // convert from vDSP complex split to [ r0, r1, ..., rN, iN-1, .., i2, i1]
    252273  compspec->data[0] = s->spec.realp[0];
     
    258279  // apply scaling
    259280  smpl_t scale = 1./2.;
    260 #if !HAVE_AUBIO_DOUBLE
    261   vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size);
    262 #else
    263   vDSP_vsmulD(compspec->data, 1, &scale, compspec->data, 1, s->fft_size);
    264 #endif
     281  aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size);
    265282#else                         // using OOURA
    266283  rdft(s->winsize, 1, s->in, s->ip, s->w);
     
    305322    s->out[2 * i + 1] = compspec->data[s->winsize - i];
    306323  }
    307 #if !HAVE_AUBIO_DOUBLE
    308324  // convert to split complex format used in vDSP
    309   vDSP_ctoz((DSPComplex*)s->out, 2, &s->spec, 1, s->fft_size/2);
     325  aubio_vDSP_ctoz((aubio_DSPComplex*)s->out, 2, &s->spec, 1, s->fft_size/2);
    310326  // compute the FFT
    311   vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_INVERSE);
     327  aubio_vDSP_fft_zrip(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_INVERSE);
    312328  // convert result to real output
    313   vDSP_ztoc(&s->spec, 1, (DSPComplex*)output->data, 2, s->fft_size/2);
     329  aubio_vDSP_ztoc(&s->spec, 1, (aubio_DSPComplex*)output->data, 2, s->fft_size/2);
    314330  // apply scaling
    315331  smpl_t scale = 1.0 / s->winsize;
    316   vDSP_vsmul(output->data, 1, &scale, output->data, 1, s->fft_size);
    317 #else
    318   // convert to split complex format used in vDSP
    319   vDSP_ctozD((DSPDoubleComplex*)s->out, 2, &s->spec, 1, s->fft_size/2);
    320   // compute the FFT
    321   vDSP_fft_zripD(s->fftSetup, &s->spec, 1, s->log2fftsize, FFT_INVERSE);
    322   // convert result to real output
    323   vDSP_ztocD(&s->spec, 1, (DSPDoubleComplex*)output->data, 2, s->fft_size/2);
    324   // apply scaling
    325   smpl_t scale = 1.0 / s->winsize;
    326   vDSP_vsmulD(output->data, 1, &scale, output->data, 1, s->fft_size);
    327 #endif
     332  aubio_vDSP_vsmul(output->data, 1, &scale, output->data, 1, s->fft_size);
    328333#else                         // using OOURA
    329334  smpl_t scale = 2.0 / s->winsize;
     
    392397  uint_t i;
    393398  for (i = 0; i < compspec->length / 2 + 1; i++) {
    394     compspec->data[i] = 
     399    compspec->data[i] =
    395400      spectrum->norm[i]*COS(spectrum->phas[i]);
    396401  }
  • src/spectral/fft.h

    r65c352e r695e171  
    1919*/
    2020
    21 /** \file 
     21/** \file
    2222
    2323  Fast Fourier Transform
     
    4040
    4141/** FFT object
    42  
     42
    4343  This object computes forward and backward FFTs.
    4444
     
    5252*/
    5353aubio_fft_t * new_aubio_fft (uint_t size);
    54 /** delete FFT object 
     54/** delete FFT object
    5555
    5656  \param s fft object as returned by new_aubio_fft
     
    6262
    6363  \param s fft object as returned by new_aubio_fft
    64   \param input input signal 
    65   \param spectrum output spectrum 
     64  \param input input signal
     65  \param spectrum output spectrum
    6666
    6767*/
     
    7070
    7171  \param s fft object as returned by new_aubio_fft
    72   \param spectrum input spectrum 
    73   \param output output signal 
     72  \param spectrum input spectrum
     73  \param output output signal
    7474
    7575*/
     
    7979
    8080  \param s fft object as returned by new_aubio_fft
    81   \param input real input signal 
     81  \param input real input signal
    8282  \param compspec complex output fft real/imag
    8383
     
    8787
    8888  \param s fft object as returned by new_aubio_fft
    89   \param compspec real/imag input fft array 
    90   \param output real output array 
     89  \param compspec real/imag input fft array
     90  \param output real output array
    9191
    9292*/
    9393void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);
    9494
    95 /** convert real/imag spectrum to norm/phas spectrum 
     95/** convert real/imag spectrum to norm/phas spectrum
    9696
    97   \param compspec real/imag input fft array 
    98   \param spectrum cvec norm/phas output array 
     97  \param compspec real/imag input fft array
     98  \param spectrum cvec norm/phas output array
    9999
    100100*/
    101101void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum);
    102 /** convert real/imag spectrum to norm/phas spectrum 
     102/** convert real/imag spectrum to norm/phas spectrum
    103103
    104   \param compspec real/imag input fft array 
    105   \param spectrum cvec norm/phas output array 
     104  \param compspec real/imag input fft array
     105  \param spectrum cvec norm/phas output array
    106106
    107107*/
    108108void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec);
    109109
    110 /** compute phas spectrum from real/imag parts 
     110/** compute phas spectrum from real/imag parts
    111111
    112   \param compspec real/imag input fft array 
    113   \param spectrum cvec norm/phas output array 
     112  \param compspec real/imag input fft array
     113  \param spectrum cvec norm/phas output array
    114114
    115115*/
    116116void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum);
    117 /** compute imaginary part from the norm/phas cvec 
     117/** compute imaginary part from the norm/phas cvec
    118118
    119   \param spectrum norm/phas input array 
    120   \param compspec real/imag output fft array 
     119  \param spectrum norm/phas input array
     120  \param compspec real/imag output fft array
    121121
    122122*/
    123123void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec);
    124124
    125 /** compute norm component from real/imag parts 
     125/** compute norm component from real/imag parts
    126126
    127   \param compspec real/imag input fft array 
    128   \param spectrum cvec norm/phas output array 
     127  \param compspec real/imag input fft array
     128  \param spectrum cvec norm/phas output array
    129129
    130130*/
    131131void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum);
    132 /** compute real part from norm/phas components 
     132/** compute real part from norm/phas components
    133133
    134   \param spectrum norm/phas input array 
    135   \param compspec real/imag output fft array 
     134  \param spectrum norm/phas input array
     135  \param compspec real/imag output fft array
    136136
    137137*/
  • src/spectral/filterbank_mel.h

    r65c352e r695e171  
    5959
    6060  The filter coefficients are built according to Malcolm Slaney's Auditory
    61   Toolbox, available at http://cobweb.ecn.purdue.edu/~malcolm/interval/1998-010/
     61  Toolbox, available at http://engineering.purdue.edu/~malcolm/interval/1998-010/
    6262  (see file mfcc.m).
    6363
  • src/spectral/mfcc.h

    r65c352e r695e171  
    2222/** \file
    2323
    24   Mel-frequency cepstrum coefficients object
     24  Mel-Frequency Cepstrum Coefficients object
     25
     26  This object computes MFCC coefficients on an input cvec_t.
     27
     28  The implementation follows the specifications established by Malcolm Slaney
     29  in its Auditory Toolbox, available online (see file mfcc.m).
     30
     31  http://engineering.ecn.purdue.edu/~malcolm/interval/1998-010/
    2532
    2633  \example spectral/test-mfcc.c
  • src/spectral/phasevoc.h

    r65c352e r695e171  
    5757
    5858/** compute spectral frame
    59  
     59
    6060  This function accepts an input vector of size [hop_s]. The
    6161  analysis buffer is rotated and filled with the new data. After windowing of
     
    6464
    6565  \param pv phase vocoder object as returned by new_aubio_pvoc
    66   \param in new input signal (hop_s long) 
     66  \param in new input signal (hop_s long)
    6767  \param fftgrain output spectral frame
    6868
     
    7575  synthesis is then computed using the previously synthetised frames, and the
    7676  output stored in out.
    77  
     77
    7878  \param pv phase vocoder object as returned by new_aubio_pvoc
    7979  \param fftgrain input spectral frame
    80   \param out output signal (hop_s long) 
     80  \param out output signal (hop_s long)
    8181
    8282*/
     
    9898#ifdef __cplusplus
    9999}
    100 #endif 
     100#endif
    101101
    102102#endif /* _AUBIO_PHASEVOC_H */
  • src/spectral/tss.h

    r65c352e r695e171  
    6363
    6464/** split input into transient and steady states components
    65  
     65
    6666  \param o tss object as returned by new_aubio_tss()
    6767  \param input input spectral frame
     
    7373    cvec_t * stead);
    7474
    75 /** set transient / steady state separation threshold 
    76  
     75/** set transient / steady state separation threshold
     76
    7777  \param o tss object as returned by new_aubio_tss()
    7878  \param thrs new threshold value
     
    8282
    8383/** set parameter a, defaults to 3
    84  
     84
    8585  \param o tss object as returned by new_aubio_tss()
    8686  \param alpha new value for alpha parameter
     
    9090
    9191/** set parameter b, defaults to 3
    92  
     92
    9393  \param o tss object as returned by new_aubio_tss()
    9494  \param beta new value for beta parameter
Note: See TracChangeset for help on using the changeset viewer.