#include "onset/onset.h"
#include "notes/notes.h"
+#define AUBIO_DEFAULT_NOTES_SILENCE -70.
+// increase to 10. for .1 cent precision
+// or to 100. for .01 cent precision
+#define AUBIO_DEFAULT_CENT_PRECISION 1.
+#define AUBIO_DEFAULT_NOTES_MINIOI_MS 30.
+
struct _aubio_notes_t {
uint_t onset_buf_size;
uint_t isready;
};
-aubio_notes_t * new_aubio_notes (const char_t * notes_method,
+aubio_notes_t * new_aubio_notes (const char_t * method,
uint_t buf_size, uint_t hop_size, uint_t samplerate) {
aubio_notes_t *o = AUBIO_NEW(aubio_notes_t);
o->pitch = new_aubio_pitch (pitch_method, o->pitch_buf_size, o->hop_size, o->samplerate);
if (o->pitch_tolerance != 0.) aubio_pitch_set_tolerance (o->pitch, o->pitch_tolerance);
+ aubio_pitch_set_unit (o->pitch, "midi");
o->pitch_output = new_fvec (1);
- if (strcmp(notes_method, "default") != 0) {
- AUBIO_ERR("unknown notes detection method %s, using default.\n",
- notes_method);
+ if (strcmp(method, "default") != 0) {
+ AUBIO_ERR("notes: unknown notes detection method \"%s\"\n", method);
goto fail;
}
o->note_buffer = new_fvec(o->median);
o->curnote = -1.;
o->newnote = 0.;
- o->silence_threshold = -90.;
+ aubio_notes_set_silence(o, AUBIO_DEFAULT_NOTES_SILENCE);
+ aubio_notes_set_minioi_ms (o, AUBIO_DEFAULT_NOTES_MINIOI_MS);
return o;
return NULL;
}
+uint_t aubio_notes_set_silence(aubio_notes_t *o, smpl_t silence)
+{
+ uint_t err = AUBIO_OK;
+ if (aubio_pitch_set_silence(o->pitch, silence) != AUBIO_OK) {
+ err = AUBIO_FAIL;
+ }
+ if (aubio_onset_set_silence(o->onset, silence) != AUBIO_OK) {
+ err = AUBIO_FAIL;
+ }
+ o->silence_threshold = silence;
+ return err;
+}
+
+smpl_t aubio_notes_get_silence(const aubio_notes_t *o)
+{
+ return aubio_pitch_get_silence(o->pitch);
+}
+
+uint_t aubio_notes_set_minioi_ms (aubio_notes_t *o, smpl_t minioi_ms)
+{
+ uint_t err = AUBIO_OK;
+ if (!o->onset || (aubio_onset_set_minioi_ms(o->onset, minioi_ms) != 0)) {
+ err = AUBIO_FAIL;
+ }
+ return err;
+}
+
+smpl_t aubio_notes_get_minioi_ms(const aubio_notes_t *o)
+{
+ return aubio_onset_get_minioi_ms(o->onset);
+}
+
/** 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
for (i = 0; i < note_buffer->length - 1; i++) {
note_buffer->data[i] = note_buffer->data[i + 1];
}
- note_buffer->data[note_buffer->length - 1] = curnote;
+ //note_buffer->data[note_buffer->length - 1] = ROUND(10.*curnote)/10.;
+ note_buffer->data[note_buffer->length - 1] = ROUND(AUBIO_DEFAULT_CENT_PRECISION*curnote);
return;
}
-static uint_t
+static smpl_t
aubio_notes_get_latest_note (aubio_notes_t *o)
{
- uint_t i;
- for (i = 0; i < o->note_buffer->length; i++) {
- o->note_buffer2->data[i] = o->note_buffer->data[i];
- }
- return fvec_median (o->note_buffer2);
+ fvec_copy(o->note_buffer, o->note_buffer2);
+ return fvec_median (o->note_buffer2) / AUBIO_DEFAULT_CENT_PRECISION;
}
/* kill old note */
//send_noteon(curnote,0);
notes->data[2] = o->curnote;
- notes->data[3] = 0;
o->newnote = aubio_notes_get_latest_note(o);
o->curnote = o->newnote;
/* get and send new one */