Changeset 155cc10 for src


Ignore:
Timestamp:
Mar 10, 2017, 2:26:32 PM (8 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/applefworks, fix/ffmpeg5, master, sampler
Children:
ee8a57c
Parents:
00d0275 (diff), 67b6618 (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 awhitening

Location:
src
Files:
7 added
96 edited

Legend:

Unmodified
Added
Removed
  • src/aubio.h

    r00d0275 r155cc10  
    112112  directories of the source tree.
    113113
     114  Some examples:
     115  - @ref spectral/test-fft.c
     116  - @ref spectral/test-phasevoc.c
     117  - @ref onset/test-onset.c
     118  - @ref pitch/test-pitch.c
     119  - @ref tempo/test-tempo.c
     120  - @ref test-fvec.c
     121  - @ref test-cvec.c
     122
    114123  \subsection unstable_api Unstable API
    115124
     
    131140
    132141  Latest versions, further documentation, examples, wiki, and mailing lists can
    133   be found at http://aubio.org .
     142  be found at https://aubio.org .
    134143
    135144 */
     
    184193#include "onset/onset.h"
    185194#include "tempo/tempo.h"
     195#include "notes/notes.h"
    186196#include "io/source.h"
    187197#include "io/sink.h"
     
    189199#include "synth/wavetable.h"
    190200#include "utils/parameter.h"
     201#include "utils/log.h"
    191202
    192203#if AUBIO_UNSTABLE
  • src/aubio_priv.h

    r00d0275 r155cc10  
    2525 */
    2626
    27 #ifndef _AUBIO__PRIV_H
    28 #define _AUBIO__PRIV_H
     27#ifndef AUBIO_PRIV_H
     28#define AUBIO_PRIV_H
    2929
    3030/*********************
     
    3434 */
    3535
     36#ifdef HAVE_CONFIG_H
    3637#include "config.h"
    37 
    38 #if HAVE_STDLIB_H
     38#endif
     39
     40#ifdef HAVE_STDLIB_H
    3941#include <stdlib.h>
    4042#endif
    4143
    42 #if HAVE_STDIO_H
     44#ifdef HAVE_STDIO_H
    4345#include <stdio.h>
    4446#endif
     
    6567#endif
    6668
     69#ifdef HAVE_STDARG_H
     70#include <stdarg.h>
     71#endif
     72
    6773#ifdef HAVE_ACCELERATE
    6874#define HAVE_ATLAS 1
    6975#include <Accelerate/Accelerate.h>
    70 #elif HAVE_ATLAS_CBLAS_H
     76#elif defined(HAVE_ATLAS_CBLAS_H)
    7177#define HAVE_ATLAS 1
    7278#include <atlas/cblas.h>
     
    7783#ifdef HAVE_ACCELERATE
    7884#include <Accelerate/Accelerate.h>
    79 #if !HAVE_AUBIO_DOUBLE
     85#ifndef HAVE_AUBIO_DOUBLE
    8086#define aubio_vDSP_mmov       vDSP_mmov
    8187#define aubio_vDSP_vmul       vDSP_vmul
     
    8793#define aubio_vDSP_minv       vDSP_minv
    8894#define aubio_vDSP_minvi      vDSP_minvi
     95#define aubio_vDSP_dotpr      vDSP_dotpr
    8996#else /* HAVE_AUBIO_DOUBLE */
    9097#define aubio_vDSP_mmov       vDSP_mmovD
     
    97104#define aubio_vDSP_minv       vDSP_minvD
    98105#define aubio_vDSP_minvi      vDSP_minviD
     106#define aubio_vDSP_dotpr      vDSP_dotprD
    99107#endif /* HAVE_AUBIO_DOUBLE */
    100108#endif /* HAVE_ACCELERATE */
    101109
    102110#ifdef HAVE_ATLAS
    103 #if !HAVE_AUBIO_DOUBLE
     111#ifndef HAVE_AUBIO_DOUBLE
    104112#define aubio_catlas_set      catlas_sset
    105113#define aubio_cblas_copy      cblas_scopy
     
    167175} aubio_status;
    168176
     177/* Logging */
     178
     179#include "utils/log.h"
     180
     181/** internal logging function, defined in utils/log.c */
     182uint_t aubio_log(sint_t level, const char_t *fmt, ...);
     183
    169184#ifdef HAVE_C99_VARARGS_MACROS
    170 #define AUBIO_ERR(...)               fprintf(stderr, "AUBIO ERROR: " __VA_ARGS__)
    171 #define AUBIO_MSG(...)               fprintf(stdout, __VA_ARGS__)
    172 #define AUBIO_DBG(...)               fprintf(stderr, __VA_ARGS__)
    173 #define AUBIO_WRN(...)               fprintf(stderr, "AUBIO WARNING: " __VA_ARGS__)
    174 #else
    175 #define AUBIO_ERR(format, args...)   fprintf(stderr, "AUBIO ERROR: " format , ##args)
    176 #define AUBIO_MSG(format, args...)   fprintf(stdout, format , ##args)
    177 #define AUBIO_DBG(format, args...)   fprintf(stderr, format , ##args)
    178 #define AUBIO_WRN(format, args...)   fprintf(stderr, "AUBIO WARNING: " format, ##args)
     185#define AUBIO_ERR(...)               aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " __VA_ARGS__)
     186#define AUBIO_INF(...)               aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " __VA_ARGS__)
     187#define AUBIO_MSG(...)               aubio_log(AUBIO_LOG_MSG, __VA_ARGS__)
     188#define AUBIO_DBG(...)               aubio_log(AUBIO_LOG_DBG, __VA_ARGS__)
     189#define AUBIO_WRN(...)               aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " __VA_ARGS__)
     190#else
     191#define AUBIO_ERR(format, args...)   aubio_log(AUBIO_LOG_ERR, "AUBIO ERROR: " format , ##args)
     192#define AUBIO_INF(format, args...)   aubio_log(AUBIO_LOG_INF, "AUBIO INFO: " format , ##args)
     193#define AUBIO_MSG(format, args...)   aubio_log(AUBIO_LOG_MSG, format , ##args)
     194#define AUBIO_DBG(format, args...)   aubio_log(AUBIO_LOG_DBG, format , ##args)
     195#define AUBIO_WRN(format, args...)   aubio_log(AUBIO_LOG_WRN, "AUBIO WARNING: " format, ##args)
    179196#endif
    180197
     
    183200#define AUBIO_QUIT(_s)               exit(_s)
    184201#define AUBIO_SPRINTF                sprintf
     202
     203#define AUBIO_MAX_SAMPLERATE (192000*8)
     204#define AUBIO_MAX_CHANNELS 1024
    185205
    186206/* pi and 2*pi */
     
    191211#endif
    192212#define TWO_PI     (PI*2.)
     213
     214#ifndef PATH_MAX
     215#define PATH_MAX 1024
     216#endif
    193217
    194218/* aliases to math.h functions */
     
    204228#define FLOOR      floorf
    205229#define CEIL       ceilf
     230#define ATAN       atanf
    206231#define ATAN2      atan2f
    207232#else
     
    216241#define FLOOR      floor
    217242#define CEIL       ceil
     243#define ATAN       atan
    218244#define ATAN2      atan2
    219245#endif
     
    249275#endif
    250276
     277/* avoid unresolved symbol with msvc 9 */
     278#if defined(_MSC_VER) && (_MSC_VER < 1900)
     279#define isnan _isnan
     280#endif
     281
    251282/* handy shortcuts */
    252283#define DB2LIN(g) (POW(10.0,(g)*0.05f))
     
    284315#endif
    285316
    286 #endif /* _AUBIO__PRIV_H */
     317/* are we using gcc -std=c99 ? */
     318#if defined(__STRICT_ANSI__)
     319#define strnlen(a,b) MIN(strlen(a),b)
     320#if !HAVE_AUBIO_DOUBLE
     321#define floorf floor
     322#endif
     323#endif /* __STRICT_ANSI__ */
     324
     325#endif /* AUBIO_PRIV_H */
  • src/cvec.c

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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
     
    111111  uint_t i,j;
    112112  for (i=0; i< s->height; i++) {
    113     for (j=0; j< FLOOR(s->length/2); j++) {
     113    for (j=0; j< FLOOR((smpl_t)s->length/2); j++) {
    114114      ELEM_SWAP(s->data[i][j], s->data[i][s->length-1-j]);
    115115    }
     
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    2222#include "fvec.h"
    2323
    24 fvec_t * new_fvec( uint_t length) {
     24fvec_t * new_fvec(uint_t length) {
    2525  fvec_t * s;
    2626  if ((sint_t)length <= 0) {
     
    4242}
    4343
    44 smpl_t fvec_get_sample(fvec_t *s, uint_t position) {
     44smpl_t fvec_get_sample(const fvec_t *s, uint_t position) {
    4545  return s->data[position];
    4646}
    4747
    48 smpl_t * fvec_get_data(fvec_t *s) {
     48smpl_t * fvec_get_data(const fvec_t *s) {
    4949  return s->data;
    5050}
     
    5252/* helper functions */
    5353
    54 void fvec_print(fvec_t *s) {
     54void fvec_print(const fvec_t *s) {
    5555  uint_t j;
    5656  for (j=0; j< s->length; j++) {
     
    9191void fvec_rev(fvec_t *s) {
    9292  uint_t j;
    93   for (j=0; j< FLOOR(s->length/2); j++) {
     93  for (j=0; j< FLOOR((smpl_t)s->length/2); j++) {
    9494    ELEM_SWAP(s->data[j], s->data[s->length-1-j]);
    9595  }
    9696}
    9797
    98 void fvec_weight(fvec_t *s, fvec_t *weight) {
     98void fvec_weight(fvec_t *s, const fvec_t *weight) {
    9999#ifndef HAVE_ACCELERATE
    100100  uint_t j;
     
    108108}
    109109
    110 void fvec_weighted_copy(fvec_t *in, fvec_t *weight, fvec_t *out) {
     110void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out) {
    111111#ifndef HAVE_ACCELERATE
    112112  uint_t j;
     
    120120}
    121121
    122 void fvec_copy(fvec_t *s, fvec_t *t) {
     122void fvec_copy(const fvec_t *s, fvec_t *t) {
    123123  if (s->length != t->length) {
    124124    AUBIO_ERR("trying to copy %d elements to %d elements \n",
     
    126126    return;
    127127  }
    128 #if HAVE_NOOPT
     128#ifdef HAVE_NOOPT
    129129  uint_t j;
    130130  for (j=0; j< t->length; j++) {
  • src/fvec.h

    r00d0275 r155cc10  
    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);
    164164
    165165/** make a copy of a vector, applying weights to each element
     
    170170
    171171*/
    172 void fvec_weighted_copy(fvec_t *in, fvec_t *weight, fvec_t *out);
     172void fvec_weighted_copy(const fvec_t *in, const fvec_t *weight, fvec_t *out);
    173173
    174174#ifdef __cplusplus
     
    176176#endif
    177177
    178 #endif /* _AUBIO__FVEC_H */
     178#endif /* AUBIO_FVEC_H */
  • src/io/audio_unit.c

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222#ifdef HAVE_AUDIO_UNIT
    23 #include "aubio_priv.h"
    2423
    2524#include "fvec.h"
  • src/io/audio_unit.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "fvec.h"
     
    5554};
    5655
    57 aubio_sink_t * new_aubio_sink(char_t * uri, uint_t samplerate) {
     56aubio_sink_t * new_aubio_sink(const char_t * uri, uint_t samplerate) {
    5857  aubio_sink_t * s = AUBIO_NEW(aubio_sink_t);
    5958#ifdef HAVE_SINK_APPLE_AUDIO
     
    7170  }
    7271#endif /* HAVE_SINK_APPLE_AUDIO */
    73 #if HAVE_SNDFILE
     72#ifdef HAVE_SNDFILE
    7473  s->sink = (void *)new_aubio_sink_sndfile(uri, samplerate);
    7574  if (s->sink) {
     
    8584  }
    8685#endif /* HAVE_SNDFILE */
    87 #if HAVE_WAVWRITE
     86#ifdef HAVE_WAVWRITE
    8887  s->sink = (void *)new_aubio_sink_wavwrite(uri, samplerate);
    8988  if (s->sink) {
     
    9998  }
    10099#endif /* HAVE_WAVWRITE */
    101   AUBIO_ERROR("sink: failed creating %s with samplerate %dHz\n",
    102       uri, samplerate);
     100#if !defined(HAVE_WAVWRITE) && \
     101  !defined(HAVE_SNDFILE) && \
     102  !defined(HAVE_SINK_APPLE_AUDIO)
     103  AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
     104#endif
    103105  AUBIO_FREE(s);
    104106  return NULL;
     
    121123}
    122124
    123 uint_t aubio_sink_get_samplerate(aubio_sink_t * s) {
     125uint_t aubio_sink_get_samplerate(const aubio_sink_t * s) {
    124126  return s->s_get_samplerate((void *)s->sink);
    125127}
    126128
    127 uint_t aubio_sink_get_channels(aubio_sink_t * s) {
     129uint_t aubio_sink_get_channels(const aubio_sink_t * s) {
    128130  return s->s_get_channels((void *)s->sink);
    129131}
  • src/io/sink.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_SINK_APPLE_AUDIO
    24 
    25 #include "aubio_priv.h"
    2624#include "fvec.h"
    2725#include "fmat.h"
    2826#include "io/sink_apple_audio.h"
     27#include "io/ioutils.h"
    2928
    3029// CFURLRef, CFURLCreateWithFileSystemPath, ...
     
    4443#define MAX_SIZE 4096 // the maximum number of frames that can be written at a time
    4544
     45void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write);
     46
    4647struct _aubio_sink_apple_audio_t {
    4748  uint_t samplerate;
     
    5657};
    5758
    58 aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(char_t * uri, uint_t samplerate) {
     59aubio_sink_apple_audio_t * new_aubio_sink_apple_audio(const char_t * uri, uint_t samplerate) {
    5960  aubio_sink_apple_audio_t * s = AUBIO_NEW(aubio_sink_apple_audio_t);
    60   s->path = uri;
    6161  s->max_frames = MAX_SIZE;
    62   s->async = true;
    63 
    64   if (uri == NULL) {
     62  s->async = false;
     63
     64  if ( (uri == NULL) || (strlen(uri) < 1) ) {
    6565    AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    6666    goto beach;
    6767  }
     68  if (s->path != NULL) AUBIO_FREE(s->path);
     69  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
     70  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
    6871
    6972  s->samplerate = 0;
    7073  s->channels = 0;
    7174
    72   // negative samplerate given, abort
    73   if ((sint_t)samplerate < 0) goto beach;
    7475  // zero samplerate given. do not open yet
    75   if ((sint_t)samplerate == 0) return s;
     76  if ((sint_t)samplerate == 0) {
     77    return s;
     78  }
     79  // invalid samplerate given, abort
     80  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     81    goto beach;
     82  }
    7683
    7784  s->samplerate = samplerate;
     
    9198uint_t aubio_sink_apple_audio_preset_samplerate(aubio_sink_apple_audio_t *s, uint_t samplerate)
    9299{
    93   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     100  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     101    return AUBIO_FAIL;
     102  }
    94103  s->samplerate = samplerate;
    95104  // automatically open when both samplerate and channels have been set
     
    102111uint_t aubio_sink_apple_audio_preset_channels(aubio_sink_apple_audio_t *s, uint_t channels)
    103112{
    104   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     113  if (aubio_io_validate_channels("sink_apple_audio", s->path, channels)) {
     114    return AUBIO_FAIL;
     115  }
    105116  s->channels = channels;
    106117  // automatically open when both samplerate and channels have been set
     
    111122}
    112123
    113 uint_t aubio_sink_apple_audio_get_samplerate(aubio_sink_apple_audio_t *s)
     124uint_t aubio_sink_apple_audio_get_samplerate(const aubio_sink_apple_audio_t *s)
    114125{
    115126  return s->samplerate;
    116127}
    117128
    118 uint_t aubio_sink_apple_audio_get_channels(aubio_sink_apple_audio_t *s)
     129uint_t aubio_sink_apple_audio_get_channels(const aubio_sink_apple_audio_t *s)
    119130{
    120131  return s->channels;
     
    163174
    164175void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    165   OSStatus err = noErr;
    166176  UInt32 c, v;
    167177  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    180190      }
    181191  }
    182   if (s->async) {
    183     err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
    184 
    185     if (err) {
    186       char_t errorstr[20];
    187       AUBIO_ERROR("sink_apple_audio: error while writing %s "
    188           "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
    189           getPrintableOSStatusError(errorstr, err));
    190       s->async = false;
    191     } else {
    192       return;
    193     }
    194 
    195   } else {
    196     err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
    197 
    198     if (err) {
    199       char_t errorstr[20];
    200       AUBIO_ERROR("sink_apple_audio: error while writing %s "
    201           "in ExtAudioFileWrite (%s)\n", s->path,
    202           getPrintableOSStatusError(errorstr, err));
    203     }
    204   }
    205   return;
     192  aubio_sink_apple_audio_write(s, write);
    206193}
    207194
    208195void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    209   OSStatus err = noErr;
    210196  UInt32 c, v;
    211197  short *data = (short*)s->bufferList.mBuffers[0].mData;
     
    224210      }
    225211  }
     212  aubio_sink_apple_audio_write(s, write);
     213}
     214
     215void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
     216  OSStatus err = noErr;
    226217  if (s->async) {
    227218    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
    228 
    229219    if (err) {
    230220      char_t errorstr[20];
     221      if (err == kExtAudioFileError_AsyncWriteBufferOverflow) {
     222        sprintf(errorstr,"buffer overflow");
     223      } else if (err == kExtAudioFileError_AsyncWriteTooLarge) {
     224        sprintf(errorstr,"write too large");
     225      } else {
     226        // unknown error
     227        getPrintableOSStatusError(errorstr, err);
     228      }
    231229      AUBIO_ERROR("sink_apple_audio: error while writing %s "
    232           "in ExtAudioFileWriteAsync (%s), switching to sync\n", s->path,
    233           getPrintableOSStatusError(errorstr, err));
    234       s->async = false;
    235     } else {
    236       return;
     230                  "in ExtAudioFileWriteAsync (%s)\n", s->path, errorstr);
    237231    }
    238 
    239232  } else {
    240233    err = ExtAudioFileWrite(s->audioFile, write, &s->bufferList);
    241 
    242234    if (err) {
    243235      char_t errorstr[20];
     
    247239    }
    248240  }
    249   return;
    250241}
    251242
     
    268259void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    269260  if (s->audioFile) aubio_sink_apple_audio_close (s);
     261  if (s->path) AUBIO_FREE(s->path);
    270262  freeAudioBufferList(&s->bufferList);
    271263  AUBIO_FREE(s);
  • src/io/sink_apple_audio.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    2020
    2121
    22 #include "config.h"
     22#include "aubio_priv.h"
    2323
    2424#ifdef HAVE_SNDFILE
     
    2626#include <sndfile.h>
    2727
    28 #include "aubio_priv.h"
    2928#include "fvec.h"
    3029#include "fmat.h"
    3130#include "io/sink_sndfile.h"
    32 
    33 #define MAX_CHANNELS 6
     31#include "io/ioutils.h"
     32
    3433#define MAX_SIZE 4096
    3534
     
    5453uint_t aubio_sink_sndfile_open(aubio_sink_sndfile_t *s);
    5554
    56 aubio_sink_sndfile_t * new_aubio_sink_sndfile(char_t * path, uint_t samplerate) {
     55aubio_sink_sndfile_t * new_aubio_sink_sndfile(const char_t * path, uint_t samplerate) {
    5756  aubio_sink_sndfile_t * s = AUBIO_NEW(aubio_sink_sndfile_t);
    5857  s->max_size = MAX_SIZE;
    59   s->path = path;
    6058
    6159  if (path == NULL) {
     
    6462  }
    6563
     64  if (s->path) AUBIO_FREE(s->path);
     65  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     66  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     67
    6668  s->samplerate = 0;
    6769  s->channels = 0;
    6870
    69   // negative samplerate given, abort
    70   if ((sint_t)samplerate < 0) goto beach;
    7171  // zero samplerate given. do not open yet
    72   if ((sint_t)samplerate == 0) return s;
     72  if ((sint_t)samplerate == 0) {
     73    return s;
     74  }
     75  // invalid samplerate given, abort
     76  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     77    goto beach;
     78  }
    7379
    7480  s->samplerate = samplerate;
     
    8793uint_t aubio_sink_sndfile_preset_samplerate(aubio_sink_sndfile_t *s, uint_t samplerate)
    8894{
    89   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     95  if (aubio_io_validate_samplerate("sink_sndfile", s->path, samplerate)) {
     96    return AUBIO_FAIL;
     97  }
    9098  s->samplerate = samplerate;
    9199  // automatically open when both samplerate and channels have been set
     
    98106uint_t aubio_sink_sndfile_preset_channels(aubio_sink_sndfile_t *s, uint_t channels)
    99107{
    100   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     108  if (aubio_io_validate_channels("sink_sndfile", s->path, channels)) {
     109    return AUBIO_FAIL;
     110  }
    101111  s->channels = channels;
    102112  // automatically open when both samplerate and channels have been set
     
    107117}
    108118
    109 uint_t aubio_sink_sndfile_get_samplerate(aubio_sink_sndfile_t *s)
     119uint_t aubio_sink_sndfile_get_samplerate(const aubio_sink_sndfile_t *s)
    110120{
    111121  return s->samplerate;
    112122}
    113123
    114 uint_t aubio_sink_sndfile_get_channels(aubio_sink_sndfile_t *s)
     124uint_t aubio_sink_sndfile_get_channels(const aubio_sink_sndfile_t *s)
    115125{
    116126  return s->channels;
     
    130140  if (s->handle == NULL) {
    131141    /* show libsndfile err msg */
    132     AUBIO_ERR("sink_sndfile: Failed opening %s. %s\n", s->path, sf_strerror (NULL));
     142    AUBIO_ERR("sink_sndfile: Failed opening \"%s\" with %d channels, %dHz: %s\n",
     143        s->path, s->channels, s->samplerate, sf_strerror (NULL));
    133144    return AUBIO_FAIL;
    134145  }
     
    136147  s->scratch_size = s->max_size*s->channels;
    137148  /* allocate data for de/interleaving reallocated when needed. */
    138   if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
     149  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
     150    abort();
    139151    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
    140         s->max_size, s->channels, MAX_CHANNELS * MAX_CHANNELS);
     152        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    141153    return AUBIO_FAIL;
    142154  }
     
    220232void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    221233  if (!s) return;
     234  if (s->path) AUBIO_FREE(s->path);
    222235  aubio_sink_sndfile_close(s);
    223236  AUBIO_FREE(s->scratch_data);
  • src/io/sink_sndfile.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    2020
    2121
    22 #include "config.h"
     22#include "aubio_priv.h"
    2323
    2424#ifdef HAVE_WAVWRITE
    2525
    26 #include "aubio_priv.h"
    2726#include "fvec.h"
    2827#include "fmat.h"
    2928#include "io/sink_wavwrite.h"
     29#include "io/ioutils.h"
    3030
    3131#include <errno.h>
    3232
    33 #define MAX_CHANNELS 6
    3433#define MAX_SIZE 4096
    3534
     
    6968};
    7069
    71 unsigned char *write_little_endian (unsigned int s, unsigned char *str, unsigned int length);
    72 unsigned char *write_little_endian (unsigned int s, unsigned char *str, unsigned int length) {
     70static unsigned char *write_little_endian (unsigned int s, unsigned char *str,
     71    unsigned int length);
     72
     73static unsigned char *write_little_endian (unsigned int s, unsigned char *str,
     74    unsigned int length)
     75{
    7376  uint_t i;
    7477  for (i = 0; i < length; i++) {
     
    7881}
    7982
    80 aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(char_t * path, uint_t samplerate) {
     83aubio_sink_wavwrite_t * new_aubio_sink_wavwrite(const char_t * path, uint_t samplerate) {
    8184  aubio_sink_wavwrite_t * s = AUBIO_NEW(aubio_sink_wavwrite_t);
    8285
     
    9093  }
    9194
    92   s->path = path;
     95  if (s->path) AUBIO_FREE(s->path);
     96  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     97  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     98
    9399  s->max_size = MAX_SIZE;
    94100  s->bitspersample = 16;
     
    98104  s->channels = 0;
    99105
    100   // negative samplerate given, abort
    101   if ((sint_t)samplerate < 0) goto beach;
    102106  // zero samplerate given. do not open yet
    103   if ((sint_t)samplerate == 0) return s;
    104   // samplerate way too large, fail
    105   if ((sint_t)samplerate > 192000 * 4) goto beach;
     107  if ((sint_t)samplerate == 0) {
     108    return s;
     109  }
     110  // invalid samplerate given, abort
     111  if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) {
     112    goto beach;
     113  }
    106114
    107115  s->samplerate = samplerate;
     
    123131uint_t aubio_sink_wavwrite_preset_samplerate(aubio_sink_wavwrite_t *s, uint_t samplerate)
    124132{
    125   if ((sint_t)(samplerate) <= 0) return AUBIO_FAIL;
     133  if (aubio_io_validate_samplerate("sink_wavwrite", s->path, samplerate)) {
     134    return AUBIO_FAIL;
     135  }
    126136  s->samplerate = samplerate;
    127137  // automatically open when both samplerate and channels have been set
     
    134144uint_t aubio_sink_wavwrite_preset_channels(aubio_sink_wavwrite_t *s, uint_t channels)
    135145{
    136   if ((sint_t)(channels) <= 0) return AUBIO_FAIL;
     146  if (aubio_io_validate_channels("sink_wavwrite", s->path, channels)) {
     147    return AUBIO_FAIL;
     148  }
    137149  s->channels = channels;
    138150  // automatically open when both samplerate and channels have been set
     
    143155}
    144156
    145 uint_t aubio_sink_wavwrite_get_samplerate(aubio_sink_wavwrite_t *s)
     157uint_t aubio_sink_wavwrite_get_samplerate(const aubio_sink_wavwrite_t *s)
    146158{
    147159  return s->samplerate;
    148160}
    149161
    150 uint_t aubio_sink_wavwrite_get_channels(aubio_sink_wavwrite_t *s)
     162uint_t aubio_sink_wavwrite_get_channels(const aubio_sink_wavwrite_t *s)
    151163{
    152164  return s->channels;
     
    207219  s->scratch_size = s->max_size * s->channels;
    208220  /* allocate data for de/interleaving reallocated when needed. */
    209   if (s->scratch_size >= MAX_SIZE * MAX_CHANNELS) {
     221  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
    210222    AUBIO_ERR("sink_wavwrite: %d x %d exceeds SIZE maximum buffer size %d\n",
    211         s->max_size, s->channels, MAX_SIZE * MAX_CHANNELS);
     223        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    212224    goto beach;
    213225  }
     
    288300  if (!s) return;
    289301  aubio_sink_wavwrite_close(s);
     302  if (s->path) AUBIO_FREE(s->path);
    290303  AUBIO_FREE(s->scratch_data);
    291304  AUBIO_FREE(s);
  • src/io/sink_wavwrite.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "fvec.h"
     
    4140typedef uint_t (*aubio_source_get_samplerate_t)(aubio_source_t * s);
    4241typedef uint_t (*aubio_source_get_channels_t)(aubio_source_t * s);
     42typedef uint_t (*aubio_source_get_duration_t)(aubio_source_t * s);
    4343typedef uint_t (*aubio_source_seek_t)(aubio_source_t * s, uint_t seek);
    4444typedef uint_t (*aubio_source_close_t)(aubio_source_t * s);
     
    5151  aubio_source_get_samplerate_t s_get_samplerate;
    5252  aubio_source_get_channels_t s_get_channels;
     53  aubio_source_get_duration_t s_get_duration;
    5354  aubio_source_seek_t s_seek;
    5455  aubio_source_close_t s_close;
     
    5657};
    5758
    58 aubio_source_t * new_aubio_source(char_t * uri, uint_t samplerate, uint_t hop_size) {
     59aubio_source_t * new_aubio_source(const char_t * uri, uint_t samplerate, uint_t hop_size) {
    5960  aubio_source_t * s = AUBIO_NEW(aubio_source_t);
    60 #if HAVE_LIBAV
     61#ifdef HAVE_LIBAV
    6162  s->source = (void *)new_aubio_source_avcodec(uri, samplerate, hop_size);
    6263  if (s->source) {
     
    6566    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_avcodec_get_channels);
    6667    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_avcodec_get_samplerate);
     68    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_avcodec_get_duration);
    6769    s->s_seek = (aubio_source_seek_t)(aubio_source_avcodec_seek);
    6870    s->s_close = (aubio_source_close_t)(aubio_source_avcodec_close);
     
    7880    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_apple_audio_get_channels);
    7981    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_apple_audio_get_samplerate);
     82    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_apple_audio_get_duration);
    8083    s->s_seek = (aubio_source_seek_t)(aubio_source_apple_audio_seek);
    8184    s->s_close = (aubio_source_close_t)(aubio_source_apple_audio_close);
     
    8487  }
    8588#endif /* HAVE_SOURCE_APPLE_AUDIO */
    86 #if HAVE_SNDFILE
     89#ifdef HAVE_SNDFILE
    8790  s->source = (void *)new_aubio_source_sndfile(uri, samplerate, hop_size);
    8891  if (s->source) {
     
    9194    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_sndfile_get_channels);
    9295    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_sndfile_get_samplerate);
     96    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_sndfile_get_duration);
    9397    s->s_seek = (aubio_source_seek_t)(aubio_source_sndfile_seek);
    9498    s->s_close = (aubio_source_close_t)(aubio_source_sndfile_close);
     
    97101  }
    98102#endif /* HAVE_SNDFILE */
    99 #if HAVE_WAVREAD
     103#ifdef HAVE_WAVREAD
    100104  s->source = (void *)new_aubio_source_wavread(uri, samplerate, hop_size);
    101105  if (s->source) {
     
    104108    s->s_get_channels = (aubio_source_get_channels_t)(aubio_source_wavread_get_channels);
    105109    s->s_get_samplerate = (aubio_source_get_samplerate_t)(aubio_source_wavread_get_samplerate);
     110    s->s_get_duration = (aubio_source_get_duration_t)(aubio_source_wavread_get_duration);
    106111    s->s_seek = (aubio_source_seek_t)(aubio_source_wavread_seek);
    107112    s->s_close = (aubio_source_close_t)(aubio_source_wavread_close);
     
    110115  }
    111116#endif /* HAVE_WAVREAD */
    112   AUBIO_ERROR("source: failed creating aubio source with %s"
    113      " at samplerate %d with hop_size %d\n", uri, samplerate, hop_size);
     117#if !defined(HAVE_WAVREAD) && \
     118  !defined(HAVE_LIBAV) && \
     119  !defined(HAVE_SOURCE_APPLE_AUDIO) && \
     120  !defined(HAVE_SNDFILE)
     121  AUBIO_ERROR("source: failed creating with %s at %dHz with hop size %d"
     122     " (no source built-in)\n", uri, samplerate, hop_size);
     123#endif
    114124  AUBIO_FREE(s);
    115125  return NULL;
     
    142152}
    143153
     154uint_t aubio_source_get_duration(aubio_source_t *s) {
     155  return s->s_get_duration((void *)s->source);
     156}
     157
    144158uint_t aubio_source_seek (aubio_source_t * s, uint_t seek ) {
    145159  return s->s_seek((void *)s->source, seek);
  • src/io/source.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_SOURCE_APPLE_AUDIO
    2424
    25 #include "aubio_priv.h"
    2625#include "fvec.h"
    2726#include "fmat.h"
     
    5554char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    5655
    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)
     56uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path);
     57
     58aubio_source_apple_audio_t * new_aubio_source_apple_audio(const char_t * path, uint_t samplerate, uint_t block_size)
    6059{
    6160  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
     
    8079  s->block_size = block_size;
    8180  s->samplerate = samplerate;
    82   s->path = path;
    8381
    8482  if ( aubio_source_apple_audio_open ( s, path ) ) {
     
    9290}
    9391
    94 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path)
     92uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, const char_t * path)
    9593{
    9694  OSStatus err = noErr;
    9795  UInt32 propSize;
    98   s->path = path;
     96
     97  if (s->path) AUBIO_FREE(s->path);
     98  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     99  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    99100
    100101  // open the resource url
    101   CFURLRef fileURL = createURLFromPath(path);
     102  CFURLRef fileURL = createURLFromPath(s->path);
    102103  err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
    103104  CFRelease(fileURL);
     
    279280{
    280281  OSStatus err = noErr;
    281   if (!s->audioFile) { return AUBIO_FAIL; }
     282  if (!s->audioFile) { return AUBIO_OK; }
    282283  err = ExtAudioFileDispose(s->audioFile);
    283284  s->audioFile = NULL;
     
    294295void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
    295296  aubio_source_apple_audio_close (s);
     297  if (s->path) AUBIO_FREE(s->path);
    296298  freeAudioBufferList(&s->bufferList);
    297299  AUBIO_FREE(s);
     
    309311  }
    310312  // check if we are not seeking out of the file
    311   SInt64 fileLengthFrames = 0;
    312   UInt32 propSize = sizeof(fileLengthFrames);
    313   ExtAudioFileGetProperty(s->audioFile,
    314       kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     313  uint_t fileLengthFrames = aubio_source_apple_audio_get_duration(s);
    315314  // compute position in the source file, before resampling
    316315  smpl_t ratio = s->source_samplerate * 1. / s->samplerate;
     
    353352}
    354353
    355 uint_t aubio_source_apple_audio_get_samplerate(aubio_source_apple_audio_t * s) {
     354uint_t aubio_source_apple_audio_get_samplerate(const aubio_source_apple_audio_t * s) {
    356355  return s->samplerate;
    357356}
    358357
    359 uint_t aubio_source_apple_audio_get_channels(aubio_source_apple_audio_t * s) {
     358uint_t aubio_source_apple_audio_get_channels(const aubio_source_apple_audio_t * s) {
    360359  return s->channels;
    361360}
    362361
     362uint_t aubio_source_apple_audio_get_duration(const aubio_source_apple_audio_t * s) {
     363  SInt64 fileLengthFrames = 0;
     364  UInt32 propSize = sizeof(fileLengthFrames);
     365  OSStatus err = ExtAudioFileGetProperty(s->audioFile,
     366      kExtAudioFileProperty_FileLengthFrames, &propSize, &fileLengthFrames);
     367  if (err) {
     368    char_t errorstr[20];
     369    AUBIO_ERROR("source_apple_audio: Failed getting %s duration, "
     370        "error in ExtAudioFileGetProperty (%s)\n", s->path,
     371        getPrintableOSStatusError(errorstr, err));
     372    return err;
     373  }
     374  return (uint_t)fileLengthFrames;
     375}
     376
    363377#endif /* HAVE_SOURCE_APPLE_AUDIO */
  • src/io/source_apple_audio.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 
    22 #include "config.h"
     21#include "aubio_priv.h"
    2322
    2423#ifdef HAVE_LIBAV
    25 
    26 // determine whether we use libavformat from ffmpe or libav
    27 #define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99)
    2824
    2925#include <libavcodec/avcodec.h>
     
    3329#include <stdlib.h>
    3430
     31// determine whether we use libavformat from ffmpeg or from libav
     32#define FFMPEG_LIBAVFORMAT (LIBAVFORMAT_VERSION_MICRO > 99 )
     33// max_analyze_duration2 was used from ffmpeg libavformat 55.43.100 through 57.2.100
     34#define FFMPEG_LIBAVFORMAT_MAX_DUR2 FFMPEG_LIBAVFORMAT && ( \
     35      (LIBAVFORMAT_VERSION_MAJOR == 55 && LIBAVFORMAT_VERSION_MINOR >= 43) \
     36      || (LIBAVFORMAT_VERSION_MAJOR == 56) \
     37      || (LIBAVFORMAT_VERSION_MAJOR == 57 && LIBAVFORMAT_VERSION_MINOR < 2) \
     38      )
     39
     40// backward compatibility with libavcodec55
     41#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55,28,1)
     42#warning "libavcodec55 is deprecated"
     43#define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
     44#define av_frame_alloc  avcodec_alloc_frame
     45#define av_frame_free avcodec_free_frame
     46#define av_packet_unref av_free_packet
     47#endif
     48
    3549#include "aubio_priv.h"
    3650#include "fvec.h"
     
    5468  AVCodecContext *avCodecCtx;
    5569  AVFrame *avFrame;
     70  AVPacket avPacket;
    5671  AVAudioResampleContext *avr;
    57   float *output;
     72  smpl_t *output;
    5873  uint_t read_samples;
    5974  uint_t read_index;
     
    6782void aubio_source_avcodec_readframe(aubio_source_avcodec_t *s, uint_t * read_samples);
    6883
    69 aubio_source_avcodec_t * new_aubio_source_avcodec(char_t * path, uint_t samplerate, uint_t hop_size) {
     84uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s);
     85
     86uint_t aubio_source_avcodec_has_network_url(aubio_source_avcodec_t *s) {
     87  char proto[20], authorization[256], hostname[128], uripath[256];
     88  int proto_size = 20, authorization_size = 256, hostname_size = 128,
     89      *port_ptr = 0, path_size = 256;
     90  av_url_split(proto, proto_size, authorization, authorization_size, hostname,
     91      hostname_size, port_ptr, uripath, path_size, s->path);
     92  if (strlen(proto)) {
     93    return 1;
     94  }
     95  return 0;
     96}
     97
     98
     99aubio_source_avcodec_t * new_aubio_source_avcodec(const char_t * path, uint_t samplerate, uint_t hop_size) {
    70100  aubio_source_avcodec_t * s = AUBIO_NEW(aubio_source_avcodec_t);
    71101  int err;
     
    85115  s->hop_size = hop_size;
    86116  s->channels = 1;
    87   s->path = path;
     117
     118  if (s->path) AUBIO_FREE(s->path);
     119  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     120  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    88121
    89122  // register all formats and codecs
    90123  av_register_all();
    91124
    92   // if path[0] != '/'
    93   //avformat_network_init();
     125  if (aubio_source_avcodec_has_network_url(s)) {
     126    avformat_network_init();
     127  }
    94128
    95129  // try opening the file and get some info about it
     
    104138
    105139  // try to make sure max_analyze_duration is big enough for most songs
    106 #if FFMPEG_LIBAVFORMAT
     140#if FFMPEG_LIBAVFORMAT_MAX_DUR2
    107141  avFormatCtx->max_analyze_duration2 *= 100;
    108142#else
     
    126160  sint_t selected_stream = -1;
    127161  for (i = 0; i < avFormatCtx->nb_streams; i++) {
     162#if FF_API_LAVF_AVCTX
     163    if (avFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
     164#else
    128165    if (avFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
     166#endif
    129167      if (selected_stream == -1) {
    130168        selected_stream = i;
     
    143181
    144182  AVCodecContext *avCodecCtx = s->avCodecCtx;
     183#if FF_API_LAVF_AVCTX
     184  AVCodecParameters *codecpar = avFormatCtx->streams[selected_stream]->codecpar;
     185  if (codecpar == NULL) {
     186    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
     187    goto beach;
     188  }
     189  AVCodec *codec = avcodec_find_decoder(codecpar->codec_id);
     190
     191  /* Allocate a codec context for the decoder */
     192  avCodecCtx = avcodec_alloc_context3(codec);
     193  if (!avCodecCtx) {
     194    AUBIO_ERR("source_avcodec: Failed to allocate the %s codec context for path %s\n",
     195        av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path);
     196    goto beach;
     197  }
     198#else
    145199  avCodecCtx = avFormatCtx->streams[selected_stream]->codec;
    146200  AVCodec *codec = avcodec_find_decoder(avCodecCtx->codec_id);
     201#endif
    147202  if (codec == NULL) {
    148203    AUBIO_ERR("source_avcodec: Could not find decoder for %s", s->path);
    149204    goto beach;
    150205  }
     206
     207#if FF_API_LAVF_AVCTX
     208  /* Copy codec parameters from input stream to output codec context */
     209  if ((err = avcodec_parameters_to_context(avCodecCtx, codecpar)) < 0) {
     210    AUBIO_ERR("source_avcodec: Failed to copy %s codec parameters to decoder context for %s\n",
     211       av_get_media_type_string(AVMEDIA_TYPE_AUDIO), s->path);
     212    goto beach;
     213  }
     214#endif
    151215
    152216  if ( ( err = avcodec_open2(avCodecCtx, codec, NULL) ) < 0) {
     
    164228
    165229  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;
     230    s->samplerate = s->input_samplerate;
     231  } else {
     232    s->samplerate = samplerate;
     233  }
    170234
    171235  if (s->samplerate >  s->input_samplerate) {
     
    181245
    182246  /* allocate output for avr */
    183   s->output = (float *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(float));
     247  s->output = (smpl_t *)av_malloc(AUBIO_AVCODEC_MAX_BUFFER_SIZE * sizeof(smpl_t));
    184248
    185249  s->read_samples = 0;
     
    208272
    209273void aubio_source_avcodec_reset_resampler(aubio_source_avcodec_t * s, uint_t multi) {
     274  // create or reset resampler to/from mono/multi-channel
    210275  if ( (multi != s->multi) || (s->avr == NULL) ) {
    211276    int64_t input_layout = av_get_default_channel_layout(s->input_channels);
    212277    uint_t output_channels = multi ? s->input_channels : 1;
    213278    int64_t output_layout = av_get_default_channel_layout(output_channels);
    214     if (s->avr != NULL) {
    215       avresample_close( s->avr );
    216       av_free ( s->avr );
    217       s->avr = NULL;
    218     }
    219     AVAudioResampleContext *avr = s->avr;
    220     avr = avresample_alloc_context();
     279    AVAudioResampleContext *avr = avresample_alloc_context();
     280    AVAudioResampleContext *oldavr = s->avr;
    221281
    222282    av_opt_set_int(avr, "in_channel_layout",  input_layout,           0);
     
    225285    av_opt_set_int(avr, "out_sample_rate",    s->samplerate,          0);
    226286    av_opt_set_int(avr, "in_sample_fmt",      s->avCodecCtx->sample_fmt, 0);
     287#if HAVE_AUBIO_DOUBLE
     288    av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_DBL,      0);
     289#else
    227290    av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLT,      0);
     291#endif
     292    // TODO: use planar?
     293    //av_opt_set_int(avr, "out_sample_fmt",     AV_SAMPLE_FMT_FLTP,      0);
    228294    int err;
    229295    if ( ( err = avresample_open(avr) ) < 0) {
     
    236302    }
    237303    s->avr = avr;
     304    if (oldavr != NULL) {
     305      avresample_close( oldavr );
     306      av_free ( oldavr );
     307      oldavr = NULL;
     308    }
    238309    s->multi = multi;
    239310  }
     
    244315  AVCodecContext *avCodecCtx = s->avCodecCtx;
    245316  AVFrame *avFrame = s->avFrame;
    246   AVPacket avPacket;
     317  AVPacket avPacket = s->avPacket;
    247318  av_init_packet (&avPacket);
    248319  AVAudioResampleContext *avr = s->avr;
    249   float *output = s->output;
     320  smpl_t *output = s->output;
    250321  *read_samples = 0;
    251322
     
    260331      char errorstr[256];
    261332      av_strerror (err, errorstr, sizeof(errorstr));
    262       AUBIO_ERR("Could not read frame in %s (%s)\n", s->path, errorstr);
     333      AUBIO_ERR("source_avcodec: could not read frame in %s (%s)\n", s->path, errorstr);
    263334      goto beach;
    264335    }
     
    266337
    267338  int got_frame = 0;
     339#if FF_API_LAVF_AVCTX
     340  int ret = avcodec_send_packet(avCodecCtx, &avPacket);
     341  if (ret < 0 && ret != AVERROR_EOF) {
     342    AUBIO_ERR("source_avcodec: error when sending packet for %s\n", s->path);
     343    goto beach;
     344  }
     345  ret = avcodec_receive_frame(avCodecCtx, avFrame);
     346  if (ret >= 0) {
     347    got_frame = 1;
     348  }
     349  if (ret < 0) {
     350    if (ret == AVERROR(EAGAIN)) {
     351      AUBIO_WRN("source_avcodec: output is not available right now - user must try to send new input\n");
     352    } else if (ret == AVERROR_EOF) {
     353      AUBIO_WRN("source_avcodec: the decoder has been fully flushed, and there will be no more output frames\n");
     354    } else {
     355      AUBIO_ERR("source_avcodec: decoding errors on %s\n", s->path);
     356      goto beach;
     357    }
     358  }
     359#else
    268360  int len = avcodec_decode_audio4(avCodecCtx, avFrame, &got_frame, &avPacket);
    269361
    270362  if (len < 0) {
    271     AUBIO_ERR("Error while decoding %s\n", s->path);
    272     goto beach;
    273   }
     363    AUBIO_ERR("source_avcodec: error while decoding %s\n", s->path);
     364    goto beach;
     365  }
     366#endif
    274367  if (got_frame == 0) {
    275     //AUBIO_ERR("Could not get frame for (%s)\n", s->path);
     368    AUBIO_WRN("source_avcodec: did not get a frame when reading %s\n", s->path);
    276369    goto beach;
    277370  }
     
    287380        (uint8_t **)avFrame->data, in_linesize, in_samples);
    288381  if (out_samples <= 0) {
    289     //AUBIO_ERR("No sample found while converting frame (%s)\n", s->path);
     382    AUBIO_WRN("source_avcodec: no sample found while converting frame (%s)\n", s->path);
    290383    goto beach;
    291384  }
     
    300393  s->output = output;
    301394
    302   av_free_packet(&avPacket);
     395  av_packet_unref(&avPacket);
    303396}
    304397
    305398void aubio_source_avcodec_do(aubio_source_avcodec_t * s, fvec_t * read_data, uint_t * read){
    306   if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);
    307399  uint_t i;
    308400  uint_t end = 0;
    309401  uint_t total_wrote = 0;
     402  // switch from multi
     403  if (s->multi == 1) aubio_source_avcodec_reset_resampler(s, 0);
    310404  while (total_wrote < s->hop_size) {
    311405    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    327421  }
    328422  if (total_wrote < s->hop_size) {
    329     for (i = end; i < s->hop_size; i++) {
     423    for (i = total_wrote; i < s->hop_size; i++) {
    330424      read_data->data[i] = 0.;
    331425    }
     
    335429
    336430void aubio_source_avcodec_do_multi(aubio_source_avcodec_t * s, fmat_t * read_data, uint_t * read){
    337   if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);
    338431  uint_t i,j;
    339432  uint_t end = 0;
    340433  uint_t total_wrote = 0;
     434  // switch from mono
     435  if (s->multi == 0) aubio_source_avcodec_reset_resampler(s, 1);
    341436  while (total_wrote < s->hop_size) {
    342437    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    362457  if (total_wrote < s->hop_size) {
    363458    for (j = 0; j < read_data->height; j++) {
    364       for (i = end; i < s->hop_size; i++) {
     459      for (i = total_wrote; i < s->hop_size; i++) {
    365460        read_data->data[j][i] = 0.;
    366461      }
     
    370465}
    371466
    372 uint_t aubio_source_avcodec_get_samplerate(aubio_source_avcodec_t * s) {
     467uint_t aubio_source_avcodec_get_samplerate(const aubio_source_avcodec_t * s) {
    373468  return s->samplerate;
    374469}
    375470
    376 uint_t aubio_source_avcodec_get_channels(aubio_source_avcodec_t * s) {
     471uint_t aubio_source_avcodec_get_channels(const aubio_source_avcodec_t * s) {
    377472  return s->input_channels;
    378473}
     
    383478  int64_t max_ts = MIN(resampled_pos + 2000, INT64_MAX);
    384479  int seek_flags = AVSEEK_FLAG_FRAME | AVSEEK_FLAG_ANY;
    385   int ret = avformat_seek_file(s->avFormatCtx, s->selected_stream,
     480  int ret = AUBIO_FAIL;
     481  if (s->avFormatCtx != NULL && s->avr != NULL) {
     482    ret = AUBIO_OK;
     483  } else {
     484    AUBIO_ERR("source_avcodec: failed seeking in %s (file not opened?)", s->path);
     485    return ret;
     486  }
     487  if ((sint_t)pos < 0) {
     488    AUBIO_ERR("source_avcodec: could not seek %s at %d (seeking position"
     489       " should be >= 0)\n", s->path, pos);
     490    return AUBIO_FAIL;
     491  }
     492  ret = avformat_seek_file(s->avFormatCtx, s->selected_stream,
    386493      min_ts, resampled_pos, max_ts, seek_flags);
    387494  if (ret < 0) {
    388     AUBIO_ERR("Failed seeking to %d in file %s", pos, s->path);
     495    AUBIO_ERR("source_avcodec: failed seeking to %d in file %s", pos, s->path);
    389496  }
    390497  // reset read status
     
    398505}
    399506
     507uint_t aubio_source_avcodec_get_duration (aubio_source_avcodec_t * s) {
     508  if (s && &(s->avFormatCtx) != NULL) {
     509    int64_t duration = s->avFormatCtx->duration;
     510    return s->samplerate * ((uint_t)duration / 1e6 );
     511  }
     512  return 0;
     513}
     514
    400515uint_t aubio_source_avcodec_close(aubio_source_avcodec_t * s) {
    401516  if (s->avr != NULL) {
     
    409524  s->avCodecCtx = NULL;
    410525  if (s->avFormatCtx != NULL) {
    411     avformat_close_input ( &(s->avFormatCtx) );
    412   }
    413   s->avFormatCtx = NULL;
     526    avformat_close_input(&s->avFormatCtx);
     527#ifndef HAVE_AUBIO_LIBAVCODEC_DEPRECATED // avoid crash on old libavcodec54
     528    avformat_free_context(s->avFormatCtx);
     529#endif
     530    s->avFormatCtx = NULL;
     531  }
     532  av_packet_unref(&s->avPacket);
    414533  return AUBIO_OK;
    415534}
     
    426545  }
    427546  s->avFrame = NULL;
     547  if (s->path) {
     548    AUBIO_FREE(s->path);
     549  }
     550  s->path = NULL;
    428551  AUBIO_FREE(s);
    429552}
  • src/io/source_avcodec.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 
    22 #include "config.h"
     21#include "aubio_priv.h"
    2322
    2423#ifdef HAVE_SNDFILE
     
    2625#include <sndfile.h>
    2726
    28 #include "aubio_priv.h"
    2927#include "fvec.h"
    3028#include "fmat.h"
     
    3331#include "temporal/resampler.h"
    3432
    35 #define MAX_CHANNELS 6
    3633#define MAX_SIZE 4096
    37 #define MAX_SAMPLES MAX_CHANNELS * MAX_SIZE
     34#define MAX_SAMPLES AUBIO_MAX_CHANNELS * MAX_SIZE
     35
     36#if !HAVE_AUBIO_DOUBLE
     37#define aubio_sf_read_smpl sf_read_float
     38#else /* HAVE_AUBIO_DOUBLE */
     39#define aubio_sf_read_smpl sf_read_double
     40#endif /* HAVE_AUBIO_DOUBLE */
    3841
    3942struct _aubio_source_sndfile_t {
     
    4851  int input_channels;
    4952  int input_format;
     53  int duration;
    5054
    5155  // resampling stuff
     
    5357  uint_t input_hop_size;
    5458#ifdef HAVE_SAMPLERATE
    55   aubio_resampler_t *resampler;
     59  aubio_resampler_t **resamplers;
    5660  fvec_t *input_data;
     61  fmat_t *input_mat;
    5762#endif /* HAVE_SAMPLERATE */
    5863
    5964  // some temporary memory for sndfile to write at
    6065  uint_t scratch_size;
    61   float *scratch_data;
     66  smpl_t *scratch_data;
    6267};
    6368
    64 aubio_source_sndfile_t * new_aubio_source_sndfile(char_t * path, uint_t samplerate, uint_t hop_size) {
     69aubio_source_sndfile_t * new_aubio_source_sndfile(const char_t * path, uint_t samplerate, uint_t hop_size) {
    6570  aubio_source_sndfile_t * s = AUBIO_NEW(aubio_source_sndfile_t);
    6671  SF_INFO sfinfo;
     
    8186  s->hop_size = hop_size;
    8287  s->channels = 1;
    83   s->path = path;
     88
     89  if (s->path) AUBIO_FREE(s->path);
     90  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     91  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
    8492
    8593  // try opening the file, getting the info in sfinfo
     
    8997  if (s->handle == NULL) {
    9098    /* show libsndfile err msg */
    91     AUBIO_ERR("source_sndfile: Failed opening %s: %s\n", s->path, sf_strerror (NULL));
     99    AUBIO_ERR("source_sndfile: Failed opening %s (%s)\n", s->path,
     100        sf_strerror (NULL));
    92101    goto beach;
    93102  }
     
    97106  s->input_channels   = sfinfo.channels;
    98107  s->input_format     = sfinfo.format;
     108  s->duration         = sfinfo.frames;
    99109
    100110  if (samplerate == 0) {
    101     samplerate = s->input_samplerate;
     111    s->samplerate = s->input_samplerate;
    102112    //AUBIO_DBG("sampling rate set to 0, automagically adjusting to %d\n", samplerate);
    103   }
    104   s->samplerate = samplerate;
     113  } else {
     114    s->samplerate = samplerate;
     115  }
    105116  /* compute input block size required before resampling */
    106   s->ratio = s->samplerate/(float)s->input_samplerate;
     117  s->ratio = s->samplerate/(smpl_t)s->input_samplerate;
    107118  s->input_hop_size = (uint_t)FLOOR(s->hop_size / s->ratio + .5);
    108119
     
    114125
    115126#ifdef HAVE_SAMPLERATE
    116   s->resampler = NULL;
    117127  s->input_data = NULL;
     128  s->input_mat = NULL;
     129  s->resamplers = NULL;
    118130  if (s->ratio != 1) {
     131    uint_t i;
     132    s->resamplers = AUBIO_ARRAY(aubio_resampler_t*, s->input_channels);
    119133    s->input_data = new_fvec(s->input_hop_size);
    120     s->resampler = new_aubio_resampler(s->ratio, 4);
     134    s->input_mat = new_fmat(s->input_channels, s->input_hop_size);
     135    for (i = 0; i < (uint_t)s->input_channels; i++) {
     136      s->resamplers[i] = new_aubio_resampler(s->ratio, 4);
     137    }
    121138    if (s->ratio > 1) {
    122139      // we would need to add a ring buffer for these
    123       if ( (uint_t)(s->input_hop_size * s->ratio + .5)  != s->hop_size ) {
     140      if ( (uint_t)FLOOR(s->input_hop_size * s->ratio + .5)  != s->hop_size ) {
    124141        AUBIO_ERR("source_sndfile: can not upsample %s from %d to %d\n", s->path,
    125142            s->input_samplerate, s->samplerate);
     
    129146          s->input_samplerate, s->samplerate);
    130147    }
     148    s->duration = (uint_t)FLOOR(s->duration * s->ratio);
    131149  }
    132150#else
     
    139157  /* allocate data for de/interleaving reallocated when needed. */
    140158  s->scratch_size = s->input_hop_size * s->input_channels;
    141   s->scratch_data = AUBIO_ARRAY(float,s->scratch_size);
     159  s->scratch_data = AUBIO_ARRAY(smpl_t, s->scratch_size);
    142160
    143161  return s;
     
    153171  uint_t i,j, input_channels = s->input_channels;
    154172  /* read from file into scratch_data */
    155   sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     173  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    156174
    157175  /* where to store de-interleaved data */
     
    176194
    177195#ifdef HAVE_SAMPLERATE
    178   if (s->resampler) {
    179     aubio_resampler_do(s->resampler, s->input_data, read_data);
     196  if (s->resamplers) {
     197    aubio_resampler_do(s->resamplers[0], s->input_data, read_data);
    180198  }
    181199#endif /* HAVE_SAMPLERATE */
     
    194212  uint_t i,j, input_channels = s->input_channels;
    195213  /* do actual reading */
    196   sf_count_t read_samples = sf_read_float (s->handle, s->scratch_data, s->scratch_size);
     214  sf_count_t read_samples = aubio_sf_read_smpl (s->handle, s->scratch_data, s->scratch_size);
    197215
    198216  /* where to store de-interleaved data */
     
    200218#ifdef HAVE_SAMPLERATE
    201219  if (s->ratio != 1) {
    202     AUBIO_ERR("source_sndfile: no multi channel resampling yet\n");
    203     return;
    204     //ptr_data = s->input_data->data;
     220    ptr_data = s->input_mat->data;
    205221  } else
    206222#endif /* HAVE_SAMPLERATE */
     
    214230    for (j = 0; j < read_samples / input_channels; j++) {
    215231      for (i = 0; i < read_data->height; i++) {
    216         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];
     232        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    217233      }
    218234    }
     
    222238    for (j = 0; j < read_samples / input_channels; j++) {
    223239      for (i = 0; i < input_channels; i++) {
    224         ptr_data[i][j] = (smpl_t)s->scratch_data[j * input_channels + i];
     240        ptr_data[i][j] = s->scratch_data[j * input_channels + i];
    225241      }
    226242    }
     
    232248    for (j = 0; j < read_samples / input_channels; j++) {
    233249      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)];
    235       }
    236     }
    237   }
    238 
    239 #ifdef HAVE_SAMPLERATE
    240   if (s->resampler) {
    241     //aubio_resampler_do(s->resampler, s->input_data, read_data);
     250        ptr_data[i][j] = s->scratch_data[j * input_channels + (input_channels - 1)];
     251      }
     252    }
     253  }
     254
     255#ifdef HAVE_SAMPLERATE
     256  if (s->resamplers) {
     257    for (i = 0; i < input_channels; i++) {
     258      fvec_t input_chan, read_chan;
     259      input_chan.data = s->input_mat->data[i];
     260      input_chan.length = s->input_mat->length;
     261      read_chan.data = read_data->data[i];
     262      read_chan.length = read_data->length;
     263      aubio_resampler_do(s->resamplers[i], &input_chan, &read_chan);
     264    }
    242265  }
    243266#endif /* HAVE_SAMPLERATE */
     
    263286}
    264287
     288uint_t aubio_source_sndfile_get_duration (const aubio_source_sndfile_t * s) {
     289  if (s && s->duration) {
     290    return s->duration;
     291  }
     292  return 0;
     293}
     294
    265295uint_t aubio_source_sndfile_seek (aubio_source_sndfile_t * s, uint_t pos) {
    266296  uint_t resampled_pos = (uint_t)ROUND(pos / s->ratio);
    267   sf_count_t sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET);
     297  sf_count_t sf_ret;
     298  if (s->handle == NULL) {
     299    AUBIO_ERR("source_sndfile: failed seeking in %s (file not opened?)\n",
     300        s->path);
     301    return AUBIO_FAIL;
     302  }
     303  if ((sint_t)pos < 0) {
     304    AUBIO_ERR("source_sndfile: could not seek %s at %d (seeking position"
     305       " should be >= 0)\n", s->path, pos);
     306    return AUBIO_FAIL;
     307  }
     308  sf_ret = sf_seek (s->handle, resampled_pos, SEEK_SET);
    268309  if (sf_ret == -1) {
    269310    AUBIO_ERR("source_sndfile: Failed seeking %s at %d: %s\n", s->path, pos, sf_strerror (NULL));
     
    280321uint_t aubio_source_sndfile_close (aubio_source_sndfile_t *s) {
    281322  if (!s->handle) {
    282     return AUBIO_FAIL;
     323    return AUBIO_OK;
    283324  }
    284325  if(sf_close(s->handle)) {
     
    286327    return AUBIO_FAIL;
    287328  }
     329  s->handle = NULL;
    288330  return AUBIO_OK;
    289331}
     
    293335  aubio_source_sndfile_close(s);
    294336#ifdef HAVE_SAMPLERATE
    295   if (s->resampler != NULL) {
    296     del_aubio_resampler(s->resampler);
     337  if (s->resamplers != NULL) {
     338    uint_t i = 0, input_channels = s->input_channels;
     339    for (i = 0; i < input_channels; i ++) {
     340      if (s->resamplers[i] != NULL) {
     341        del_aubio_resampler(s->resamplers[i]);
     342      }
     343    }
     344    AUBIO_FREE(s->resamplers);
    297345  }
    298346  if (s->input_data) {
    299347    del_fvec(s->input_data);
    300348  }
    301 #endif /* HAVE_SAMPLERATE */
     349  if (s->input_mat) {
     350    del_fmat(s->input_mat);
     351  }
     352#endif /* HAVE_SAMPLERATE */
     353  if (s->path) AUBIO_FREE(s->path);
    302354  AUBIO_FREE(s->scratch_data);
    303355  AUBIO_FREE(s);
  • src/io/source_sndfile.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
     21#include "aubio_priv.h"
    2222
    2323#ifdef HAVE_WAVREAD
    2424
    25 #include "aubio_priv.h"
    2625#include "fvec.h"
    2726#include "fmat.h"
     
    5352  uint_t eof;
    5453
     54  uint_t duration;
     55
    5556  size_t seek_start;
    5657
     
    5960};
    6061
    61 unsigned int read_little_endian (unsigned char *buf, unsigned int length);
    62 unsigned int read_little_endian (unsigned char *buf, unsigned int length) {
     62static unsigned int read_little_endian (unsigned char *buf,
     63    unsigned int length);
     64
     65static unsigned int read_little_endian (unsigned char *buf,
     66    unsigned int length)
     67{
    6368  uint_t i, ret = 0;
    6469  for (i = 0; i < length; i++) {
     
    6873}
    6974
    70 aubio_source_wavread_t * new_aubio_source_wavread(char_t * path, uint_t samplerate, uint_t hop_size) {
     75aubio_source_wavread_t * new_aubio_source_wavread(const char_t * path, uint_t samplerate, uint_t hop_size) {
    7176  aubio_source_wavread_t * s = AUBIO_NEW(aubio_source_wavread_t);
    72   size_t bytes_read = 0, bytes_expected = 44;
    73   unsigned char buf[5];
    74   unsigned int format, channels, sr, byterate, blockalign, bitspersample;//, data_size;
     77  size_t bytes_read = 0, bytes_junk = 0, bytes_expected = 44;
     78  unsigned char buf[5] = "\0";
     79  unsigned int format, channels, sr, byterate, blockalign, duration, bitspersample;//, data_size;
    7580
    7681  if (path == NULL) {
     
    8792  }
    8893
    89   s->path = path;
     94  if (s->path) AUBIO_FREE(s->path);
     95  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
     96  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     97
    9098  s->samplerate = samplerate;
    9199  s->hop_size = hop_size;
     
    101109  buf[4] = '\0';
    102110  if ( strcmp((const char *)buf, "RIFF") != 0 ) {
    103     AUBIO_ERR("source_wavread: could not find RIFF header in %s\n", s->path);
     111    AUBIO_ERR("source_wavread: Failed opening %s (could not find RIFF header)\n", s->path);
    104112    goto beach;
    105113  }
     
    112120  buf[4] = '\0';
    113121  if ( strcmp((const char *)buf, "WAVE") != 0 ) {
    114     AUBIO_ERR("source_wavread: wrong format in RIFF header in %s\n", s->path);
     122    AUBIO_ERR("source_wavread: Failed opening %s (wrong format in RIFF header)\n", s->path);
    115123    goto beach;
    116124  }
     
    119127  bytes_read += fread(buf, 1, 4, s->fid);
    120128  buf[4] = '\0';
     129
     130  // check if we have a JUNK Chunk
     131  if ( strcmp((const char *)buf, "JUNK") == 0 ) {
     132    bytes_junk = fread(buf, 1, 4, s->fid);
     133    buf[4] = '\0';
     134    bytes_junk += read_little_endian(buf, 4);
     135    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
     136      AUBIO_ERR("source_wavread: Failed opening %s (could not seek past JUNK Chunk: %s)\n",
     137          s->path, strerror(errno));
     138      goto beach;
     139    }
     140    bytes_read += bytes_junk;
     141    bytes_expected += bytes_junk + 4;
     142    // now really read the fmt chunk
     143    bytes_read += fread(buf, 1, 4, s->fid);
     144    buf[4] = '\0';
     145  }
     146
     147  // get the fmt chunk
    121148  if ( strcmp((const char *)buf, "fmt ") != 0 ) {
    122     AUBIO_ERR("source_wavread: fmt RIFF header in %s\n", s->path);
     149    AUBIO_ERR("source_wavread: Failed opening %s (could not find 'fmt ' in RIFF header)\n", s->path);
    123150    goto beach;
    124151  }
     
    129156  if ( format != 16 ) {
    130157    // TODO accept format 18
    131     AUBIO_ERR("source_wavread: file %s is not encoded with PCM\n", s->path);
     158    AUBIO_ERR("source_wavread: Failed opening %s (not encoded with PCM)\n", s->path);
    132159    goto beach;
    133160  }
    134161  if ( buf[1] || buf[2] | buf[3] ) {
    135     AUBIO_ERR("source_wavread: Subchunk1Size should be 0, in %s\n", s->path);
     162    AUBIO_ERR("source_wavread: Failed opening %s (Subchunk1Size should be 0)\n", s->path);
    136163    goto beach;
    137164  }
     
    140167  bytes_read += fread(buf, 1, 2, s->fid);
    141168  if ( buf[0] != 1 || buf[1] != 0) {
    142     AUBIO_ERR("source_wavread: AudioFormat should be PCM, in %s\n", s->path);
     169    AUBIO_ERR("source_wavread: Failed opening %s (AudioFormat should be PCM)\n", s->path);
    143170    goto beach;
    144171  }
     
    172199
    173200  if ( byterate * 8 != sr * channels * bitspersample ) {
    174     AUBIO_ERR("source_wavread: wrong byterate in %s\n", s->path);
     201    AUBIO_ERR("source_wavread: Failed opening %s (wrong byterate)\n", s->path);
    175202    goto beach;
    176203  }
    177204
    178205  if ( blockalign * 8 != channels * bitspersample ) {
    179     AUBIO_ERR("source_wavread: wrong blockalign in %s\n", s->path);
     206    AUBIO_ERR("source_wavread: Failed opening %s (wrong blockalign)\n", s->path);
    180207    goto beach;
    181208  }
     
    206233  bytes_read += fread(buf, 1, 4, s->fid);
    207234  buf[4] = '\0';
    208   if ( strcmp((const char *)buf, "data") != 0 ) {
    209     AUBIO_ERR("source_wavread: data RIFF header not found in %s\n", s->path);
    210     goto beach;
     235  while ( strcmp((const char *)buf, "data") != 0 ) {
     236    if (feof(s->fid) || ferror(s->fid)) {
     237      AUBIO_ERR("source_wavread: no data RIFF header found in %s\n", s->path);
     238      goto beach;
     239    }
     240    bytes_junk = fread(buf, 1, 4, s->fid);
     241    buf[4] = '\0';
     242    bytes_junk += read_little_endian(buf, 4);
     243    if (fseek(s->fid, bytes_read + bytes_junk, SEEK_SET) != 0) {
     244      AUBIO_ERR("source_wavread: could not seek past unknown chunk in %s (%s)\n",
     245          s->path, strerror(errno));
     246      goto beach;
     247    }
     248    bytes_read += bytes_junk;
     249    bytes_expected += bytes_junk+ 4;
     250    bytes_read += fread(buf, 1, 4, s->fid);
     251    buf[4] = '\0';
    211252  }
    212253
    213254  // Subchunk2Size
    214255  bytes_read += fread(buf, 1, 4, s->fid);
     256  duration = read_little_endian(buf, 4) / blockalign;
     257
    215258  //data_size = buf[0] + (buf[1] << 8) + (buf[2] << 16) + (buf[3] << 24);
    216259  //AUBIO_MSG("found %d frames in %s\n", 8 * data_size / bitspersample / channels, s->path);
     
    233276  s->bitspersample = bitspersample;
    234277
     278  s->duration = duration;
     279
    235280  s->short_output = (unsigned char *)calloc(s->blockalign, AUBIO_WAVREAD_BUFSIZE);
    236281  s->read_index = 0;
     
    284329  uint_t end = 0;
    285330  uint_t total_wrote = 0;
     331  if (s->fid == NULL) {
     332    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     333        s->path);
     334    return;
     335  }
    286336  while (total_wrote < s->hop_size) {
    287337    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    318368  uint_t end = 0;
    319369  uint_t total_wrote = 0;
     370  if (s->fid == NULL) {
     371    AUBIO_ERR("source_wavread: could not read from %s (file not opened)\n",
     372        s->path);
     373    return;
     374  }
    320375  while (total_wrote < s->hop_size) {
    321376    end = MIN(s->read_samples - s->read_index, s->hop_size - total_wrote);
     
    358413uint_t aubio_source_wavread_seek (aubio_source_wavread_t * s, uint_t pos) {
    359414  uint_t ret = 0;
     415  if (s->fid == NULL) {
     416    AUBIO_ERR("source_wavread: could not seek %s (file not opened?)\n", s->path, pos);
     417    return AUBIO_FAIL;
     418  }
    360419  if ((sint_t)pos < 0) {
     420    AUBIO_ERR("source_wavread: could not seek %s at %d (seeking position should be >= 0)\n", s->path, pos);
    361421    return AUBIO_FAIL;
    362422  }
     
    372432}
    373433
     434uint_t aubio_source_wavread_get_duration (const aubio_source_wavread_t * s) {
     435  if (s && s->duration) {
     436    return s->duration;
     437  }
     438  return 0;
     439}
     440
    374441uint_t aubio_source_wavread_close (aubio_source_wavread_t * s) {
    375   if (!s->fid) {
    376     return AUBIO_FAIL;
     442  if (s->fid == NULL) {
     443    return AUBIO_OK;
    377444  }
    378445  if (fclose(s->fid)) {
     
    389456  if (s->short_output) AUBIO_FREE(s->short_output);
    390457  if (s->output) del_fmat(s->output);
     458  if (s->path) AUBIO_FREE(s->path);
    391459  AUBIO_FREE(s);
    392460}
  • src/io/source_wavread.h

    r00d0275 r155cc10  
    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

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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    2525#include "mathutils.h"
    2626#include "musicutils.h"
    27 #include "config.h"
    2827
    2928/** Window types */
     
    254253fvec_shift (fvec_t * s)
    255254{
     255  uint_t half = s->length / 2, start = half, j;
     256  // if length is odd, middle element is moved to the end
     257  if (2 * half < s->length) start ++;
    256258#ifndef HAVE_ATLAS
    257   uint_t j;
    258   for (j = 0; j < s->length / 2; j++) {
    259     ELEM_SWAP (s->data[j], s->data[j + s->length / 2]);
    260   }
    261 #else
    262   uint_t half = s->length / 2;
    263   aubio_cblas_swap(half, s->data, 1, s->data + half, 1);
    264 #endif
    265 }
    266 
    267 smpl_t
    268 aubio_level_lin (fvec_t * f)
     259  for (j = 0; j < half; j++) {
     260    ELEM_SWAP (s->data[j], s->data[j + start]);
     261  }
     262#else
     263  aubio_cblas_swap(half, s->data, 1, s->data + start, 1);
     264#endif
     265  if (start != half) {
     266    for (j = 0; j < half; j++) {
     267      ELEM_SWAP (s->data[j + start - 1], s->data[j + start]);
     268    }
     269  }
     270}
     271
     272void
     273fvec_ishift (fvec_t * s)
     274{
     275  uint_t half = s->length / 2, start = half, j;
     276  // if length is odd, middle element is moved to the beginning
     277  if (2 * half < s->length) start ++;
     278#ifndef HAVE_ATLAS
     279  for (j = 0; j < half; j++) {
     280    ELEM_SWAP (s->data[j], s->data[j + start]);
     281  }
     282#else
     283  aubio_cblas_swap(half, s->data, 1, s->data + start, 1);
     284#endif
     285  if (start != half) {
     286    for (j = 0; j < half; j++) {
     287      ELEM_SWAP (s->data[half], s->data[j]);
     288    }
     289  }
     290}
     291
     292smpl_t
     293aubio_level_lin (const fvec_t * f)
    269294{
    270295  smpl_t energy = 0.;
     
    415440}
    416441
    417 smpl_t fvec_quadratic_peak_pos (fvec_t * x, uint_t pos) {
     442smpl_t fvec_quadratic_peak_pos (const fvec_t * x, uint_t pos) {
    418443  smpl_t s0, s1, s2; uint_t x0, x2;
     444  smpl_t half = .5, two = 2.;
    419445  if (pos == 0 || pos == x->length - 1) return pos;
    420446  x0 = (pos < 1) ? pos : pos - 1;
     
    425451  s1 = x->data[pos];
    426452  s2 = x->data[x2];
    427   return pos + 0.5 * (s0 - s2 ) / (s0 - 2.* s1 + s2);
     453  return pos + half * (s0 - s2 ) / (s0 - two * s1 + s2);
    428454}
    429455
     
    439465}
    440466
    441 uint_t fvec_peakpick(fvec_t * onset, uint_t pos) {
     467uint_t fvec_peakpick(const fvec_t * onset, uint_t pos) {
    442468  uint_t tmp=0;
    443469  tmp = (onset->data[pos] > onset->data[pos-1]
     
    526552
    527553smpl_t
    528 aubio_db_spl (fvec_t * o)
     554aubio_db_spl (const fvec_t * o)
    529555{
    530556  return 10. * LOG10 (aubio_level_lin (o));
     
    532558
    533559uint_t
    534 aubio_silence_detection (fvec_t * o, smpl_t threshold)
     560aubio_silence_detection (const fvec_t * o, smpl_t threshold)
    535561{
    536562  return (aubio_db_spl (o) < threshold);
     
    538564
    539565smpl_t
    540 aubio_level_detection (fvec_t * o, smpl_t threshold)
     566aubio_level_detection (const fvec_t * o, smpl_t threshold)
    541567{
    542568  smpl_t db_spl = aubio_db_spl (o);
     
    572598
    573599void
    574 aubio_autocorr (fvec_t * input, fvec_t * output)
     600aubio_autocorr (const fvec_t * input, fvec_t * output)
    575601{
    576602  uint_t i, j, length = input->length;
  • src/mathutils.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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
     
    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
     
    155155
    156156*/
    157 smpl_t aubio_level_detection (fvec_t * v, smpl_t threshold);
     157smpl_t aubio_level_detection (const fvec_t * v, smpl_t threshold);
    158158
    159159#ifdef __cplusplus
     
    161161#endif
    162162
    163 #endif /* _AUBIO__MUSICUTILS_H */
     163#endif /* AUBIO_MUSICUTILS_H */
  • src/onset/onset.c

    r00d0275 r155cc10  
    5252
    5353/* execute onset detection function on iput buffer */
    54 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset)
     54void aubio_onset_do (aubio_onset_t *o, const fvec_t * input, fvec_t * onset)
    5555{
    5656  smpl_t isonset = 0;
     
    100100}
    101101
    102 uint_t aubio_onset_get_last (aubio_onset_t *o)
     102uint_t aubio_onset_get_last (const aubio_onset_t *o)
    103103{
    104104  return o->last_onset - o->delay;
    105105}
    106106
    107 smpl_t aubio_onset_get_last_s (aubio_onset_t *o)
     107smpl_t aubio_onset_get_last_s (const aubio_onset_t *o)
    108108{
    109109  return aubio_onset_get_last (o) / (smpl_t) (o->samplerate);
    110110}
    111111
    112 smpl_t aubio_onset_get_last_ms (aubio_onset_t *o)
     112smpl_t aubio_onset_get_last_ms (const aubio_onset_t *o)
    113113{
    114114  return aubio_onset_get_last_s (o) * 1000.;
     
    131131}
    132132
    133 smpl_t aubio_onset_get_silence(aubio_onset_t * o) {
     133smpl_t aubio_onset_get_silence(const aubio_onset_t * o) {
    134134  return o->silence;
    135135}
     
    140140}
    141141
    142 smpl_t aubio_onset_get_threshold(aubio_onset_t * o) {
     142smpl_t aubio_onset_get_threshold(const aubio_onset_t * o) {
    143143  return aubio_peakpicker_get_threshold(o->pp);
    144144}
     
    149149}
    150150
    151 uint_t aubio_onset_get_minioi(aubio_onset_t * o) {
     151uint_t aubio_onset_get_minioi(const aubio_onset_t * o) {
    152152  return o->minioi;
    153153}
    154154
    155155uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) {
    156   return aubio_onset_set_minioi (o, minioi * o->samplerate);
    157 }
    158 
    159 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o) {
     156  return aubio_onset_set_minioi (o, (uint_t)ROUND(minioi * o->samplerate));
     157}
     158
     159smpl_t aubio_onset_get_minioi_s(const aubio_onset_t * o) {
    160160  return aubio_onset_get_minioi (o) / (smpl_t) o->samplerate;
    161161}
     
    165165}
    166166
    167 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o) {
     167smpl_t aubio_onset_get_minioi_ms(const aubio_onset_t * o) {
    168168  return aubio_onset_get_minioi_s (o) * 1000.;
    169169}
     
    174174}
    175175
    176 uint_t aubio_onset_get_delay(aubio_onset_t * o) {
     176uint_t aubio_onset_get_delay(const aubio_onset_t * o) {
    177177  return o->delay;
    178178}
     
    182182}
    183183
    184 smpl_t aubio_onset_get_delay_s(aubio_onset_t * o) {
     184smpl_t aubio_onset_get_delay_s(const aubio_onset_t * o) {
    185185  return aubio_onset_get_delay (o) / (smpl_t) o->samplerate;
    186186}
     
    190190}
    191191
    192 smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o) {
     192smpl_t aubio_onset_get_delay_ms(const aubio_onset_t * o) {
    193193  return aubio_onset_get_delay_s (o) * 1000.;
    194194}
    195195
    196 smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
     196smpl_t aubio_onset_get_descriptor(const aubio_onset_t * o) {
    197197  return o->desc->data[0];
    198198}
    199199
    200 smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
     200smpl_t aubio_onset_get_thresholded_descriptor(const aubio_onset_t * o) {
    201201  fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    202202  return thresholded->data[0];
     
    204204
    205205/* Allocate memory for an onset detection */
    206 aubio_onset_t * new_aubio_onset (char_t * onset_mode,
     206aubio_onset_t * new_aubio_onset (const char_t * onset_mode,
    207207    uint_t buf_size, uint_t hop_size, uint_t samplerate)
    208208{
     
    213213    AUBIO_ERR("onset: got hop_size %d, but can not be < 1\n", hop_size);
    214214    goto beach;
    215   } else if ((sint_t)buf_size < 1) {
    216     AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", buf_size);
     215  } else if ((sint_t)buf_size < 2) {
     216    AUBIO_ERR("onset: got buffer_size %d, but can not be < 2\n", buf_size);
    217217    goto beach;
    218218  } else if (buf_size < hop_size) {
    219     AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", buf_size, hop_size);
     219    AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", hop_size, buf_size);
    220220    goto beach;
    221221  } else if ((sint_t)samplerate < 1) {
     
    232232  o->pp = new_aubio_peakpicker();
    233233  o->od = new_aubio_specdesc(onset_mode,buf_size);
     234  if (o->od == NULL) goto beach_specdesc;
    234235  o->fftgrain = new_cvec(buf_size);
    235236  o->desc = new_fvec(1);
     
    244245  return o;
    245246
     247beach_specdesc:
     248  del_aubio_peakpicker(o->pp);
     249  del_aubio_pvoc(o->pv);
    246250beach:
    247251  AUBIO_FREE(o);
  • src/onset/onset.h

    r00d0275 r155cc10  
    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 adaptive whitening
     
    150150
    151151*/
    152 smpl_t aubio_onset_get_silence(aubio_onset_t * o);
     152smpl_t aubio_onset_get_silence(const aubio_onset_t * o);
    153153
    154154/** get onset detection function
     
    158158
    159159*/
    160 smpl_t aubio_onset_get_descriptor ( aubio_onset_t *o);
     160smpl_t aubio_onset_get_descriptor (const aubio_onset_t *o);
    161161
    162162/** get thresholded onset detection function
     
    166166
    167167*/
    168 smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);
     168smpl_t aubio_onset_get_thresholded_descriptor (const aubio_onset_t *o);
    169169
    170170/** set onset detection peak picking threshold
     
    237237
    238238*/
    239 uint_t aubio_onset_get_minioi(aubio_onset_t * o);
     239uint_t aubio_onset_get_minioi(const aubio_onset_t * o);
    240240
    241241/** get minimum inter onset interval in seconds
     
    246246
    247247*/
    248 smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o);
     248smpl_t aubio_onset_get_minioi_s(const aubio_onset_t * o);
    249249
    250250/** get minimum inter onset interval in milliseconds
     
    255255
    256256*/
    257 smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o);
     257smpl_t aubio_onset_get_minioi_ms(const aubio_onset_t * o);
    258258
    259259/** get delay in samples
     
    264264
    265265*/
    266 uint_t aubio_onset_get_delay(aubio_onset_t * o);
     266uint_t aubio_onset_get_delay(const aubio_onset_t * o);
    267267
    268268/** get delay in seconds
     
    273273
    274274*/
    275 smpl_t aubio_onset_get_delay_s(aubio_onset_t * o);
     275smpl_t aubio_onset_get_delay_s(const aubio_onset_t * o);
    276276
    277277/** get delay in milliseconds
     
    282282
    283283*/
    284 smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o);
     284smpl_t aubio_onset_get_delay_ms(const aubio_onset_t * o);
    285285
    286286/** get onset peak picking threshold
     
    290290
    291291*/
    292 smpl_t aubio_onset_get_threshold(aubio_onset_t * o);
     292smpl_t aubio_onset_get_threshold(const aubio_onset_t * o);
    293293
    294294/** delete onset detection object
     
    303303#endif
    304304
    305 #endif /* _AUBIO_ONSET_H */
     305#endif /* AUBIO_ONSET_H */
  • src/onset/peakpicker.c

    r00d0275 r155cc10  
    186186   */
    187187  t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789,
    188       -0.59488894, 0.23484048);
     188      // FIXME: broken since c9e20ca, revert for now
     189      //-0.59488894, 0.23484048);
     190      0.23484048, 0);
    189191
    190192  return t;
  • src/onset/peakpicker.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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);
    97 
    98 /* conversion functions for frequency conversions */
    99 smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize);
    100 smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);
    101 smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);
     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);
     98
     99/* internal functions for frequency conversion */
     100static smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize);
     101static smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);
     102static smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);
    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{
    111112  aubio_pitch_t *p = AUBIO_NEW (aubio_pitch_t);
    112113  aubio_pitch_type pitch_type;
     114  if (pitch_mode == NULL) {
     115    AUBIO_ERR ("pitch: can not use ‘NULL‘ for pitch detection method\n");
     116    goto beach;
     117  }
    113118  if (strcmp (pitch_mode, "mcomb") == 0)
    114119    pitch_type = aubio_pitcht_mcomb;
     
    126131    pitch_type = aubio_pitcht_default;
    127132  else {
    128     AUBIO_ERR ("unknown pitch detection method %s, using default.\n",
    129         pitch_mode);
    130     pitch_type = aubio_pitcht_default;
     133    AUBIO_ERR ("pitch: unknown pitch detection method ‘%s’\n", pitch_mode);
     134    goto beach;
    131135  }
    132136
    133137  // check parameters are valid
    134138  if ((sint_t)hopsize < 1) {
    135     AUBIO_ERR("onset: got hopsize %d, but can not be < 1\n", hopsize);
     139    AUBIO_ERR("pitch: got hopsize %d, but can not be < 1\n", hopsize);
    136140    goto beach;
    137141  } else if ((sint_t)bufsize < 1) {
    138     AUBIO_ERR("onset: got buffer_size %d, but can not be < 1\n", bufsize);
     142    AUBIO_ERR("pitch: got buffer_size %d, but can not be < 1\n", bufsize);
    139143    goto beach;
    140144  } else if (bufsize < hopsize) {
    141     AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", bufsize, hopsize);
     145    AUBIO_ERR("pitch: hop size (%d) is larger than win size (%d)\n", hopsize, bufsize);
    142146    goto beach;
    143147  } else if ((sint_t)samplerate < 1) {
    144     AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate);
     148    AUBIO_ERR("pitch: samplerate (%d) can not be < 1\n", samplerate);
    145149    goto beach;
    146150  }
     
    156160      p->buf = new_fvec (bufsize);
    157161      p->p_object = new_aubio_pitchyin (bufsize);
     162      if (!p->p_object) goto beach;
    158163      p->detect_cb = aubio_pitch_do_yin;
    159164      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyin_get_confidence;
     
    161166      break;
    162167    case aubio_pitcht_mcomb:
     168      p->filtered = new_fvec (hopsize);
    163169      p->pv = new_aubio_pvoc (bufsize, hopsize);
     170      if (!p->pv) goto beach;
    164171      p->fftgrain = new_cvec (bufsize);
    165172      p->p_object = new_aubio_pitchmcomb (bufsize, hopsize);
     
    170177      p->buf = new_fvec (bufsize);
    171178      p->p_object = new_aubio_pitchfcomb (bufsize, hopsize);
     179      if (!p->p_object) goto beach;
    172180      p->detect_cb = aubio_pitch_do_fcomb;
    173181      break;
     
    180188      p->buf = new_fvec (bufsize);
    181189      p->p_object = new_aubio_pitchyinfft (samplerate, bufsize);
     190      if (!p->p_object) goto beach;
    182191      p->detect_cb = aubio_pitch_do_yinfft;
    183192      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchyinfft_get_confidence;
     
    187196      p->buf = new_fvec (bufsize);
    188197      p->p_object = new_aubio_pitchspecacf (bufsize);
     198      if (!p->p_object) goto beach;
    189199      p->detect_cb = aubio_pitch_do_specacf;
    190200      p->conf_cb = (aubio_pitch_get_conf_t)aubio_pitchspecacf_get_tolerance;
     
    197207
    198208beach:
     209  if (p->filtered) del_fvec(p->filtered);
     210  if (p->buf) del_fvec(p->buf);
    199211  AUBIO_FREE(p);
    200212  return NULL;
     
    210222      break;
    211223    case aubio_pitcht_mcomb:
     224      del_fvec (p->filtered);
    212225      del_aubio_pvoc (p->pv);
    213226      del_cvec (p->fftgrain);
     
    238251
    239252void
    240 aubio_pitch_slideblock (aubio_pitch_t * p, fvec_t * ibuf)
     253aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf)
    241254{
    242255  uint_t overlap_size = p->buf->length - ibuf->length;
     
    258271
    259272uint_t
    260 aubio_pitch_set_unit (aubio_pitch_t * p, char_t * pitch_unit)
     273aubio_pitch_set_unit (aubio_pitch_t * p, const char_t * pitch_unit)
    261274{
    262275  uint_t err = AUBIO_OK;
     
    281294    pitch_mode = aubio_pitchm_default;
    282295  else {
    283     AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
     296    AUBIO_WRN("pitch: unknown pitch detection unit ‘%s’, using default\n",
     297        pitch_unit);
    284298    pitch_mode = aubio_pitchm_default;
    285299    err = AUBIO_FAIL;
     
    322336}
    323337
     338smpl_t
     339aubio_pitch_get_tolerance (aubio_pitch_t * p)
     340{
     341  smpl_t tolerance = 1.;
     342  switch (p->type) {
     343    case aubio_pitcht_yin:
     344      tolerance = aubio_pitchyin_get_tolerance (p->p_object);
     345      break;
     346    case aubio_pitcht_yinfft:
     347      tolerance = aubio_pitchyinfft_get_tolerance (p->p_object);
     348      break;
     349    default:
     350      break;
     351  }
     352  return tolerance;
     353}
     354
    324355uint_t
    325356aubio_pitch_set_silence (aubio_pitch_t * p, smpl_t silence)
     
    329360    return AUBIO_OK;
    330361  } else {
    331     AUBIO_ERR("pitch: could not set silence to %.2f", silence);
     362    AUBIO_WRN("pitch: could not set silence to %.2f\n", silence);
    332363    return AUBIO_FAIL;
    333364  }
     
    343374/* do method, calling the detection callback, then the conversion callback */
    344375void
    345 aubio_pitch_do (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     376aubio_pitch_do (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    346377{
    347378  p->detect_cb (p, ibuf, obuf);
     
    354385/* do method for each algorithm */
    355386void
    356 aubio_pitch_do_mcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
    357 {
    358   aubio_filter_do (p->filter, ibuf);
     387aubio_pitch_do_mcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
     388{
     389  aubio_filter_do_outplace (p->filter, ibuf, p->filtered);
    359390  aubio_pvoc_do (p->pv, ibuf, p->fftgrain);
    360391  aubio_pitchmcomb_do (p->p_object, p->fftgrain, obuf);
     
    363394
    364395void
    365 aubio_pitch_do_yin (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     396aubio_pitch_do_yin (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    366397{
    367398  smpl_t pitch = 0.;
     
    379410
    380411void
    381 aubio_pitch_do_yinfft (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * obuf)
     412aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf)
    382413{
    383414  smpl_t pitch = 0.;
     
    394425
    395426void
    396 aubio_pitch_do_specacf (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     427aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    397428{
    398429  smpl_t pitch = 0., period;
     
    410441
    411442void
    412 aubio_pitch_do_fcomb (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     443aubio_pitch_do_fcomb (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    413444{
    414445  aubio_pitch_slideblock (p, ibuf);
     
    418449
    419450void
    420 aubio_pitch_do_schmitt (aubio_pitch_t * p, fvec_t * ibuf, fvec_t * out)
     451aubio_pitch_do_schmitt (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * out)
    421452{
    422453  smpl_t period, pitch = 0.;
  • src/pitch/pitch.h

    r00d0275 r155cc10  
    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
     
    117117*/
    118118uint_t aubio_pitch_set_tolerance (aubio_pitch_t * o, smpl_t tol);
     119
     120/** get yin or yinfft tolerance threshold
     121
     122  \param o pitch detection object as returned by new_aubio_pitch()
     123  \return tolerance (default is 0.15 for yin and 0.85 for yinfft)
     124
     125*/
     126smpl_t aubio_pitch_get_tolerance (aubio_pitch_t * o);
    119127
    120128/** deletion of the pitch detection object
     
    135143
    136144*/
    137 aubio_pitch_t *new_aubio_pitch (char_t * method,
     145aubio_pitch_t *new_aubio_pitch (const char_t * method,
    138146    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    139147
     
    143151  \param mode set pitch units for output
    144152
     153  mode can be one of "Hz", "midi", "cent", or "bin". Defaults to "Hz".
     154
    145155  \return 0 if successfull, non-zero otherwise
    146156
    147157*/
    148 uint_t aubio_pitch_set_unit (aubio_pitch_t * o, char_t * mode);
     158uint_t aubio_pitch_set_unit (aubio_pitch_t * o, const char_t * mode);
    149159
    150160/** set the silence threshold of the pitch detection object
     
    180190#endif
    181191
    182 #endif /* _AUBIO_PITCH_H */
     192#endif /* AUBIO_PITCH_H */
  • src/pitch/pitchfcomb.c

    r00d0275 r155cc10  
    5454  p->fftSize = bufsize;
    5555  p->stepSize = hopsize;
     56  p->fft = new_aubio_fft (bufsize);
     57  if (!p->fft) goto beach;
    5658  p->winput = new_fvec (bufsize);
    5759  p->fftOut = new_cvec (bufsize);
    5860  p->fftLastPhase = new_fvec (bufsize);
    59   p->fft = new_aubio_fft (bufsize);
    6061  p->win = new_aubio_window ("hanning", bufsize);
    6162  return p;
     63
     64beach:
     65  AUBIO_FREE(p);
     66  return NULL;
    6267}
    6368
    6469/* input must be stepsize long */
    6570void
    66 aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, fvec_t * input, fvec_t * output)
     71aubio_pitchfcomb_do (aubio_pitchfcomb_t * p, const fvec_t * input, fvec_t * output)
    6772{
    6873  uint_t k, l, maxharm = 0;
  • src/pitch/pitchfcomb.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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;
     
    365365  uint_t i, j;
    366366  uint_t spec_size;
    367   p->spec_partition = 4;
     367  p->spec_partition = 2;
    368368  p->ncand = 5;
    369369  p->npartials = 5;
     
    377377  p->phasefreq = bufsize / hopsize / TWO_PI;
    378378  p->phasediff = TWO_PI * hopsize / bufsize;
    379   spec_size = bufsize / p->spec_partition;
     379  spec_size = bufsize / p->spec_partition + 1;
    380380  //p->pickerfn = quadpick;
    381381  //p->biquad = new_biquad(0.1600,0.3200,0.1600, -0.5949, 0.2348);
  • src/pitch/pitchmcomb.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    4343{
    4444  aubio_pitchspecacf_t *p = AUBIO_NEW (aubio_pitchspecacf_t);
     45  p->fft = new_aubio_fft (bufsize);
     46  if (!p->fft) goto beach;
    4547  p->win = new_aubio_window ("hanningz", bufsize);
    4648  p->winput = new_fvec (bufsize);
    47   p->fft = new_aubio_fft (bufsize);
    4849  p->fftout = new_fvec (bufsize);
    4950  p->sqrmag = new_fvec (bufsize);
     
    5253  p->confidence = 0.;
    5354  return p;
     55
     56beach:
     57  AUBIO_FREE(p);
     58  return NULL;
    5459}
    5560
    5661void
    57 aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, fvec_t * input, fvec_t * output)
     62aubio_pitchspecacf_do (aubio_pitchspecacf_t * p, const fvec_t * input, fvec_t * output)
    5863{
    5964  uint_t l, tau;
     
    9297
    9398smpl_t
    94 aubio_pitchspecacf_get_confidence (aubio_pitchspecacf_t * o) {
     99aubio_pitchspecacf_get_confidence (const aubio_pitchspecacf_t * o) {
    95100  // no confidence for now
    96101  return o->confidence;
     
    105110
    106111smpl_t
    107 aubio_pitchspecacf_get_tolerance (aubio_pitchspecacf_t * p)
     112aubio_pitchspecacf_get_tolerance (const aubio_pitchspecacf_t * p)
    108113{
    109114  return p->tol;
  • src/pitch/pitchspecacf.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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;
     
    128128}
    129129
    130 
    131130/* all the above in one */
    132131void
    133 aubio_pitchyin_do (aubio_pitchyin_t * o, fvec_t * input, fvec_t * out)
     132aubio_pitchyin_do (aubio_pitchyin_t * o, const fvec_t * input, fvec_t * out)
    134133{
    135   smpl_t tol = o->tol;
    136   fvec_t *yin = o->yin;
    137   uint_t j, tau = 0;
     134  const smpl_t tol = o->tol;
     135  fvec_t* yin = o->yin;
     136  const smpl_t *input_data = input->data;
     137  const uint_t length = yin->length;
     138  smpl_t *yin_data = yin->data;
     139  uint_t j, tau;
    138140  sint_t period;
    139   smpl_t tmp = 0., tmp2 = 0.;
    140   yin->data[0] = 1.;
    141   for (tau = 1; tau < yin->length; tau++) {
    142     yin->data[tau] = 0.;
    143     for (j = 0; j < yin->length; j++) {
    144       tmp = input->data[j] - input->data[j + tau];
    145       yin->data[tau] += SQR (tmp);
     141  smpl_t tmp, tmp2 = 0.;
     142
     143  yin_data[0] = 1.;
     144  for (tau = 1; tau < length; tau++) {
     145    yin_data[tau] = 0.;
     146    for (j = 0; j < length; j++) {
     147      tmp = input_data[j] - input_data[j + tau];
     148      yin_data[tau] += SQR (tmp);
    146149    }
    147     tmp2 += yin->data[tau];
     150    tmp2 += yin_data[tau];
    148151    if (tmp2 != 0) {
    149152      yin->data[tau] *= tau / tmp2;
     
    152155    }
    153156    period = tau - 3;
    154     if (tau > 4 && (yin->data[period] < tol) &&
    155         (yin->data[period] < yin->data[period + 1])) {
     157    if (tau > 4 && (yin_data[period] < tol) &&
     158        (yin_data[period] < yin_data[period + 1])) {
    156159      out->data[0] = fvec_quadratic_peak_pos (yin, period);
    157160      goto beach;
  • src/pitch/pitchyin.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    6363  p->winput = new_fvec (bufsize);
    6464  p->fft = new_aubio_fft (bufsize);
     65  if (!p->fft) goto beach;
    6566  p->fftout = new_fvec (bufsize);
    6667  p->sqrmag = new_fvec (bufsize);
     
    9697  p->short_period = (uint_t)ROUND(samplerate / 1300.);
    9798  return p;
     99
     100beach:
     101  if (p->winput) del_fvec(p->winput);
     102  AUBIO_FREE(p);
     103  return NULL;
    98104}
    99105
    100106void
    101 aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, fvec_t * input, fvec_t * output)
     107aubio_pitchyinfft_do (aubio_pitchyinfft_t * p, const fvec_t * input, fvec_t * output)
    102108{
    103109  uint_t tau, l;
  • src/pitch/pitchyinfft.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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
     
    115115#else                         // using OOURA
    116116// let's use ooura instead
    117 extern void rdft(int, int, smpl_t *, int *, smpl_t *);
     117extern void aubio_ooura_rdft(int, int, smpl_t *, int *, smpl_t *);
    118118
    119119#endif /* HAVE_ACCELERATE */
     
    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  }
     
    189189#else                         // using OOURA
    190190  if (aubio_is_power_of_two(winsize) != 1) {
    191     AUBIO_ERR("fft: can only create with sizes power of two,"
    192               " requested %d\n", winsize);
     191    AUBIO_ERR("fft: can only create with sizes power of two, requested %d,"
     192        " try recompiling aubio with --enable-fftw3\n", winsize);
    193193    goto beach;
    194194  }
     
    213213  del_fvec(s->compspec);
    214214#ifdef HAVE_FFTW3             // using FFTW3
     215  pthread_mutex_lock(&aubio_fftw_mutex);
    215216  fftw_destroy_plan(s->pfw);
    216217  fftw_destroy_plan(s->pbw);
    217218  fftw_free(s->specdata);
     219  pthread_mutex_unlock(&aubio_fftw_mutex);
    218220#else /* HAVE_FFTW3 */
    219221#ifdef HAVE_ACCELERATE        // using ACCELERATE
     
    231233}
    232234
    233 void aubio_fft_do(aubio_fft_t * s, fvec_t * input, cvec_t * spectrum) {
     235void aubio_fft_do(aubio_fft_t * s, const fvec_t * input, cvec_t * spectrum) {
    234236  aubio_fft_do_complex(s, input, s->compspec);
    235237  aubio_fft_get_spectrum(s->compspec, spectrum);
    236238}
    237239
    238 void aubio_fft_rdo(aubio_fft_t * s, cvec_t * spectrum, fvec_t * output) {
     240void aubio_fft_rdo(aubio_fft_t * s, const cvec_t * spectrum, fvec_t * output) {
    239241  aubio_fft_get_realimag(spectrum, s->compspec);
    240242  aubio_fft_rdo_complex(s, s->compspec, output);
    241243}
    242244
    243 void aubio_fft_do_complex(aubio_fft_t * s, fvec_t * input, fvec_t * compspec) {
     245void aubio_fft_do_complex(aubio_fft_t * s, const fvec_t * input, fvec_t * compspec) {
    244246  uint_t i;
    245247#ifndef HAVE_MEMCPY_HACKS
     
    281283  aubio_vDSP_vsmul(compspec->data, 1, &scale, compspec->data, 1, s->fft_size);
    282284#else                         // using OOURA
    283   rdft(s->winsize, 1, s->in, s->ip, s->w);
     285  aubio_ooura_rdft(s->winsize, 1, s->in, s->ip, s->w);
    284286  compspec->data[0] = s->in[0];
    285287  compspec->data[s->winsize / 2] = s->in[1];
     
    292294}
    293295
    294 void aubio_fft_rdo_complex(aubio_fft_t * s, fvec_t * compspec, fvec_t * output) {
     296void aubio_fft_rdo_complex(aubio_fft_t * s, const fvec_t * compspec, fvec_t * output) {
    295297  uint_t i;
    296298#ifdef HAVE_FFTW3
     
    339341    s->out[2 * i + 1] = - compspec->data[s->winsize - i];
    340342  }
    341   rdft(s->winsize, -1, s->out, s->ip, s->w);
     343  aubio_ooura_rdft(s->winsize, -1, s->out, s->ip, s->w);
    342344  for (i=0; i < s->winsize; i++) {
    343345    output->data[i] = s->out[i] * scale;
     
    347349}
    348350
    349 void aubio_fft_get_spectrum(fvec_t * compspec, cvec_t * spectrum) {
     351void aubio_fft_get_spectrum(const fvec_t * compspec, cvec_t * spectrum) {
    350352  aubio_fft_get_phas(compspec, spectrum);
    351353  aubio_fft_get_norm(compspec, spectrum);
    352354}
    353355
    354 void aubio_fft_get_realimag(cvec_t * spectrum, fvec_t * compspec) {
     356void aubio_fft_get_realimag(const cvec_t * spectrum, fvec_t * compspec) {
    355357  aubio_fft_get_imag(spectrum, compspec);
    356358  aubio_fft_get_real(spectrum, compspec);
    357359}
    358360
    359 void aubio_fft_get_phas(fvec_t * compspec, cvec_t * spectrum) {
     361void aubio_fft_get_phas(const fvec_t * compspec, cvec_t * spectrum) {
    360362  uint_t i;
    361363  if (compspec->data[0] < 0) {
     
    375377}
    376378
    377 void aubio_fft_get_norm(fvec_t * compspec, cvec_t * spectrum) {
     379void aubio_fft_get_norm(const fvec_t * compspec, cvec_t * spectrum) {
    378380  uint_t i = 0;
    379381  spectrum->norm[0] = ABS(compspec->data[0]);
     
    386388}
    387389
    388 void aubio_fft_get_imag(cvec_t * spectrum, fvec_t * compspec) {
     390void aubio_fft_get_imag(const cvec_t * spectrum, fvec_t * compspec) {
    389391  uint_t i;
    390392  for (i = 1; i < ( compspec->length + 1 ) / 2 /*- 1 + 1*/; i++) {
     
    394396}
    395397
    396 void aubio_fft_get_real(cvec_t * spectrum, fvec_t * compspec) {
     398void aubio_fft_get_real(const cvec_t * spectrum, fvec_t * compspec) {
    397399  uint_t i;
    398400  for (i = 0; i < compspec->length / 2 + 1; i++) {
  • src/spectral/fft.h

    r00d0275 r155cc10  
    2828    - [vDSP](https://developer.apple.com/library/mac/#documentation/Accelerate/Reference/vDSPRef/Reference/reference.html)
    2929
    30   \example src/spectral/test-fft.c
     30  \example spectral/test-fft.c
    3131
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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/ooura_fft8g.c

    r00d0275 r155cc10  
    33//  - include "aubio_priv.h" (for config.h and types.h)
    44//  - add missing prototypes
    5 //  - use COS and SIN macros
     5//  - use COS, SIN, and ATAN macros
     6//  - add cast to (smpl_t) to avoid float conversion warnings
     7//  - declare initialization as static
     8//  - prefix public function with aubio_ooura_
    69
    710#include "aubio_priv.h"
    811
    9 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    10 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    11 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    12 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
    13 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
    14 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
    15 void makewt(int nw, int *ip, smpl_t *w);
    16 void makect(int nc, int *ip, smpl_t *c);
    17 void bitrv2(int n, int *ip, smpl_t *a);
    18 void bitrv2conj(int n, int *ip, smpl_t *a);
    19 void cftfsub(int n, smpl_t *a, smpl_t *w);
    20 void cftbsub(int n, smpl_t *a, smpl_t *w);
    21 void cft1st(int n, smpl_t *a, smpl_t *w);
    22 void cftmdl(int n, int l, smpl_t *a, smpl_t *w);
    23 void rftfsub(int n, smpl_t *a, int nc, smpl_t *c);
    24 void rftbsub(int n, smpl_t *a, int nc, smpl_t *c);
    25 void dctsub(int n, smpl_t *a, int nc, smpl_t *c);
    26 void dstsub(int n, smpl_t *a, int nc, smpl_t *c);
     12void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     13void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     14void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     15void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w);
     16void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
     17void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w);
     18static void makewt(int nw, int *ip, smpl_t *w);
     19static void makect(int nc, int *ip, smpl_t *c);
     20static void bitrv2(int n, int *ip, smpl_t *a);
     21static void bitrv2conj(int n, int *ip, smpl_t *a);
     22static void cftfsub(int n, smpl_t *a, smpl_t *w);
     23static void cftbsub(int n, smpl_t *a, smpl_t *w);
     24static void cft1st(int n, smpl_t *a, smpl_t *w);
     25static void cftmdl(int n, int l, smpl_t *a, smpl_t *w);
     26static void rftfsub(int n, smpl_t *a, int nc, smpl_t *c);
     27static void rftbsub(int n, smpl_t *a, int nc, smpl_t *c);
     28static void dctsub(int n, smpl_t *a, int nc, smpl_t *c);
     29static void dstsub(int n, smpl_t *a, int nc, smpl_t *c);
    2730
    2831/*
     
    303306
    304307
    305 void cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     308void aubio_ooura_cdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    306309{
    307310    void makewt(int nw, int *ip, smpl_t *w);
     
    328331
    329332
    330 void rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     333void aubio_ooura_rdft(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    331334{
    332335    void makewt(int nw, int *ip, smpl_t *w);
     
    362365        a[1] = xi;
    363366    } else {
    364         a[1] = 0.5 * (a[0] - a[1]);
     367        a[1] = (smpl_t)0.5 * (a[0] - a[1]);
    365368        a[0] -= a[1];
    366369        if (n > 4) {
     
    375378
    376379
    377 void ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     380void aubio_ooura_ddct(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    378381{
    379382    void makewt(int nw, int *ip, smpl_t *w);
     
    434437
    435438
    436 void ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
     439void aubio_ooura_ddst(int n, int isgn, smpl_t *a, int *ip, smpl_t *w)
    437440{
    438441    void makewt(int nw, int *ip, smpl_t *w);
     
    493496
    494497
    495 void dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
     498void aubio_ooura_dfct(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
    496499{
    497500    void makewt(int nw, int *ip, smpl_t *w);
     
    589592
    590593
    591 void dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
     594void aubio_ooura_dfst(int n, smpl_t *a, smpl_t *t, int *ip, smpl_t *w)
    592595{
    593596    void makewt(int nw, int *ip, smpl_t *w);
     
    691694    if (nw > 2) {
    692695        nwh = nw >> 1;
    693         delta = atan(1.0) / nwh;
     696        delta = ATAN(1.0) / nwh;
    694697        w[0] = 1;
    695698        w[1] = 0;
     
    725728    if (nc > 1) {
    726729        nch = nc >> 1;
    727         delta = atan(1.0) / nch;
    728         c[0] = cos(delta * nch);
    729         c[nch] = 0.5 * c[0];
     730        delta = ATAN(1.0) / nch;
     731        c[0] = COS(delta * nch);
     732        c[nch] = (smpl_t)0.5 * c[0];
    730733        for (j = 1; j < nch; j++) {
    731             c[j] = 0.5 * cos(delta * j);
    732             c[nc - j] = 0.5 * sin(delta * j);
     734            c[j] = (smpl_t)0.5 * COS(delta * j);
     735            c[nc - j] = (smpl_t)0.5 * SIN(delta * j);
    733736        }
    734737    }
     
    15861589        k = n - j;
    15871590        kk += ks;
    1588         wkr = 0.5 - c[nc - kk];
     1591        wkr = (smpl_t)0.5 - c[nc - kk];
    15891592        wki = c[kk];
    15901593        xr = a[j] - a[k];
     
    16121615        k = n - j;
    16131616        kk += ks;
    1614         wkr = 0.5 - c[nc - kk];
     1617        wkr = (smpl_t)0.5 - c[nc - kk];
    16151618        wki = c[kk];
    16161619        xr = a[j] - a[k];
  • src/spectral/phasevoc.c

    r00d0275 r155cc10  
    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) {
    86     AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", win_s, hop_s);
     91    AUBIO_ERR("pvoc: hop size (%d) is larger than win size (%d)\n", hop_s, win_s);
    8792    goto beach;
    8893  }
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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;
     
    274274      onset_type = aubio_onset_default;
    275275  else {
    276       AUBIO_ERR("unknown spectral descriptor type %s, using default.\n", onset_mode);
    277       onset_type = aubio_onset_default;
     276      AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode);
     277      AUBIO_FREE(o);
     278      return NULL;
    278279  }
    279280  switch(onset_type) {
    280281    /* for both energy and hfc, only fftgrain->norm is required */
    281     case aubio_onset_energy: 
     282    case aubio_onset_energy:
    282283      break;
    283284    case aubio_onset_hfc:
     
    367368void del_aubio_specdesc (aubio_specdesc_t *o){
    368369  switch(o->onset_type) {
    369     case aubio_onset_energy: 
     370    case aubio_onset_energy:
    370371      break;
    371372    case aubio_onset_hfc:
  • src/spectral/specdesc.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    2020
    2121
    22 #include "config.h"
    2322#include "aubio_priv.h"
    2423#include "fvec.h"
     
    5655}
    5756
    58 uint_t aubio_sampler_load( aubio_sampler_t * o, char_t * uri )
     57uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri )
    5958{
    6059  if (o->source) del_aubio_source(o->source);
    61   o->uri = uri;
     60
     61  if (o->uri) AUBIO_FREE(o->uri);
     62  o->uri = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX));
     63  strncpy(o->uri, uri, strnlen(uri, PATH_MAX));
     64
    6265  o->source = new_aubio_source(uri, o->samplerate, o->blocksize);
    6366  if (o->source) return 0;
     
    6669}
    6770
    68 void aubio_sampler_do ( aubio_sampler_t * o, fvec_t * input, fvec_t * output)
     71void aubio_sampler_do ( aubio_sampler_t * o, const fvec_t * input, fvec_t * output)
    6972{
    7073  uint_t read = 0, i;
     
    8386}
    8487
    85 void aubio_sampler_do_multi ( aubio_sampler_t * o, fmat_t * input, fmat_t * output)
     88void aubio_sampler_do_multi ( aubio_sampler_t * o, const fmat_t * input, fmat_t * output)
    8689{
    8790  uint_t read = 0, i, j;
     
    104107}
    105108
    106 uint_t aubio_sampler_get_playing ( aubio_sampler_t * o )
     109uint_t aubio_sampler_get_playing ( const aubio_sampler_t * o )
    107110{
    108111  return o->playing;
     
    131134    del_aubio_source(o->source);
    132135  }
     136  if (o->uri) AUBIO_FREE(o->uri);
    133137  del_fvec(o->source_output);
    134138  del_fmat(o->source_output_multi);
  • src/synth/sampler.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    2020
    2121
    22 #include "config.h"
    2322#include "aubio_priv.h"
    2423#include "fvec.h"
     
    6968}
    7069
    71 static smpl_t interp_2(fvec_t *input, smpl_t pos) {
     70static smpl_t interp_2(const fvec_t *input, smpl_t pos) {
    7271  uint_t idx = (uint_t)FLOOR(pos);
    7372  smpl_t frac = pos - (smpl_t)idx;
     
    7776}
    7877
    79 void aubio_wavetable_do ( aubio_wavetable_t * s, fvec_t * input, fvec_t * output)
     78void aubio_wavetable_do ( aubio_wavetable_t * s, const fvec_t * input, fvec_t * output)
    8079{
    8180  uint_t i;
     
    108107}
    109108
    110 void aubio_wavetable_do_multi ( aubio_wavetable_t * s, fmat_t * input, fmat_t * output)
     109void aubio_wavetable_do_multi ( aubio_wavetable_t * s, const fmat_t * input, fmat_t * output)
    111110{
    112111  uint_t i, j;
     
    143142}
    144143
    145 uint_t aubio_wavetable_get_playing ( aubio_wavetable_t * s )
     144uint_t aubio_wavetable_get_playing ( const aubio_wavetable_t * s )
    146145{
    147146  return s->playing;
     
    173172}
    174173
    175 smpl_t aubio_wavetable_get_freq ( aubio_wavetable_t * s) {
     174smpl_t aubio_wavetable_get_freq ( const aubio_wavetable_t * s) {
    176175  return aubio_parameter_get_current_value ( s->freq);
    177176}
     
    182181}
    183182
    184 smpl_t aubio_wavetable_get_amp ( aubio_wavetable_t * s) {
     183smpl_t aubio_wavetable_get_amp ( const aubio_wavetable_t * s) {
    185184  return aubio_parameter_get_current_value ( s->amp );
    186185}
  • src/synth/wavetable.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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_period (aubio_beattracking_t * bt)
     412aubio_beattracking_get_period (const aubio_beattracking_t * bt)
    413413{
    414414  return bt->hop_size * bt->bp;
     
    416416
    417417smpl_t
    418 aubio_beattracking_get_period_s (aubio_beattracking_t * bt)
     418aubio_beattracking_get_period_s (const aubio_beattracking_t * bt)
    419419{
    420420  return aubio_beattracking_get_period(bt) / (smpl_t) bt->samplerate;
     
    422422
    423423smpl_t
    424 aubio_beattracking_get_bpm (aubio_beattracking_t * bt)
     424aubio_beattracking_get_bpm (const aubio_beattracking_t * bt)
    425425{
    426426  if (bt->bp != 0) {
     
    432432
    433433smpl_t
    434 aubio_beattracking_get_confidence (aubio_beattracking_t * bt)
     434aubio_beattracking_get_confidence (const aubio_beattracking_t * bt)
    435435{
    436436  if (bt->gp) {
  • src/tempo/beattracking.h

    r00d0275 r155cc10  
    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);
    6969
     
    7676
    7777*/
    78 smpl_t aubio_beattracking_get_period (aubio_beattracking_t * bt);
     78smpl_t aubio_beattracking_get_period (const aubio_beattracking_t * bt);
    7979
    8080/** get current beat period in seconds
     
    8686
    8787*/
    88 smpl_t aubio_beattracking_get_period_s (aubio_beattracking_t * bt);
     88smpl_t aubio_beattracking_get_period_s (const aubio_beattracking_t * bt);
    8989
    9090/** get current tempo in bpm
     
    9696
    9797*/
    98 smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt);
     98smpl_t aubio_beattracking_get_bpm(const aubio_beattracking_t * bt);
    9999
    100100/** get current tempo confidence
     
    106106
    107107*/
    108 smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * bt);
     108smpl_t aubio_beattracking_get_confidence(const aubio_beattracking_t * bt);
    109109
    110110/** delete beat tracking object
     
    119119#endif
    120120
    121 #endif /* _AUBIO_BEATTRACKING_H */
     121#endif /* AUBIO_BEATTRACKING_H */
  • src/tempo/tempo.c

    r00d0275 r155cc10  
    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 */
     
    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 */
    7352  uint_t last_tatum;             /** time of latest detected tatum, in samples */
    7453  uint_t tatum_signature;        /** number of tatum between each beats */
     
    7655
    7756/* execute tempo detection function on iput buffer */
    78 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)
    7958{
    8059  uint_t i;
     
    10180  o->blockpos++;
    10281  aubio_peakpicker_do (o->pp, o->of, o->onset);
    103   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];
    10484  thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    10585  o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0];
     
    125105uint_t aubio_tempo_get_last (aubio_tempo_t *o)
    126106{
    127   return o->last_beat - o->delay;
     107  return o->last_beat + o->delay;
    128108}
    129109
     
    138118}
    139119
    140 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) {
    141121  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;
    142132  return AUBIO_OK;
    143133}
     
    145135uint_t aubio_tempo_get_delay(aubio_tempo_t * o) {
    146136  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.;
    147145}
    148146
     
    167165
    168166/* Allocate memory for an tempo detection */
    169 aubio_tempo_t * new_aubio_tempo (char_t * tempo_mode,
     167aubio_tempo_t * new_aubio_tempo (const char_t * tempo_mode,
    170168    uint_t buf_size, uint_t hop_size, uint_t samplerate)
    171169{
     
    177175    AUBIO_ERR("tempo: got hop size %d, but can not be < 1\n", hop_size);
    178176    goto beach;
    179   } else if ((sint_t)buf_size < 1) {
    180     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);
    181179    goto beach;
    182180  } else if (buf_size < hop_size) {
  • src/tempo/tempo.h

    r00d0275 r155cc10  
    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
     
    155155  \param o beat tracking object
    156156
    157   \return confidence with which the tempo has been observed, `0` if no
    158   consistent value is found.
     157  \return confidence with which the tempo has been observed, the higher the
     158  more confidence, `0` if no consistent value is found.
    159159
    160160*/
    161161smpl_t aubio_tempo_get_confidence(aubio_tempo_t * o);
    162162
    163 /* set number of tatum per beat
     163/** set number of tatum per beat
    164164
    165165   \param o beat tracking object
     
    169169uint_t aubio_tempo_set_tatum_signature(aubio_tempo_t *o, uint_t signature);
    170170
    171 /* check whether a tatum was detected in the current frame
     171/** check whether a tatum was detected in the current frame
    172172
    173173   \param o beat tracking object
     
    178178uint_t aubio_tempo_was_tatum(aubio_tempo_t *o);
    179179
    180 /* get position of last_tatum, in samples
     180/** get position of last_tatum, in samples
    181181
    182182   \param o beat tracking object
     
    184184*/
    185185smpl_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);
    186243
    187244/** delete tempo detection object
     
    196253#endif
    197254
    198 #endif /* _AUBIO_TEMPO_H */
     255#endif /* AUBIO_TEMPO_H */
  • src/temporal/a_weighting.c

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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.c

    r00d0275 r155cc10  
    4242  as->data[0] = 1.;
    4343  as->data[1] = a1;
    44   as->data[1] = a2;
     44  as->data[2] = a2;
    4545  return AUBIO_OK;
    4646}
  • src/temporal/biquad.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
    22 
    2321#include "aubio_priv.h"
    2422#include "fvec.h"
    2523#include "temporal/resampler.h"
    2624
    27 #if HAVE_SAMPLERATE
     25#ifdef HAVE_SAMPLERATE
     26
     27#if HAVE_AUBIO_DOUBLE
     28#error "Should not use libsamplerate with aubio in double precision"
     29#endif
    2830
    2931#include <samplerate.h>         /* from libsamplerate */
     
    6264
    6365void
    64 aubio_resampler_do (aubio_resampler_t * s, fvec_t * input, fvec_t * output)
     66aubio_resampler_do (aubio_resampler_t * s, const fvec_t * input, fvec_t * output)
    6567{
    6668  s->proc->input_frames = input->length;
     
    9395
    9496void
    95 aubio_resampler_do (aubio_resampler_t * s UNUSED, fvec_t * input UNUSED, fvec_t * output UNUSED)
     97aubio_resampler_do (aubio_resampler_t * s UNUSED, const fvec_t * input UNUSED, fvec_t * output UNUSED)
    9698{
    9799}
  • src/temporal/resampler.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    1919*/
    2020
    21 #include "config.h"
    2221#include "aubio_priv.h"
    2322#include "parameter.h"
     
    8584}
    8685
    87 smpl_t aubio_parameter_get_current_value ( aubio_parameter_t * s )
     86smpl_t aubio_parameter_get_current_value ( const aubio_parameter_t * s )
    8887{
    8988  return s->current_value;
     
    110109}
    111110
    112 uint_t aubio_parameter_get_steps ( aubio_parameter_t * param )
     111uint_t aubio_parameter_get_steps ( const aubio_parameter_t * param )
    113112{
    114113  return param->steps;
     
    121120}
    122121
    123 smpl_t aubio_parameter_get_min_value ( aubio_parameter_t * param )
     122smpl_t aubio_parameter_get_min_value ( const aubio_parameter_t * param )
    124123{
    125124  return param->min_value;
     
    132131}
    133132
    134 smpl_t aubio_parameter_get_max_value ( aubio_parameter_t * param )
     133smpl_t aubio_parameter_get_max_value ( const aubio_parameter_t * param )
    135134{
    136135  return param->max_value;
  • src/utils/parameter.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    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.c

    r00d0275 r155cc10  
    1 #include "config.h"
    21#include "aubio_priv.h"
    32#include "types.h"
  • src/vecutils.h

    r00d0275 r155cc10  
    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

    r00d0275 r155cc10  
    22
    33uselib = []
     4uselib += ['M']
    45uselib += ['FFTW3', 'FFTW3F']
    56uselib += ['SAMPLERATE']
     
    1112uselib += ['BLAS']
    1213
    13 # build each source files
    1414source = ctx.path.ant_glob('*.c **/*.c')
     15
    1516ctx(features = 'c',
    1617        source = source,
    1718        includes = ['.'],
    18         uselib = uselib,
    19         lib = 'm',
     19        use = uselib,
    2020        target = 'lib_objects')
    2121
     
    2424    build_features = ['cstlib', 'cshlib']
    2525elif ctx.env['DEST_OS'] in ['win32', 'win64']:
    26     build_features = ['cshlib']
    27 else: #linux, darwin, android, mingw, ...
    28     build_features = ['cshlib', 'cstlib']
     26    build_features = ['cstlib', 'cshlib']
     27elif ctx.env['DEST_OS'] in ['emscripten']:
     28    build_features = ['cstlib']
     29elif '--static' in ctx.env['LDFLAGS'] or '--static' in ctx.env['LINKFLAGS']:
     30    # static in cflags, ...
     31    build_features = ['cstlib']
     32else:
     33    # linux, darwin, android, mingw, ...
     34    build_features = ['cstlib', 'cshlib']
     35
     36# also install static lib
     37from waflib.Tools.c import cstlib
     38from waflib.Tools.fc import fcstlib
     39fcstlib.inst_to = cstlib.inst_to = '${LIBDIR}'
    2940
    3041for target in build_features:
    3142    ctx(features = 'c ' + target,
    32             use = ['lib_objects'],
    33             uselib = uselib,
    34             lib = 'm',
     43            use = uselib + ['lib_objects'],
    3544            target = 'aubio',
    3645            vnum = ctx.env['LIB_VERSION'])
    3746
    3847# install headers, except _priv.h ones
    39 ctx.install_files('${PREFIX}/include/aubio/',
     48ctx.install_files('${INCLUDEDIR}/aubio/',
    4049        ctx.path.ant_glob('**/*.h', excl = ['**_priv.h', 'config.h']),
    4150        relative_trick=True)
Note: See TracChangeset for help on using the changeset viewer.