ref: 340cb937f86df50f6630f90ecc9d0c252007fbb8
parent: a90e9d4852c375f27bb44e812fbad970fee624a8
author: Paul Brossier <piem@piem.org>
date: Wed Aug 12 12:15:39 EDT 2015
examples/: add time format option
--- a/examples/aubiomfcc.c
+++ b/examples/aubiomfcc.c
@@ -40,9 +40,11 @@
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) {--- a/examples/aubioonset.c
+++ b/examples/aubioonset.c
@@ -49,7 +49,13 @@
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) );+ }
}
}
--- a/examples/aubiopitch.c
+++ b/examples/aubiopitch.c
@@ -46,8 +46,8 @@
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) {--- a/examples/aubioquiet.c
+++ b/examples/aubioquiet.c
@@ -38,10 +38,14 @@
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");}
}
--- a/examples/aubiotrack.c
+++ b/examples/aubiotrack.c
@@ -50,7 +50,8 @@
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");}
}
--- a/examples/parse_args.h
+++ b/examples/parse_args.h
@@ -34,6 +34,8 @@
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 @@
#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 @@
#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 @@
{"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}@@ -200,6 +206,9 @@
break;
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);
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -47,6 +47,8 @@
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 @@
} 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);+ }
+}
--- a/examples/utils.h
+++ b/examples/utils.h
@@ -56,3 +56,5 @@
void process_block (fvec_t *ibuf, fvec_t *obuf);
void process_print (void);
+
+void print_time (uint_t samples);
--
⑨