ref: 7e80dc995fca1efe9b996c34c8380ebd66b47442
parent: fa74361e4d4aefdd8d8a43797b27d799e04c4872
author: Paul Brossier <piem@piem.org>
date: Mon Feb 8 13:06:52 EST 2016
src/tempo/tempo.h: implement get/set_delay
--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -28,27 +28,6 @@
#include "mathutils.h"
#include "tempo/tempo.h"
-// TODO implement get/set_delay
-
-/** set current delay
-
- \param o beat tracking object
-
- \return current delay, in samples
-
- */
-uint_t aubio_tempo_get_delay(aubio_tempo_t * o);
-
-/** set current delay
-
- \param o beat tracking object
- \param delay delay to set tempo to, in samples
-
- \return `0` if successful, non-zero otherwise
-
- */
-uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay);
-
/* structure to store object state */
struct _aubio_tempo_t {
aubio_specdesc_t * od; /** onset detection */
@@ -69,7 +48,7 @@
uint_t hop_size; /** get hop_size */
uint_t total_frames; /** total frames since beginning */
uint_t last_beat; /** time of latest detected beat, in samples */
- uint_t delay; /** delay to remove to last beat, in samples */
+ sint_t delay; /** delay to remove to last beat, in samples */
uint_t last_tatum; /** time of latest detected tatum, in samples */
uint_t tatum_signature; /** number of tatum between each beats */
};
@@ -124,7 +103,7 @@
uint_t aubio_tempo_get_last (aubio_tempo_t *o)
{
- return o->last_beat - o->delay;
+ return o->last_beat + o->delay;
}
smpl_t aubio_tempo_get_last_s (aubio_tempo_t *o)
@@ -137,13 +116,31 @@
return aubio_tempo_get_last_s (o) * 1000.;
}
-uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay) {
+uint_t aubio_tempo_set_delay(aubio_tempo_t * o, sint_t delay) {
o->delay = delay;
return AUBIO_OK;
}
+uint_t aubio_tempo_set_delay_s(aubio_tempo_t * o, smpl_t delay) {
+ o->delay = delay * o->samplerate;
+ return AUBIO_OK;
+}
+
+uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay) {
+ o->delay = 1000. * delay * o->samplerate;
+ return AUBIO_OK;
+}
+
uint_t aubio_tempo_get_delay(aubio_tempo_t * o) {
return o->delay;
+}
+
+smpl_t aubio_tempo_get_delay_s(aubio_tempo_t * o) {
+ return o->delay / (smpl_t)(o->samplerate);
+}
+
+smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o) {
+ return o->delay / (smpl_t)(o->samplerate) / 1000.;
}
uint_t aubio_tempo_set_silence(aubio_tempo_t * o, smpl_t silence) {
--- a/src/tempo/tempo.h
+++ b/src/tempo/tempo.h
@@ -184,6 +184,63 @@
*/
smpl_t aubio_tempo_get_last_tatum(aubio_tempo_t *o);
+/** get current delay
+
+ \param o beat tracking object
+
+ \return current delay, in samples
+
+ */
+uint_t aubio_tempo_get_delay(aubio_tempo_t * o);
+
+/** get current delay in seconds
+
+ \param o beat tracking object
+
+ \return current delay, in seconds
+
+ */
+smpl_t aubio_tempo_get_delay_s(aubio_tempo_t * o);
+
+/** get current delay in ms
+
+ \param o beat tracking object
+
+ \return current delay, in milliseconds
+
+ */
+smpl_t aubio_tempo_get_delay_ms(aubio_tempo_t * o);
+
+/** set current delay
+
+ \param o beat tracking object
+ \param delay delay to set tempo to, in samples
+
+ \return `0` if successful, non-zero otherwise
+
+ */
+uint_t aubio_tempo_set_delay(aubio_tempo_t * o, sint_t delay);
+
+/** set current delay in seconds
+
+ \param o beat tracking object
+ \param delay delay to set tempo to, in seconds
+
+ \return `0` if successful, non-zero otherwise
+
+ */
+uint_t aubio_tempo_set_delay_s(aubio_tempo_t * o, smpl_t delay);
+
+/** set current delay
+
+ \param o beat tracking object
+ \param delay delay to set tempo to, in samples
+
+ \return `0` if successful, non-zero otherwise
+
+ */
+uint_t aubio_tempo_set_delay_ms(aubio_tempo_t * o, smpl_t delay);
+
/** delete tempo detection object
\param o beat tracking object