shithub: aubio

Download patch

ref: 6bba139da789a532b9712f199dd84e6f3a70aafd
parent: f761f06484e549e42eb3fe34f0d836e40efa73bb
author: Paul Brossier <piem@piem.org>
date: Thu Oct 4 14:35:14 EDT 2018

src/notes/notes.h: add get/set for release drop level (closes: #203)

--- a/src/notes/notes.c
+++ b/src/notes/notes.c
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2014 Paul Brossier <piem@aubio.org>
+  Copyright (C) 2014-2018 Paul Brossier <piem@aubio.org>
 
   This file is part of aubio.
 
@@ -25,7 +25,7 @@
 #include "notes/notes.h"
 
 #define AUBIO_DEFAULT_NOTES_SILENCE -70.
-#define AUBIO_DEFAULT_NOTES_LEVEL_DROP 10.
+#define AUBIO_DEFAULT_NOTES_RELEASE_DROP 10.
 // increase to 10. for .1  cent precision
 //      or to 100. for .01 cent precision
 #define AUBIO_DEFAULT_CENT_PRECISION 1.
@@ -59,7 +59,7 @@
   uint_t isready;
 
   smpl_t last_onset_level;
-  smpl_t level_delta_db;
+  smpl_t release_drop_level;
 };
 
 aubio_notes_t * new_aubio_notes (const char_t * method,
@@ -106,7 +106,7 @@
   aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS);
 
   o->last_onset_level = AUBIO_DEFAULT_NOTES_SILENCE;
-  o->level_delta_db = AUBIO_DEFAULT_NOTES_LEVEL_DROP;
+  o->release_drop_level = AUBIO_DEFAULT_NOTES_RELEASE_DROP;
 
   return o;
 
@@ -147,6 +147,22 @@
   return aubio_onset_get_minioi_ms(o->onset);
 }
 
+uint_t aubio_notes_set_release_drop(aubio_notes_t *o, smpl_t release_drop_level)
+{
+  uint_t err = AUBIO_OK;
+  if (release_drop_level < 0.) {
+    err = AUBIO_FAIL;
+  } else {
+    o->release_drop_level = release_drop_level;
+  }
+  return err;
+}
+
+smpl_t aubio_notes_get_release_drop(const aubio_notes_t *o)
+{
+  return o->release_drop_level;
+}
+
 /** append new note candidate to the note_buffer and return filtered value. we
  * need to copy the input array as fvec_median destroy its input data.*/
 static void
@@ -210,7 +226,7 @@
       o->last_onset_level = curlevel;
     }
   } else {
-    if (curlevel < o->last_onset_level - o->level_delta_db)
+    if (curlevel < o->last_onset_level - o->release_drop_level)
     {
       // send note off
       //AUBIO_WRN("notes: sending note-off, release detected\n");
--- a/src/notes/notes.h
+++ b/src/notes/notes.h
@@ -106,6 +106,36 @@
 */
 uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms);
 
+/** get notes object release drop level, in dB
+
+  \param o notes detection object as returned by new_aubio_notes()
+
+  \return current release drop level, in dB
+
+ */
+smpl_t aubio_notes_get_release_drop (const aubio_notes_t *o);
+
+/** set note release drop level, in dB
+
+  This function sets the release_drop_level parameter, in dB. When a new note
+  is found, the current level in dB is measured. If the measured level drops
+  under that initial level - release_drop_level, then a note-off will be
+  emitted.
+
+  Defaults to `10`, in dB.
+
+  \note This parameter was added in version `0.4.8`. Results obtained with
+  earlier versions can be reproduced by setting this value to `100`, so that
+  note-off will not be played until the next note.
+
+  \param o notes detection object as returned by new_aubio_notes()
+  \param release_drop new release drop level, in dB
+
+  \return 0 on success, non-zero otherwise
+
+*/
+uint_t aubio_notes_set_release_drop (aubio_notes_t *o, smpl_t release_drop);
+
 #ifdef __cplusplus
 }
 #endif