[tests] add run_on_default_source_and_sink helper
[aubio.git] / examples / aubionotes.c
index 7541098..339fdaf 100644 (file)
@@ -21,6 +21,8 @@
 #include "utils.h"
 #define PROG_HAS_PITCH 1
 #define PROG_HAS_ONSET 1
+#define PROG_HAS_NOTES 1
+#define PROG_HAS_SILENCE 1
 #define PROG_HAS_JACK 1
 // TODO add PROG_HAS_OUTPUT
 #include "parse_args.h"
@@ -33,12 +35,12 @@ void process_block (fvec_t *ibuf, fvec_t *obuf)
   aubio_notes_do (notes, ibuf, obuf);
   // did we get a note off?
   if (obuf->data[2] != 0) {
-    lastmidi = aubio_freqtomidi (obuf->data[2]) + .5;
+    lastmidi = obuf->data[2];
     send_noteon(lastmidi, 0);
   }
   // did we get a note on?
   if (obuf->data[0] != 0) {
-    lastmidi = aubio_freqtomidi (obuf->data[0]) + .5;
+    lastmidi = obuf->data[0];
     send_noteon(lastmidi, obuf->data[1]);
   }
 }
@@ -49,6 +51,8 @@ void process_print (void)
 }
 
 int main(int argc, char **argv) {
+  int ret = 0;
+
   examples_common_init(argc,argv);
 
   verbmsg ("using source: %s at %dHz\n", source_uri, samplerate);
@@ -64,15 +68,38 @@ int main(int argc, char **argv) {
   verbmsg ("tolerance: %f\n", pitch_tolerance);
 
   notes = new_aubio_notes ("default", buffer_size, hop_size, samplerate);
+  if (notes == NULL) { ret = 1; goto beach; }
+
+  if (onset_minioi != 0.) {
+    aubio_notes_set_minioi_ms(notes, onset_minioi);
+  }
+  if (onset_threshold != 0.) {
+    errmsg ("warning: onset threshold not supported yet\n");
+    //aubio_onset_set_threshold(aubio_notes_get_aubio_onset(o), onset_threshold);
+  }
+  if (silence_threshold != -90.) {
+    if (aubio_notes_set_silence (notes, silence_threshold) != 0) {
+      errmsg ("failed setting notes silence threshold to %.2f\n",
+          silence_threshold);
+    }
+  }
+  if (release_drop != 10.) {
+    if (aubio_notes_set_release_drop (notes, release_drop) != 0) {
+      errmsg ("failed setting notes release drop to %.2f\n",
+          release_drop);
+    }
+  }
 
   examples_common_process((aubio_process_func_t)process_block, process_print);
 
-  // send a last note off
-  send_noteon (lastmidi, 0);
+  // send a last note off if required
+  if (lastmidi) {
+    send_noteon (lastmidi, 0);
+  }
 
   del_aubio_notes (notes);
 
+beach:
   examples_common_del();
-  return 0;
+  return ret;
 }
-