Changeset 633400d for src


Ignore:
Timestamp:
Dec 5, 2018, 10:34:39 PM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/cnn, feature/crepe, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
Children:
283a619a
Parents:
5b46bc3 (diff), f19db54 (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 'master' into feature/pitchshift

Location:
src
Files:
14 added
59 edited

Legend:

Unmodified
Added
Removed
  • src/aubio.h

    r5b46bc3 r633400d  
    110110
    111111  Several examples of C programs are available in the \p examples/ and \p tests/src
    112   directories of the source tree. See more examples:
    113   @ref spectral/test-fft.c
    114   @ref spectral/test-phasevoc.c
    115   @ref onset/test-onset.c
    116   @ref pitch/test-pitch.c
    117   @ref tempo/test-tempo.c
    118   @ref test-fvec.c
    119   @ref test-cvec.c
     112  directories of the source tree.
     113
     114  Some examples:
     115  - @ref spectral/test-fft.c
     116  - @ref spectral/test-phasevoc.c
     117  - @ref onset/test-onset.c
     118  - @ref pitch/test-pitch.c
     119  - @ref tempo/test-tempo.c
     120  - @ref test-fvec.c
     121  - @ref test-cvec.c
    120122
    121123  \subsection unstable_api Unstable API
     
    138140
    139141  Latest versions, further documentation, examples, wiki, and mailing lists can
    140   be found at http://aubio.org .
     142  be found at https://aubio.org .
    141143
    142144 */
     
    181183#include "temporal/c_weighting.h"
    182184#include "spectral/fft.h"
     185#include "spectral/dct.h"
    183186#include "spectral/phasevoc.h"
    184187#include "spectral/filterbank.h"
     
    186189#include "spectral/mfcc.h"
    187190#include "spectral/specdesc.h"
     191#include "spectral/awhitening.h"
    188192#include "spectral/tss.h"
    189193#include "pitch/pitch.h"
     
    212216#include "pitch/pitchyin.h"
    213217#include "pitch/pitchyinfft.h"
     218#include "pitch/pitchyinfast.h"
    214219#include "pitch/pitchschmitt.h"
    215220#include "pitch/pitchfcomb.h"
  • src/aubio_priv.h

    r5b46bc3 r633400d  
    3434 */
    3535
     36#ifdef HAVE_CONFIG_H
    3637#include "config.h"
     38#endif
    3739
    3840#ifdef HAVE_STDLIB_H
     
    6971#endif
    7072
    71 #ifdef HAVE_ACCELERATE
     73#if defined(HAVE_ACCELERATE)
    7274#define HAVE_ATLAS 1
     75#define HAVE_BLAS 1
    7376#include <Accelerate/Accelerate.h>
    7477#elif defined(HAVE_ATLAS_CBLAS_H)
     78#elif defined(HAVE_BLAS)
     79#if defined(HAVE_ATLAS_CBLAS_H)
    7580#define HAVE_ATLAS 1
    7681#include <atlas/cblas.h>
    77 #else
    78 #undef HAVE_ATLAS
     82#elif defined(HAVE_OPENBLAS_CBLAS_H)
     83#include <openblas/cblas.h>
     84#elif defined(HAVE_CBLAS_H)
     85#include <cblas.h>
     86#endif
    7987#endif
    8088
     
    8492#define aubio_vDSP_mmov       vDSP_mmov
    8593#define aubio_vDSP_vmul       vDSP_vmul
     94#define aubio_vDSP_vsmul      vDSP_vsmul
     95#define aubio_vDSP_vsadd      vDSP_vsadd
    8696#define aubio_vDSP_vfill      vDSP_vfill
    8797#define aubio_vDSP_meanv      vDSP_meanv
     
    92102#define aubio_vDSP_minvi      vDSP_minvi
    93103#define aubio_vDSP_dotpr      vDSP_dotpr
     104#define aubio_vDSP_vclr       vDSP_vclr
    94105#else /* HAVE_AUBIO_DOUBLE */
    95106#define aubio_vDSP_mmov       vDSP_mmovD
    96107#define aubio_vDSP_vmul       vDSP_vmulD
     108#define aubio_vDSP_vsmul      vDSP_vsmulD
     109#define aubio_vDSP_vsadd      vDSP_vsaddD
    97110#define aubio_vDSP_vfill      vDSP_vfillD
    98111#define aubio_vDSP_meanv      vDSP_meanvD
     
    103116#define aubio_vDSP_minvi      vDSP_minviD
    104117#define aubio_vDSP_dotpr      vDSP_dotprD
     118#define aubio_vDSP_vclr       vDSP_vclrD
    105119#endif /* HAVE_AUBIO_DOUBLE */
    106120#endif /* HAVE_ACCELERATE */
    107121
     122#if defined(HAVE_BLAS)
     123#ifndef HAVE_AUBIO_DOUBLE
    108124#ifdef HAVE_ATLAS
    109 #ifndef HAVE_AUBIO_DOUBLE
    110125#define aubio_catlas_set      catlas_sset
     126#endif /* HAVE_ATLAS */
    111127#define aubio_cblas_copy      cblas_scopy
    112128#define aubio_cblas_swap      cblas_sswap
    113129#define aubio_cblas_dot       cblas_sdot
    114130#else /* HAVE_AUBIO_DOUBLE */
     131#ifdef HAVE_ATLAS
    115132#define aubio_catlas_set      catlas_dset
     133#endif /* HAVE_ATLAS */
    116134#define aubio_cblas_copy      cblas_dcopy
    117135#define aubio_cblas_swap      cblas_dswap
    118136#define aubio_cblas_dot       cblas_ddot
    119137#endif /* HAVE_AUBIO_DOUBLE */
    120 #endif /* HAVE_ATLAS */
    121 
    122 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS)
     138#endif /* HAVE_BLAS */
     139
     140#if defined HAVE_INTEL_IPP
     141#include <ippcore.h>
     142#include <ippvm.h>
     143#include <ipps.h>
     144#ifndef HAVE_AUBIO_DOUBLE
     145#define aubio_ippsSet         ippsSet_32f
     146#define aubio_ippsZero        ippsZero_32f
     147#define aubio_ippsCopy        ippsCopy_32f
     148#define aubio_ippsMul         ippsMul_32f
     149#define aubio_ippsMulC        ippsMulC_32f
     150#define aubio_ippsAddC        ippsAddC_32f
     151#define aubio_ippsLn          ippsLn_32f_A21
     152#define aubio_ippsMean(a,b,c) ippsMean_32f(a, b, c, ippAlgHintFast)
     153#define aubio_ippsSum(a,b,c)  ippsSum_32f(a, b, c, ippAlgHintFast)
     154#define aubio_ippsMax         ippsMax_32f
     155#define aubio_ippsMin         ippsMin_32f
     156#else /* HAVE_AUBIO_DOUBLE */
     157#define aubio_ippsSet         ippsSet_64f
     158#define aubio_ippsZero        ippsZero_64f
     159#define aubio_ippsCopy        ippsCopy_64f
     160#define aubio_ippsMul         ippsMul_64f
     161#define aubio_ippsMulC        ippsMulC_64f
     162#define aubio_ippsAddC        ippsAddC_64f
     163#define aubio_ippsLn          ippsLn_64f_A26
     164#define aubio_ippsMean        ippsMean_64f
     165#define aubio_ippsSum         ippsSum_64f
     166#define aubio_ippsMax         ippsMax_64f
     167#define aubio_ippsMin         ippsMin_64f
     168#endif /* HAVE_AUBIO_DOUBLE */
     169#endif
     170
     171#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS) && !defined(HAVE_INTEL_IPP)
    123172#define HAVE_NOOPT 1
    124 #else
    125 #undef HAVE_NOOPT
    126173#endif
    127174
     
    182229#ifdef HAVE_C99_VARARGS_MACROS
    183230#define AUBIO_ERR(...)               aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__)
     231#define AUBIO_INF(...)               aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " __VA_ARGS__)
    184232#define AUBIO_MSG(...)               aubio_log(AUBIO_LOG_MSG, __VA_ARGS__)
    185233#define AUBIO_DBG(...)               aubio_log(AUBIO_LOG_DBG, __VA_ARGS__)
    186234#define AUBIO_WRN(...)               aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " __VA_ARGS__)
    187235#else
    188 #define AUBIO_ERR(format, args...)   aubio_log(stderr, "AUBIO ERROR: " format , ##args)
    189 #define AUBIO_MSG(format, args...)   aubio_log(stdout, format , ##args)
    190 #define AUBIO_DBG(format, args...)   aubio_log(stderr, format , ##args)
    191 #define AUBIO_WRN(format, args...)   aubio_log(stderr, "AUBIO WARNING: " format, ##args)
     236#define AUBIO_ERR(format, args...)   aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " format , ##args)
     237#define AUBIO_INF(format, args...)   aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " format , ##args)
     238#define AUBIO_MSG(format, args...)   aubio_log(AUBIO_LOG_MSG, format , ##args)
     239#define AUBIO_DBG(format, args...)   aubio_log(AUBIO_LOG_DBG, format , ##args)
     240#define AUBIO_WRN(format, args...)   aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " format, ##args)
    192241#endif
    193242
     
    196245#define AUBIO_QUIT(_s)               exit(_s)
    197246#define AUBIO_SPRINTF                sprintf
     247
     248#define AUBIO_MAX_SAMPLERATE (192000*8)
     249#define AUBIO_MAX_CHANNELS 1024
    198250
    199251/* pi and 2*pi */
     
    221273#define FLOOR      floorf
    222274#define CEIL       ceilf
     275#define ATAN       atanf
    223276#define ATAN2      atan2f
    224277#else
     
    233286#define FLOOR      floor
    234287#define CEIL       ceil
     288#define ATAN       atan
    235289#define ATAN2      atan2
    236290#endif
  • src/cvec.c

    r5b46bc3 r633400d  
    8686    return;
    8787  }
    88 #ifdef HAVE_MEMCPY_HACKS
     88#if defined(HAVE_INTEL_IPP)
     89  aubio_ippsCopy(s->phas, t->phas, (int)s->length);
     90  aubio_ippsCopy(s->norm, t->norm, (int)s->length);
     91#elif defined(HAVE_MEMCPY_HACKS)
    8992  memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
    9093  memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
    91 #else /* HAVE_MEMCPY_HACKS */
     94#else
    9295  uint_t j;
    9396  for (j=0; j< t->length; j++) {
     
    9598    t->phas[j] = s->phas[j];
    9699  }
    97 #endif /* HAVE_MEMCPY_HACKS */
     100#endif
    98101}
    99102
    100 void cvec_norm_set_all (cvec_t *s, smpl_t val) {
     103void cvec_norm_set_all(cvec_t *s, smpl_t val) {
     104#if defined(HAVE_INTEL_IPP)
     105  aubio_ippsSet(val, s->norm, (int)s->length);
     106#else
    101107  uint_t j;
    102108  for (j=0; j< s->length; j++) {
    103109    s->norm[j] = val;
    104110  }
     111#endif
    105112}
    106113
    107114void cvec_norm_zeros(cvec_t *s) {
    108 #ifdef HAVE_MEMCPY_HACKS
     115#if defined(HAVE_INTEL_IPP)
     116  aubio_ippsZero(s->norm, (int)s->length);
     117#elif defined(HAVE_MEMCPY_HACKS)
    109118  memset(s->norm, 0, s->length * sizeof(smpl_t));
    110 #else /* HAVE_MEMCPY_HACKS */
     119#else
    111120  cvec_norm_set_all (s, 0.);
    112 #endif /* HAVE_MEMCPY_HACKS */
     121#endif
    113122}
    114123
     
    118127
    119128void cvec_phas_set_all (cvec_t *s, smpl_t val) {
     129#if defined(HAVE_INTEL_IPP)
     130  aubio_ippsSet(val, s->phas, (int)s->length);
     131#else
    120132  uint_t j;
    121133  for (j=0; j< s->length; j++) {
    122134    s->phas[j] = val;
    123135  }
     136#endif
    124137}
    125138
    126139void cvec_phas_zeros(cvec_t *s) {
    127 #ifdef HAVE_MEMCPY_HACKS
     140#if defined(HAVE_INTEL_IPP)
     141  aubio_ippsZero(s->phas, (int)s->length);
     142#elif defined(HAVE_MEMCPY_HACKS)
    128143  memset(s->phas, 0, s->length * sizeof(smpl_t));
    129144#else
     
    140155  cvec_phas_zeros(s);
    141156}
     157
     158void cvec_logmag(cvec_t *s, smpl_t lambda) {
     159#if defined(HAVE_INTEL_IPP)
     160  aubio_ippsMulC(s->norm, lambda, s->norm, (int)s->length);
     161  aubio_ippsAddC(s->norm, 1.0, s->norm, (int)s->length);
     162  aubio_ippsLn(s->norm, s->norm, (int)s->length);
     163#else
     164  uint_t j;
     165  for (j=0; j< s->length; j++) {
     166    s->norm[j] = LOG(lambda * s->norm[j] + 1);
     167  }
     168#endif
     169}
  • src/cvec.h

    r5b46bc3 r633400d  
    231231void cvec_zeros(cvec_t *s);
    232232
     233/** take logarithmic magnitude
     234
     235  \param s input cvec to compress
     236  \param lambda value to use for normalisation
     237
     238  \f$ S_k = log( \lambda * S_k + 1 ) \f$
     239
     240*/
     241void cvec_logmag(cvec_t *s, smpl_t lambda);
     242
    233243#ifdef __cplusplus
    234244}
  • src/fmat.c

    r5b46bc3 r633400d  
    111111  uint_t i,j;
    112112  for (i=0; i< s->height; i++) {
    113     for (j=0; j< FLOOR(s->length/2); j++) {
     113    for (j=0; j< FLOOR((smpl_t)s->length/2); j++) {
    114114      ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
    115115    }
     
    161161  assert(s->length == scale->length);
    162162#endif
    163 #if !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS)
     163#if !defined(HAVE_ACCELERATE) && !defined(HAVE_BLAS)
    164164  uint_t j;
    165165  fvec_zeros(output);
     
    170170    }
    171171  }
    172 #elif defined(HAVE_ATLAS)
     172#elif defined(HAVE_BLAS)
    173173  for (k = 0; k < s->height; k++) {
    174174    output->data[k] = aubio_cblas_dot( s->length, scale->data, 1, s->data[k], 1);
  • src/fvec.c

    r5b46bc3 r633400d  
    6161
    6262void fvec_set_all (fvec_t *s, smpl_t val) {
    63 #if !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS)
    64   uint_t j;
    65   for (j=0; j< s->length; j++) {
    66     s->data[j] = val;
    67   }
     63#if defined(HAVE_INTEL_IPP)
     64  aubio_ippsSet(val, s->data, (int)s->length);
    6865#elif defined(HAVE_ATLAS)
    6966  aubio_catlas_set(s->length, val, s->data, 1);
    7067#elif defined(HAVE_ACCELERATE)
    7168  aubio_vDSP_vfill(&val, s->data, 1, s->length);
     69#else
     70  uint_t j;
     71  for ( j = 0; j< s->length; j++ )
     72  {
     73    s->data[j] = val;
     74  }
    7275#endif
    7376}
    7477
    7578void fvec_zeros(fvec_t *s) {
    76 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
    77   fvec_set_all (s, 0.);
    78 #else
    79 #if defined(HAVE_MEMCPY_HACKS)
     79#if defined(HAVE_INTEL_IPP)
     80  aubio_ippsZero(s->data, (int)s->length);
     81#elif defined(HAVE_ACCELERATE)
     82  aubio_vDSP_vclr(s->data, 1, s->length);
     83#elif defined(HAVE_MEMCPY_HACKS)
    8084  memset(s->data, 0, s->length * sizeof(smpl_t));
    8185#else
    82   aubio_vDSP_vclr(s->data, 1, s->length);
    83 #endif
     86  fvec_set_all(s, 0.);
    8487#endif
    8588}
     
    9194void fvec_rev(fvec_t *s) {
    9295  uint_t j;
    93   for (j=0; j< FLOOR(s->length/2); j++) {
     96  for (j=0; j< FLOOR((smpl_t)s->length/2); j++) {
    9497    ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
    9598  }
     
    97100
    98101void fvec_weight(fvec_t *s, const fvec_t *weight) {
    99 #ifndef HAVE_ACCELERATE
     102  uint_t length = MIN(s->length, weight->length);
     103#if defined(HAVE_INTEL_IPP)
     104  aubio_ippsMul(s->data, weight->data, s->data, (int)length);
     105#elif defined(HAVE_ACCELERATE)
     106  aubio_vDSP_vmul( s->data, 1, weight->data, 1, s->data, 1, length );
     107#else
    100108  uint_t j;
    101   uint_t length = MIN(s->length, weight->length);
    102   for (j=0; j< length; j++) {
     109  for (j = 0; j < length; j++) {
    103110    s->data[j] *= weight->data[j];
    104111  }
    105 #else
    106   aubio_vDSP_vmul(s->data, 1, weight->data, 1, s->data, 1, s->length);
    107112#endif /* HAVE_ACCELERATE */
    108113}
    109114
    110115void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) {
    111 #ifndef HAVE_ACCELERATE
     116  uint_t length = MIN(in->length, MIN(out->length, weight->length));
     117#if defined(HAVE_INTEL_IPP)
     118  aubio_ippsMul(in->data, weight->data, out->data, (int)length);
     119#elif defined(HAVE_ACCELERATE)
     120  aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, length);
     121#else
    112122  uint_t j;
    113   uint_t length = MIN(out->length, weight->length);
    114   for (j=0; j< length; j++) {
     123  for (j = 0; j < length; j++) {
    115124    out->data[j] = in->data[j] * weight->data[j];
    116125  }
    117 #else
    118   aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, out->length);
    119 #endif /* HAVE_ACCELERATE */
     126#endif
    120127}
    121128
     
    126133    return;
    127134  }
    128 #ifdef HAVE_NOOPT
    129   uint_t j;
    130   for (j=0; j< t->length; j++) {
    131     t->data[j] = s->data[j];
    132   }
    133 #elif defined(HAVE_MEMCPY_HACKS)
    134   memcpy(t->data, s->data, t->length * sizeof(smpl_t));
    135 #elif defined(HAVE_ATLAS)
     135#if defined(HAVE_INTEL_IPP)
     136  aubio_ippsCopy(s->data, t->data, (int)s->length);
     137#elif defined(HAVE_BLAS)
    136138  aubio_cblas_copy(s->length, s->data, 1, t->data, 1);
    137139#elif defined(HAVE_ACCELERATE)
    138140  aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
     141#elif defined(HAVE_MEMCPY_HACKS)
     142  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
     143#else
     144  uint_t j;
     145  for (j = 0; j < t->length; j++) {
     146    t->data[j] = s->data[j];
     147  }
    139148#endif
    140149}
  • src/io/audio_unit.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222#ifdef HAVE_AUDIO_UNIT
    23 #include "aubio_priv.h"
    2423
    2524#include "fvec.h"
  • src/io/sink.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "fvec.h"
     
    9998  }
    10099#endif /* HAVE_WAVWRITE */
    101   AUBIO_ERROR("sink: failed creating %s with samplerate %dHz\n",
    102       uri, samplerate);
     100#if !defined(HAVE_WAVWRITE) && \
     101  !defined(HAVE_SNDFILE) && \
     102  !defined(HAVE_SINK_APPLE_AUDIO)
     103  AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
     104#endif
    103105  AUBIO_FREE(s);
    104106  return NULL;
  • src/io/sink_apple_audio.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_SINK_APPLE_AUDIO
    24 
    25 #include "aubio_priv.h"
    2624#include "fvec.h"
    2725#include "fmat.h"
    2826#include "io/sink_apple_audio.h"
     27#include "io/ioutils.h"
    2928
    3029// CFURLRef, CFURLCreateWithFileSystemPath, ...
     
    6362  s->async = false;
    6463
    65   if (uri == NULL) {
     64  if ( (uri == NULL) || (strlen(uri) < 1) ) {
    6665    AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    6766    goto beach;
     
    7473  s->channels = 0;
    7574
    76   // negative samplerate given, abort
    77   if ((sint_t)samplerate < 0) goto beach;
    7875  // zero samplerate given. do not open yet
    79   if ((sint_t)samplerate == 0) return s;
     76  if ((sint_t)samplerate == 0) {
     77    return s;
     78  }
     79  // invalid samplerate given, abort
     80  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     81    goto beach;
     82  }
    8083
    8184  s->samplerate = samplerate;
     
    9598uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate)
    9699{
    97   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     100  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     101    return AUBIO_FAIL;
     102  }
    98103  s->samplerate = samplerate;
    99104  // automatically open when both samplerate and channels have been set
     
    106111uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels)
    107112{
    108   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     113  if (aubio_io_validate_channels("sink_apple_audio", s->path, channels)) {
     114    return AUBIO_FAIL;
     115  }
    109116  s->channels = channels;
    110117  // automatically open when both samplerate and channels have been set
  • src/io/sink_sndfile.c

    r5b46bc3 r633400d  
    2020
    2121
    22 #include "config.h"
     22#include "aubio_priv.h"
    2323
    2424#ifdef HAVE_SNDFILE
     
    2626#include <sndfile.h>
    2727
    28 #include "aubio_priv.h"
    2928#include "fvec.h"
    3029#include "fmat.h"
    3130#include "io/sink_sndfile.h"
    32 
    33 #define MAX_CHANNELS 6
     31#include "io/ioutils.h"
     32
    3433#define MAX_SIZE 4096
    3534
     
    7069  s->channels = 0;
    7170
    72   // negative samplerate given, abort
    73   if ((sint_t)samplerate < 0) goto beach;
    7471  // zero samplerate given. do not open yet
    75   if ((sint_t)samplerate == 0) return s;
     72  if ((sint_t)samplerate == 0) {
     73    return s;
     74  }
     75  // invalid samplerate given, abort
     76  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     77    goto beach;
     78  }
    7679
    7780  s->samplerate = samplerate;
     
    9093uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate)
    9194{
    92   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     95  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     96    return AUBIO_FAIL;
     97  }
    9398  s->samplerate = samplerate;
    9499  // automatically open when both samplerate and channels have been set
     
    101106uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels)
    102107{
    103   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     108  if (aubio_io_validate_channels("sink_sndfile", s->path, channels)) {
     109    return AUBIO_FAIL;
     110  }
    104111  s->channels = channels;
    105112  // automatically open when both samplerate and channels have been set
     
    133140  if (s->handle == NULL) {
    134141    /* show libsndfile err msg */
    135     AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL));
     142    AUBIO_ERR("sink_sndfile: Failed opening \"%s\" with %d channels, %dHz: %s\n",
     143        s->path, s->channels, s->samplerate, sf_strerror (NULL));
    136144    return AUBIO_FAIL;
    137145  }
     
    139147  s->scratch_size = s->max_size*s->channels;
    140148  /* allocate data for de/interleaving reallocated when needed. */
    141   if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
     149  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
     150    abort();
    142151    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
    143         s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
     152        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    144153    return AUBIO_FAIL;
    145154  }
  • src/io/sink_wavwrite.c

    r5b46bc3 r633400d  
    2020
    2121
    22 #include "config.h"
     22#include "aubio_priv.h"
    2323
    2424#ifdef HAVE_WAVWRITE
    2525
    26 #include "aubio_priv.h"
    2726#include "fvec.h"
    2827#include "fmat.h"
    2928#include "io/sink_wavwrite.h"
     29#include "io/ioutils.h"
    3030
    3131#include <errno.h>
    3232
    33 #define MAX_CHANNELS 6
    3433#define MAX_SIZE 4096
    3534
     
    105104  s->channels = 0;
    106105
    107   // negative samplerate given, abort
    108   if ((sint_t)samplerate < 0) goto beach;
    109106  // zero samplerate given. do not open yet
    110   if ((sint_t)samplerate == 0) return s;
    111   // samplerate way too large, fail
    112   if ((sint_t)samplerate > 192000 * 4) goto beach;
     107  if ((sint_t)samplerate == 0) {
     108    return s;
     109  }
     110  // invalid samplerate given, abort
     111  if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) {
     112    goto beach;
     113  }
    113114
    114115  s->samplerate = samplerate;
     
    130131uint_t aubio_sink_wavwrite_preset_samplerate(aubio_sink_wavwrite_t *s, uint_t samplerate)
    131132{
    132   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     133  if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) {
     134    return AUBIO_FAIL;
     135  }
    133136  s->samplerate = samplerate;
    134137  // automatically open when both samplerate and channels have been set
     
    141144uint_t aubio_sink_wavwrite_preset_channels(aubio_sink_wavwrite_t *s, uint_t channels)
    142145{
    143   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     146  if (aubio_io_validate_channels("sink_wavwrite", s->path, channels)) {
     147    return AUBIO_FAIL;
     148  }
    144149  s->channels = channels;
    145150  // automatically open when both samplerate and channels have been set
     
    214219  s->scratch_size = s->max_size * s->channels;
    215220  /* allocate data for de/interleaving reallocated when needed. */
    216   if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
     221  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
    217222    AUBIO_ERR("sink_wavwrite: %d x %d exceeds SIZE maximum buffer size %d\n",
    218         s->max_size, s->channels, MAX_SIZE * MAX_CHANNELS);
     223        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    219224    goto beach;
    220225  }
  • src/io/source.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "fvec.h"
     
    116115  }
    117116#endif /* HAVE_WAVREAD */
    118   AUBIO_ERROR("source: failed creating aubio source with %s"
    119      " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
     117#if !defined(HAVE_WAVREAD) && \
     118  !defined(HAVE_LIBAV) && \
     119  !defined(HAVE_SOURCE_APPLE_AUDIO) && \
     120  !defined(HAVE_SNDFILE)
     121  AUBIO_ERROR("source: failed creating with %s at %dHz with hop size %d"
     122     " (no source built-in)\n", uri, samplerate, hop_size);
     123#endif
    120124  AUBIO_FREE(s);
    121125  return NULL;
  • src/io/source_apple_audio.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_SOURCE_APPLE_AUDIO
    2424
    25 #include "aubio_priv.h"
    2625#include "fvec.h"
    2726#include "fmat.h"
     
    281280{
    282281  OSStatus err = noErr;
    283   if (!s->audioFile) { return AUBIO_FAIL; }
     282  if (!s->audioFile) { return AUBIO_OK; }
    284283  err = ExtAudioFileDispose(s->audioFile);
    285284  s->audioFile = NULL;
  • src/io/source_avcodec.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 
    22 #include "config.h"
     21#include "aubio_priv.h"
    2322
    2423#ifdef HAVE_LIBAV
     24
     25#include <libavcodec/avcodec.h>
     26#include <libavformat/avformat.h>
     27#if defined(HAVE_SWRESAMPLE)
     28#include <libswresample/swresample.h>
     29#elif defined(HAVE_AVRESAMPLE)
     30#include <libavresample/avresample.h>
     31#endif
     32#include <libavutil/opt.h>
     33#include <stdlib.h>
    2534
    2635// determine whether we use libavformat from ffmpeg or from libav
    2736#define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 )
    28 // max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through 57.2.100
     37// max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 -> 57.2.100
    2938#define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \
    3039      (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \
     
    3342      )
    3443
    35 #include <libavcodec/avcodec.h>
    36 #include <libavformat/avformat.h>
    37 #include <libavresample/avresample.h>
    38 #include <libavutil/opt.h>
    39 #include <stdlib.h>
     44// backward compatibility with libavcodec55
     45#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,0,0)
     46#define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
     47#endif
     48
     49#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
     50#warning "libavcodec < 56 is deprecated"
     51#define av_frame_alloc  avcodec_alloc_frame
     52#define av_frame_free avcodec_free_frame
     53#define av_packet_unref av_free_packet
     54#endif
    4055
    4156#include "aubio_priv.h"
     
    4459#include "source_avcodec.h"
    4560
     61#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(56, 56, 0)
    4662#define AUBIO_AVCODEC_MAX_BUFFER_SIZE FF_MIN_BUFFER_SIZE
     63#else
     64#define AUBIO_AVCODEC_MAX_BUFFER_SIZE AV_INPUT_BUFFER_MIN_SIZE
     65#endif
    4766
    4867struct _aubio_source_avcodec_t {
     
    6079  AVCodecContext *avCodecCtx;
    6180  AVFrame *avFrame;
     81  AVPacket avPacket;
     82#ifdef HAVE_AVRESAMPLE
    6283  AVAudioResampleContext *avr;
    63   float *output;
     84#elif defined(HAVE_SWRESAMPLE)
     85  SwrContext *avr;
     86#endif
     87  smpl_t *output;
    6488  uint_t read_samples;
    6589  uint_t read_index;
    6690  sint_t selected_stream;
    6791  uint_t eof;
    68   uint_t multi;
    6992};
    7093
    71 // hack to create or re-create the context the first time _do or _do_multi is called
    72 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi);
    73 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples);
     94// create or re-create the context when _do or _do_multi is called
     95void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s);
     96// actually read a frame
     97void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
     98    uint_t * read_samples);
    7499
    75100uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s);
     
    88113
    89114
    90 aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) {
     115aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path,
     116    uint_t samplerate, uint_t hop_size) {
    91117  aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
     118  AVFormatContext *avFormatCtx = s->avFormatCtx;
     119  AVCodecContext *avCodecCtx = s->avCodecCtx;
     120  AVFrame *avFrame = s->avFrame;
     121  sint_t selected_stream = -1;
     122#if FF_API_LAVF_AVCTX
     123  AVCodecParameters *codecpar;
     124#endif
     125  AVCodec *codec;
     126  uint_t i;
    92127  int err;
    93128  if (path == NULL) {
     
    96131  }
    97132  if ((sint_t)samplerate < 0) {
    98     AUBIO_ERR("source_avcodec: Can not open %s with samplerate %d\n", path, samplerate);
     133    AUBIO_ERR("source_avcodec: Can not open %s with samplerate %d\n",
     134        path, samplerate);
    99135    goto beach;
    100136  }
    101137  if ((sint_t)hop_size <= 0) {
    102     AUBIO_ERR("source_avcodec: Can not open %s with hop_size %d\n", path, hop_size);
     138    AUBIO_ERR("source_avcodec: Can not open %s with hop_size %d\n",
     139        path, hop_size);
    103140    goto beach;
    104141  }
     
    111148  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    112149
     150#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58,0,0)
    113151  // register all formats and codecs
    114152  av_register_all();
     153#endif
    115154
    116155  if (aubio_source_avcodec_has_network_url(s)) {
     
    119158
    120159  // try opening the file and get some info about it
    121   AVFormatContext *avFormatCtx = s->avFormatCtx;
    122160  avFormatCtx = NULL;
    123161  if ( (err = avformat_open_input(&avFormatCtx, s->path, NULL, NULL) ) < 0 ) {
     
    139177    char errorstr[256];
    140178    av_strerror (err, errorstr, sizeof(errorstr));
    141     AUBIO_ERR("source_avcodec: Could not find stream information " "for %s (%s)\n", s->path,
    142         errorstr);
     179    AUBIO_ERR("source_avcodec: Could not find stream information "
     180        "for %s (%s)\n", s->path, errorstr);
    143181    goto beach;
    144182  }
     
    148186
    149187  // look for the first audio stream
    150   uint_t i;
    151   sint_t selected_stream = -1;
    152188  for (i = 0; i < avFormatCtx->nb_streams; i++) {
     189#if FF_API_LAVF_AVCTX
     190    if (avFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
     191#else
    153192    if (avFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
     193#endif
    154194      if (selected_stream == -1) {
    155195        selected_stream = i;
     
    167207  s->selected_stream = selected_stream;
    168208
    169   AVCodecContext *avCodecCtx = s->avCodecCtx;
     209#if FF_API_LAVF_AVCTX
     210  codecpar = avFormatCtx->streams[selected_stream]->codecpar;
     211  if (codecpar == NULL) {
     212    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
     213    goto beach;
     214  }
     215  codec = avcodec_find_decoder(codecpar->codec_id);
     216
     217  /* Allocate a codec context for the decoder */
     218  avCodecCtx = avcodec_alloc_context3(codec);
     219  if (!avCodecCtx) {
     220    AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context "
     221        "for path %s\n", av_get_media_type_string(AVMEDIA_TYPE_AUDIO),
     222        s->path);
     223    goto beach;
     224  }
     225#else
    170226  avCodecCtx = avFormatCtx->streams[selected_stream]->codec;
    171   AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id);
     227  codec = avcodec_find_decoder(avCodecCtx->codec_id);
     228#endif
    172229  if (codec == NULL) {
    173230    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
    174231    goto beach;
    175232  }
     233
     234#if FF_API_LAVF_AVCTX
     235  /* Copy codec parameters from input stream to output codec context */
     236  if ((err = avcodec_parameters_to_context(avCodecCtx, codecpar)) < 0) {
     237    AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to "
     238        "decoder context for %s\n",
     239        av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path);
     240    goto beach;
     241  }
     242#endif
    176243
    177244  if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) {
    178245    char errorstr[256];
    179246    av_strerror (err, errorstr, sizeof(errorstr));
    180     AUBIO_ERR("source_avcodec: Could not load codec for %s (%s)\n", s->path, errorstr);
     247    AUBIO_ERR("source_avcodec: Could not load codec for %s (%s)\n", s->path,
     248        errorstr);
    181249    goto beach;
    182250  }
     
    199267  }
    200268
    201   AVFrame *avFrame = s->avFrame;
    202269  avFrame = av_frame_alloc();
    203270  if (!avFrame) {
     
    206273
    207274  /* allocate output for avr */
    208   s->output = (float *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(float));
     275  s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE
     276      * sizeof(smpl_t));
    209277
    210278  s->read_samples = 0;
     
    215283  s->avFrame = avFrame;
    216284
    217   // default to mono output
    218   aubio_source_avcodec_reset_resampler(s, 0);
     285  aubio_source_avcodec_reset_resampler(s);
     286
     287  if (s->avr == NULL) goto beach;
    219288
    220289  s->eof = 0;
    221   s->multi = 0;
    222290
    223291  //av_log_set_level(AV_LOG_QUIET);
     
    232300}
    233301
    234 void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi) {
    235   if ( (multi != s->multi) || (s->avr == NULL) ) {
     302void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s)
     303{
     304  // create or reset resampler to/from mono/multi-channel
     305  if ( s->avr == NULL ) {
     306    int err;
    236307    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    237     uint_t output_channels = multi ? s->input_channels : 1;
    238     int64_t output_layout = av_get_default_channel_layout(output_channels);
    239     if (s->avr != NULL) {
    240       avresample_close( s->avr );
    241       av_free ( s->avr );
    242       s->avr = NULL;
    243     }
    244     AVAudioResampleContext *avr = s->avr;
    245     avr = avresample_alloc_context();
    246 
    247     av_opt_set_int(avr, "in_channel_layout",  input_layout,           0);
    248     av_opt_set_int(avr, "out_channel_layout", output_layout,          0);
    249     av_opt_set_int(avr, "in_sample_rate",     s->input_samplerate,    0);
    250     av_opt_set_int(avr, "out_sample_rate",    s->samplerate,          0);
     308    int64_t output_layout = av_get_default_channel_layout(s->input_channels);
     309#ifdef HAVE_AVRESAMPLE
     310    AVAudioResampleContext *avr = avresample_alloc_context();
     311#elif defined(HAVE_SWRESAMPLE)
     312    SwrContext *avr = swr_alloc();
     313#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
     314
     315    av_opt_set_int(avr, "in_channel_layout",  input_layout,              0);
     316    av_opt_set_int(avr, "out_channel_layout", output_layout,             0);
     317    av_opt_set_int(avr, "in_sample_rate",     s->input_samplerate,       0);
     318    av_opt_set_int(avr, "out_sample_rate",    s->samplerate,             0);
    251319    av_opt_set_int(avr, "in_sample_fmt",      s->avCodecCtx->sample_fmt, 0);
    252     av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLT,      0);
    253     int err;
    254     if ( ( err = avresample_open(avr) ) < 0) {
     320#if HAVE_AUBIO_DOUBLE
     321    av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_DBL,         0);
     322#else
     323    av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLT,         0);
     324#endif
     325    // TODO: use planar?
     326    //av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLTP,      0);
     327#ifdef HAVE_AVRESAMPLE
     328    if ( ( err = avresample_open(avr) ) < 0)
     329#elif defined(HAVE_SWRESAMPLE)
     330    if ( ( err = swr_init(avr) ) < 0)
     331#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
     332    {
    255333      char errorstr[256];
    256334      av_strerror (err, errorstr, sizeof(errorstr));
    257       AUBIO_ERR("source_avcodec: Could not open AVAudioResampleContext for %s (%s)\n",
    258           s->path, errorstr);
    259       //goto beach;
     335      AUBIO_ERR("source_avcodec: Could not open resampling context"
     336         " for %s (%s)\n", s->path, errorstr);
    260337      return;
    261338    }
    262339    s->avr = avr;
    263     s->multi = multi;
    264   }
    265 }
    266 
    267 void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples) {
     340  }
     341}
     342
     343void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s,
     344    uint_t * read_samples)
     345{
    268346  AVFormatContext *avFormatCtx = s->avFormatCtx;
    269347  AVCodecContext *avCodecCtx = s->avCodecCtx;
    270348  AVFrame *avFrame = s->avFrame;
    271   AVPacket avPacket;
     349  AVPacket avPacket = s->avPacket;
     350#ifdef HAVE_AVRESAMPLE
     351  AVAudioResampleContext *avr = s->avr;
     352#elif defined(HAVE_SWRESAMPLE)
     353  SwrContext *avr = s->avr;
     354#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
     355  int got_frame = 0;
     356#ifdef HAVE_AVRESAMPLE
     357  int in_linesize = 0;
     358  int in_samples = avFrame->nb_samples;
     359  int out_linesize = 0;
     360  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
     361  int out_samples = 0;
     362#elif defined(HAVE_SWRESAMPLE)
     363  int in_samples = avFrame->nb_samples;
     364  int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     365  int out_samples = 0;
     366#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
     367  smpl_t *output = s->output;
     368#ifndef FF_API_LAVF_AVCTX
     369  int len = 0;
     370#else
     371  int ret = 0;
     372#endif
    272373  av_init_packet (&avPacket);
    273   AVAudioResampleContext *avr = s->avr;
    274   float *output = s->output;
    275374  *read_samples = 0;
    276375
     
    285384      char errorstr[256];
    286385      av_strerror (err, errorstr, sizeof(errorstr));
    287       AUBIO_ERR("Could not read frame in %s (%s)\n", s->path, errorstr);
     386      AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n",
     387          s->path, errorstr);
     388      s->eof = 1;
    288389      goto beach;
    289390    }
    290391  } while (avPacket.stream_index != s->selected_stream);
    291392
    292   int got_frame = 0;
    293   int len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
     393#if FF_API_LAVF_AVCTX
     394  ret = avcodec_send_packet(avCodecCtx, &avPacket);
     395  if (ret < 0 && ret != AVERROR_EOF) {
     396    AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path);
     397    goto beach;
     398  }
     399  ret = avcodec_receive_frame(avCodecCtx, avFrame);
     400  if (ret >= 0) {
     401    got_frame = 1;
     402  }
     403  if (ret < 0) {
     404    if (ret == AVERROR(EAGAIN)) {
     405      //AUBIO_WRN("source_avcodec: output is not available right now - "
     406      //    "user must try to send new input\n");
     407      goto beach;
     408    } else if (ret == AVERROR_EOF) {
     409      AUBIO_WRN("source_avcodec: the decoder has been fully flushed, "
     410          "and there will be no more output frames\n");
     411    } else {
     412      AUBIO_ERR("source_avcodec: decoding errors on %s\n", s->path);
     413      goto beach;
     414    }
     415  }
     416#else
     417  len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
    294418
    295419  if (len < 0) {
    296     AUBIO_ERR("Error while decoding %s\n", s->path);
    297     goto beach;
    298   }
     420    AUBIO_ERR("source_avcodec: error while decoding %s\n", s->path);
     421    goto beach;
     422  }
     423#endif
    299424  if (got_frame == 0) {
    300     //AUBIO_ERR("Could not get frame for (%s)\n", s->path);
    301     goto beach;
    302   }
    303 
    304   int in_linesize = 0;
     425    AUBIO_WRN("source_avcodec: did not get a frame when reading %s\n",
     426        s->path);
     427    goto beach;
     428  }
     429
     430#if LIBAVUTIL_VERSION_MAJOR > 52
     431  if (avFrame->channels != (sint_t)s->input_channels) {
     432    AUBIO_WRN ("source_avcodec: trying to read from %d channel(s),"
     433        "but configured for %d; is '%s' corrupt?\n",
     434        avFrame->channels, s->input_channels, s->path);
     435    goto beach;
     436  }
     437#else
     438#warning "avutil < 53 is deprecated, crashes might occur on corrupt files"
     439#endif
     440
     441#ifdef HAVE_AVRESAMPLE
     442  in_linesize = 0;
    305443  av_samples_get_buffer_size(&in_linesize, avCodecCtx->channels,
    306444      avFrame->nb_samples, avCodecCtx->sample_fmt, 1);
    307   int in_samples = avFrame->nb_samples;
    308   int out_linesize = 0;
    309   int max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
    310   int out_samples = avresample_convert ( avr,
     445  in_samples = avFrame->nb_samples;
     446  out_linesize = 0;
     447  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE;
     448  out_samples = avresample_convert ( avr,
    311449        (uint8_t **)&output, out_linesize, max_out_samples,
    312450        (uint8_t **)avFrame->data, in_linesize, in_samples);
     451#elif defined(HAVE_SWRESAMPLE)
     452  in_samples = avFrame->nb_samples;
     453  max_out_samples = AUBIO_AVCODEC_MAX_BUFFER_SIZE / avCodecCtx->channels;
     454  out_samples = swr_convert( avr,
     455      (uint8_t **)&output, max_out_samples,
     456      (const uint8_t **)avFrame->data, in_samples);
     457#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    313458  if (out_samples <= 0) {
    314     //AUBIO_ERR("No sample found while converting frame (%s)\n", s->path);
     459    AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n",
     460        s->path);
    315461    goto beach;
    316462  }
     
    322468  s->avCodecCtx = avCodecCtx;
    323469  s->avFrame = avFrame;
     470#if defined(HAVE_AVRESAMPLE) || defined(HAVE_SWRESAMPLE)
    324471  s->avr = avr;
     472#endif /* HAVE_AVRESAMPLE || HAVE_SWRESAMPLE */
    325473  s->output = output;
    326474
     
    328476}
    329477
    330 void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){
    331   if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);
    332   uint_t i;
     478void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data,
     479    uint_t * read) {
     480  uint_t i, j;
    333481  uint_t end = 0;
    334482  uint_t total_wrote = 0;
     
    336484    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
    337485    for (i = 0; i < end; i++) {
    338       read_data->data[i + total_wrote] = s->output[i + s->read_index];
     486      read_data->data[i + total_wrote] = 0.;
     487      for (j = 0; j < s->input_channels; j++) {
     488        read_data->data[i + total_wrote] +=
     489          s->output[(i + s->read_index) * s->input_channels + j];
     490      }
     491      read_data->data[i + total_wrote] *= 1./s->input_channels;
    339492    }
    340493    total_wrote += end;
     
    352505  }
    353506  if (total_wrote < s->hop_size) {
    354     for (i = end; i < s->hop_size; i++) {
     507    for (i = total_wrote; i < s->hop_size; i++) {
    355508      read_data->data[i] = 0.;
    356509    }
     
    359512}
    360513
    361 void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, fmat_t * read_data, uint_t * read){
    362   if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);
     514void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s,
     515    fmat_t * read_data, uint_t * read) {
    363516  uint_t i,j;
    364517  uint_t end = 0;
     
    387540  if (total_wrote < s->hop_size) {
    388541    for (j = 0; j < read_data->height; j++) {
    389       for (i = end; i < s->hop_size; i++) {
     542      for (i = total_wrote; i < s->hop_size; i++) {
    390543        read_data->data[j][i] = 0.;
    391544      }
     
    404557
    405558uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t * s, uint_t pos) {
    406   int64_t resampled_pos = (uint_t)ROUND(pos * (s->input_samplerate * 1. / s->samplerate));
     559  int64_t resampled_pos =
     560    (uint_t)ROUND(pos * (s->input_samplerate * 1. / s->samplerate));
    407561  int64_t min_ts = MAX(resampled_pos - 2000, 0);
    408562  int64_t max_ts = MIN(resampled_pos + 2000, INT64_MAX);
    409563  int seek_flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_ANY;
    410   int ret = avformat_seek_file(s->avFormatCtx, s->selected_stream,
     564  int ret = AUBIO_FAIL;
     565  if (s->avFormatCtx != NULL && s->avr != NULL) {
     566    ret = AUBIO_OK;
     567  } else {
     568    AUBIO_ERR("source_avcodec: failed seeking in %s (file not opened?)",
     569        s->path);
     570    return ret;
     571  }
     572  if ((sint_t)pos < 0) {
     573    AUBIO_ERR("source_avcodec: could not seek %s at %d (seeking position"
     574       " should be >= 0)\n", s->path, pos);
     575    return AUBIO_FAIL;
     576  }
     577  ret = avformat_seek_file(s->avFormatCtx, s->selected_stream,
    411578      min_ts, resampled_pos, max_ts, seek_flags);
    412579  if (ret < 0) {
    413     AUBIO_ERR("Failed seeking to %d in file %s", pos, s->path);
     580    AUBIO_ERR("source_avcodec: failed seeking to %d in file %s",
     581        pos, s->path);
    414582  }
    415583  // reset read status
     
    417585  s->read_index = 0;
    418586  s->read_samples = 0;
     587#ifdef HAVE_AVRESAMPLE
    419588  // reset the AVAudioResampleContext
    420589  avresample_close(s->avr);
    421590  avresample_open(s->avr);
     591#elif defined(HAVE_SWRESAMPLE)
     592  swr_close(s->avr);
     593  swr_init(s->avr);
     594#endif
    422595  return ret;
    423596}
     
    433606uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
    434607  if (s->avr != NULL) {
     608#ifdef HAVE_AVRESAMPLE
    435609    avresample_close( s->avr );
     610#elif defined(HAVE_SWRESAMPLE)
     611    swr_close ( s->avr );
     612#endif
    436613    av_free ( s->avr );
    437614  }
    438615  s->avr = NULL;
    439616  if (s->avCodecCtx != NULL) {
     617#ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED
     618    avcodec_free_context( &s->avCodecCtx );
     619#else
    440620    avcodec_close ( s->avCodecCtx );
     621#endif
    441622  }
    442623  s->avCodecCtx = NULL;
    443624  if (s->avFormatCtx != NULL) {
    444     avformat_close_input ( &(s->avFormatCtx) );
    445   }
    446   s->avFormatCtx = NULL;
     625    avformat_close_input(&s->avFormatCtx);
     626    s->avFormatCtx = NULL;
     627  }
     628  av_packet_unref(&s->avPacket);
    447629  return AUBIO_OK;
    448630}
     
    458640    av_frame_free( &(s->avFrame) );
    459641  }
    460   if (s->path) AUBIO_FREE(s->path);
    461642  s->avFrame = NULL;
     643  if (s->path) {
     644    AUBIO_FREE(s->path);
     645  }
     646  s->path = NULL;
    462647  AUBIO_FREE(s);
    463648}
  • src/io/source_sndfile.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 
    22 #include "config.h"
     21#include "aubio_priv.h"
    2322
    2423#ifdef HAVE_SNDFILE
     
    2625#include <sndfile.h>
    2726
    28 #include "aubio_priv.h"
    2927#include "fvec.h"
    3028#include "fmat.h"
     
    3331#include "temporal/resampler.h"
    3432
    35 #define MAX_CHANNELS 6
    3633#define MAX_SIZE 4096
    37 #define MAX_SAMPLES MAX_CHANNELS * MAX_SIZE
     34#define MAX_SAMPLES AUBIO_MAX_CHANNELS * MAX_SIZE
    3835
    3936#if !HAVE_AUBIO_DOUBLE
     
    141138    if (s->ratio > 1) {
    142139      // we would need to add a ring buffer for these
    143       if ( (uint_t)(s->input_hop_size * s->ratio + .5)  != s->hop_size ) {
     140      if ( (uint_t)FLOOR(s->input_hop_size * s->ratio + .5)  != s->hop_size ) {
    144141        AUBIO_ERR("source_sndfile: can not upsample %s from %d to %d\n", s->path,
    145142            s->input_samplerate, s->samplerate);
     
    298295uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) {
    299296  uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio);
    300   sf_count_t sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET);
     297  sf_count_t sf_ret;
     298  if (s->handle == NULL) {
     299    AUBIO_ERR("source_sndfile: failed seeking in %s (file not opened?)\n",
     300        s->path);
     301    return AUBIO_FAIL;
     302  }
     303  if ((sint_t)pos < 0) {
     304    AUBIO_ERR("source_sndfile: could not seek %s at %d (seeking position"
     305       " should be >= 0)\n", s->path, pos);
     306    return AUBIO_FAIL;
     307  }
     308  sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET);
    301309  if (sf_ret == -1) {
    302310    AUBIO_ERR("source_sndfile: Failed seeking %s at %d: %s\n", s->path, pos, sf_strerror (NULL));
     
    313321uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s) {
    314322  if (!s->handle) {
    315     return AUBIO_FAIL;
     323    return AUBIO_OK;
    316324  }
    317325  if(sf_close(s->handle)) {
     
    319327    return AUBIO_FAIL;
    320328  }
     329  s->handle = NULL;
    321330  return AUBIO_OK;
    322331}
  • src/io/source_wavread.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_WAVREAD
    2424
    25 #include "aubio_priv.h"
    2625#include "fvec.h"
    2726#include "fmat.h"
     
    7776  aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t);
    7877  size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44;
    79   unsigned char buf[5];
     78  unsigned char buf[5] = "\0";
    8079  unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size;
    8180
     
    110109  buf[4] = '\0';
    111110  if ( strcmp((const char *)buf, "RIFF") != 0 ) {
    112     AUBIO_ERR("source_wavread: could not find RIFF header in %s\n", s->path);
     111    AUBIO_ERR("source_wavread: Failed opening %s (could not find RIFF header)\n", s->path);
    113112    goto beach;
    114113  }
     
    121120  buf[4] = '\0';
    122121  if ( strcmp((const char *)buf, "WAVE") != 0 ) {
    123     AUBIO_ERR("source_wavread: wrong format in RIFF header in %s\n", s->path);
     122    AUBIO_ERR("source_wavread: Failed opening %s (wrong format in RIFF header)\n", s->path);
    124123    goto beach;
    125124  }
     
    135134    bytes_junk += read_little_endian(buf, 4);
    136135    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
    137       AUBIO_ERR("source_wavread: could not seek past JUNK Chunk in %s (%s)\n",
     136      AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
    138137          s->path, strerror(errno));
    139138      goto beach;
     
    148147  // get the fmt chunk
    149148  if ( strcmp((const char *)buf, "fmt ") != 0 ) {
    150     AUBIO_ERR("source_wavread: failed finding fmt RIFF header in %s\n", s->path);
     149    AUBIO_ERR("source_wavread: Failed opening %s (could not find 'fmt ' in RIFF header)\n", s->path);
    151150    goto beach;
    152151  }
     
    157156  if ( format != 16 ) {
    158157    // TODO accept format 18
    159     AUBIO_ERR("source_wavread: file %s is not encoded with PCM\n", s->path);
     158    AUBIO_ERR("source_wavread: Failed opening %s (not encoded with PCM)\n", s->path);
    160159    goto beach;
    161160  }
    162161  if ( buf[1] || buf[2] | buf[3] ) {
    163     AUBIO_ERR("source_wavread: Subchunk1Size should be 0, in %s\n", s->path);
     162    AUBIO_ERR("source_wavread: Failed opening %s (Subchunk1Size should be 0)\n", s->path);
    164163    goto beach;
    165164  }
     
    168167  bytes_read += fread(buf, 1, 2, s->fid);
    169168  if ( buf[0] != 1 || buf[1] != 0) {
    170     AUBIO_ERR("source_wavread: AudioFormat should be PCM, in %s\n", s->path);
     169    AUBIO_ERR("source_wavread: Failed opening %s (AudioFormat should be PCM)\n", s->path);
    171170    goto beach;
    172171  }
     
    191190  bytes_read += fread(buf, 1, 2, s->fid);
    192191  bitspersample = read_little_endian(buf, 2);
     192
     193  if ( channels == 0 ) {
     194    AUBIO_ERR("source_wavread: Failed opening %s (number of channels can not be 0)\n", s->path);
     195    goto beach;
     196  }
     197
     198  if ( (sint_t)sr <= 0 ) {
     199    AUBIO_ERR("source_wavread: Failed opening %s (samplerate can not be <= 0)\n", s->path);
     200    goto beach;
     201  }
     202
     203  if ( byterate == 0 ) {
     204    AUBIO_ERR("source_wavread: Failed opening %s (byterate can not be 0)\n", s->path);
     205    goto beach;
     206  }
     207
     208  if ( bitspersample == 0 ) {
     209    AUBIO_ERR("source_wavread: Failed opening %s (bitspersample can not be 0)\n", s->path);
     210    goto beach;
     211  }
    193212#if 0
    194213  if ( bitspersample != 16 ) {
     
    200219
    201220  if ( byterate * 8 != sr * channels * bitspersample ) {
    202     AUBIO_ERR("source_wavread: wrong byterate in %s\n", s->path);
     221    AUBIO_ERR("source_wavread: Failed opening %s (wrong byterate)\n", s->path);
    203222    goto beach;
    204223  }
    205224
    206225  if ( blockalign * 8 != channels * bitspersample ) {
    207     AUBIO_ERR("source_wavread: wrong blockalign in %s\n", s->path);
     226    AUBIO_ERR("source_wavread: Failed opening %s (wrong blockalign)\n", s->path);
    208227    goto beach;
    209228  }
     
    330349  uint_t end = 0;
    331350  uint_t total_wrote = 0;
     351  if (s->fid == NULL) {
     352    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     353        s->path);
     354    return;
     355  }
    332356  while (total_wrote < s->hop_size) {
    333357    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    364388  uint_t end = 0;
    365389  uint_t total_wrote = 0;
     390  if (s->fid == NULL) {
     391    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     392        s->path);
     393    return;
     394  }
    366395  while (total_wrote < s->hop_size) {
    367396    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    404433uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) {
    405434  uint_t ret = 0;
     435  if (s->fid == NULL) {
     436    AUBIO_ERR("source_wavread: could not seek %s (file not opened?)\n", s->path, pos);
     437    return AUBIO_FAIL;
     438  }
    406439  if ((sint_t)pos < 0) {
     440    AUBIO_ERR("source_wavread: could not seek %s at %d (seeking position should be >= 0)\n", s->path, pos);
    407441    return AUBIO_FAIL;
    408442  }
     
    426460
    427461uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
    428   if (!s->fid) {
    429     return AUBIO_FAIL;
     462  if (s->fid == NULL) {
     463    return AUBIO_OK;
    430464  }
    431465  if (fclose(s->fid)) {
  • src/io/utils_apple_audio.c

    r5b46bc3 r633400d  
    1 #include "config.h"
     1#include "aubio_priv.h"
    22
    33#if defined(HAVE_SOURCE_APPLE_AUDIO) || defined(HAVE_SINK_APPLE_AUDIO)
     
    77// ExtAudioFileRef, AudioStreamBasicDescription, AudioBufferList, ...
    88#include <AudioToolbox/AudioToolbox.h>
    9 #include "aubio_priv.h"
    109
    1110int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
  • src/mathutils.c

    r5b46bc3 r633400d  
    2525#include "mathutils.h"
    2626#include "musicutils.h"
    27 #include "config.h"
    2827
    2928/** Window types */
    3029typedef enum
    3130{
     31  aubio_win_ones,
    3232  aubio_win_rectangle,
    3333  aubio_win_hamming,
     
    6565      AUBIO_ERR ("window type can not be null.\n");
    6666      return 1;
    67   } else if (strcmp (window_type, "rectangle") == 0)
     67  } else if (strcmp (window_type, "ones") == 0)
     68      wintype = aubio_win_ones;
     69  else if (strcmp (window_type, "rectangle") == 0)
    6870      wintype = aubio_win_rectangle;
    6971  else if (strcmp (window_type, "hamming") == 0)
     
    9092  }
    9193  switch(wintype) {
     94    case aubio_win_ones:
     95      fvec_ones(win);
     96      break;
    9297    case aubio_win_rectangle:
    93       for (i=0;i<size;i++)
    94         w[i] = 0.5;
     98      fvec_set_all(win, .5);
    9599      break;
    96100    case aubio_win_hamming:
     
    156160{
    157161  smpl_t tmp = 0.0;
    158 #ifndef HAVE_ACCELERATE
     162#if defined(HAVE_INTEL_IPP)
     163  aubio_ippsMean(s->data, (int)s->length, &tmp);
     164  return tmp;
     165#elif defined(HAVE_ACCELERATE)
     166  aubio_vDSP_meanv(s->data, 1, &tmp, s->length);
     167  return tmp;
     168#else
    159169  uint_t j;
    160170  for (j = 0; j < s->length; j++) {
    161171    tmp += s->data[j];
    162172  }
    163   return tmp / (smpl_t) (s->length);
    164 #else
    165   aubio_vDSP_meanv(s->data, 1, &tmp, s->length);
    166   return tmp;
    167 #endif /* HAVE_ACCELERATE */
     173  return tmp / (smpl_t)(s->length);
     174#endif
    168175}
    169176
     
    172179{
    173180  smpl_t tmp = 0.0;
    174 #ifndef HAVE_ACCELERATE
     181#if defined(HAVE_INTEL_IPP)
     182  aubio_ippsSum(s->data, (int)s->length, &tmp);
     183#elif defined(HAVE_ACCELERATE)
     184  aubio_vDSP_sve(s->data, 1, &tmp, s->length);
     185#else
    175186  uint_t j;
    176187  for (j = 0; j < s->length; j++) {
    177188    tmp += s->data[j];
    178189  }
    179 #else
    180   aubio_vDSP_sve(s->data, 1, &tmp, s->length);
    181 #endif /* HAVE_ACCELERATE */
     190#endif
    182191  return tmp;
    183192}
     
    186195fvec_max (fvec_t * s)
    187196{
    188 #ifndef HAVE_ACCELERATE
    189   uint_t j;
    190   smpl_t tmp = 0.0;
    191   for (j = 0; j < s->length; j++) {
     197#if defined(HAVE_INTEL_IPP)
     198  smpl_t tmp = 0.;
     199  aubio_ippsMax( s->data, (int)s->length, &tmp);
     200#elif defined(HAVE_ACCELERATE)
     201  smpl_t tmp = 0.;
     202  aubio_vDSP_maxv( s->data, 1, &tmp, s->length );
     203#else
     204  uint_t j;
     205  smpl_t tmp = s->data[0];
     206  for (j = 1; j < s->length; j++) {
    192207    tmp = (tmp > s->data[j]) ? tmp : s->data[j];
    193208  }
    194 #else
     209#endif
     210  return tmp;
     211}
     212
     213smpl_t
     214fvec_min (fvec_t * s)
     215{
     216#if defined(HAVE_INTEL_IPP)
    195217  smpl_t tmp = 0.;
    196   aubio_vDSP_maxv(s->data, 1, &tmp, s->length);
    197 #endif
    198   return tmp;
    199 }
    200 
    201 smpl_t
    202 fvec_min (fvec_t * s)
    203 {
    204 #ifndef HAVE_ACCELERATE
    205   uint_t j;
    206   smpl_t tmp = s->data[0];
    207   for (j = 0; j < s->length; j++) {
    208     tmp = (tmp < s->data[j]) ? tmp : s->data[j];
    209   }
    210 #else
     218  aubio_ippsMin(s->data, (int)s->length, &tmp);
     219#elif defined(HAVE_ACCELERATE)
    211220  smpl_t tmp = 0.;
    212221  aubio_vDSP_minv(s->data, 1, &tmp, s->length);
     222#else
     223  uint_t j;
     224  smpl_t tmp = s->data[0];
     225  for (j = 1; j < s->length; j++) {
     226    tmp = (tmp < s->data[j]) ? tmp : s->data[j];
     227  }
    213228#endif
    214229  return tmp;
     
    227242#else
    228243  smpl_t tmp = 0.;
    229   uint_t pos = 0.;
    230   aubio_vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    231 #endif
    232   return pos;
     244  vDSP_Length pos = 0;
     245  aubio_vDSP_minvi(s->data, 1, &tmp, &pos, s->length);
     246#endif
     247  return (uint_t)pos;
    233248}
    234249
     
    245260#else
    246261  smpl_t tmp = 0.;
    247   uint_t pos = 0.;
    248   aubio_vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    249 #endif
    250   return pos;
     262  vDSP_Length pos = 0;
     263  aubio_vDSP_maxvi(s->data, 1, &tmp, &pos, s->length);
     264#endif
     265  return (uint_t)pos;
    251266}
    252267
     
    257272  // if length is odd, middle element is moved to the end
    258273  if (2 * half < s->length) start ++;
    259 #ifndef HAVE_ATLAS
     274#ifndef HAVE_BLAS
    260275  for (j = 0; j < half; j++) {
    261276    ELEM_SWAP (s->data[j], s->data[j + start]);
     
    277292  // if length is odd, middle element is moved to the beginning
    278293  if (2 * half < s->length) start ++;
    279 #ifndef HAVE_ATLAS
     294#ifndef HAVE_BLAS
    280295  for (j = 0; j < half; j++) {
    281296    ELEM_SWAP (s->data[j], s->data[j + start]);
     
    291306}
    292307
     308void fvec_push(fvec_t *in, smpl_t new_elem) {
     309  uint_t i;
     310  for (i = 0; i < in->length - 1; i++) {
     311    in->data[i] = in->data[i + 1];
     312  }
     313  in->data[in->length - 1] = new_elem;
     314}
     315
     316void fvec_clamp(fvec_t *in, smpl_t absmax) {
     317  uint_t i;
     318  for (i = 0; i < in->length; i++) {
     319    if (in->data[i] > 0 && in->data[i] > ABS(absmax)) {
     320      in->data[i] = absmax;
     321    } else if (in->data[i] < 0 && in->data[i] < -ABS(absmax)) {
     322      in->data[i] = -absmax;
     323    }
     324  }
     325}
     326
    293327smpl_t
    294328aubio_level_lin (const fvec_t * f)
    295329{
    296330  smpl_t energy = 0.;
    297 #ifndef HAVE_ATLAS
     331#ifndef HAVE_BLAS
    298332  uint_t j;
    299333  for (j = 0; j < f->length; j++) {
     
    351385  for (j = 0; j < o->length; j++) {
    352386    o->data[j] += val;
     387  }
     388}
     389
     390void
     391fvec_mul (fvec_t *o, smpl_t val)
     392{
     393  uint_t j;
     394  for (j = 0; j < o->length; j++) {
     395    o->data[j] *= val;
    353396  }
    354397}
     
    489532  /* log(freq/A-2)/log(2) */
    490533  midi = freq / 6.875;
    491   midi = LOG (midi) / 0.69314718055995;
     534  midi = LOG (midi) / 0.6931471805599453;
    492535  midi *= 12;
    493536  midi -= 3;
     
    501544  if (midi > 140.) return 0.; // avoid infs
    502545  freq = (midi + 3.) / 12.;
    503   freq = EXP (freq * 0.69314718055995);
     546  freq = EXP (freq * 0.6931471805599453);
    504547  freq *= 6.875;
    505548  return freq;
     
    550593  while (i < a) i <<= 1;
    551594  return i;
     595}
     596
     597uint_t
     598aubio_power_of_two_order (uint_t a)
     599{
     600  int order = 0;
     601  int temp = aubio_next_power_of_two(a);
     602  while (temp >>= 1) {
     603    ++order;
     604  }
     605  return order;
    552606}
    553607
  • src/mathutils.h

    r5b46bc3 r633400d  
    118118void fvec_ishift (fvec_t * v);
    119119
     120/** push a new element to the end of a vector, erasing the first element and
     121 * sliding all others
     122
     123  \param in vector to push to
     124  \param new_elem new_element to add at the end of the vector
     125
     126  In numpy words, this is equivalent to: in = np.concatenate([in, [new_elem]])[1:]
     127
     128*/
     129void fvec_push(fvec_t *in, smpl_t new_elem);
     130
    120131/** compute the sum of all elements of a vector
    121132
     
    182193*/
    183194void fvec_add (fvec_t * v, smpl_t c);
     195
     196/** multiply each elements of a vector by a scalar
     197
     198  \param v vector to add constant to
     199  \param s constant to scale v with
     200
     201*/
     202void fvec_mul (fvec_t * v, smpl_t s);
    184203
    185204/** remove the minimum value of the vector to each elements
     
    302321uint_t aubio_next_power_of_two(uint_t a);
    303322
     323/** return the log2 factor of the given power of 2 value a */
     324uint_t aubio_power_of_two_order(uint_t a);
     325
    304326/** compute normalised autocorrelation function
    305327
  • src/musicutils.h

    r5b46bc3 r633400d  
    8787smpl_t aubio_freqtobin (smpl_t freq, smpl_t samplerate, smpl_t fftsize);
    8888
     89/** convert frequency (Hz) to mel
     90
     91  \param freq input frequency, in Hz
     92
     93  \return output mel
     94
     95  Converts a scalar from the frequency domain to the mel scale using Slaney
     96  Auditory Toolbox's implementation:
     97
     98  If \f$ f < 1000 \f$, \f$ m = 3 f / 200 \f$.
     99
     100  If \f$ f >= 1000 \f$, \f$ m = 1000 + 27 \frac{{ln}(f) - ln(1000))}
     101  {{ln}(6400) - ln(1000)}
     102  \f$
     103
     104  See also
     105  --------
     106
     107  aubio_meltohz(), aubio_hztomel_htk().
     108
     109*/
     110smpl_t aubio_hztomel (smpl_t freq);
     111
     112/** convert mel to frequency (Hz)
     113
     114  \param mel input mel
     115
     116  \return output frequency, in Hz
     117
     118  Converts a scalar from the mel scale to the frequency domain using Slaney
     119  Auditory Toolbox's implementation:
     120
     121  If \f$ f < 1000 \f$, \f$ f = 200 m/3 \f$.
     122
     123  If \f$ f \geq 1000 \f$, \f$ f = 1000 + \left(\frac{6400}{1000}\right)
     124  ^{\frac{m - 1000}{27}} \f$
     125
     126  See also
     127  --------
     128
     129  aubio_hztomel(), aubio_meltohz_htk().
     130
     131  References
     132  ----------
     133
     134  Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
     135  https://engineering.purdue.edu/~malcolm/interval/1998-010/
     136
     137*/
     138smpl_t aubio_meltohz (smpl_t mel);
     139
     140/** convert frequency (Hz) to mel
     141
     142  \param freq input frequency, in Hz
     143
     144  \return output mel
     145
     146  Converts a scalar from the frequency domain to the mel scale, using the
     147  equation defined by O'Shaughnessy, as implemented in the HTK speech
     148  recognition toolkit:
     149
     150  \f$ m = 1127 + ln(1 + \frac{f}{700}) \f$
     151
     152  See also
     153  --------
     154
     155  aubio_meltohz_htk(), aubio_hztomel().
     156
     157  References
     158  ----------
     159
     160  Douglas O'Shaughnessy (1987). *Speech communication: human and machine*.
     161  Addison-Wesley. p. 150. ISBN 978-0-201-16520-3.
     162
     163  HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/
     164
     165 */
     166smpl_t aubio_hztomel_htk (smpl_t freq);
     167
     168/** convert mel to frequency (Hz)
     169
     170  \param mel input mel
     171
     172  \return output frequency, in Hz
     173
     174  Converts a scalar from the mel scale to the frequency domain, using the
     175  equation defined by O'Shaughnessy, as implemented in the HTK speech
     176  recognition toolkit:
     177
     178  \f$ f = 700 * {e}^\left(\frac{f}{1127} - 1\right) \f$
     179
     180  See also
     181  --------
     182
     183  aubio_hztomel_htk(), aubio_meltohz().
     184
     185*/
     186smpl_t aubio_meltohz_htk (smpl_t mel);
     187
    89188/** convert frequency (Hz) to midi value (0-128) */
    90189smpl_t aubio_freqtomidi (smpl_t freq);
     
    156255*/
    157256smpl_t aubio_level_detection (const fvec_t * v, smpl_t threshold);
     257
     258/** clamp the values of a vector within the range [-abs(max), abs(max)]
     259
     260  \param in vector to clamp
     261  \param absmax maximum value over which input vector elements should be clamped
     262
     263*/
     264void fvec_clamp(fvec_t *in, smpl_t absmax);
    158265
    159266#ifdef __cplusplus
  • src/notes/notes.c

    r5b46bc3 r633400d  
    11/*
    2   Copyright (C) 2014 Paul Brossier <piem@aubio.org>
     2  Copyright (C) 2014-2018 Paul Brossier <piem@aubio.org>
    33
    44  This file is part of aubio.
     
    2525#include "notes/notes.h"
    2626
     27#define AUBIO_DEFAULT_NOTES_SILENCE -70.
     28#define AUBIO_DEFAULT_NOTES_RELEASE_DROP 10.
     29// increase to 10. for .1  cent precision
     30//      or to 100. for .01 cent precision
     31#define AUBIO_DEFAULT_CENT_PRECISION 1.
     32#define AUBIO_DEFAULT_NOTES_MINIOI_MS 30.
     33
    2734struct _aubio_notes_t {
    2835
     
    5158
    5259  uint_t isready;
     60
     61  smpl_t last_onset_level;
     62  smpl_t release_drop_level;
    5363};
    5464
     
    7484
    7585  o->onset = new_aubio_onset (onset_method, o->onset_buf_size, o->hop_size, o->samplerate);
     86  if (o->onset == NULL) goto fail;
    7687  if (o->onset_threshold != 0.) aubio_onset_set_threshold (o->onset, o->onset_threshold);
    7788  o->onset_output = new_fvec (1);
    7889
    7990  o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate);
     91  if (o->pitch == NULL) goto fail;
    8092  if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance);
     93  aubio_pitch_set_unit (o->pitch, "midi");
    8194  o->pitch_output = new_fvec (1);
    8295
     
    88101  o->note_buffer2 = new_fvec(o->median);
    89102
     103  if (!o->onset_output || !o->pitch_output ||
     104      !o->note_buffer || !o->note_buffer2) goto fail;
     105
    90106  o->curnote = -1.;
    91107  o->newnote = 0.;
    92108
    93   o->silence_threshold = -90.;
     109  aubio_notes_set_silence(o, AUBIO_DEFAULT_NOTES_SILENCE);
     110  aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS);
     111
     112  o->last_onset_level = AUBIO_DEFAULT_NOTES_SILENCE;
     113  o->release_drop_level = AUBIO_DEFAULT_NOTES_RELEASE_DROP;
    94114
    95115  return o;
     
    98118  del_aubio_notes(o);
    99119  return NULL;
     120}
     121
     122uint_t aubio_notes_set_silence(aubio_notes_t *o, smpl_t silence)
     123{
     124  uint_t err = AUBIO_OK;
     125  if (aubio_pitch_set_silence(o->pitch, silence) != AUBIO_OK) {
     126    err = AUBIO_FAIL;
     127  }
     128  if (aubio_onset_set_silence(o->onset, silence) != AUBIO_OK) {
     129    err = AUBIO_FAIL;
     130  }
     131  o->silence_threshold = silence;
     132  return err;
     133}
     134
     135smpl_t aubio_notes_get_silence(const aubio_notes_t *o)
     136{
     137  return aubio_pitch_get_silence(o->pitch);
     138}
     139
     140uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms)
     141{
     142  uint_t err = AUBIO_OK;
     143  if (!o->onset || (aubio_onset_set_minioi_ms(o->onset, minioi_ms) != 0)) {
     144    err = AUBIO_FAIL;
     145  }
     146  return err;
     147}
     148
     149smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o)
     150{
     151  return aubio_onset_get_minioi_ms(o->onset);
     152}
     153
     154uint_t aubio_notes_set_release_drop(aubio_notes_t *o, smpl_t release_drop_level)
     155{
     156  uint_t err = AUBIO_OK;
     157  if (release_drop_level <= 0.) {
     158    AUBIO_ERR("notes: release_drop should be >= 0, got %f\n", release_drop_level);
     159    err = AUBIO_FAIL;
     160  } else {
     161    o->release_drop_level = release_drop_level;
     162  }
     163  return err;
     164}
     165
     166smpl_t aubio_notes_get_release_drop(const aubio_notes_t *o)
     167{
     168  return o->release_drop_level;
    100169}
    101170
     
    109178    note_buffer->data[i] = note_buffer->data[i + 1];
    110179  }
    111   note_buffer->data[note_buffer->length - 1] = curnote;
     180  //note_buffer->data[note_buffer->length - 1] = ROUND(10.*curnote)/10.;
     181  note_buffer->data[note_buffer->length - 1] = ROUND(AUBIO_DEFAULT_CENT_PRECISION*curnote);
    112182  return;
    113183}
    114184
    115 static uint_t
     185static smpl_t
    116186aubio_notes_get_latest_note (aubio_notes_t *o)
    117187{
    118   uint_t i;
    119   for (i = 0; i < o->note_buffer->length; i++) {
    120     o->note_buffer2->data[i] = o->note_buffer->data[i];
    121   }
    122   return fvec_median (o->note_buffer2);
     188  fvec_copy(o->note_buffer, o->note_buffer2);
     189  return fvec_median (o->note_buffer2) / AUBIO_DEFAULT_CENT_PRECISION;
    123190}
    124191
     
    146213      //notes->data[0] = o->curnote;
    147214      //notes->data[1] = 0.;
     215      //AUBIO_WRN("notes: sending note-off at onset, not enough level\n");
    148216      notes->data[2] = o->curnote;
    149217    } else {
     
    153221        /* kill old note */
    154222        //send_noteon(o->curnote,0, o->samplerate);
     223        //AUBIO_WRN("notes: sending note-off at onset, new onset detected\n");
    155224        notes->data[2] = o->curnote;
    156225        /* get and send new one */
     
    160229        o->curnote = new_pitch;
    161230      }
     231      o->last_onset_level = curlevel;
    162232    }
    163233  } else {
    164     if (o->median) {
     234    if (curlevel < o->last_onset_level - o->release_drop_level)
     235    {
     236      // send note off
     237      //AUBIO_WRN("notes: sending note-off, release detected\n");
     238      notes->data[0] = 0;
     239      notes->data[1] = 0;
     240      notes->data[2] = o->curnote;
     241      // reset last_onset_level to silence_threshold
     242      o->last_onset_level = o->silence_threshold;
     243      o->curnote = 0;
     244    }
     245    else if (o->median)
     246    {
    165247      if (o->isready > 0)
    166248        o->isready++;
     
    169251        /* kill old note */
    170252        //send_noteon(curnote,0);
    171         notes->data[2] = o->curnote;
     253        if (o->curnote != 0)
     254        {
     255          //AUBIO_WRN("notes: sending note-off, new note detected\n");
     256          notes->data[2] = o->curnote;
     257        }
    172258        o->newnote = aubio_notes_get_latest_note(o);
    173259        o->curnote = o->newnote;
  • src/notes/notes.h

    r5b46bc3 r633400d  
    1616  You should have received a copy of the GNU General Public License
    1717  along with aubio.  If not, see <http://www.gnu.org/licenses/>.
     18
     19*/
     20
     21/** \file
     22
     23  Note detection object
    1824
    1925*/
     
    5258
    5359  \param o note detection object as returned by new_aubio_notes()
    54   \param in input signal of size [hop_size]
    55   \param out output notes of size [3] ? FIXME
     60  \param input input signal of size [hop_size]
     61  \param output output notes, fvec of length 3
     62
     63  The notes output is a vector of length 3 containing:
     64   - 0. the midi note value, or 0 if no note was found
     65   - 1. the note velocity
     66   - 2. the midi note to turn off
    5667
    5768*/
    5869void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * output);
     70
     71/** set notes detection silence threshold
     72
     73  \param o notes detection object as returned by new_aubio_notes()
     74  \param silence new silence detection threshold
     75
     76  \return 0 on success, non-zero otherwise
     77
     78*/
     79uint_t aubio_notes_set_silence(aubio_notes_t * o, smpl_t silence);
     80
     81/** get notes detection silence threshold
     82
     83  \param o notes detection object as returned by new_aubio_notes()
     84
     85  \return current silence threshold
     86
     87*/
     88smpl_t aubio_notes_get_silence(const aubio_notes_t * o);
     89
     90/** get notes detection minimum inter-onset interval, in millisecond
     91
     92  \param o notes detection object as returned by new_aubio_notes()
     93
     94  \return current minimum inter onset interval
     95
     96 */
     97smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o);
     98
     99/** set notes detection minimum inter-onset interval, in millisecond
     100
     101  \param o notes detection object as returned by new_aubio_notes()
     102  \param minioi_ms new inter-onset interval
     103
     104  \return 0 on success, non-zero otherwise
     105
     106*/
     107uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms);
     108
     109/** get notes object release drop level, in dB
     110
     111  \param o notes detection object as returned by new_aubio_notes()
     112
     113  \return current release drop level, in dB
     114
     115 */
     116smpl_t aubio_notes_get_release_drop (const aubio_notes_t *o);
     117
     118/** set note release drop level, in dB
     119
     120  This function sets the release_drop_level parameter, in dB. When a new note
     121  is found, the current level in dB is measured. If the measured level drops
     122  under that initial level - release_drop_level, then a note-off will be
     123  emitted.
     124
     125  Defaults to `10`, in dB.
     126
     127  \note This parameter was added in version `0.4.8`. Results obtained with
     128  earlier versions can be reproduced by setting this value to `100`, so that
     129  note-off will not be played until the next note.
     130
     131  \param o notes detection object as returned by new_aubio_notes()
     132  \param release_drop new release drop level, in dB
     133
     134  \return 0 on success, non-zero otherwise
     135
     136*/
     137uint_t aubio_notes_set_release_drop (aubio_notes_t *o, smpl_t release_drop);
    59138
    60139#ifdef __cplusplus
  • src/onset/onset.c

    r5b46bc3 r633400d  
    2424#include "spectral/specdesc.h"
    2525#include "spectral/phasevoc.h"
     26#include "spectral/awhitening.h"
    2627#include "onset/peakpicker.h"
    2728#include "mathutils.h"
    2829#include "onset/onset.h"
     30
     31void aubio_onset_default_parameters (aubio_onset_t *o, const char_t * method);
    2932
    3033/** structure to store object state */
     
    4346  uint_t total_frames;          /**< total number of frames processed since the beginning */
    4447  uint_t last_onset;            /**< last detected onset location, in frames */
     48
     49  uint_t apply_compression;
     50  smpl_t lambda_compression;
     51  uint_t apply_awhitening;      /**< apply adaptive spectral whitening */
     52  aubio_spectral_whitening_t *spectral_whitening;
    4553};
    4654
     
    5058  smpl_t isonset = 0;
    5159  aubio_pvoc_do (o->pv,input, o->fftgrain);
     60  /*
     61  if (apply_filtering) {
     62  }
     63  */
     64  if (o->apply_awhitening) {
     65    aubio_spectral_whitening_do(o->spectral_whitening, o->fftgrain);
     66  }
     67  if (o->apply_compression) {
     68    cvec_logmag(o->fftgrain, o->lambda_compression);
     69  }
    5270  aubio_specdesc_do (o->od, o->fftgrain, o->desc);
    5371  aubio_peakpicker_do(o->pp, o->desc, onset);
     
    5876      isonset  = 0;
    5977    } else {
     78      // we have an onset
    6079      uint_t new_onset = o->total_frames + (uint_t)ROUND(isonset * o->hop_size);
     80      // check if last onset time was more than minioi ago
    6181      if (o->last_onset + o->minioi < new_onset) {
    62         //AUBIO_DBG ("accepted detection, marking as onset\n");
    63         o->last_onset = new_onset;
     82        // start of file: make sure (new_onset - delay) >= 0
     83        if (o->last_onset > 0 && o->delay > new_onset) {
     84          isonset = 0;
     85        } else {
     86          //AUBIO_DBG ("accepted detection, marking as onset\n");
     87          o->last_onset = MAX(o->delay, new_onset);
     88        }
    6489      } else {
    6590        //AUBIO_DBG ("doubled onset, not marking as onset\n");
     
    100125}
    101126
     127uint_t aubio_onset_set_awhitening (aubio_onset_t *o, uint_t enable)
     128{
     129  o->apply_awhitening = enable == 1 ? 1 : 0;
     130  return AUBIO_OK;
     131}
     132
     133smpl_t aubio_onset_get_awhitening (aubio_onset_t *o)
     134{
     135  return o->apply_awhitening;
     136}
     137
     138uint_t aubio_onset_set_compression (aubio_onset_t *o, smpl_t lambda)
     139{
     140  if (lambda < 0.) {
     141    return AUBIO_FAIL;
     142  }
     143  o->lambda_compression = lambda;
     144  o->apply_compression = (o->lambda_compression > 0.) ? 1 : 0;
     145  return AUBIO_OK;
     146}
     147
     148smpl_t aubio_onset_get_compression (aubio_onset_t *o)
     149{
     150  return o->apply_compression ? o->lambda_compression : 0;
     151}
     152
    102153uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) {
    103154  o->silence = silence;
     
    206257  o->pp = new_aubio_peakpicker();
    207258  o->od = new_aubio_specdesc(onset_mode,buf_size);
    208   if (o->od == NULL) goto beach_specdesc;
    209259  o->fftgrain = new_cvec(buf_size);
    210260  o->desc = new_fvec(1);
    211 
     261  o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate);
     262
     263  if (!o->pv || !o->pp || !o->od || !o->fftgrain
     264      || !o->desc || !o->spectral_whitening)
     265    goto beach;
     266
     267  /* initialize internal variables */
     268  aubio_onset_set_default_parameters (o, onset_mode);
     269
     270  aubio_onset_reset(o);
     271  return o;
     272
     273beach:
     274  del_aubio_onset(o);
     275  return NULL;
     276}
     277
     278void aubio_onset_reset (aubio_onset_t *o) {
     279  o->last_onset = 0;
     280  o->total_frames = 0;
     281}
     282
     283uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * onset_mode)
     284{
     285  uint_t ret = AUBIO_OK;
    212286  /* set some default parameter */
    213287  aubio_onset_set_threshold (o, 0.3);
    214   aubio_onset_set_delay(o, 4.3 * hop_size);
    215   aubio_onset_set_minioi_ms(o, 20.);
    216   aubio_onset_set_silence(o, -70.);
    217 
    218   /* initialize internal variables */
    219   o->last_onset = 0;
    220   o->total_frames = 0;
    221   return o;
    222 
    223 beach_specdesc:
    224   del_aubio_peakpicker(o->pp);
    225   del_aubio_pvoc(o->pv);
    226 beach:
     288  aubio_onset_set_delay (o, 4.3 * o->hop_size);
     289  aubio_onset_set_minioi_ms (o, 50.);
     290  aubio_onset_set_silence (o, -70.);
     291  // disable spectral whitening
     292  aubio_onset_set_awhitening (o, 0);
     293  // disable logarithmic magnitude
     294  aubio_onset_set_compression (o, 0.);
     295
     296  /* method specific optimisations */
     297  if (strcmp (onset_mode, "energy") == 0) {
     298  } else if (strcmp (onset_mode, "hfc") == 0 || strcmp (onset_mode, "default") == 0) {
     299    aubio_onset_set_threshold (o, 0.058);
     300    aubio_onset_set_compression (o, 1.);
     301  } else if (strcmp (onset_mode, "complexdomain") == 0
     302             || strcmp (onset_mode, "complex") == 0) {
     303    aubio_onset_set_delay (o, 4.6 * o->hop_size);
     304    aubio_onset_set_threshold (o, 0.15);
     305    aubio_onset_set_awhitening(o, 1);
     306    aubio_onset_set_compression (o, 1.);
     307  } else if (strcmp (onset_mode, "phase") == 0) {
     308    o->apply_compression = 0;
     309    aubio_onset_set_awhitening (o, 0);
     310  } else if (strcmp (onset_mode, "wphase") == 0) {
     311    // use defaults for now
     312  } else if (strcmp (onset_mode, "mkl") == 0) {
     313    aubio_onset_set_threshold (o, 0.05);
     314    aubio_onset_set_awhitening(o, 1);
     315    aubio_onset_set_compression (o, 0.02);
     316  } else if (strcmp (onset_mode, "kl") == 0) {
     317    aubio_onset_set_threshold (o, 0.35);
     318    aubio_onset_set_awhitening(o, 1);
     319    aubio_onset_set_compression (o, 0.02);
     320  } else if (strcmp (onset_mode, "specflux") == 0) {
     321    aubio_onset_set_threshold (o, 0.18);
     322    aubio_onset_set_awhitening(o, 1);
     323    aubio_spectral_whitening_set_relax_time(o->spectral_whitening, 100);
     324    aubio_spectral_whitening_set_floor(o->spectral_whitening, 1.);
     325    aubio_onset_set_compression (o, 10.);
     326  } else if (strcmp (onset_mode, "specdiff") == 0) {
     327  } else if (strcmp (onset_mode, "old_default") == 0) {
     328    // used to reproduce results obtained with the previous version
     329    aubio_onset_set_threshold (o, 0.3);
     330    aubio_onset_set_minioi_ms (o, 20.);
     331    aubio_onset_set_compression (o, 0.);
     332  } else {
     333    AUBIO_WRN("onset: unknown spectral descriptor type %s, "
     334               "using default parameters.\n", onset_mode);
     335    ret = AUBIO_FAIL;
     336  }
     337  return ret;
     338}
     339
     340void del_aubio_onset (aubio_onset_t *o)
     341{
     342  if (o->spectral_whitening)
     343    del_aubio_spectral_whitening(o->spectral_whitening);
     344  if (o->od)
     345    del_aubio_specdesc(o->od);
     346  if (o->pp)
     347    del_aubio_peakpicker(o->pp);
     348  if (o->pv)
     349    del_aubio_pvoc(o->pv);
     350  if (o->desc)
     351    del_fvec(o->desc);
     352  if (o->fftgrain)
     353    del_cvec(o->fftgrain);
    227354  AUBIO_FREE(o);
    228   return NULL;
    229 }
    230 
    231 void del_aubio_onset (aubio_onset_t *o)
    232 {
    233   del_aubio_specdesc(o->od);
    234   del_aubio_peakpicker(o->pp);
    235   del_aubio_pvoc(o->pv);
    236   del_fvec(o->desc);
    237   del_cvec(o->fftgrain);
    238   AUBIO_FREE(o);
    239 }
     355}
  • src/onset/onset.h

    r5b46bc3 r633400d  
    118118smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o);
    119119
     120/** set onset detection adaptive whitening
     121
     122  \param o onset detection object as returned by new_aubio_onset()
     123  \param enable 1 to enable, 0 to disable
     124
     125  \return 0 if successful, 1 otherwise
     126
     127*/
     128uint_t aubio_onset_set_awhitening(aubio_onset_t * o, uint_t enable);
     129
     130/** get onset detection adaptive whitening
     131
     132  \param o onset detection object as returned by new_aubio_onset()
     133
     134  \return 1 if enabled, 0 otherwise
     135
     136*/
     137smpl_t aubio_onset_get_awhitening(aubio_onset_t * o);
     138
     139/** set or disable log compression
     140
     141  \param o onset detection object as returned by new_aubio_onset()
     142  \param lambda logarithmic compression factor, 0 to disable
     143
     144  \return 0 if successful, 1 otherwise
     145
     146 */
     147uint_t aubio_onset_set_compression(aubio_onset_t *o, smpl_t lambda);
     148
     149/** get onset detection log compression
     150
     151  \param o onset detection object as returned by new_aubio_onset()
     152
     153  \returns 0 if disabled, compression factor otherwise
     154
     155 */
     156smpl_t aubio_onset_get_compression(aubio_onset_t *o);
     157
    120158/** set onset detection silence threshold
    121159
     
    274312*/
    275313smpl_t aubio_onset_get_threshold(const aubio_onset_t * o);
     314
     315/** set default parameters
     316
     317  \param o onset detection object as returned by new_aubio_onset()
     318  \param onset_mode detection mode to adjust
     319
     320  This function is called at the end of new_aubio_onset().
     321
     322 */
     323uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * onset_mode);
     324
     325/** reset onset detection
     326
     327  \param o onset detection object as returned by new_aubio_onset()
     328
     329  Reset current time and last onset to 0.
     330
     331  This function is called at the end of new_aubio_onset().
     332
     333 */
     334void aubio_onset_reset(aubio_onset_t * o);
    276335
    277336/** delete onset detection object
  • src/onset/peakpicker.c

    r5b46bc3 r633400d  
    9393  fvec_t *scratch = p->scratch;
    9494  smpl_t mean = 0., median = 0.;
    95   uint_t length = p->win_post + p->win_pre + 1;
    9695  uint_t j = 0;
    9796
    98   /* store onset in onset_keep */
    99   /* shift all elements but last, then write last */
    100   for (j = 0; j < length - 1; j++) {
    101     onset_keep->data[j] = onset_keep->data[j + 1];
    102     onset_proc->data[j] = onset_keep->data[j];
    103   }
    104   onset_keep->data[length - 1] = onset->data[0];
    105   onset_proc->data[length - 1] = onset->data[0];
     97  /* push new novelty to the end */
     98  fvec_push(onset_keep, onset->data[0]);
     99  /* store a copy */
     100  fvec_copy(onset_keep, onset_proc);
    106101
    107   /* filter onset_proc */
    108   /** \bug filtfilt calculated post+pre times, should be only once !? */
     102  /* filter this copy */
    109103  aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch);
    110104
    111105  /* calculate mean and median for onset_proc */
    112106  mean = fvec_mean (onset_proc);
    113   /* copy to scratch */
    114   for (j = 0; j < length; j++)
    115     scratch->data[j] = onset_proc->data[j];
     107
     108  /* copy to scratch and compute its median */
     109  fvec_copy(onset_proc, scratch);
    116110  median = p->thresholdfn (scratch);
    117111
     
    186180   */
    187181  t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789,
    188       -0.59488894, 0.23484048);
     182      // FIXME: broken since c9e20ca, revert for now
     183      //-0.59488894, 0.23484048);
     184      0.23484048, 0);
    189185
    190186  return t;
  • src/pitch/pitch.c

    r5b46bc3 r633400d  
    3333#include "pitch/pitchschmitt.h"
    3434#include "pitch/pitchyinfft.h"
     35#include "pitch/pitchyinfast.h"
    3536#include "pitch/pitchspecacf.h"
    3637#include "pitch/pitch.h"
     
    4647  aubio_pitcht_fcomb,      /**< `fcomb`, Fast comb filter */
    4748  aubio_pitcht_yinfft,     /**< `yinfft`, Spectral YIN */
     49  aubio_pitcht_yinfast,    /**< `yinfast`, YIN fast */
    4850  aubio_pitcht_specacf,    /**< `specacf`, Spectral autocorrelation */
    4951  aubio_pitcht_default
     
    9597static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    9698static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     99static void aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    97100static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    98101
     
    112115  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
    113116  aubio_pitch_type pitch_type;
     117  if (pitch_mode == NULL) {
     118    AUBIO_ERR ("pitch: can not use ‘NULL‘ for pitch detection method\n");
     119    goto beach;
     120  }
    114121  if (strcmp (pitch_mode, "mcomb") == 0)
    115122    pitch_type = aubio_pitcht_mcomb;
     123  else if (strcmp (pitch_mode, "yinfast") == 0)
     124    pitch_type = aubio_pitcht_yinfast;
    116125  else if (strcmp (pitch_mode, "yinfft") == 0)
    117126    pitch_type = aubio_pitcht_yinfft;
     
    139148    goto beach;
    140149  } else if (bufsize < hopsize) {
    141     AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);
     150    AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", hopsize, bufsize);
    142151    goto beach;
    143152  } else if ((sint_t)samplerate < 1) {
     
    156165      p->buf = new_fvec (bufsize);
    157166      p->p_object = new_aubio_pitchyin (bufsize);
     167      if (!p->p_object) goto beach;
    158168      p->detect_cb = aubio_pitch_do_yin;
    159169      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence;
     
    163173      p->filtered = new_fvec (hopsize);
    164174      p->pv = new_aubio_pvoc (bufsize, hopsize);
     175      if (!p->pv) goto beach;
    165176      p->fftgrain = new_cvec (bufsize);
    166177      p->p_object = new_aubio_pitchmcomb (bufsize, hopsize);
     
    171182      p->buf = new_fvec (bufsize);
    172183      p->p_object = new_aubio_pitchfcomb (bufsize, hopsize);
     184      if (!p->p_object) goto beach;
    173185      p->detect_cb = aubio_pitch_do_fcomb;
    174186      break;
     
    181193      p->buf = new_fvec (bufsize);
    182194      p->p_object = new_aubio_pitchyinfft (samplerate, bufsize);
     195      if (!p->p_object) goto beach;
    183196      p->detect_cb = aubio_pitch_do_yinfft;
    184197      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence;
    185198      aubio_pitchyinfft_set_tolerance (p->p_object, 0.85);
    186199      break;
     200    case aubio_pitcht_yinfast:
     201      p->buf = new_fvec (bufsize);
     202      p->p_object = new_aubio_pitchyinfast (bufsize);
     203      if (!p->p_object) goto beach;
     204      p->detect_cb = aubio_pitch_do_yinfast;
     205      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfast_get_confidence;
     206      aubio_pitchyinfast_set_tolerance (p->p_object, 0.15);
     207      break;
    187208    case aubio_pitcht_specacf:
    188209      p->buf = new_fvec (bufsize);
    189210      p->p_object = new_aubio_pitchspecacf (bufsize);
     211      if (!p->p_object) goto beach;
    190212      p->detect_cb = aubio_pitch_do_specacf;
    191213      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance;
     
    198220
    199221beach:
     222  if (p->filtered) del_fvec(p->filtered);
     223  if (p->buf) del_fvec(p->buf);
    200224  AUBIO_FREE(p);
    201225  return NULL;
     
    228252      del_fvec (p->buf);
    229253      del_aubio_pitchyinfft (p->p_object);
     254      break;
     255    case aubio_pitcht_yinfast:
     256      del_fvec (p->buf);
     257      del_aubio_pitchyinfast (p->p_object);
    230258      break;
    231259    case aubio_pitcht_specacf:
     
    319347      aubio_pitchyinfft_set_tolerance (p->p_object, tol);
    320348      break;
     349    case aubio_pitcht_yinfast:
     350      aubio_pitchyinfast_set_tolerance (p->p_object, tol);
     351      break;
    321352    default:
    322353      break;
     
    335366    case aubio_pitcht_yinfft:
    336367      tolerance = aubio_pitchyinfft_get_tolerance (p->p_object);
     368      break;
     369    case aubio_pitcht_yinfast:
     370      tolerance = aubio_pitchyinfast_get_tolerance (p->p_object);
    337371      break;
    338372    default:
     
    404438  aubio_pitch_slideblock (p, ibuf);
    405439  aubio_pitchyinfft_do (p->p_object, p->buf, obuf);
     440  pitch = obuf->data[0];
     441  if (pitch > 0) {
     442    pitch = p->samplerate / (pitch + 0.);
     443  } else {
     444    pitch = 0.;
     445  }
     446  obuf->data[0] = pitch;
     447}
     448
     449void
     450aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
     451{
     452  smpl_t pitch = 0.;
     453  aubio_pitch_slideblock (p, ibuf);
     454  aubio_pitchyinfast_do (p->p_object, p->buf, obuf);
    406455  pitch = obuf->data[0];
    407456  if (pitch > 0) {
  • src/pitch/pitch.h

    r5b46bc3 r633400d  
    8282  see http://recherche.ircam.fr/equipes/pcm/pub/people/cheveign.html
    8383
     84  \b \p yinfast : Yinfast algorithm
     85
     86  This algorithm is equivalent to the YIN algorithm, but computed in the
     87  spectral domain for efficiency. See also `python/demos/demo_yin_compare.py`.
     88
    8489  \b \p yinfft : Yinfft algorithm
    8590
     
    151156  \param mode set pitch units for output
    152157
     158  mode can be one of "Hz", "midi", "cent", or "bin". Defaults to "Hz".
     159
    153160  \return 0 if successfull, non-zero otherwise
    154161
  • src/pitch/pitchfcomb.c

    r5b46bc3 r633400d  
    5454  p->fftSize = bufsize;
    5555  p->stepSize = hopsize;
     56  p->fft = new_aubio_fft (bufsize);
     57  if (!p->fft) goto beach;
    5658  p->winput = new_fvec (bufsize);
    5759  p->fftOut = new_cvec (bufsize);
    5860  p->fftLastPhase = new_fvec (bufsize);
    59   p->fft = new_aubio_fft (bufsize);
    6061  p->win = new_aubio_window ("hanning", bufsize);
    6162  return p;
     63
     64beach:
     65  AUBIO_FREE(p);
     66  return NULL;
    6267}
    6368
  • src/pitch/pitchmcomb.c

    r5b46bc3 r633400d  
    3838 * sort_pitchpeak(peaks, length);
    3939 */
     40#if 0
    4041/** spectral_peak comparison function (must return signed int) */
    4142static sint_t aubio_pitchmcomb_sort_peak_comp (const void *x, const void *y);
     
    4546uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain,
    4647    smpl_t * cands);
     48#endif
    4749
    4850/** sort spectral_candidate against their comb ene */
    4951void aubio_pitchmcomb_sort_cand_ene (aubio_spectralcandidate_t ** candidates,
    5052    uint_t nbins);
     53#if 0
    5154/** sort spectral_candidate against their frequency */
    5255void aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates,
    5356    uint_t nbins);
     57#endif
    5458
    5559struct _aubio_pitchmcomb_t
     
    134138}
    135139
     140#if 0
    136141uint_t
    137142aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, smpl_t * cands)
     
    164169  }
    165170}
     171#endif
    166172
    167173void
     
    314320}
    315321
     322#if 0
    316323void
    317324aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins)
     
    343350}
    344351
    345 
    346352void
    347353aubio_pitchmcomb_sort_cand_freq (aubio_spectralcandidate_t ** candidates,
     
    357363  }
    358364}
     365#endif
    359366
    360367aubio_pitchmcomb_t *
  • src/pitch/pitchspecacf.c

    r5b46bc3 r633400d  
    4343{
    4444  aubio_pitchspecacf_t *p = AUBIO_NEW (aubio_pitchspecacf_t);
     45  p->fft = new_aubio_fft (bufsize);
     46  if (!p->fft) goto beach;
    4547  p->win = new_aubio_window ("hanningz", bufsize);
    4648  p->winput = new_fvec (bufsize);
    47   p->fft = new_aubio_fft (bufsize);
    4849  p->fftout = new_fvec (bufsize);
    4950  p->sqrmag = new_fvec (bufsize);
     
    5253  p->confidence = 0.;
    5354  return p;
     55
     56beach:
     57  AUBIO_FREE(p);
     58  return NULL;
    5459}
    5560
  • src/pitch/pitchyin.c

    r5b46bc3 r633400d  
    3737  fvec_t *yin;
    3838  smpl_t tol;
    39   smpl_t confidence;
     39  uint_t peak_pos;
    4040};
    4141
     42#if 0
    4243/** compute difference function
    4344
     
    6162*/
    6263uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf);
     64#endif
    6365
    6466aubio_pitchyin_t *
     
    6870  o->yin = new_fvec (bufsize / 2);
    6971  o->tol = 0.15;
     72  o->peak_pos = 0;
    7073  return o;
    7174}
     
    7881}
    7982
     83#if 0
    8084/* outputs the difference function */
    8185void
     
    127131  return 0;
    128132}
    129 
     133#endif
    130134
    131135/* all the above in one */
     
    133137aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out)
    134138{
    135   smpl_t tol = o->tol;
    136   fvec_t *yin = o->yin;
    137   uint_t j, tau = 0;
     139  const smpl_t tol = o->tol;
     140  fvec_t* yin = o->yin;
     141  const smpl_t *input_data = input->data;
     142  const uint_t length = yin->length;
     143  smpl_t *yin_data = yin->data;
     144  uint_t j, tau;
    138145  sint_t period;
    139   smpl_t tmp = 0., tmp2 = 0.;
    140   yin->data[0] = 1.;
    141   for (tau = 1; tau < yin->length; tau++) {
    142     yin->data[tau] = 0.;
    143     for (j = 0; j < yin->length; j++) {
    144       tmp = input->data[j] - input->data[j + tau];
    145       yin->data[tau] += SQR (tmp);
     146  smpl_t tmp, tmp2 = 0.;
     147
     148  yin_data[0] = 1.;
     149  for (tau = 1; tau < length; tau++) {
     150    yin_data[tau] = 0.;
     151    for (j = 0; j < length; j++) {
     152      tmp = input_data[j] - input_data[j + tau];
     153      yin_data[tau] += SQR (tmp);
    146154    }
    147     tmp2 += yin->data[tau];
     155    tmp2 += yin_data[tau];
    148156    if (tmp2 != 0) {
    149157      yin->data[tau] *= tau / tmp2;
     
    152160    }
    153161    period = tau - 3;
    154     if (tau > 4 && (yin->data[period] < tol) &&
    155         (yin->data[period] < yin->data[period + 1])) {
    156       out->data[0] = fvec_quadratic_peak_pos (yin, period);
    157       goto beach;
     162    if (tau > 4 && (yin_data[period] < tol) &&
     163        (yin_data[period] < yin_data[period + 1])) {
     164      o->peak_pos = (uint_t)period;
     165      out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
     166      return;
    158167    }
    159168  }
    160   out->data[0] = fvec_quadratic_peak_pos (yin, fvec_min_elem (yin));
    161 beach:
    162   return;
     169  o->peak_pos = (uint_t)fvec_min_elem (yin);
     170  out->data[0] = fvec_quadratic_peak_pos (yin, o->peak_pos);
    163171}
    164172
    165173smpl_t
    166174aubio_pitchyin_get_confidence (aubio_pitchyin_t * o) {
    167   o->confidence = 1. - fvec_min (o->yin);
    168   return o->confidence;
     175  return 1. - o->yin->data[o->peak_pos];
    169176}
    170177
  • src/pitch/pitchyinfft.c

    r5b46bc3 r633400d  
    3737  fvec_t *yinfft;     /**< Yin function */
    3838  smpl_t tol;         /**< Yin tolerance */
    39   smpl_t confidence;  /**< confidence */
     39  uint_t peak_pos;    /**< currently selected peak pos*/
    4040  uint_t short_period; /** shortest period under which to check for octave error */
    4141};
     
    4545   160.,   200.,   250.,   315.,   400.,   500.,   630.,   800.,  1000.,  1250.,
    4646  1600.,  2000.,  2500.,  3150.,  4000.,  5000.,  6300.,  8000.,  9000., 10000.,
    47  12500., 15000., 20000., 25100
     47 12500., 15000., 20000., 25100., -1.
    4848};
    4949
     
    6363  p->winput = new_fvec (bufsize);
    6464  p->fft = new_aubio_fft (bufsize);
     65  if (!p->fft) goto beach;
    6566  p->fftout = new_fvec (bufsize);
    6667  p->sqrmag = new_fvec (bufsize);
    6768  p->yinfft = new_fvec (bufsize / 2 + 1);
    6869  p->tol = 0.85;
     70  p->peak_pos = 0;
    6971  p->win = new_aubio_window ("hanningz", bufsize);
    7072  p->weight = new_fvec (bufsize / 2 + 1);
    7173  for (i = 0; i < p->weight->length; i++) {
    7274    freq = (smpl_t) i / (smpl_t) bufsize *(smpl_t) samplerate;
    73     while (freq > freqs[j]) {
     75    while (freq > freqs[j] && freqs[j] > 0) {
     76      //AUBIO_DBG("freq %3.5f > %3.5f \tsamplerate %d (Hz) \t"
     77      //    "(weight length %d, bufsize %d) %d %d\n", freq, freqs[j],
     78      //    samplerate, p->weight->length, bufsize, i, j);
    7479      j += 1;
    7580    }
     
    96101  p->short_period = (uint_t)ROUND(samplerate / 1300.);
    97102  return p;
     103
     104beach:
     105  if (p->winput) del_fvec(p->winput);
     106  AUBIO_FREE(p);
     107  return NULL;
    98108}
    99109
     
    156166      halfperiod = FLOOR (tau / 2 + .5);
    157167      if (yin->data[halfperiod] < p->tol)
    158         output->data[0] = fvec_quadratic_peak_pos (yin, halfperiod);
     168        p->peak_pos = halfperiod;
    159169      else
    160         output->data[0] = fvec_quadratic_peak_pos (yin, tau);
     170        p->peak_pos = tau;
     171      output->data[0] = fvec_quadratic_peak_pos (yin, p->peak_pos);
    161172    }
    162173  } else {
     174    p->peak_pos = 0;
    163175    output->data[0] = 0.;
    164176  }
     
    180192smpl_t
    181193aubio_pitchyinfft_get_confidence (aubio_pitchyinfft_t * o) {
    182   o->confidence = 1. - fvec_min (o->yinfft);
    183   return o->confidence;
     194  return 1. - o->yinfft->data[o->peak_pos];
    184195}
    185196
  • src/spectral/fft.c

    r5b46bc3 r633400d  
    7878pthread_mutex_t aubio_fftw_mutex = PTHREAD_MUTEX_INITIALIZER;
    7979
    80 #else
    81 #ifdef HAVE_ACCELERATE        // using ACCELERATE
     80#elif defined HAVE_ACCELERATE        // using ACCELERATE
    8281// https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html
    8382#include <Accelerate/Accelerate.h>
     
    9190#define aubio_vDSP_vsadd               vDSP_vsadd
    9291#define aubio_vDSP_vsmul               vDSP_vsmul
    93 #define aubio_vDSP_create_fftsetup     vDSP_create_fftsetup
    94 #define aubio_vDSP_destroy_fftsetup    vDSP_destroy_fftsetup
    9592#define aubio_DSPComplex               DSPComplex
    9693#define aubio_DSPSplitComplex          DSPSplitComplex
    97 #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
    9898#define aubio_vvsqrt                   vvsqrtf
    9999#else
     
    105105#define aubio_vDSP_vsadd               vDSP_vsaddD
    106106#define aubio_vDSP_vsmul               vDSP_vsmulD
    107 #define aubio_vDSP_create_fftsetup     vDSP_create_fftsetupD
    108 #define aubio_vDSP_destroy_fftsetup    vDSP_destroy_fftsetupD
    109107#define aubio_DSPComplex               DSPDoubleComplex
    110108#define aubio_DSPSplitComplex          DSPDoubleSplitComplex
    111 #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
    112113#define aubio_vvsqrt                   vvsqrt
    113114#endif /* HAVE_AUBIO_DOUBLE */
    114115
    115 #else                         // using OOURA
     116#elif defined HAVE_INTEL_IPP // using INTEL IPP
     117
     118#if !HAVE_AUBIO_DOUBLE
     119#define aubio_IppFloat                 Ipp32f
     120#define aubio_IppComplex               Ipp32fc
     121#define aubio_FFTSpec                  FFTSpec_R_32f
     122#define aubio_ippsMalloc_complex       ippsMalloc_32fc
     123#define aubio_ippsFFTInit_R            ippsFFTInit_R_32f
     124#define aubio_ippsFFTGetSize_R         ippsFFTGetSize_R_32f
     125#define aubio_ippsFFTInv_CCSToR        ippsFFTInv_CCSToR_32f
     126#define aubio_ippsFFTFwd_RToCCS        ippsFFTFwd_RToCCS_32f
     127#define aubio_ippsAtan2                ippsAtan2_32f_A21
     128#else /* HAVE_AUBIO_DOUBLE */
     129#define aubio_IppFloat                 Ipp64f
     130#define aubio_IppComplex               Ipp64fc
     131#define aubio_FFTSpec                  FFTSpec_R_64f
     132#define aubio_ippsMalloc_complex       ippsMalloc_64fc
     133#define aubio_ippsFFTInit_R            ippsFFTInit_R_64f
     134#define aubio_ippsFFTGetSize_R         ippsFFTGetSize_R_64f
     135#define aubio_ippsFFTInv_CCSToR        ippsFFTInv_CCSToR_64f
     136#define aubio_ippsFFTFwd_RToCCS        ippsFFTFwd_RToCCS_64f
     137#define aubio_ippsAtan2                ippsAtan2_64f_A50
     138#endif
     139
     140
     141#else // using OOURA
    116142// let's use ooura instead
    117143extern void aubio_ooura_rdft(int, int, smpl_t *, int *, smpl_t *);
    118144
    119 #endif /* HAVE_ACCELERATE */
    120 #endif /* HAVE_FFTW3 */
     145#endif
    121146
    122147struct _aubio_fft_t {
    123148  uint_t winsize;
    124149  uint_t fft_size;
     150
    125151#ifdef HAVE_FFTW3             // using FFTW3
    126152  real_t *in, *out;
    127153  fftw_plan pfw, pbw;
    128   fft_data_t * specdata;      /* complex spectral data */
    129 #else
    130 #ifdef HAVE_ACCELERATE        // using ACCELERATE
    131   int log2fftsize;
    132   aubio_FFTSetup fftSetup;
     154  fft_data_t * specdata; /* complex spectral data */
     155
     156#elif defined HAVE_ACCELERATE  // using ACCELERATE
     157  aubio_vDSP_DFT_Setup fftSetupFwd;
     158  aubio_vDSP_DFT_Setup fftSetupBwd;
    133159  aubio_DSPSplitComplex spec;
    134160  smpl_t *in, *out;
     161
     162#elif defined HAVE_INTEL_IPP  // using Intel IPP
     163  smpl_t *in, *out;
     164  Ipp8u* memSpec;
     165  Ipp8u* memInit;
     166  Ipp8u* memBuffer;
     167  struct aubio_FFTSpec* fftSpec;
     168  aubio_IppComplex* complexOut;
    135169#else                         // using OOURA
    136170  smpl_t *in, *out;
    137171  smpl_t *w;
    138172  int *ip;
    139 #endif /* HAVE_ACCELERATE */
    140 #endif /* HAVE_FFTW3 */
     173#endif /* using OOURA */
     174
    141175  fvec_t * compspec;
    142176};
     
    148182    goto beach;
    149183  }
     184
    150185#ifdef HAVE_FFTW3
    151186  uint_t i;
     
    176211    s->specdata[i] = 0.;
    177212  }
    178 #else
    179 #ifdef HAVE_ACCELERATE        // using ACCELERATE
     213
     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          "--enable-fftw3.\n", winsize);
     227      goto beach;
     228    }
     229  }
    180230  s->winsize = winsize;
    181231  s->fft_size = winsize;
    182232  s->compspec = new_fvec(winsize);
    183   s->log2fftsize = (uint_t)log2f(s->fft_size);
    184233  s->in = AUBIO_ARRAY(smpl_t, s->fft_size);
    185234  s->out = AUBIO_ARRAY(smpl_t, s->fft_size);
    186235  s->spec.realp = AUBIO_ARRAY(smpl_t, s->fft_size/2);
    187236  s->spec.imagp = AUBIO_ARRAY(smpl_t, s->fft_size/2);
    188   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);
     241
     242#elif defined HAVE_INTEL_IPP  // using Intel IPP
     243  const IppHintAlgorithm qualityHint = ippAlgHintAccurate; // OR ippAlgHintFast;
     244  const int flags = IPP_FFT_NODIV_BY_ANY; // we're scaling manually afterwards
     245  int order = aubio_power_of_two_order(winsize);
     246  int sizeSpec, sizeInit, sizeBuffer;
     247  IppStatus status;
     248
     249  if (winsize <= 4 || aubio_is_power_of_two(winsize) != 1)
     250  {
     251    AUBIO_ERR("intel IPP fft: can only create with sizes > 4 and power of two, requested %d,"
     252      " try recompiling aubio with --enable-fftw3\n", winsize);
     253    goto beach;
     254  }
     255
     256  status = aubio_ippsFFTGetSize_R(order, flags, qualityHint,
     257      &sizeSpec, &sizeInit, &sizeBuffer);
     258  if (status != ippStsNoErr) {
     259    AUBIO_ERR("fft: failed to initialize fft. IPP error: %d\n", status);
     260    goto beach;
     261  }
     262  s->fft_size = s->winsize = winsize;
     263  s->compspec = new_fvec(winsize);
     264  s->in = AUBIO_ARRAY(smpl_t, s->winsize);
     265  s->out = AUBIO_ARRAY(smpl_t, s->winsize);
     266  s->memSpec = ippsMalloc_8u(sizeSpec);
     267  s->memBuffer = ippsMalloc_8u(sizeBuffer);
     268  if (sizeInit > 0 ) {
     269    s->memInit = ippsMalloc_8u(sizeInit);
     270  }
     271  s->complexOut = aubio_ippsMalloc_complex(s->fft_size / 2 + 1);
     272  status = aubio_ippsFFTInit_R(
     273    &s->fftSpec, order, flags, qualityHint, s->memSpec, s->memInit);
     274  if (status != ippStsNoErr) {
     275    AUBIO_ERR("fft: failed to initialize. IPP error: %d\n", status);
     276    goto beach;
     277  }
     278
    189279#else                         // using OOURA
    190280  if (aubio_is_power_of_two(winsize) != 1) {
     
    201291  s->w     = AUBIO_ARRAY(smpl_t, s->fft_size);
    202292  s->ip[0] = 0;
    203 #endif /* HAVE_ACCELERATE */
    204 #endif /* HAVE_FFTW3 */
     293#endif /* using OOURA */
     294
    205295  return s;
     296
    206297beach:
    207298  AUBIO_FREE(s);
     
    211302void del_aubio_fft(aubio_fft_t * s) {
    212303  /* destroy data */
    213   del_fvec(s->compspec);
    214304#ifdef HAVE_FFTW3             // using FFTW3
    215305  pthread_mutex_lock(&aubio_fftw_mutex);
     
    218308  fftw_free(s->specdata);
    219309  pthread_mutex_unlock(&aubio_fftw_mutex);
    220 #else /* HAVE_FFTW3 */
    221 #ifdef HAVE_ACCELERATE        // using ACCELERATE
     310
     311#elif defined HAVE_ACCELERATE // using ACCELERATE
    222312  AUBIO_FREE(s->spec.realp);
    223313  AUBIO_FREE(s->spec.imagp);
    224   aubio_vDSP_destroy_fftsetup(s->fftSetup);
     314  aubio_vDSP_DFT_DestroySetup(s->fftSetupBwd);
     315  aubio_vDSP_DFT_DestroySetup(s->fftSetupFwd);
     316
     317#elif defined HAVE_INTEL_IPP  // using Intel IPP
     318  ippFree(s->memSpec);
     319  ippFree(s->memInit);
     320  ippFree(s->memBuffer);
     321  ippFree(s->complexOut);
     322
    225323#else                         // using OOURA
    226324  AUBIO_FREE(s->w);
    227325  AUBIO_FREE(s->ip);
    228 #endif /* HAVE_ACCELERATE */
    229 #endif /* HAVE_FFTW3 */
     326#endif
     327
     328  del_fvec(s->compspec);
     329  AUBIO_FREE(s->in);
    230330  AUBIO_FREE(s->out);
    231   AUBIO_FREE(s->in);
    232331  AUBIO_FREE(s);
    233332}
     
    252351  memcpy(s->in, input->data, s->winsize * sizeof(smpl_t));
    253352#endif /* HAVE_MEMCPY_HACKS */
     353
    254354#ifdef HAVE_FFTW3             // using FFTW3
    255355  fftw_execute(s->pfw);
     
    266366  }
    267367#endif /* HAVE_COMPLEX_H */
    268 #else /* HAVE_FFTW3 */
    269 #ifdef HAVE_ACCELERATE        // using ACCELERATE
     368
     369#elif defined HAVE_ACCELERATE // using ACCELERATE
    270370  // convert real data to even/odd format used in vDSP
    271371  aubio_vDSP_ctoz((aubio_DSPComplex*)s->in, 2, &s->spec, 1, s->fft_size/2);
    272372  // compute the FFT
    273   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);
    274375  // convert from vDSP complex split to [ r0, r1, ..., rN, iN-1, .., i2, i1]
    275376  compspec->data[0] = s->spec.realp[0];
     
    282383  smpl_t scale = 1./2.;
    283384  aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size);
     385
     386#elif defined HAVE_INTEL_IPP  // using Intel IPP
     387
     388  // apply fft
     389  aubio_ippsFFTFwd_RToCCS(s->in, (aubio_IppFloat*)s->complexOut, s->fftSpec, s->memBuffer);
     390  // convert complex buffer to [ r0, r1, ..., rN, iN-1, .., i2, i1]
     391  compspec->data[0] = s->complexOut[0].re;
     392  compspec->data[s->fft_size / 2] = s->complexOut[s->fft_size / 2].re;
     393  for (i = 1; i < s->fft_size / 2; i++) {
     394    compspec->data[i] = s->complexOut[i].re;
     395    compspec->data[s->fft_size - i] = s->complexOut[i].im;
     396  }
     397
    284398#else                         // using OOURA
    285399  aubio_ooura_rdft(s->winsize, 1, s->in, s->ip, s->w);
     
    290404    compspec->data[s->winsize - i] = - s->in[2 * i + 1];
    291405  }
    292 #endif /* HAVE_ACCELERATE */
    293 #endif /* HAVE_FFTW3 */
     406#endif /* using OOURA */
    294407}
    295408
     
    314427    output->data[i] = s->out[i]*renorm;
    315428  }
    316 #else /* HAVE_FFTW3 */
    317 #ifdef HAVE_ACCELERATE        // using ACCELERATE
     429
     430#elif defined HAVE_ACCELERATE // using ACCELERATE
    318431  // convert from real imag  [ r0, r1, ..., rN, iN-1, .., i2, i1]
    319432  // to vDSP packed format   [ r0, rN, r1, i1, ..., rN-1, iN-1 ]
     
    327440  aubio_vDSP_ctoz((aubio_DSPComplex*)s->out, 2, &s->spec, 1, s->fft_size/2);
    328441  // compute the FFT
    329   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);
    330444  // convert result to real output
    331445  aubio_vDSP_ztoc(&s->spec, 1, (aubio_DSPComplex*)output->data, 2, s->fft_size/2);
     
    333447  smpl_t scale = 1.0 / s->winsize;
    334448  aubio_vDSP_vsmul(output->data, 1, &scale, output->data, 1, s->fft_size);
     449
     450#elif defined HAVE_INTEL_IPP  // using Intel IPP
     451
     452  // convert from real imag  [ r0, 0, ..., rN, iN-1, .., i2, i1, iN-1] to complex format
     453  s->complexOut[0].re = compspec->data[0];
     454  s->complexOut[0].im = 0;
     455  s->complexOut[s->fft_size / 2].re = compspec->data[s->fft_size / 2];
     456  s->complexOut[s->fft_size / 2].im = 0.0;
     457  for (i = 1; i < s->fft_size / 2; i++) {
     458    s->complexOut[i].re = compspec->data[i];
     459    s->complexOut[i].im = compspec->data[s->fft_size - i];
     460  }
     461  // apply fft
     462  aubio_ippsFFTInv_CCSToR((const aubio_IppFloat *)s->complexOut, output->data, s->fftSpec, s->memBuffer);
     463  // apply scaling
     464  aubio_ippsMulC(output->data, 1.0 / s->winsize, output->data, s->fft_size);
     465
    335466#else                         // using OOURA
    336467  smpl_t scale = 2.0 / s->winsize;
     
    345476    output->data[i] = s->out[i] * scale;
    346477  }
    347 #endif /* HAVE_ACCELERATE */
    348 #endif /* HAVE_FFTW3 */
     478#endif
    349479}
    350480
     
    366496    spectrum->phas[0] = 0.;
    367497  }
     498#if defined(HAVE_INTEL_IPP)
     499  // convert from real imag  [ r0, r1, ..., rN, iN-1, ..., i2, i1, i0]
     500  //                     to  [ r0, r1, ..., rN, i0, i1, i2, ..., iN-1]
     501  for (i = 1; i < spectrum->length / 2; i++) {
     502    ELEM_SWAP(compspec->data[compspec->length - i],
     503        compspec->data[spectrum->length + i - 1]);
     504  }
     505  aubio_ippsAtan2(compspec->data + spectrum->length,
     506      compspec->data + 1, spectrum->phas + 1, spectrum->length - 1);
     507  // revert the imaginary part back again
     508  for (i = 1; i < spectrum->length / 2; i++) {
     509    ELEM_SWAP(compspec->data[spectrum->length + i - 1],
     510        compspec->data[compspec->length - i]);
     511  }
     512#else
    368513  for (i=1; i < spectrum->length - 1; i++) {
    369514    spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i],
    370515        compspec->data[i]);
    371516  }
    372   if (compspec->data[compspec->length/2] < 0) {
    373     spectrum->phas[spectrum->length - 1] = PI;
     517#endif
     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
    374528  } else {
    375     spectrum->phas[spectrum->length - 1] = 0.;
    376   }
     529    i = spectrum->length - 1;
     530    spectrum->phas[i] = ATAN2(compspec->data[compspec->length-i],
     531        compspec->data[i]);
     532  }
     533#endif
    377534}
    378535
     
    384541        + SQR(compspec->data[compspec->length - i]) );
    385542  }
    386   spectrum->norm[spectrum->length-1] =
    387     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->length-1] =
     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
    388556}
    389557
  • src/spectral/filterbank.c

    r5b46bc3 r633400d  
    2424#include "fmat.h"
    2525#include "cvec.h"
     26#include "vecutils.h"
    2627#include "spectral/filterbank.h"
    2728#include "mathutils.h"
     
    3334  uint_t n_filters;
    3435  fmat_t *filters;
     36  smpl_t norm;
     37  smpl_t power;
    3538};
    3639
     
    4043  /* allocate space for filterbank object */
    4144  aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
     45
     46  if ((sint_t)n_filters <= 0) {
     47    AUBIO_ERR("filterbank: n_filters should be > 0, got %d\n", n_filters);
     48    goto fail;
     49  }
     50  if ((sint_t)win_s <= 0) {
     51    AUBIO_ERR("filterbank: win_s should be > 0, got %d\n", win_s);
     52    goto fail;
     53  }
    4254  fb->win_s = win_s;
    4355  fb->n_filters = n_filters;
     
    4658  fb->filters = new_fmat (n_filters, win_s / 2 + 1);
    4759
     60  fb->norm = 1;
     61
     62  fb->power = 1;
     63
    4864  return fb;
     65fail:
     66  AUBIO_FREE (fb);
     67  return NULL;
    4968}
    5069
     
    6887  tmp.data = in->norm;
    6988
     89  if (f->power != 1.) fvec_pow(&tmp, f->power);
     90
    7091  fmat_vecmul(f->filters, &tmp, out);
    7192
     
    85106  return 0;
    86107}
     108
     109uint_t
     110aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm)
     111{
     112  if (norm != 0 && norm != 1) return AUBIO_FAIL;
     113  f->norm = norm;
     114  return AUBIO_OK;
     115}
     116
     117smpl_t
     118aubio_filterbank_get_norm (aubio_filterbank_t *f)
     119{
     120  return f->norm;
     121}
     122
     123uint_t
     124aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power)
     125{
     126  f->power = power;
     127  return AUBIO_OK;
     128}
     129
     130smpl_t
     131aubio_filterbank_get_power (aubio_filterbank_t *f)
     132{
     133  return f->power;
     134}
  • src/spectral/filterbank.h

    r5b46bc3 r633400d  
    8484uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters);
    8585
     86/** set norm parameter
     87
     88  \param f filterbank object, as returned by new_aubio_filterbank()
     89  \param norm `1` to norm the filters, `0` otherwise.
     90
     91  If set to `0`, the filters will not be normalized. If set to `1`,
     92  each filter will be normalized to one. Defaults to `1`.
     93
     94  This function should be called *before* setting the filters with one of
     95  aubio_filterbank_set_triangle_bands(), aubio_filterbank_set_mel_coeffs(),
     96  aubio_filterbank_set_mel_coeffs_htk(), or
     97  aubio_filterbank_set_mel_coeffs_slaney().
     98
     99 */
     100uint_t aubio_filterbank_set_norm (aubio_filterbank_t *f, smpl_t norm);
     101
     102/** get norm parameter
     103
     104  \param f filterbank object, as returned by new_aubio_filterbank()
     105  \returns `1` if norm is set, `0` otherwise. Defaults to `1`.
     106
     107 */
     108smpl_t aubio_filterbank_get_norm (aubio_filterbank_t *f);
     109
     110/** set power parameter
     111
     112  \param f filterbank object, as returned by new_aubio_filterbank()
     113  \param power Raise norm of the input spectrum norm to this power before
     114  computing filterbank.  Defaults to `1`.
     115
     116 */
     117uint_t aubio_filterbank_set_power (aubio_filterbank_t *f, smpl_t power);
     118
     119/** get power parameter
     120
     121  \param f filterbank object, as returned by new_aubio_filterbank()
     122  \return current power parameter. Defaults to `1`.
     123
     124 */
     125smpl_t aubio_filterbank_get_power (aubio_filterbank_t *f);
     126
    86127#ifdef __cplusplus
    87128}
  • src/spectral/filterbank_mel.c

    r5b46bc3 r633400d  
    5555  }
    5656
    57   if (freqs->data[freqs->length - 1] > samplerate / 2) {
    58     AUBIO_WRN ("Nyquist frequency is %fHz, but highest frequency band ends at \
    59 %fHz\n", samplerate / 2, freqs->data[freqs->length - 1]);
     57  for (fn = 0; fn < freqs->length; fn++) {
     58    if (freqs->data[fn] < 0) {
     59      AUBIO_ERR("filterbank_mel: freqs must contain only positive values.\n");
     60      return AUBIO_FAIL;
     61    } else if (freqs->data[fn] > samplerate / 2) {
     62      AUBIO_WRN("filterbank_mel: freqs should contain only "
     63          "values < samplerate / 2.\n");
     64    } else if (fn > 0 && freqs->data[fn] < freqs->data[fn-1]) {
     65      AUBIO_ERR("filterbank_mel: freqs should be a list of frequencies "
     66          "sorted from low to high, but freq[%d] < freq[%d-1]\n", fn, fn);
     67      return AUBIO_FAIL;
     68    } else if (fn > 0 && freqs->data[fn] == freqs->data[fn-1]) {
     69      AUBIO_WRN("filterbank_mel: set_triangle_bands received a list "
     70          "with twice the frequency %f\n", freqs->data[fn]);
     71    }
    6072  }
    6173
     
    7991
    8092  /* compute triangle heights so that each triangle has unit area */
    81   for (fn = 0; fn < n_filters; fn++) {
    82     triangle_heights->data[fn] =
    83         2. / (upper_freqs->data[fn] - lower_freqs->data[fn]);
     93  if (aubio_filterbank_get_norm(fb)) {
     94    for (fn = 0; fn < n_filters; fn++) {
     95      triangle_heights->data[fn] =
     96          2. / (upper_freqs->data[fn] - lower_freqs->data[fn]);
     97    }
     98  } else {
     99    fvec_ones (triangle_heights);
    84100  }
    85101
     
    92108  /* zeroing of all filters */
    93109  fmat_zeros (filters);
    94 
    95   if (fft_freqs->data[1] >= lower_freqs->data[0]) {
    96     /* - 1 to make sure we don't miss the smallest power of two */
    97     uint_t min_win_s =
    98         (uint_t) FLOOR (samplerate / lower_freqs->data[0]) - 1;
    99     AUBIO_WRN ("Lowest frequency bin (%.2fHz) is higher than lowest frequency \
    100 band (%.2f-%.2fHz). Consider increasing the window size from %d to %d.\n",
    101         fft_freqs->data[1], lower_freqs->data[0],
    102         upper_freqs->data[0], (win_s - 1) * 2,
    103         aubio_next_power_of_two (min_win_s));
    104   }
    105110
    106111  /* building each filter table */
     
    117122
    118123    /* compute positive slope step size */
    119     riseInc =
    120         triangle_heights->data[fn] /
    121         (center_freqs->data[fn] - lower_freqs->data[fn]);
     124    riseInc = triangle_heights->data[fn]
     125      / (center_freqs->data[fn] - lower_freqs->data[fn]);
    122126
    123127    /* compute coefficients in positive slope */
     
    133137
    134138    /* compute negative slope step size */
    135     downInc =
    136         triangle_heights->data[fn] /
    137         (upper_freqs->data[fn] - center_freqs->data[fn]);
     139    downInc = triangle_heights->data[fn]
     140      / (upper_freqs->data[fn] - center_freqs->data[fn]);
    138141
    139142    /* compute coefficents in negative slope */
     
    161164  del_fvec (fft_freqs);
    162165
    163   return 0;
     166  return AUBIO_OK;
    164167}
    165168
     
    168171    smpl_t samplerate)
    169172{
    170   uint_t retval;
    171 
    172173  /* Malcolm Slaney parameters */
    173   smpl_t lowestFrequency = 133.3333;
    174   smpl_t linearSpacing = 66.66666666;
    175   smpl_t logSpacing = 1.0711703;
    176 
    177   uint_t linearFilters = 13;
    178   uint_t logFilters = 27;
    179   uint_t n_filters = linearFilters + logFilters;
    180 
    181   uint_t fn;                    /* filter counter */
    182 
     174  const smpl_t lowestFrequency = 133.3333;
     175  const smpl_t linearSpacing = 66.66666666;
     176  const smpl_t logSpacing = 1.0711703;
     177
     178  const uint_t linearFilters = 13;
     179  const uint_t logFilters = 27;
     180  const uint_t n_filters = linearFilters + logFilters;
     181
     182  uint_t fn, retval;
    183183  smpl_t lastlinearCF;
    184184
    185185  /* buffers to compute filter frequencies */
    186   fvec_t *freqs = new_fvec (n_filters + 2);
     186  fvec_t *freqs;
     187
     188  if (samplerate <= 0) {
     189    AUBIO_ERR("filterbank: set_mel_coeffs_slaney samplerate should be > 0\n");
     190    return AUBIO_FAIL;
     191  }
     192
     193  freqs = new_fvec (n_filters + 2);
    187194
    188195  /* first step: fill all the linear filter frequencies */
     
    206213  return retval;
    207214}
     215
     216static uint_t aubio_filterbank_check_freqs (aubio_filterbank_t *fb UNUSED,
     217    smpl_t samplerate, smpl_t *freq_min, smpl_t *freq_max)
     218{
     219  if (samplerate <= 0) {
     220    AUBIO_ERR("filterbank: set_mel_coeffs samplerate should be > 0\n");
     221    return AUBIO_FAIL;
     222  }
     223  if (*freq_max < 0) {
     224    AUBIO_ERR("filterbank: set_mel_coeffs freq_max should be > 0\n");
     225    return AUBIO_FAIL;
     226  } else if (*freq_max == 0) {
     227    *freq_max = samplerate / 2.;
     228  }
     229  if (*freq_min < 0) {
     230    AUBIO_ERR("filterbank: set_mel_coeffs freq_min should be > 0\n");
     231    return AUBIO_FAIL;
     232  }
     233  return AUBIO_OK;
     234}
     235
     236uint_t
     237aubio_filterbank_set_mel_coeffs (aubio_filterbank_t * fb, smpl_t samplerate,
     238    smpl_t freq_min, smpl_t freq_max)
     239{
     240  uint_t m, retval;
     241  smpl_t start = freq_min, end = freq_max, step;
     242  fvec_t *freqs;
     243  fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
     244  uint_t n_bands = coeffs->height;
     245
     246  if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) {
     247    return AUBIO_FAIL;
     248  }
     249
     250  start = aubio_hztomel(start);
     251  end = aubio_hztomel(end);
     252
     253  freqs = new_fvec(n_bands + 2);
     254  step = (end - start) / (n_bands + 1);
     255
     256  for (m = 0; m < n_bands + 2; m++)
     257  {
     258    freqs->data[m] = MIN(aubio_meltohz(start + step * m), samplerate/2.);
     259  }
     260
     261  retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
     262
     263  /* destroy vector used to store frequency limits */
     264  del_fvec (freqs);
     265  return retval;
     266}
     267
     268uint_t
     269aubio_filterbank_set_mel_coeffs_htk (aubio_filterbank_t * fb, smpl_t samplerate,
     270    smpl_t freq_min, smpl_t freq_max)
     271{
     272  uint_t m, retval;
     273  smpl_t start = freq_min, end = freq_max, step;
     274  fvec_t *freqs;
     275  fmat_t *coeffs = aubio_filterbank_get_coeffs(fb);
     276  uint_t n_bands = coeffs->height;
     277
     278  if (aubio_filterbank_check_freqs(fb, samplerate, &start, &end)) {
     279    return AUBIO_FAIL;
     280  }
     281
     282  start = aubio_hztomel_htk(start);
     283  end = aubio_hztomel_htk(end);
     284
     285  freqs = new_fvec (n_bands + 2);
     286  step = (end - start) / (n_bands + 1);
     287
     288  for (m = 0; m < n_bands + 2; m++)
     289  {
     290    freqs->data[m] = MIN(aubio_meltohz_htk(start + step * m), samplerate/2.);
     291  }
     292
     293  retval = aubio_filterbank_set_triangle_bands (fb, freqs, samplerate);
     294
     295  /* destroy vector used to store frequency limits */
     296  del_fvec (freqs);
     297  return retval;
     298}
  • src/spectral/filterbank_mel.h

    r5b46bc3 r633400d  
    5656
    5757  \param fb filterbank object
    58   \param samplerate audio sampling rate
     58  \param samplerate audio sampling rate, in Hz
    5959
    60   The filter coefficients are built according to Malcolm Slaney's Auditory
    61   Toolbox, available at http://engineering.purdue.edu/~malcolm/interval/1998-010/
    62   (see file mfcc.m).
     60  The filter coefficients are built to match exactly Malcolm Slaney's Auditory
     61  Toolbox implementation (see file mfcc.m). The number of filters should be 40.
     62
     63  References
     64  ----------
     65
     66  Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
     67  https://engineering.purdue.edu/~malcolm/interval/1998-010/
    6368
    6469*/
    6570uint_t aubio_filterbank_set_mel_coeffs_slaney (aubio_filterbank_t * fb,
    6671    smpl_t samplerate);
     72
     73/** Mel filterbank initialization
     74
     75  \param fb filterbank object
     76  \param samplerate audio sampling rate
     77  \param fmin start frequency, in Hz
     78  \param fmax end frequency, in Hz
     79
     80  The filterbank will be initialized with bands linearly spaced in the mel
     81  scale, from `fmin` to `fmax`.
     82
     83  References
     84  ----------
     85
     86  Malcolm Slaney, *Auditory Toolbox Version 2, Technical Report #1998-010*
     87  https://engineering.purdue.edu/~malcolm/interval/1998-010/
     88
     89*/
     90uint_t aubio_filterbank_set_mel_coeffs(aubio_filterbank_t * fb,
     91    smpl_t samplerate, smpl_t fmin, smpl_t fmax);
     92
     93/** Mel filterbank initialization
     94
     95  \param fb filterbank object
     96  \param samplerate audio sampling rate
     97  \param fmin start frequency, in Hz
     98  \param fmax end frequency, in Hz
     99
     100  The bank of filters will be initalized to to cover linearly spaced bands in
     101  the Htk mel scale, from `fmin` to `fmax`.
     102
     103  References
     104  ----------
     105
     106  Douglas O'Shaughnessy (1987). *Speech communication: human and machine*.
     107  Addison-Wesley. p. 150. ISBN 978-0-201-16520-3.
     108
     109  HTK Speech Recognition Toolkit: http://htk.eng.cam.ac.uk/
     110
     111*/
     112uint_t aubio_filterbank_set_mel_coeffs_htk(aubio_filterbank_t * fb,
     113    smpl_t samplerate, smpl_t fmin, smpl_t fmax);
    67114
    68115#ifdef __cplusplus
  • src/spectral/mfcc.c

    r5b46bc3 r633400d  
    2929#include "spectral/filterbank.h"
    3030#include "spectral/filterbank_mel.h"
     31#include "spectral/dct.h"
    3132#include "spectral/mfcc.h"
    3233
     
    3738  uint_t win_s;             /** grain length */
    3839  uint_t samplerate;        /** sample rate (needed?) */
    39   uint_t n_filters;         /** number of  *filters */
     40  uint_t n_filters;         /** number of filters */
    4041  uint_t n_coefs;           /** number of coefficients (<= n_filters/2 +1) */
    4142  aubio_filterbank_t *fb;   /** filter bank */
    4243  fvec_t *in_dct;           /** input buffer for dct * [fb->n_filters] */
    43   fmat_t *dct_coeffs;       /** DCT transform n_filters * n_coeffs */
     44  aubio_dct_t *dct;         /** dct object */
     45  fvec_t *output;           /** dct output */
     46  smpl_t scale;
    4447};
    4548
     
    5255  /* allocate space for mfcc object */
    5356  aubio_mfcc_t *mfcc = AUBIO_NEW (aubio_mfcc_t);
    54   smpl_t scaling;
    5557
    56   uint_t i, j;
     58  if ((sint_t)n_coefs <= 0) {
     59    AUBIO_ERR("mfcc: n_coefs should be > 0, got %d\n", n_coefs);
     60    goto failure;
     61  }
     62  if ((sint_t)samplerate <= 0) {
     63    AUBIO_ERR("mfcc: samplerate should be > 0, got %d\n", samplerate);
     64    goto failure;
     65  }
    5766
    5867  mfcc->win_s = win_s;
     
    6372  /* filterbank allocation */
    6473  mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s);
    65   aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
     74
     75  if (!mfcc->fb)
     76    goto failure;
     77
     78  if (n_filters == 40)
     79    aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
     80  else
     81    aubio_filterbank_set_mel_coeffs(mfcc->fb, samplerate,
     82        0, samplerate/2.);
    6683
    6784  /* allocating buffers */
    6885  mfcc->in_dct = new_fvec (n_filters);
    6986
    70   mfcc->dct_coeffs = new_fmat (n_coefs, n_filters);
     87  mfcc->dct = new_aubio_dct (n_filters);
     88  mfcc->output = new_fvec (n_filters);
    7189
    72   /* compute DCT transform dct_coeffs[j][i] as
    73      cos ( j * (i+.5) * PI / n_filters ) */
    74   scaling = 1. / SQRT (n_filters / 2.);
    75   for (i = 0; i < n_filters; i++) {
    76     for (j = 0; j < n_coefs; j++) {
    77       mfcc->dct_coeffs->data[j][i] =
    78           scaling * COS (j * (i + 0.5) * PI / n_filters);
    79     }
    80     mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.;
    81   }
     90  if (!mfcc->in_dct || !mfcc->dct || !mfcc->output)
     91    goto failure;
     92
     93  mfcc->scale = 1.;
    8294
    8395  return mfcc;
     96
     97failure:
     98  del_aubio_mfcc(mfcc);
     99  return NULL;
    84100}
    85101
     
    87103del_aubio_mfcc (aubio_mfcc_t * mf)
    88104{
    89 
    90   /* delete filterbank */
    91   del_aubio_filterbank (mf->fb);
    92 
    93   /* delete buffers */
    94   del_fvec (mf->in_dct);
    95   del_fmat (mf->dct_coeffs);
    96 
    97   /* delete mfcc object */
     105  if (mf->fb)
     106    del_aubio_filterbank (mf->fb);
     107  if (mf->in_dct)
     108    del_fvec (mf->in_dct);
     109  if (mf->dct)
     110    del_aubio_dct (mf->dct);
     111  if (mf->output)
     112    del_fvec (mf->output);
    98113  AUBIO_FREE (mf);
    99114}
     
    103118aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out)
    104119{
     120  fvec_t tmp;
     121
    105122  /* compute filterbank */
    106123  aubio_filterbank_do (mf->fb, in, mf->in_dct);
     
    109126  fvec_log10 (mf->in_dct);
    110127
    111   /* raise power */
    112   //fvec_pow (mf->in_dct, 3.);
     128  if (mf->scale != 1) fvec_mul (mf->in_dct, mf->scale);
    113129
    114130  /* compute mfccs */
    115   fmat_vecmul(mf->dct_coeffs, mf->in_dct, out);
     131  aubio_dct_do(mf->dct, mf->in_dct, mf->output);
     132  // copy only first n_coeffs elements
     133  // TODO assert mf->output->length == n_coeffs
     134  tmp.data = mf->output->data;
     135  tmp.length = out->length;
     136  fvec_copy(&tmp, out);
    116137
    117138  return;
    118139}
     140
     141uint_t aubio_mfcc_set_power (aubio_mfcc_t *mf, smpl_t power)
     142{
     143  return aubio_filterbank_set_power(mf->fb, power);
     144}
     145
     146smpl_t aubio_mfcc_get_power (aubio_mfcc_t *mf)
     147{
     148  return aubio_filterbank_get_power(mf->fb);
     149}
     150
     151uint_t aubio_mfcc_set_scale (aubio_mfcc_t *mf, smpl_t scale)
     152{
     153  mf->scale = scale;
     154  return AUBIO_OK;
     155}
     156
     157smpl_t aubio_mfcc_get_scale (aubio_mfcc_t *mf)
     158{
     159  return mf->scale;
     160}
     161
     162uint_t aubio_mfcc_set_mel_coeffs (aubio_mfcc_t *mf, smpl_t freq_min,
     163    smpl_t freq_max)
     164{
     165  return aubio_filterbank_set_mel_coeffs(mf->fb, mf->samplerate,
     166      freq_min, freq_max);
     167}
     168
     169uint_t aubio_mfcc_set_mel_coeffs_htk (aubio_mfcc_t *mf, smpl_t freq_min,
     170    smpl_t freq_max)
     171{
     172  return aubio_filterbank_set_mel_coeffs_htk(mf->fb, mf->samplerate,
     173      freq_min, freq_max);
     174}
     175
     176uint_t aubio_mfcc_set_mel_coeffs_slaney (aubio_mfcc_t *mf)
     177{
     178  return aubio_filterbank_set_mel_coeffs_slaney (mf->fb, mf->samplerate);
     179}
  • src/spectral/mfcc.h

    r5b46bc3 r633400d  
    2727
    2828  The implementation follows the specifications established by Malcolm Slaney
    29   in its Auditory Toolbox, available online (see file mfcc.m).
     29  in its Auditory Toolbox, available online at the following address (see
     30  file mfcc.m):
    3031
    31   http://engineering.ecn.purdue.edu/~malcolm/interval/1998-010/
     32  https://engineering.purdue.edu/~malcolm/interval/1998-010/
    3233
    3334  \example spectral/test-mfcc.c
     
    7374void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out);
    7475
     76/** set power parameter
     77
     78  \param mf mfcc object, as returned by new_aubio_mfcc()
     79  \param power Raise norm of the input spectrum norm to this power before
     80  computing filterbank.  Defaults to `1`.
     81
     82  See aubio_filterbank_set_power().
     83
     84 */
     85uint_t aubio_mfcc_set_power (aubio_mfcc_t *mf, smpl_t power);
     86
     87/** get power parameter
     88
     89  \param mf mfcc object, as returned by new_aubio_mfcc()
     90  \return current power parameter. Defaults to `1`.
     91
     92  See aubio_filterbank_get_power().
     93
     94 */
     95smpl_t aubio_mfcc_get_power (aubio_mfcc_t *mf);
     96
     97/** set scaling parameter
     98
     99  \param mf mfcc object, as returned by new_aubio_mfcc()
     100  \param scale Scaling value to apply.
     101
     102  Scales the output of the filterbank after taking its logarithm and before
     103  computing the DCT. Defaults to `1`.
     104
     105*/
     106uint_t aubio_mfcc_set_scale (aubio_mfcc_t *mf, smpl_t scale);
     107
     108/** get scaling parameter
     109
     110  \param mf mfcc object, as returned by new_aubio_mfcc()
     111  \return current scaling parameter. Defaults to `1`.
     112
     113 */
     114smpl_t aubio_mfcc_get_scale (aubio_mfcc_t *mf);
     115
     116/** Mel filterbank initialization
     117
     118  \param mf mfcc object
     119  \param fmin start frequency, in Hz
     120  \param fmax end frequency, in Hz
     121
     122  The filterbank will be initialized with bands linearly spaced in the mel
     123  scale, from `fmin` to `fmax`.
     124
     125  See also
     126  --------
     127
     128  aubio_filterbank_set_mel_coeffs()
     129
     130*/
     131uint_t aubio_mfcc_set_mel_coeffs (aubio_mfcc_t *mf,
     132        smpl_t fmin, smpl_t fmax);
     133
     134/** Mel filterbank initialization
     135
     136  \param mf mfcc object
     137  \param fmin start frequency, in Hz
     138  \param fmax end frequency, in Hz
     139
     140  The bank of filters will be initalized to to cover linearly spaced bands in
     141  the Htk mel scale, from `fmin` to `fmax`.
     142
     143  See also
     144  --------
     145
     146  aubio_filterbank_set_mel_coeffs_htk()
     147
     148*/
     149uint_t aubio_mfcc_set_mel_coeffs_htk (aubio_mfcc_t *mf,
     150        smpl_t fmin, smpl_t fmax);
     151
     152/** Mel filterbank initialization (Auditory Toolbox's parameters)
     153
     154  \param mf mfcc object
     155
     156  The filter coefficients are built to match exactly Malcolm Slaney's Auditory
     157  Toolbox implementation. The number of filters should be 40.
     158
     159  This is the default filterbank when `mf` was created with `n_filters = 40`.
     160
     161  See also
     162  --------
     163
     164  aubio_filterbank_set_mel_coeffs_slaney()
     165
     166*/
     167uint_t aubio_mfcc_set_mel_coeffs_slaney (aubio_mfcc_t *mf);
     168
    75169#ifdef __cplusplus
    76170}
  • src/spectral/ooura_fft8g.c

    r5b46bc3 r633400d  
    33//  - include "aubio_priv.h" (for config.h and types.h)
    44//  - add missing prototypes
    5 //  - use COS and SIN macros
     5//  - use COS, SIN, and ATAN macros
     6//  - add cast to (smpl_t) to avoid float conversion warnings
    67//  - declare initialization as static
    78//  - prefix public function with aubio_ooura_
     
    364365        a[1] = xi;
    365366    } else {
    366         a[1] = 0.5 * (a[0] - a[1]);
     367        a[1] = (smpl_t)0.5 * (a[0] - a[1]);
    367368        a[0] -= a[1];
    368369        if (n > 4) {
     
    693694    if (nw > 2) {
    694695        nwh = nw >> 1;
    695         delta = atan(1.0) / nwh;
     696        delta = ATAN(1.0) / nwh;
    696697        w[0] = 1;
    697698        w[1] = 0;
     
    727728    if (nc > 1) {
    728729        nch = nc >> 1;
    729         delta = atan(1.0) / nch;
    730         c[0] = cos(delta * nch);
    731         c[nch] = 0.5 * c[0];
     730        delta = ATAN(1.0) / nch;
     731        c[0] = COS(delta * nch);
     732        c[nch] = (smpl_t)0.5 * c[0];
    732733        for (j = 1; j < nch; j++) {
    733             c[j] = 0.5 * cos(delta * j);
    734             c[nc - j] = 0.5 * sin(delta * j);
     734            c[j] = (smpl_t)0.5 * COS(delta * j);
     735            c[nc - j] = (smpl_t)0.5 * SIN(delta * j);
    735736        }
    736737    }
     
    15881589        k = n - j;
    15891590        kk += ks;
    1590         wkr = 0.5 - c[nc - kk];
     1591        wkr = (smpl_t)0.5 - c[nc - kk];
    15911592        wki = c[kk];
    15921593        xr = a[j] - a[k];
     
    16141615        k = n - j;
    16151616        kk += ks;
    1616         wkr = 0.5 - c[nc - kk];
     1617        wkr = (smpl_t)0.5 - c[nc - kk];
    16171618        wki = c[kk];
    16181619        xr = a[j] - a[k];
  • src/spectral/phasevoc.c

    r5b46bc3 r633400d  
    8989    goto beach;
    9090  } else if (win_s < hop_s) {
    91     AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", win_s, hop_s);
     91    AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", hop_s, win_s);
    9292    goto beach;
    9393  }
     
    142142  AUBIO_FREE (pv);
    143143  return NULL;
     144}
     145
     146uint_t aubio_pvoc_set_window(aubio_pvoc_t *pv, const char_t *window) {
     147  return fvec_set_window(pv->w, (char_t*)window);
    144148}
    145149
     
    209213    synthold[i] += synth[i + pv->hop_s] * pv->scale;
    210214}
     215
     216uint_t aubio_pvoc_get_win(aubio_pvoc_t* pv)
     217{
     218  return pv->win_s;
     219}
     220
     221uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv)
     222{
     223  return pv->hop_s;
     224}
  • src/spectral/phasevoc.h

    r5b46bc3 r633400d  
    8989*/
    9090uint_t aubio_pvoc_get_win(aubio_pvoc_t* pv);
     91
    9192/** get hop size
    9293
     
    9697uint_t aubio_pvoc_get_hop(aubio_pvoc_t* pv);
    9798
     99/** set window type
     100
     101  \param pv phase vocoder to set the window type
     102  \param window_type a string representing a window
     103
     104  \return 0 if successful, non-zero otherwise
     105
     106 */
     107uint_t aubio_pvoc_set_window(aubio_pvoc_t *pv, const char_t *window_type);
     108
    98109#ifdef __cplusplus
    99110}
  • src/spectral/specdesc.c

    r5b46bc3 r633400d  
    3131void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
    3232void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     33void aubio_specdesc_wphase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
    3334void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
    3435void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     
    5859        aubio_onset_complex,        /**< complex domain */       
    5960        aubio_onset_phase,          /**< phase fast */           
     61        aubio_onset_wphase,         /**< weighted phase */
    6062        aubio_onset_kl,             /**< Kullback Liebler */
    6163        aubio_onset_mkl,            /**< modified Kullback Liebler */
     
    158160  onset->data[0] = aubio_hist_mean(o->histog); 
    159161  //onset->data[0] = fvec_mean(o->dev1);
     162}
     163
     164/* weighted phase */
     165void
     166aubio_specdesc_wphase(aubio_specdesc_t *o,
     167    const cvec_t *fftgrain, fvec_t *onset) {
     168  uint_t i;
     169  aubio_specdesc_phase(o, fftgrain, onset);
     170  for (i = 0; i < fftgrain->length; i++) {
     171    o->dev1->data[i] *= fftgrain->norm[i];
     172  }
     173  /* apply o->histogram */
     174  aubio_hist_dyn_notnull(o->histog,o->dev1);
     175  /* weight it */
     176  aubio_hist_weight(o->histog);
     177  /* its mean is the result */
     178  onset->data[0] = aubio_hist_mean(o->histog);
    160179}
    161180
     
    251270  else if (strcmp (onset_mode, "phase") == 0)
    252271      onset_type = aubio_onset_phase;
     272  else if (strcmp (onset_mode, "wphase") == 0)
     273      onset_type = aubio_onset_wphase;
    253274  else if (strcmp (onset_mode, "mkl") == 0)
    254275      onset_type = aubio_onset_mkl;
     
    271292  else if (strcmp (onset_mode, "rolloff") == 0)
    272293      onset_type = aubio_specmethod_rolloff;
     294  else if (strcmp (onset_mode, "old_default") == 0)
     295      onset_type = aubio_onset_default;
    273296  else if (strcmp (onset_mode, "default") == 0)
    274297      onset_type = aubio_onset_default;
    275298  else {
    276       AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode);
     299      AUBIO_ERR("specdesc: unknown spectral descriptor type '%s'\n",
     300          onset_mode);
    277301      AUBIO_FREE(o);
    278302      return NULL;
     
    292316      break;
    293317    case aubio_onset_phase:
     318    case aubio_onset_wphase:
    294319      o->dev1   = new_fvec(rsize);
    295320      o->theta1 = new_fvec(rsize);
     
    326351      o->funcpointer = aubio_specdesc_phase;
    327352      break;
     353    case aubio_onset_wphase:
     354      o->funcpointer = aubio_specdesc_wphase;
     355      break;
    328356    case aubio_onset_specdiff:
    329357      o->funcpointer = aubio_specdesc_specdiff;
     
    379407      break;
    380408    case aubio_onset_phase:
     409    case aubio_onset_wphase:
    381410      del_fvec(o->dev1);
    382411      del_fvec(o->theta1);
  • src/spectral/specdesc.h

    r5b46bc3 r633400d  
    6060  Hong-Kong, 2003.
    6161
     62  \b \p wphase : Weighted Phase Deviation onset detection function
     63
     64  S. Dixon. Onset detection revisited. In Proceedings of the 9th International
     65  Conference on Digital Audio Ef- fects (DAFx) , pages 133–137, 2006.
     66
     67  http://www.eecs.qmul.ac.uk/~simond/pub/2006/dafx.pdf
     68
    6269  \b \p specdiff : Spectral difference method onset detection function
    6370
     
    175182  The parameter \p method is a string that can be any of:
    176183
    177     - `energy`, `hfc`, `complex`, `phase`, `specdiff`, `kl`, `mkl`, `specflux`
    178     - `centroid`, `spread`, `skewness`, `kurtosis`, `slope`, `decrease`, `rolloff`
     184    - onset novelty functions: `complex`, `energy`, `hfc`, `kl`, `mkl`,
     185    `phase`, `specdiff`, `specflux`, `wphase`,
     186
     187    - spectral descriptors: `centroid`, `decrease`, `kurtosis`, `rolloff`,
     188    `skewness`, `slope`, `spread`.
    179189
    180190*/
  • src/synth/sampler.c

    r5b46bc3 r633400d  
    2020
    2121
    22 #include "config.h"
    2322#include "aubio_priv.h"
    2423#include "fvec.h"
  • src/synth/wavetable.c

    r5b46bc3 r633400d  
    2020
    2121
    22 #include "config.h"
    2322#include "aubio_priv.h"
    2423#include "fvec.h"
     
    105104      output->data[i] += input->data[i];
    106105    }
     106    fvec_clamp(output, 1.);
    107107  }
    108108}
     
    165165  aubio_wavetable_set_amp (s, 0.);
    166166  //s->last_pos = 0;
    167   return aubio_wavetable_set_playing (s, 1);
     167  return aubio_wavetable_set_playing (s, 0);
     168}
     169
     170uint_t
     171aubio_wavetable_load ( aubio_wavetable_t *s UNUSED, const char_t *uri UNUSED)
     172{
     173  AUBIO_ERR("wavetable: load method not implemented yet, see sampler\n");
     174  return AUBIO_FAIL;
    168175}
    169176
  • src/synth/wavetable.h

    r5b46bc3 r633400d  
    5353
    5454/** load source in wavetable
     55
     56  TODO: This function is not implemented yet. See new_aubio_sampler() instead.
    5557
    5658  \param o wavetable, created by new_aubio_wavetable()
  • src/tempo/beattracking.h

    r5b46bc3 r633400d  
    3232  Matthew E. P. Davies, Paul Brossier, and Mark D. Plumbley. Beat tracking
    3333  towards automatic musical accompaniment. In Proceedings of the Audio
    34   Engeeniring Society 118th Convention, Barcelona, Spain, May 2005.
     34  Engineering Society 118th Convention, Barcelona, Spain, May 2005.
    3535
    3636  \example tempo/test-beattracking.c
  • src/tempo/tempo.c

    r5b46bc3 r633400d  
    129129
    130130uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay) {
    131   o->delay = 1000. * delay * o->samplerate;
    132   return AUBIO_OK;
     131  return aubio_tempo_set_delay_s(o, delay / 1000.);
    133132}
    134133
     
    142141
    143142smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o) {
    144   return o->delay / (smpl_t)(o->samplerate) / 1000.;
     143  return aubio_tempo_get_delay_s(o) * 1000.;
    145144}
    146145
     
    169168{
    170169  aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
    171   char_t specdesc_func[20];
     170  char_t specdesc_func[PATH_MAX];
    172171  o->samplerate = samplerate;
    173172  // check parameters are valid
     
    204203  aubio_peakpicker_set_threshold (o->pp, o->threshold);
    205204  if ( strcmp(tempo_mode, "default") == 0 ) {
    206     strcpy(specdesc_func, "specflux");
     205    strncpy(specdesc_func, "specflux", PATH_MAX - 1);
    207206  } else {
    208     strcpy(specdesc_func, tempo_mode);
     207    strncpy(specdesc_func, tempo_mode, PATH_MAX - 1);
     208    specdesc_func[PATH_MAX - 1] = '\0';
    209209  }
    210210  o->od       = new_aubio_specdesc(specdesc_func,buf_size);
     
    216216    onset2 = new_fvec(1);
    217217  }*/
     218  if (!o->dfframe || !o->fftgrain || !o->out || !o->pv ||
     219      !o->pp || !o->od || !o->of || !o->bt || !o->onset) {
     220    AUBIO_ERR("tempo: failed creating tempo object\n");
     221    goto beach;
     222  }
    218223  o->last_tatum = 0;
    219224  o->tatum_signature = 4;
     
    221226
    222227beach:
    223   AUBIO_FREE(o);
     228  del_aubio_tempo(o);
    224229  return NULL;
    225230}
     
    278283void del_aubio_tempo (aubio_tempo_t *o)
    279284{
    280   del_aubio_specdesc(o->od);
    281   del_aubio_beattracking(o->bt);
    282   del_aubio_peakpicker(o->pp);
    283   del_aubio_pvoc(o->pv);
    284   del_fvec(o->out);
    285   del_fvec(o->of);
    286   del_cvec(o->fftgrain);
    287   del_fvec(o->dfframe);
    288   del_fvec(o->onset);
     285  if (o->od)
     286    del_aubio_specdesc(o->od);
     287  if (o->bt)
     288    del_aubio_beattracking(o->bt);
     289  if (o->pp)
     290    del_aubio_peakpicker(o->pp);
     291  if (o->pv)
     292    del_aubio_pvoc(o->pv);
     293  if (o->out)
     294    del_fvec(o->out);
     295  if (o->of)
     296    del_fvec(o->of);
     297  if (o->fftgrain)
     298    del_cvec(o->fftgrain);
     299  if (o->dfframe)
     300    del_fvec(o->dfframe);
     301  if (o->onset)
     302    del_fvec(o->onset);
    289303  AUBIO_FREE(o);
    290   return;
    291 }
     304}
  • src/tempo/tempo.h

    r5b46bc3 r633400d  
    155155  \param o beat tracking object
    156156
    157   \return confidence with which the tempo has been observed, `0` if no
    158   consistent value is found.
     157  \return confidence with which the tempo has been observed, the higher the
     158  more confidence, `0` if no consistent value is found.
    159159
    160160*/
  • src/temporal/biquad.c

    r5b46bc3 r633400d  
    4242  as->data[0] = 1.;
    4343  as->data[1] = a1;
    44   as->data[1] = a2;
     44  as->data[2] = a2;
    4545  return AUBIO_OK;
    4646}
  • src/temporal/resampler.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
    22 
    2321#include "aubio_priv.h"
    2422#include "fvec.h"
     
    2624
    2725#ifdef HAVE_SAMPLERATE
     26
     27#if HAVE_AUBIO_DOUBLE
     28#error "Should not use libsamplerate with aubio in double precision"
     29#endif
    2830
    2931#include <samplerate.h>         /* from libsamplerate */
  • src/utils/hist.c

    r5b46bc3 r633400d  
    4444  smpl_t accum = step;
    4545  uint_t i;
     46  if ((sint_t)nelems <= 0) {
     47    return NULL;
     48  }
    4649  s->nelems = nelems;
    4750  s->hist = new_fvec(nelems);
  • src/utils/log.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "log.h"
     
    3635  FILE *out;
    3736  out = stdout;
    38   if (level == AUBIO_LOG_DBG || level == AUBIO_LOG_ERR) {
     37  if (level == AUBIO_LOG_ERR || level == AUBIO_LOG_DBG || level == AUBIO_LOG_WRN) {
    3938    out = stderr;
    4039  }
  • src/utils/log.h

    r5b46bc3 r633400d  
    4646enum aubio_log_level {
    4747  AUBIO_LOG_ERR, /**< critical errors */
    48   AUBIO_LOG_WRN, /**< warnings */
     48  AUBIO_LOG_INF, /**< infos */
    4949  AUBIO_LOG_MSG, /**< general messages */
    5050  AUBIO_LOG_DBG, /**< debug messages */
     51  AUBIO_LOG_WRN, /**< warnings */
    5152  AUBIO_LOG_LAST_LEVEL, /**< number of valid levels */
    5253};
  • src/utils/parameter.c

    r5b46bc3 r633400d  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "parameter.h"
  • src/utils/windll.c

    r5b46bc3 r633400d  
    2525*/
    2626
    27 #include "config.h"
     27#include "aubio_priv.h"
    2828
    2929#ifdef HAVE_WIN_HACKS
     
    4242#include "aubio.h"
    4343
    44 BOOL APIENTRY DllMain( HMODULE hModule,
     44BOOL APIENTRY DllMain( HMODULE hModule UNUSED,
    4545                       DWORD  ul_reason_for_call,
    46                        LPVOID lpReserved )
     46                       LPVOID lpReserved UNUSED)
    4747{
    4848  switch (ul_reason_for_call)
  • src/vecutils.c

    r5b46bc3 r633400d  
    1 #include "config.h"
    21#include "aubio_priv.h"
    32#include "types.h"
  • src/wscript_build

    r5b46bc3 r633400d  
    44uselib += ['M']
    55uselib += ['FFTW3', 'FFTW3F']
     6uselib += ['INTEL_IPP']
    67uselib += ['SAMPLERATE']
    78uselib += ['SNDFILE']
     
    910uselib += ['AVCODEC']
    1011uselib += ['AVFORMAT']
     12uselib += ['SWRESAMPLE']
    1113uselib += ['AVRESAMPLE']
    1214uselib += ['AVUTIL']
     
    2527    build_features = ['cstlib', 'cshlib']
    2628elif ctx.env['DEST_OS'] in ['win32', 'win64']:
     29    build_features = ['cstlib', 'cshlib gensyms']
     30elif ctx.env['DEST_OS'] in ['emscripten']:
     31    build_features = ['cstlib','cshlib']
     32elif '--static' in ctx.env['LDFLAGS'] or '--static' in ctx.env['LINKFLAGS']:
     33    # static in cflags, ...
     34    build_features = ['cstlib']
     35else:
     36    # linux, darwin, android, mingw, ...
    2737    build_features = ['cstlib', 'cshlib']
    28 elif ctx.env['DEST_OS'] in ['emscripten']:
    29     build_features = ['cstlib']
    30 else: #linux, darwin, android, mingw, ...
    31     build_features = ['cstlib', 'cshlib']
     38
     39# also install static lib
     40from waflib.Tools.c import cstlib
     41cstlib.inst_to = '${LIBDIR}'
    3242
    3343for target in build_features:
     
    3545            use = uselib + ['lib_objects'],
    3646            target = 'aubio',
     47            export_symbols_regex=r'(?:.*aubio|fvec|lvec|cvec|fmat|new|del)_.*',
    3748            vnum = ctx.env['LIB_VERSION'])
    3849
    3950# install headers, except _priv.h ones
    40 ctx.install_files('${PREFIX}/include/aubio/',
     51ctx.install_files('${INCLUDEDIR}/aubio/',
    4152        ctx.path.ant_glob('**/*.h', excl = ['**_priv.h', 'config.h']),
    4253        relative_trick=True)
Note: See TracChangeset for help on using the changeset viewer.