From c23e59160fc0ad02ec2cb76fa5938f452887f468 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 11 Mar 2017 04:57:49 +0100 Subject: [PATCH] src/spectral/specdesc.c: add weighted phase deviation --- src/spectral/specdesc.c | 26 ++++++++++++++++++++++++++ src/spectral/specdesc.h | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/src/spectral/specdesc.c b/src/spectral/specdesc.c index 67b95c39..adade618 100644 --- a/src/spectral/specdesc.c +++ b/src/spectral/specdesc.c @@ -30,6 +30,7 @@ void aubio_specdesc_energy(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t void aubio_specdesc_hfc(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); void aubio_specdesc_complex(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); void aubio_specdesc_phase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); +void aubio_specdesc_wphase(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); void aubio_specdesc_kl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); void aubio_specdesc_mkl(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset); @@ -57,6 +58,7 @@ typedef enum { aubio_onset_hfc, /**< high frequency content */ aubio_onset_complex, /**< complex domain */ aubio_onset_phase, /**< phase fast */ + aubio_onset_wphase, /**< weighted phase */ aubio_onset_kl, /**< Kullback Liebler */ aubio_onset_mkl, /**< modified Kullback Liebler */ aubio_onset_specflux, /**< spectral flux */ @@ -159,6 +161,23 @@ void aubio_specdesc_phase(aubio_specdesc_t *o, //onset->data[0] = fvec_mean(o->dev1); } +/* weighted phase */ +void +aubio_specdesc_wphase(aubio_specdesc_t *o, + const cvec_t *fftgrain, fvec_t *onset) { + uint_t i; + aubio_specdesc_phase(o, fftgrain, onset); + for (i = 0; i < fftgrain->length; i++) { + o->dev1->data[i] *= fftgrain->norm[i]; + } + /* apply o->histogram */ + aubio_hist_dyn_notnull(o->histog,o->dev1); + /* weight it */ + aubio_hist_weight(o->histog); + /* its mean is the result */ + onset->data[0] = aubio_hist_mean(o->histog); +} + /* Spectral difference method onset detection function */ void aubio_specdesc_specdiff(aubio_specdesc_t *o, const cvec_t * fftgrain, fvec_t * onset){ @@ -250,6 +269,8 @@ new_aubio_specdesc (const char_t * onset_mode, uint_t size){ onset_type = aubio_onset_complex; else if (strcmp (onset_mode, "phase") == 0) onset_type = aubio_onset_phase; + else if (strcmp (onset_mode, "wphase") == 0) + onset_type = aubio_onset_wphase; else if (strcmp (onset_mode, "mkl") == 0) onset_type = aubio_onset_mkl; else if (strcmp (onset_mode, "kl") == 0) @@ -291,6 +312,7 @@ new_aubio_specdesc (const char_t * onset_mode, uint_t size){ o->theta2 = new_fvec(rsize); break; case aubio_onset_phase: + case aubio_onset_wphase: o->dev1 = new_fvec(rsize); o->theta1 = new_fvec(rsize); o->theta2 = new_fvec(rsize); @@ -325,6 +347,9 @@ new_aubio_specdesc (const char_t * onset_mode, uint_t size){ case aubio_onset_phase: o->funcpointer = aubio_specdesc_phase; break; + case aubio_onset_wphase: + o->funcpointer = aubio_specdesc_wphase; + break; case aubio_onset_specdiff: o->funcpointer = aubio_specdesc_specdiff; break; @@ -378,6 +403,7 @@ void del_aubio_specdesc (aubio_specdesc_t *o){ del_fvec(o->theta2); break; case aubio_onset_phase: + case aubio_onset_wphase: del_fvec(o->dev1); del_fvec(o->theta1); del_fvec(o->theta2); diff --git a/src/spectral/specdesc.h b/src/spectral/specdesc.h index 2cdb87ac..6cb5796e 100644 --- a/src/spectral/specdesc.h +++ b/src/spectral/specdesc.h @@ -59,6 +59,13 @@ Conference on Acoustics Speech and Signal Processing, pages 441­444, Hong-Kong, 2003. + \b \p wphase : Weighted Phase Deviation onset detection function + + S. Dixon. Onset detection revisited. In Proceedings of the 9th International + Conference on Digital Audio Ef- fects (DAFx) , pages 133–137, 2006. + + http://www.eecs.qmul.ac.uk/~simond/pub/2006/dafx.pdf + \b \p specdiff : Spectral difference method onset detection function Jonhatan Foote and Shingo Uchihashi. The beat spectrum: a new approach to -- 2.11.0