def __init__(self,bufsize,hopsize,channels,myvec,threshold,mode='dual',derivate=False):
self.myfft = cvec(bufsize,channels)
self.pv = pvoc(bufsize,hopsize,channels)
- if mode in [complexdomain,hfc,phase,energy,specdiff] :
- self.myod = onsetdetection(mode,bufsize,channels)
- self.myonset = fvec(1,channels)
- else:
+ if mode in ['dual'] :
self.myod = onsetdetection(hfc,bufsize,channels)
self.myod2 = onsetdetection(complexdomain,bufsize,channels)
self.myonset = fvec(1,channels)
self.myonset2 = fvec(1,channels)
+ else:
+ self.myod = onsetdetection(mode,bufsize,channels)
+ self.myonset = fvec(1,channels)
self.mode = mode
self.pp = peakpick(float(threshold))
self.derivate = derivate
import numarray
from aubio.onsetcompare import onset_roc
+ if len(onsets) == 0: onsets = [0.];
+
# onset detection function
downtime = (hopsize/samplerate)*numarray.arange(len(ofunc))
d = Gnuplot.Data(downtime,ofunc,with='lines')
/* Complex Domain Method onset detection function */
-/* moved to /2 032402 */
void aubio_onsetdetection_complex (aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset) {
uint_t i, j;
uint_t nbins = fftgrain->length;
}
/* Spectral difference method onset detection function */
-/* moved to /2 032402 */
void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o,
cvec_t * fftgrain, fvec_t * onset){
uint_t i, j;
}
}
+/* Kullback Liebler onset detection function
+ * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
+ * negative (1.+) and infinite values (+1.e-10) */
+void aubio_onsetdetection_kl(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++) {
+ onset->data[i][0] += fftgrain->norm[i][j]
+ *LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
+ o->oldmag->data[i][j] = fftgrain->norm[i][j];
+ }
+ if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
+ }
+}
+
+/* Modified Kullback Liebler onset detection function
+ * note we use ln(1+Xn/(Xn-1+0.0001)) to avoid
+ * negative (1.+) and infinite values (+1.e-10) */
+void aubio_onsetdetection_mkl(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++) {
+ onset->data[i][0] += LOG(1.+fftgrain->norm[i][j]/(o->oldmag->data[i][j]+1.e-10));
+ o->oldmag->data[i][j] = fftgrain->norm[i][j];
+ }
+ if (isnan(onset->data[i][0])) onset->data[i][0] = 0.;
+ }
+}
+
/* Generic function pointing to the choosen one */
void
aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain,
o->histog = new_aubio_hist(0.0f, PI, 10, channels);
o->threshold = 0.1;
break;
+ case kl:
+ o->oldmag = new_fvec(rsize,channels);
+ break;
+ case mkl:
+ o->oldmag = new_fvec(rsize,channels);
+ break;
default:
break;
}
case specdiff:
o->funcpointer = aubio_onsetdetection_specdiff;
break;
+ case kl:
+ o->funcpointer = aubio_onsetdetection_kl;
+ break;
+ case mkl:
+ o->funcpointer = aubio_onsetdetection_mkl;
+ break;
default:
break;
}
specdiff, /**< spectral diff */
hfc, /**< high frequency content */
complexdomain, /**< complex domain */
- phase /**< phase fast */
+ phase, /**< phase fast */
+ kl, /**< Kullback Liebler (Hainsworth et al., Onset detection in musical audio signals) */
+ mkl /**< modified Kullback Liebler (Hainsworth et al., Onset detection in musical audio signals) */
} aubio_onsetdetection_type;
/** onsetdetection structure */
* - interpfact 2
*/
void aubio_onsetdetection_specdiff(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
+/** Kullback-Liebler onset detection function */
+void aubio_onsetdetection_kl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
+/** Modified Kullback-Liebler onset detection function */
+void aubio_onsetdetection_mkl(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
/** Generic function pointing to the choosen one */
void aubio_onsetdetection(aubio_onsetdetection_t *o, cvec_t * fftgrain, fvec_t * onset);
/** Allocate memory for an onset detection */