From 6bba139da789a532b9712f199dd84e6f3a70aafd Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 4 Oct 2018 18:35:14 +0200 Subject: [PATCH] src/notes/notes.h: add get/set for release drop level (closes: #203) --- src/notes/notes.c | 26 +++++++++++++++++++++----- src/notes/notes.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/notes/notes.c b/src/notes/notes.c index f4750902..cc450e84 100644 --- a/src/notes/notes.c +++ b/src/notes/notes.c @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Paul Brossier + Copyright (C) 2014-2018 Paul Brossier 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 @@ struct _aubio_notes_t { 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_t * new_aubio_notes (const char_t * method, 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 @@ smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o) 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 @@ void aubio_notes_do (aubio_notes_t *o, const fvec_t * input, fvec_t * notes) 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"); diff --git a/src/notes/notes.h b/src/notes/notes.h index bf0df85b..f256be31 100644 --- a/src/notes/notes.h +++ b/src/notes/notes.h @@ -106,6 +106,36 @@ smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o); */ 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 -- 2.11.0