Changeset f264b17 for src


Ignore:
Timestamp:
Jun 22, 2016, 1:00:10 PM (9 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
4b9443c4
Parents:
60fc05b (diff), 6769586 (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 notes

Location:
src
Files:
1 added
90 edited

Legend:

Unmodified
Added
Removed
  • src/aubio_priv.h

    r60fc05b rf264b17  
    2525 */
    2626
    27 #ifndef _AUBIO__PRIV_H
    28 #define _AUBIO__PRIV_H
     27#ifndef AUBIO_PRIV_H
     28#define AUBIO_PRIV_H
    2929
    3030/*********************
     
    3636#include "config.h"
    3737
    38 #if HAVE_STDLIB_H
     38#ifdef HAVE_STDLIB_H
    3939#include <stdlib.h>
    4040#endif
    4141
    42 #if HAVE_STDIO_H
     42#ifdef HAVE_STDIO_H
    4343#include <stdio.h>
    4444#endif
     
    6363#ifdef HAVE_LIMITS_H
    6464#include <limits.h> // for CHAR_BIT, in C99 standard
     65#endif
     66
     67#ifdef HAVE_ACCELERATE
     68#define HAVE_ATLAS 1
     69#include <Accelerate/Accelerate.h>
     70#elif defined(HAVE_ATLAS_CBLAS_H)
     71#define HAVE_ATLAS 1
     72#include <atlas/cblas.h>
     73#else
     74#undef HAVE_ATLAS
     75#endif
     76
     77#ifdef HAVE_ACCELERATE
     78#include <Accelerate/Accelerate.h>
     79#ifndef HAVE_AUBIO_DOUBLE
     80#define aubio_vDSP_mmov       vDSP_mmov
     81#define aubio_vDSP_vmul       vDSP_vmul
     82#define aubio_vDSP_vfill      vDSP_vfill
     83#define aubio_vDSP_meanv      vDSP_meanv
     84#define aubio_vDSP_sve        vDSP_sve
     85#define aubio_vDSP_maxv       vDSP_maxv
     86#define aubio_vDSP_maxvi      vDSP_maxvi
     87#define aubio_vDSP_minv       vDSP_minv
     88#define aubio_vDSP_minvi      vDSP_minvi
     89#define aubio_vDSP_dotpr      vDSP_dotpr
     90#else /* HAVE_AUBIO_DOUBLE */
     91#define aubio_vDSP_mmov       vDSP_mmovD
     92#define aubio_vDSP_vmul       vDSP_vmulD
     93#define aubio_vDSP_vfill      vDSP_vfillD
     94#define aubio_vDSP_meanv      vDSP_meanvD
     95#define aubio_vDSP_sve        vDSP_sveD
     96#define aubio_vDSP_maxv       vDSP_maxvD
     97#define aubio_vDSP_maxvi      vDSP_maxviD
     98#define aubio_vDSP_minv       vDSP_minvD
     99#define aubio_vDSP_minvi      vDSP_minviD
     100#define aubio_vDSP_dotpr      vDSP_dotprD
     101#endif /* HAVE_AUBIO_DOUBLE */
     102#endif /* HAVE_ACCELERATE */
     103
     104#ifdef HAVE_ATLAS
     105#ifndef HAVE_AUBIO_DOUBLE
     106#define aubio_catlas_set      catlas_sset
     107#define aubio_cblas_copy      cblas_scopy
     108#define aubio_cblas_swap      cblas_sswap
     109#define aubio_cblas_dot       cblas_sdot
     110#else /* HAVE_AUBIO_DOUBLE */
     111#define aubio_catlas_set      catlas_dset
     112#define aubio_cblas_copy      cblas_dcopy
     113#define aubio_cblas_swap      cblas_dswap
     114#define aubio_cblas_dot       cblas_ddot
     115#endif /* HAVE_AUBIO_DOUBLE */
     116#endif /* HAVE_ATLAS */
     117
     118#if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS)
     119#define HAVE_NOOPT 1
     120#else
     121#undef HAVE_NOOPT
    65122#endif
    66123
     
    136193#endif
    137194#define TWO_PI     (PI*2.)
     195
     196#ifndef PATH_MAX
     197#define PATH_MAX 1024
     198#endif
    138199
    139200/* aliases to math.h functions */
     
    194255#endif
    195256
     257/* avoid unresolved symbol with msvc 9 */
     258#if defined(_MSC_VER) && (_MSC_VER < 1900)
     259#define isnan _isnan
     260#endif
     261
    196262/* handy shortcuts */
    197263#define DB2LIN(g) (POW(10.0,(g)*0.05f))
     
    229295#endif
    230296
    231 #endif /* _AUBIO__PRIV_H */
     297/* are we using gcc -std=c99 ? */
     298#if defined(__STRICT_ANSI__)
     299#define strnlen(a,b) MIN(strlen(a),b)
     300#if !HAVE_AUBIO_DOUBLE
     301#define floorf floor
     302#endif
     303#endif /* __STRICT_ANSI__ */
     304
     305#endif /* AUBIO_PRIV_H */
  • src/cvec.c

    r60fc05b rf264b17  
    2222#include "cvec.h"
    2323
    24 cvec_t * new_cvec( uint_t length) {
     24cvec_t * new_cvec(uint_t length) {
    2525  cvec_t * s;
    2626  if ((sint_t)length <= 0) {
     
    5656}
    5757
    58 smpl_t * cvec_norm_get_data (cvec_t *s) {
     58smpl_t * cvec_norm_get_data (const cvec_t *s) {
    5959  return s->norm;
    6060}
    6161
    62 smpl_t * cvec_phas_get_data (cvec_t *s) {
     62smpl_t * cvec_phas_get_data (const cvec_t *s) {
    6363  return s->phas;
    6464}
     
    6666/* helper functions */
    6767
    68 void cvec_print(cvec_t *s) {
     68void cvec_print(const cvec_t *s) {
    6969  uint_t j;
    7070  AUBIO_MSG("norm: ");
     
    8080}
    8181
    82 void cvec_copy(cvec_t *s, cvec_t *t) {
     82void cvec_copy(const cvec_t *s, cvec_t *t) {
    8383  if (s->length != t->length) {
    8484    AUBIO_ERR("trying to copy %d elements to %d elements \n",
     
    8686    return;
    8787  }
    88 #if HAVE_MEMCPY_HACKS
     88#ifdef HAVE_MEMCPY_HACKS
    8989  memcpy(t->norm, s->norm, t->length * sizeof(smpl_t));
    9090  memcpy(t->phas, s->phas, t->length * sizeof(smpl_t));
    91 #else
     91#else /* HAVE_MEMCPY_HACKS */
    9292  uint_t j;
    9393  for (j=0; j< t->length; j++) {
     
    9595    t->phas[j] = s->phas[j];
    9696  }
    97 #endif
     97#endif /* HAVE_MEMCPY_HACKS */
    9898}
    9999
     
    106106
    107107void cvec_norm_zeros(cvec_t *s) {
    108 #if HAVE_MEMCPY_HACKS
     108#ifdef HAVE_MEMCPY_HACKS
    109109  memset(s->norm, 0, s->length * sizeof(smpl_t));
    110 #else
     110#else /* HAVE_MEMCPY_HACKS */
    111111  cvec_norm_set_all (s, 0.);
    112 #endif
     112#endif /* HAVE_MEMCPY_HACKS */
    113113}
    114114
     
    125125
    126126void cvec_phas_zeros(cvec_t *s) {
    127 #if HAVE_MEMCPY_HACKS
     127#ifdef HAVE_MEMCPY_HACKS
    128128  memset(s->phas, 0, s->length * sizeof(smpl_t));
    129129#else
  • src/cvec.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO__CVEC_H
    22 #define _AUBIO__CVEC_H
     21#ifndef AUBIO_CVEC_H
     22#define AUBIO_CVEC_H
    2323
    2424#ifdef __cplusplus
     
    151151
    152152*/
    153 smpl_t * cvec_norm_get_data (cvec_t *s);
     153smpl_t * cvec_norm_get_data (const cvec_t *s);
    154154
    155155/** read phase data from a complex buffer
     
    163163
    164164*/
    165 smpl_t * cvec_phas_get_data (cvec_t *s);
     165smpl_t * cvec_phas_get_data (const cvec_t *s);
    166166
    167167/** print out cvec data
     
    170170
    171171*/
    172 void cvec_print(cvec_t *s);
     172void cvec_print(const cvec_t *s);
    173173
    174174/** make a copy of a vector
     
    178178
    179179*/
    180 void cvec_copy(cvec_t *s, cvec_t *t);
     180void cvec_copy(const cvec_t *s, cvec_t *t);
    181181
    182182/** set all norm elements to a given value
     
    235235#endif
    236236
    237 #endif /* _AUBIO__CVEC_H */
     237#endif /* AUBIO_CVEC_H */
  • src/fmat.c

    r60fc05b rf264b17  
    5454}
    5555
    56 smpl_t fmat_get_sample(fmat_t *s, uint_t channel, uint_t position) {
     56smpl_t fmat_get_sample(const fmat_t *s, uint_t channel, uint_t position) {
    5757  return s->data[channel][position];
    5858}
    5959
    60 void fmat_get_channel(fmat_t *s, uint_t channel, fvec_t *output) {
     60void fmat_get_channel(const fmat_t *s, uint_t channel, fvec_t *output) {
    6161  output->data = s->data[channel];
    6262  output->length = s->length;
     
    6464}
    6565
    66 smpl_t * fmat_get_channel_data(fmat_t *s, uint_t channel) {
     66smpl_t * fmat_get_channel_data(const fmat_t *s, uint_t channel) {
    6767  return s->data[channel];
    6868}
    6969
    70 smpl_t ** fmat_get_data(fmat_t *s) {
     70smpl_t ** fmat_get_data(const fmat_t *s) {
    7171  return s->data;
    7272}
     
    7474/* helper functions */
    7575
    76 void fmat_print(fmat_t *s) {
     76void fmat_print(const fmat_t *s) {
    7777  uint_t i,j;
    7878  for (i=0; i< s->height; i++) {
     
    9494
    9595void fmat_zeros(fmat_t *s) {
    96 #if HAVE_MEMCPY_HACKS
     96#ifdef HAVE_MEMCPY_HACKS
    9797  uint_t i;
    9898  for (i=0; i< s->height; i++) {
    9999    memset(s->data[i], 0, s->length * sizeof(smpl_t));
    100100  }
    101 #else
     101#else /* HAVE_MEMCPY_HACKS */
    102102  fmat_set(s, 0.);
    103 #endif
     103#endif /* HAVE_MEMCPY_HACKS */
    104104}
    105105
     
    117117}
    118118
    119 void fmat_weight(fmat_t *s, fmat_t *weight) {
     119void fmat_weight(fmat_t *s, const fmat_t *weight) {
    120120  uint_t i,j;
    121121  uint_t length = MIN(s->length, weight->length);
     
    127127}
    128128
    129 void fmat_copy(fmat_t *s, fmat_t *t) {
     129void fmat_copy(const fmat_t *s, fmat_t *t) {
    130130  uint_t i;
    131 #if !HAVE_MEMCPY_HACKS
     131#ifndef HAVE_MEMCPY_HACKS
    132132  uint_t j;
    133 #endif
     133#endif /* HAVE_MEMCPY_HACKS */
    134134  if (s->height != t->height) {
    135135    AUBIO_ERR("trying to copy %d rows to %d rows \n",
     
    142142    return;
    143143  }
    144 #if HAVE_MEMCPY_HACKS
     144#ifdef HAVE_MEMCPY_HACKS
    145145  for (i=0; i< s->height; i++) {
    146146    memcpy(t->data[i], s->data[i], t->length * sizeof(smpl_t));
    147147  }
    148 #else
     148#else /* HAVE_MEMCPY_HACKS */
    149149  for (i=0; i< t->height; i++) {
    150150    for (j=0; j< t->length; j++) {
     
    152152    }
    153153  }
     154#endif /* HAVE_MEMCPY_HACKS */
     155}
     156
     157void 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
     163#if !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS)
     164  uint_t j;
     165  fvec_zeros(output);
     166  for (j = 0; j < s->length; j++) {
     167    for (k = 0; k < s->height; k++) {
     168      output->data[k] += scale->data[j]
     169          * s->data[k][j];
     170    }
     171  }
     172#elif defined(HAVE_ATLAS)
     173  for (k = 0; k < s->height; k++) {
     174    output->data[k] = aubio_cblas_dot( s->length, scale->data, 1, s->data[k], 1);
     175  }
     176#elif defined(HAVE_ACCELERATE)
     177#if 0
     178  // seems slower and less precise (and dangerous?)
     179  vDSP_mmul (s->data[0], 1, scale->data, 1, output->data, 1, s->height, 1, s->length);
     180#else
     181  for (k = 0; k < s->height; k++) {
     182    aubio_vDSP_dotpr( scale->data, 1, s->data[k], 1, &(output->data[k]), s->length);
     183  }
     184#endif
    154185#endif
    155186}
    156 
  • src/fmat.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO__FMAT_H
    22 #define _AUBIO__FMAT_H
     21#ifndef AUBIO_FMAT_H
     22#define AUBIO_FMAT_H
    2323
    2424#ifdef __cplusplus
     
    6666
    6767*/
    68 smpl_t fmat_get_sample(fmat_t *s, uint_t channel, uint_t position);
     68smpl_t fmat_get_sample(const fmat_t *s, uint_t channel, uint_t position);
    6969
    7070/** write sample value in a buffer
     
    8585
    8686*/
    87 void fmat_get_channel (fmat_t *s, uint_t channel, fvec_t *output);
     87void fmat_get_channel (const fmat_t *s, uint_t channel, fvec_t *output);
    8888
    8989/** get vector buffer from an fmat data
     
    9393
    9494*/
    95 smpl_t * fmat_get_channel_data (fmat_t *s, uint_t channel);
     95smpl_t * fmat_get_channel_data (const fmat_t *s, uint_t channel);
    9696
    9797/** read data from a buffer
     
    100100
    101101*/
    102 smpl_t ** fmat_get_data(fmat_t *s);
     102smpl_t ** fmat_get_data(const fmat_t *s);
    103103
    104104/** print out fmat data
     
    107107
    108108*/
    109 void fmat_print(fmat_t *s);
     109void fmat_print(const fmat_t *s);
    110110
    111111/** set all elements to a given value
     
    147147
    148148*/
    149 void fmat_weight(fmat_t *s, fmat_t *weight);
     149void fmat_weight(fmat_t *s, const fmat_t *weight);
    150150
    151151/** make a copy of a matrix
     
    155155
    156156*/
    157 void fmat_copy(fmat_t *s, fmat_t *t);
     157void fmat_copy(const fmat_t *s, fmat_t *t);
     158
     159/* compute the product of a matrix by a vector
     160
     161   \param s matrix to compute product with
     162   \param scale vector to compute product with
     163   \param output vector to store restults in
     164
     165*/
     166void fmat_vecmul(const fmat_t *s, const fvec_t *scale, fvec_t *output);
    158167
    159168#ifdef __cplusplus
     
    161170#endif
    162171
    163 #endif /* _AUBIO__FMAT_H */
     172#endif /* AUBIO_FMAT_H */
  • src/fvec.c

    r60fc05b rf264b17  
    2222#include "fvec.h"
    2323
    24 #ifdef HAVE_ACCELERATE
    25 #include <Accelerate/Accelerate.h>
    26 #if !HAVE_AUBIO_DOUBLE
    27 #define aubio_vDSP_mmov       vDSP_mmov
    28 #define aubio_vDSP_vmul       vDSP_vmul
    29 #define aubio_vDSP_vfill      vDSP_vfill
    30 #else /* HAVE_AUBIO_DOUBLE */
    31 #define aubio_vDSP_mmov       vDSP_mmovD
    32 #define aubio_vDSP_vmul       vDSP_vmulD
    33 #define aubio_vDSP_vfill      vDSP_vfillD
    34 #endif /* HAVE_AUBIO_DOUBLE */
    35 #endif
    36 
    37 fvec_t * new_fvec( uint_t length) {
     24fvec_t * new_fvec(uint_t length) {
    3825  fvec_t * s;
    3926  if ((sint_t)length <= 0) {
     
    5542}
    5643
    57 smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
     44smpl_t fvec_get_sample(const fvec_t *s, uint_t position) {
    5845  return s->data[position];
    5946}
    6047
    61 smpl_t * fvec_get_data(fvec_t *s) {
     48smpl_t * fvec_get_data(const fvec_t *s) {
    6249  return s->data;
    6350}
     
    6552/* helper functions */
    6653
    67 void fvec_print(fvec_t *s) {
     54void fvec_print(const fvec_t *s) {
    6855  uint_t j;
    6956  for (j=0; j< s->length; j++) {
     
    7461
    7562void fvec_set_all (fvec_t *s, smpl_t val) {
    76 #ifndef HAVE_ACCELERATE
     63#if !defined(HAVE_ACCELERATE) && !defined(HAVE_ATLAS)
    7764  uint_t j;
    7865  for (j=0; j< s->length; j++) {
    7966    s->data[j] = val;
    8067  }
    81 #else
     68#elif defined(HAVE_ATLAS)
     69  aubio_catlas_set(s->length, val, s->data, 1);
     70#elif defined(HAVE_ACCELERATE)
    8271  aubio_vDSP_vfill(&val, s->data, 1, s->length);
    8372#endif
     
    10796}
    10897
    109 void fvec_weight(fvec_t *s, fvec_t *weight) {
     98void fvec_weight(fvec_t *s, const fvec_t *weight) {
    11099#ifndef HAVE_ACCELERATE
    111100  uint_t j;
     
    119108}
    120109
    121 void fvec_copy(fvec_t *s, fvec_t *t) {
     110void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) {
     111#ifndef HAVE_ACCELERATE
     112  uint_t j;
     113  uint_t length = MIN(out->length, weight->length);
     114  for (j=0; j< length; j++) {
     115    out->data[j] = in->data[j] * weight->data[j];
     116  }
     117#else
     118  aubio_vDSP_vmul(in->data, 1, weight->data, 1, out->data, 1, out->length);
     119#endif /* HAVE_ACCELERATE */
     120}
     121
     122void fvec_copy(const fvec_t *s, fvec_t *t) {
    122123  if (s->length != t->length) {
    123124    AUBIO_ERR("trying to copy %d elements to %d elements \n",
     
    125126    return;
    126127  }
    127 #if !defined(HAVE_MEMCPY_HACKS) && !defined(HAVE_ACCELERATE)
     128#ifdef HAVE_NOOPT
    128129  uint_t j;
    129130  for (j=0; j< t->length; j++) {
    130131    t->data[j] = s->data[j];
    131132  }
    132 #else
    133 #if defined(HAVE_MEMCPY_HACKS)
     133#elif defined(HAVE_MEMCPY_HACKS)
    134134  memcpy(t->data, s->data, t->length * sizeof(smpl_t));
    135 #else
     135#elif defined(HAVE_ATLAS)
     136  aubio_cblas_copy(s->length, s->data, 1, t->data, 1);
     137#elif defined(HAVE_ACCELERATE)
    136138  aubio_vDSP_mmov(s->data, t->data, 1, s->length, 1, 1);
    137139#endif
    138 #endif
    139140}
  • src/fvec.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO__FVEC_H
    22 #define _AUBIO__FVEC_H
     21#ifndef AUBIO_FVEC_H
     22#define AUBIO_FVEC_H
    2323
    2424#ifdef __cplusplus
     
    9090
    9191*/
    92 smpl_t fvec_get_sample(fvec_t *s, uint_t position);
     92smpl_t fvec_get_sample(const fvec_t *s, uint_t position);
    9393
    9494/** write sample value in a buffer
     
    106106
    107107*/
    108 smpl_t * fvec_get_data(fvec_t *s);
     108smpl_t * fvec_get_data(const fvec_t *s);
    109109
    110110/** print out fvec data
     
    113113
    114114*/
    115 void fvec_print(fvec_t *s);
     115void fvec_print(const fvec_t *s);
    116116
    117117/** set all elements to a given value
     
    153153
    154154*/
    155 void fvec_weight(fvec_t *s, fvec_t *weight);
     155void fvec_weight(fvec_t *s, const fvec_t *weight);
    156156
    157157/** make a copy of a vector
     
    161161
    162162*/
    163 void fvec_copy(fvec_t *s, fvec_t *t);
     163void fvec_copy(const fvec_t *s, fvec_t *t);
     164
     165/** make a copy of a vector, applying weights to each element
     166
     167  \param in input vector
     168  \param weight weights vector
     169  \param out output vector
     170
     171*/
     172void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out);
    164173
    165174#ifdef __cplusplus
     
    167176#endif
    168177
    169 #endif /* _AUBIO__FVEC_H */
     178#endif /* AUBIO_FVEC_H */
  • src/io/audio_unit.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_AUDIO_UNIT_H
    22 #define _AUBIO_AUDIO_UNIT_H
     21#ifndef AUBIO_AUDIO_UNIT_H
     22#define AUBIO_AUDIO_UNIT_H
    2323
    2424/** \file
     
    5959#endif
    6060
    61 #endif /* _AUBIO_AUDIO_UNIT_H */
     61#endif /* AUBIO_AUDIO_UNIT_H */
  • src/io/sink.c

    r60fc05b rf264b17  
    5555};
    5656
    57 aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate) {
     57aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
    5858  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
    5959#ifdef HAVE_SINK_APPLE_AUDIO
     
    7171  }
    7272#endif /* HAVE_SINK_APPLE_AUDIO */
    73 #if HAVE_SNDFILE
     73#ifdef HAVE_SNDFILE
    7474  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
    7575  if (s->sink) {
     
    8585  }
    8686#endif /* HAVE_SNDFILE */
    87 #if HAVE_WAVWRITE
     87#ifdef HAVE_WAVWRITE
    8888  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
    8989  if (s->sink) {
     
    121121}
    122122
    123 uint_t aubio_sink_get_samplerate(aubio_sink_t * s) {
     123uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) {
    124124  return s->s_get_samplerate((void *)s->sink);
    125125}
    126126
    127 uint_t aubio_sink_get_channels(aubio_sink_t * s) {
     127uint_t aubio_sink_get_channels(const aubio_sink_t * s) {
    128128  return s->s_get_channels((void *)s->sink);
    129129}
  • src/io/sink.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_H
    22 #define _AUBIO_SINK_H
     21#ifndef AUBIO_SINK_H
     22#define AUBIO_SINK_H
    2323
    2424/** \file
     
    7777
    7878*/
    79 aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate);
     79aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate);
    8080
    8181/**
     
    121121
    122122*/
    123 uint_t aubio_sink_get_samplerate(aubio_sink_t *s);
     123uint_t aubio_sink_get_samplerate(const aubio_sink_t *s);
    124124
    125125/**
     
    131131
    132132*/
    133 uint_t aubio_sink_get_channels(aubio_sink_t *s);
     133uint_t aubio_sink_get_channels(const aubio_sink_t *s);
    134134
    135135/**
     
    179179#endif
    180180
    181 #endif /* _AUBIO_SINK_H */
     181#endif /* AUBIO_SINK_H */
  • src/io/sink_apple_audio.c

    r60fc05b rf264b17  
    3737extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    3838extern void freeAudioBufferList(AudioBufferList *bufferList);
    39 extern CFURLRef getURLFromPath(const char * path);
     39extern CFURLRef createURLFromPath(const char * path);
    4040char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    4141
     
    4343
    4444#define MAX_SIZE 4096 // the maximum number of frames that can be written at a time
     45
     46void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write);
    4547
    4648struct _aubio_sink_apple_audio_t {
     
    5658};
    5759
    58 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate) {
     60aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) {
    5961  aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t);
    60   s->path = uri;
    6162  s->max_frames = MAX_SIZE;
    62   s->async = true;
     63  s->async = false;
    6364
    6465  if (uri == NULL) {
     
    6667    goto beach;
    6768  }
     69  if (s->path != NULL) AUBIO_FREE(s->path);
     70  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
     71  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
    6872
    6973  s->samplerate = 0;
     
    111115}
    112116
    113 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s)
     117uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s)
    114118{
    115119  return s->samplerate;
    116120}
    117121
    118 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s)
     122uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s)
    119123{
    120124  return s->channels;
     
    138142
    139143  AudioFileTypeID fileType = kAudioFileWAVEType;
    140   CFURLRef fileURL = getURLFromPath(s->path);
     144  CFURLRef fileURL = createURLFromPath(s->path);
    141145  bool overwrite = true;
    142146  OSStatus err = noErr;
    143147  err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
    144148     overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);
     149  CFRelease(fileURL);
    145150  if (err) {
    146151    char_t errorstr[20];
     
    162167
    163168void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    164   OSStatus err = noErr;
    165169  UInt32 c, v;
    166170  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    179183      }
    180184  }
    181   if (s->async) {
    182     err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
    183 
    184     if (err) {
    185       char_t errorstr[20];
    186       AUBIO_ERROR("sink_apple_audio: error while writing %s "
    187           "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
    188           getPrintableOSStatusError(errorstr, err));
    189       s->async = false;
    190     } else {
    191       return;
    192     }
    193 
    194   } else {
    195     err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
    196 
    197     if (err) {
    198       char_t errorstr[20];
    199       AUBIO_ERROR("sink_apple_audio: error while writing %s "
    200           "in ExtAudioFileWrite (%s)\n", s->path,
    201           getPrintableOSStatusError(errorstr, err));
    202     }
    203   }
    204   return;
     185  aubio_sink_apple_audio_write(s, write);
    205186}
    206187
    207188void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    208   OSStatus err = noErr;
    209189  UInt32 c, v;
    210190  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    223203      }
    224204  }
     205  aubio_sink_apple_audio_write(s, write);
     206}
     207
     208void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
     209  OSStatus err = noErr;
    225210  if (s->async) {
    226211    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
    227 
    228212    if (err) {
    229213      char_t errorstr[20];
     214      if (err == kExtAudioFileError_AsyncWriteBufferOverflow) {
     215        sprintf(errorstr,"buffer overflow");
     216      } else if (err == kExtAudioFileError_AsyncWriteTooLarge) {
     217        sprintf(errorstr,"write too large");
     218      } else {
     219        // unknown error
     220        getPrintableOSStatusError(errorstr, err);
     221      }
    230222      AUBIO_ERROR("sink_apple_audio: error while writing %s "
    231           "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
    232           getPrintableOSStatusError(errorstr, err));
    233       s->async = false;
    234     } else {
    235       return;
     223                  "in ExtAudioFileWriteAsync (%s)\n", s->path, errorstr);
    236224    }
    237 
    238225  } else {
    239226    err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
    240 
    241227    if (err) {
    242228      char_t errorstr[20];
     
    246232    }
    247233  }
    248   return;
    249234}
    250235
     
    267252void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    268253  if (s->audioFile) aubio_sink_apple_audio_close (s);
     254  if (s->path) AUBIO_FREE(s->path);
    269255  freeAudioBufferList(&s->bufferList);
    270256  AUBIO_FREE(s);
  • src/io/sink_apple_audio.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_APPLE_AUDIO_H
    22 #define _AUBIO_SINK_APPLE_AUDIO_H
     21#ifndef AUBIO_SINK_APPLE_AUDIO_H
     22#define AUBIO_SINK_APPLE_AUDIO_H
    2323
    2424/** \file
     
    5959
    6060*/
    61 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate);
     61aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate);
    6262
    6363/**
     
    103103
    104104*/
    105 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s);
     105uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s);
    106106
    107107/**
     
    113113
    114114*/
    115 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s);
     115uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s);
    116116
    117117/**
     
    161161#endif
    162162
    163 #endif /* _AUBIO_SINK_APPLE_AUDIO_H */
     163#endif /* AUBIO_SINK_APPLE_AUDIO_H */
  • src/io/sink_sndfile.c

    r60fc05b rf264b17  
    5454uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s);
    5555
    56 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) {
     56aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) {
    5757  aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
    5858  s->max_size = MAX_SIZE;
    59   s->path = path;
    6059
    6160  if (path == NULL) {
     
    6362    return NULL;
    6463  }
     64
     65  if (s->path) AUBIO_FREE(s->path);
     66  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     67  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    6568
    6669  s->samplerate = 0;
     
    107110}
    108111
    109 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s)
     112uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s)
    110113{
    111114  return s->samplerate;
    112115}
    113116
    114 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s)
     117uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s)
    115118{
    116119  return s->channels;
     
    220223void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    221224  if (!s) return;
     225  if (s->path) AUBIO_FREE(s->path);
    222226  aubio_sink_sndfile_close(s);
    223227  AUBIO_FREE(s->scratch_data);
  • src/io/sink_sndfile.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_SNDFILE_H
    22 #define _AUBIO_SINK_SNDFILE_H
     21#ifndef AUBIO_SINK_SNDFILE_H
     22#define AUBIO_SINK_SNDFILE_H
    2323
    2424/** \file
     
    5858
    5959*/
    60 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * uri, uint_t samplerate);
     60aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * uri, uint_t samplerate);
    6161
    6262/**
     
    102102
    103103*/
    104 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s);
     104uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s);
    105105
    106106/**
     
    112112
    113113*/
    114 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s);
     114uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s);
    115115
    116116/**
     
    160160#endif
    161161
    162 #endif /* _AUBIO_SINK_SNDFILE_H */
     162#endif /* AUBIO_SINK_SNDFILE_H */
  • src/io/sink_wavwrite.c

    r60fc05b rf264b17  
    7878}
    7979
    80 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(char_t * path, uint_t samplerate) {
     80aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * path, uint_t samplerate) {
    8181  aubio_sink_wavwrite_t * s = AUBIO_NEW(aubio_sink_wavwrite_t);
    8282
     
    9090  }
    9191
    92   s->path = path;
     92  if (s->path) AUBIO_FREE(s->path);
     93  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     94  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     95
    9396  s->max_size = MAX_SIZE;
    9497  s->bitspersample = 16;
     
    143146}
    144147
    145 uint_t aubio_sink_wavwrite_get_samplerate(aubio_sink_wavwrite_t *s)
     148uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s)
    146149{
    147150  return s->samplerate;
    148151}
    149152
    150 uint_t aubio_sink_wavwrite_get_channels(aubio_sink_wavwrite_t *s)
     153uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s)
    151154{
    152155  return s->channels;
     
    288291  if (!s) return;
    289292  aubio_sink_wavwrite_close(s);
     293  if (s->path) AUBIO_FREE(s->path);
    290294  AUBIO_FREE(s->scratch_data);
    291295  AUBIO_FREE(s);
  • src/io/sink_wavwrite.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SINK_WAVWRITE_H
    22 #define _AUBIO_SINK_WAVWRITE_H
     21#ifndef AUBIO_SINK_WAVWRITE_H
     22#define AUBIO_SINK_WAVWRITE_H
    2323
    2424/** \file
     
    5858
    5959*/
    60 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(char_t * uri, uint_t samplerate);
     60aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * uri, uint_t samplerate);
    6161
    6262/**
     
    102102
    103103*/
    104 uint_t aubio_sink_wavwrite_get_samplerate(aubio_sink_wavwrite_t *s);
     104uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s);
    105105
    106106/**
     
    112112
    113113*/
    114 uint_t aubio_sink_wavwrite_get_channels(aubio_sink_wavwrite_t *s);
     114uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s);
    115115
    116116/**
     
    160160#endif
    161161
    162 #endif /* _AUBIO_SINK_WAVWRITE_H */
     162#endif /* AUBIO_SINK_WAVWRITE_H */
  • src/io/source.c

    r60fc05b rf264b17  
    4141typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
    4242typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
     43typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s);
    4344typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
    4445typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
     
    5152  aubio_source_get_samplerate_t s_get_samplerate;
    5253  aubio_source_get_channels_t s_get_channels;
     54  aubio_source_get_duration_t s_get_duration;
    5355  aubio_source_seek_t s_seek;
    5456  aubio_source_close_t s_close;
     
    5658};
    5759
    58 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
     60aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
    5961  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
    60 #if HAVE_LIBAV
     62#ifdef HAVE_LIBAV
    6163  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
    6264  if (s->source) {
     
    6567    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
    6668    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
     69    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
    6770    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
    6871    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
     
    7881    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
    7982    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
     83    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
    8084    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
    8185    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
     
    8488  }
    8589#endif /* HAVE_SOURCE_APPLE_AUDIO */
    86 #if HAVE_SNDFILE
     90#ifdef HAVE_SNDFILE
    8791  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
    8892  if (s->source) {
     
    9195    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
    9296    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
     97    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
    9398    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
    9499    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
     
    97102  }
    98103#endif /* HAVE_SNDFILE */
    99 #if HAVE_WAVREAD
     104#ifdef HAVE_WAVREAD
    100105  s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
    101106  if (s->source) {
     
    104109    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
    105110    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
     111    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
    106112    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
    107113    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
     
    142148}
    143149
     150uint_t aubio_source_get_duration(aubio_source_t *s) {
     151  return s->s_get_duration((void *)s->source);
     152}
     153
    144154uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
    145155  return s->s_seek((void *)s->source, seek);
  • src/io/source.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_H
    22 #define _AUBIO_SOURCE_H
     21#ifndef AUBIO_SOURCE_H
     22#define AUBIO_SOURCE_H
    2323
    2424/** \file
     
    8686
    8787*/
    88 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size);
     88aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size);
    8989
    9090/**
     
    150150/**
    151151
     152  get the duration of source object, in frames
     153
     154  \param s source object, created with ::new_aubio_source
     155  \return number of frames in file
     156
     157*/
     158uint_t aubio_source_get_duration (aubio_source_t * s);
     159
     160/**
     161
    152162  close source object
    153163
     
    172182#endif
    173183
    174 #endif /* _AUBIO_SOURCE_H */
     184#endif /* AUBIO_SOURCE_H */
  • src/io/source_apple_audio.c

    r60fc05b rf264b17  
    5252extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5353extern void freeAudioBufferList(AudioBufferList *bufferList);
    54 extern CFURLRef getURLFromPath(const char * path);
     54extern CFURLRef createURLFromPath(const char * path);
    5555char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    5656
    57 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path);
    58 
    59 aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * path, uint_t samplerate, uint_t block_size)
     57uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path);
     58
     59aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * path, uint_t samplerate, uint_t block_size)
    6060{
    6161  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
     
    8080  s->block_size = block_size;
    8181  s->samplerate = samplerate;
    82   s->path = path;
    8382
    8483  if ( aubio_source_apple_audio_open ( s, path ) ) {
     
    9291}
    9392
    94 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path)
     93uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path)
    9594{
    9695  OSStatus err = noErr;
    9796  UInt32 propSize;
    98   s->path = path;
     97
     98  if (s->path) AUBIO_FREE(s->path);
     99  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     100  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    99101
    100102  // open the resource url
    101   CFURLRef fileURL = getURLFromPath(path);
     103  CFURLRef fileURL = createURLFromPath(s->path);
    102104  err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
     105  CFRelease(fileURL);
    103106  if (err == -43) {
    104107    AUBIO_ERR("source_apple_audio: Failed opening %s, "
     
    293296void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
    294297  aubio_source_apple_audio_close (s);
     298  if (s->path) AUBIO_FREE(s->path);
    295299  freeAudioBufferList(&s->bufferList);
    296300  AUBIO_FREE(s);
     
    308312  }
    309313  // check if we are not seeking out of the file
    310   SInt64 fileLengthFrames = 0;
    311   UInt32 propSize = sizeof(fileLengthFrames);
    312   ExtAudioFileGetProperty(s->audioFile,
    313       kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     314  uint_t fileLengthFrames = aubio_source_apple_audio_get_duration(s);
    314315  // compute position in the source file, before resampling
    315316  smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
     
    352353}
    353354
    354 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
     355uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s) {
    355356  return s->samplerate;
    356357}
    357358
    358 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {
     359uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s) {
    359360  return s->channels;
    360361}
    361362
     363uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s) {
     364  SInt64 fileLengthFrames = 0;
     365  UInt32 propSize = sizeof(fileLengthFrames);
     366  OSStatus err = ExtAudioFileGetProperty(s->audioFile,
     367      kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     368  if (err) {
     369    char_t errorstr[20];
     370    AUBIO_ERROR("source_apple_audio: Failed getting %s duration, "
     371        "error in ExtAudioFileGetProperty (%s)\n", s->path,
     372        getPrintableOSStatusError(errorstr, err));
     373    return err;
     374  }
     375  return (uint_t)fileLengthFrames;
     376}
     377
    362378#endif /* HAVE_SOURCE_APPLE_AUDIO */
  • src/io/source_apple_audio.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_APPLE_AUDIO_H
    22 #define _AUBIO_SOURCE_APPLE_AUDIO_H
     21#ifndef AUBIO_SOURCE_APPLE_AUDIO_H
     22#define AUBIO_SOURCE_APPLE_AUDIO_H
    2323
    2424/** \file
     
    5858
    5959*/
    60 aubio_source_apple_audio_t * new_aubio_source_apple_audio(char_t * uri, uint_t samplerate, uint_t hop_size);
     60aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6161
    6262/**
     
    9696
    9797*/
    98 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s);
     98uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s);
    9999
    100100/**
     
    106106
    107107*/
    108 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s);
     108uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s);
     109
     110/**
     111
     112  get the duration of source object, in frames
     113
     114  \param s source object, created with ::new_aubio_source_apple_audio
     115  \return number of frames in file
     116
     117*/
     118uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s);
    109119
    110120/**
     
    144154#endif
    145155
    146 #endif /* _AUBIO_SOURCE_APPLE_AUDIO_H */
     156#endif /* AUBIO_SOURCE_APPLE_AUDIO_H */
  • src/io/source_avcodec.c

    r60fc05b rf264b17  
    2424#ifdef HAVE_LIBAV
    2525
    26 // determine whether we use libavformat from ffmpe or libav
    27 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99)
     26// determine whether we use libavformat from ffmpeg or from libav
     27#define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 )
     28// max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through 57.2.100
     29#define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \
     30      (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \
     31      || (LIBAVFORMAT_VERSION_MAJOR == 56) \
     32      || (LIBAVFORMAT_VERSION_MAJOR == 57 && LIBAVFORMAT_VERSION_MINOR < 2) \
     33      )
    2834
    2935#include <libavcodec/avcodec.h>
     
    6773void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples);
    6874
    69 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplerate, uint_t hop_size) {
     75uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s);
     76
     77uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s) {
     78  char proto[20], authorization[256], hostname[128], uripath[256];
     79  int proto_size = 20, authorization_size = 256, hostname_size = 128,
     80      *port_ptr = 0, path_size = 256;
     81  av_url_split(proto, proto_size, authorization, authorization_size, hostname,
     82      hostname_size, port_ptr, uripath, path_size, s->path);
     83  if (strlen(proto)) {
     84    return 1;
     85  }
     86  return 0;
     87}
     88
     89
     90aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) {
    7091  aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
    7192  int err;
     
    85106  s->hop_size = hop_size;
    86107  s->channels = 1;
    87   s->path = path;
     108
     109  if (s->path) AUBIO_FREE(s->path);
     110  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     111  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    88112
    89113  // register all formats and codecs
    90114  av_register_all();
    91115
    92   // if path[0] != '/'
    93   //avformat_network_init();
     116  if (aubio_source_avcodec_has_network_url(s)) {
     117    avformat_network_init();
     118  }
    94119
    95120  // try opening the file and get some info about it
     
    104129
    105130  // try to make sure max_analyze_duration is big enough for most songs
    106 #if FFMPEG_LIBAVFORMAT
     131#if FFMPEG_LIBAVFORMAT_MAX_DUR2
    107132  avFormatCtx->max_analyze_duration2 *= 100;
    108133#else
     
    164189
    165190  if (samplerate == 0) {
    166     samplerate = s->input_samplerate;
    167     //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
    168   }
    169   s->samplerate = samplerate;
     191    s->samplerate = s->input_samplerate;
     192  } else {
     193    s->samplerate = samplerate;
     194  }
    170195
    171196  if (s->samplerate >  s->input_samplerate) {
     
    300325  s->output = output;
    301326
    302   av_free_packet(&avPacket);
     327  av_packet_unref(&avPacket);
    303328}
    304329
     
    370395}
    371396
    372 uint_t aubio_source_avcodec_get_samplerate(aubio_source_avcodec_t * s) {
     397uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s) {
    373398  return s->samplerate;
    374399}
    375400
    376 uint_t aubio_source_avcodec_get_channels(aubio_source_avcodec_t * s) {
     401uint_t aubio_source_avcodec_get_channels(const aubio_source_avcodec_t * s) {
    377402  return s->input_channels;
    378403}
     
    398423}
    399424
     425uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) {
     426  if (s && &(s->avFormatCtx) != NULL) {
     427    int64_t duration = s->avFormatCtx->duration;
     428    return s->samplerate * ((uint_t)duration / 1e6 );
     429  }
     430  return 0;
     431}
     432
    400433uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
    401434  if (s->avr != NULL) {
     
    425458    av_frame_free( &(s->avFrame) );
    426459  }
     460  if (s->path) AUBIO_FREE(s->path);
    427461  s->avFrame = NULL;
    428462  AUBIO_FREE(s);
  • src/io/source_avcodec.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_AVCODEC_H
    22 #define _AUBIO_SOURCE_AVCODEC_H
     21#ifndef AUBIO_SOURCE_AVCODEC_H
     22#define AUBIO_SOURCE_AVCODEC_H
    2323
    2424/** \file
     
    5757
    5858*/
    59 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * uri, uint_t samplerate, uint_t hop_size);
     59aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6060
    6161/**
     
    9595
    9696*/
    97 uint_t aubio_source_avcodec_get_samplerate(aubio_source_avcodec_t * s);
     97uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s);
    9898
    9999/**
     
    105105
    106106*/
    107 uint_t aubio_source_avcodec_get_channels (aubio_source_avcodec_t * s);
     107uint_t aubio_source_avcodec_get_channels (const aubio_source_avcodec_t * s);
    108108
    109109/**
     
    118118*/
    119119uint_t aubio_source_avcodec_seek (aubio_source_avcodec_t *s, uint_t pos);
     120
     121/**
     122
     123  get the duration of source object, in frames
     124
     125  \param s source object, created with ::new_aubio_source_avcodec
     126  \return number of frames in file
     127
     128*/
     129uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s);
    120130
    121131/**
     
    143153#endif
    144154
    145 #endif /* _AUBIO_SOURCE_AVCODEC_H */
     155#endif /* AUBIO_SOURCE_AVCODEC_H */
  • src/io/source_sndfile.c

    r60fc05b rf264b17  
    3636#define MAX_SIZE 4096
    3737#define MAX_SAMPLES MAX_CHANNELS * MAX_SIZE
     38
     39#if !HAVE_AUBIO_DOUBLE
     40#define aubio_sf_read_smpl sf_read_float
     41#else /* HAVE_AUBIO_DOUBLE */
     42#define aubio_sf_read_smpl sf_read_double
     43#endif /* HAVE_AUBIO_DOUBLE */
    3844
    3945struct _aubio_source_sndfile_t {
     
    4854  int input_channels;
    4955  int input_format;
     56  int duration;
    5057
    5158  // resampling stuff
     
    5966  // some temporary memory for sndfile to write at
    6067  uint_t scratch_size;
    61   float *scratch_data;
     68  smpl_t *scratch_data;
    6269};
    6370
    64 aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) {
     71aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t samplerate, uint_t hop_size) {
    6572  aubio_source_sndfile_t * s = AUBIO_NEW(aubio_source_sndfile_t);
    6673  SF_INFO sfinfo;
     
    8188  s->hop_size = hop_size;
    8289  s->channels = 1;
    83   s->path = path;
     90
     91  if (s->path) AUBIO_FREE(s->path);
     92  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     93  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    8494
    8595  // try opening the file, getting the info in sfinfo
     
    97107  s->input_channels   = sfinfo.channels;
    98108  s->input_format     = sfinfo.format;
     109  s->duration         = sfinfo.frames;
    99110
    100111  if (samplerate == 0) {
    101     samplerate = s->input_samplerate;
     112    s->samplerate = s->input_samplerate;
    102113    //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
    103   }
    104   s->samplerate = samplerate;
     114  } else {
     115    s->samplerate = samplerate;
     116  }
    105117  /* compute input block size required before resampling */
    106   s->ratio = s->samplerate/(float)s->input_samplerate;
     118  s->ratio = s->samplerate/(smpl_t)s->input_samplerate;
    107119  s->input_hop_size = (uint_t)FLOOR(s->hop_size / s->ratio + .5);
    108120
     
    129141          s->input_samplerate, s->samplerate);
    130142    }
     143    s->duration = (uint_t)FLOOR(s->duration * s->ratio);
    131144  }
    132145#else
     
    139152  /* allocate data for de/interleaving reallocated when needed. */
    140153  s->scratch_size = s->input_hop_size * s->input_channels;
    141   s->scratch_data = AUBIO_ARRAY(float,s->scratch_size);
     154  s->scratch_data = AUBIO_ARRAY(smpl_t, s->scratch_size);
    142155
    143156  return s;
     
    153166  uint_t i,j, input_channels = s->input_channels;
    154167  /* read from file into scratch_data */
    155   sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     168  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    156169
    157170  /* where to store de-interleaved data */
     
    194207  uint_t i,j, input_channels = s->input_channels;
    195208  /* do actual reading */
    196   sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     209  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    197210
    198211  /* where to store de-interleaved data */
     
    214227    for (j = 0; j < read_samples / input_channels; j++) {
    215228      for (i = 0; i < read_data->height; i++) {
    216         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];
     229        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    217230      }
    218231    }
     
    222235    for (j = 0; j < read_samples / input_channels; j++) {
    223236      for (i = 0; i < input_channels; i++) {
    224         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];
     237        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    225238      }
    226239    }
     
    232245    for (j = 0; j < read_samples / input_channels; j++) {
    233246      for (i = input_channels; i < read_data->height; i++) {
    234         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + (input_channels - 1)];
     247        ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
    235248      }
    236249    }
     
    261274uint_t aubio_source_sndfile_get_channels(aubio_source_sndfile_t * s) {
    262275  return s->input_channels;
     276}
     277
     278uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) {
     279  if (s && s->duration) {
     280    return s->duration;
     281  }
     282  return 0;
    263283}
    264284
     
    300320  }
    301321#endif /* HAVE_SAMPLERATE */
     322  if (s->path) AUBIO_FREE(s->path);
    302323  AUBIO_FREE(s->scratch_data);
    303324  AUBIO_FREE(s);
  • src/io/source_sndfile.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_SNDFILE_H
    22 #define _AUBIO_SOURCE_SNDFILE_H
     21#ifndef AUBIO_SOURCE_SNDFILE_H
     22#define AUBIO_SOURCE_SNDFILE_H
    2323
    2424/** \file
     
    5757
    5858*/
    59 aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * uri, uint_t samplerate, uint_t hop_size);
     59aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6060
    6161/**
     
    121121/**
    122122
     123  get the duration of source object, in frames
     124
     125  \param s source object, created with ::new_aubio_source_sndfile
     126  \return number of frames in file
     127
     128*/
     129uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t *s);
     130
     131/**
     132
    123133  close source
    124134
     
    143153#endif
    144154
    145 #endif /* _AUBIO_SOURCE_SNDFILE_H */
     155#endif /* AUBIO_SOURCE_SNDFILE_H */
  • src/io/source_wavread.c

    r60fc05b rf264b17  
    5353  uint_t eof;
    5454
     55  uint_t duration;
     56
    5557  size_t seek_start;
    5658
     
    6870}
    6971
    70 aubio_source_wavread_t * new_aubio_source_wavread(char_t * path, uint_t samplerate, uint_t hop_size) {
     72aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t samplerate, uint_t hop_size) {
    7173  aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t);
    7274  size_t bytes_read = 0, bytes_expected = 44;
    7375  unsigned char buf[5];
    74   unsigned int format, channels, sr, byterate, blockalign, bitspersample;//, data_size;
     76  unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size;
    7577
    7678  if (path == NULL) {
     
    8789  }
    8890
    89   s->path = path;
     91  if (s->path) AUBIO_FREE(s->path);
     92  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     93  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     94
    9095  s->samplerate = samplerate;
    9196  s->hop_size = hop_size;
     
    213218  // Subchunk2Size
    214219  bytes_read += fread(buf, 1, 4, s->fid);
     220  duration = read_little_endian(buf, 4) / blockalign;
     221
    215222  //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24);
    216223  //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path);
     
    232239  s->blockalign= blockalign;
    233240  s->bitspersample = bitspersample;
     241
     242  s->duration = duration;
    234243
    235244  s->short_output = (unsigned char *)calloc(s->blockalign, AUBIO_WAVREAD_BUFSIZE);
     
    372381}
    373382
     383uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t * s) {
     384  if (s && s->duration) {
     385    return s->duration;
     386  }
     387  return 0;
     388}
     389
    374390uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
    375391  if (!s->fid) {
     
    389405  if (s->short_output) AUBIO_FREE(s->short_output);
    390406  if (s->output) del_fmat(s->output);
     407  if (s->path) AUBIO_FREE(s->path);
    391408  AUBIO_FREE(s);
    392409}
  • src/io/source_wavread.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SOURCE_WAVREAD_H
    22 #define _AUBIO_SOURCE_WAVREAD_H
     21#ifndef AUBIO_SOURCE_WAVREAD_H
     22#define AUBIO_SOURCE_WAVREAD_H
    2323
    2424/** \file
     
    6262
    6363*/
    64 aubio_source_wavread_t * new_aubio_source_wavread(char_t * uri, uint_t samplerate, uint_t hop_size);
     64aubio_source_wavread_t * new_aubio_source_wavread(const char_t * uri, uint_t samplerate, uint_t hop_size);
    6565
    6666/**
     
    126126/**
    127127
     128  get the duration of source object, in frames
     129
     130  \param s source object, created with ::new_aubio_source_sndfile
     131  \return number of frames in file
     132
     133*/
     134uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t *s);
     135
     136/**
     137
    128138  close source
    129139
     
    148158#endif
    149159
    150 #endif /* _AUBIO_SOURCE_WAVREAD_H */
     160#endif /* AUBIO_SOURCE_WAVREAD_H */
  • src/io/utils_apple_audio.c

    r60fc05b rf264b17  
    3434}
    3535
    36 CFURLRef getURLFromPath(const char * path) {
     36CFURLRef createURLFromPath(const char * path) {
    3737  CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
    3838      path, kCFStringEncodingUTF8);
    3939
    40   return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
     40  CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
    4141      kCFURLPOSIXPathStyle, false);
     42  CFRelease(cfTotalPath);
     43  return url;
    4244}
    4345
  • src/lvec.c

    r60fc05b rf264b17  
    2222#include "lvec.h"
    2323
    24 lvec_t * new_lvec( uint_t length) {
     24lvec_t * new_lvec(uint_t length) {
    2525  lvec_t * s;
    2626  if ((sint_t)length <= 0) {
     
    4646}
    4747
    48 lsmp_t * lvec_get_data(lvec_t *s) {
     48lsmp_t * lvec_get_data(const lvec_t *s) {
    4949  return s->data;
    5050}
     
    5252/* helper functions */
    5353
    54 void lvec_print(lvec_t *s) {
     54void lvec_print(const lvec_t *s) {
    5555  uint_t j;
    5656  for (j=0; j< s->length; j++) {
  • src/lvec.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO__LVEC_H
    22 #define _AUBIO__LVEC_H
     21#ifndef AUBIO_LVEC_H
     22#define AUBIO_LVEC_H
    2323
    2424#ifdef __cplusplus
     
    8181
    8282*/
    83 lsmp_t * lvec_get_data(lvec_t *s);
     83lsmp_t * lvec_get_data(const lvec_t *s);
    8484
    8585/** print out lvec data
     
    8888
    8989*/
    90 void lvec_print(lvec_t *s);
     90void lvec_print(const lvec_t *s);
    9191
    9292/** set all elements to a given value
     
    116116#endif
    117117
    118 #endif /* _AUBIO__LVEC_H */
     118#endif /* AUBIO_LVEC_H */
  • src/mathutils.c

    r60fc05b rf264b17  
    2626#include "musicutils.h"
    2727#include "config.h"
    28 
    29 #ifdef HAVE_ACCELERATE
    30 #include <Accelerate/Accelerate.h>
    31 #endif
    3228
    3329/** Window types */
     
    167163  return tmp / (smpl_t) (s->length);
    168164#else
    169 #if !HAVE_AUBIO_DOUBLE
    170   vDSP_meanv(s->data, 1, &tmp, s->length);
    171 #else /* HAVE_AUBIO_DOUBLE */
    172   vDSP_meanvD(s->data, 1, &tmp, s->length);
    173 #endif /* HAVE_AUBIO_DOUBLE */
     165  aubio_vDSP_meanv(s->data, 1, &tmp, s->length);
    174166  return tmp;
    175167#endif /* HAVE_ACCELERATE */
     
    186178  }
    187179#else
    188 #if !HAVE_AUBIO_DOUBLE
    189   vDSP_sve(s->data, 1, &tmp, s->length);
    190 #else /* HAVE_AUBIO_DOUBLE */
    191   vDSP_sveD(s->data, 1, &tmp, s->length);
    192 #endif /* HAVE_AUBIO_DOUBLE */
     180  aubio_vDSP_sve(s->data, 1, &tmp, s->length);
    193181#endif /* HAVE_ACCELERATE */
    194182  return tmp;
     
    206194#else
    207195  smpl_t tmp = 0.;
    208 #if !HAVE_AUBIO_DOUBLE
    209   vDSP_maxv(s->data, 1, &tmp, s->length);
    210 #else
    211   vDSP_maxvD(s->data, 1, &tmp, s->length);
    212 #endif
     196  aubio_vDSP_maxv(s->data, 1, &tmp, s->length);
    213197#endif
    214198  return tmp;
     
    226210#else
    227211  smpl_t tmp = 0.;
    228 #if !HAVE_AUBIO_DOUBLE
    229   vDSP_minv(s->data, 1, &tmp, s->length);
    230 #else
    231   vDSP_minvD(s->data, 1, &tmp, s->length);
    232 #endif
     212  aubio_vDSP_minv(s->data, 1, &tmp, s->length);
    233213#endif
    234214  return tmp;
     
    248228  smpl_t tmp = 0.;
    249229  uint_t pos = 0.;
    250 #if !HAVE_AUBIO_DOUBLE
    251   vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    252 #else
    253   vDSP_minviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    254 #endif
     230  aubio_vDSP_minvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    255231#endif
    256232  return pos;
     
    270246  smpl_t tmp = 0.;
    271247  uint_t pos = 0.;
    272 #if !HAVE_AUBIO_DOUBLE
    273   vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    274 #else
    275   vDSP_maxviD(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    276 #endif
     248  aubio_vDSP_maxvi(s->data, 1, &tmp, (vDSP_Length *)&pos, s->length);
    277249#endif
    278250  return pos;
     
    282254fvec_shift (fvec_t * s)
    283255{
    284   uint_t j;
    285   for (j = 0; j < s->length / 2; j++) {
    286     ELEM_SWAP (s->data[j], s->data[j + s->length / 2]);
    287   }
    288 }
    289 
    290 smpl_t
    291 aubio_level_lin (fvec_t * f)
     256  uint_t half = s->length / 2, start = half, j;
     257  // if length is odd, middle element is moved to the end
     258  if (2 * half < s->length) start ++;
     259#ifndef HAVE_ATLAS
     260  for (j = 0; j < half; j++) {
     261    ELEM_SWAP (s->data[j], s->data[j + start]);
     262  }
     263#else
     264  aubio_cblas_swap(half, s->data, 1, s->data + start, 1);
     265#endif
     266  if (start != half) {
     267    for (j = 0; j < half; j++) {
     268      ELEM_SWAP (s->data[j + start - 1], s->data[j + start]);
     269    }
     270  }
     271}
     272
     273void
     274fvec_ishift (fvec_t * s)
     275{
     276  uint_t half = s->length / 2, start = half, j;
     277  // if length is odd, middle element is moved to the beginning
     278  if (2 * half < s->length) start ++;
     279#ifndef HAVE_ATLAS
     280  for (j = 0; j < half; j++) {
     281    ELEM_SWAP (s->data[j], s->data[j + start]);
     282  }
     283#else
     284  aubio_cblas_swap(half, s->data, 1, s->data + start, 1);
     285#endif
     286  if (start != half) {
     287    for (j = 0; j < half; j++) {
     288      ELEM_SWAP (s->data[half], s->data[j]);
     289    }
     290  }
     291}
     292
     293smpl_t
     294aubio_level_lin (const fvec_t * f)
    292295{
    293296  smpl_t energy = 0.;
     297#ifndef HAVE_ATLAS
    294298  uint_t j;
    295299  for (j = 0; j < f->length; j++) {
    296300    energy += SQR (f->data[j]);
    297301  }
     302#else
     303  energy = aubio_cblas_dot(f->length, f->data, 1, f->data, 1);
     304#endif
    298305  return energy / f->length;
    299306}
     
    434441}
    435442
    436 smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t pos) {
     443smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t pos) {
    437444  smpl_t s0, s1, s2; uint_t x0, x2;
     445  smpl_t half = .5, two = 2.;
    438446  if (pos == 0 || pos == x->length - 1) return pos;
    439447  x0 = (pos < 1) ? pos : pos - 1;
     
    444452  s1 = x->data[pos];
    445453  s2 = x->data[x2];
    446   return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2);
     454  return pos + half * (s0 - s2 ) / (s0 - two * s1 + s2);
    447455}
    448456
     
    458466}
    459467
    460 uint_t fvec_peakpick(fvec_t * onset, uint_t pos) {
     468uint_t fvec_peakpick(const fvec_t * onset, uint_t pos) {
    461469  uint_t tmp=0;
    462470  tmp = (onset->data[pos] > onset->data[pos-1]
     
    545553
    546554smpl_t
    547 aubio_db_spl (fvec_t * o)
     555aubio_db_spl (const fvec_t * o)
    548556{
    549557  return 10. * LOG10 (aubio_level_lin (o));
     
    551559
    552560uint_t
    553 aubio_silence_detection (fvec_t * o, smpl_t threshold)
     561aubio_silence_detection (const fvec_t * o, smpl_t threshold)
    554562{
    555563  return (aubio_db_spl (o) < threshold);
     
    591599
    592600void
    593 aubio_autocorr (fvec_t * input, fvec_t * output)
     601aubio_autocorr (const fvec_t * input, fvec_t * output)
    594602{
    595603  uint_t i, j, length = input->length;
  • src/mathutils.h

    r60fc05b rf264b17  
    2828 */
    2929
    30 #ifndef _AUBIO_MATHUTILS_H
    31 #define _AUBIO_MATHUTILS_H
     30#ifndef AUBIO_MATHUTILS_H
     31#define AUBIO_MATHUTILS_H
    3232
    3333#include "fvec.h"
     
    9999*/
    100100void fvec_shift (fvec_t * v);
     101
     102/** swap the left and right halves of a vector
     103
     104  This function swaps the left part of the signal with the right part of the
     105signal. Therefore
     106
     107  \f$ a[0], a[1], ..., a[\frac{N}{2}], a[\frac{N}{2}+1], ..., a[N-1], a[N] \f$
     108
     109  becomes
     110
     111  \f$ a[\frac{N}{2}+1], ..., a[N-1], a[N], a[0], a[1], ..., a[\frac{N}{2}] \f$
     112
     113  This operation, known as 'ifftshift' in the Matlab Signal Processing Toolbox,
     114can be used after computing the inverse FFT to simplify the phase relationship
     115of the resulting spectrum. See Amalia de Götzen's paper referred to above.
     116
     117*/
     118void fvec_ishift (fvec_t * v);
    101119
    102120/** compute the sum of all elements of a vector
     
    233251
    234252*/
    235 smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t p);
     253smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t p);
    236254
    237255/** finds magnitude of peak by quadratic interpolation
     
    276294
    277295*/
    278 uint_t fvec_peakpick (fvec_t * v, uint_t p);
     296uint_t fvec_peakpick (const fvec_t * v, uint_t p);
    279297
    280298/** return 1 if a is a power of 2, 0 otherwise */
     
    290308
    291309*/
    292 void aubio_autocorr (fvec_t * input, fvec_t * output);
     310void aubio_autocorr (const fvec_t * input, fvec_t * output);
    293311
    294312#ifdef __cplusplus
     
    296314#endif
    297315
    298 #endif /* _AUBIO_MATHUTILS_H */
     316#endif /* AUBIO_MATHUTILS_H */
  • src/musicutils.h

    r60fc05b rf264b17  
    2323 */
    2424
    25 #ifndef _AUBIO__MUSICUTILS_H
    26 #define _AUBIO__MUSICUTILS_H
     25#ifndef AUBIO_MUSICUTILS_H
     26#define AUBIO_MUSICUTILS_H
    2727
    2828#ifdef __cplusplus
     
    5757the International Conference on Digital Audio Effects (DAFx-00), pages 37–44,
    5858Uni- versity of Verona, Italy, 2000.
    59   (<a href="http://profs.sci.univr.it/%7Edafx/Final-Papers/ps/Bernardini.ps.gz">
    60   ps.gz</a>)
     59  (<a href="http://www.cs.princeton.edu/courses/archive/spr09/cos325/Bernardini.pdf">
     60  pdf</a>)
    6161
    6262 */
     
    122122
    123123*/
    124 smpl_t aubio_level_lin (fvec_t * v);
     124smpl_t aubio_level_lin (const fvec_t * v);
    125125
    126126/** compute sound pressure level (SPL) in dB
     
    135135
    136136*/
    137 smpl_t aubio_db_spl (fvec_t * v);
     137smpl_t aubio_db_spl (const fvec_t * v);
    138138
    139139/** check if buffer level in dB SPL is under a given threshold
     
    145145
    146146*/
    147 uint_t aubio_silence_detection (fvec_t * v, smpl_t threshold);
     147uint_t aubio_silence_detection (const fvec_t * v, smpl_t threshold);
    148148
    149149/** get buffer level if level >= threshold, 1. otherwise
     
    161161#endif
    162162
    163 #endif /* _AUBIO__MUSICUTILS_H */
     163#endif /* AUBIO_MUSICUTILS_H */
  • src/onset/onset.c

    r60fc05b rf264b17  
    4646
    4747/* execute onset detection function on iput buffer */
    48 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)
     48void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset)
    4949{
    5050  smpl_t isonset = 0;
     
    8585}
    8686
    87 uint_t aubio_onset_get_last (aubio_onset_t *o)
     87uint_t aubio_onset_get_last (const aubio_onset_t *o)
    8888{
    8989  return o->last_onset - o->delay;
    9090}
    9191
    92 smpl_t aubio_onset_get_last_s (aubio_onset_t *o)
     92smpl_t aubio_onset_get_last_s (const aubio_onset_t *o)
    9393{
    9494  return aubio_onset_get_last (o) / (smpl_t) (o->samplerate);
    9595}
    9696
    97 smpl_t aubio_onset_get_last_ms (aubio_onset_t *o)
     97smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o)
    9898{
    9999  return aubio_onset_get_last_s (o) * 1000.;
     
    105105}
    106106
    107 smpl_t aubio_onset_get_silence(aubio_onset_t * o) {
     107smpl_t aubio_onset_get_silence(const aubio_onset_t * o) {
    108108  return o->silence;
    109109}
     
    114114}
    115115
    116 smpl_t aubio_onset_get_threshold(aubio_onset_t * o) {
     116smpl_t aubio_onset_get_threshold(const aubio_onset_t * o) {
    117117  return aubio_peakpicker_get_threshold(o->pp);
    118118}
     
    123123}
    124124
    125 uint_t aubio_onset_get_minioi(aubio_onset_t * o) {
     125uint_t aubio_onset_get_minioi(const aubio_onset_t * o) {
    126126  return o->minioi;
    127127}
    128128
    129129uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) {
    130   return aubio_onset_set_minioi (o, minioi * o->samplerate);
    131 }
    132 
    133 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o) {
     130  return aubio_onset_set_minioi (o, (uint_t)ROUND(minioi * o->samplerate));
     131}
     132
     133smpl_t aubio_onset_get_minioi_s(const aubio_onset_t * o) {
    134134  return aubio_onset_get_minioi (o) / (smpl_t) o->samplerate;
    135135}
     
    139139}
    140140
    141 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o) {
     141smpl_t aubio_onset_get_minioi_ms(const aubio_onset_t * o) {
    142142  return aubio_onset_get_minioi_s (o) * 1000.;
    143143}
     
    148148}
    149149
    150 uint_t aubio_onset_get_delay(aubio_onset_t * o) {
     150uint_t aubio_onset_get_delay(const aubio_onset_t * o) {
    151151  return o->delay;
    152152}
     
    156156}
    157157
    158 smpl_t aubio_onset_get_delay_s(aubio_onset_t * o) {
     158smpl_t aubio_onset_get_delay_s(const aubio_onset_t * o) {
    159159  return aubio_onset_get_delay (o) / (smpl_t) o->samplerate;
    160160}
     
    164164}
    165165
    166 smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o) {
     166smpl_t aubio_onset_get_delay_ms(const aubio_onset_t * o) {
    167167  return aubio_onset_get_delay_s (o) * 1000.;
    168168}
    169169
    170 smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
     170smpl_t aubio_onset_get_descriptor(const aubio_onset_t * o) {
    171171  return o->desc->data[0];
    172172}
    173173
    174 smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
     174smpl_t aubio_onset_get_thresholded_descriptor(const aubio_onset_t * o) {
    175175  fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    176176  return thresholded->data[0];
     
    178178
    179179/* Allocate memory for an onset detection */
    180 aubio_onset_t * new_aubio_onset (char_t * onset_mode,
     180aubio_onset_t * new_aubio_onset (const char_t * onset_mode,
    181181    uint_t buf_size, uint_t hop_size, uint_t samplerate)
    182182{
     
    187187    AUBIO_ERR("onset: got hop_size %d, but can not be < 1\n", hop_size);
    188188    goto beach;
    189   } else if ((sint_t)buf_size < 1) {
    190     AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", buf_size);
     189  } else if ((sint_t)buf_size < 2) {
     190    AUBIO_ERR("onset: got buffer_size %d, but can not be < 2\n", buf_size);
    191191    goto beach;
    192192  } else if (buf_size < hop_size) {
  • src/onset/onset.h

    r60fc05b rf264b17  
    4040
    4141
    42 #ifndef _AUBIO_ONSET_H
    43 #define _AUBIO_ONSET_H
     42#ifndef AUBIO_ONSET_H
     43#define AUBIO_ONSET_H
    4444
    4545#ifdef __cplusplus
     
    6060
    6161*/
    62 aubio_onset_t * new_aubio_onset (char_t * method,
     62aubio_onset_t * new_aubio_onset (const char_t * method,
    6363    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    6464
     
    8989
    9090*/
    91 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset);
     91void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset);
    9292
    9393/** get the time of the latest onset detected, in samples
     
    9898
    9999*/
    100 uint_t aubio_onset_get_last (aubio_onset_t *o);
     100uint_t aubio_onset_get_last (const aubio_onset_t *o);
    101101
    102102/** get the time of the latest onset detected, in seconds
     
    107107
    108108*/
    109 smpl_t aubio_onset_get_last_s (aubio_onset_t *o);
     109smpl_t aubio_onset_get_last_s (const aubio_onset_t *o);
    110110
    111111/** get the time of the latest onset detected, in milliseconds
     
    116116
    117117*/
    118 smpl_t aubio_onset_get_last_ms (aubio_onset_t *o);
     118smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o);
    119119
    120120/** set onset detection silence threshold
     
    133133
    134134*/
    135 smpl_t aubio_onset_get_silence(aubio_onset_t * o);
     135smpl_t aubio_onset_get_silence(const aubio_onset_t * o);
    136136
    137137/** get onset detection function
     
    141141
    142142*/
    143 smpl_t aubio_onset_get_descriptor ( aubio_onset_t *o);
     143smpl_t aubio_onset_get_descriptor (const aubio_onset_t *o);
    144144
    145145/** get thresholded onset detection function
     
    149149
    150150*/
    151 smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);
     151smpl_t aubio_onset_get_thresholded_descriptor (const aubio_onset_t *o);
    152152
    153153/** set onset detection peak picking threshold
     
    220220
    221221*/
    222 uint_t aubio_onset_get_minioi(aubio_onset_t * o);
     222uint_t aubio_onset_get_minioi(const aubio_onset_t * o);
    223223
    224224/** get minimum inter onset interval in seconds
     
    229229
    230230*/
    231 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o);
     231smpl_t aubio_onset_get_minioi_s(const aubio_onset_t * o);
    232232
    233233/** get minimum inter onset interval in milliseconds
     
    238238
    239239*/
    240 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o);
     240smpl_t aubio_onset_get_minioi_ms(const aubio_onset_t * o);
    241241
    242242/** get delay in samples
     
    247247
    248248*/
    249 uint_t aubio_onset_get_delay(aubio_onset_t * o);
     249uint_t aubio_onset_get_delay(const aubio_onset_t * o);
    250250
    251251/** get delay in seconds
     
    256256
    257257*/
    258 smpl_t aubio_onset_get_delay_s(aubio_onset_t * o);
     258smpl_t aubio_onset_get_delay_s(const aubio_onset_t * o);
    259259
    260260/** get delay in milliseconds
     
    265265
    266266*/
    267 smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o);
     267smpl_t aubio_onset_get_delay_ms(const aubio_onset_t * o);
    268268
    269269/** get onset peak picking threshold
     
    273273
    274274*/
    275 smpl_t aubio_onset_get_threshold(aubio_onset_t * o);
     275smpl_t aubio_onset_get_threshold(const aubio_onset_t * o);
    276276
    277277/** delete onset detection object
     
    286286#endif
    287287
    288 #endif /* _AUBIO_ONSET_H */
     288#endif /* AUBIO_ONSET_H */
  • src/onset/peakpicker.h

    r60fc05b rf264b17  
    2727*/
    2828
    29 #ifndef _AUBIO_PEAKPICK_H
    30 #define _AUBIO_PEAKPICK_H
     29#ifndef AUBIO_PEAKPICK_H
     30#define AUBIO_PEAKPICK_H
    3131
    3232#ifdef __cplusplus
     
    5555#endif
    5656
    57 #endif /* _AUBIO_PEAKPICK_H */
     57#endif /* AUBIO_PEAKPICK_H */
  • src/pitch/pitch.c

    r60fc05b rf264b17  
    6262
    6363/** callback to get pitch candidate, defined below */
    64 typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     64typedef void (*aubio_pitch_detect_t) (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    6565
    6666/** callback to convert pitch from one unit to another, defined below */
     
    7979  void *p_object;                 /**< pointer to pitch object */
    8080  aubio_filter_t *filter;         /**< filter */
     81  fvec_t *filtered;               /**< filtered input */
    8182  aubio_pvoc_t *pv;               /**< phase vocoder for mcomb */
    8283  cvec_t *fftgrain;               /**< spectral frame for mcomb */
     
    8990
    9091/* callback functions for pitch detection */
    91 static void aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    92 static void aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    93 static void aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    94 static void aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    95 static void aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
    96 static void aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf);
     92static void aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     93static void aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     94static void aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     95static void aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     96static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
     97static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
    9798
    9899/* conversion functions for frequency conversions */
     
    102103
    103104/* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */
    104 void aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf);
     105void aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf);
    105106
    106107
    107108aubio_pitch_t *
    108 new_aubio_pitch (char_t * pitch_mode,
     109new_aubio_pitch (const char_t * pitch_mode,
    109110    uint_t bufsize, uint_t hopsize, uint_t samplerate)
    110111{
     
    133134  // check parameters are valid
    134135  if ((sint_t)hopsize < 1) {
    135     AUBIO_ERR("onset: got hopsize %d, but can not be < 1\n", hopsize);
     136    AUBIO_ERR("pitch: got hopsize %d, but can not be < 1\n", hopsize);
    136137    goto beach;
    137138  } else if ((sint_t)bufsize < 1) {
    138     AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", bufsize);
     139    AUBIO_ERR("pitch: got buffer_size %d, but can not be < 1\n", bufsize);
    139140    goto beach;
    140141  } else if (bufsize < hopsize) {
    141     AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);
     142    AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);
    142143    goto beach;
    143144  } else if ((sint_t)samplerate < 1) {
    144     AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate);
     145    AUBIO_ERR("pitch: samplerate (%d) can not be < 1\n", samplerate);
    145146    goto beach;
    146147  }
     
    161162      break;
    162163    case aubio_pitcht_mcomb:
     164      p->filtered = new_fvec (hopsize);
    163165      p->pv = new_aubio_pvoc (bufsize, hopsize);
    164166      p->fftgrain = new_cvec (bufsize);
     
    210212      break;
    211213    case aubio_pitcht_mcomb:
     214      del_fvec (p->filtered);
    212215      del_aubio_pvoc (p->pv);
    213216      del_cvec (p->fftgrain);
     
    238241
    239242void
    240 aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)
    241 {
    242   uint_t j = 0, overlap_size = 0;
    243   overlap_size = p->buf->length - ibuf->length;
     243aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf)
     244{
     245  uint_t overlap_size = p->buf->length - ibuf->length;
     246#if 1 //!HAVE_MEMCPY_HACKS
     247  uint_t j;
    244248  for (j = 0; j < overlap_size; j++) {
    245249    p->buf->data[j] = p->buf->data[j + ibuf->length];
     
    248252    p->buf->data[j + overlap_size] = ibuf->data[j];
    249253  }
     254#else
     255  smpl_t *data = p->buf->data;
     256  smpl_t *newdata = ibuf->data;
     257  memmove(data, data + ibuf->length, overlap_size);
     258  memcpy(data + overlap_size, newdata, ibuf->length);
     259#endif
    250260}
    251261
    252262uint_t
    253 aubio_pitch_set_unit (aubio_pitch_t * p, char_t * pitch_unit)
     263aubio_pitch_set_unit (aubio_pitch_t * p, const char_t * pitch_unit)
    254264{
    255265  uint_t err = AUBIO_OK;
     
    336346/* do method, calling the detection callback, then the conversion callback */
    337347void
    338 aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     348aubio_pitch_do (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    339349{
    340350  p->detect_cb (p, ibuf, obuf);
     
    347357/* do method for each algorithm */
    348358void
    349 aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    350 {
    351   aubio_filter_do (p->filter, ibuf);
     359aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
     360{
     361  aubio_filter_do_outplace (p->filter, ibuf, p->filtered);
    352362  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
    353363  aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf);
     
    356366
    357367void
    358 aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     368aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    359369{
    360370  smpl_t pitch = 0.;
     
    372382
    373383void
    374 aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     384aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    375385{
    376386  smpl_t pitch = 0.;
     
    387397
    388398void
    389 aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     399aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    390400{
    391401  smpl_t pitch = 0., period;
     
    403413
    404414void
    405 aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     415aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    406416{
    407417  aubio_pitch_slideblock (p, ibuf);
     
    411421
    412422void
    413 aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     423aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    414424{
    415425  smpl_t period, pitch = 0.;
  • src/pitch/pitch.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_PITCH_H
    22 #define _AUBIO_PITCH_H
     21#ifndef AUBIO_PITCH_H
     22#define AUBIO_PITCH_H
    2323
    2424#ifdef __cplusplus
     
    108108
    109109*/
    110 void aubio_pitch_do (aubio_pitch_t * o, fvec_t * in, fvec_t * out);
     110void aubio_pitch_do (aubio_pitch_t * o, const fvec_t * in, fvec_t * out);
    111111
    112112/** change yin or yinfft tolerance threshold
     
    135135
    136136*/
    137 aubio_pitch_t *new_aubio_pitch (char_t * method,
     137aubio_pitch_t *new_aubio_pitch (const char_t * method,
    138138    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    139139
     
    146146
    147147*/
    148 uint_t aubio_pitch_set_unit (aubio_pitch_t * o, char_t * mode);
     148uint_t aubio_pitch_set_unit (aubio_pitch_t * o, const char_t * mode);
    149149
    150150/** set the silence threshold of the pitch detection object
     
    180180#endif
    181181
    182 #endif /* _AUBIO_PITCH_H */
     182#endif /* AUBIO_PITCH_H */
  • src/pitch/pitchfcomb.c

    r60fc05b rf264b17  
    6464/* input must be stepsize long */
    6565void
    66 aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
     66aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, fvec_t * output)
    6767{
    6868  uint_t k, l, maxharm = 0;
  • src/pitch/pitchfcomb.h

    r60fc05b rf264b17  
    3535*/
    3636
    37 #ifndef _AUBIO_PITCHFCOMB_H
    38 #define _AUBIO_PITCHFCOMB_H
     37#ifndef AUBIO_PITCHFCOMB_H
     38#define AUBIO_PITCHFCOMB_H
    3939
    4040#ifdef __cplusplus
     
    5252
    5353*/
    54 void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input,
     54void aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input,
    5555    fvec_t * output);
    5656
     
    7474#endif
    7575
    76 #endif /* _AUBIO_PITCHFCOMB_H */
     76#endif /* AUBIO_PITCHFCOMB_H */
  • src/pitch/pitchmcomb.c

    r60fc05b rf264b17  
    3232    uint_t length);
    3333uint_t aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks,
    34     fvec_t * X);
    35 void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * oldmag);
    36 void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag);
     34    const fvec_t * X);
     35void aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, const fvec_t * oldmag);
     36void aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, const fvec_t * newmag);
    3737/* not used but useful : sort by amplitudes (or anything else)
    3838 * sort_pitchpeak(peaks, length);
     
    4343void aubio_pitchmcomb_sort_peak (aubio_spectralpeak_t * peaks, uint_t nbins);
    4444/** select the best candidates */
    45 uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain,
     45uint_t aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain,
    4646    smpl_t * cands);
    4747
     
    102102
    103103void
    104 aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * fftgrain, fvec_t * output)
     104aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, fvec_t * output)
    105105{
    106106  uint_t j;
     
    135135
    136136uint_t
    137 aubio_pitch_cands (aubio_pitchmcomb_t * p, cvec_t * fftgrain, smpl_t * cands)
     137aubio_pitch_cands (aubio_pitchmcomb_t * p, const cvec_t * fftgrain, smpl_t * cands)
    138138{
    139139  uint_t j;
     
    166166
    167167void
    168 aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, fvec_t * newmag)
     168aubio_pitchmcomb_spectral_pp (aubio_pitchmcomb_t * p, const fvec_t * newmag)
    169169{
    170170  fvec_t *mag = (fvec_t *) p->scratch;
     
    198198
    199199void
    200 aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, fvec_t * newmag)
     200aubio_pitchmcomb_combdet (aubio_pitchmcomb_t * p, const fvec_t * newmag)
    201201{
    202202  aubio_spectralpeak_t *peaks = (aubio_spectralpeak_t *) p->peaks;
     
    286286 */
    287287uint_t
    288 aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, fvec_t * X)
     288aubio_pitchmcomb_quadpick (aubio_spectralpeak_t * spectral_peaks, const fvec_t * X)
    289289{
    290290  uint_t j, ispeak, count = 0;
     
    336336  uint_t run = 0;
    337337  for (cur = 0; cur < nbins; cur++) {
    338     run = cur + 1;
    339     for (run = cur; run < nbins; run++) {
     338    for (run = cur + 1; run < nbins; run++) {
    340339      if (candidates[run]->ene > candidates[cur]->ene)
    341340        CAND_SWAP (candidates[run], candidates[cur]);
     
    352351  uint_t run = 0;
    353352  for (cur = 0; cur < nbins; cur++) {
    354     run = cur + 1;
    355     for (run = cur; run < nbins; run++) {
     353    for (run = cur + 1; run < nbins; run++) {
    356354      if (candidates[run]->ebin < candidates[cur]->ebin)
    357355        CAND_SWAP (candidates[run], candidates[cur]);
     
    367365  uint_t i, j;
    368366  uint_t spec_size;
    369   p->spec_partition = 4;
     367  p->spec_partition = 2;
    370368  p->ncand = 5;
    371369  p->npartials = 5;
     
    379377  p->phasefreq = bufsize / hopsize / TWO_PI;
    380378  p->phasediff = TWO_PI * hopsize / bufsize;
    381   spec_size = bufsize / p->spec_partition;
     379  spec_size = bufsize / p->spec_partition + 1;
    382380  //p->pickerfn = quadpick;
    383381  //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348);
  • src/pitch/pitchmcomb.h

    r60fc05b rf264b17  
    3636*/
    3737
    38 #ifndef _AUBIO_PITCHMCOMB_H
    39 #define _AUBIO_PITCHMCOMB_H
     38#ifndef AUBIO_PITCHMCOMB_H
     39#define AUBIO_PITCHMCOMB_H
    4040
    4141#ifdef __cplusplus
     
    5353
    5454*/
    55 void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, cvec_t * in_fftgrain,
     55void aubio_pitchmcomb_do (aubio_pitchmcomb_t * p, const cvec_t * in_fftgrain,
    5656    fvec_t * out_cands);
    5757
     
    7575#endif
    7676
    77 #endif /* _AUBIO_PITCHMCOMB_H */
     77#endif /* AUBIO_PITCHMCOMB_H */
  • src/pitch/pitchschmitt.c

    r60fc05b rf264b17  
    4848
    4949void
    50 aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * input,
     50aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, const fvec_t * input,
    5151    fvec_t * output)
    5252{
  • src/pitch/pitchschmitt.h

    r60fc05b rf264b17  
    3535*/
    3636
    37 #ifndef _AUBIO_PITCHSCHMITT_H
    38 #define _AUBIO_PITCHSCHMITT_H
     37#ifndef AUBIO_PITCHSCHMITT_H
     38#define AUBIO_PITCHSCHMITT_H
    3939
    4040#ifdef __cplusplus
     
    5252
    5353*/
    54 void aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, fvec_t * samples_in,
     54void aubio_pitchschmitt_do (aubio_pitchschmitt_t * p, const fvec_t * samples_in,
    5555    fvec_t * cands_out);
    5656
     
    7373#endif
    7474
    75 #endif /* _AUBIO_PITCHSCHMITT_H */
    76 
     75#endif /* AUBIO_PITCHSCHMITT_H */
  • src/pitch/pitchspecacf.c

    r60fc05b rf264b17  
    5555
    5656void
    57 aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)
     57aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, const fvec_t * input, fvec_t * output)
    5858{
    5959  uint_t l, tau;
     
    9292
    9393smpl_t
    94 aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o) {
     94aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o) {
    9595  // no confidence for now
    9696  return o->confidence;
     
    105105
    106106smpl_t
    107 aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * p)
     107aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * p)
    108108{
    109109  return p->tol;
  • src/pitch/pitchspecacf.h

    r60fc05b rf264b17  
    3939*/
    4040
    41 #ifndef _AUBIO_PITCHSPECACF_H
    42 #define _AUBIO_PITCHSPECACF_H
     41#ifndef AUBIO_PITCHSPECACF_H
     42#define AUBIO_PITCHSPECACF_H
    4343
    4444#ifdef __cplusplus
     
    5656
    5757*/
    58 void aubio_pitchspecacf_do (aubio_pitchspecacf_t * o, fvec_t * samples_in, fvec_t * cands_out);
     58void aubio_pitchspecacf_do (aubio_pitchspecacf_t * o, const fvec_t * samples_in, fvec_t * cands_out);
    5959/** creation of the pitch detection object
    6060
     
    7777
    7878*/
    79 smpl_t aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * o);
     79smpl_t aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * o);
    8080
    8181/** set tolerance parameter for `specacf` pitch detection object
     
    9595
    9696*/
    97 smpl_t aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o);
     97smpl_t aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o);
    9898
    9999#ifdef __cplusplus
     
    101101#endif
    102102
    103 #endif /* _AUBIO_PITCHSPECACF_H */
     103#endif /* AUBIO_PITCHSPECACF_H */
  • src/pitch/pitchyin.c

    r60fc05b rf264b17  
    4141
    4242/** compute difference function
    43  
    44   \param input input signal 
     43
     44  \param input input signal
    4545  \param yinbuf output buffer to store difference function (half shorter than input)
    4646
     
    4848void aubio_pitchyin_diff (fvec_t * input, fvec_t * yinbuf);
    4949
    50 /** in place computation of the YIN cumulative normalised function 
    51  
    52   \param yinbuf input signal (a square difference function), also used to store function 
     50/** in place computation of the YIN cumulative normalised function
     51
     52  \param yinbuf input signal (a square difference function), also used to store function
    5353
    5454*/
     
    5656
    5757/** detect pitch in a YIN function
    58  
     58
    5959  \param yinbuf input buffer as computed by aubio_pitchyin_getcum
    6060
    6161*/
    62 uint_t aubio_pitchyin_getpitch (fvec_t * yinbuf);
     62uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf);
    6363
    6464aubio_pitchyin_t *
     
    112112
    113113uint_t
    114 aubio_pitchyin_getpitch (fvec_t * yin)
     114aubio_pitchyin_getpitch (const fvec_t * yin)
    115115{
    116116  uint_t tau = 1;
     
    131131/* all the above in one */
    132132void
    133 aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * input, fvec_t * out)
     133aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out)
    134134{
    135135  smpl_t tol = o->tol;
  • src/pitch/pitchyin.h

    r60fc05b rf264b17  
    3636*/
    3737
    38 #ifndef _AUBIO_PITCHYIN_H
    39 #define _AUBIO_PITCHYIN_H
     38#ifndef AUBIO_PITCHYIN_H
     39#define AUBIO_PITCHYIN_H
    4040
    4141#ifdef __cplusplus
     
    6767
    6868*/
    69 void aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * samples_in, fvec_t * cands_out);
     69void aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * samples_in, fvec_t * cands_out);
    7070
    7171
     
    9898#endif
    9999
    100 #endif /* _AUBIO_PITCHYIN_H */
     100#endif /* AUBIO_PITCHYIN_H */
  • src/pitch/pitchyinfft.c

    r60fc05b rf264b17  
    9999
    100100void
    101 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)
     101aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, const fvec_t * input, fvec_t * output)
    102102{
    103103  uint_t tau, l;
     
    108108  smpl_t tmp = 0., sum = 0.;
    109109  // window the input
    110   for (l = 0; l < input->length; l++) {
    111     p->winput->data[l] = p->win->data[l] * input->data[l];
    112   }
     110  fvec_weighted_copy(input, p->win, p->winput);
    113111  // get the real / imag parts of its fft
    114112  aubio_fft_do_complex (p->fft, p->winput, fftout);
  • src/pitch/pitchyinfft.h

    r60fc05b rf264b17  
    3636*/
    3737
    38 #ifndef _AUBIO_PITCHYINFFT_H
    39 #define _AUBIO_PITCHYINFFT_H
     38#ifndef AUBIO_PITCHYINFFT_H
     39#define AUBIO_PITCHYINFFT_H
    4040
    4141#ifdef __cplusplus
     
    5353
    5454*/
    55 void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, fvec_t * samples_in, fvec_t * cands_out);
     55void aubio_pitchyinfft_do (aubio_pitchyinfft_t * o, const fvec_t * samples_in, fvec_t * cands_out);
    5656/** creation of the pitch detection object
    5757
     
    9797#endif
    9898
    99 #endif /* _AUBIO_PITCHYINFFT_H */
     99#endif /* AUBIO_PITCHYINFFT_H */
  • src/spectral/fft.c

    r60fc05b rf264b17  
    6565#ifdef HAVE_FFTW3F
    6666#if HAVE_AUBIO_DOUBLE
    67 #warning "Using aubio in double precision with fftw3 in single precision"
     67#error "Using aubio in double precision with fftw3 in single precision"
    6868#endif /* HAVE_AUBIO_DOUBLE */
    6969#define real_t float
    70 #else /* HAVE_FFTW3F */
     70#elif defined (HAVE_FFTW3) /* HAVE_FFTW3F */
    7171#if !HAVE_AUBIO_DOUBLE
    72 #warning "Using aubio in single precision with fftw3 in double precision"
     72#error "Using aubio in single precision with fftw3 in double precision"
    7373#endif /* HAVE_AUBIO_DOUBLE */
    7474#define real_t double
     
    144144aubio_fft_t * new_aubio_fft (uint_t winsize) {
    145145  aubio_fft_t * s = AUBIO_NEW(aubio_fft_t);
    146   if ((sint_t)winsize < 1) {
    147     AUBIO_ERR("fft: got winsize %d, but can not be < 1\n", winsize);
     146  if ((sint_t)winsize < 2) {
     147    AUBIO_ERR("fft: got winsize %d, but can not be < 2\n", winsize);
    148148    goto beach;
    149149  }
     
    231231}
    232232
    233 void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) {
     233void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) {
    234234  aubio_fft_do_complex(s, input, s->compspec);
    235235  aubio_fft_get_spectrum(s->compspec, spectrum);
    236236}
    237237
    238 void aubio_fft_rdo(aubio_fft_t * s, cvec_t * spectrum, fvec_t * output) {
     238void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) {
    239239  aubio_fft_get_realimag(spectrum, s->compspec);
    240240  aubio_fft_rdo_complex(s, s->compspec, output);
    241241}
    242242
    243 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
     243void aubio_fft_do_complex(aubio_fft_t * s, const fvec_t * input, fvec_t * compspec) {
    244244  uint_t i;
    245245#ifndef HAVE_MEMCPY_HACKS
     
    292292}
    293293
    294 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {
     294void aubio_fft_rdo_complex(aubio_fft_t * s, const fvec_t * compspec, fvec_t * output) {
    295295  uint_t i;
    296296#ifdef HAVE_FFTW3
     
    347347}
    348348
    349 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum) {
     349void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum) {
    350350  aubio_fft_get_phas(compspec, spectrum);
    351351  aubio_fft_get_norm(compspec, spectrum);
    352352}
    353353
    354 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec) {
     354void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec) {
    355355  aubio_fft_get_imag(spectrum, compspec);
    356356  aubio_fft_get_real(spectrum, compspec);
    357357}
    358358
    359 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
     359void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) {
    360360  uint_t i;
    361361  if (compspec->data[0] < 0) {
     
    375375}
    376376
    377 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
     377void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) {
    378378  uint_t i = 0;
    379379  spectrum->norm[0] = ABS(compspec->data[0]);
     
    386386}
    387387
    388 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
     388void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) {
    389389  uint_t i;
    390390  for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) {
     
    394394}
    395395
    396 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) {
     396void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec) {
    397397  uint_t i;
    398398  for (i = 0; i < compspec->length / 2 + 1; i++) {
  • src/spectral/fft.h

    r60fc05b rf264b17  
    3232*/
    3333
    34 #ifndef _AUBIO_FFT_H
    35 #define _AUBIO_FFT_H
     34#ifndef AUBIO_FFT_H
     35#define AUBIO_FFT_H
    3636
    3737#ifdef __cplusplus
     
    6666
    6767*/
    68 void aubio_fft_do (aubio_fft_t *s, fvec_t * input, cvec_t * spectrum);
     68void aubio_fft_do (aubio_fft_t *s, const fvec_t * input, cvec_t * spectrum);
    6969/** compute backward (inverse) FFT
    7070
     
    7474
    7575*/
    76 void aubio_fft_rdo (aubio_fft_t *s, cvec_t * spectrum, fvec_t * output);
     76void aubio_fft_rdo (aubio_fft_t *s, const cvec_t * spectrum, fvec_t * output);
    7777
    7878/** compute forward FFT
     
    8383
    8484*/
    85 void aubio_fft_do_complex (aubio_fft_t *s, fvec_t * input, fvec_t * compspec);
     85void aubio_fft_do_complex (aubio_fft_t *s, const fvec_t * input, fvec_t * compspec);
    8686/** compute backward (inverse) FFT from real/imag
    8787
     
    9191
    9292*/
    93 void aubio_fft_rdo_complex (aubio_fft_t *s, fvec_t * compspec, fvec_t * output);
     93void aubio_fft_rdo_complex (aubio_fft_t *s, const fvec_t * compspec, fvec_t * output);
    9494
    9595/** convert real/imag spectrum to norm/phas spectrum
     
    9999
    100100*/
    101 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum);
     101void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum);
    102102/** convert real/imag spectrum to norm/phas spectrum
    103103
     
    106106
    107107*/
    108 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec);
     108void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec);
    109109
    110110/** compute phas spectrum from real/imag parts
     
    114114
    115115*/
    116 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum);
     116void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum);
    117117/** compute imaginary part from the norm/phas cvec
    118118
     
    121121
    122122*/
    123 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec);
     123void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec);
    124124
    125125/** compute norm component from real/imag parts
     
    129129
    130130*/
    131 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum);
     131void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum);
    132132/** compute real part from norm/phas components
    133133
     
    136136
    137137*/
    138 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec);
     138void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec);
    139139
    140140#ifdef __cplusplus
     
    142142#endif
    143143
    144 #endif /* _AUBIO_FFT_H */
     144#endif /* AUBIO_FFT_H */
  • src/spectral/filterbank.c

    r60fc05b rf264b17  
    5757
    5858void
    59 aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out)
     59aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out)
    6060{
    61   uint_t j, fn;
     61  /* apply filter to all input channel, provided out has enough channels */
     62  //uint_t max_filters = MIN (f->n_filters, out->length);
     63  //uint_t max_length = MIN (in->length, f->filters->length);
    6264
    63   /* apply filter to all input channel, provided out has enough channels */
    64   uint_t max_filters = MIN (f->n_filters, out->length);
    65   uint_t max_length = MIN (in->length, f->filters->length);
     65  // view cvec->norm as fvec->data
     66  fvec_t tmp;
     67  tmp.length = in->length;
     68  tmp.data = in->norm;
    6669
    67   /* reset all values in output vector */
    68   fvec_zeros (out);
    69 
    70   /* for each filter */
    71   for (fn = 0; fn < max_filters; fn++) {
    72     /* for each sample */
    73     for (j = 0; j < max_length; j++) {
    74       out->data[fn] += in->norm[j] * f->filters->data[fn][j];
    75     }
    76   }
     70  fmat_vecmul(f->filters, &tmp, out);
    7771
    7872  return;
     
    8074
    8175fmat_t *
    82 aubio_filterbank_get_coeffs (aubio_filterbank_t * f)
     76aubio_filterbank_get_coeffs (const aubio_filterbank_t * f)
    8377{
    8478  return f->filters;
     
    8680
    8781uint_t
    88 aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filter_coeffs)
     82aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filter_coeffs)
    8983{
    9084  fmat_copy(filter_coeffs, f->filters);
  • src/spectral/filterbank.h

    r60fc05b rf264b17  
    3030*/
    3131
    32 #ifndef _AUBIO_FILTERBANK_H
    33 #define _AUBIO_FILTERBANK_H
     32#ifndef AUBIO_FILTERBANK_H
     33#define AUBIO_FILTERBANK_H
    3434
    3535#ifdef __cplusplus
     
    6767
    6868*/
    69 void aubio_filterbank_do (aubio_filterbank_t * f, cvec_t * in, fvec_t * out);
     69void aubio_filterbank_do (aubio_filterbank_t * f, const cvec_t * in, fvec_t * out);
    7070
    7171/** return a pointer to the matrix object containing all filter coefficients
     
    7474
    7575 */
    76 fmat_t *aubio_filterbank_get_coeffs (aubio_filterbank_t * f);
     76fmat_t *aubio_filterbank_get_coeffs (const aubio_filterbank_t * f);
    7777
    7878/** copy filter coefficients to the filterbank
     
    8282
    8383 */
    84 uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, fmat_t * filters);
     84uint_t aubio_filterbank_set_coeffs (aubio_filterbank_t * f, const fmat_t * filters);
    8585
    8686#ifdef __cplusplus
     
    8888#endif
    8989
    90 #endif /* _AUBIO_FILTERBANK_H */
     90#endif /* AUBIO_FILTERBANK_H */
  • src/spectral/filterbank_mel.c

    r60fc05b rf264b17  
    3030uint_t
    3131aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
    32     fvec_t * freqs, smpl_t samplerate)
     32    const fvec_t * freqs, smpl_t samplerate)
    3333{
    3434
  • src/spectral/filterbank_mel.h

    r60fc05b rf264b17  
    3232*/
    3333
    34 #ifndef _AUBIO_FILTERBANK_MEL_H
    35 #define _AUBIO_FILTERBANK_MEL_H
     34#ifndef AUBIO_FILTERBANK_MEL_H
     35#define AUBIO_FILTERBANK_MEL_H
    3636
    3737#ifdef __cplusplus
     
    5151*/
    5252uint_t aubio_filterbank_set_triangle_bands (aubio_filterbank_t * fb,
    53     fvec_t * freqs, smpl_t samplerate);
     53    const fvec_t * freqs, smpl_t samplerate);
    5454
    5555/** filterbank initialization for Mel filters using Slaney's coefficients
     
    7070#endif
    7171
    72 #endif /* _AUBIO_FILTERBANK_MEL_H */
     72#endif /* AUBIO_FILTERBANK_MEL_H */
  • src/spectral/mfcc.c

    r60fc05b rf264b17  
    6868  mfcc->in_dct = new_fvec (n_filters);
    6969
    70   mfcc->dct_coeffs = new_fmat (n_filters, n_coefs);
     70  mfcc->dct_coeffs = new_fmat (n_coefs, n_filters);
    7171
    72   /* compute DCT transform dct_coeffs[i][j] as
     72  /* compute DCT transform dct_coeffs[j][i] as
    7373     cos ( j * (i+.5) * PI / n_filters ) */
    7474  scaling = 1. / SQRT (n_filters / 2.);
    7575  for (i = 0; i < n_filters; i++) {
    7676    for (j = 0; j < n_coefs; j++) {
    77       mfcc->dct_coeffs->data[i][j] =
     77      mfcc->dct_coeffs->data[j][i] =
    7878          scaling * COS (j * (i + 0.5) * PI / n_filters);
    7979    }
    80     mfcc->dct_coeffs->data[i][0] *= SQRT (2.) / 2.;
     80    mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.;
    8181  }
    8282
    8383  return mfcc;
    84 };
     84}
    8585
    8686void
     
    101101
    102102void
    103 aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out)
     103aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out)
    104104{
    105   uint_t j, k;
    106 
    107105  /* compute filterbank */
    108106  aubio_filterbank_do (mf->fb, in, mf->in_dct);
     
    114112  //fvec_pow (mf->in_dct, 3.);
    115113
    116   /* zeros output */
    117   fvec_zeros(out);
    118 
    119   /* compute discrete cosine transform */
    120   for (j = 0; j < mf->n_filters; j++) {
    121     for (k = 0; k < mf->n_coefs; k++) {
    122       out->data[k] += mf->in_dct->data[j]
    123           * mf->dct_coeffs->data[j][k];
    124     }
    125   }
     114  /* compute mfccs */
     115  fmat_vecmul(mf->dct_coeffs, mf->in_dct, out);
    126116
    127117  return;
  • src/spectral/mfcc.h

    r60fc05b rf264b17  
    3535*/
    3636
    37 #ifndef _AUBIO_MFCC_H
    38 #define _AUBIO_MFCC_H
     37#ifndef AUBIO_MFCC_H
     38#define AUBIO_MFCC_H
    3939
    4040#ifdef __cplusplus
     
    7171
    7272*/
    73 void aubio_mfcc_do (aubio_mfcc_t * mf, cvec_t * in, fvec_t * out);
     73void aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out);
    7474
    7575#ifdef __cplusplus
     
    7777#endif
    7878
    79 #endif /* _AUBIO_MFCC_H */
     79#endif /* AUBIO_MFCC_H */
  • src/spectral/phasevoc.c

    r60fc05b rf264b17  
    4545
    4646/** returns data and dataold slided by hop_s */
    47 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new);
     47static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new);
    4848
    4949/** do additive synthesis from 'old' and 'cur' */
    5050static void aubio_pvoc_addsynth(aubio_pvoc_t *pv, fvec_t * synthnew);
    5151
    52 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t * datanew, cvec_t *fftgrain) {
     52void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t * datanew, cvec_t *fftgrain) {
    5353  /* slide  */
    5454  aubio_pvoc_swapbuffers(pv, datanew);
     
    6565  aubio_fft_rdo(pv->fft,fftgrain,pv->synth);
    6666  /* unshift */
    67   fvec_shift(pv->synth);
     67  fvec_ishift(pv->synth);
     68  /* windowing */
     69  // if overlap = 50%, do not apply window (identity)
     70  if (pv->hop_s * 2 < pv->win_s) {
     71    fvec_weight(pv->synth, pv->w);
     72  }
    6873  /* additive synthesis */
    6974  aubio_pvoc_addsynth(pv, synthnew);
     
    8085    AUBIO_ERR("pvoc: got hop_size %d, but can not be < 1\n", hop_s);
    8186    goto beach;
    82   } else if ((sint_t)win_s < 1) {
    83     AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 1\n", win_s);
     87  } else if ((sint_t)win_s < 2) {
     88    AUBIO_ERR("pvoc: got buffer_size %d, but can not be < 2\n", win_s);
    8489    goto beach;
    8590  } else if (win_s < hop_s) {
     
    8994
    9095  pv->fft      = new_aubio_fft (win_s);
     96  if (pv->fft == NULL) {
     97    goto beach;
     98  }
    9199
    92100  /* remember old */
     
    118126  pv->hop_datasize = pv->hop_s * sizeof(smpl_t);
    119127
    120   pv->scale = pv->hop_s * 2. / pv->win_s;
     128  // for reconstruction with 75% overlap
     129  if (win_s == hop_s * 4) {
     130    pv->scale = 2./3.;
     131  } else if (win_s == hop_s * 8) {
     132    pv->scale = 1./3.;
     133  } else if (win_s == hop_s * 2) {
     134    pv->scale = 1.;
     135  } else {
     136    pv->scale = .5;
     137  }
    121138
    122139  return pv;
     
    137154}
    138155
    139 static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, fvec_t *new)
     156static void aubio_pvoc_swapbuffers(aubio_pvoc_t *pv, const fvec_t *new)
    140157{
    141158  /* some convenience pointers */
     
    143160  smpl_t * dataold = pv->dataold->data;
    144161  smpl_t * datanew = new->data;
    145 #if !HAVE_MEMCPY_HACKS
     162#ifndef HAVE_MEMCPY_HACKS
    146163  uint_t i;
    147164  for (i = 0; i < pv->end; i++)
  • src/spectral/phasevoc.h

    r60fc05b rf264b17  
    3232*/
    3333
    34 #ifndef _AUBIO_PHASEVOC_H
    35 #define _AUBIO_PHASEVOC_H
     34#ifndef AUBIO_PHASEVOC_H
     35#define AUBIO_PHASEVOC_H
    3636
    3737#ifdef __cplusplus
     
    6868
    6969*/
    70 void aubio_pvoc_do(aubio_pvoc_t *pv, fvec_t *in, cvec_t * fftgrain);
     70void aubio_pvoc_do(aubio_pvoc_t *pv, const fvec_t *in, cvec_t * fftgrain);
    7171/** compute signal from spectral frame
    7272
     
    100100#endif
    101101
    102 #endif /* _AUBIO_PHASEVOC_H */
     102#endif /* AUBIO_PHASEVOC_H */
  • src/spectral/specdesc.c

    r60fc05b rf264b17  
    2727#include "utils/hist.h"
    2828
    29 void aubio_specdesc_energy(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    30 void aubio_specdesc_hfc(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    31 void aubio_specdesc_complex(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    32 void aubio_specdesc_phase(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    33 void aubio_specdesc_specdiff(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    34 void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    35 void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    36 void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset);
    37 
    38 extern void aubio_specdesc_centroid (aubio_specdesc_t * o, cvec_t * spec,
    39     fvec_t * desc);
    40 extern void aubio_specdesc_spread (aubio_specdesc_t * o, cvec_t * spec,
    41     fvec_t * desc);
    42 extern void aubio_specdesc_skewness (aubio_specdesc_t * o, cvec_t * spec,
    43     fvec_t * desc);
    44 extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, cvec_t * spec,
    45     fvec_t * desc);
    46 extern void aubio_specdesc_slope (aubio_specdesc_t * o, cvec_t * spec,
    47     fvec_t * desc);
    48 extern void aubio_specdesc_decrease (aubio_specdesc_t * o, cvec_t * spec,
    49     fvec_t * desc);
    50 extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, cvec_t * spec,
     29void aubio_specdesc_energy(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     30void aubio_specdesc_hfc(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     31void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     32void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     33void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     34void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     35void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     36void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset);
     37
     38extern void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec,
     39    fvec_t * desc);
     40extern void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec,
     41    fvec_t * desc);
     42extern void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec,
     43    fvec_t * desc);
     44extern void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec,
     45    fvec_t * desc);
     46extern void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec,
     47    fvec_t * desc);
     48extern void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec,
     49    fvec_t * desc);
     50extern void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec,
    5151    fvec_t * desc);
    5252
     
    7676  /** Pointer to aubio_specdesc_<type> function */
    7777  void (*funcpointer)(aubio_specdesc_t *o,
    78       cvec_t * fftgrain, fvec_t * onset);
     78      const cvec_t * fftgrain, fvec_t * onset);
    7979  smpl_t threshold;      /**< minimum norm threshold for phase and specdiff */
    8080  fvec_t *oldmag;        /**< previous norm vector */
     
    8888/* Energy based onset detection function */
    8989void aubio_specdesc_energy  (aubio_specdesc_t *o UNUSED,
    90     cvec_t * fftgrain, fvec_t * onset) {
     90    const cvec_t * fftgrain, fvec_t * onset) {
    9191  uint_t j;
    9292  onset->data[0] = 0.;
     
    9898/* High Frequency Content onset detection function */
    9999void aubio_specdesc_hfc(aubio_specdesc_t *o UNUSED,
    100     cvec_t * fftgrain, fvec_t * onset){
     100    const cvec_t * fftgrain, fvec_t * onset){
    101101  uint_t j;
    102102  onset->data[0] = 0.;
     
    108108
    109109/* Complex Domain Method onset detection function */
    110 void aubio_specdesc_complex (aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset) {
     110void aubio_specdesc_complex (aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset) {
    111111  uint_t j;
    112112  uint_t nbins = fftgrain->length;
     
    132132/* Phase Based Method onset detection function */
    133133void aubio_specdesc_phase(aubio_specdesc_t *o,
    134     cvec_t * fftgrain, fvec_t * onset){
     134    const cvec_t * fftgrain, fvec_t * onset){
    135135  uint_t j;
    136136  uint_t nbins = fftgrain->length;
     
    162162/* Spectral difference method onset detection function */
    163163void aubio_specdesc_specdiff(aubio_specdesc_t *o,
    164     cvec_t * fftgrain, fvec_t * onset){
     164    const cvec_t * fftgrain, fvec_t * onset){
    165165  uint_t j;
    166166  uint_t nbins = fftgrain->length;
     
    189189 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
    190190 * negative (1.+) and infinite values (+1.e-10) */
    191 void aubio_specdesc_kl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
     191void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){
    192192  uint_t j;
    193193    onset->data[0] = 0.;
     
    203203 * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
    204204 * negative (1.+) and infinite values (+1.e-10) */
    205 void aubio_specdesc_mkl(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
     205void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){
    206206  uint_t j;
    207207    onset->data[0] = 0.;
     
    214214
    215215/* Spectral flux */
    216 void aubio_specdesc_specflux(aubio_specdesc_t *o, cvec_t * fftgrain, fvec_t * onset){
     216void aubio_specdesc_specflux(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){
    217217  uint_t j;
    218218  onset->data[0] = 0.;
     
    226226/* Generic function pointing to the choosen one */
    227227void
    228 aubio_specdesc_do (aubio_specdesc_t *o, cvec_t * fftgrain,
     228aubio_specdesc_do (aubio_specdesc_t *o, const cvec_t * fftgrain,
    229229    fvec_t * onset) {
    230230  o->funcpointer(o,fftgrain,onset);
     
    235235 */
    236236aubio_specdesc_t *
    237 new_aubio_specdesc (char_t * onset_mode, uint_t size){
     237new_aubio_specdesc (const char_t * onset_mode, uint_t size){
    238238  aubio_specdesc_t * o = AUBIO_NEW(aubio_specdesc_t);
    239239  uint_t rsize = size/2+1;
  • src/spectral/specdesc.h

    r60fc05b rf264b17  
    146146
    147147
    148 #ifndef _AUBIO_SPECDESC_H
    149 #define _AUBIO_SPECDESC_H
     148#ifndef AUBIO_SPECDESC_H
     149#define AUBIO_SPECDESC_H
    150150
    151151#ifdef __cplusplus
     
    165165
    166166*/
    167 void aubio_specdesc_do (aubio_specdesc_t * o, cvec_t * fftgrain,
     167void aubio_specdesc_do (aubio_specdesc_t * o, const cvec_t * fftgrain,
    168168    fvec_t * desc);
    169169
     
    179179
    180180*/
    181 aubio_specdesc_t *new_aubio_specdesc (char_t * method, uint_t buf_size);
     181aubio_specdesc_t *new_aubio_specdesc (const char_t * method, uint_t buf_size);
    182182
    183183/** deletion of a spectral descriptor
     
    192192#endif
    193193
    194 #endif /* _AUBIO_SPECDESC_H */
     194#endif /* AUBIO_SPECDESC_H */
  • src/spectral/statistics.c

    r60fc05b rf264b17  
    2323#include "spectral/specdesc.h"
    2424
    25 void aubio_specdesc_centroid (aubio_specdesc_t * o, cvec_t * spec,
    26     fvec_t * desc);
    27 void aubio_specdesc_spread (aubio_specdesc_t * o, cvec_t * spec,
    28     fvec_t * desc);
    29 void aubio_specdesc_skewness (aubio_specdesc_t * o, cvec_t * spec,
    30     fvec_t * desc);
    31 void aubio_specdesc_kurtosis (aubio_specdesc_t * o, cvec_t * spec,
    32     fvec_t * desc);
    33 void aubio_specdesc_slope (aubio_specdesc_t * o, cvec_t * spec,
    34     fvec_t * desc);
    35 void aubio_specdesc_decrease (aubio_specdesc_t * o, cvec_t * spec,
    36     fvec_t * desc);
    37 void aubio_specdesc_rolloff (aubio_specdesc_t * o, cvec_t * spec,
    38     fvec_t * desc);
    39 
    40 
    41 smpl_t cvec_sum (cvec_t * s);
    42 smpl_t cvec_mean (cvec_t * s);
    43 smpl_t cvec_centroid (cvec_t * s);
    44 smpl_t cvec_moment (cvec_t * s, uint_t moment);
    45 
    46 smpl_t
    47 cvec_sum (cvec_t * s)
     25void aubio_specdesc_centroid (aubio_specdesc_t * o, const cvec_t * spec,
     26    fvec_t * desc);
     27void aubio_specdesc_spread (aubio_specdesc_t * o, const cvec_t * spec,
     28    fvec_t * desc);
     29void aubio_specdesc_skewness (aubio_specdesc_t * o, const cvec_t * spec,
     30    fvec_t * desc);
     31void aubio_specdesc_kurtosis (aubio_specdesc_t * o, const cvec_t * spec,
     32    fvec_t * desc);
     33void aubio_specdesc_slope (aubio_specdesc_t * o, const cvec_t * spec,
     34    fvec_t * desc);
     35void aubio_specdesc_decrease (aubio_specdesc_t * o, const cvec_t * spec,
     36    fvec_t * desc);
     37void aubio_specdesc_rolloff (aubio_specdesc_t * o, const cvec_t * spec,
     38    fvec_t * desc);
     39
     40
     41smpl_t cvec_sum (const cvec_t * s);
     42smpl_t cvec_mean (const cvec_t * s);
     43smpl_t cvec_centroid (const cvec_t * s);
     44smpl_t cvec_moment (const cvec_t * s, uint_t moment);
     45
     46smpl_t
     47cvec_sum (const cvec_t * s)
    4848{
    4949  uint_t j;
     
    5656
    5757smpl_t
    58 cvec_mean (cvec_t * s)
     58cvec_mean (const cvec_t * s)
    5959{
    6060  return cvec_sum (s) / (smpl_t) (s->length);
     
    6262
    6363smpl_t
    64 cvec_centroid (cvec_t * spec)
     64cvec_centroid (const cvec_t * spec)
    6565{
    6666  smpl_t sum = 0., sc = 0.;
     
    7878
    7979smpl_t
    80 cvec_moment (cvec_t * spec, uint_t order)
     80cvec_moment (const cvec_t * spec, uint_t order)
    8181{
    8282  smpl_t sum = 0., centroid = 0., sc = 0.;
     
    9595
    9696void
    97 aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     97aubio_specdesc_centroid (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    9898    fvec_t * desc)
    9999{
     
    102102
    103103void
    104 aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     104aubio_specdesc_spread (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    105105    fvec_t * desc)
    106106{
     
    109109
    110110void
    111 aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     111aubio_specdesc_skewness (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    112112    fvec_t * desc)
    113113{
     
    123123
    124124void
    125 aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     125aubio_specdesc_kurtosis (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    126126    fvec_t * desc)
    127127{
     
    137137
    138138void
    139 aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, cvec_t * spec,
     139aubio_specdesc_slope (aubio_specdesc_t * o UNUSED, const cvec_t * spec,
    140140    fvec_t * desc)
    141141{
     
    165165
    166166void
    167 aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, cvec_t * spec,
     167aubio_specdesc_decrease (aubio_specdesc_t *o UNUSED, const cvec_t * spec,
    168168    fvec_t * desc)
    169169{
     
    183183
    184184void
    185 aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, cvec_t * spec,
     185aubio_specdesc_rolloff (aubio_specdesc_t *o UNUSED, const cvec_t * spec,
    186186    fvec_t *desc)
    187187{
  • src/spectral/tss.c

    r60fc05b rf264b17  
    4141};
    4242
    43 void aubio_tss_do(aubio_tss_t *o, cvec_t * input,
     43void aubio_tss_do(aubio_tss_t *o, const cvec_t * input,
    4444    cvec_t * trans, cvec_t * stead)
    4545{
  • src/spectral/tss.h

    r60fc05b rf264b17  
    3737*/
    3838
    39 #ifndef _AUBIO_TSS_H
    40 #define _AUBIO_TSS_H
     39#ifndef AUBIO_TSS_H
     40#define AUBIO_TSS_H
    4141
    4242#ifdef __cplusplus
     
    7070
    7171*/
    72 void aubio_tss_do (aubio_tss_t * o, cvec_t * input, cvec_t * trans,
     72void aubio_tss_do (aubio_tss_t * o, const cvec_t * input, cvec_t * trans,
    7373    cvec_t * stead);
    7474
     
    101101#endif
    102102
    103 #endif /* _AUBIO_TSS_H */
     103#endif /* AUBIO_TSS_H */
  • src/synth/sampler.c

    r60fc05b rf264b17  
    5656}
    5757
    58 uint_t aubio_sampler_load( aubio_sampler_t * o, char_t * uri )
     58uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri )
    5959{
    6060  if (o->source) del_aubio_source(o->source);
    61   o->uri = uri;
     61
     62  if (o->uri) AUBIO_FREE(o->uri);
     63  o->uri = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX));
     64  strncpy(o->uri, uri, strnlen(uri, PATH_MAX));
     65
    6266  o->source = new_aubio_source(uri, o->samplerate, o->blocksize);
    6367  if (o->source) return 0;
     
    6670}
    6771
    68 void aubio_sampler_do ( aubio_sampler_t * o, fvec_t * input, fvec_t * output)
     72void aubio_sampler_do ( aubio_sampler_t * o, const fvec_t * input, fvec_t * output)
    6973{
    7074  uint_t read = 0, i;
     
    8387}
    8488
    85 void aubio_sampler_do_multi ( aubio_sampler_t * o, fmat_t * input, fmat_t * output)
     89void aubio_sampler_do_multi ( aubio_sampler_t * o, const fmat_t * input, fmat_t * output)
    8690{
    8791  uint_t read = 0, i, j;
     
    104108}
    105109
    106 uint_t aubio_sampler_get_playing ( aubio_sampler_t * o )
     110uint_t aubio_sampler_get_playing ( const aubio_sampler_t * o )
    107111{
    108112  return o->playing;
     
    131135    del_aubio_source(o->source);
    132136  }
     137  if (o->uri) AUBIO_FREE(o->uri);
    133138  del_fvec(o->source_output);
    134139  del_fmat(o->source_output_multi);
  • src/synth/sampler.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_SAMPLER_H
    22 #define _AUBIO_SAMPLER_H
     21#ifndef AUBIO_SAMPLER_H
     22#define AUBIO_SAMPLER_H
    2323
    2424/** \file
     
    6060
    6161*/
    62 uint_t aubio_sampler_load( aubio_sampler_t * o, char_t * uri );
     62uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri );
    6363
    6464/** process sampler function
     
    7474
    7575*/
    76 void aubio_sampler_do ( aubio_sampler_t * o, fvec_t * input, fvec_t * output);
     76void aubio_sampler_do ( aubio_sampler_t * o, const fvec_t * input, fvec_t * output);
    7777
    7878/** process sampler function, multiple channels
     
    8888
    8989*/
    90 void aubio_sampler_do_multi ( aubio_sampler_t * o, fmat_t * input, fmat_t * output);
     90void aubio_sampler_do_multi ( aubio_sampler_t * o, const fmat_t * input, fmat_t * output);
    9191
    9292/** get current playing state
     
    9797
    9898*/
    99 uint_t aubio_sampler_get_playing ( aubio_sampler_t * o );
     99uint_t aubio_sampler_get_playing ( const aubio_sampler_t * o );
    100100
    101101/** set current playing state
     
    138138#endif
    139139
    140 #endif /* _AUBIO_SAMPLER_H */
     140#endif /* AUBIO_SAMPLER_H */
  • src/synth/wavetable.c

    r60fc05b rf264b17  
    6969}
    7070
    71 static smpl_t interp_2(fvec_t *input, smpl_t pos) {
     71static smpl_t interp_2(const fvec_t *input, smpl_t pos) {
    7272  uint_t idx = (uint_t)FLOOR(pos);
    7373  smpl_t frac = pos - (smpl_t)idx;
     
    7777}
    7878
    79 void aubio_wavetable_do ( aubio_wavetable_t * s, fvec_t * input, fvec_t * output)
     79void aubio_wavetable_do ( aubio_wavetable_t * s, const fvec_t * input, fvec_t * output)
    8080{
    8181  uint_t i;
     
    108108}
    109109
    110 void aubio_wavetable_do_multi ( aubio_wavetable_t * s, fmat_t * input, fmat_t * output)
     110void aubio_wavetable_do_multi ( aubio_wavetable_t * s, const fmat_t * input, fmat_t * output)
    111111{
    112112  uint_t i, j;
     
    143143}
    144144
    145 uint_t aubio_wavetable_get_playing ( aubio_wavetable_t * s )
     145uint_t aubio_wavetable_get_playing ( const aubio_wavetable_t * s )
    146146{
    147147  return s->playing;
     
    173173}
    174174
    175 smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * s) {
     175smpl_t aubio_wavetable_get_freq ( const aubio_wavetable_t * s) {
    176176  return aubio_parameter_get_current_value ( s->freq);
    177177}
     
    182182}
    183183
    184 smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * s) {
     184smpl_t aubio_wavetable_get_amp ( const aubio_wavetable_t * s) {
    185185  return aubio_parameter_get_current_value ( s->amp );
    186186}
  • src/synth/wavetable.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_WAVETABLE_H
    22 #define _AUBIO_WAVETABLE_H
     21#ifndef AUBIO_WAVETABLE_H
     22#define AUBIO_WAVETABLE_H
    2323
    2424/** \file
     
    6060
    6161*/
    62 uint_t aubio_wavetable_load( aubio_wavetable_t * o, char_t * uri );
     62uint_t aubio_wavetable_load( aubio_wavetable_t * o, const char_t * uri );
    6363
    6464/** process wavetable function
     
    7474
    7575*/
    76 void aubio_wavetable_do ( aubio_wavetable_t * o, fvec_t * input, fvec_t * output);
     76void aubio_wavetable_do ( aubio_wavetable_t * o, const fvec_t * input, fvec_t * output);
    7777
    7878/** process wavetable function, multiple channels
     
    8888
    8989*/
    90 void aubio_wavetable_do_multi ( aubio_wavetable_t * o, fmat_t * input, fmat_t * output);
     90void aubio_wavetable_do_multi ( aubio_wavetable_t * o, const fmat_t * input, fmat_t * output);
    9191
    9292/** get current playing state
     
    9797
    9898*/
    99 uint_t aubio_wavetable_get_playing ( aubio_wavetable_t * o );
     99uint_t aubio_wavetable_get_playing ( const aubio_wavetable_t * o );
    100100
    101101/** set current playing state
     
    144144
    145145*/
    146 smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * o);
     146smpl_t aubio_wavetable_get_freq ( const aubio_wavetable_t * o);
    147147
    148148/** set wavetable amplitude
     
    163163
    164164*/
    165 smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * o);
     165smpl_t aubio_wavetable_get_amp ( const aubio_wavetable_t * o);
    166166
    167167/** destroy aubio_wavetable_t object
     
    176176#endif
    177177
    178 #endif /* _AUBIO_WAVETABLE_H */
     178#endif /* AUBIO_WAVETABLE_H */
  • src/tempo/beattracking.c

    r60fc05b rf264b17  
    124124
    125125void
    126 aubio_beattracking_do (aubio_beattracking_t * bt, fvec_t * dfframe,
     126aubio_beattracking_do (aubio_beattracking_t * bt, const fvec_t * dfframe,
    127127    fvec_t * output)
    128128{
     
    410410
    411411smpl_t
    412 aubio_beattracking_get_bpm (aubio_beattracking_t * bt)
     412aubio_beattracking_get_period (const aubio_beattracking_t * bt)
     413{
     414  return bt->hop_size * bt->bp;
     415}
     416
     417smpl_t
     418aubio_beattracking_get_period_s (const aubio_beattracking_t * bt)
     419{
     420  return aubio_beattracking_get_period(bt) / (smpl_t) bt->samplerate;
     421}
     422
     423smpl_t
     424aubio_beattracking_get_bpm (const aubio_beattracking_t * bt)
    413425{
    414426  if (bt->bp != 0) {
    415     return 60. * bt->samplerate/ bt->bp / bt->hop_size;
     427    return 60. / aubio_beattracking_get_period_s(bt);
    416428  } else {
    417429    return 0.;
     
    420432
    421433smpl_t
    422 aubio_beattracking_get_confidence (aubio_beattracking_t * bt)
     434aubio_beattracking_get_confidence (const aubio_beattracking_t * bt)
    423435{
    424436  if (bt->gp) {
  • src/tempo/beattracking.h

    r60fc05b rf264b17  
    3737
    3838*/
    39 #ifndef _AUBIO_BEATTRACKING_H
    40 #define _AUBIO_BEATTRACKING_H
     39#ifndef AUBIO_BEATTRACKING_H
     40#define AUBIO_BEATTRACKING_H
    4141
    4242#ifdef __cplusplus
     
    6565
    6666*/
    67 void aubio_beattracking_do (aubio_beattracking_t * bt, fvec_t * dfframes,
     67void aubio_beattracking_do (aubio_beattracking_t * bt, const fvec_t * dfframes,
    6868    fvec_t * out);
     69
     70/** get current beat period in samples
     71
     72  \param bt beat tracking object
     73
     74  Returns the currently observed period, in samples, or 0 if no consistent
     75  value is found.
     76
     77*/
     78smpl_t aubio_beattracking_get_period (const aubio_beattracking_t * bt);
     79
     80/** get current beat period in seconds
     81
     82  \param bt beat tracking object
     83
     84  Returns the currently observed period, in seconds, or 0 if no consistent
     85  value is found.
     86
     87*/
     88smpl_t aubio_beattracking_get_period_s (const aubio_beattracking_t * bt);
    6989
    7090/** get current tempo in bpm
     
    7696
    7797*/
    78 smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt);
     98smpl_t aubio_beattracking_get_bpm(const aubio_beattracking_t * bt);
    7999
    80100/** get current tempo confidence
     
    86106
    87107*/
    88 smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * bt);
     108smpl_t aubio_beattracking_get_confidence(const aubio_beattracking_t * bt);
    89109
    90110/** delete beat tracking object
     
    99119#endif
    100120
    101 #endif /* _AUBIO_BEATTRACKING_H */
     121#endif /* AUBIO_BEATTRACKING_H */
  • src/tempo/tempo.c

    r60fc05b rf264b17  
    2828#include "mathutils.h"
    2929#include "tempo/tempo.h"
    30 
    31 // TODO implement get/set_delay
    32 
    33 /** set current delay
    34 
    35   \param o beat tracking object
    36 
    37   \return current delay, in samples
    38 
    39  */
    40 uint_t aubio_tempo_get_delay(aubio_tempo_t * o);
    41 
    42 /** set current delay
    43 
    44   \param o beat tracking object
    45   \param delay delay to set tempo to, in samples
    46 
    47   \return `0` if successful, non-zero otherwise
    48 
    49  */
    50 uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay);
    5130
    5231/* structure to store object state */
     
    6544  sint_t blockpos;               /** current position in dfframe */
    6645  uint_t winlen;                 /** dfframe bufsize */
    67   uint_t step;                   /** dfframe hopsize */ 
    68   uint_t samplerate;             /** sampling rate of the signal */ 
     46  uint_t step;                   /** dfframe hopsize */
     47  uint_t samplerate;             /** sampling rate of the signal */
    6948  uint_t hop_size;               /** get hop_size */
    7049  uint_t total_frames;           /** total frames since beginning */
    7150  uint_t last_beat;              /** time of latest detected beat, in samples */
    72   uint_t delay;                  /** delay to remove to last beat, in samples */
     51  sint_t delay;                  /** delay to remove to last beat, in samples */
     52  uint_t last_tatum;             /** time of latest detected tatum, in samples */
     53  uint_t tatum_signature;        /** number of tatum between each beats */
    7354};
    7455
    7556/* execute tempo detection function on iput buffer */
    76 void aubio_tempo_do(aubio_tempo_t *o, fvec_t * input, fvec_t * tempo)
     57void aubio_tempo_do(aubio_tempo_t *o, const fvec_t * input, fvec_t * tempo)
    7758{
    7859  uint_t i;
     
    9172    aubio_beattracking_do(o->bt,o->dfframe,o->out);
    9273    /* rotate dfframe */
    93     for (i = 0 ; i < winlen - step; i++ ) 
     74    for (i = 0 ; i < winlen - step; i++ )
    9475      o->dfframe->data[i] = o->dfframe->data[i+step];
    95     for (i = winlen - step ; i < winlen; i++ ) 
     76    for (i = winlen - step ; i < winlen; i++ )
    9677      o->dfframe->data[i] = 0.;
    9778    o->blockpos = -1;
     
    9980  o->blockpos++;
    10081  aubio_peakpicker_do (o->pp, o->of, o->onset);
    101   tempo->data[1] = o->onset->data[0];
     82  // store onset detection function in second sample of vector
     83  //tempo->data[1] = o->onset->data[0];
    10284  thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    10385  o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0];
    10486  /* end of second level loop */
    10587  tempo->data[0] = 0; /* reset tactus */
    106   i=0;
     88  //i=0;
    10789  for (i = 1; i < o->out->data[0]; i++ ) {
    10890    /* if current frame is a predicted tactus */
     
    11496      }
    11597      o->last_beat = o->total_frames + (uint_t)ROUND(tempo->data[0] * o->hop_size);
     98      o->last_tatum = o->last_beat;
    11699    }
    117100  }
     
    122105uint_t aubio_tempo_get_last (aubio_tempo_t *o)
    123106{
    124   return o->last_beat - o->delay;
     107  return o->last_beat + o->delay;
    125108}
    126109
     
    135118}
    136119
    137 uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay) {
     120uint_t aubio_tempo_set_delay(aubio_tempo_t * o, sint_t delay) {
    138121  o->delay = delay;
     122  return AUBIO_OK;
     123}
     124
     125uint_t aubio_tempo_set_delay_s(aubio_tempo_t * o, smpl_t delay) {
     126  o->delay = delay * o->samplerate;
     127  return AUBIO_OK;
     128}
     129
     130uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay) {
     131  o->delay = 1000. * delay * o->samplerate;
    139132  return AUBIO_OK;
    140133}
     
    142135uint_t aubio_tempo_get_delay(aubio_tempo_t * o) {
    143136  return o->delay;
     137}
     138
     139smpl_t aubio_tempo_get_delay_s(aubio_tempo_t * o) {
     140  return o->delay / (smpl_t)(o->samplerate);
     141}
     142
     143smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o) {
     144  return o->delay / (smpl_t)(o->samplerate) / 1000.;
    144145}
    145146
     
    164165
    165166/* Allocate memory for an tempo detection */
    166 aubio_tempo_t * new_aubio_tempo (char_t * tempo_mode,
     167aubio_tempo_t * new_aubio_tempo (const char_t * tempo_mode,
    167168    uint_t buf_size, uint_t hop_size, uint_t samplerate)
    168169{
     
    174175    AUBIO_ERR("tempo: got hop size %d, but can not be < 1\n", hop_size);
    175176    goto beach;
    176   } else if ((sint_t)buf_size < 1) {
    177     AUBIO_ERR("tempo: got window size %d, but can not be < 1\n", buf_size);
     177  } else if ((sint_t)buf_size < 2) {
     178    AUBIO_ERR("tempo: got window size %d, but can not be < 2\n", buf_size);
    178179    goto beach;
    179180  } else if (buf_size < hop_size) {
     
    215216    onset2 = new_fvec(1);
    216217  }*/
     218  o->last_tatum = 0;
     219  o->tatum_signature = 4;
    217220  return o;
    218221
     
    226229}
    227230
     231smpl_t aubio_tempo_get_period (aubio_tempo_t *o)
     232{
     233  return aubio_beattracking_get_period (o->bt);
     234}
     235
     236smpl_t aubio_tempo_get_period_s (aubio_tempo_t *o)
     237{
     238  return aubio_beattracking_get_period_s (o->bt);
     239}
     240
    228241smpl_t aubio_tempo_get_confidence(aubio_tempo_t *o) {
    229242  return aubio_beattracking_get_confidence(o->bt);
     243}
     244
     245uint_t aubio_tempo_was_tatum (aubio_tempo_t *o)
     246{
     247  uint_t last_tatum_distance = o->total_frames - o->last_tatum;
     248  smpl_t beat_period = aubio_tempo_get_period(o);
     249  smpl_t tatum_period = beat_period / o->tatum_signature;
     250  if (last_tatum_distance < o->hop_size) {
     251    o->last_tatum = o->last_beat;
     252    return 2;
     253  }
     254  else if (last_tatum_distance > tatum_period) {
     255    if ( last_tatum_distance + o->hop_size > beat_period ) {
     256      // next beat is too close, pass
     257      return 0;
     258    }
     259    o->last_tatum = o->total_frames;
     260    return 1;
     261  }
     262  return 0;
     263}
     264
     265smpl_t aubio_tempo_get_last_tatum (aubio_tempo_t *o) {
     266  return (smpl_t)o->last_tatum - o->delay;
     267}
     268
     269uint_t aubio_tempo_set_tatum_signature (aubio_tempo_t *o, uint_t signature) {
     270  if (signature < 1 || signature > 64) {
     271    return AUBIO_FAIL;
     272  } else {
     273    o->tatum_signature = signature;
     274    return AUBIO_OK;
     275  }
    230276}
    231277
  • src/tempo/tempo.h

    r60fc05b rf264b17  
    3131*/
    3232
    33 #ifndef _AUBIO_TEMPO_H
    34 #define _AUBIO_TEMPO_H
     33#ifndef AUBIO_TEMPO_H
     34#define AUBIO_TEMPO_H
    3535
    3636#ifdef __cplusplus
     
    5151
    5252*/
    53 aubio_tempo_t * new_aubio_tempo (char_t * method,
     53aubio_tempo_t * new_aubio_tempo (const char_t * method,
    5454    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    5555
     
    6161
    6262*/
    63 void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo);
     63void aubio_tempo_do (aubio_tempo_t *o, const fvec_t * input, fvec_t * tempo);
    6464
    6565/** get the time of the latest beat detected, in samples
     
    121121*/
    122122smpl_t aubio_tempo_get_threshold(aubio_tempo_t * o);
     123
     124/** get current beat period in samples
     125
     126  \param bt beat tracking object
     127
     128  Returns the currently observed period, in samples, or 0 if no consistent
     129  value is found.
     130
     131*/
     132smpl_t aubio_tempo_get_period (aubio_tempo_t * bt);
     133
     134/** get current beat period in seconds
     135
     136  \param bt beat tracking object
     137
     138  Returns the currently observed period, in seconds, or 0 if no consistent
     139  value is found.
     140
     141*/
     142smpl_t aubio_tempo_get_period_s (aubio_tempo_t * bt);
    123143
    124144/** get current tempo
     
    140160*/
    141161smpl_t aubio_tempo_get_confidence(aubio_tempo_t * o);
     162
     163/* set number of tatum per beat
     164
     165   \param o beat tracking object
     166   \param signature number of tatum per beat (between 1 and 64)
     167
     168*/
     169uint_t aubio_tempo_set_tatum_signature(aubio_tempo_t *o, uint_t signature);
     170
     171/* check whether a tatum was detected in the current frame
     172
     173   \param o beat tracking object
     174
     175   \return 2 if a beat was detected, 1 if a tatum was detected, 0 otherwise
     176
     177*/
     178uint_t aubio_tempo_was_tatum(aubio_tempo_t *o);
     179
     180/* get position of last_tatum, in samples
     181
     182   \param o beat tracking object
     183
     184*/
     185smpl_t aubio_tempo_get_last_tatum(aubio_tempo_t *o);
     186
     187/** get current delay
     188
     189  \param o beat tracking object
     190
     191  \return current delay, in samples
     192
     193 */
     194uint_t aubio_tempo_get_delay(aubio_tempo_t * o);
     195
     196/** get current delay in seconds
     197
     198  \param o beat tracking object
     199
     200  \return current delay, in seconds
     201
     202 */
     203smpl_t aubio_tempo_get_delay_s(aubio_tempo_t * o);
     204
     205/** get current delay in ms
     206
     207  \param o beat tracking object
     208
     209  \return current delay, in milliseconds
     210
     211 */
     212smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o);
     213
     214/** set current delay
     215
     216  \param o beat tracking object
     217  \param delay delay to set tempo to, in samples
     218
     219  \return `0` if successful, non-zero otherwise
     220
     221 */
     222uint_t aubio_tempo_set_delay(aubio_tempo_t * o, sint_t delay);
     223
     224/** set current delay in seconds
     225
     226  \param o beat tracking object
     227  \param delay delay to set tempo to, in seconds
     228
     229  \return `0` if successful, non-zero otherwise
     230
     231 */
     232uint_t aubio_tempo_set_delay_s(aubio_tempo_t * o, smpl_t delay);
     233
     234/** set current delay
     235
     236  \param o beat tracking object
     237  \param delay delay to set tempo to, in samples
     238
     239  \return `0` if successful, non-zero otherwise
     240
     241 */
     242uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay);
    142243
    143244/** delete tempo detection object
     
    152253#endif
    153254
    154 #endif /* _AUBIO_TEMPO_H */
     255#endif /* AUBIO_TEMPO_H */
  • src/temporal/a_weighting.c

    r60fc05b rf264b17  
    3030{
    3131  uint_t order; lsmp_t *a, *b; lvec_t *as, *bs;
     32
     33  if ((sint_t)samplerate <= 0) {
     34    AUBIO_ERROR("aubio_filter: failed setting A-weighting with samplerate %d\n", samplerate);
     35    return AUBIO_FAIL;
     36  }
     37  if (f == NULL) {
     38    AUBIO_ERROR("aubio_filter: failed setting A-weighting with filter NULL\n");
     39    return AUBIO_FAIL;
     40  }
     41
     42  order = aubio_filter_get_order (f);
     43  if (order != 7) {
     44    AUBIO_ERROR ("aubio_filter: order of A-weighting filter must be 7, not %d\n", order);
     45    return 1;
     46  }
     47
    3248  aubio_filter_set_samplerate (f, samplerate);
    3349  bs = aubio_filter_get_feedforward (f);
    3450  as = aubio_filter_get_feedback (f);
    3551  b = bs->data, a = as->data;
    36   order = aubio_filter_get_order (f);
    37 
    38   if (order != 7) {
    39     AUBIO_ERROR ("order of A-weighting filter must be 7, not %d\n", order);
    40     return 1;
    41   }
    4252
    4353  /* select coefficients according to sampling frequency */
     
    245255{
    246256  aubio_filter_t *f = new_aubio_filter (7);
    247   aubio_filter_set_a_weighting (f, samplerate);
     257  if (aubio_filter_set_a_weighting(f,samplerate) != AUBIO_OK) {
     258    del_aubio_filter(f);
     259    return NULL;
     260  }
    248261  return f;
    249262}
  • src/temporal/a_weighting.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_FILTER_A_DESIGN_H
    22 #define _AUBIO_FILTER_A_DESIGN_H
     21#ifndef AUBIO_FILTER_A_DESIGN_H
     22#define AUBIO_FILTER_A_DESIGN_H
    2323
    2424/** \file
     
    8686#endif
    8787
    88 #endif /* _AUBIO_FILTER_A_DESIGN_H */
     88#endif /* AUBIO_FILTER_A_DESIGN_H */
  • src/temporal/biquad.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_FILTER_BIQUAD_H
    22 #define _AUBIO_FILTER_BIQUAD_H
     21#ifndef AUBIO_FILTER_BIQUAD_H
     22#define AUBIO_FILTER_BIQUAD_H
    2323
    2424/** \file
     
    7373#endif
    7474
    75 #endif /* _AUBIO_FILTER_BIQUAD_H */
     75#endif /* AUBIO_FILTER_BIQUAD_H */
  • src/temporal/c_weighting.c

    r60fc05b rf264b17  
    3030{
    3131  uint_t order; lsmp_t *a, *b; lvec_t *as, *bs;
     32
     33  if ((sint_t)samplerate <= 0) {
     34    AUBIO_ERROR("aubio_filter: failed setting C-weighting with samplerate %d\n", samplerate);
     35    return AUBIO_FAIL;
     36  }
     37  if (f == NULL) {
     38    AUBIO_ERROR("aubio_filter: failed setting C-weighting with filter NULL\n");
     39    return AUBIO_FAIL;
     40  }
     41
     42  order = aubio_filter_get_order (f);
     43  if ( order != 5 ) {
     44    AUBIO_ERROR ("aubio_filter: order of C-weighting filter must be 5, not %d\n", order);
     45    return 1;
     46  }
     47
    3248  aubio_filter_set_samplerate (f, samplerate);
    3349  bs = aubio_filter_get_feedforward (f);
    3450  as = aubio_filter_get_feedback (f);
    3551  b = bs->data, a = as->data;
    36   order = aubio_filter_get_order (f);
    37 
    38   if ( order != 5 ) {
    39     AUBIO_ERROR ("order of C-weighting filter must be 5, not %d\n", order);
    40     return 1;
    41   }
    4252
    4353  /* select coefficients according to sampling frequency */
     
    200210aubio_filter_t * new_aubio_filter_c_weighting (uint_t samplerate) {
    201211  aubio_filter_t * f = new_aubio_filter(5);
    202   aubio_filter_set_c_weighting (f, samplerate);
     212  if (aubio_filter_set_c_weighting(f,samplerate) != AUBIO_OK) {
     213    del_aubio_filter(f);
     214    return NULL;
     215  }
    203216  return f;
    204217}
    205 
  • src/temporal/c_weighting.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_FILTER_C_DESIGN_H
    22 #define _AUBIO_FILTER_C_DESIGN_H
     21#ifndef AUBIO_FILTER_C_DESIGN_H
     22#define AUBIO_FILTER_C_DESIGN_H
    2323
    2424/** \file
     
    8686#endif
    8787
    88 #endif /* _AUBIO_FILTER_C_DESIGN_H */
     88#endif /* AUBIO_FILTER_C_DESIGN_H */
  • src/temporal/filter.c

    r60fc05b rf264b17  
    4040
    4141void
    42 aubio_filter_do_outplace (aubio_filter_t * f, fvec_t * in, fvec_t * out)
     42aubio_filter_do_outplace (aubio_filter_t * f, const fvec_t * in, fvec_t * out)
    4343{
    4444  fvec_copy (in, out);
     
    9494
    9595lvec_t *
    96 aubio_filter_get_feedback (aubio_filter_t * f)
     96aubio_filter_get_feedback (const aubio_filter_t * f)
    9797{
    9898  return f->a;
     
    100100
    101101lvec_t *
    102 aubio_filter_get_feedforward (aubio_filter_t * f)
     102aubio_filter_get_feedforward (const aubio_filter_t * f)
    103103{
    104104  return f->b;
     
    106106
    107107uint_t
    108 aubio_filter_get_order (aubio_filter_t * f)
     108aubio_filter_get_order (const aubio_filter_t * f)
    109109{
    110110  return f->order;
     
    112112
    113113uint_t
    114 aubio_filter_get_samplerate (aubio_filter_t * f)
     114aubio_filter_get_samplerate (const aubio_filter_t * f)
    115115{
    116116  return f->samplerate;
     
    135135{
    136136  aubio_filter_t *f = AUBIO_NEW (aubio_filter_t);
     137  if ((sint_t)order < 1) {
     138    AUBIO_FREE(f);
     139    return NULL;
     140  }
    137141  f->x = new_lvec (order);
    138142  f->y = new_lvec (order);
     
    143147  f->order = order;
    144148  /* set default to identity */
    145   f->a->data[1] = 1.;
     149  f->a->data[0] = 1.;
     150  f->b->data[0] = 1.;
    146151  return f;
    147152}
  • src/temporal/filter.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_FILTER_H
    22 #define _AUBIO_FILTER_H
     21#ifndef AUBIO_FILTER_H
     22#define AUBIO_FILTER_H
    2323
    2424/** \file
     
    8787
    8888*/
    89 void aubio_filter_do_outplace (aubio_filter_t * f, fvec_t * in, fvec_t * out);
     89void aubio_filter_do_outplace (aubio_filter_t * f, const fvec_t * in, fvec_t * out);
    9090
    9191/** filter input vector forward and backward
     
    105105
    106106*/
    107 lvec_t *aubio_filter_get_feedback (aubio_filter_t * f);
     107lvec_t *aubio_filter_get_feedback (const aubio_filter_t * f);
    108108
    109109/** returns a pointer to feedforward coefficients \f$ b_i \f$
     
    114114
    115115*/
    116 lvec_t *aubio_filter_get_feedforward (aubio_filter_t * f);
     116lvec_t *aubio_filter_get_feedforward (const aubio_filter_t * f);
    117117
    118118/** get order of the filter
     
    123123
    124124*/
    125 uint_t aubio_filter_get_order (aubio_filter_t * f);
     125uint_t aubio_filter_get_order (const aubio_filter_t * f);
    126126
    127127/** get sampling rate of the filter
     
    132132
    133133*/
    134 uint_t aubio_filter_get_samplerate (aubio_filter_t * f);
     134uint_t aubio_filter_get_samplerate (const aubio_filter_t * f);
    135135
    136136/** get sampling rate of the filter
     
    174174#endif
    175175
    176 #endif /* _AUBIO_FILTER_H */
     176#endif /* AUBIO_FILTER_H */
  • src/temporal/resampler.c

    r60fc05b rf264b17  
    2525#include "temporal/resampler.h"
    2626
    27 #if HAVE_SAMPLERATE
     27#ifdef HAVE_SAMPLERATE
    2828
    2929#include <samplerate.h>         /* from libsamplerate */
     
    6262
    6363void
    64 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)
     64aubio_resampler_do (aubio_resampler_t * s, const fvec_t * input, fvec_t * output)
    6565{
    6666  s->proc->input_frames = input->length;
     
    9393
    9494void
    95 aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED)
     95aubio_resampler_do (aubio_resampler_t * s UNUSED, const fvec_t * input UNUSED, fvec_t * output UNUSED)
    9696{
    9797}
  • src/temporal/resampler.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_RESAMPLER_H
    22 #define _AUBIO_RESAMPLER_H
     21#ifndef AUBIO_RESAMPLER_H
     22#define AUBIO_RESAMPLER_H
    2323
    2424/** \file
     
    5656
    5757*/
    58 void aubio_resampler_do (aubio_resampler_t * s, fvec_t * input,
     58void aubio_resampler_do (aubio_resampler_t * s, const fvec_t * input,
    5959    fvec_t * output);
    6060
     
    6363#endif
    6464
    65 #endif /* _AUBIO_RESAMPLER_H */
     65#endif /* AUBIO_RESAMPLER_H */
  • src/types.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO__TYPES_H
    22 #define _AUBIO__TYPES_H
     21#ifndef AUBIO_TYPES_H
     22#define AUBIO_TYPES_H
    2323
    2424/** \file
     
    6868#endif
    6969
    70 #endif /* _AUBIO__TYPES_H */
     70#endif /* AUBIO_TYPES_H */
  • src/utils/hist.c

    r60fc05b rf264b17  
    138138}
    139139
    140 smpl_t aubio_hist_mean (aubio_hist_t *s) {
     140smpl_t aubio_hist_mean (const aubio_hist_t *s) {
    141141  uint_t j;
    142142  smpl_t tmp = 0.0;
  • src/utils/hist.h

    r60fc05b rf264b17  
    2626 */
    2727
    28 #ifndef _AUBIO_HIST_H
    29 #define _AUBIO_HIST_H
     28#ifndef AUBIO_HIST_H
     29#define AUBIO_HIST_H
    3030
    3131#ifdef __cplusplus
     
    5151void aubio_hist_do_notnull(aubio_hist_t *s, fvec_t * input);
    5252/** compute the mean of the histogram */
    53 smpl_t aubio_hist_mean(aubio_hist_t *s);
     53smpl_t aubio_hist_mean(const aubio_hist_t *s);
    5454/** weight the histogram */
    5555void aubio_hist_weight(aubio_hist_t *s);
     
    6161#endif
    6262
    63 #endif /* _AUBIO_HIST_H */
     63#endif /* AUBIO_HIST_H */
  • src/utils/parameter.c

    r60fc05b rf264b17  
    8585}
    8686
    87 smpl_t aubio_parameter_get_current_value ( aubio_parameter_t * s )
     87smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * s )
    8888{
    8989  return s->current_value;
     
    110110}
    111111
    112 uint_t aubio_parameter_get_steps ( aubio_parameter_t * param )
     112uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param )
    113113{
    114114  return param->steps;
     
    121121}
    122122
    123 smpl_t aubio_parameter_get_min_value ( aubio_parameter_t * param )
     123smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param )
    124124{
    125125  return param->min_value;
     
    132132}
    133133
    134 smpl_t aubio_parameter_get_max_value ( aubio_parameter_t * param )
     134smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param )
    135135{
    136136  return param->max_value;
  • src/utils/parameter.h

    r60fc05b rf264b17  
    1919*/
    2020
    21 #ifndef _AUBIO_PARAMETER_H
    22 #define _AUBIO_PARAMETER_H
     21#ifndef AUBIO_PARAMETER_H
     22#define AUBIO_PARAMETER_H
    2323
    2424/** \file
     
    7777
    7878*/
    79 smpl_t aubio_parameter_get_current_value ( aubio_parameter_t * param );
     79smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * param );
    8080
    8181/** set current parameter value, skipping interpolation
     
    106106
    107107*/
    108 uint_t aubio_parameter_get_steps ( aubio_parameter_t * param);
     108uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param);
    109109
    110110/** set minimum value of this parameter
     
    125125
    126126*/
    127 smpl_t aubio_parameter_get_min_value ( aubio_parameter_t * param );
     127smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param );
    128128
    129129/** set maximum value of this parameter
     
    144144
    145145*/
    146 smpl_t aubio_parameter_get_max_value ( aubio_parameter_t * param );
     146smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param );
    147147
    148148/** destroy ::aubio_parameter_t object
     
    157157#endif
    158158
    159 #endif /* _AUBIO_PARAMETER_H */
     159#endif /* AUBIO_PARAMETER_H */
  • src/utils/scale.c

    r60fc05b rf264b17  
    3838};
    3939
    40 aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig, 
     40aubio_scale_t * new_aubio_scale (smpl_t ilow, smpl_t ihig,
    4141    smpl_t olow, smpl_t ohig) {
    4242  aubio_scale_t * s = AUBIO_NEW(aubio_scale_t);
  • src/utils/scale.h

    r60fc05b rf264b17  
    2929
    3030*/
    31 #ifndef _AUBIO_SCALE_H
    32 #define _AUBIO_SCALE_H
     31#ifndef AUBIO_SCALE_H
     32#define AUBIO_SCALE_H
    3333
    3434#ifdef __cplusplus
     
    7878#endif
    7979
    80 #endif /* _AUBIO_SCALE_H */
     80#endif /* AUBIO_SCALE_H */
  • src/vecutils.h

    r60fc05b rf264b17  
    2525 */
    2626
    27 #ifndef _AUBIO__VECUTILS_H
    28 #define _AUBIO__VECUTILS_H
     27#ifndef AUBIO_VECUTILS_H
     28#define AUBIO_VECUTILS_H
    2929
    3030#ifdef __cplusplus
     
    114114#endif
    115115
    116 #endif /* _AUBIO__VECUTILS_H */
     116#endif /* AUBIO_VECUTILS_H */
  • src/wscript_build

    r60fc05b rf264b17  
    22
    33uselib = []
     4uselib += ['M']
    45uselib += ['FFTW3', 'FFTW3F']
    56uselib += ['SAMPLERATE']
     
    910uselib += ['AVRESAMPLE']
    1011uselib += ['AVUTIL']
     12uselib += ['BLAS']
    1113
    12 # build each source files
    1314source = ctx.path.ant_glob('*.c **/*.c')
     15
    1416ctx(features = 'c',
    1517        source = source,
    1618        includes = ['.'],
    17         uselib = uselib,
    18         lib = 'm',
     19        use = uselib,
    1920        target = 'lib_objects')
    2021
     
    2324    build_features = ['cstlib', 'cshlib']
    2425elif ctx.env['DEST_OS'] in ['win32', 'win64']:
    25     build_features = ['cshlib']
     26    build_features = ['cstlib', 'cshlib']
     27elif ctx.env['DEST_OS'] in ['emscripten']:
     28    build_features = ['cstlib']
    2629else: #linux, darwin, android, mingw, ...
    27     build_features = ['cshlib', 'cstlib']
     30    build_features = ['cstlib', 'cshlib']
    2831
    2932for target in build_features:
    3033    ctx(features = 'c ' + target,
    31             use = ['lib_objects'],
    32             uselib = uselib,
    33             lib = 'm',
     34            use = uselib + ['lib_objects'],
    3435            target = 'aubio',
    3536            vnum = ctx.env['LIB_VERSION'])
Note: See TracChangeset for help on using the changeset viewer.