Changeset 729a3c0


Ignore:
Timestamp:
Nov 17, 2011, 2:29:35 AM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
cfaa3c4
Parents:
e298138
Message:

add support for ooura so that aubio can be build without fftw

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • configure.ac

    re298138 r729a3c0  
    174174dnl Check for fftw3 (required)
    175175dnl if we compile in double precsion, default to fftw3, else fftw3f
     176
     177AC_ARG_ENABLE(fftw3,
     178  AC_HELP_STRING([--enable-fftw3],[compile with fftw3 [[default=auto]]]),
     179  [with_fftw3=$enableval],
     180  with_fftw3="yes")
     181
    176182if test "$with_double_precision" = "yes"; then
    177183    default_fftw3f="no"
    178184else
    179     default_fftw3f="yes"
    180 fi
     185    default_fftw3f=$with_fftw3
     186fi
     187
    181188AC_ARG_ENABLE(fftw3f,
    182189  AC_HELP_STRING([--enable-fftw3f],[compile with fftw3f [[default=auto]]]),
    183190  [with_fftw3f=$enableval],
    184191  [with_fftw3f=$default_fftw3f])
     192
     193# check if we have fftw3f
    185194if test "$with_fftw3f" = "yes"; then
    186195  PKG_CHECK_MODULES(FFTWLIB,    fftw3f >= 3.0.0,     HAVE_FFTW3F=1, HAVE_FFTW3F=0)
    187196else
    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
     198if test "$with_fftw3" = "yes"; then
     199  PKG_CHECK_MODULES(FFTWLIB,    fftw3  >= 3.0.0,     HAVE_FFTW3=1, HAVE_FFTW3=0)
     200fi
     201fi
     202
    193203if test "${HAVE_FFTW3}" = "1"; then
    194204  AC_DEFINE(HAVE_FFTW3,1,[Define to enable fftw3 support])
    195205fi
    196206if test "${HAVE_FFTW3F}" = "1"; then
     207  AC_DEFINE(HAVE_FFTW3,1,[Define to enable fftw3 support])
    197208  AC_DEFINE(HAVE_FFTW3F,1,[Define to enable fftw3f support])
    198209fi
     
    264275echo "Summary:"
    265276if test "${HAVE_FFTW3F}" = "1"; then
    266   echo "Fftw3:                   yes (using fftw3f)"
     277  echo "FFT:                     using fftw3f"
    267278else
    268279if test "${HAVE_FFTW3}" = "1"; then
    269   echo "Fftw3:                   yes (not using fftw3f)"
    270 else
    271   echo "Fftw3:                   no (that should not happen)"
     280  echo "Fft:                     using fftw3"
     281else
     282  echo "Fft:                     using ooura"
    272283fi
    273284fi
  • src/Makefile.am

    re298138 r729a3c0  
    5959        spectral/phasevoc.c \
    6060        spectral/fft.c \
     61        spectral/ooura_fft8g.c \
    6162        spectral/tss.c \
    6263        spectral/specdesc.c \
  • src/mathutils.c

    re298138 r729a3c0  
    512512aubio_cleanup (void)
    513513{
    514 #if HAVE_FFTW3
     514#ifdef HAVE_FFTW3F
     515  fftwf_cleanup ();
     516#else
     517#ifdef HAVE_FFTW3
    515518  fftw_cleanup ();
    516 #else
    517 #if HAVE_FFTW3F
    518   fftwf_cleanup ();
    519519#endif
    520520#endif
  • src/spectral/fft.c

    re298138 r729a3c0  
    2525#include "spectral/fft.h"
    2626
     27#ifdef HAVE_FFTW3
    2728/* note that <complex.h> is not included here but only in aubio_priv.h, so that
    2829 * c++ projects can still use their own complex definition. */
     
    3132
    3233#ifdef HAVE_COMPLEX_H
    33 #if HAVE_FFTW3F
     34#ifdef HAVE_FFTW3F
    3435/** fft data type with complex.h and fftw3f */
    3536#define FFTW_TYPE fftwf_complex
     
    3940#endif
    4041#else
    41 #if HAVE_FFTW3F
     42#ifdef HAVE_FFTW3F
    4243/** fft data type without complex.h and with fftw3f */
    4344#define FFTW_TYPE float
     
    5152typedef FFTW_TYPE fft_data_t;
    5253
    53 #if HAVE_FFTW3F
     54#ifdef HAVE_FFTW3F
    5455#define fftw_malloc            fftwf_malloc
    5556#define fftw_free              fftwf_free
     
    6263#endif
    6364
    64 #if HAVE_FFTW3F
    65 #if HAVE_AUBIO_DOUBLE
     65#ifdef HAVE_FFTW3F
     66#ifdef HAVE_AUBIO_DOUBLE
    6667#warning "Using aubio in double precision with fftw3 in single precision"
    6768#endif /* HAVE_AUBIO_DOUBLE */
    6869#define real_t float
    6970#else /* HAVE_FFTW3F */
    70 #if !HAVE_AUBIO_DOUBLE
     71#ifndef HAVE_AUBIO_DOUBLE
    7172#warning "Using aubio in single precision with fftw3 in double precision"
    7273#endif /* HAVE_AUBIO_DOUBLE */
     
    7778pthread_mutex_t aubio_fftw_mutex = PTHREAD_MUTEX_INITIALIZER;
    7879
     80#endif /* HAVE_FFTW3 */
     81
    7982struct _aubio_fft_t {
    8083  uint_t winsize;
    8184  uint_t fft_size;
     85#ifdef HAVE_FFTW3
    8286  real_t *in, *out;
    8387  fftw_plan pfw, pbw;
    8488  fft_data_t * specdata;     /* complex spectral data */
     89#else
     90  double *in, *out;
     91  double *w;
     92  int *ip;
     93#endif /* HAVE_FFTW3 */
    8594  fvec_t * compspec;
    8695};
    8796
    88 aubio_fft_t * new_aubio_fft(uint_t winsize) {
     97#ifndef HAVE_FFTW3
     98// let's use ooura instead
     99extern void rdft(int, int, double *, int *, double *);
     100#endif
     101
     102aubio_fft_t * new_aubio_fft (uint_t winsize) {
    89103  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    90104  uint_t i;
     105#ifdef HAVE_FFTW3
    91106  s->winsize  = winsize;
    92107  /* allocate memory */
     
    115130    s->specdata[i] = 0.;
    116131  }
     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
    117142  return s;
    118143}
     
    121146  /* destroy data */
    122147  del_fvec(s->compspec);
     148#ifdef HAVE_FFTW3
    123149  fftw_destroy_plan(s->pfw);
    124150  fftw_destroy_plan(s->pbw);
    125151  fftw_free(s->specdata);
     152#else /* HAVE_FFTW3 */
     153  AUBIO_FREE(s->w);
     154  AUBIO_FREE(s->ip);
     155#endif /* HAVE_FFTW3 */
    126156  AUBIO_FREE(s->out);
    127   AUBIO_FREE(s->in );
     157  AUBIO_FREE(s->in);
    128158  AUBIO_FREE(s);
    129159}
     
    140170
    141171void 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
    146177  fftw_execute(s->pfw);
    147178#ifdef HAVE_COMPLEX_H
    148179  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]);
    152183  }
    153184  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 */
    159199}
    160200
    161201void 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
    163204  const smpl_t renorm = 1./(smpl_t)s->winsize;
    164205#ifdef HAVE_COMPLEX_H
    165206  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];
    169210  }
    170211  s->specdata[s->fft_size - 1] = compspec->data[s->fft_size - 1];
    171212#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];
    174215  }
    175216#endif
    176217  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 */
    180234}
    181235
     
    191245
    192246void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
    193   uint_t j;
     247  uint_t i;
    194248  if (compspec->data[0] < 0) {
    195249    spectrum->phas[0] = PI;
     
    197251    spectrum->phas[0] = 0.;
    198252  }
    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]);
    202256  }
    203257  if (compspec->data[compspec->length/2] < 0) {
     
    209263
    210264void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
    211   uint_t j = 0;
     265  uint_t i = 0;
    212266  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] =
    218272    ABS(compspec->data[compspec->length/2]);
    219273}
    220274
    221275void 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]);
    226280  }
    227281}
    228282
    229283void 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  
     1uselib = ['SAMPLERATE']
     2if 'HAVE_FFTW3' in conf.get_env():
     3  source = bld.path.ant_glob('*.c **/*.c', excl = ['**/ooura_fft8g.c'])
     4  uselib += ['FFTW3', 'FFTW3F']
     5else:
     6  source = bld.path.ant_glob('*.c **/*.c')
     7
    18# build libaubio
    2 libaubio = bld.new_task_gen(
    3     features = 'c cshlib',
     9bld.shlib(
    410    includes = ['.'],
    5     source = bld.path.ant_glob('*.c **/*.c'),
     11    source = source,
    612    target = 'aubio',
    7     uselib = ['FFTW3', 'FFTW3F', 'SAMPLERATE'],
     13    lib = 'm',
     14    uselib = uselib,
    815    vnum = bld.env['LIB_VERSION'])
    916
  • wscript

    re298138 r729a3c0  
    3131  opt.add_option('--enable-double', action='store_true', default=False,
    3232      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')
    3335  opt.add_option('--disable-fftw3f', action='store_true', default=False,
    3436      help='compile with fftw3 instead of fftw3f')
     
    8688    conf.define('HAVE_AUBIO_DOUBLE', 0)
    8789
    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):
    9593      conf.check_cfg(package = 'fftw3', atleast_version = '3.0.0',
    9694          args = '--cflags --libs')
    9795    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
    100107
    101108  # optional dependancies
     
    192199    if str(target_name).endswith('test-phasevoc-jack.c'):
    193200      this_target.includes = ['src', 'examples']
    194       this_target.use = ['aubio']
    195201      this_target.uselib = ['JACK']
    196202      this_target.target += ' examples/jackio.c'
Note: See TracChangeset for help on using the changeset viewer.