From ce6186a3ee2a610ab4f35d6b3fece9cd551ae035 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 7 Dec 2013 20:14:09 -0500 Subject: [PATCH] examples/aubio{trac,onset}.c: add silence option --- examples/aubionotes.c | 2 +- examples/aubioonset.c | 11 ++++++++--- examples/aubioquiet.c | 2 +- examples/aubiotrack.c | 17 ++++++++++------- examples/parse_args.h | 4 ++-- examples/utils.c | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/examples/aubionotes.c b/examples/aubionotes.c index dc57ce8e..fd8278e0 100644 --- a/examples/aubionotes.c +++ b/examples/aubionotes.c @@ -57,7 +57,7 @@ process_block(fvec_t *ibuf, fvec_t *obuf) { } /* 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.) { diff --git a/examples/aubioonset.c b/examples/aubioonset.c index d8c7987e..09ce0e4b 100644 --- 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 @@ process_block(fvec_t *ibuf, fvec_t *obuf) { 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 @@ int main(int argc, char **argv) { 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); diff --git a/examples/aubioquiet.c b/examples/aubioquiet.c index e1fbbfa3..ba0d71d9 100644 --- a/examples/aubioquiet.c +++ b/examples/aubioquiet.c @@ -25,7 +25,7 @@ sint_t wassilence = 1, issilence; 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; diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index 48d4cdc7..83bd214d 100644 --- 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_block(fvec_t * ibuf, fvec_t *obuf) { } 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); } diff --git a/examples/parse_args.h b/examples/parse_args.h index 1ab652eb..1f227992 100644 --- a/examples/parse_args.h +++ b/examples/parse_args.h @@ -37,7 +37,7 @@ extern smpl_t pitch_tolerance; // 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 @@ parse_args (int argc, char **argv) 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; diff --git a/examples/utils.c b/examples/utils.c index 09875315..2c4c90e2 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -50,7 +50,7 @@ smpl_t pitch_tolerance = 0.0; // will be set if != 0. // tempo stuff char_t * tempo_method = "default"; // more general stuff -smpl_t silence = -90.; +smpl_t silence_threshold = -90.; uint_t mix_input = 0; // -- 2.11.0