shithub: aubio

Download patch

ref: 7f6f8800d1b869d5b4ea5bb3a5cc3c79b9733cb5
parent: 68586d46c605442daae7e05ffc0d59b3b6ef6b51
parent: 80d00833d879fc4688b7ef71eb3ac0d0dd3e0115
author: Paul Brossier <piem@piem.org>
date: Wed Sep 28 11:23:01 EDT 2016

Merge branch 'master' into pitchshift

--- a/src/io/sink_wavwrite.c
+++ b/src/io/sink_wavwrite.c
@@ -68,8 +68,12 @@
   unsigned short *scratch_data;
 };
 
-unsigned char *write_little_endian (unsigned int s, unsigned char *str, unsigned int length);
-unsigned char *write_little_endian (unsigned int s, unsigned char *str, unsigned int length) {
+static unsigned char *write_little_endian (unsigned int s, unsigned char *str,
+    unsigned int length);
+
+static unsigned char *write_little_endian (unsigned int s, unsigned char *str,
+    unsigned int length)
+{
   uint_t i;
   for (i = 0; i < length; i++) {
     str[i] = s >> (i * 8);
--- a/src/io/source_wavread.c
+++ b/src/io/source_wavread.c
@@ -60,8 +60,12 @@
   fmat_t *output;
 };
 
-unsigned int read_little_endian (unsigned char *buf, unsigned int length);
-unsigned int read_little_endian (unsigned char *buf, unsigned int length) {
+static unsigned int read_little_endian (unsigned char *buf,
+    unsigned int length);
+
+static unsigned int read_little_endian (unsigned char *buf,
+    unsigned int length)
+{
   uint_t i, ret = 0;
   for (i = 0; i < length; i++) {
     ret += buf[i] << (i * 8);
--- a/src/onset/onset.c
+++ b/src/onset/onset.c
@@ -190,7 +190,7 @@
     AUBIO_ERR("onset: got buffer_size %d, but can not be < 2\n", buf_size);
     goto beach;
   } else if (buf_size < hop_size) {
-    AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", buf_size, hop_size);
+    AUBIO_ERR("onset: hop size (%d) is larger than win size (%d)\n", hop_size, buf_size);
     goto beach;
   } else if ((sint_t)samplerate < 1) {
     AUBIO_ERR("onset: samplerate (%d) can not be < 1\n", samplerate);
@@ -205,6 +205,7 @@
   o->pv = new_aubio_pvoc(buf_size, o->hop_size);
   o->pp = new_aubio_peakpicker();
   o->od = new_aubio_specdesc(onset_mode,buf_size);
+  if (o->od == NULL) goto beach_specdesc;
   o->fftgrain = new_cvec(buf_size);
   o->desc = new_fvec(1);
 
@@ -219,6 +220,9 @@
   o->total_frames = 0;
   return o;
 
+beach_specdesc:
+  del_aubio_peakpicker(o->pp);
+  del_aubio_pvoc(o->pv);
 beach:
   AUBIO_FREE(o);
   return NULL;
--- a/src/pitch/pitch.c
+++ b/src/pitch/pitch.c
@@ -96,10 +96,10 @@
 static void aubio_pitch_do_yinfft (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
 static void aubio_pitch_do_specacf (aubio_pitch_t * p, const fvec_t * ibuf, fvec_t * obuf);
 
-/* conversion functions for frequency conversions */
-smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize);
-smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);
-smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);
+/* internal functions for frequency conversion */
+static smpl_t freqconvbin (smpl_t f, uint_t samplerate, uint_t bufsize);
+static smpl_t freqconvmidi (smpl_t f, uint_t samplerate, uint_t bufsize);
+static smpl_t freqconvpass (smpl_t f, uint_t samplerate, uint_t bufsize);
 
 /* adapter to stack ibuf new samples at the end of buf, and trim `buf` to `bufsize` */
 void aubio_pitch_slideblock (aubio_pitch_t * p, const fvec_t * ibuf);
@@ -126,9 +126,8 @@
   else if (strcmp (pitch_mode, "default") == 0)
     pitch_type = aubio_pitcht_default;
   else {
-    AUBIO_ERR ("unknown pitch detection method %s, using default.\n",
-        pitch_mode);
-    pitch_type = aubio_pitcht_default;
+    AUBIO_ERR ("pitch: unknown pitch detection method ‘%s’\n", pitch_mode);
+    goto beach;
   }
 
   // check parameters are valid
@@ -283,7 +282,8 @@
   else if (strcmp (pitch_unit, "default") == 0)
     pitch_mode = aubio_pitchm_default;
   else {
-    AUBIO_ERR ("unknown pitch detection unit %s, using default\n", pitch_unit);
+    AUBIO_WRN("pitch: unknown pitch detection unit ‘%s’, using default\n",
+        pitch_unit);
     pitch_mode = aubio_pitchm_default;
     err = AUBIO_FAIL;
   }
@@ -324,6 +324,23 @@
   return AUBIO_OK;
 }
 
+smpl_t
+aubio_pitch_get_tolerance (aubio_pitch_t * p)
+{
+  smpl_t tolerance = 1.;
+  switch (p->type) {
+    case aubio_pitcht_yin:
+      tolerance = aubio_pitchyin_get_tolerance (p->p_object);
+      break;
+    case aubio_pitcht_yinfft:
+      tolerance = aubio_pitchyinfft_get_tolerance (p->p_object);
+      break;
+    default:
+      break;
+  }
+  return tolerance;
+}
+
 uint_t
 aubio_pitch_set_silence (aubio_pitch_t * p, smpl_t silence)
 {
@@ -331,7 +348,7 @@
     p->silence = silence;
     return AUBIO_OK;
   } else {
-    AUBIO_ERR("pitch: could not set silence to %.2f", silence);
+    AUBIO_WRN("pitch: could not set silence to %.2f\n", silence);
     return AUBIO_FAIL;
   }
 }
--- a/src/pitch/pitch.h
+++ b/src/pitch/pitch.h
@@ -117,6 +117,14 @@
 */
 uint_t aubio_pitch_set_tolerance (aubio_pitch_t * o, smpl_t tol);
 
+/** get yin or yinfft tolerance threshold
+
+  \param o pitch detection object as returned by new_aubio_pitch()
+  \return tolerance (default is 0.15 for yin and 0.85 for yinfft)
+
+*/
+smpl_t aubio_pitch_get_tolerance (aubio_pitch_t * o);
+
 /** deletion of the pitch detection object
 
   \param o pitch detection object as returned by new_aubio_pitch()
--