shithub: aubio

Download patch

ref: df7be4385dc2c85d14e8c8c168c782e6b60eedb6
parent: 340cb937f86df50f6630f90ecc9d0c252007fbb8
author: Paul Brossier <piem@piem.org>
date: Wed Aug 12 12:31:40 EDT 2015

examples/parse_args.h: only parse time format string once, warn if unknown

--- a/examples/aubioonset.c
+++ b/examples/aubioonset.c
@@ -49,13 +49,8 @@
 void process_print (void)
 {
   if ( is_onset ) {
-    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) );
-    }
+    print_time(aubio_onset_get_last (o));
+    outmsg ("\n");
   }
 }
 
--- a/examples/parse_args.h
+++ b/examples/parse_args.h
@@ -35,7 +35,7 @@
 extern char_t * pitch_unit;
 extern smpl_t pitch_tolerance;
 // time stuff
-extern char_t * time_format;
+extern uint_t time_format;
 // tempo stuff
 extern char_t * tempo_method;
 // more general stuff
@@ -208,7 +208,15 @@
         pitch_tolerance = (smpl_t) atof (optarg);
         break;
       case 'T':
-        time_format = optarg;
+        if (strcmp (optarg, "samples") == 0) {
+          time_format = 2;
+        } else if (strcmp (optarg, "ms") == 0) {
+          time_format = 1;
+        } else if (strcmp (optarg, "seconds") == 0) {
+          time_format = 0;
+        } else {
+          errmsg ("Warning: did not get '%s' time-format string\n", optarg);
+        }
         break;
       case 's':                /* silence threshold */
         silence_threshold = (smpl_t) atof (optarg);
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -48,7 +48,7 @@
 char_t * pitch_method = "default";
 smpl_t pitch_tolerance = 0.0; // will be set if != 0.
 // time stuff
-char_t * time_format = "seconds";
+uint_t time_format = 0; // for "seconds", 1 for "ms", 2 for "samples"
 // tempo stuff
 char_t * tempo_method = "default";
 // more general stuff
@@ -209,9 +209,9 @@
 
 void print_time (uint_t time_in_samples) {
   /* output times in selected format */
-  if (strcmp (time_format, "samples") == 0) {
+  if (time_format == 2) {
     outmsg ("%d", time_in_samples);
-  } else if (strcmp (time_format, "ms") == 0) {
+  } else if (time_format == 1) {
     outmsg ("%f", 1000. * time_in_samples / (float) samplerate);
   } else {
     outmsg ("%f", time_in_samples / (float) samplerate);