shithub: aubio

Download patch

ref: ce6186a3ee2a610ab4f35d6b3fece9cd551ae035
parent: fe6a393ab0c45b93eae8a463948807af798791e6
author: Paul Brossier <piem@piem.org>
date: Sat Dec 7 15:14:09 EST 2013

examples/aubio{trac,onset}.c: add silence option

--- a/examples/aubionotes.c
+++ b/examples/aubionotes.c
@@ -57,7 +57,7 @@
   }
 
   /* curlevel is negatif or 1 if silence */
-  smpl_t curlevel = aubio_level_detection(ibuf, silence);
+  smpl_t curlevel = aubio_level_detection(ibuf, silence_threshold);
   if (fvec_read_sample(onset, 0)) {
     /* test for silence */
     if (curlevel == 1.) {
--- a/examples/aubioonset.c
+++ b/examples/aubioonset.c
@@ -27,12 +27,17 @@
 aubio_onset_t *o;
 aubio_wavetable_t *wavetable;
 fvec_t *onset;
+smpl_t is_onset;
+uint_t is_silence = 0.;
 
 void
 process_block(fvec_t *ibuf, fvec_t *obuf) {
   fvec_zeros(obuf);
   aubio_onset_do (o, ibuf, onset);
-  if ( fvec_read_sample(onset, 0) ) {
+  if (silence_threshold != -90.)
+    is_silence = aubio_silence_detection(ibuf, silence_threshold);
+  is_onset = fvec_read_sample(onset, 0);
+  if ( is_onset && !is_silence ) {
     aubio_wavetable_play ( wavetable );
   } else {
     aubio_wavetable_stop ( wavetable );
@@ -46,8 +51,7 @@
 void
 process_print (void)
 {
-  smpl_t onset_found = fvec_read_sample (onset, 0);
-  if (onset_found) {
+  if ( is_onset && !is_silence ) {
     outmsg ("%f\n", aubio_onset_get_last_s (o) );
   }
 }
@@ -59,6 +63,7 @@
   verbmsg ("onset method: %s, ", onset_method);
   verbmsg ("buffer_size: %d, ", buffer_size);
   verbmsg ("hop_size: %d, ", hop_size);
+  verbmsg ("threshold: %f, ", silence_threshold);
   verbmsg ("threshold: %f\n", onset_threshold);
 
   o = new_aubio_onset (onset_method, buffer_size, hop_size, samplerate);
--- a/examples/aubioquiet.c
+++ b/examples/aubioquiet.c
@@ -25,7 +25,7 @@
 
 void process_block(fvec_t * ibuf, fvec_t * obuf) {
   fvec_zeros (obuf);
-  if (aubio_silence_detection(ibuf, silence)==1) {
+  if (aubio_silence_detection(ibuf, silence_threshold)==1) {
     if (wassilence==1) issilence = 1;
     else issilence = 2;
     wassilence=1;
--- a/examples/aubiotrack.c
+++ b/examples/aubiotrack.c
@@ -27,15 +27,18 @@
 aubio_tempo_t * tempo;
 aubio_wavetable_t *wavetable;
 fvec_t * tempo_out;
-smpl_t istactus = 0;
-smpl_t isonset = 0;
+smpl_t is_beat = 0;
+smpl_t is_onset = 0;
+uint_t is_silence = 0.;
 
 void process_block(fvec_t * ibuf, fvec_t *obuf) {
   aubio_tempo_do (tempo, ibuf, tempo_out);
-  istactus = fvec_read_sample (tempo_out, 0);
-  isonset = fvec_read_sample (tempo_out, 1);
+  is_beat = fvec_read_sample (tempo_out, 0);
+  is_onset = fvec_read_sample (tempo_out, 1);
+  if (silence_threshold != -90.)
+    is_silence = aubio_silence_detection(ibuf, silence_threshold);
   fvec_zeros (obuf);
-  if (istactus > 0.) {
+  if ( is_beat && !is_silence ) {
     aubio_wavetable_play ( wavetable );
   } else {
     aubio_wavetable_stop ( wavetable );
@@ -47,10 +50,10 @@
 }
 
 void process_print (void) {
-  if (istactus) {
+  if ( is_beat && !is_silence ) {
     outmsg("%f\n", aubio_tempo_get_last_s(tempo) );
   }
-  //if (isonset && verbose)
+  //if ( is_onset )
   //  outmsg(" \t \t%f\n",(blocks)*hop_size/(float)samplerate);
 }
 
--- a/examples/parse_args.h
+++ b/examples/parse_args.h
@@ -37,7 +37,7 @@
 // tempo stuff
 extern char_t * tempo_method;
 // more general stuff
-extern smpl_t silence;
+extern smpl_t silence_threshold;
 extern uint_t mix_input;
 
 typedef int (*aubio_process_func_t)(fvec_t * input, fvec_t * output);
@@ -183,7 +183,7 @@
         pitch_tolerance = (smpl_t) atof (optarg);
         break;
       case 's':                /* silence threshold */
-        silence = (smpl_t) atof (optarg);
+        silence_threshold = (smpl_t) atof (optarg);
         break;
       case 'm':                /* mix_input flag */
         mix_input = 1;
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -50,7 +50,7 @@
 // tempo stuff
 char_t * tempo_method = "default";
 // more general stuff
-smpl_t silence = -90.;
+smpl_t silence_threshold = -90.;
 uint_t mix_input = 0;
 
 //