src/synth/sampler.h: add aubio_sampler_get_duration sampler
authorPaul Brossier <piem@piem.org>
Tue, 27 Jun 2017 14:56:00 +0000 (16:56 +0200)
committerPaul Brossier <piem@piem.org>
Tue, 27 Jun 2017 14:56:00 +0000 (16:56 +0200)
src/synth/sampler.c
src/synth/sampler.h

index 6b6236b..6284f2a 100644 (file)
@@ -56,6 +56,7 @@ typedef enum {
 struct _aubio_sampler_t {
   uint_t samplerate;
   uint_t blocksize;
+  uint_t duration;
   // current reading mode (can be a file or an array)
   uint_t reading_from;
   // current interpolation mode (can be quadratic, timestretch, ...)
@@ -128,6 +129,7 @@ aubio_sampler_t *new_aubio_sampler(uint_t blocksize, uint_t samplerate)
   }
   s->samplerate = samplerate;
   s->blocksize = blocksize;
+  s->duration = 0;
   s->source = NULL;
   s->playing = 0;
   s->loop = 0;
@@ -278,6 +280,7 @@ uint_t aubio_sampler_load( aubio_sampler_t * o, const char_t * uri )
     o->eof_remaining = 0;
     o->opened = 1;
     ret = AUBIO_OK;
+    o->duration = duration;
     AUBIO_MSG("sampler: loaded %s\n", uri);
 #ifdef HAVE_THREADS
     if (o->waited) {
@@ -810,6 +813,17 @@ aubio_sampler_get_samplerate (aubio_sampler_t *o)
 }
 
 uint_t
+aubio_sampler_get_duration (aubio_sampler_t *o)
+{
+  if (o->duration !=0) {
+    return o->duration;
+  } else {
+    AUBIO_WRN("sampler: failed getting duration for %s\n", o->uri);
+    return 0;
+  }
+}
+
+uint_t
 aubio_sampler_get_opened (aubio_sampler_t *o)
 {
   return o->opened; //== 1 ? AUBIO_OK : AUBIO_FAIL;
index 3e7db30..490203d 100644 (file)
@@ -217,6 +217,15 @@ uint_t aubio_sampler_get_finished (aubio_sampler_t * o);
 */
 uint_t aubio_sampler_get_samplerate(aubio_sampler_t * o);
 
+/** get duration
+
+  \param o sampler, created by new_aubio_sampler()
+
+  \return duration of the opened uri, in samples
+
+*/
+uint_t aubio_sampler_get_duration(aubio_sampler_t * o);
+
 /** get the number of samples that were set to zero while opening a file
 
   \param o sampler, created by new_aubio_sampler()