shithub: aubio

Download patch

ref: 86053617e29e886672287d728d982a1778f073e5
parent: 34e505f2faab363748a243919d4de0f09434efaf
parent: 95748a62ec9ac31b5b05607402f8bc10be87e012
author: Paul Brossier <piem@piem.org>
date: Mon Nov 2 18:16:24 EST 2015

Merge branch 'develop' into awhitening

--- a/src/io/sink_apple_audio.c
+++ b/src/io/sink_apple_audio.c
@@ -36,7 +36,7 @@
 
 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int segmentSize);
 extern void freeAudioBufferList(AudioBufferList *bufferList);
-extern CFURLRef getURLFromPath(const char * path);
+extern CFURLRef createURLFromPath(const char * path);
 char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
 
 uint_t aubio_sink_apple_audio_open(aubio_sink_apple_audio_t *s);
@@ -137,11 +137,12 @@
   clientFormat.mReserved         = 0;
 
   AudioFileTypeID fileType = kAudioFileWAVEType;
-  CFURLRef fileURL = getURLFromPath(s->path);
+  CFURLRef fileURL = createURLFromPath(s->path);
   bool overwrite = true;
   OSStatus err = noErr;
   err = ExtAudioFileCreateWithURL(fileURL, fileType, &clientFormat, NULL,
      overwrite ? kAudioFileFlags_EraseFile : 0, &s->audioFile);
+  CFRelease(fileURL);
   if (err) {
     char_t errorstr[20];
     AUBIO_ERR("sink_apple_audio: error when trying to create %s with "
--- a/src/io/source_apple_audio.c
+++ b/src/io/source_apple_audio.c
@@ -51,7 +51,7 @@
 
 extern int createAubioBufferList(AudioBufferList *bufferList, int channels, int max_source_samples);
 extern void freeAudioBufferList(AudioBufferList *bufferList);
-extern CFURLRef getURLFromPath(const char * path);
+extern CFURLRef createURLFromPath(const char * path);
 char_t *getPrintableOSStatusError(char_t *str, OSStatus error);
 
 uint_t aubio_source_apple_audio_open (aubio_source_apple_audio_t *s, char_t * path);
@@ -98,8 +98,9 @@
   s->path = path;
 
   // open the resource url
-  CFURLRef fileURL = getURLFromPath(path);
+  CFURLRef fileURL = createURLFromPath(path);
   err = ExtAudioFileOpenURL(fileURL, &s->audioFile);
+  CFRelease(fileURL);
   if (err == -43) {
     AUBIO_ERR("source_apple_audio: Failed opening %s, "
         "file not found, or no read access\n", s->path);
--- a/src/io/utils_apple_audio.c
+++ b/src/io/utils_apple_audio.c
@@ -33,12 +33,14 @@
   bufferList = NULL;
 }
 
-CFURLRef getURLFromPath(const char * path) {
+CFURLRef createURLFromPath(const char * path) {
   CFStringRef cfTotalPath = CFStringCreateWithCString (kCFAllocatorDefault,
       path, kCFStringEncodingUTF8);
 
-  return CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
+  CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfTotalPath,
       kCFURLPOSIXPathStyle, false);
+  CFRelease(cfTotalPath);
+  return url;
 }
 
 char_t *getPrintableOSStatusError(char_t *str, OSStatus error)
--- a/src/pitch/pitchmcomb.c
+++ b/src/pitch/pitchmcomb.c
@@ -335,8 +335,7 @@
   uint_t cur = 0;
   uint_t run = 0;
   for (cur = 0; cur < nbins; cur++) {
-    run = cur + 1;
-    for (run = cur; run < nbins; run++) {
+    for (run = cur + 1; run < nbins; run++) {
       if (candidates[run]->ene > candidates[cur]->ene)
         CAND_SWAP (candidates[run], candidates[cur]);
     }
@@ -351,8 +350,7 @@
   uint_t cur = 0;
   uint_t run = 0;
   for (cur = 0; cur < nbins; cur++) {
-    run = cur + 1;
-    for (run = cur; run < nbins; run++) {
+    for (run = cur + 1; run < nbins; run++) {
       if (candidates[run]->ebin < candidates[cur]->ebin)
         CAND_SWAP (candidates[run], candidates[cur]);
     }
--- a/src/tempo/beattracking.c
+++ b/src/tempo/beattracking.c
@@ -409,10 +409,22 @@
 }
 
 smpl_t
+aubio_beattracking_get_period (aubio_beattracking_t * bt)
+{
+  return bt->hop_size * bt->bp;
+}
+
+smpl_t
+aubio_beattracking_get_period_s (aubio_beattracking_t * bt)
+{
+  return aubio_beattracking_get_period(bt) / (smpl_t) bt->samplerate;
+}
+
+smpl_t
 aubio_beattracking_get_bpm (aubio_beattracking_t * bt)
 {
   if (bt->bp != 0) {
-    return 60. * bt->samplerate/ bt->bp / bt->hop_size;
+    return 60. / aubio_beattracking_get_period_s(bt);
   } else {
     return 0.;
   }
--- a/src/tempo/beattracking.h
+++ b/src/tempo/beattracking.h
@@ -67,6 +67,26 @@
 void aubio_beattracking_do (aubio_beattracking_t * bt, fvec_t * dfframes,
     fvec_t * out);
 
+/** get current beat period in samples
+
+  \param bt beat tracking object
+
+  Returns the currently observed period, in samples, or 0 if no consistent
+  value is found.
+
+*/
+smpl_t aubio_beattracking_get_period (aubio_beattracking_t * bt);
+
+/** get current beat period in seconds
+
+  \param bt beat tracking object
+
+  Returns the currently observed period, in seconds, or 0 if no consistent
+  value is found.
+
+*/
+smpl_t aubio_beattracking_get_period_s (aubio_beattracking_t * bt);
+
 /** get current tempo in bpm
 
   \param bt beat tracking object
--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -64,12 +64,14 @@
   smpl_t threshold;              /** peak picking threshold */
   sint_t blockpos;               /** current position in dfframe */
   uint_t winlen;                 /** dfframe bufsize */
-  uint_t step;                   /** dfframe hopsize */ 
-  uint_t samplerate;             /** sampling rate of the signal */ 
+  uint_t step;                   /** dfframe hopsize */
+  uint_t samplerate;             /** sampling rate of the signal */
   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 */
+  uint_t last_tatum;             /** time of latest detected tatum, in samples */
+  uint_t tatum_signature;        /** number of tatum between each beats */
 };
 
 /* execute tempo detection function on iput buffer */
@@ -90,9 +92,9 @@
     /* check dfframe */
     aubio_beattracking_do(o->bt,o->dfframe,o->out);
     /* rotate dfframe */
-    for (i = 0 ; i < winlen - step; i++ ) 
+    for (i = 0 ; i < winlen - step; i++ )
       o->dfframe->data[i] = o->dfframe->data[i+step];
-    for (i = winlen - step ; i < winlen; i++ ) 
+    for (i = winlen - step ; i < winlen; i++ )
       o->dfframe->data[i] = 0.;
     o->blockpos = -1;
   }
@@ -103,7 +105,7 @@
   o->dfframe->data[winlen - step + o->blockpos] = thresholded->data[0];
   /* end of second level loop */
   tempo->data[0] = 0; /* reset tactus */
-  i=0;
+  //i=0;
   for (i = 1; i < o->out->data[0]; i++ ) {
     /* if current frame is a predicted tactus */
     if (o->blockpos == FLOOR(o->out->data[i])) {
@@ -113,6 +115,7 @@
         tempo->data[0] = 0; // unset beat if silent
       }
       o->last_beat = o->total_frames + (uint_t)ROUND(tempo->data[0] * o->hop_size);
+      o->last_tatum = o->last_beat;
     }
   }
   o->total_frames += o->hop_size;
@@ -214,6 +217,8 @@
     o2 = new_aubio_specdesc(type_onset2,buffer_size);
     onset2 = new_fvec(1);
   }*/
+  o->last_tatum = 0;
+  o->tatum_signature = 4;
   return o;
 
 beach:
@@ -225,8 +230,51 @@
   return aubio_beattracking_get_bpm(o->bt);
 }
 
+smpl_t aubio_tempo_get_period (aubio_tempo_t *o)
+{
+  return aubio_beattracking_get_period (o->bt);
+}
+
+smpl_t aubio_tempo_get_period_s (aubio_tempo_t *o)
+{
+  return aubio_beattracking_get_period_s (o->bt);
+}
+
 smpl_t aubio_tempo_get_confidence(aubio_tempo_t *o) {
   return aubio_beattracking_get_confidence(o->bt);
+}
+
+uint_t aubio_tempo_was_tatum (aubio_tempo_t *o)
+{
+  uint_t last_tatum_distance = o->total_frames - o->last_tatum;
+  smpl_t beat_period = aubio_tempo_get_period(o);
+  smpl_t tatum_period = beat_period / o->tatum_signature;
+  if (last_tatum_distance < o->hop_size) {
+    o->last_tatum = o->last_beat;
+    return 2;
+  }
+  else if (last_tatum_distance > tatum_period) {
+    if ( last_tatum_distance + o->hop_size > beat_period ) {
+      // next beat is too close, pass
+      return 0;
+    }
+    o->last_tatum = o->total_frames;
+    return 1;
+  }
+  return 0;
+}
+
+smpl_t aubio_tempo_get_last_tatum (aubio_tempo_t *o) {
+  return (smpl_t)o->last_tatum - o->delay;
+}
+
+uint_t aubio_tempo_set_tatum_signature (aubio_tempo_t *o, uint_t signature) {
+  if (signature < 1 || signature > 64) {
+    return AUBIO_FAIL;
+  } else {
+    o->tatum_signature = signature;
+    return AUBIO_OK;
+  }
 }
 
 void del_aubio_tempo (aubio_tempo_t *o)
--- a/src/tempo/tempo.h
+++ b/src/tempo/tempo.h
@@ -121,6 +121,26 @@
 */
 smpl_t aubio_tempo_get_threshold(aubio_tempo_t * o);
 
+/** get current beat period in samples
+
+  \param bt beat tracking object
+
+  Returns the currently observed period, in samples, or 0 if no consistent
+  value is found.
+
+*/
+smpl_t aubio_tempo_get_period (aubio_tempo_t * bt);
+
+/** get current beat period in seconds
+
+  \param bt beat tracking object
+
+  Returns the currently observed period, in seconds, or 0 if no consistent
+  value is found.
+
+*/
+smpl_t aubio_tempo_get_period_s (aubio_tempo_t * bt);
+
 /** get current tempo
 
   \param o beat tracking object
@@ -139,6 +159,30 @@
 
 */
 smpl_t aubio_tempo_get_confidence(aubio_tempo_t * o);
+
+/* set number of tatum per beat
+
+   \param o beat tracking object
+   \param signature number of tatum per beat (between 1 and 64)
+
+*/
+uint_t aubio_tempo_set_tatum_signature(aubio_tempo_t *o, uint_t signature);
+
+/* check whether a tatum was detected in the current frame
+
+   \param o beat tracking object
+
+   \return 2 if a beat was detected, 1 if a tatum was detected, 0 otherwise
+
+*/
+uint_t aubio_tempo_was_tatum(aubio_tempo_t *o);
+
+/* get position of last_tatum, in samples
+
+   \param o beat tracking object
+
+*/
+smpl_t aubio_tempo_get_last_tatum(aubio_tempo_t *o);
 
 /** delete tempo detection object
 
--