Changeset 868c6b8


Ignore:
Timestamp:
Dec 19, 2018, 6:16:29 PM (12 months ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/constantq
Children:
dfe6ab6
Parents:
f87e191 (diff), fda3394 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into feature/constantq

Files:
9 added
7 deleted
69 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    rf87e191 r868c6b8  
    66*.gcno
    77*.gcda
     8python/lib/aubio/_aubio.*.so
     9.coverage
    810
    911# ignore compiled examples
  • MANIFEST.in

    rf87e191 r868c6b8  
    1212include src/*/*.c src/*/*.h
    1313include examples/*.c examples/*.h
    14 include tests/*.h tests/*/*.c tests/*/*/*.c
     14recursive-include tests *.h *.c *.py
    1515include python/ext/*.h
    1616recursive-include python *.py
  • Makefile

    rf87e191 r868c6b8  
    262262                --output-file build/coverage.info
    263263        # remove tests
    264         lcov $(LCOVOPTS) --remove build/coverage.info '*/tests/*' '*/ooura_fft8g*' \
     264        lcov $(LCOVOPTS) --remove build/coverage.info '*/ooura_fft8g*' \
    265265                --output-file build/coverage_lib.info
    266266
     
    268268coverage_report: export WAFOPTS += --disable-docs
    269269coverage_report: coverage
    270         # create coverage report dir
    271         mkdir -p build/coverage/
    272270        # generate report with lcov's genhtml
    273         genhtml build/coverage_lib.info --output-directory build/coverage/lcov \
     271        genhtml build/coverage_lib.info --output-directory build/coverage_c \
    274272                --branch-coverage --highlight --legend
    275273        # generate python report with coverage python package
    276274        coverage report
    277         coverage html -d build/coverage/coverage
     275        coverage html -d build/coverage_python
    278276        # show links to generated reports
    279         for i in $$(ls build/coverage/*/index.html); do echo file://$(PWD)/$$i; done
     277        for i in $$(ls build/coverage_*/index.html); do echo file://$(PWD)/$$i; done
    280278
    281279sphinx: configure
  • doc/python.rst

    rf87e191 r868c6b8  
    3131   py_datatypes
    3232   py_io
     33   py_temporal
     34   py_spectral
     35   py_analysis
     36   py_synth
    3337   py_utils
    3438   py_examples
  • examples/aubiomfcc.c

    rf87e191 r868c6b8  
    6969  }
    7070
    71   examples_common_process((aubio_process_func_t)process_block, process_print);
     71  examples_common_process(process_block, process_print);
    7272
    7373  del_aubio_pvoc (pv);
  • examples/aubionotes.c

    rf87e191 r868c6b8  
    9191  }
    9292
    93   examples_common_process((aubio_process_func_t)process_block, process_print);
     93  examples_common_process(process_block, process_print);
    9494
    9595  // send a last note off if required
  • examples/aubioonset.c

    rf87e191 r868c6b8  
    8787  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
    8888
    89   examples_common_process((aubio_process_func_t)process_block, process_print);
     89  examples_common_process(process_block, process_print);
    9090
    9191  // send a last note off
  • examples/aubiopitch.c

    rf87e191 r868c6b8  
    8080  aubio_wavetable_play ( wavetable );
    8181
    82   examples_common_process((aubio_process_func_t)process_block,process_print);
     82  examples_common_process(process_block, process_print);
    8383
    8484  del_aubio_pitch (o);
  • examples/aubioquiet.c

    rf87e191 r868c6b8  
    5656  verbmsg ("buffer_size: %d, ", buffer_size);
    5757  verbmsg ("hop_size: %d\n", hop_size);
    58   examples_common_process((aubio_process_func_t)process_block,process_print);
     58  examples_common_process(process_block, process_print);
    5959  examples_common_del();
    6060  return 0;
  • examples/aubiotrack.c

    rf87e191 r868c6b8  
    8888  //aubio_sampler_load (sampler, "/archives/sounds/woodblock.aiff");
    8989
    90   examples_common_process((aubio_process_func_t)process_block,process_print);
     90  examples_common_process(process_block, process_print);
    9191
    9292  // send a last note off
  • python/README.md

    rf87e191 r868c6b8  
    2828-----
    2929
    30 Some examples are available in the [`python/demos`][demos_dir] folder. Each
     30Some examples are available in the [`python/demos` folder][demos_dir]. Each
    3131script is a command line program which accepts one ore more argument.
    3232
  • python/ext/aubio-types.h

    rf87e191 r868c6b8  
    22#include <structmember.h>
    33
     4#include "aubio-docstrings.h"
    45#include "aubio-generated.h"
    56
  • python/ext/aubiomodule.c

    rf87e191 r868c6b8  
    224224
    225225  // compute the function
    226   result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, fvec_alpha_norm (&vec, alpha));
     226  result = PyFloat_FromDouble(fvec_alpha_norm (&vec, alpha));
    227227  if (result == NULL) {
    228228    return NULL;
     
    320320
    321321  // compute the function
    322   result = Py_BuildValue (AUBIO_NPY_SMPL_CHR, aubio_zero_crossing_rate (&vec));
     322  result = PyFloat_FromDouble(aubio_zero_crossing_rate (&vec));
    323323  if (result == NULL) {
    324324    return NULL;
  • python/ext/py-cvec.c

    rf87e191 r868c6b8  
    137137  }
    138138
    139   args = Py_BuildValue ("I", self->length);
     139  args = PyLong_FromLong(self->length);
    140140  if (args == NULL) {
    141141    goto fail;
  • python/ext/py-fft.c

    rf87e191 r868c6b8  
    11#include "aubio-types.h"
    22
    3 static char Py_fft_doc[] = "fft object";
     3static char Py_fft_doc[] = ""
     4"fft(size=1024)\n"
     5"\n"
     6"Compute Fast Fourier Transorms.\n"
     7"\n"
     8"Parameters\n"
     9"----------\n"
     10"size : int\n"
     11"    size of the FFT to compute\n"
     12"\n"
     13"Example\n"
     14"-------\n"
     15">>> x = aubio.fvec(512)\n"
     16">>> f = aubio.fft(512)\n"
     17">>> c = f(x); c\n"
     18"aubio cvec of 257 elements\n"
     19">>> x2 = f.rdo(c); x2.shape\n"
     20"(512,)\n"
     21"";
    422
    523typedef struct
  • python/ext/py-filter.c

    rf87e191 r868c6b8  
    1111} Py_filter;
    1212
    13 static char Py_filter_doc[] = "filter object";
     13static char Py_filter_doc[] = ""
     14"digital_filter(order=7)\n"
     15"\n"
     16"Create a digital filter.\n"
     17"";
     18
     19static char Py_filter_set_c_weighting_doc[] = ""
     20"set_c_weighting(samplerate)\n"
     21"\n"
     22"Set filter coefficients to C-weighting.\n"
     23"\n"
     24"`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n"
     25"44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 5.\n"
     26"\n"
     27"Parameters\n"
     28"----------\n"
     29"samplerate : int\n"
     30"    Sampling-rate of the input signal, in Hz.\n"
     31"";
     32
     33static char Py_filter_set_a_weighting_doc[] = ""
     34"set_a_weighting(samplerate)\n"
     35"\n"
     36"Set filter coefficients to A-weighting.\n"
     37"\n"
     38"`samplerate` should be one of 8000, 11025, 16000, 22050, 24000, 32000,\n"
     39"44100, 48000, 88200, 96000, or 192000. `order` of the filter should be 7.\n"
     40"\n"
     41"Parameters\n"
     42"----------\n"
     43"samplerate : int\n"
     44"    Sampling-rate of the input signal.\n"
     45"";
     46
     47static char Py_filter_set_biquad_doc[] = ""
     48"set_biquad(b0, b1, b2, a1, a2)\n"
     49"\n"
     50"Set biquad coefficients. `order` of the filter should be 3.\n"
     51"\n"
     52"Parameters\n"
     53"----------\n"
     54"b0 : float\n"
     55"    Forward filter coefficient.\n"
     56"b1 : float\n"
     57"    Forward filter coefficient.\n"
     58"b2 : float\n"
     59"    Forward filter coefficient.\n"
     60"a1 : float\n"
     61"    Feedback filter coefficient.\n"
     62"a2 : float\n"
     63"    Feedback filter coefficient.\n"
     64"";
    1465
    1566static PyObject *
     
    157208static PyMethodDef Py_filter_methods[] = {
    158209  {"set_c_weighting", (PyCFunction) Py_filter_set_c_weighting, METH_VARARGS,
    159       "set filter coefficients to C-weighting"},
     210      Py_filter_set_c_weighting_doc},
    160211  {"set_a_weighting", (PyCFunction) Py_filter_set_a_weighting, METH_VARARGS,
    161       "set filter coefficients to A-weighting"},
     212      Py_filter_set_a_weighting_doc},
    162213  {"set_biquad", (PyCFunction) Py_filter_set_biquad, METH_VARARGS,
    163       "set b0, b1, b2, a1, a2 biquad coefficients"},
     214      Py_filter_set_biquad_doc},
    164215  {NULL}
    165216};
  • python/ext/py-filterbank.c

    rf87e191 r868c6b8  
    11#include "aubio-types.h"
    22
    3 static char Py_filterbank_doc[] = "filterbank object";
     3static char Py_filterbank_doc[] = ""
     4"filterbank(n_filters=40, win_s=1024)\n"
     5"\n"
     6"Create a bank of spectral filters. Each instance is a callable\n"
     7"that holds a matrix of coefficients.\n"
     8"\n"
     9"See also :meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`,\n"
     10":meth:`set_mel_coeffs_slaney`, :meth:`set_triangle_bands`, and\n"
     11":meth:`set_coeffs`.\n"
     12"\n"
     13"Parameters\n"
     14"----------\n"
     15"n_filters : int\n"
     16"    Number of filters to create.\n"
     17"win_s : int\n"
     18"    Size of the input spectrum to process.\n"
     19"\n"
     20"Examples\n"
     21"--------\n"
     22">>> f = aubio.filterbank(128, 1024)\n"
     23">>> f.set_mel_coeffs(44100, 0, 10000)\n"
     24">>> c = aubio.cvec(1024)\n"
     25">>> f(c).shape\n"
     26"(128, )\n"
     27"";
     28
     29static char Py_filterbank_set_triangle_bands_doc[] =""
     30"set_triangle_bands(freqs, samplerate)\n"
     31"\n"
     32"Set triangular bands. The coefficients will be set to triangular\n"
     33"overlapping windows using the boundaries specified by `freqs`.\n"
     34"\n"
     35"`freqs` should contain `n_filters + 2` frequencies in Hz, ordered\n"
     36"by value, from smallest to largest. The first element should be greater\n"
     37"or equal to zero; the last element should be smaller or equal to\n"
     38"`samplerate / 2`.\n"
     39"\n"
     40"Parameters\n"
     41"----------\n"
     42"freqs: fvec\n"
     43"    List of frequencies, in Hz.\n"
     44"samplerate : float\n"
     45"    Sampling-rate of the expected input.\n"
     46"\n"
     47"Example\n"
     48"-------\n"
     49">>> fb = aubio.filterbank(n_filters=100, win_s=2048)\n"
     50">>> samplerate = 44100; freqs = np.linspace(0, 20200, 102)\n"
     51">>> fb.set_triangle_bands(aubio.fvec(freqs), samplerate)\n"
     52"";
     53
     54static char Py_filterbank_set_mel_coeffs_slaney_doc[] = ""
     55"set_mel_coeffs_slaney(samplerate)\n"
     56"\n"
     57"Set coefficients of filterbank to match Slaney's Auditory Toolbox.\n"
     58"\n"
     59"The filter coefficients will be set as in Malcolm Slaney's\n"
     60"implementation. The filterbank should have been created with\n"
     61"`n_filters = 40`.\n"
     62"\n"
     63"This is approximately equivalent to using :meth:`set_mel_coeffs` with\n"
     64"`fmin = 400./3., fmax = 6853.84`.\n"
     65"\n"
     66"Parameters\n"
     67"----------\n"
     68"samplerate : float\n"
     69"    Sampling-rate of the expected input.\n"
     70"\n"
     71"References\n"
     72"----------\n"
     73"\n"
     74"Malcolm Slaney, `Auditory Toolbox Version 2, Technical Report #1998-010\n"
     75"<https://engineering.purdue.edu/~malcolm/interval/1998-010/>`_\n"
     76"";
     77
     78static char Py_filterbank_set_mel_coeffs_doc[] = ""
     79"set_mel_coeffs(samplerate, fmin, fmax)\n"
     80"\n"
     81"Set coefficients of filterbank to linearly spaced mel scale.\n"
     82"\n"
     83"Parameters\n"
     84"----------\n"
     85"samplerate : float\n"
     86"    Sampling-rate of the expected input.\n"
     87"fmin : float\n"
     88"    Lower frequency boundary of the first filter.\n"
     89"fmax : float\n"
     90"    Upper frequency boundary of the last filter.\n"
     91"\n"
     92"See also\n"
     93"--------\n"
     94"hztomel\n"
     95"";
     96
     97static char Py_filterbank_set_mel_coeffs_htk_doc[] = ""
     98"set_mel_coeffs_htk(samplerate, fmin, fmax)\n"
     99"\n"
     100"Set coefficients of the filters to be linearly spaced in the HTK mel scale.\n"
     101"\n"
     102"Parameters\n"
     103"----------\n"
     104"samplerate : float\n"
     105"    Sampling-rate of the expected input.\n"
     106"fmin : float\n"
     107"    Lower frequency boundary of the first filter.\n"
     108"fmax : float\n"
     109"    Upper frequency boundary of the last filter.\n"
     110"\n"
     111"See also\n"
     112"--------\n"
     113"hztomel with `htk=True`\n"
     114"";
     115
     116static char Py_filterbank_get_coeffs_doc[] = ""
     117"get_coeffs()\n"
     118"\n"
     119"Get coefficients matrix of filterbank.\n"
     120"\n"
     121"Returns\n"
     122"-------\n"
     123"array_like\n"
     124"    Array of shape (n_filters, win_s/2+1) containing the coefficients.\n"
     125"";
     126
     127static char Py_filterbank_set_coeffs_doc[] = ""
     128"set_coeffs(coeffs)\n"
     129"\n"
     130"Set coefficients of filterbank.\n"
     131"\n"
     132"Parameters\n"
     133"----------\n"
     134"coeffs : fmat\n"
     135"    Array of shape (n_filters, win_s/2+1) containing the coefficients.\n"
     136"";
     137
     138static char Py_filterbank_set_power_doc[] = ""
     139"set_power(power)\n"
     140"\n"
     141"Set power applied to input spectrum of filterbank.\n"
     142"\n"
     143"Parameters\n"
     144"----------\n"
     145"power : float\n"
     146"    Power to raise input spectrum to before computing the filters.\n"
     147"";
     148
     149static char Py_filterbank_get_power_doc[] = ""
     150"get_power()\n"
     151"\n"
     152"Get power applied to filterbank.\n"
     153"\n"
     154"Returns\n"
     155"-------\n"
     156"float\n"
     157"    Power parameter.\n"
     158"";
     159
     160static char Py_filterbank_set_norm_doc[] = ""
     161"set_norm(norm)\n"
     162"\n"
     163"Set norm parameter. If set to `0`, the filters will not be normalized.\n"
     164"If set to `1`, the filters will be normalized to one. Default to `1`.\n"
     165"\n"
     166"This function should be called *before* :meth:`set_triangle_bands`,\n"
     167":meth:`set_mel_coeffs`, :meth:`set_mel_coeffs_htk`, or\n"
     168":meth:`set_mel_coeffs_slaney`.\n"
     169"\n"
     170"Parameters\n"
     171"----------\n"
     172"norm : int\n"
     173"   `0` to disable, `1` to enable\n"
     174"";
     175
     176static char Py_filterbank_get_norm_doc[] = ""
     177"get_norm()\n"
     178"\n"
     179"Get norm parameter of filterbank.\n"
     180"\n"
     181"Returns\n"
     182"-------\n"
     183"float\n"
     184"    Norm parameter.\n"
     185"";
    4186
    5187typedef struct
     
    290472
    291473static PyObject *
     474Py_filterbank_get_power (Py_filterbank * self, PyObject *unused)
     475{
     476  smpl_t power = aubio_filterbank_get_power(self->o);
     477  return (PyObject *)PyFloat_FromDouble (power);
     478}
     479
     480static PyObject *
    292481Py_filterbank_set_norm(Py_filterbank *self, PyObject *args)
    293482{
     
    312501}
    313502
     503static PyObject *
     504Py_filterbank_get_norm (Py_filterbank * self, PyObject *unused)
     505{
     506  smpl_t norm = aubio_filterbank_get_norm(self->o);
     507  return (PyObject *)PyFloat_FromDouble (norm);
     508}
     509
    314510static PyMethodDef Py_filterbank_methods[] = {
    315511  {"set_triangle_bands", (PyCFunction) Py_filterbank_set_triangle_bands,
    316     METH_VARARGS, "set coefficients of filterbanks"},
     512    METH_VARARGS, Py_filterbank_set_triangle_bands_doc},
    317513  {"set_mel_coeffs_slaney", (PyCFunction) Py_filterbank_set_mel_coeffs_slaney,
    318     METH_VARARGS, "set coefficients of filterbank as in Auditory Toolbox"},
     514    METH_VARARGS, Py_filterbank_set_mel_coeffs_slaney_doc},
    319515  {"set_mel_coeffs", (PyCFunction) Py_filterbank_set_mel_coeffs,
    320     METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
     516    METH_VARARGS, Py_filterbank_set_mel_coeffs_doc},
    321517  {"set_mel_coeffs_htk", (PyCFunction) Py_filterbank_set_mel_coeffs_htk,
    322     METH_VARARGS, "set coefficients of filterbank to linearly spaced mel scale"},
     518    METH_VARARGS, Py_filterbank_set_mel_coeffs_htk_doc},
    323519  {"get_coeffs", (PyCFunction) Py_filterbank_get_coeffs,
    324     METH_NOARGS, "get coefficients of filterbank"},
     520    METH_NOARGS, Py_filterbank_get_coeffs_doc},
    325521  {"set_coeffs", (PyCFunction) Py_filterbank_set_coeffs,
    326     METH_VARARGS, "set coefficients of filterbank"},
     522    METH_VARARGS, Py_filterbank_set_coeffs_doc},
    327523  {"set_power", (PyCFunction) Py_filterbank_set_power,
    328     METH_VARARGS, "set power applied to filterbank input spectrum"},
     524    METH_VARARGS, Py_filterbank_set_power_doc},
     525  {"get_power", (PyCFunction) Py_filterbank_get_power,
     526    METH_NOARGS, Py_filterbank_get_power_doc},
    329527  {"set_norm", (PyCFunction) Py_filterbank_set_norm,
    330     METH_VARARGS, "set norm applied to filterbank input spectrum"},
     528    METH_VARARGS, Py_filterbank_set_norm_doc},
     529  {"get_norm", (PyCFunction) Py_filterbank_get_norm,
     530    METH_NOARGS, Py_filterbank_get_norm_doc},
    331531  {NULL}
    332532};
  • python/ext/py-musicutils.c

    rf87e191 r868c6b8  
    4040  }
    4141
    42   level_lin = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_lin(&vec));
     42  level_lin = PyFloat_FromDouble(aubio_level_lin(&vec));
    4343  if (level_lin == NULL) {
    4444    PyErr_SetString (PyExc_ValueError, "failed computing level_lin");
     
    6868  }
    6969
    70   db_spl = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_db_spl(&vec));
     70  db_spl = PyFloat_FromDouble(aubio_db_spl(&vec));
    7171  if (db_spl == NULL) {
    7272    PyErr_SetString (PyExc_ValueError, "failed computing db_spl");
     
    9797  }
    9898
    99   silence_detection = Py_BuildValue("I", aubio_silence_detection(&vec, threshold));
     99  silence_detection = PyLong_FromLong(aubio_silence_detection(&vec, threshold));
    100100  if (silence_detection == NULL) {
    101101    PyErr_SetString (PyExc_ValueError, "failed computing silence_detection");
     
    126126  }
    127127
    128   level_detection = Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_level_detection(&vec, threshold));
     128  level_detection = PyFloat_FromDouble(aubio_level_detection(&vec, threshold));
    129129  if (level_detection == NULL) {
    130130    PyErr_SetString (PyExc_ValueError, "failed computing level_detection");
     
    195195  }
    196196  if (htk != NULL && PyObject_IsTrue(htk) == 1)
    197     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
     197    return PyFloat_FromDouble(aubio_hztomel_htk(v));
    198198  else
    199     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel(v));
     199    return PyFloat_FromDouble(aubio_hztomel(v));
    200200}
    201201
     
    212212  }
    213213  if (htk != NULL && PyObject_IsTrue(htk) == 1)
    214     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
     214    return PyFloat_FromDouble(aubio_meltohz_htk(v));
    215215  else
    216     return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz(v));
     216    return PyFloat_FromDouble(aubio_meltohz(v));
    217217}
    218218
     
    224224    return NULL;
    225225  }
    226   return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_hztomel_htk(v));
     226  return PyFloat_FromDouble(aubio_hztomel_htk(v));
    227227}
    228228
     
    234234    return NULL;
    235235  }
    236   return Py_BuildValue(AUBIO_NPY_SMPL_CHR, aubio_meltohz_htk(v));
    237 }
     236  return PyFloat_FromDouble(aubio_meltohz_htk(v));
     237}
  • python/ext/py-phasevoc.c

    rf87e191 r868c6b8  
    9191  self->hop_s = Py_default_vector_length/2;
    9292
    93   if (self == NULL) {
    94     return NULL;
    95   }
    96 
    9793  if (win_s > 0) {
    9894    self->win_s = win_s;
  • python/lib/gen_code.py

    rf87e191 r868c6b8  
    234234
    235235    def gen_doc(self):
    236         out = """
    237 // TODO: add documentation
    238 static char Py_{shortname}_doc[] = \"undefined\";
     236        sig = []
     237        for p in self.input_params:
     238            name = p['name']
     239            defval = aubiodefvalue[name].replace('"','\\\"')
     240            sig.append("{name}={defval}".format(defval=defval, name=name))
     241        out = """
     242#ifndef PYAUBIO_{shortname}_doc
     243#define PYAUBIO_{shortname}_doc "{shortname}({sig})"
     244#endif /* PYAUBIO_{shortname}_doc */
     245
     246static char Py_{shortname}_doc[] = ""
     247PYAUBIO_{shortname}_doc
     248"";
    239249"""
    240         return out.format(**self.__dict__)
     250        return out.format(sig=', '.join(sig), **self.__dict__)
    241251
    242252    def gen_new(self):
  • python/tests/test_mfcc.py

    rf87e191 r868c6b8  
    117117        buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000
    118118        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
    119         m.set_scale(10.)
     119        m.set_scale(10.5)
     120        assert m.get_scale() == 10.5
    120121        m(cvec(buf_size))
    121122
     
    123124        buf_size, n_filters, n_coeffs, samplerate = 512, 20, 10, 16000
    124125        m = mfcc(buf_size, n_filters, n_coeffs, samplerate)
    125         m.set_power(2.)
     126        m.set_power(2.5)
     127        assert m.get_power() == 2.5
    126128        m(cvec(buf_size))
    127129
  • scripts/get_waf.sh

    rf87e191 r868c6b8  
    44#set -x
    55
    6 WAFVERSION=2.0.12
     6WAFVERSION=2.0.13
    77WAFTARBALL=waf-$WAFVERSION.tar.bz2
    88WAFURL=https://waf.io/$WAFTARBALL
  • src/aubio_priv.h

    rf87e191 r868c6b8  
    368368#endif /* __STRICT_ANSI__ */
    369369
     370#if defined(DEBUG)
     371#include <assert.h>
     372#define AUBIO_ASSERT(x) assert(x)
     373#else
     374#define AUBIO_ASSERT(x)
     375#endif /* DEBUG */
     376
    370377#endif /* AUBIO_PRIV_H */
  • src/io/ioutils.c

    rf87e191 r868c6b8  
    5252  return AUBIO_OK;
    5353}
     54
     55uint_t
     56aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
     57    uint_t max_size, uint_t write_data_length, uint_t write)
     58{
     59  uint_t can_write = write;
     60
     61  if (write > max_size) {
     62    AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
     63        " at most %d can be written at once\n", kind, path, write, max_size);
     64    can_write = max_size;
     65  }
     66
     67  if (can_write > write_data_length) {
     68    AUBIO_WRN("%s: partial write to %s, trying to write %d frames,"
     69        " but found input of length %d\n", kind, path, write,
     70        write_data_length);
     71    can_write = write_data_length;
     72  }
     73
     74  return can_write;
     75}
     76
     77uint_t
     78aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
     79    uint_t sink_channels, uint_t write_data_height)
     80{
     81  uint_t channels = sink_channels;
     82  if (write_data_height < sink_channels) {
     83    AUBIO_WRN("%s: partial write to %s, trying to write %d channels,"
     84        " but found input of height %d\n", kind, path, sink_channels,
     85        write_data_height);
     86    channels = write_data_height;
     87  }
     88  return channels;
     89}
  • src/io/ioutils.h

    rf87e191 r868c6b8  
    5454    uint_t channels);
    5555
     56/** validate length of input
     57
     58  \param kind       the object kind to report on
     59  \param path       the path to report on
     60  \param max_size   maximum number of frames that can be written
     61  \param write_data_length actual length of input vector/matrix
     62  \param write number of samples asked
     63
     64  \return write or the maximum number of frames that can be written
     65*/
     66uint_t
     67aubio_sink_validate_input_length(const char_t *kind, const char_t *path,
     68    uint_t max_size, uint_t write_data_length, uint_t write);
     69
     70/** validate height of input
     71
     72  \param kind       the object kind to report on
     73  \param path       the path to report on
     74  \param max_size   maximum number of channels that can be written
     75  \param write_data_height actual height of input matrix
     76
     77  \return write_data_height or the maximum number of channels
     78*/
     79uint_t
     80aubio_sink_validate_input_channels(const char_t *kind, const char_t *path,
     81    uint_t sink_channels, uint_t write_data_height);
     82
    5683#ifdef __cplusplus
    5784}
  • src/io/sink.c

    rf87e191 r868c6b8  
    103103  AUBIO_ERROR("sink: failed creating '%s' at %dHz (no sink built-in)\n", uri, samplerate);
    104104#endif
    105   AUBIO_FREE(s);
     105  del_aubio_sink(s);
    106106  return NULL;
    107107}
     
    136136
    137137void del_aubio_sink(aubio_sink_t * s) {
    138   if (!s) return;
    139   s->s_del((void *)s->sink);
     138  AUBIO_ASSERT(s);
     139  if (s->s_del && s->sink)
     140    s->s_del((void *)s->sink);
    140141  AUBIO_FREE(s);
    141   return;
    142142}
  • src/io/sink_apple_audio.c

    rf87e191 r868c6b8  
    3232#include <AudioToolbox/AudioToolbox.h>
    3333
    34 #define FLOAT_TO_SHORT(x) (short)(x * 32768)
    35 
    36 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
     34extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
    3735extern void freeAudioBufferList(AudioBufferList *bufferList);
    3836extern CFURLRef createURLFromPath(const char * path);
     
    6260  s->async = false;
    6361
    64   if ( (uri == NULL) || (strlen(uri) < 1) ) {
     62  if ( (uri == NULL) || (strnlen(uri, PATH_MAX) < 1) ) {
    6563    AUBIO_ERROR("sink_apple_audio: Aborted opening null path\n");
    6664    goto beach;
    6765  }
    68   if (s->path != NULL) AUBIO_FREE(s->path);
     66
    6967  s->path = AUBIO_ARRAY(char_t, strnlen(uri, PATH_MAX) + 1);
    7068  strncpy(s->path, uri, strnlen(uri, PATH_MAX) + 1);
     
    7775    return s;
    7876  }
     77
    7978  // invalid samplerate given, abort
    8079  if (aubio_io_validate_samplerate("sink_apple_audio", s->path, samplerate)) {
     
    9291  return s;
    9392beach:
    94   AUBIO_FREE(s);
     93  del_aubio_sink_apple_audio(s);
    9594  return NULL;
    9695}
     
    103102  s->samplerate = samplerate;
    104103  // automatically open when both samplerate and channels have been set
    105   if (s->samplerate != 0 && s->channels != 0) {
     104  if (/* s->samplerate != 0 && */ s->channels != 0) {
    106105    return aubio_sink_apple_audio_open(s);
    107106  }
     
    116115  s->channels = channels;
    117116  // automatically open when both samplerate and channels have been set
    118   if (s->samplerate != 0 && s->channels != 0) {
     117  if (s->samplerate != 0 /* && s->channels != 0 */) {
    119118    return aubio_sink_apple_audio_open(s);
    120119  }
     
    151150  CFURLRef fileURL = createURLFromPath(s->path);
    152151  bool overwrite = true;
     152
     153  // set the in-memory format
     154  AudioStreamBasicDescription inputFormat;
     155  memset(&inputFormat, 0, sizeof(AudioStreamBasicDescription));
     156  inputFormat.mFormatID         = kAudioFormatLinearPCM;
     157  inputFormat.mSampleRate       = (Float64)(s->samplerate);
     158  inputFormat.mFormatFlags      = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked;
     159  inputFormat.mChannelsPerFrame = s->channels;
     160  inputFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
     161  inputFormat.mFramesPerPacket  = 1;
     162  inputFormat.mBytesPerFrame    = inputFormat.mBitsPerChannel * inputFormat.mChannelsPerFrame / 8;
     163  inputFormat.mBytesPerPacket   = inputFormat.mFramesPerPacket * inputFormat.mBytesPerFrame;
    153164  OSStatus err = noErr;
    154165  err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
     
    162173    goto beach;
    163174  }
    164   if (createAubioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
     175
     176  err = ExtAudioFileSetProperty(s->audioFile,
     177      kExtAudioFileProperty_ClientDataFormat,
     178      sizeof(AudioStreamBasicDescription), &inputFormat);
     179  if (err) {
     180    char_t errorstr[20];
     181    AUBIO_ERR("sink_apple_audio: error when trying to set output format on %s "
     182        "(%s)\n", s->path, getPrintableOSStatusError(errorstr, err));
     183    goto beach;
     184  }
     185
     186  if (createAudioBufferList(&s->bufferList, s->channels, s->max_frames * s->channels)) {
    165187    AUBIO_ERR("sink_apple_audio: error when creating buffer list for %s, "
    166188        "out of memory? \n", s->path);
     
    175197void aubio_sink_apple_audio_do(aubio_sink_apple_audio_t * s, fvec_t * write_data, uint_t write) {
    176198  UInt32 c, v;
    177   short *data = (short*)s->bufferList.mBuffers[0].mData;
    178   if (write > s->max_frames) {
    179     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
    180     write = s->max_frames;
    181   }
    182   smpl_t *buf = write_data->data;
    183 
    184   if (buf) {
    185       for (c = 0; c < s->channels; c++) {
    186           for (v = 0; v < write; v++) {
    187               data[v * s->channels + c] =
    188                   FLOAT_TO_SHORT(buf[ v * s->channels + c]);
    189           }
    190       }
    191   }
    192   aubio_sink_apple_audio_write(s, write);
     199  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
     200  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
     201      s->max_frames, write_data->length, write);
     202
     203  for (c = 0; c < s->channels; c++) {
     204    for (v = 0; v < length; v++) {
     205      data[v * s->channels + c] = write_data->data[v];
     206    }
     207  }
     208
     209  aubio_sink_apple_audio_write(s, length);
    193210}
    194211
    195212void aubio_sink_apple_audio_do_multi(aubio_sink_apple_audio_t * s, fmat_t * write_data, uint_t write) {
    196213  UInt32 c, v;
    197   short *data = (short*)s->bufferList.mBuffers[0].mData;
    198   if (write > s->max_frames) {
    199     AUBIO_WRN("sink_apple_audio: trying to write %d frames, max %d\n", write, s->max_frames);
    200     write = s->max_frames;
    201   }
    202   smpl_t **buf = write_data->data;
    203 
    204   if (buf) {
    205       for (c = 0; c < s->channels; c++) {
    206           for (v = 0; v < write; v++) {
    207               data[v * s->channels + c] =
    208                   FLOAT_TO_SHORT(buf[c][v]);
    209           }
    210       }
    211   }
    212   aubio_sink_apple_audio_write(s, write);
     214  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
     215  uint_t channels = aubio_sink_validate_input_channels("sink_apple_audio",
     216      s->path, s->channels, write_data->height);
     217  uint_t length = aubio_sink_validate_input_length("sink_apple_audio", s->path,
     218      s->max_frames, write_data->length, write);
     219
     220  for (c = 0; c < channels; c++) {
     221    for (v = 0; v < length; v++) {
     222      data[v * s->channels + c] = write_data->data[c][v];
     223    }
     224  }
     225
     226  aubio_sink_apple_audio_write(s, length);
    213227}
    214228
    215229void aubio_sink_apple_audio_write(aubio_sink_apple_audio_t *s, uint_t write) {
    216230  OSStatus err = noErr;
     231  // set mDataByteSize to match the number of frames to be written
     232  // see https://www.mail-archive.com/coreaudio-api@lists.apple.com/msg01109.html
     233  s->bufferList.mBuffers[0].mDataByteSize = write * s->channels
     234    * sizeof(smpl_t);
    217235  if (s->async) {
    218236    err = ExtAudioFileWriteAsync(s->audioFile, write, &s->bufferList);
     
    258276
    259277void del_aubio_sink_apple_audio(aubio_sink_apple_audio_t * s) {
    260   if (s->audioFile) aubio_sink_apple_audio_close (s);
    261   if (s->path) AUBIO_FREE(s->path);
     278  AUBIO_ASSERT(s);
     279  if (s->audioFile)
     280    aubio_sink_apple_audio_close (s);
     281  if (s->path)
     282    AUBIO_FREE(s->path);
    262283  freeAudioBufferList(&s->bufferList);
    263284  AUBIO_FREE(s);
    264   return;
    265285}
    266286
  • src/io/sink_sndfile.c

    rf87e191 r868c6b8  
    5959  if (path == NULL) {
    6060    AUBIO_ERR("sink_sndfile: Aborted opening null path\n");
    61     return NULL;
    62   }
    63 
    64   if (s->path) AUBIO_FREE(s->path);
     61    goto beach;
     62  }
     63
    6564  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    6665  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    9897  s->samplerate = samplerate;
    9998  // automatically open when both samplerate and channels have been set
    100   if (s->samplerate != 0 && s->channels != 0) {
     99  if (/* s->samplerate != 0 && */ s->channels != 0) {
    101100    return aubio_sink_sndfile_open(s);
    102101  }
     
    111110  s->channels = channels;
    112111  // automatically open when both samplerate and channels have been set
    113   if (s->samplerate != 0 && s->channels != 0) {
     112  if (s->samplerate != 0 /* && s->channels != 0 */) {
    114113    return aubio_sink_sndfile_open(s);
    115114  }
     
    148147  /* allocate data for de/interleaving reallocated when needed. */
    149148  if (s->scratch_size >= MAX_SIZE * AUBIO_MAX_CHANNELS) {
    150     abort();
    151     AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum aubio_sink_sndfile buffer size %d\n",
     149    AUBIO_ERR("sink_sndfile: %d x %d exceeds maximum buffer size %d\n",
    152150        s->max_size, s->channels, MAX_SIZE * AUBIO_MAX_CHANNELS);
    153151    return AUBIO_FAIL;
     
    159157
    160158void aubio_sink_sndfile_do(aubio_sink_sndfile_t *s, fvec_t * write_data, uint_t write){
    161   uint_t i, j, channels = s->channels;
    162   int nsamples = 0;
    163   smpl_t *pwrite;
     159  uint_t i, j;
    164160  sf_count_t written_frames;
    165 
    166   if (write > s->max_size) {
    167     AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
    168       write, s->max_size);
    169     write = s->max_size;
    170   }
    171 
    172   nsamples = channels * write;
     161  uint_t channels = s->channels;
     162  uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
     163      s->max_size, write_data->length, write);
     164  int nsamples = channels * length;
    173165
    174166  /* interleaving data  */
    175167  for ( i = 0; i < channels; i++) {
    176     pwrite = (smpl_t *)write_data->data;
    177     for (j = 0; j < write; j++) {
    178       s->scratch_data[channels*j+i] = pwrite[j];
     168    for (j = 0; j < length; j++) {
     169      s->scratch_data[channels*j+i] = write_data->data[j];
    179170    }
    180171  }
     
    189180
    190181void aubio_sink_sndfile_do_multi(aubio_sink_sndfile_t *s, fmat_t * write_data, uint_t write){
    191   uint_t i, j, channels = s->channels;
    192   int nsamples = 0;
    193   smpl_t *pwrite;
     182  uint_t i, j;
    194183  sf_count_t written_frames;
    195 
    196   if (write > s->max_size) {
    197     AUBIO_WRN("sink_sndfile: trying to write %d frames, but only %d can be written at a time\n",
    198       write, s->max_size);
    199     write = s->max_size;
    200   }
    201 
    202   nsamples = channels * write;
     184  uint_t channels = aubio_sink_validate_input_channels("sink_sndfile", s->path,
     185      s->channels, write_data->height);
     186  uint_t length = aubio_sink_validate_input_length("sink_sndfile", s->path,
     187      s->max_size, write_data->length, write);
     188  int nsamples = channels * length;
    203189
    204190  /* interleaving data  */
    205   for ( i = 0; i < write_data->height; i++) {
    206     pwrite = (smpl_t *)write_data->data[i];
    207     for (j = 0; j < write; j++) {
    208       s->scratch_data[channels*j+i] = pwrite[j];
     191  for ( i = 0; i < channels; i++) {
     192    for (j = 0; j < length; j++) {
     193      s->scratch_data[channels*j+i] = write_data->data[i][j];
    209194    }
    210195  }
     
    231216
    232217void del_aubio_sink_sndfile(aubio_sink_sndfile_t * s){
    233   if (!s) return;
    234   if (s->path) AUBIO_FREE(s->path);
    235   aubio_sink_sndfile_close(s);
    236   AUBIO_FREE(s->scratch_data);
     218  AUBIO_ASSERT(s);
     219  if (s->handle)
     220    aubio_sink_sndfile_close(s);
     221  if (s->path)
     222    AUBIO_FREE(s->path);
     223  if (s->scratch_data)
     224    AUBIO_FREE(s->scratch_data);
    237225  AUBIO_FREE(s);
    238226}
  • src/io/sink_wavwrite.c

    rf87e191 r868c6b8  
    8888    goto beach;
    8989  }
    90   if ((sint_t)samplerate < 0) {
    91     AUBIO_ERR("sink_wavwrite: Can not create %s with samplerate %d\n", path, samplerate);
    92     goto beach;
    93   }
    94 
    95   if (s->path) AUBIO_FREE(s->path);
     90
    9691  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9792  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    136131  s->samplerate = samplerate;
    137132  // automatically open when both samplerate and channels have been set
    138   if (s->samplerate != 0 && s->channels != 0) {
     133  if (/* s->samplerate != 0 && */ s->channels != 0) {
    139134    return aubio_sink_wavwrite_open(s);
    140135  }
     
    149144  s->channels = channels;
    150145  // automatically open when both samplerate and channels have been set
    151   if (s->samplerate != 0 && s->channels != 0) {
     146  if (s->samplerate != 0 /* && s->channels != 0 */) {
    152147    return aubio_sink_wavwrite_open(s);
    153148  }
     
    234229
    235230void aubio_sink_wavwrite_do(aubio_sink_wavwrite_t *s, fvec_t * write_data, uint_t write){
    236   uint_t i = 0, written_frames = 0;
    237 
    238   if (write > s->max_size) {
    239     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    240         "but only %d can be written at a time\n", write, s->path, s->max_size);
    241     write = s->max_size;
    242   }
    243 
    244   for (i = 0; i < write; i++) {
    245     s->scratch_data[i] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
    246   }
    247   written_frames = fwrite(s->scratch_data, 2, write, s->fid);
     231  uint_t c = 0, i = 0, written_frames = 0;
     232  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
     233      s->max_size, write_data->length, write);
     234
     235  for (c = 0; c < s->channels; c++) {
     236    for (i = 0; i < length; i++) {
     237      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[i]));
     238    }
     239  }
     240  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    248241
    249242  if (written_frames != write) {
     
    258251  uint_t c = 0, i = 0, written_frames = 0;
    259252
    260   if (write > s->max_size) {
    261     AUBIO_WRN("sink_wavwrite: trying to write %d frames to %s, "
    262         "but only %d can be written at a time\n", write, s->path, s->max_size);
    263     write = s->max_size;
    264   }
    265 
    266   for (c = 0; c < s->channels; c++) {
    267     for (i = 0; i < write; i++) {
     253  uint_t channels = aubio_sink_validate_input_channels("sink_wavwrite", s->path,
     254      s->channels, write_data->height);
     255  uint_t length = aubio_sink_validate_input_length("sink_wavwrite", s->path,
     256      s->max_size, write_data->length, write);
     257
     258  for (c = 0; c < channels; c++) {
     259    for (i = 0; i < length; i++) {
    268260      s->scratch_data[i * s->channels + c] = HTOLES(FLOAT_TO_SHORT(write_data->data[c][i]));
    269261    }
    270262  }
    271   written_frames = fwrite(s->scratch_data, 2, write * s->channels, s->fid);
     263  written_frames = fwrite(s->scratch_data, 2, length * s->channels, s->fid);
    272264
    273265  if (written_frames != write * s->channels) {
     
    298290
    299291void del_aubio_sink_wavwrite(aubio_sink_wavwrite_t * s){
    300   if (!s) return;
    301   aubio_sink_wavwrite_close(s);
    302   if (s->path) AUBIO_FREE(s->path);
    303   AUBIO_FREE(s->scratch_data);
     292  AUBIO_ASSERT(s);
     293  if (s->fid)
     294    aubio_sink_wavwrite_close(s);
     295  if (s->path)
     296    AUBIO_FREE(s->path);
     297  if (s->scratch_data)
     298    AUBIO_FREE(s->scratch_data);
    304299  AUBIO_FREE(s);
    305300}
  • src/io/source.c

    rf87e191 r868c6b8  
    122122     " (no source built-in)\n", uri, samplerate, hop_size);
    123123#endif
    124   AUBIO_FREE(s);
     124  del_aubio_source(s);
    125125  return NULL;
    126126}
     
    139139
    140140void del_aubio_source(aubio_source_t * s) {
    141   if (!s) return;
    142   s->s_del((void *)s->source);
     141  AUBIO_ASSERT(s);
     142  if (s->s_del && s->source)
     143    s->s_del((void *)s->source);
    143144  AUBIO_FREE(s);
    144145}
  • src/io/source.h

    rf87e191 r868c6b8  
    6060
    6161  \example io/test-source.c
    62   \example io/test-source_multi.c
    6362
    6463*/
  • src/io/source_apple_audio.c

    rf87e191 r868c6b8  
    3434#define RT_BYTE3( a )      ( ((a) >> 16) & 0xff )
    3535#define RT_BYTE4( a )      ( ((a) >> 24) & 0xff )
    36 
    37 #define SHORT_TO_FLOAT(x) (smpl_t)(x * 3.0517578125e-05)
    3836
    3937struct _aubio_source_apple_audio_t {
     
    4947};
    5048
    51 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
     49extern int createAudioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
    5250extern void freeAudioBufferList(AudioBufferList *bufferList);
    5351extern CFURLRef createURLFromPath(const char * path);
     
    6058  aubio_source_apple_audio_t * s = AUBIO_NEW(aubio_source_apple_audio_t);
    6159
    62   if (path == NULL) {
     60  if (path == NULL || strnlen(path, PATH_MAX) < 1) {
    6361    AUBIO_ERROR("source_apple_audio: Aborted opening null path\n");
    6462    goto beach;
     
    8684
    8785beach:
    88   AUBIO_FREE(s);
     86  del_aubio_source_apple_audio(s);
    8987  return NULL;
    9088}
     
    9593  UInt32 propSize;
    9694
    97   if (s->path) AUBIO_FREE(s->path);
    9895  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9996  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    140137
    141138  AudioStreamBasicDescription clientFormat;
    142   propSize = sizeof(clientFormat);
     139  propSize = sizeof(AudioStreamBasicDescription);
    143140  memset(&clientFormat, 0, sizeof(AudioStreamBasicDescription));
    144141  clientFormat.mFormatID         = kAudioFormatLinearPCM;
    145142  clientFormat.mSampleRate       = (Float64)(s->samplerate);
    146   clientFormat.mFormatFlags      = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked;
     143  clientFormat.mFormatFlags      = kAudioFormatFlagIsFloat;
    147144  clientFormat.mChannelsPerFrame = s->channels;
    148   clientFormat.mBitsPerChannel   = sizeof(short) * 8;
     145  clientFormat.mBitsPerChannel   = sizeof(smpl_t) * 8;
    149146  clientFormat.mFramesPerPacket  = 1;
    150147  clientFormat.mBytesPerFrame    = clientFormat.mBitsPerChannel * clientFormat.mChannelsPerFrame / 8;
    151148  clientFormat.mBytesPerPacket   = clientFormat.mFramesPerPacket * clientFormat.mBytesPerFrame;
    152   clientFormat.mReserved         = 0;
    153149
    154150  // set the client format description
     
    188184  // allocate the AudioBufferList
    189185  freeAudioBufferList(&s->bufferList);
    190   if (createAubioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
     186  if (createAudioBufferList(&s->bufferList, s->channels, s->block_size * s->channels)) {
    191187    AUBIO_ERR("source_apple_audio: failed creating bufferList\n");
    192188    goto beach;
     
    197193}
    198194
    199 void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to, uint_t * read) {
    200   UInt32 c, v, loadedPackets = s->block_size;
     195static UInt32 aubio_source_apple_audio_read_frame(aubio_source_apple_audio_t *s)
     196{
     197  UInt32 loadedPackets = s->block_size;
    201198  OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    202199  if (err) {
     
    205202        "with ExtAudioFileRead (%s)\n", s->path,
    206203        getPrintableOSStatusError(errorstr, err));
    207     goto beach;
    208   }
    209 
    210   short *data = (short*)s->bufferList.mBuffers[0].mData;
    211 
    212   smpl_t *buf = read_to->data;
     204  }
     205  return loadedPackets;
     206}
     207
     208void aubio_source_apple_audio_do(aubio_source_apple_audio_t *s, fvec_t * read_to,
     209    uint_t * read) {
     210  uint_t c, v;
     211  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
     212  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    213213
    214214  for (v = 0; v < loadedPackets; v++) {
    215     buf[v] = 0.;
     215    read_to->data[v] = 0.;
    216216    for (c = 0; c < s->channels; c++) {
    217       buf[v] += SHORT_TO_FLOAT(data[ v * s->channels + c]);
    218     }
    219     buf[v] /= (smpl_t)s->channels;
     217      read_to->data[v] += data[ v * s->channels + c];
     218    }
     219    read_to->data[v] /= (smpl_t)s->channels;
    220220  }
    221221  // short read, fill with zeros
    222222  if (loadedPackets < s->block_size) {
    223223    for (v = loadedPackets; v < s->block_size; v++) {
    224       buf[v] = 0.;
     224      read_to->data[v] = 0.;
    225225    }
    226226  }
     
    228228  *read = (uint_t)loadedPackets;
    229229  return;
    230 beach:
    231   *read = 0;
    232   return;
    233230}
    234231
    235232void aubio_source_apple_audio_do_multi(aubio_source_apple_audio_t *s, fmat_t * read_to, uint_t * read) {
    236   UInt32 c, v, loadedPackets = s->block_size;
    237   OSStatus err = ExtAudioFileRead(s->audioFile, &loadedPackets, &s->bufferList);
    238   if (err) {
    239     char_t errorstr[20];
    240     AUBIO_ERROR("source_apple_audio: error while reading %s "
    241         "with ExtAudioFileRead (%s)\n", s->path,
    242         getPrintableOSStatusError(errorstr, err));
    243     goto beach;
    244   }
    245 
    246   short *data = (short*)s->bufferList.mBuffers[0].mData;
    247 
    248   smpl_t **buf = read_to->data;
     233  uint_t c, v;
     234  UInt32 loadedPackets = aubio_source_apple_audio_read_frame(s);
     235  smpl_t *data = (smpl_t*)s->bufferList.mBuffers[0].mData;
    249236
    250237  for (v = 0; v < loadedPackets; v++) {
    251238    for (c = 0; c < read_to->height; c++) {
    252       buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + c]);
     239      read_to->data[c][v] = data[ v * s->channels + c];
    253240    }
    254241  }
     
    258245    for (v = 0; v < loadedPackets; v++) {
    259246      for (c = s->channels; c < read_to->height; c++) {
    260         buf[c][v] = SHORT_TO_FLOAT(data[ v * s->channels + (s->channels - 1)]);
     247        read_to->data[c][v] = data[ v * s->channels + (s->channels - 1)];
    261248      }
    262249    }
     
    266253    for (v = loadedPackets; v < s->block_size; v++) {
    267254      for (c = 0; c < read_to->height; c++) {
    268         buf[c][v] = 0.;
     255        read_to->data[c][v] = 0.;
    269256      }
    270257    }
    271258  }
     259
    272260  *read = (uint_t)loadedPackets;
    273   return;
    274 beach:
    275   *read = 0;
    276261  return;
    277262}
     
    294279
    295280void del_aubio_source_apple_audio(aubio_source_apple_audio_t * s){
     281  AUBIO_ASSERT(s);
    296282  aubio_source_apple_audio_close (s);
    297283  if (s->path) AUBIO_FREE(s->path);
    298284  freeAudioBufferList(&s->bufferList);
    299285  AUBIO_FREE(s);
    300   return;
    301286}
    302287
     
    324309  // after a short read, the bufferList size needs to resetted to prepare for a full read
    325310  AudioBufferList *bufferList = &s->bufferList;
    326   bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (short);
     311  bufferList->mBuffers[0].mDataByteSize = s->block_size * s->channels * sizeof (smpl_t);
    327312  // do the actual seek
    328313  err = ExtAudioFileSeek(s->audioFile, resampled_pos);
  • src/io/source_avcodec.c

    rf87e191 r868c6b8  
    4545#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57,0,0)
    4646#define HAVE_AUBIO_LIBAVCODEC_DEPRECATED 1
     47#endif
     48
     49#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58,3,102)
     50#define HAVE_AUBIO_LIBAVCODEC_TIMEBASE_FIX 1
    4751#endif
    4852
     
    144148  s->channels = 1;
    145149
    146   if (s->path) AUBIO_FREE(s->path);
    147150  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    148151  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    240243    goto beach;
    241244  }
     245#if HAVE_AUBIO_LIBAVCODEC_TIMEBASE_FIX
     246  // avoids 'skipped frames warning' with avecodec < 58, deprecated after
     247  av_codec_set_pkt_timebase(avCodecCtx,
     248      avFormatCtx->streams[selected_stream]->time_base);
     249#endif
    242250#endif
    243251
     
    631639
    632640void del_aubio_source_avcodec(aubio_source_avcodec_t * s){
    633   if (!s) return;
     641  AUBIO_ASSERT(s);
    634642  aubio_source_avcodec_close(s);
    635643  if (s->output != NULL) {
  • src/io/source_sndfile.c

    rf87e191 r868c6b8  
    8787  s->channels = 1;
    8888
    89   if (s->path) AUBIO_FREE(s->path);
    9089  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9190  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    332331
    333332void del_aubio_source_sndfile(aubio_source_sndfile_t * s){
    334   if (!s) return;
     333  AUBIO_ASSERT(s);
    335334  aubio_source_sndfile_close(s);
    336335#ifdef HAVE_SAMPLERATE
  • src/io/source_wavread.c

    rf87e191 r868c6b8  
    9292  }
    9393
    94   if (s->path) AUBIO_FREE(s->path);
    9594  s->path = AUBIO_ARRAY(char_t, strnlen(path, PATH_MAX) + 1);
    9695  strncpy(s->path, path, strnlen(path, PATH_MAX) + 1);
     
    472471
    473472void del_aubio_source_wavread(aubio_source_wavread_t * s) {
    474   if (!s) return;
     473  AUBIO_ASSERT(s);
    475474  aubio_source_wavread_close(s);
    476475  if (s->short_output) AUBIO_FREE(s->short_output);
  • src/io/utils_apple_audio.c

    rf87e191 r868c6b8  
    1313char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
    1414
    15 int createAubioBufferList(AudioBufferList * bufferList, int channels, int max_source_samples) {
     15int createAudioBufferList(AudioBufferList * bufferList, int channels,
     16    int max_source_samples) {
    1617  bufferList->mNumberBuffers = 1;
    1718  bufferList->mBuffers[0].mNumberChannels = channels;
    18   bufferList->mBuffers[0].mData = AUBIO_ARRAY(short, max_source_samples);
    19   bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(short);
     19  bufferList->mBuffers[0].mData = AUBIO_ARRAY(smpl_t, max_source_samples);
     20  bufferList->mBuffers[0].mDataByteSize = max_source_samples * sizeof(smpl_t);
    2021  return 0;
    2122}
  • src/notes/notes.c

    rf87e191 r868c6b8  
    8484
    8585  o->onset = new_aubio_onset (onset_method, o->onset_buf_size, o->hop_size, o->samplerate);
     86  if (o->onset == NULL) goto fail;
    8687  if (o->onset_threshold != 0.) aubio_onset_set_threshold (o->onset, o->onset_threshold);
    8788  o->onset_output = new_fvec (1);
     
    99100  o->note_buffer = new_fvec(o->median);
    100101  o->note_buffer2 = new_fvec(o->median);
     102
     103  if (!o->onset_output || !o->pitch_output ||
     104      !o->note_buffer || !o->note_buffer2) goto fail;
    101105
    102106  o->curnote = -1.;
  • src/pitch/pitchmcomb.c

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

    rf87e191 r868c6b8  
    9393  del_fvec (p->sqrmag);
    9494  del_fvec (p->fftout);
     95  del_fvec (p->acf);
    9596  AUBIO_FREE (p);
    9697}
  • src/pitch/pitchyin.c

    rf87e191 r868c6b8  
    4040};
    4141
     42#if 0
    4243/** compute difference function
    4344
     
    6162*/
    6263uint_t aubio_pitchyin_getpitch (const fvec_t * yinbuf);
     64#endif
    6365
    6466aubio_pitchyin_t *
     
    7981}
    8082
     83#if 0
    8184/* outputs the difference function */
    8285void
     
    128131  return 0;
    129132}
     133#endif
    130134
    131135/* all the above in one */
  • src/pitch/pitchyinfast.c

    rf87e191 r868c6b8  
    5959  o->kernel_fft = new_fvec (bufsize);
    6060  o->fft = new_aubio_fft (bufsize);
     61  if (!o->yin || !o->tmpdata || !o->tmpdata || !o->sqdiff
     62      || !o->kernel || !o->samples_fft || !o->kernel || !o->fft)
     63  {
     64    del_aubio_pitchyinfast(o);
     65    return NULL;
     66  }
    6167  o->tol = 0.15;
    6268  o->peak_pos = 0;
     
    6773del_aubio_pitchyinfast (aubio_pitchyinfast_t * o)
    6874{
    69   del_fvec (o->yin);
    70   del_fvec (o->tmpdata);
    71   del_fvec (o->sqdiff);
    72   del_fvec (o->kernel);
    73   del_fvec (o->samples_fft);
    74   del_fvec (o->kernel_fft);
    75   del_aubio_fft (o->fft);
     75  if (o->yin)
     76    del_fvec (o->yin);
     77  if (o->tmpdata)
     78    del_fvec (o->tmpdata);
     79  if (o->sqdiff)
     80    del_fvec (o->sqdiff);
     81  if (o->kernel)
     82    del_fvec (o->kernel);
     83  if (o->samples_fft)
     84    del_fvec (o->samples_fft);
     85  if (o->kernel_fft)
     86    del_fvec (o->kernel_fft);
     87  if (o->fft)
     88    del_aubio_fft (o->fft);
    7689  AUBIO_FREE (o);
    7790}
  • src/spectral/awhitening.c

    rf87e191 r868c6b8  
    4444{
    4545  uint_t i = 0;
    46   for (i = 0; i < o->peak_values->length; i++) {
     46  uint_t length = MIN(fftgrain->length, o->peak_values->length);
     47  for (i = 0; i < length; i++) {
    4748    smpl_t tmp = MAX(o->r_decay * o->peak_values->data[i], o->floor);
    4849    o->peak_values->data[i] = MAX(fftgrain->norm[i], tmp);
  • src/spectral/filterbank.c

    rf87e191 r868c6b8  
    131131aubio_filterbank_get_power (aubio_filterbank_t *f)
    132132{
    133   return f->norm;
     133  return f->power;
    134134}
  • src/spectral/mfcc.c

    rf87e191 r868c6b8  
    144144}
    145145
    146 uint_t aubio_mfcc_get_power (aubio_mfcc_t *mf)
     146smpl_t aubio_mfcc_get_power (aubio_mfcc_t *mf)
    147147{
    148148  return aubio_filterbank_get_power(mf->fb);
     
    155155}
    156156
    157 uint_t aubio_mfcc_get_scale (aubio_mfcc_t *mf)
     157smpl_t aubio_mfcc_get_scale (aubio_mfcc_t *mf)
    158158{
    159159  return mf->scale;
  • src/spectral/mfcc.h

    rf87e191 r868c6b8  
    9393
    9494 */
    95 uint_t aubio_mfcc_get_power (aubio_mfcc_t *mf);
     95smpl_t aubio_mfcc_get_power (aubio_mfcc_t *mf);
    9696
    9797/** set scaling parameter
     
    112112
    113113 */
    114 uint_t aubio_mfcc_get_scale (aubio_mfcc_t *mf);
     114smpl_t aubio_mfcc_get_scale (aubio_mfcc_t *mf);
    115115
    116116/** Mel filterbank initialization
  • src/utils/hist.c

    rf87e191 r868c6b8  
    4444  smpl_t accum = step;
    4545  uint_t i;
     46  if ((sint_t)nelems <= 0) {
     47    AUBIO_FREE(s);
     48    return NULL;
     49  }
    4650  s->nelems = nelems;
    4751  s->hist = new_fvec(nelems);
  • tests/src/io/test-sink.c

    rf87e191 r868c6b8  
    22#include "utils_tests.h"
    33
    4 int main (int argc, char **argv)
     4int test_wrong_params(void);
     5
     6int main(int argc, char **argv)
    57{
    6   sint_t err = 0;
    7 
    8   if (argc < 3) {
    9     err = 2;
    10     PRINT_ERR("not enough arguments\n");
    11     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
     8  uint_t err = 0;
     9  if (argc < 3 || argc >= 6) {
     10    PRINT_ERR("wrong number of arguments, running tests\n");
     11    err = test_wrong_params();
     12    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
     13        argv[0]);
    1214    return err;
    1315  }
     
    2022  char_t *sink_path = argv[2];
    2123
     24  aubio_source_t *src = NULL;
     25  aubio_sink_t *snk = NULL;
     26
    2227  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    2328  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    24   if ( argc >= 6 ) {
    25     err = 2;
    26     PRINT_ERR("too many arguments\n");
    27     return err;
    28   }
    2929
    3030  fvec_t *vec = new_fvec(hop_size);
    31   if (!vec) { err = 1; goto beach_fvec; }
     31  if (!vec) { err = 1; goto failure; }
    3232
    33   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    34   if (!i) { err = 1; goto beach_source; }
     33  src = new_aubio_source(source_path, samplerate, hop_size);
     34  if (!src) { err = 1; goto failure; }
     35  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
    3536
    36   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    37 
    38   aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
    39   if (!o) { err = 1; goto beach_sink; }
     37  snk = new_aubio_sink(sink_path, samplerate);
     38  if (!snk) { err = 1; goto failure; }
    4039
    4140  do {
    42     aubio_source_do(i, vec, &read);
    43     aubio_sink_do(o, vec, read);
     41    aubio_source_do(src, vec, &read);
     42    aubio_sink_do(snk, vec, read);
    4443    n_frames += read;
    4544  } while ( read == hop_size );
    4645
    47   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
     46  PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n",
    4847      n_frames, samplerate, n_frames / hop_size,
    4948      source_path, sink_path);
    5049
    51   del_aubio_sink(o);
    52 beach_sink:
    53   del_aubio_source(i);
    54 beach_source:
    55   del_fvec(vec);
    56 beach_fvec:
     50  // close sink now (optional)
     51  aubio_sink_close(snk);
     52
     53failure:
     54  if (snk)
     55    del_aubio_sink(snk);
     56  if (src)
     57    del_aubio_source(src);
     58  if (vec)
     59    del_fvec(vec);
     60
    5761  return err;
    5862}
     63
     64int test_wrong_params(void)
     65{
     66  fvec_t *vec;
     67  fmat_t *mat;
     68  aubio_sink_t *s;
     69  char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
     70  uint_t samplerate = 44100;
     71  uint_t hop_size = 256;
     72  uint_t oversized_hop_size = 4097;
     73  uint_t oversized_samplerate = 192000 * 8 + 1;
     74  uint_t channels = 3;
     75  uint_t oversized_channels = 1025;
     76  // create temp file
     77  int fd = create_temp_sink(sink_path);
     78
     79  if (!fd) return 1;
     80
     81  if (new_aubio_sink(   0,   samplerate)) return 1;
     82  if (new_aubio_sink("\0",   samplerate)) return 1;
     83  if (new_aubio_sink(sink_path,      -1)) return 1;
     84
     85  s = new_aubio_sink(sink_path, 0);
     86
     87  // check setting wrong parameters fails
     88  if (!aubio_sink_preset_samplerate(s, oversized_samplerate)) return 1;
     89  if (!aubio_sink_preset_channels(s, oversized_channels)) return 1;
     90  if (!aubio_sink_preset_channels(s, -1)) return 1;
     91
     92  // check setting valid parameters passes
     93  if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
     94  if (aubio_sink_preset_channels(s, 1)) return 1;
     95
     96  // check writing a vector with valid length
     97  vec = new_fvec(hop_size);
     98  aubio_sink_do(s, vec, hop_size);
     99  // check writing more than in the input
     100  aubio_sink_do(s, vec, hop_size+1);
     101  // check write 0 frames
     102  aubio_sink_do(s, vec, 0);
     103  del_fvec(vec);
     104
     105  // check writing an oversized vector
     106  vec = new_fvec(oversized_hop_size);
     107  aubio_sink_do(s, vec, oversized_hop_size);
     108  del_fvec(vec);
     109
     110  // test delete without closing
     111  del_aubio_sink(s);
     112
     113  s = new_aubio_sink(sink_path, 0);
     114
     115  // preset channels first
     116  if (aubio_sink_preset_channels(s, channels)) return 1;
     117  if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
     118
     119  if (aubio_sink_get_samplerate(s) != samplerate) return 1;
     120  if (aubio_sink_get_channels(s) != channels) return 1;
     121
     122  mat = new_fmat(channels, hop_size);
     123  // check writing a vector with valid length
     124  aubio_sink_do_multi(s, mat, hop_size);
     125  // check writing 0 frames
     126  aubio_sink_do_multi(s, mat, 0);
     127  // check writing more than in the input
     128  aubio_sink_do_multi(s, mat, hop_size+1);
     129  del_fmat(mat);
     130
     131  // check writing oversized input
     132  mat = new_fmat(channels, oversized_hop_size);
     133  aubio_sink_do_multi(s, mat, oversized_hop_size);
     134  del_fmat(mat);
     135
     136  // check writing undersized input
     137  mat = new_fmat(channels - 1, hop_size);
     138  aubio_sink_do_multi(s, mat, hop_size);
     139  del_fmat(mat);
     140
     141  aubio_sink_close(s);
     142  // test closing twice
     143  aubio_sink_close(s);
     144
     145  del_aubio_sink(s);
     146
     147  // delete temp file
     148  close_temp_sink(sink_path, fd);
     149
     150  return run_on_default_source_and_sink(main);
     151}
  • tests/src/io/test-sink_apple_audio.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_sink_custom "apple_audio"
     6
     7#ifdef HAVE_SINK_APPLE_AUDIO
     8#define HAVE_AUBIO_SINK_CUSTOM
     9#define aubio_sink_custom_t aubio_sink_apple_audio_t
     10#define new_aubio_sink_custom new_aubio_sink_apple_audio
     11#define del_aubio_sink_custom del_aubio_sink_apple_audio
     12#define aubio_sink_custom_do aubio_sink_apple_audio_do
     13#define aubio_sink_custom_do_multi aubio_sink_apple_audio_do_multi
     14#define aubio_sink_custom_close aubio_sink_apple_audio_close
     15#define aubio_sink_custom_preset_samplerate aubio_sink_apple_audio_preset_samplerate
     16#define aubio_sink_custom_preset_channels aubio_sink_apple_audio_preset_channels
     17#define aubio_sink_custom_get_samplerate aubio_sink_apple_audio_get_samplerate
     18#define aubio_sink_custom_get_channels aubio_sink_apple_audio_get_channels
     19#endif /* HAVE_SINK_APPLE_AUDIO */
     20
     21#include "base-sink_custom.h"
    422
    523// this file uses the unstable aubio api, please use aubio_sink instead
     
    826int main (int argc, char **argv)
    927{
    10   sint_t err = 0;
    11 
    12   if (argc < 3) {
    13     err = 2;
    14     PRINT_ERR("not enough arguments\n");
    15     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    16     return err;
    17   }
    18 
    19 #ifdef HAVE_SINK_APPLE_AUDIO
    20   uint_t samplerate = 0;
    21   uint_t hop_size = 512;
    22   uint_t n_frames = 0, read = 0;
    23 
    24   char_t *source_path = argv[1];
    25   char_t *sink_path = argv[2];
    26 
    27   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    28   if ( argc >= 5 ) hop_size = atoi(argv[4]);
    29   if ( argc >= 6 ) {
    30     err = 2;
    31     PRINT_ERR("too many arguments\n");
    32     return err;
    33   }
    34 
    35   fvec_t *vec = new_fvec(hop_size);
    36   if (!vec) { err = 1; goto beach_fvec; }
    37 
    38   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    39   if (!i) { err = 1; goto beach_source; }
    40 
    41   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    42 
    43   aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate);
    44   if (!o) { err = 1; goto beach_sink; }
    45 
    46   do {
    47     aubio_source_do(i, vec, &read);
    48     aubio_sink_apple_audio_do(o, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    53       n_frames, samplerate, n_frames / hop_size,
    54       source_path, sink_path);
    55 
    56   del_aubio_sink_apple_audio(o);
    57 beach_sink:
    58   del_aubio_source(i);
    59 beach_source:
    60   del_fvec(vec);
    61 beach_fvec:
    62 #else /* HAVE_SINK_APPLE_AUDIO */
    63   err = 3;
    64   PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
    65 #endif /* HAVE_SINK_APPLE_AUDIO */
    66   return err;
     28  return base_main(argc, argv);
    6729}
  • tests/src/io/test-sink_sndfile.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_sink_custom "sndfile"
     6
     7#ifdef HAVE_SNDFILE
     8#define HAVE_AUBIO_SINK_CUSTOM
     9#define aubio_sink_custom_t aubio_sink_sndfile_t
     10#define new_aubio_sink_custom new_aubio_sink_sndfile
     11#define del_aubio_sink_custom del_aubio_sink_sndfile
     12#define aubio_sink_custom_do aubio_sink_sndfile_do
     13#define aubio_sink_custom_do_multi aubio_sink_sndfile_do_multi
     14#define aubio_sink_custom_close aubio_sink_sndfile_close
     15#define aubio_sink_custom_preset_samplerate aubio_sink_sndfile_preset_samplerate
     16#define aubio_sink_custom_preset_channels aubio_sink_sndfile_preset_channels
     17#define aubio_sink_custom_get_samplerate aubio_sink_sndfile_get_samplerate
     18#define aubio_sink_custom_get_channels aubio_sink_sndfile_get_channels
     19#endif /* HAVE_SNDFILE */
     20
     21#include "base-sink_custom.h"
    422
    523// this file uses the unstable aubio api, please use aubio_sink instead
     
    826int main (int argc, char **argv)
    927{
    10   sint_t err = 0;
    11 
    12   if (argc < 3) {
    13     err = 2;
    14     PRINT_ERR("not enough arguments\n");
    15     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    16     return err;
    17   }
    18 
    19 #ifdef HAVE_SNDFILE
    20   uint_t samplerate = 0;
    21   uint_t hop_size = 512;
    22   uint_t n_frames = 0, read = 0;
    23 
    24   char_t *source_path = argv[1];
    25   char_t *sink_path = argv[2];
    26 
    27   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    28   if ( argc >= 5 ) hop_size = atoi(argv[4]);
    29   if ( argc >= 6 ) {
    30     err = 2;
    31     PRINT_ERR("too many arguments\n");
    32     return err;
    33   }
    34 
    35   fvec_t *vec = new_fvec(hop_size);
    36   if (!vec) { err = 1; goto beach_fvec; }
    37 
    38   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    39   if (!i) { err = 1; goto beach_source; }
    40 
    41   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    42 
    43   aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, samplerate);
    44   if (!o) { err = 1; goto beach_sink; }
    45 
    46   do {
    47     aubio_source_do(i, vec, &read);
    48     aubio_sink_sndfile_do(o, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    53       n_frames, samplerate, n_frames / hop_size,
    54       source_path, sink_path);
    55 
    56   del_aubio_sink_sndfile(o);
    57 beach_sink:
    58   del_aubio_source(i);
    59 beach_source:
    60   del_fvec(vec);
    61 beach_fvec:
    62 #else
    63   err = 3;
    64   PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
    65 #endif /* HAVE_SNDFILE */
    66   return err;
     28  return base_main(argc, argv);
    6729}
  • tests/src/io/test-sink_wavwrite.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_sink_custom "wavwrite"
     6
     7#ifdef HAVE_WAVWRITE
     8#define HAVE_AUBIO_SINK_CUSTOM
     9#define aubio_sink_custom_t aubio_sink_wavwrite_t
     10#define new_aubio_sink_custom new_aubio_sink_wavwrite
     11#define del_aubio_sink_custom del_aubio_sink_wavwrite
     12#define aubio_sink_custom_do aubio_sink_wavwrite_do
     13#define aubio_sink_custom_do_multi aubio_sink_wavwrite_do_multi
     14#define aubio_sink_custom_close aubio_sink_wavwrite_close
     15#define aubio_sink_custom_preset_samplerate aubio_sink_wavwrite_preset_samplerate
     16#define aubio_sink_custom_preset_channels aubio_sink_wavwrite_preset_channels
     17#define aubio_sink_custom_get_samplerate aubio_sink_wavwrite_get_samplerate
     18#define aubio_sink_custom_get_channels aubio_sink_wavwrite_get_channels
     19#endif /* HAVE_WAVWRITE */
     20
     21#include "base-sink_custom.h"
    422
    523// this file uses the unstable aubio api, please use aubio_sink instead
     
    826int main (int argc, char **argv)
    927{
    10   sint_t err = 0;
    11 
    12   if (argc < 3) {
    13     err = 2;
    14     PRINT_ERR("not enough arguments\n");
    15     PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    16     return err;
    17   }
    18 
    19 #ifdef HAVE_WAVWRITE
    20   uint_t samplerate = 0;
    21   uint_t hop_size = 512;
    22   uint_t n_frames = 0, read = 0;
    23 
    24   char_t *source_path = argv[1];
    25   char_t *sink_path = argv[2];
    26 
    27   if ( argc >= 4 ) samplerate = atoi(argv[3]);
    28   if ( argc >= 5 ) hop_size = atoi(argv[4]);
    29   if ( argc >= 6 ) {
    30     err = 2;
    31     PRINT_ERR("too many arguments\n");
    32     return err;
    33   }
    34 
    35   fvec_t *vec = new_fvec(hop_size);
    36   if (!vec) { err = 1; goto beach_fvec; }
    37 
    38   aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
    39   if (!i) { err = 1; goto beach_source; }
    40 
    41   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
    42 
    43   aubio_sink_wavwrite_t *o = new_aubio_sink_wavwrite(sink_path, samplerate);
    44   if (!o) { err = 1; goto beach_sink; }
    45 
    46   do {
    47     aubio_source_do(i, vec, &read);
    48     aubio_sink_wavwrite_do(o, vec, read);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
    53       n_frames, samplerate, n_frames / hop_size,
    54       source_path, sink_path);
    55 
    56   del_aubio_sink_wavwrite(o);
    57 beach_sink:
    58   del_aubio_source(i);
    59 beach_source:
    60   del_fvec(vec);
    61 beach_fvec:
    62 #else
    63   err = 3;
    64   PRINT_ERR("aubio was not compiled with aubio_sink_wavwrite\n");
    65 #endif /* HAVE_WAVWRITE */
    66   return err;
     28  return base_main(argc, argv);
    6729}
  • tests/src/io/test-source.c

    rf87e191 r868c6b8  
    22#include "utils_tests.h"
    33
    4 int main (int argc, char **argv)
     4int test_wrong_params(void);
     5
     6int main(int argc, char **argv)
    57{
    68  uint_t err = 0;
    79  if (argc < 2) {
    8     err = 2;
    9     PRINT_ERR("not enough arguments\n");
     10    PRINT_ERR("not enough arguments, running tests\n");
     11    err = test_wrong_params();
    1012    PRINT_MSG("read a wave file as a mono vector\n");
    1113    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     
    2325  uint_t hop_size = 256;
    2426  uint_t n_frames = 0, read = 0;
    25   if ( argc == 3 ) samplerate = atoi(argv[2]);
    26   if ( argc == 4 ) hop_size = atoi(argv[3]);
     27  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     28  if ( argc >= 4 ) hop_size = atoi(argv[3]);
    2729
    2830  char_t *source_path = argv[1];
    2931
    30 
    3132  aubio_source_t* s =
    3233    new_aubio_source(source_path, samplerate, hop_size);
    33   if (!s) { err = 1; goto beach; }
    3434  fvec_t *vec = new_fvec(hop_size);
     35  if (!s || !vec) { err = 1; goto beach; }
    3536
    3637  uint_t n_frames_expected = aubio_source_get_duration(s);
     
    5051  // close the file (optional)
    5152  aubio_source_close(s);
     53
     54beach:
     55  if (vec)
     56    del_fvec(vec);
     57  if (s)
     58    del_aubio_source(s);
     59  return err;
     60}
     61
     62int test_wrong_params(void)
     63{
     64  char_t *uri = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
     65  uint_t samplerate = 44100;
     66  uint_t hop_size = 512;
     67  uint_t channels, read = 0;
     68  fvec_t *vec;
     69  fmat_t *mat;
     70  aubio_source_t *s;
     71
     72  if (new_aubio_source(0,    samplerate, hop_size)) return 1;
     73  if (new_aubio_source("\0", samplerate, hop_size)) return 1;
     74  if (new_aubio_source(uri,          -1, hop_size)) return 1;
     75  if (new_aubio_source(uri,           0,        0)) return 1;
     76
     77  s = new_aubio_source(uri, samplerate, hop_size);
     78  if (!s) return 1;
     79  channels = aubio_source_get_channels(s);
     80
     81  // vector to read downmixed samples
     82  vec = new_fvec(hop_size);
     83  // matrix to read individual channels
     84  mat = new_fmat(channels, hop_size);
     85
     86  if (aubio_source_get_samplerate(s) != samplerate) return 1;
     87
     88  // read first hop_size frames
     89  aubio_source_do(s, vec, &read);
     90  if (read != hop_size) return 1;
     91
     92  // seek to 0
     93  if(aubio_source_seek(s, 0)) return 1;
     94
     95  // read again as multiple channels
     96  aubio_source_do_multi(s, mat, &read);
     97  if (read != hop_size) return 1;
     98
     99  // close the file (optional)
     100  aubio_source_close(s);
    52101  // test closing the file a second time
    53102  aubio_source_close(s);
    54103
    55   del_fvec (vec);
    56   del_aubio_source (s);
    57 beach:
    58   return err;
     104  del_aubio_source(s);
     105  del_fmat(mat);
     106  del_fvec(vec);
     107
     108  return run_on_default_source(main);
    59109}
  • tests/src/io/test-source_apple_audio.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "apple_audio"
     6
     7#ifdef HAVE_SOURCE_APPLE_AUDIO
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_apple_audio_t
     10#define new_aubio_source_custom new_aubio_source_apple_audio
     11#define del_aubio_source_custom del_aubio_source_apple_audio
     12#define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_apple_audio_get_duration
     14#define aubio_source_custom_do aubio_source_apple_audio_do
     15#define aubio_source_custom_do_multi aubio_source_apple_audio_do_multi
     16#define aubio_source_custom_seek aubio_source_apple_audio_seek
     17#define aubio_source_custom_close aubio_source_apple_audio_close
     18#define aubio_source_custom_get_channels aubio_source_apple_audio_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_apple_audio_get_samplerate
     20#endif /* HAVE_SOURCE_APPLE_AUDIO */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     err = 2;
    13     PRINT_ERR("not enough arguments\n");
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.aif at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.mp3 at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.mp3 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #if HAVE_SOURCE_APPLE_AUDIO
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc == 3 ) samplerate = atoi(argv[2]);
    31   if ( argc == 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_apple_audio_t * s =
    37     new_aubio_source_apple_audio(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_apple_audio_get_duration(s);
    42 
    43   samplerate = aubio_source_apple_audio_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_apple_audio_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_apple_audio (s);
    57 beach:
    58 #else /* HAVE_SOURCE_APPLE_AUDIO */
    59   err = 3;
    60   PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n");
    61 #endif /* HAVE_SOURCE_APPLE_AUDIO */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/src/io/test-source_avcodec.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "avcodec"
     6
     7#ifdef HAVE_LIBAV
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_avcodec_t
     10#define new_aubio_source_custom new_aubio_source_avcodec
     11#define del_aubio_source_custom del_aubio_source_avcodec
     12#define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_avcodec_get_duration
     14#define aubio_source_custom_do aubio_source_avcodec_do
     15#define aubio_source_custom_do_multi aubio_source_avcodec_do_multi
     16#define aubio_source_custom_seek aubio_source_avcodec_seek
     17#define aubio_source_custom_close aubio_source_avcodec_close
     18#define aubio_source_custom_get_channels aubio_source_avcodec_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_avcodec_get_samplerate
     20#endif /* HAVE_LIBAV */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     err = 2;
    13     PRINT_ERR("not enough arguments\n");
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.wav at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #ifdef HAVE_LIBAV
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc == 3 ) samplerate = atoi(argv[2]);
    31   if ( argc == 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_avcodec_t * s =
    37     new_aubio_source_avcodec(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_avcodec_get_duration(s);
    42 
    43   samplerate = aubio_source_avcodec_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_avcodec_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_avcodec (s);
    57 beach:
    58 #else /* HAVE_LIBAV */
    59   err = 3;
    60   PRINT_ERR("aubio was not compiled with aubio_source_avcodec\n");
    61 #endif /* HAVE_LIBAV */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/src/io/test-source_sndfile.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "sndfile"
     6
     7#ifdef HAVE_SNDFILE
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_sndfile_t
     10#define new_aubio_source_custom new_aubio_source_sndfile
     11#define del_aubio_source_custom del_aubio_source_sndfile
     12#define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_sndfile_get_duration
     14#define aubio_source_custom_do aubio_source_sndfile_do
     15#define aubio_source_custom_do_multi aubio_source_sndfile_do_multi
     16#define aubio_source_custom_seek aubio_source_sndfile_seek
     17#define aubio_source_custom_close aubio_source_sndfile_close
     18#define aubio_source_custom_get_channels aubio_source_sndfile_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_sndfile_get_samplerate
     20#endif /* HAVE_LIBAV */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     err = 2;
    13     PRINT_ERR("not enough arguments\n");
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.wav at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #ifdef HAVE_SNDFILE
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc == 3 ) samplerate = atoi(argv[2]);
    31   if ( argc == 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_sndfile_t * s =
    37     new_aubio_source_sndfile(source_path, samplerate, hop_size);
    38   if (!s) { err = 1; goto beach; }
    39   fvec_t *vec = new_fvec(hop_size);
    40 
    41   uint_t n_frames_expected = aubio_source_sndfile_get_duration(s);
    42 
    43   samplerate = aubio_source_sndfile_get_samplerate(s);
    44 
    45   do {
    46     aubio_source_sndfile_do(s, vec, &read);
    47     fvec_print (vec);
    48     n_frames += read;
    49   } while ( read == hop_size );
    50 
    51   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    52             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    53             source_path);
    54 
    55   del_fvec (vec);
    56   del_aubio_source_sndfile (s);
    57 beach:
    58 #else
    59   err = 3;
    60   PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
    61 #endif /* HAVE_SNDFILE */
    62   return err;
     29  return base_main(argc, argv);
    6330}
  • tests/src/io/test-source_wavread.c

    rf87e191 r868c6b8  
    22#include <aubio.h>
    33#include "utils_tests.h"
     4
     5#define aubio_source_custom "wavread"
     6
     7#ifdef HAVE_WAVREAD
     8#define HAVE_AUBIO_SOURCE_CUSTOM
     9#define aubio_source_custom_t aubio_source_wavread_t
     10#define new_aubio_source_custom new_aubio_source_wavread
     11#define del_aubio_source_custom del_aubio_source_wavread
     12#define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
     13#define aubio_source_custom_get_duration aubio_source_wavread_get_duration
     14#define aubio_source_custom_do aubio_source_wavread_do
     15#define aubio_source_custom_do_multi aubio_source_wavread_do_multi
     16#define aubio_source_custom_seek aubio_source_wavread_seek
     17#define aubio_source_custom_close aubio_source_wavread_close
     18#define aubio_source_custom_get_channels aubio_source_wavread_get_channels
     19#define aubio_source_custom_get_samplerate aubio_source_wavread_get_samplerate
     20#endif /* HAVE_WAVREAD */
     21
     22#include "base-source_custom.h"
    423
    524// this file uses the unstable aubio api, please use aubio_source instead
     
    827int main (int argc, char **argv)
    928{
    10   uint_t err = 0;
    11   if (argc < 2) {
    12     err = 2;
    13     PRINT_ERR("not enough arguments\n");
    14     PRINT_MSG("read a wave file as a mono vector\n");
    15     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    16     PRINT_MSG("examples:\n");
    17     PRINT_MSG(" - read file.wav at original samplerate\n");
    18     PRINT_MSG("       %s file.wav\n", argv[0]);
    19     PRINT_MSG(" - read file.wav at 32000Hz\n");
    20     PRINT_MSG("       %s file.aif 32000\n", argv[0]);
    21     PRINT_MSG(" - read file.wav at original samplerate with 4096 blocks\n");
    22     PRINT_MSG("       %s file.wav 0 4096 \n", argv[0]);
    23     return err;
    24   }
    25 
    26 #ifdef HAVE_WAVREAD
    27   uint_t samplerate = 0;
    28   uint_t hop_size = 256;
    29   uint_t n_frames = 0, read = 0;
    30   if ( argc == 3 ) samplerate = atoi(argv[2]);
    31   if ( argc == 4 ) hop_size = atoi(argv[3]);
    32 
    33   char_t *source_path = argv[1];
    34 
    35 
    36   aubio_source_wavread_t * s =
    37     new_aubio_source_wavread(source_path, samplerate, hop_size);
    38 
    39   if (!s) { err = 1; goto beach; }
    40   fvec_t *vec = new_fvec(hop_size);
    41 
    42   uint_t n_frames_expected = aubio_source_wavread_get_duration(s);
    43 
    44   samplerate = aubio_source_wavread_get_samplerate(s);
    45 
    46   do {
    47     aubio_source_wavread_do(s, vec, &read);
    48     fvec_print (vec);
    49     n_frames += read;
    50   } while ( read == hop_size );
    51 
    52   PRINT_MSG("read %d frames (expected %d) at %dHz (%d blocks) from %s\n",
    53             n_frames, n_frames_expected, samplerate, n_frames / hop_size,
    54             source_path);
    55 
    56   del_fvec (vec);
    57   del_aubio_source_wavread (s);
    58 beach:
    59 #else
    60   err = 3;
    61   PRINT_ERR("aubio was not compiled with aubio_source_wavread\n");
    62 #endif /* HAVE_WAVREAD */
    63   return err;
     29  return base_main(argc, argv);
    6430}
  • tests/src/onset/test-onset.c

    rf87e191 r868c6b8  
    1010    err = 2;
    1111    PRINT_WRN("no arguments, running tests\n");
    12     if (test_wrong_params() != 0) {
    13       PRINT_ERR("tests failed!\n");
    14       err = 1;
    15     } else {
    16       err = 0;
    17     }
     12    err = test_wrong_params();
    1813    PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
    1914    return err;
     
    2318  uint_t hop_size = win_s / 4;
    2419  uint_t n_frames = 0, read = 0;
    25   if ( argc == 3 ) samplerate = atoi(argv[2]);
    26   if ( argc == 4 ) hop_size = atoi(argv[3]);
     20  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     21  if ( argc >= 4 ) hop_size = atoi(argv[3]);
    2722
    2823  char_t *source_path = argv[1];
     
    7570  uint_t samplerate = 44100;
    7671  // hop_size < 1
    77   if (new_aubio_onset("default", 5, 0, samplerate))
    78     return 1;
     72  if (new_aubio_onset("default", 5, 0, samplerate)) return 1;
     73
    7974  // buf_size < 2
    80   if (new_aubio_onset("default", 1, 1, samplerate))
    81     return 1;
     75  if (new_aubio_onset("default", 1, 1, samplerate)) return 1;
     76
    8277  // buf_size < hop_size
    83   if (new_aubio_onset("default", hop_size, win_size, samplerate))
    84     return 1;
     78  if (new_aubio_onset("default", hop_size, win_size, samplerate)) return 1;
     79
    8580  // samplerate < 1
    86   if (new_aubio_onset("default", 1024, 512, 0))
    87     return 1;
     81  if (new_aubio_onset("default", 1024, 512, 0)) return 1;
    8882
    8983  // specdesc creation failed
    90   if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
    91     return 1;
    92   // pv creation failed
    93   if (new_aubio_onset("default", 5, 2, samplerate))
    94     return 1;
     84  if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) return 1;
    9585
    9686  aubio_onset_t *o;
     87
     88  // pv creation might fail
     89  o = new_aubio_onset("default", 5, 2, samplerate);
     90  if (o) del_aubio_onset(o);
     91
    9792  o = new_aubio_onset("default", win_size, hop_size, samplerate);
    98   if (!aubio_onset_set_default_parameters(o, "wrong_type"))
    99     return 1;
     93  if (!aubio_onset_set_default_parameters(o, "wrong_type")) return 1;
    10094  del_aubio_onset(o);
    10195
    102   return 0;
     96  return run_on_default_source(main);
    10397}
  • tests/src/pitch/test-pitch.c

    rf87e191 r868c6b8  
    3131  aubio_cleanup ();
    3232
     33  if (new_aubio_pitch(0, win_s, hop_s, samplerate)) return 1;
     34  if (new_aubio_pitch("unknown", win_s, hop_s, samplerate)) return 1;
     35  if (new_aubio_pitch("default", win_s,     0, samplerate)) return 1;
     36  if (new_aubio_pitch("default",     0, hop_s, samplerate)) return 1;
     37  if (new_aubio_pitch("default", hop_s, win_s, samplerate)) return 1;
     38  if (new_aubio_pitch("default", win_s, hop_s,          0)) return 1;
     39
     40  o = new_aubio_pitch("default", win_s, hop_s, samplerate);
     41
     42  if (aubio_pitch_set_unit(o, "freq")) return 1;
     43  if (aubio_pitch_set_unit(o, "hertz")) return 1;
     44  if (aubio_pitch_set_unit(o, "Hertz")) return 1;
     45  if (aubio_pitch_set_unit(o, "Hz")) return 1;
     46  if (aubio_pitch_set_unit(o, "f0")) return 1;
     47  if (aubio_pitch_set_unit(o, "midi")) return 1;
     48  if (aubio_pitch_set_unit(o, "cent")) return 1;
     49  if (aubio_pitch_set_unit(o, "bin")) return 1;
     50  if (!aubio_pitch_set_unit(o, "unknown")) return 1;
     51
     52  if (aubio_pitch_set_tolerance(o, 0.3)) return 1;
     53  if (aubio_pitch_set_silence(o, 0)) return 1;
     54  if (aubio_pitch_set_silence(o, -200)) return 1;
     55  if (!aubio_pitch_set_silence(o, -300)) return 1;
     56  del_aubio_pitch(o);
     57
     58  // fft based might fail with non power of 2
     59  o = new_aubio_pitch("yinfft", win_s + 1, hop_s, samplerate);
     60  if (o) del_aubio_pitch(o);
     61  o = new_aubio_pitch("yinfast", win_s + 1, hop_s, samplerate);
     62  if (o) del_aubio_pitch(o);
     63  o = new_aubio_pitch("fcomb", win_s + 1, hop_s, samplerate);
     64  if (o) del_aubio_pitch(o);
     65  o = new_aubio_pitch("mcomb", win_s + 1, hop_s, samplerate);
     66  if (o) del_aubio_pitch(o);
     67  o = new_aubio_pitch("specacf", win_s + 1, hop_s, samplerate);
     68  if (o) del_aubio_pitch(o);
     69
    3370  return 0;
    3471}
  • tests/src/spectral/test-awhitening.c

    rf87e191 r868c6b8  
    1111    err = 2;
    1212    PRINT_WRN("no arguments, running tests\n");
    13     if (test_wrong_params() != 0) {
    14       PRINT_ERR("tests failed!\n");
    15       err = 1;
    16     } else {
    17       err = 0;
    18     }
     13    err = test_wrong_params();
    1914    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
    2015    return err;
     
    3126  if ( argc >= 4 ) samplerate = atoi(argv[3]);
    3227  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    33   if ( argc >= 6 ) {
    34     err = 2;
    35     PRINT_ERR("too many arguments\n");
    36     return err;
    37   }
    3828
    3929  fvec_t *vec = new_fvec(hop_size);
     
    5242
    5343  aubio_pvoc_t *pv = new_aubio_pvoc(win_size, hop_size);
     44  if (!pv) { err = 1; goto beach_pvoc; }
    5445
    5546  aubio_spectral_whitening_t *awhitening =
    5647    new_aubio_spectral_whitening (win_size, hop_size, samplerate);
     48  if (!awhitening) { err = 1; goto beach_awhitening; }
    5749
    5850  aubio_spectral_whitening_set_relax_time(awhitening, 20.);
     
    8274      source_path, sink_path);
    8375
     76  del_aubio_spectral_whitening(awhitening);
     77beach_awhitening:
     78  del_aubio_pvoc(pv);
     79beach_pvoc:
    8480  del_aubio_sink(o);
    8581beach_sink:
     
    8783beach_source:
    8884  del_fvec(vec);
     85  del_fvec(out);
     86  del_fvec(scale);
     87  del_cvec(fftgrain);
    8988beach_fvec:
    9089  return err;
     
    109108  del_aubio_spectral_whitening(o);
    110109
    111   return 0;
     110  return run_on_default_source_and_sink(main);
    112111}
  • tests/src/spectral/test-dct.c

    rf87e191 r868c6b8  
    3333    aubio_dct_rdo (dct, dctout, out);
    3434    for (j = 0; j < in->length; j++) {
    35       if (fabsf(in->data[j] - out->data[j]) > 10.e-4) {
    36         fprintf(stderr, "dct reconstruction failed\n");
    37       }
     35      return_code += (fabsf(in->data[j] - out->data[j]) > 10.e-4);
    3836    }
    3937  }
  • tests/src/spectral/test-mfcc.c

    rf87e191 r868c6b8  
    11#include <aubio.h>
     2#include "utils_tests.h"
    23
    3 int main (void)
     4int test_wrong_params(void);
     5
     6int main (int argc, char** argv)
     7{
     8  sint_t err = 0;
     9
     10  if (argc < 2) {
     11    err = 2;
     12    PRINT_WRN("no arguments, running tests\n");
     13    err = test_wrong_params();
     14    PRINT_MSG("usage: %s <input_path> [samplerate] [hop_size]\n", argv[0]);
     15    return err;
     16  }
     17
     18  uint_t win_s; // fft size
     19  uint_t hop_s = 256; // block size
     20  uint_t samplerate = 0; // samplerate
     21  uint_t n_filters = 40; // number of filters
     22  uint_t n_coeffs = 13; // number of coefficients
     23  uint_t read = 0;
     24
     25  char_t *source_path = argv[1];
     26
     27  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     28  if ( argc >= 4 ) hop_s = atoi(argv[3]);
     29
     30  win_s = 2 * hop_s;
     31
     32  aubio_source_t *source = 0;
     33  aubio_pvoc_t *pv = 0;
     34  aubio_mfcc_t *mfcc = 0;
     35
     36  fvec_t *in = new_fvec (win_s); // input buffer
     37  cvec_t *fftgrain = new_cvec (win_s); // input buffer
     38  fvec_t *out = new_fvec (n_coeffs); // output coefficients
     39
     40  if (!in || !fftgrain || !out) { err = 1; goto failure; }
     41
     42  // source
     43  source = new_aubio_source(source_path, samplerate, hop_s);
     44  if (!source) { err = 1; goto failure; }
     45  if (samplerate == 0) samplerate = aubio_source_get_samplerate(source);
     46
     47  // phase vocoder
     48  pv = new_aubio_pvoc(win_s, hop_s);
     49  if (!pv) { err = 1; goto failure; }
     50
     51  // mfcc object
     52  mfcc = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
     53  if (!mfcc) { err = 1; goto failure; }
     54
     55  // processing loop
     56  do {
     57    aubio_source_do(source, in, &read);
     58    aubio_pvoc_do(pv, in, fftgrain);
     59    aubio_mfcc_do(mfcc, fftgrain, out);
     60    fvec_print(out);
     61  } while (read == hop_s);
     62
     63failure:
     64
     65  if (mfcc)
     66    del_aubio_mfcc(mfcc);
     67  if (pv)
     68    del_aubio_pvoc(pv);
     69  if (source)
     70    del_aubio_source(source);
     71  if (in)
     72    del_fvec(in);
     73  if (fftgrain)
     74    del_cvec(fftgrain);
     75  if (out)
     76    del_fvec(out);
     77  aubio_cleanup();
     78  return err;
     79}
     80
     81int test_wrong_params()
    482{
    583  uint_t win_s = 512; // fft size
     
    785  uint_t n_coeffs = 13; // number of coefficients
    886  smpl_t samplerate = 16000.; // samplerate
    9   cvec_t *in = new_cvec (win_s); // input buffer
    10   fvec_t *out = new_fvec (n_coeffs); // output coefficients
    1187
    1288  if (new_aubio_mfcc(    0, n_filters, n_coeffs, samplerate)) return 1;
     
    1591  if (new_aubio_mfcc(win_s, n_filters, n_coeffs,          0)) return 1;
    1692
    17   // create mfcc object
    18   aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
    19 
    20   cvec_norm_set_all (in, 1.);
    21   aubio_mfcc_do (o, in, out);
    22   fvec_print (out);
    23 
    24   cvec_norm_set_all (in, .5);
    25   aubio_mfcc_do (o, in, out);
    26   fvec_print (out);
    27 
    28   // clean up
    29   del_aubio_mfcc (o);
    30   del_cvec (in);
    31   del_fvec (out);
    32   aubio_cleanup ();
    33 
    34   return 0;
     93  return run_on_default_source(main);
    3594}
  • tests/src/synth/test-sampler.c

    rf87e191 r868c6b8  
     1#include <string.h> // strncpy
     2#include <limits.h> // PATH_MAX
    13#include <aubio.h>
    24#include "utils_tests.h"
     
    68  sint_t err = 0;
    79
    8   if (argc < 4) {
    9     err = 2;
    10     PRINT_ERR("not enough arguments\n");
     10  if (argc < 3) {
     11    PRINT_ERR("not enough arguments, running tests\n");
     12    err = run_on_default_source_and_sink(main);
    1113    PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]);
    1214    return err;
     
    1921  char_t *source_path = argv[1];
    2022  char_t *sink_path = argv[2];
    21   char_t *sample_path = argv[3];
    22   if ( argc == 5 ) samplerate = atoi(argv[4]);
     23  char_t sample_path[PATH_MAX];
     24  if ( argc >= 4 ) {
     25    strncpy(sample_path, argv[3], PATH_MAX - 1);
     26  } else {
     27    // use input_path as sample
     28    strncpy(sample_path, source_path, PATH_MAX - 1);
     29  }
     30  sample_path[PATH_MAX - 1] = '\0';
     31  if ( argc >= 5 ) samplerate = atoi(argv[4]);
    2332
    2433  fvec_t *vec = new_fvec(hop_size);
  • tests/src/synth/test-wavetable.c

    rf87e191 r868c6b8  
    77
    88  if (argc < 2) {
    9     err = 2;
    10     PRINT_ERR("not enough arguments\n");
     9    PRINT_ERR("not enough arguments, running tests\n");
     10    err = run_on_default_sink(main);
    1111    PRINT_MSG("usage: %s <output_path> [freq] [samplerate]\n", argv[0]);
    1212    return err;
     
    1818
    1919  char_t *sink_path = argv[1];
    20   if ( argc == 4 ) samplerate = atoi(argv[3]);
    21   if ( argc == 3 ) freq = atof(argv[2]);
     20  if ( argc >= 4 ) samplerate = atoi(argv[3]);
     21  if ( argc >= 3 ) freq = atof(argv[2]);
    2222
    2323  fvec_t *vec = new_fvec(hop_size);
  • tests/src/tempo/test-tempo.c

    rf87e191 r868c6b8  
    88  uint_t err = 0;
    99  if (argc < 2) {
    10     err = 2;
    1110    PRINT_WRN("no arguments, running tests\n");
    12     if (test_wrong_params() != 0) {
    13       PRINT_ERR("tests failed!\n");
    14       err = 1;
    15     } else {
    16       err = 0;
    17     }
     11    err = test_wrong_params();
    1812    PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n",
    1913        argv[0]);
     
    8882
    8983  // test wrong method fails
    90   if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate))
    91     return 1;
     84  if (new_aubio_tempo("undefined", win_size, hop_size, samplerate)) return 1;
    9285
    9386  // test hop > win fails
    94   if (new_aubio_tempo("default", hop_size, win_size, samplerate))
    95     return 1;
     87  if (new_aubio_tempo("default", hop_size, win_size, samplerate)) return 1;
    9688
    9789  // test null hop_size fails
    98   if (new_aubio_tempo("default", win_size, 0, samplerate))
    99     return 1;
     90  if (new_aubio_tempo("default", win_size, 0, samplerate)) return 1;
    10091
    10192  // test 1 buf_size fails
    102   if (new_aubio_tempo("default", 1, 1, samplerate))
    103     return 1;
     93  if (new_aubio_tempo("default", 1, 1, samplerate)) return 1;
    10494
    10595  // test null samplerate fails
    106   if (new_aubio_tempo("default", win_size, hop_size, 0))
    107     return 1;
     96  if (new_aubio_tempo("default", win_size, hop_size, 0)) return 1;
    10897
    10998  // test short sizes workaround
    11099  t = new_aubio_tempo("default", 2048, 2048, 500);
    111   if (!t)
    112     return 1;
     100  if (!t) return 1;
    113101
    114102  del_aubio_tempo(t);
    115103
    116104  t = new_aubio_tempo("default", win_size, hop_size, samplerate);
    117   if (!t)
    118     return 1;
     105  if (!t) return 1;
    119106
    120107  in = new_fvec(hop_size);
     
    136123  del_fvec(out);
    137124
    138   return 0;
     125  return run_on_default_source(main);
    139126}
  • tests/src/temporal/test-filter.c

    rf87e191 r868c6b8  
    1010  aubio_filter_t *o = new_aubio_filter_c_weighting (44100);
    1111
    12   if (new_aubio_filter(0))
    13     return 1;
     12  if (new_aubio_filter(0)) return 1;
    1413
    15   if (aubio_filter_get_samplerate(o) != 44100)
    16     return 1;
     14  if (aubio_filter_get_samplerate(o) != 44100) return 1;
    1715
    18   if (aubio_filter_set_c_weighting (o, -1) == 0)
    19     return 1;
     16  if (aubio_filter_set_c_weighting (o, -1) == 0) return 1;
    2017
    21   if (aubio_filter_set_c_weighting (0, 32000) == 0)
    22     return 1;
     18  if (aubio_filter_set_c_weighting (0, 32000) == 0) return 1;
    2319
    2420  in->data[impulse_at] = 0.5;
     
    3026  o = new_aubio_filter_a_weighting (32000);
    3127
    32   if (aubio_filter_set_a_weighting (o, -1) == 0)
    33     return 1;
    34   if (aubio_filter_set_a_weighting (0, 32000) == 0)
    35     return 1;
     28  if (aubio_filter_set_a_weighting (o, -1) == 0) return 1;
     29
     30  if (aubio_filter_set_a_weighting (0, 32000) == 0) return 1;
    3631
    3732  in->data[impulse_at] = 0.5;
  • tests/src/test-mathutils.c

    rf87e191 r868c6b8  
    101101  fvec_set_window(window, "rectangle");
    102102  fvec_print(window);
     103  del_fvec(window);
    103104
    104105  window_size /= 2.;
    105   window = new_aubio_window("triangle", window_size);
     106  window = new_aubio_window("parzen", window_size);
    106107  fvec_print(window);
    107108  del_fvec(window);
     
    117118  test_miditofreq();
    118119  test_freqtomidi();
     120  test_aubio_window();
    119121  return 0;
    120122}
  • tests/src/utils/test-hist.c

    rf87e191 r868c6b8  
    2626    del_fvec(t);
    2727  }
     28  if (new_aubio_hist(0, 1, 0)) return 1;
    2829  return 0;
    2930}
  • tests/utils_tests.h

    rf87e191 r868c6b8  
    55#include <assert.h>
    66#include "config.h"
     7
     8#ifdef HAVE_STRING_H
     9#include <string.h>
     10#endif
     11
     12#ifdef HAVE_UNISTD_H
     13#include <unistd.h> // unlink, close
     14#endif
     15
     16#ifdef HAVE_LIMITS_H
     17#include <limits.h> // PATH_MAX
     18#endif /* HAVE_LIMITS_H */
     19#ifndef PATH_MAX
     20#define PATH_MAX 1024
     21#endif
     22
     23#if defined(HAVE_WIN_HACKS) && !defined(__GNUC__)
     24#include <io.h> // _access
     25#endif
     26
     27// This macro is used to pass a string to msvc compiler: since msvc's -D flag
     28// strips the quotes, we define the string without quotes and re-add them with
     29// this macro.
     30
     31#define REDEFINESTRING(x) #x
     32#define DEFINEDSTRING(x) REDEFINESTRING(x)
     33
     34#ifndef AUBIO_TESTS_SOURCE
     35#error "AUBIO_TESTS_SOURCE is not defined"
     36#endif
    737
    838#ifdef HAVE_C99_VARARGS_MACROS
     
    2656#endif
    2757
    28 // are we on windows ? or are we using -std=c99 ?
    29 #if defined(HAVE_WIN_HACKS) || defined(__STRICT_ANSI__)
    30 // http://en.wikipedia.org/wiki/Linear_congruential_generator
    31 // no srandom/random on win32
     58#if defined(HAVE_WIN_HACKS)
    3259
    33 uint_t srandom_seed = 1029;
     60// use srand/rand on windows
     61#define srandom srand
     62#define random rand
    3463
    35 void srandom(uint_t new_seed) {
    36     srandom_seed = new_seed;
    37 }
     64#elif defined(__STRICT_ANSI__)
    3865
    39 uint_t random(void) {
    40     srandom_seed = 1664525 * srandom_seed + 1013904223;
    41     return srandom_seed;
    42 }
     66// workaround to build with -std=c99 (for instance with older cygwin),
     67// assuming libbc is recent enough to supports these functions.
     68extern void srandom(unsigned);
     69extern int random(void);
     70extern char mkstemp(const char *pat);
     71
    4372#endif
    4473
     
    4877  time_t now = time(0);
    4978  struct tm *tm_struct = localtime(&now);
    50   int seed = tm_struct->tm_sec;
     79  size_t **tm_address = (void*)&tm_struct;
     80  int seed = tm_struct->tm_sec + (size_t)tm_address;
    5181  //PRINT_WRN("current seed: %d\n", seed);
    52   srandom (seed);
     82  srandom ((unsigned int)seed);
    5383}
     84
     85// create_temp_sink / close_temp_sink
     86#if defined(__GNUC__) // mkstemp
     87
     88int check_source(char *source_path)
     89{
     90  return access(source_path, R_OK);
     91}
     92
     93int create_temp_sink(char *sink_path)
     94{
     95  return mkstemp(sink_path);
     96}
     97
     98int close_temp_sink(char *sink_path, int sink_fildes)
     99{
     100  int err;
     101  if ((err = close(sink_fildes)) != 0) return err;
     102  if ((err = unlink(sink_path)) != 0) return err;
     103  return err;
     104}
     105
     106#elif defined(HAVE_WIN_HACKS) //&& !defined(__GNUC__)
     107// windows workaround, where mkstemp does not exist...
     108
     109int check_source(char *source_path)
     110{
     111  return _access(source_path, 04);
     112}
     113
     114int create_temp_sink(char *templ)
     115{
     116  int i = 0;
     117  static const char letters[] = "abcdefg0123456789";
     118  int letters_len = strlen(letters);
     119  int templ_len = strlen(templ);
     120  if (templ_len == 0) return 0;
     121  utils_init_random();
     122  for (i = 0; i < 6; i++)
     123  {
     124    templ[templ_len - i] = letters[rand() % letters_len];
     125  }
     126  return 1;
     127}
     128
     129int close_temp_sink(char* sink_path, int sink_fildes) {
     130  // the file should be closed when not using mkstemp, no need to open it
     131  if (sink_fildes == 0) return 1;
     132  return _unlink(sink_path);
     133}
     134
     135#else // windows workaround
     136// otherwise, we don't really know what to do yet
     137#error "mkstemp undefined, but not on windows. additional workaround required."
     138#endif
     139
     140// pass progname / default
     141int run_on_default_source( int main(int, char**) )
     142{
     143  const int argc = 2;
     144  int err = 0;
     145  char** argv = (char**)calloc(argc, sizeof(char*));
     146  argv[0] = __FILE__;
     147  argv[1] = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
     148  // check if the file can be read
     149  if ( check_source(argv[1]) ) return 1;
     150  err = main(argc, argv);
     151  if (argv) free(argv);
     152  return err;
     153}
     154
     155int run_on_default_sink( int main(int, char**) )
     156{
     157  const int argc = 2;
     158  int err = 0;
     159  char** argv = (char**)calloc(argc, sizeof(char*));
     160  char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
     161  int fd = create_temp_sink(sink_path);
     162  if (!fd) return 1;
     163  argv[0] = __FILE__;
     164  argv[1] = sink_path;
     165  err = main(argc, argv);
     166  close_temp_sink(sink_path, fd);
     167  if (argv) free(argv);
     168  return err;
     169}
     170
     171int run_on_default_source_and_sink( int main(int, char**) )
     172{
     173  const int argc = 3;
     174  int err = 0;
     175  char** argv = (char**)calloc(argc, sizeof(char*));
     176  char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
     177  int fd = create_temp_sink(sink_path);
     178  if (!fd) return 1;
     179  argv[0] = __FILE__;
     180  argv[1] = DEFINEDSTRING(AUBIO_TESTS_SOURCE);
     181  argv[2] = sink_path;
     182  // check if the file can be read
     183  if ( check_source(argv[1]) ) return 1;
     184  err = main(argc, argv);
     185  close_temp_sink(sink_path, fd);
     186  if (argv) free(argv);
     187  return err;
     188}
  • tests/wscript_build

    rf87e191 r868c6b8  
    88programs_sources = ctx.path.ant_glob('src/**/*.c')
    99
     10test_sound_target = '44100Hz_44100f_sine441_stereo.wav'
     11test_sound_abspath = bld.path.get_bld().make_node(test_sound_target)
     12# workaround to double escape backslash characters on windows
     13test_sound_abspath = str(test_sound_abspath).replace('\\', '\\\\')
     14
     15b = bld(name='create_tests_source',
     16    rule='python ${SRC} ${TGT}',
     17    source='create_tests_source.py',
     18    target=test_sound_target)
     19# use post() to create the task, keep a reference to it
     20b.post()
     21create_tests_source = b.tasks[0]
     22
    1023for source_file in programs_sources:
    1124    target = os.path.basename(os.path.splitext(str(source_file))[0])
    12     bld(features = 'c cprogram test',
     25    a = bld(features = 'c cprogram test',
    1326            source = source_file,
    1427            target = target,
     
    1629            use = uselib,
    1730            install_path = None,
    18             defines = 'AUBIO_UNSTABLE_API=1',
     31            defines = ['AUBIO_UNSTABLE_API=1',
     32                        'AUBIO_TESTS_SOURCE={}'.format(test_sound_abspath)]
    1933       )
     34    a.post()
     35    # make sure the unit_test task runs *after* the source is created
     36    a.tasks[-1].set_run_after(create_tests_source)
  • wscript

    rf87e191 r868c6b8  
    518518    sphinx(bld)
    519519
     520    from waflib.Tools import waf_unit_test
     521    bld.add_post_fun(waf_unit_test.summary)
     522    bld.add_post_fun(waf_unit_test.set_exit_code)
     523
    520524def txt2man(bld):
    521525    # build manpages from txt files using txt2man
     
    543547    if bld.env['DOXYGEN']:
    544548        bld.env.VERSION = VERSION
    545         rule = '( cat ${SRC} && echo PROJECT_NUMBER=${VERSION}; )'
     549        rule = '( cat ${SRC[0]} && echo PROJECT_NUMBER=${VERSION}'
     550        rule += ' && echo OUTPUT_DIRECTORY=%s && echo HTML_OUTPUT=%s )'
    546551        rule += ' | doxygen - > /dev/null'
     552        rule %= (os.path.abspath(out), 'api')
    547553        bld( name = 'doxygen', rule = rule,
    548                 source = 'doc/web.cfg',
    549                 target = '../doc/web/html/index.html',
    550                 cwd = 'doc')
    551         bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc',
    552                 bld.path.ant_glob('doc/web/html/**'),
    553                 cwd = bld.path.find_dir ('doc/web'),
    554                 relative_trick = True)
     554                source = ['doc/web.cfg']
     555                    + bld.path.find_dir('src').ant_glob('**/*.h'),
     556                target = bld.path.find_or_declare('api/index.html'),
     557                cwd = bld.path.find_dir('doc'))
     558        # evaluate nodes lazily to prevent build directory traversal warnings
     559        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/api',
     560                bld.path.find_or_declare('api').ant_glob('**/*',
     561                    generator=True), cwd=bld.path.find_or_declare('api'),
     562                relative_trick=True)
    555563
    556564def sphinx(bld):
    557     # build documentation from source files using sphinx-build note: build in
    558     # ../doc/_build/html, otherwise waf wont install unsigned files
    559     if bld.env['SPHINX']:
     565    # build documentation from source files using sphinx-build
     566    try:
     567        import aubio
     568        has_aubio = True
     569    except ImportError:
     570        from waflib import Logs
     571        Logs.pprint('YELLOW', "Sphinx manual: install aubio first")
     572        has_aubio = False
     573    if bld.env['SPHINX'] and has_aubio:
    560574        bld.env.VERSION = VERSION
    561         bld( name = 'sphinx',
    562                 rule = '${SPHINX} -b html -D release=${VERSION}' \
    563                         ' -D version=${VERSION} -a -q' \
    564                         ' `dirname ${SRC}` `dirname ${TGT}`',
    565                 source = 'doc/conf.py',
    566                 target = '../doc/_build/html/index.html')
    567         bld.install_files( '${DATAROOTDIR}' + '/doc/libaubio-doc/sphinx',
    568                 bld.path.ant_glob('doc/_build/html/**'),
    569                 cwd = bld.path.find_dir('doc/_build/html'),
    570                 relative_trick = True)
     575        rule = '${SPHINX} -b html -D release=${VERSION}' \
     576                ' -D version=${VERSION} -W -a -q' \
     577                ' -d %s ' % os.path.join(os.path.abspath(out), 'doctrees')
     578        rule += ' . %s' % os.path.join(os.path.abspath(out), 'manual')
     579        bld( name = 'sphinx', rule = rule,
     580                cwd = bld.path.find_dir('doc'),
     581                source = bld.path.find_dir('doc').ant_glob('*.rst'),
     582                target = bld.path.find_or_declare('manual/index.html'))
     583        # evaluate nodes lazily to prevent build directory traversal warnings
     584        bld.install_files('${DATAROOTDIR}/doc/libaubio-doc/manual',
     585                bld.path.find_or_declare('manual').ant_glob('**/*',
     586                    generator=True), cwd=bld.path.find_or_declare('manual'),
     587                relative_trick=True)
    571588
    572589# register the previous rules as build rules
Note: See TracChangeset for help on using the changeset viewer.