Changes in / [63fc1df:36ab428]


Ignore:
Files:
21 added
9 edited

Legend:

Unmodified
Added
Removed
  • python/lib/moresetuptools.py

    r63fc1df r36ab428  
    8080                'libswresample', 'libavresample',
    8181                'sndfile',
     82                'hdf5',
    8283                #'fftw3f',
    8384               ]
     
    104105        ext.define_macros += [('HAVE_FFTW3F', 1)]
    105106        ext.define_macros += [('HAVE_FFTW3', 1)]
     107    if 'hdf5' in ext.libraries:
     108        ext.libraries += ['hdf5_hl']
     109        ext.define_macros += [('HAVE_HDF5', 1)]
    106110
    107111    # add accelerate on darwin
  • src/aubio_priv.h

    r63fc1df r36ab428  
    134134#define aubio_cblas_swap      cblas_sswap
    135135#define aubio_cblas_dot       cblas_sdot
     136#define aubio_cblas__gemv     cblas_sgemv
     137#define aubio_cblas__gemm     cblas_sgemm
    136138#else /* HAVE_AUBIO_DOUBLE */
    137139#ifdef HAVE_ATLAS
     
    141143#define aubio_cblas_swap      cblas_dswap
    142144#define aubio_cblas_dot       cblas_ddot
     145#define aubio_cblas__gemv     cblas_dgemv
     146#define aubio_cblas__gemm     cblas_dgemm
    143147#endif /* HAVE_AUBIO_DOUBLE */
    144148#endif /* HAVE_BLAS */
     
    410414#endif /* DEBUG */
    411415
     416// goto to failure if condition x is not true
     417#define AUBIO_GOTO_FAILURE(x) if (!(x)) goto failure
     418
     419#define AUBIO_ASSERT_EQUAL_SHAPE(t1, t2) { \
     420    AUBIO_ASSERT(t1 && t2); \
     421    AUBIO_ASSERT(t1->ndim == t2->ndim); \
     422    uint_t nn; \
     423    for (nn = 0; nn < t1->ndim; nn++) \
     424      AUBIO_ASSERT(t1->shape[nn] == t2->shape[nn]); \
     425    }
     426
    412427#endif /* AUBIO_PRIV_H */
  • src/fmat.c

    r63fc1df r36ab428  
    2424fmat_t * new_fmat (uint_t height, uint_t length) {
    2525  fmat_t * s;
    26   uint_t i,j;
    27   if ((sint_t)length <= 0 || (sint_t)height <= 0 ) {
     26  uint_t i;
     27  if ((sint_t)height <= 0 || (sint_t)length <= 0 ) {
    2828    return NULL;
    2929  }
     
    3131  s->height = height;
    3232  s->length = length;
     33  // array of row pointers
    3334  s->data = AUBIO_ARRAY(smpl_t*,s->height);
    34   for (i=0; i< s->height; i++) {
    35     s->data[i] = AUBIO_ARRAY(smpl_t, s->length);
    36     for (j=0; j< s->length; j++) {
    37       s->data[i][j]=0.;
    38     }
     35  // first row store the full height * length buffer
     36  s->data[0] = AUBIO_ARRAY(smpl_t, s->height * s->length);
     37  for (i=1; i< s->height; i++) {
     38    s->data[i] = s->data[0] + i * s->length;
    3939  }
    4040  return s;
     
    4242
    4343void del_fmat (fmat_t *s) {
    44   uint_t i;
    45   for (i=0; i<s->height; i++) {
    46     AUBIO_FREE(s->data[i]);
    47   }
    48   AUBIO_FREE(s->data);
     44  AUBIO_ASSERT(s);
     45  if (s->data[0])
     46    AUBIO_FREE(s->data[0]);
     47  if (s->data)
     48    AUBIO_FREE(s->data);
    4949  AUBIO_FREE(s);
    5050}
     
    7878  for (i=0; i< s->height; i++) {
    7979    for (j=0; j< s->length; j++) {
    80       AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[i][j]);
     80      AUBIO_MSG(AUBIO_SMPL_FMT " ", s->data[0][i * s->length + j]);
    8181    }
    8282    AUBIO_MSG("\n");
     
    156156
    157157void fmat_vecmul(const fmat_t *s, const fvec_t *scale, fvec_t *output) {
    158   uint_t k;
    159 #if 0
    160   assert(s->height == output->length);
    161   assert(s->length == scale->length);
    162 #endif
    163158#if !defined(HAVE_ACCELERATE) && !defined(HAVE_BLAS)
    164   uint_t j;
     159  uint_t j, k;
     160  AUBIO_ASSERT(s->height == output->length);
     161  AUBIO_ASSERT(s->length == scale->length);
    165162  fvec_zeros(output);
    166163  for (j = 0; j < s->length; j++) {
    167164    for (k = 0; k < s->height; k++) {
    168       output->data[k] += scale->data[j]
    169           * s->data[k][j];
     165      output->data[k] += scale->data[j] * s->data[k][j];
    170166    }
    171167  }
    172168#elif defined(HAVE_BLAS)
     169#if 0
    173170  for (k = 0; k < s->height; k++) {
    174171    output->data[k] = aubio_cblas_dot( s->length, scale->data, 1, s->data[k], 1);
    175172  }
     173#else
     174  aubio_cblas__gemv(CblasColMajor, CblasTrans,
     175      s->length, s->height, 1.,
     176      s->data[0], s->length,
     177      scale->data, 1, 0.,
     178      output->data, 1);
     179#endif
    176180#elif defined(HAVE_ACCELERATE)
    177181#if 0
     
    179183  vDSP_mmul (s->data[0], 1, scale->data, 1, output->data, 1, s->height, 1, s->length);
    180184#else
     185  uint_t k;
    181186  for (k = 0; k < s->height; k++) {
    182187    aubio_vDSP_dotpr( scale->data, 1, s->data[k], 1, &(output->data[k]), s->length);
     
    185190#endif
    186191}
     192
     193void fvec_matmul(const fvec_t *scale, const fmat_t *s, fvec_t *output) {
     194  AUBIO_ASSERT(s->height == scale->length);
     195  AUBIO_ASSERT(s->length == output->length);
     196#if !defined(HAVE_ACCELERATE) && !defined(HAVE_BLAS)
     197  uint_t j, k;
     198  fvec_zeros(output);
     199  for (k = 0; k < s->height; k++) {
     200    for (j = 0; j < s->length; j++) {
     201      output->data[j] += s->data[k][j] * scale->data[k];
     202    }
     203  }
     204#elif defined(HAVE_BLAS)
     205#if 0
     206  for (k = 0; k < s->length; k++) {
     207    output->data[k] = aubio_cblas_dot( scale->length, scale->data, 1,
     208        &s->data[0][0] + k, s->length);
     209  }
     210#else
     211  aubio_cblas__gemv(CblasColMajor, CblasNoTrans,
     212      s->length, s->height, 1.,
     213      s->data[0], s->length,
     214      scale->data, 1, 0.,
     215      output->data, 1);
     216#endif
     217#elif defined(HAVE_ACCELERATE)
     218#if 0
     219  // seems slower and less precise (and dangerous?)
     220  vDSP_mmul (s->data[0], 1, scale->data, 1, output->data, 1, s->height, 1, s->length);
     221#else
     222  uint_t k;
     223  for (k = 0; k < s->height; k++) {
     224    aubio_vDSP_dotpr( scale->data, 1, s->data[k], 1, &(output->data[k]), scale->length);
     225  }
     226#endif
     227#endif
     228}
     229
     230void fmat_matmul(const fmat_t *a, const fmat_t *b, fmat_t *c)
     231{
     232  AUBIO_ASSERT (a->height == c->height);
     233  AUBIO_ASSERT (a->length == b->height);
     234  AUBIO_ASSERT (b->length == c->length);
     235#if !defined(HAVE_BLAS)
     236  uint_t i, j, k;
     237  for (i = 0; i < c->height; i++) {
     238    for (j = 0; j < c->length; j++) {
     239      smpl_t sum = 0.;
     240      for (k = 0; k < a->length; k++) {
     241          sum += a->data[0][i * a->length + k]
     242            * b->data[0][k * b->length + j];
     243      }
     244      c->data[0][i * c->length + j] = sum;
     245    }
     246  }
     247#else
     248  aubio_cblas__gemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, a->height,
     249      b->length, b->height, 1.F, a->data[0], a->length, b->data[0],
     250      b->length, 0.F, c->data[0], b->length);
     251#endif
     252}
  • src/fmat.h

    r63fc1df r36ab428  
    161161   \param s matrix to compute product with
    162162   \param scale vector to compute product with
    163    \param output vector to store restults in
     163   \param output vector of results
     164
    164165
    165166*/
    166167void fmat_vecmul(const fmat_t *s, const fvec_t *scale, fvec_t *output);
     168
     169/** compute the product of a vector by a matrix
     170
     171   \param s matrix to compute product with
     172   \param scale input to compute product with
     173   \param output vector of results
     174
     175*/
     176void fvec_matmul(const fvec_t *scale, const fmat_t *s, fvec_t *output);
    167177
    168178#ifdef __cplusplus
  • src/fvec.c

    r63fc1df r36ab428  
    9999}
    100100
     101void fvec_vecadd(fvec_t *s, const fvec_t *bias) {
     102  uint_t j;
     103  uint_t length = MIN(s->length, bias->length);
     104  for (j = 0; j < length; j++) {
     105    s->data[j] += bias->data[j];
     106  }
     107}
     108
    101109void fvec_weight(fvec_t *s, const fvec_t *weight) {
    102110  uint_t length = MIN(s->length, weight->length);
  • src/fvec.h

    r63fc1df r36ab428  
    144144void fvec_rev(fvec_t *s);
    145145
     146/** add a vector b to vector a, modifying a
     147
     148  \param a  input vector to add b to
     149  \param b  input vector of the values to be added to a
     150
     151  Upon return, he content of a[i] will be set to a[i] + b[i].
     152
     153*/
     154void fvec_vecadd(fvec_t *a, const fvec_t *b);
     155
    146156/** apply weight to vector
    147157
  • src/pitch/pitch.c

    r63fc1df r36ab428  
    4949  aubio_pitcht_yinfast,    /**< `yinfast`, YIN fast */
    5050  aubio_pitcht_specacf,    /**< `specacf`, Spectral autocorrelation */
     51  aubio_pitcht_crepe,      /**< `crepe`, convolutional neural network */
    5152  aubio_pitcht_default
    5253    = aubio_pitcht_yinfft, /**< `default` */
     
    99100static void aubio_pitch_do_yinfast (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    100101static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     102static void aubio_pitch_do_crepe (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    101103
    102104/* internal functions for frequency conversion */
     
    104106static smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);
    105107static smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);
     108
     109typedef struct _aubio_pitch_crepe_t aubio_pitch_crepe_t;
     110extern aubio_pitch_crepe_t *new_aubio_pitch_crepe(void);
     111extern void aubio_pitch_crepe_do(aubio_pitch_crepe_t *t, fvec_t *input, fvec_t *out);
     112extern void del_aubio_pitch_crepe(aubio_pitch_crepe_t *t);
     113extern smpl_t aubio_pitch_crepe_get_confidence (aubio_pitch_crepe_t * o);
     114uint_t aubio_pitch_crepe_set_tolerance(aubio_pitch_crepe_t * o, smpl_t
     115    tolerance);
     116smpl_t aubio_pitch_crepe_get_tolerance (aubio_pitch_crepe_t * o);
    106117
    107118/* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */
     
    133144  else if (strcmp (pitch_mode, "specacf") == 0)
    134145    pitch_type = aubio_pitcht_specacf;
     146  else if (strcmp (pitch_mode, "crepe") == 0)
     147    pitch_type = aubio_pitcht_crepe;
    135148  else if (strcmp (pitch_mode, "default") == 0)
    136149    pitch_type = aubio_pitcht_default;
     
    214227      aubio_pitchspecacf_set_tolerance (p->p_object, 0.85);
    215228      break;
     229    case aubio_pitcht_crepe:
     230      // TODO add resampling and blocking
     231      if (samplerate != 16000) {
     232        AUBIO_ERROR("pitch: crepe samplerate must be 16000Hz, got %d\n",
     233            samplerate);
     234        goto beach;
     235      }
     236      if (bufsize != 1024) {
     237        AUBIO_ERROR("pitch: crepe buffer size must be 1024, got %d\n",
     238            bufsize);
     239        goto beach;
     240      }
     241      p->buf = new_fvec (bufsize);
     242      p->p_object = new_aubio_pitch_crepe();
     243      if (!p->p_object) goto beach;
     244      p->detect_cb = aubio_pitch_do_crepe;
     245      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitch_crepe_get_confidence;
     246      //aubio_pitch_crepe_set_tolerance (p->p_object, 0.85);
     247      break;
    216248    default:
    217249      break;
     
    260292      del_fvec (p->buf);
    261293      del_aubio_pitchspecacf (p->p_object);
     294      break;
     295    case aubio_pitcht_crepe:
     296      del_fvec (p->buf);
     297      del_aubio_pitch_crepe (p->p_object);
    262298      break;
    263299    default:
     
    350386      aubio_pitchyinfast_set_tolerance (p->p_object, tol);
    351387      break;
     388    case aubio_pitcht_crepe:
     389      aubio_pitch_crepe_set_tolerance (p->p_object, tol);
     390      break;
    352391    default:
    353392      break;
     
    369408    case aubio_pitcht_yinfast:
    370409      tolerance = aubio_pitchyinfast_get_tolerance (p->p_object);
     410      break;
     411    case aubio_pitcht_crepe:
     412      tolerance = aubio_pitch_crepe_get_tolerance (p->p_object);
    371413      break;
    372414    default:
     
    479521
    480522void
     523aubio_pitch_do_crepe (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
     524{
     525  //smpl_t pitch = 0., period;
     526  aubio_pitch_slideblock (p, ibuf);
     527  aubio_pitch_crepe_do(p->p_object, p->buf, out);
     528  out->data[0] = aubio_miditofreq(out->data[0]);
     529}
     530
     531void
    481532aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    482533{
  • src/wscript_build

    r63fc1df r36ab428  
    1313uselib += ['AVUTIL']
    1414uselib += ['BLAS']
     15uselib += ['HDF5', 'HDF5_HL']
    1516
    1617source = ctx.path.ant_glob('*.c **/*.c')
  • wscript

    r63fc1df r36ab428  
    8888            help_str = 'use CoreFoundation (darwin only) (auto)',
    8989            help_disable_str = 'do not use CoreFoundation framework')
    90     add_option_enable_disable(ctx, 'blas', default = False,
     90    add_option_enable_disable(ctx, 'blas', default = None,
    9191            help_str = 'use BLAS acceleration library (no)',
    9292            help_disable_str = 'do not use BLAS library')
    93     add_option_enable_disable(ctx, 'atlas', default = False,
     93    add_option_enable_disable(ctx, 'atlas', default = None,
    9494            help_str = 'use ATLAS acceleration library (no)',
    9595            help_disable_str = 'do not use ATLAS library')
     
    100100            help_str = 'compile with source_wavwrite (default)',
    101101            help_disable_str = 'do not compile source_wavwrite')
     102
     103    add_option_enable_disable(ctx, 'hdf5', default = None,
     104            help_str = 'use libhdf5 (default)',
     105            help_disable_str = 'do not use libhdf5')
    102106
    103107    add_option_enable_disable(ctx, 'docs', default = None,
     
    463467    if (ctx.options.enable_memcpy == True):
    464468        ctx.define('HAVE_MEMCPY_HACKS', 1)
     469
     470    if (ctx.options.enable_hdf5 != False):
     471        ctx.check_cfg(package='hdf5', args='--cflags --libs',
     472                uselib_store='HDF5', mandatory=ctx.options.enable_hdf5)
     473        ctx.check(lib=['hdf5_hl'], use = ['HDF5'],
     474                uselib_store='HDF5_HL', mandatory=ctx.options.enable_hdf5)
    465475
    466476    # write configuration header
Note: See TracChangeset for help on using the changeset viewer.