From: Paul Brossier Date: Tue, 15 Sep 2009 16:47:58 +0000 (+0200) Subject: src/gst_aubiotempo.{c,h}: update to sample accurate beat position X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=b96669c50ad1a573d517db6eca753343daca231d;p=gst-aubio.git src/gst_aubiotempo.{c,h}: update to sample accurate beat position --- diff --git a/src/gstaubiotempo.c b/src/gstaubiotempo.c index 9a49560..a96d8fc 100644 --- a/src/gstaubiotempo.c +++ b/src/gstaubiotempo.c @@ -243,21 +243,21 @@ gst_aubio_tempo_transform_ip (GstBaseTransform * trans, GstBuffer * buf) if (filter->pos == filter->hop_size - 1) { aubio_tempo(filter->t, filter->ibuf, filter->out); - if (filter->out->data[0][0]==1) { - GstClockTime now = GST_BUFFER_TIMESTAMP (buf); + if (filter->out->data[0][0]>=1) { + gdouble now = GST_BUFFER_OFFSET (buf); // correction of inside buffer time - now += GST_FRAMES_TO_CLOCK_TIME (j, audiofilter->format.rate); - now -= GST_FRAMES_TO_CLOCK_TIME (filter->hop_size - 1, - audiofilter->format.rate); + now += (smpl_t)(j - filter->hop_size + 1); + // correction of float period + now += (filter->out->data[0][0] - 1.)*(smpl_t)filter->hop_size; if (filter->last_beat != -1 && now > filter->last_beat) { - filter->bpm = 60./(now - filter->last_beat)*1.e+9; + filter->bpm = 60./(GST_FRAMES_TO_CLOCK_TIME(now - filter->last_beat, audiofilter->format.rate))*1.e+9; } else { filter->bpm = 0.; } if (filter->silent == FALSE) { - g_print ("beat: %" GST_TIME_FORMAT " ", GST_TIME_ARGS(now)); + g_print ("beat: %f ", GST_FRAMES_TO_CLOCK_TIME( now, audiofilter->format.rate)*1.e-9); g_print ("| bpm: %f\n", filter->bpm); } diff --git a/src/gstaubiotempo.h b/src/gstaubiotempo.h index 5bf2324..82072e0 100644 --- a/src/gstaubiotempo.h +++ b/src/gstaubiotempo.h @@ -66,7 +66,7 @@ struct _GstAubioTempo signed int pos; gdouble bpm; - GstClockTime last_beat; + gdouble last_beat; aubio_onsetdetection_type type_onset;