shithub: aubio

Download patch

ref: fabb7cd7c6c58dd5a5b74c64198252d8ddcc3583
parent: ec2fa2a5f42855f8e77f863b25448766b709c6ff
author: Paul Brossier <piem@piem.org>
date: Wed Nov 21 07:01:22 EST 2007

onsetdection.{c,h}: add spectral flux (L2 norm, only energy increases)

--- a/src/onsetdetection.c
+++ b/src/onsetdetection.c
@@ -195,6 +195,19 @@
   }
 }
 
+/* Spectral flux */
+void aubio_onsetdetection_specflux(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset){ 
+  uint_t i, j;
+  for (i=0;i<fftgrain->channels;i++) {
+    onset->data[i][0] = 0.;
+    for (j=0;j<fftgrain->length;j++) {
+      if (fftgrain->norm[i][j] > o->oldmag->data[i][j])
+        onset->data[i][0] += fftgrain->norm[i][j] - o->oldmag->data[i][j];
+      o->oldmag->data[i][j] = fftgrain->norm[i][j];
+    }
+  }
+}
+
 /* Generic function pointing to the choosen one */
 void 
 aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain, 
@@ -242,6 +255,7 @@
       break;
     case aubio_onset_kl:
     case aubio_onset_mkl:
+    case aubio_onset_specflux:
       o->oldmag = new_fvec(rsize,channels);
       break;
     default:
@@ -273,6 +287,9 @@
       break;
     case aubio_onset_mkl:
       o->funcpointer = aubio_onsetdetection_mkl;
+      break;
+    case aubio_onset_specflux:
+      o->funcpointer = aubio_onsetdetection_specflux;
       break;
     default:
       break;
--- a/src/onsetdetection.h
+++ b/src/onsetdetection.h
@@ -47,6 +47,7 @@
         aubio_onset_phase,          /**< phase fast */            
         aubio_onset_kl,             /**< Kullback Liebler */
         aubio_onset_mkl,            /**< modified Kullback Liebler */
+        aubio_onset_specflux,       /**< spectral flux */
 } aubio_onsetdetection_type;
 
 /** onsetdetection structure */
@@ -136,6 +137,18 @@
 
 */
 void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
+/** Spectral Flux 
+
+  Simon Dixon, Onset Detection Revisited, in ``Proceedings of the 9th
+  International Conference on Digital Audio Effects'' (DAFx-06), Montreal,
+  Canada, 2006. 
+
+  \param o onset detection object as returned by new_aubio_onsetdetection()
+  \param fftgrain input spectral frame
+  \param onset output onset detection function
+
+*/
+void aubio_onsetdetection_specflux(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
 /** execute onset detection function on a spectral frame 
 
   Generic function to compute onset detection.