From 340cb937f86df50f6630f90ecc9d0c252007fbb8 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Wed, 12 Aug 2015 16:15:39 +0200 Subject: [PATCH] examples/: add time format option --- examples/aubiomfcc.c | 8 +++++--- examples/aubioonset.c | 8 +++++++- examples/aubiopitch.c | 4 ++-- examples/aubioquiet.c | 12 ++++++++---- examples/aubiotrack.c | 3 ++- examples/parse_args.h | 9 +++++++++ examples/utils.c | 19 +++++++++++++++++-- examples/utils.h | 2 ++ 8 files changed, 52 insertions(+), 13 deletions(-) diff --git a/examples/aubiomfcc.c b/examples/aubiomfcc.c index 29093fba..d8bb9102 100644 --- a/examples/aubiomfcc.c +++ b/examples/aubiomfcc.c @@ -40,9 +40,11 @@ void process_block (fvec_t *ibuf, fvec_t *obuf) void process_print (void) { - /* output times in seconds and extracted mfccs */ - outmsg("%f\t",blocks*hop_size/(float)samplerate); - fvec_print(mfcc_out); + /* output times in selected format */ + print_time (blocks * hop_size); + outmsg ("\t"); + /* output extracted mfcc */ + fvec_print (mfcc_out); } int main(int argc, char **argv) { diff --git a/examples/aubioonset.c b/examples/aubioonset.c index 52d18b18..458f1ad2 100644 --- a/examples/aubioonset.c +++ b/examples/aubioonset.c @@ -49,7 +49,13 @@ void process_block(fvec_t *ibuf, fvec_t *obuf) void process_print (void) { if ( is_onset ) { - outmsg ("%f\n", aubio_onset_get_last_s (o) ); + if (strcmp (time_format, "samples") == 0) { + outmsg ("%d\n", aubio_onset_get_last (o) ); + } else if (strcmp (time_format, "ms") == 0) { + outmsg ("%f\n", aubio_onset_get_last_ms (o) ); + } else { + outmsg ("%f\n", aubio_onset_get_last_s (o) ); + } } } diff --git a/examples/aubiopitch.c b/examples/aubiopitch.c index 5413c2b1..bdda9508 100644 --- a/examples/aubiopitch.c +++ b/examples/aubiopitch.c @@ -46,8 +46,8 @@ void process_block(fvec_t * ibuf, fvec_t * obuf) void process_print (void) { smpl_t pitch_found = fvec_get_sample(pitch, 0); - outmsg("%f %f\n",(blocks) - *hop_size/(float)samplerate, pitch_found); + print_time(blocks * hop_size); + outmsg(" %f\n", pitch_found); } int main(int argc, char **argv) { diff --git a/examples/aubioquiet.c b/examples/aubioquiet.c index bfdd3fc2..bbe158b4 100644 --- a/examples/aubioquiet.c +++ b/examples/aubioquiet.c @@ -38,10 +38,14 @@ void process_block(fvec_t * ibuf, fvec_t * obuf) { void process_print (void) { int curblocks = (blocks - 4) > 0 ? blocks - 4 : 0; - if (issilence == -1) { - outmsg("NOISY: %f\n",curblocks*hop_size/(float)samplerate); - } else if (issilence == 2) { - outmsg("QUIET: %f\n",curblocks*hop_size/(float)samplerate); + if (issilence == -1 || issilence == 2) { + if (issilence == -1) { + outmsg ("NOISY: "); + } else { // if (issilence == 2) { + outmsg ("QUIET: "); + } + print_time (curblocks * hop_size); + outmsg ("\n"); } } diff --git a/examples/aubiotrack.c b/examples/aubiotrack.c index ab0c2d7d..330fc8ca 100644 --- a/examples/aubiotrack.c +++ b/examples/aubiotrack.c @@ -50,7 +50,8 @@ void process_block(fvec_t * ibuf, fvec_t *obuf) { void process_print (void) { if ( is_beat && !is_silence ) { - outmsg("%f\n", aubio_tempo_get_last_s(tempo) ); + print_time (aubio_tempo_get_last (tempo)); + outmsg ("\n"); } } diff --git a/examples/parse_args.h b/examples/parse_args.h index 4e91c7ea..3ab7e7f3 100644 --- a/examples/parse_args.h +++ b/examples/parse_args.h @@ -34,6 +34,8 @@ extern smpl_t onset_threshold; extern char_t * pitch_method; extern char_t * pitch_unit; extern smpl_t pitch_tolerance; +// time stuff +extern char_t * time_format; // tempo stuff extern char_t * tempo_method; // more general stuff @@ -90,6 +92,8 @@ void usage (FILE * stream, int exit_code) #endif /* PROG_HAS_PITCH */ " -s --silence select silence threshold\n" " a value in dB, for instance -70, or -100; default=-90\n" + " -T --time-format select time values output format\n" + " (samples, ms, seconds) default=seconds\n" #ifdef PROG_HAS_OUTPUT " -m --mix-input mix input signal with output signal\n" " input signal will be added to output synthesis\n" @@ -122,6 +126,7 @@ parse_args (int argc, char **argv) #ifdef PROG_HAS_PITCH "p:u:l:" #endif /* PROG_HAS_PITCH */ + "T:" "s:mf"; int next_option; struct option long_options[] = { @@ -147,6 +152,7 @@ parse_args (int argc, char **argv) {"pitch-tolerance", 1, NULL, 'l'}, #endif /* PROG_HAS_PITCH */ {"silence", 1, NULL, 's'}, + {"time-format", 1, NULL, 'T'}, {"mix-input", 0, NULL, 'm'}, {"force-overwrite", 0, NULL, 'f'}, {NULL, 0, NULL, 0} @@ -201,6 +207,9 @@ parse_args (int argc, char **argv) case 'l': pitch_tolerance = (smpl_t) atof (optarg); break; + case 'T': + time_format = optarg; + break; case 's': /* silence threshold */ silence_threshold = (smpl_t) atof (optarg); break; diff --git a/examples/utils.c b/examples/utils.c index 378cffab..2cb87d24 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -47,6 +47,8 @@ smpl_t onset_threshold = 0.0; // will be set if != 0. char_t * pitch_unit = "default"; char_t * pitch_method = "default"; smpl_t pitch_tolerance = 0.0; // will be set if != 0. +// time stuff +char_t * time_format = "seconds"; // tempo stuff char_t * tempo_method = "default"; // more general stuff @@ -196,9 +198,22 @@ send_noteon (int pitch, int velo) } else #endif if (velo == 0) { - outmsg ("%f\n", blocks * hop_size / (float) samplerate); + print_time (blocks * hop_size); + outmsg ("\n"); } else { - outmsg ("%f\t%f\t", mpitch, blocks * hop_size / (float) samplerate); + outmsg ("%f\t", mpitch); + print_time (blocks * hop_size); + outmsg ("\t"); } } +void print_time (uint_t time_in_samples) { + /* output times in selected format */ + if (strcmp (time_format, "samples") == 0) { + outmsg ("%d", time_in_samples); + } else if (strcmp (time_format, "ms") == 0) { + outmsg ("%f", 1000. * time_in_samples / (float) samplerate); + } else { + outmsg ("%f", time_in_samples / (float) samplerate); + } +} diff --git a/examples/utils.h b/examples/utils.h index 0ce67bba..93b0e18b 100644 --- a/examples/utils.h +++ b/examples/utils.h @@ -56,3 +56,5 @@ typedef int (*aubio_process_func_t) (fvec_t * input, fvec_t * output); void process_block (fvec_t *ibuf, fvec_t *obuf); void process_print (void); + +void print_time (uint_t samples); -- 2.11.0