shithub: aubio

Download patch

ref: a874c48ee48f246ad5ca2c84903e904e55136d2f
parent: 456a784c9332c040a4374456357cd71143b039d1
author: Paul Brossier <piem@piem.org>
date: Thu Sep 29 12:21:50 EDT 2016

src/effects/timestretch_rubberband.c: split into functions

--- a/src/effects/timestretch_rubberband.c
+++ b/src/effects/timestretch_rubberband.c
@@ -51,6 +51,9 @@
 
 extern RubberBandOptions aubio_get_rubberband_opts(const char_t *mode);
 
+static void aubio_timestretch_warmup (aubio_timestretch_t * p);
+static sint_t aubio_timestretch_fetch(aubio_timestretch_t *p);
+
 aubio_timestretch_t *
 new_aubio_timestretch (const char_t * uri, const char_t * mode,
     smpl_t stretchratio, uint_t hopsize, uint_t samplerate)
@@ -85,7 +88,18 @@
   rubberband_set_max_process_size(p->rb, p->hopsize);
   //rubberband_set_debug_level(p->rb, 10);
 
-#if 1
+  aubio_timestretch_warmup(p);
+
+  return p;
+
+beach:
+  del_aubio_timestretch(p);
+  return NULL;
+}
+
+static void
+aubio_timestretch_warmup (aubio_timestretch_t * p)
+{
   // warm up rubber band
   uint_t source_read = 0;
   unsigned int latency = MAX(p->hopsize, rubberband_get_latency(p->rb));
@@ -97,13 +111,6 @@
     rubberband_process(p->rb, (const float* const*)&(p->in->data), p->hopsize, p->eof);
     available = rubberband_available(p->rb);
   }
-#endif
-
-  return p;
-
-beach:
-  del_aubio_timestretch(p);
-  return NULL;
 }
 
 void
@@ -183,8 +190,8 @@
   return 12. * LOG(p->pitchscale) / LOG(2.0);
 }
 
-void
-aubio_timestretch_do (aubio_timestretch_t * p, fvec_t * out, uint_t * read)
+sint_t
+aubio_timestretch_fetch(aubio_timestretch_t *p)
 {
   uint_t source_read = p->hopsize;
   // read more samples from source until we have enough available or eof is reached
@@ -197,6 +204,13 @@
     rubberband_process(p->rb, (const float* const*)&(p->in->data), source_read, p->eof);
     available = rubberband_available(p->rb);
   }
+  return source_read;
+}
+
+void
+aubio_timestretch_do (aubio_timestretch_t * p, fvec_t * out, uint_t * read)
+{
+  int available = aubio_timestretch_fetch(p);
   // now retrieve the samples and write them into out->data
   if (available >= (int)p->hopsize) {
     rubberband_retrieve(p->rb, (float* const*)&(out->data), p->hopsize);