ref: bbfa9a42e9ea4786c187774437f2553f34c019bb
parent: 8a11e2f8edc796003555b82d14d22199977abf9a
parent: db3eb5c0b4af15b5ce9c9875c76fd6603775abf6
author: Paul Brossier <piem@piem.org>
date: Mon Nov 26 13:53:43 EST 2018
Merge branch 'master' into feature/pytest
--- a/VERSION
+++ b/VERSION
@@ -1,7 +1,7 @@
AUBIO_MAJOR_VERSION=0
AUBIO_MINOR_VERSION=4
-AUBIO_PATCH_VERSION=8
-AUBIO_VERSION_STATUS=''
+AUBIO_PATCH_VERSION=9
+AUBIO_VERSION_STATUS='~alpha'
LIBAUBIO_LT_CUR=5
LIBAUBIO_LT_REV=4
LIBAUBIO_LT_AGE=8
--- a/python/tests/test_phasevoc.py
+++ b/python/tests/test_phasevoc.py
@@ -55,6 +55,15 @@
+ 'This is expected when using fftw3 on powerpc.')
assert_equal ( r, 0.)
+ def test_no_overlap(self):
+ win_s, hop_s = 1024, 1024
+ f = pvoc (win_s, hop_s)
+ t = fvec (hop_s)
+ for _ in range(4):
+ s = f(t)
+ r = f.rdo(s)
+ assert_equal ( t, 0.)
+
resynth_noise_args = "hop_s, ratio"
resynth_noise_values = [
( 256, 8),
--- /dev/null
+++ b/python/tests/test_tempo.py
@@ -1,0 +1,91 @@
+#! /usr/bin/env python
+
+from unittest import main
+from numpy.testing import TestCase, assert_equal, assert_almost_equal
+import aubio
+
+class aubio_tempo_default(TestCase):
+
+ def test_members(self):
+ o = aubio.tempo()
+ assert_equal ([o.buf_size, o.hop_size, o.method, o.samplerate],
+ [1024,512,'default',44100])
+
+class aubio_tempo_params(TestCase):
+
+ samplerate = 44100
+
+ def setUp(self):
+ self.o = aubio.tempo(samplerate = self.samplerate)
+
+ def test_get_delay(self):
+ self.assertEqual(self.o.get_delay(), 0)
+
+ def test_set_delay(self):
+ val = 256
+ self.o.set_delay(val)
+ assert_equal (self.o.get_delay(), val)
+
+ def test_get_delay_s(self):
+ self.assertEqual(self.o.get_delay_s(), 0.)
+
+ def test_set_delay_s(self):
+ val = .05
+ self.o.set_delay_s(val)
+ assert_almost_equal (self.o.get_delay_s(), val)
+
+ def test_get_delay_ms(self):
+ self.assertEqual(self.o.get_delay_ms(), 0.)
+
+ def test_set_delay_ms(self):
+ val = 50.
+ self.o.set_delay_ms(val)
+ assert_almost_equal (self.o.get_delay_ms(), val)
+
+ def test_get_threshold(self):
+ assert_almost_equal(self.o.get_threshold(), 0.3)
+
+ def test_set_threshold(self):
+ val = .1
+ self.o.set_threshold(val)
+ assert_almost_equal (self.o.get_threshold(), val)
+
+ def test_get_silence(self):
+ self.assertEqual(self.o.get_silence(), -90.)
+
+ def test_set_silence(self):
+ val = -50.
+ self.o.set_silence(val)
+ assert_almost_equal (self.o.get_silence(), val)
+
+ def test_get_last(self):
+ self.assertEqual(self.o.get_last(), 0.)
+
+ def test_get_last_s(self):
+ self.assertEqual(self.o.get_last_s(), 0.)
+
+ def test_get_last_ms(self):
+ self.assertEqual(self.o.get_last_ms(), 0.)
+
+ def test_get_period(self):
+ self.assertEqual(self.o.get_period(), 0.)
+
+ def test_get_period_s(self):
+ self.assertEqual(self.o.get_period_s(), 0.)
+
+ def test_get_last_tatum(self):
+ self.assertEqual(self.o.get_last_tatum(), 0.)
+
+ def test_set_tatum_signature(self):
+ self.o.set_tatum_signature(8)
+ self.o.set_tatum_signature(64)
+ self.o.set_tatum_signature(1)
+
+ def test_set_wrong_tatum_signature(self):
+ with self.assertRaises(ValueError):
+ self.o.set_tatum_signature(101)
+ with self.assertRaises(ValueError):
+ self.o.set_tatum_signature(0)
+
+if __name__ == '__main__':
+ main()
--- a/src/onset/onset.c
+++ b/src/onset/onset.c
@@ -256,11 +256,14 @@
o->pv = new_aubio_pvoc(buf_size, o->hop_size);
o->pp = new_aubio_peakpicker();
o->od = new_aubio_specdesc(onset_mode,buf_size);
- if (o->od == NULL) goto beach_specdesc;
o->fftgrain = new_cvec(buf_size);
o->desc = new_fvec(1);
o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate);
+ if (!o->pv || !o->pp || !o->od || !o->fftgrain
+ || !o->desc || !o->spectral_whitening)
+ goto beach;
+
/* initialize internal variables */
aubio_onset_set_default_parameters (o, onset_mode);
@@ -267,11 +270,8 @@
aubio_onset_reset(o);
return o;
-beach_specdesc:
- del_aubio_peakpicker(o->pp);
- del_aubio_pvoc(o->pv);
beach:
- AUBIO_FREE(o);
+ del_aubio_onset(o);
return NULL;
}
@@ -339,11 +339,17 @@
void del_aubio_onset (aubio_onset_t *o)
{
- del_aubio_spectral_whitening(o->spectral_whitening);
- del_aubio_specdesc(o->od);
- del_aubio_peakpicker(o->pp);
- del_aubio_pvoc(o->pv);
- del_fvec(o->desc);
- del_cvec(o->fftgrain);
+ if (o->spectral_whitening)
+ del_aubio_spectral_whitening(o->spectral_whitening);
+ if (o->od)
+ del_aubio_specdesc(o->od);
+ if (o->pp)
+ del_aubio_peakpicker(o->pp);
+ if (o->pv)
+ del_aubio_pvoc(o->pv);
+ if (o->desc)
+ del_fvec(o->desc);
+ if (o->fftgrain)
+ del_cvec(o->fftgrain);
AUBIO_FREE(o);
}
--- a/src/spectral/dct.c
+++ b/src/spectral/dct.c
@@ -81,7 +81,6 @@
aubio_dct_t* new_aubio_dct (uint_t size) {
aubio_dct_t * s = AUBIO_NEW(aubio_dct_t);
- if ((sint_t)size <= 0) goto beach;
#if defined(HAVE_ACCELERATE)
// vDSP supports sizes = f * 2 ** n, where n >= 4 and f in [1, 3, 5, 15]
// see https://developer.apple.com/documentation/accelerate/1449930-vdsp_dct_createsetup
@@ -88,7 +87,7 @@
{
uint_t radix = size;
uint_t order = 0;
- while ((radix / 2) * 2 == radix) {
+ while ((radix >= 1) && ((radix / 2) * 2 == radix)) {
radix /= 2;
order++;
}
@@ -112,7 +111,7 @@
s->del_dct = (del_aubio_dct_t)del_aubio_dct_fftw;
return s;
} else {
- AUBIO_WRN("dct: unexcepected error while creating dct_fftw with size %d",
+ AUBIO_WRN("dct: unexpected error while creating dct_fftw with size %d\n",
size);
goto plain;
}
@@ -125,7 +124,7 @@
s->del_dct = (del_aubio_dct_t)del_aubio_dct_ipp;
return s;
} else {
- AUBIO_WRN("dct: unexcepected error while creating dct_ipp with size %d",
+ AUBIO_WRN("dct: unexpected error while creating dct_ipp with size %d\n",
size);
goto plain;
}
@@ -143,7 +142,7 @@
}
#endif
// falling back to plain mode
- AUBIO_WRN("dct: d no optimised implementation could be created for size %d",
+ AUBIO_WRN("dct: no optimised implementation could be created for size %d\n",
size);
plain:
s->dct = (void *)new_aubio_dct_plain (size);
@@ -156,8 +155,8 @@
goto beach;
}
beach:
- AUBIO_ERROR("dct: failed creating with size %d, should be > 0", size);
- AUBIO_FREE (s);
+ AUBIO_ERROR("dct: failed creating with size %d, should be > 0\n", size);
+ del_aubio_dct(s);
return NULL;
}
--- a/src/spectral/dct_fftw.c
+++ b/src/spectral/dct_fftw.c
@@ -63,7 +63,9 @@
aubio_dct_fftw_t * new_aubio_dct_fftw (uint_t size) {
aubio_dct_fftw_t * s = AUBIO_NEW(aubio_dct_fftw_t);
- if (!s) {
+ if ((sint_t)size <= 0) {
+ AUBIO_ERR("dct_fftw: can only create with size > 0, requested %d\n",
+ size);
goto beach;
}
s->size = size;
--- a/src/spectral/dct_ooura.c
+++ b/src/spectral/dct_ooura.c
@@ -38,8 +38,8 @@
aubio_dct_ooura_t * new_aubio_dct_ooura (uint_t size) {
aubio_dct_ooura_t * s = AUBIO_NEW(aubio_dct_ooura_t);
- if (aubio_is_power_of_two(size) != 1) {
- AUBIO_ERR("dct: can only create with sizes power of two, requested %d\n",
+ if (aubio_is_power_of_two(size) != 1 || (sint_t)size <= 0) {
+ AUBIO_ERR("dct_ooura: can only create with sizes power of two, requested %d\n",
size);
goto beach;
}
--- a/src/spectral/dct_plain.c
+++ b/src/spectral/dct_plain.c
@@ -31,6 +31,8 @@
fmat_t *idct_coeffs; /** DCT type III orthonormal transform, size * size */
};
+void del_aubio_dct_plain (aubio_dct_plain_t *s);
+
aubio_dct_plain_t * new_aubio_dct_plain (uint_t size) {
aubio_dct_plain_t * s = AUBIO_NEW(aubio_dct_plain_t);
uint_t i, j;
@@ -38,6 +40,11 @@
if (aubio_is_power_of_two (size) == 1 && size > 16) {
AUBIO_WRN("dct_plain: using plain dct but size %d is a power of two\n", size);
}
+ if ((sint_t)size <= 0) {
+ AUBIO_ERR("dct_plain: can only create with size > 0, requested %d\n",
+ size);
+ goto failure;
+ }
s->size = size;
@@ -68,17 +75,22 @@
s->idct_coeffs->data[j][0] = 1. / SQRT (size);
}
return s;
+failure:
+ del_aubio_dct_plain(s);
+ return NULL;
}
void del_aubio_dct_plain (aubio_dct_plain_t *s) {
- del_fmat(s->dct_coeffs);
- del_fmat(s->idct_coeffs);
+ if (s->dct_coeffs)
+ del_fmat(s->dct_coeffs);
+ if (s->idct_coeffs)
+ del_fmat(s->idct_coeffs);
AUBIO_FREE(s);
}
void aubio_dct_plain_do(aubio_dct_plain_t *s, const fvec_t *input, fvec_t *output) {
if (input->length != output->length || input->length != s->size) {
- AUBIO_WRN("dct_plain: using input length %d, but output length = %d and size = %d",
+ AUBIO_WRN("dct_plain: using input length %d, but output length = %d and size = %d\n",
input->length, output->length, s->size);
}
fmat_vecmul(s->dct_coeffs, input, output);
@@ -86,7 +98,7 @@
void aubio_dct_plain_rdo(aubio_dct_plain_t *s, const fvec_t *input, fvec_t *output) {
if (input->length != output->length || input->length != s->size) {
- AUBIO_WRN("dct_plain: using input length %d, but output length = %d and size = %d",
+ AUBIO_WRN("dct_plain: using input length %d, but output length = %d and size = %d\n",
input->length, output->length, s->size);
}
fmat_vecmul(s->idct_coeffs, input, output);
--- a/src/spectral/filterbank.c
+++ b/src/spectral/filterbank.c
@@ -42,6 +42,15 @@
{
/* allocate space for filterbank object */
aubio_filterbank_t *fb = AUBIO_NEW (aubio_filterbank_t);
+
+ if ((sint_t)n_filters <= 0) {
+ AUBIO_ERR("filterbank: n_filters should be > 0, got %d\n", n_filters);
+ goto fail;
+ }
+ if ((sint_t)win_s <= 0) {
+ AUBIO_ERR("filterbank: win_s should be > 0, got %d\n", win_s);
+ goto fail;
+ }
fb->win_s = win_s;
fb->n_filters = n_filters;
@@ -53,6 +62,9 @@
fb->power = 1;
return fb;
+fail:
+ AUBIO_FREE (fb);
+ return NULL;
}
void
--- a/src/spectral/mfcc.c
+++ b/src/spectral/mfcc.c
@@ -31,10 +31,6 @@
#include "spectral/dct.h"
#include "spectral/mfcc.h"
-#ifdef HAVE_NOOPT
-#define HAVE_SLOW_DCT 1
-#endif
-
/** Internal structure for mfcc object */
struct _aubio_mfcc_t
@@ -45,12 +41,8 @@
uint_t n_coefs; /** number of coefficients (<= n_filters/2 +1) */
aubio_filterbank_t *fb; /** filter bank */
fvec_t *in_dct; /** input buffer for dct * [fb->n_filters] */
-#if defined(HAVE_SLOW_DCT)
- fmat_t *dct_coeffs; /** DCT transform n_filters * n_coeffs */
-#else
- aubio_dct_t *dct;
- fvec_t *output;
-#endif
+ aubio_dct_t *dct; /** dct object */
+ fvec_t *output; /** dct output */
smpl_t scale;
};
@@ -62,11 +54,15 @@
/* allocate space for mfcc object */
aubio_mfcc_t *mfcc = AUBIO_NEW (aubio_mfcc_t);
-#if defined(HAVE_SLOW_DCT)
- smpl_t scaling;
- uint_t i, j;
-#endif
+ if ((sint_t)n_coefs <= 0) {
+ AUBIO_ERR("mfcc: n_coefs should be > 0, got %d\n", n_coefs);
+ goto failure;
+ }
+ if ((sint_t)samplerate <= 0) {
+ AUBIO_ERR("mfcc: samplerate should be > 0, got %d\n", samplerate);
+ goto failure;
+ }
mfcc->win_s = win_s;
mfcc->samplerate = samplerate;
@@ -75,6 +71,10 @@
/* filterbank allocation */
mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s);
+
+ if (!mfcc->fb)
+ goto failure;
+
if (n_filters == 40)
aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate);
else
@@ -84,46 +84,32 @@
/* allocating buffers */
mfcc->in_dct = new_fvec (n_filters);
-#if defined(HAVE_SLOW_DCT)
- mfcc->dct_coeffs = new_fmat (n_coefs, n_filters);
-
- /* compute DCT transform dct_coeffs[j][i] as
- cos ( j * (i+.5) * PI / n_filters ) */
- scaling = 1. / SQRT (n_filters / 2.);
- for (i = 0; i < n_filters; i++) {
- for (j = 0; j < n_coefs; j++) {
- mfcc->dct_coeffs->data[j][i] =
- scaling * COS (j * (i + 0.5) * PI / n_filters);
- }
- mfcc->dct_coeffs->data[0][i] *= SQRT (2.) / 2.;
- }
-#else
mfcc->dct = new_aubio_dct (n_filters);
mfcc->output = new_fvec (n_filters);
-#endif
+ if (!mfcc->in_dct || !mfcc->dct || !mfcc->output)
+ goto failure;
+
mfcc->scale = 1.;
return mfcc;
+
+failure:
+ del_aubio_mfcc(mfcc);
+ return NULL;
}
void
del_aubio_mfcc (aubio_mfcc_t * mf)
{
-
- /* delete filterbank */
- del_aubio_filterbank (mf->fb);
-
- /* delete buffers */
- del_fvec (mf->in_dct);
-#if defined(HAVE_SLOW_DCT)
- del_fmat (mf->dct_coeffs);
-#else
- del_aubio_dct (mf->dct);
- del_fvec (mf->output);
-#endif
-
- /* delete mfcc object */
+ if (mf->fb)
+ del_aubio_filterbank (mf->fb);
+ if (mf->in_dct)
+ del_fvec (mf->in_dct);
+ if (mf->dct)
+ del_aubio_dct (mf->dct);
+ if (mf->output)
+ del_fvec (mf->output);
AUBIO_FREE (mf);
}
@@ -131,9 +117,7 @@
void
aubio_mfcc_do (aubio_mfcc_t * mf, const cvec_t * in, fvec_t * out)
{
-#ifndef HAVE_SLOW_DCT
fvec_t tmp;
-#endif
/* compute filterbank */
aubio_filterbank_do (mf->fb, in, mf->in_dct);
@@ -144,9 +128,6 @@
if (mf->scale != 1) fvec_mul (mf->in_dct, mf->scale);
/* compute mfccs */
-#if defined(HAVE_SLOW_DCT)
- fmat_vecmul(mf->dct_coeffs, mf->in_dct, out);
-#else
aubio_dct_do(mf->dct, mf->in_dct, mf->output);
// copy only first n_coeffs elements
// TODO assert mf->output->length == n_coeffs
@@ -153,7 +134,6 @@
tmp.data = mf->output->data;
tmp.length = out->length;
fvec_copy(&tmp, out);
-#endif
return;
}
--- a/src/spectral/specdesc.c
+++ b/src/spectral/specdesc.c
@@ -296,7 +296,8 @@
else if (strcmp (onset_mode, "default") == 0)
onset_type = aubio_onset_default;
else {
- AUBIO_ERR("unknown spectral descriptor type %s\n", onset_mode);
+ AUBIO_ERR("specdesc: unknown spectral descriptor type '%s'\n",
+ onset_mode);
AUBIO_FREE(o);
return NULL;
}
--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -128,8 +128,7 @@
}
uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay) {
- o->delay = 1000. * delay * o->samplerate;
- return AUBIO_OK;
+ return aubio_tempo_set_delay_s(o, delay / 1000.);
}
uint_t aubio_tempo_get_delay(aubio_tempo_t * o) {
@@ -141,7 +140,7 @@
}
smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o) {
- return o->delay / (smpl_t)(o->samplerate) / 1000.;
+ return aubio_tempo_get_delay_s(o) * 1000.;
}
uint_t aubio_tempo_set_silence(aubio_tempo_t * o, smpl_t silence) {
@@ -168,7 +167,7 @@
uint_t buf_size, uint_t hop_size, uint_t samplerate)
{
aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
- char_t specdesc_func[20];
+ char_t specdesc_func[PATH_MAX];
o->samplerate = samplerate;
// check parameters are valid
if ((sint_t)hop_size < 1) {
@@ -203,9 +202,10 @@
o->pp = new_aubio_peakpicker();
aubio_peakpicker_set_threshold (o->pp, o->threshold);
if ( strcmp(tempo_mode, "default") == 0 ) {
- strcpy(specdesc_func, "specflux");
+ strncpy(specdesc_func, "specflux", PATH_MAX - 1);
} else {
- strcpy(specdesc_func, tempo_mode);
+ strncpy(specdesc_func, tempo_mode, PATH_MAX - 1);
+ specdesc_func[PATH_MAX - 1] = '\0';
}
o->od = new_aubio_specdesc(specdesc_func,buf_size);
o->of = new_fvec(1);
@@ -215,12 +215,17 @@
o2 = new_aubio_specdesc(type_onset2,buffer_size);
onset2 = new_fvec(1);
}*/
+ if (!o->dfframe || !o->fftgrain || !o->out || !o->pv ||
+ !o->pp || !o->od || !o->of || !o->bt || !o->onset) {
+ AUBIO_ERR("tempo: failed creating tempo object\n");
+ goto beach;
+ }
o->last_tatum = 0;
o->tatum_signature = 4;
return o;
beach:
- AUBIO_FREE(o);
+ del_aubio_tempo(o);
return NULL;
}
@@ -277,15 +282,23 @@
void del_aubio_tempo (aubio_tempo_t *o)
{
- del_aubio_specdesc(o->od);
- del_aubio_beattracking(o->bt);
- del_aubio_peakpicker(o->pp);
- del_aubio_pvoc(o->pv);
- del_fvec(o->out);
- del_fvec(o->of);
- del_cvec(o->fftgrain);
- del_fvec(o->dfframe);
- del_fvec(o->onset);
+ if (o->od)
+ del_aubio_specdesc(o->od);
+ if (o->bt)
+ del_aubio_beattracking(o->bt);
+ if (o->pp)
+ del_aubio_peakpicker(o->pp);
+ if (o->pv)
+ del_aubio_pvoc(o->pv);
+ if (o->out)
+ del_fvec(o->out);
+ if (o->of)
+ del_fvec(o->of);
+ if (o->fftgrain)
+ del_cvec(o->fftgrain);
+ if (o->dfframe)
+ del_fvec(o->dfframe);
+ if (o->onset)
+ del_fvec(o->onset);
AUBIO_FREE(o);
- return;
}
--- a/tests/src/onset/test-onset.c
+++ b/tests/src/onset/test-onset.c
@@ -1,13 +1,20 @@
#include <aubio.h>
#include "utils_tests.h"
+int test_wrong_params(void);
+
int main (int argc, char **argv)
{
uint_t err = 0;
if (argc < 2) {
err = 2;
- PRINT_ERR("not enough arguments\n");
- PRINT_MSG("read a wave file as a mono vector\n");
+ PRINT_WRN("no arguments, running tests\n");
+ if (test_wrong_params() != 0) {
+ PRINT_ERR("tests failed!\n");
+ err = 1;
+ } else {
+ err = 0;
+ }
PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
return err;
}
@@ -59,4 +66,38 @@
aubio_cleanup();
return err;
+}
+
+int test_wrong_params(void)
+{
+ uint_t win_size = 1024;
+ uint_t hop_size = win_size / 2;
+ uint_t samplerate = 44100;
+ // hop_size < 1
+ if (new_aubio_onset("default", 5, 0, samplerate))
+ return 1;
+ // buf_size < 2
+ if (new_aubio_onset("default", 1, 1, samplerate))
+ return 1;
+ // buf_size < hop_size
+ if (new_aubio_onset("default", hop_size, win_size, samplerate))
+ return 1;
+ // samplerate < 1
+ if (new_aubio_onset("default", 1024, 512, 0))
+ return 1;
+
+ // specdesc creation failed
+ if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
+ return 1;
+ // pv creation failed
+ if (new_aubio_onset("default", 5, 2, samplerate))
+ return 1;
+
+ aubio_onset_t *o;
+ o = new_aubio_onset("default", win_size, hop_size, samplerate);
+ if (!aubio_onset_set_default_parameters(o, "wrong_type"))
+ return 1;
+ del_aubio_onset(o);
+
+ return 0;
}
--- a/tests/src/spectral/test-awhitening.c
+++ b/tests/src/spectral/test-awhitening.c
@@ -1,6 +1,8 @@
#include <aubio.h>
#include "utils_tests.h"
+int test_wrong_params(void);
+
int main (int argc, char **argv)
{
sint_t err = 0;
@@ -7,7 +9,13 @@
if (argc < 3) {
err = 2;
- PRINT_ERR("not enough arguments\n");
+ PRINT_WRN("no arguments, running tests\n");
+ if (test_wrong_params() != 0) {
+ PRINT_ERR("tests failed!\n");
+ err = 1;
+ } else {
+ err = 0;
+ }
PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
return err;
}
@@ -82,3 +90,23 @@
return err;
}
+int test_wrong_params(void)
+{
+ uint_t buf_size = 512;
+ uint_t hop_size = 256;
+ uint_t samplerate = 44100;
+ aubio_spectral_whitening_t *o;
+
+ if (new_aubio_spectral_whitening( 0, hop_size, samplerate)) return 1;
+ if (new_aubio_spectral_whitening(buf_size, 0, samplerate)) return 1;
+ if (new_aubio_spectral_whitening(buf_size, hop_size, 0)) return 1;
+
+ o = new_aubio_spectral_whitening(buf_size, hop_size, samplerate);
+
+ aubio_spectral_whitening_get_relax_time(o);
+ aubio_spectral_whitening_get_floor(o);
+
+ del_aubio_spectral_whitening(o);
+
+ return 0;
+}
--- a/tests/src/spectral/test-dct.c
+++ b/tests/src/spectral/test-dct.c
@@ -9,10 +9,18 @@
uint_t i, j, n_iters = 10; // number of iterations
// create dct object
aubio_dct_t * dct = new_aubio_dct(win_s);
+ aubio_dct_t * tmp;
+ if (new_aubio_dct(0)) return 1;
+
fvec_t * in = new_fvec (win_s); // input buffer
fvec_t * dctout = new_fvec (win_s); // output buffer
fvec_t * out = new_fvec (win_s); // input buffer
+
+ if ((tmp = new_aubio_dct(1)) == 0) return 1;
+ //aubio_dct_do(tmp, dctout, out);
+ //aubio_dct_rdo(tmp, dctout, out);
+ del_aubio_dct(tmp);
if (!dct || !in || !dctout) {
return_code = 1;
--- a/tests/src/spectral/test-filterbank.c
+++ b/tests/src/spectral/test-filterbank.c
@@ -8,6 +8,9 @@
cvec_t *in_spec = new_cvec (win_s); // input vector of samples
fvec_t *out_filters = new_fvec (n_filters); // per-band outputs
+ if (new_aubio_filterbank(0, win_s)) return 1;
+ if (new_aubio_filterbank(n_filters, 0)) return 1;
+
// create filterbank object
aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s);
--- a/tests/src/spectral/test-mfcc.c
+++ b/tests/src/spectral/test-mfcc.c
@@ -4,13 +4,18 @@
{
uint_t win_s = 512; // fft size
uint_t n_filters = 40; // number of filters
- uint_t n_coefs = 13; // number of coefficients
+ uint_t n_coeffs = 13; // number of coefficients
smpl_t samplerate = 16000.; // samplerate
cvec_t *in = new_cvec (win_s); // input buffer
- fvec_t *out = new_fvec (n_coefs); // output coefficients
+ fvec_t *out = new_fvec (n_coeffs); // output coefficients
+ if (new_aubio_mfcc( 0, n_filters, n_coeffs, samplerate)) return 1;
+ if (new_aubio_mfcc(win_s, 0, n_coeffs, samplerate)) return 1;
+ if (new_aubio_mfcc(win_s, n_filters, 0, samplerate)) return 1;
+ if (new_aubio_mfcc(win_s, n_filters, n_coeffs, 0)) return 1;
+
// create mfcc object
- aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate);
+ aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coeffs, samplerate);
cvec_norm_set_all (in, 1.);
aubio_mfcc_do (o, in, out);
--- a/tests/src/spectral/test-phasevoc.c
+++ b/tests/src/spectral/test-phasevoc.c
@@ -13,6 +13,13 @@
// allocate fft and other memory space
aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s);
+ if (new_aubio_pvoc(win_s, 0)) return 1;
+
+ if (aubio_pvoc_get_win(pv) != win_s) return 1;
+ if (aubio_pvoc_get_hop(pv) != hop_s) return 1;
+
+ if (aubio_pvoc_set_window(pv, "hanningz") != 0) return 1;
+
// fill input with some data
fvec_set_all (in, 1.);
fvec_print (in);
--- a/tests/src/spectral/test-tss.c
+++ b/tests/src/spectral/test-tss.c
@@ -34,6 +34,10 @@
aubio_pvoc_rdo (pvs, ctrans, trans);
}
+ aubio_tss_set_alpha(tss, 4.);
+ aubio_tss_set_beta(tss, 3.);
+ aubio_tss_set_threshold(tss, 3.);
+
del_aubio_pvoc(pv);
del_aubio_pvoc(pvt);
del_aubio_pvoc(pvs);
--- a/tests/src/tempo/test-tempo.c
+++ b/tests/src/tempo/test-tempo.c
@@ -1,14 +1,22 @@
#include <aubio.h>
#include "utils_tests.h"
+int test_wrong_params(void);
+
int main (int argc, char **argv)
{
uint_t err = 0;
if (argc < 2) {
err = 2;
- PRINT_ERR("not enough arguments\n");
- PRINT_MSG("read a wave file as a mono vector\n");
- PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n", argv[0]);
+ PRINT_WRN("no arguments, running tests\n");
+ if (test_wrong_params() != 0) {
+ PRINT_ERR("tests failed!\n");
+ err = 1;
+ } else {
+ err = 0;
+ }
+ PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n",
+ argv[0]);
return err;
}
uint_t samplerate = 0;
@@ -20,7 +28,8 @@
uint_t n_frames = 0, read = 0;
char_t *source_path = argv[1];
- aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size);
+ aubio_source_t * source = new_aubio_source(source_path, samplerate,
+ hop_size);
if (!source) { err = 1; goto beach; }
if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
@@ -30,8 +39,11 @@
fvec_t * out = new_fvec (1); // output position
// create tempo object
- aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate);
+ aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size,
+ samplerate);
+ if (!o) { err = 1; goto beach_tempo; }
+
do {
// put some fresh data in input vector
aubio_source_do(source, in, &read);
@@ -39,9 +51,11 @@
aubio_tempo_do(o,in,out);
// do something with the beats
if (out->data[0] != 0) {
- PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2fbpm with confidence %.2f\n",
+ PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2f bpm "
+ "with confidence %.2f\n",
aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o),
- aubio_tempo_get_last(o), aubio_tempo_get_bpm(o), aubio_tempo_get_confidence(o));
+ aubio_tempo_get_last(o), aubio_tempo_get_bpm(o),
+ aubio_tempo_get_confidence(o));
}
n_frames += read;
} while ( read == hop_size );
@@ -53,6 +67,7 @@
// clean up memory
del_aubio_tempo(o);
+beach_tempo:
del_fvec(in);
del_fvec(out);
del_aubio_source(source);
@@ -60,4 +75,65 @@
aubio_cleanup();
return err;
+}
+
+int test_wrong_params(void)
+{
+ uint_t win_size = 1024;
+ uint_t hop_size = 256;
+ uint_t samplerate = 44100;
+ aubio_tempo_t *t;
+ fvec_t* in, *out;
+ uint_t i;
+
+ // test wrong method fails
+ if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate))
+ return 1;
+
+ // test hop > win fails
+ if (new_aubio_tempo("default", hop_size, win_size, samplerate))
+ return 1;
+
+ // test null hop_size fails
+ if (new_aubio_tempo("default", win_size, 0, samplerate))
+ return 1;
+
+ // test 1 buf_size fails
+ if (new_aubio_tempo("default", 1, 1, samplerate))
+ return 1;
+
+ // test null samplerate fails
+ if (new_aubio_tempo("default", win_size, hop_size, 0))
+ return 1;
+
+ // test short sizes workaround
+ t = new_aubio_tempo("default", 2048, 2048, 500);
+ if (!t)
+ return 1;
+
+ del_aubio_tempo(t);
+
+ t = new_aubio_tempo("default", win_size, hop_size, samplerate);
+ if (!t)
+ return 1;
+
+ in = new_fvec(hop_size);
+ out = new_fvec(1);
+
+ // up to step = (next_power_of_two(5.8 * samplerate / hop_size ) / 4 )
+ for (i = 0; i < 256 + 1; i++)
+ {
+ aubio_tempo_do(t,in,out);
+ PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2f bpm "
+ "with confidence %.2f, was tatum %d\n",
+ aubio_tempo_get_last_ms(t), aubio_tempo_get_last_s(t),
+ aubio_tempo_get_last(t), aubio_tempo_get_bpm(t),
+ aubio_tempo_get_confidence(t), aubio_tempo_was_tatum(t));
+ }
+
+ del_aubio_tempo(t);
+ del_fvec(in);
+ del_fvec(out);
+
+ return 0;
}