ref: 851a8d152c004310afd5bdf0a300c1c74e979855
parent: d6e47684f70c9ca1ffb9cd48c82f9513ef88eddd
author: Ulrich Klauer <ulrich@chirlu.de>
date: Wed Oct 17 21:21:05 EDT 2012
spectrogram -S: use lsx_parseposition Use the new lsx_parseposition function for the -S option to the spectrogram effect and update the documentation accordingly.
--- a/sox.1
+++ b/sox.1
@@ -3310,7 +3310,7 @@
See also
.B \-X
for an alternative way of setting the X-axis resolution.
-.IP \fB\-S\ \fItime\fR
+.IP \fB\-S\ \fIposition(=)\fR
Start the spectrogram at the given point in the audio stream. For
example
.EX
@@ -3318,7 +3318,6 @@
.EE
creates a spectrogram showing all but the first minute of the audio
(the output file, however, receives the entire audio stream).
-Any time specification may be used.
.RE
.TP
\
--- a/src/spectrogram.c
+++ b/src/spectrogram.c
@@ -125,7 +125,7 @@
case 't': p->title = optstate.arg; break;
case 'c': p->comment = optstate.arg; break;
case 'o': p->out_name = optstate.arg; break;
- case 'S': next = lsx_parsesamples(1e5, optstate.arg, &dummy, 't');
+ case 'S': next = lsx_parseposition(0., optstate.arg, NULL, (uint64_t)0, (uint64_t)0, '=');
if (next && !*next) {p->start_time_str = lsx_strdup(optstate.arg); break;}
return lsx_usage(effp);
case 'd': next = lsx_parsesamples(1e5, optstate.arg, &dummy, 't');
@@ -214,7 +214,12 @@
duration = d / effp->in_signal.rate;
}
if (p->start_time_str) {
- lsx_parsesamples(effp->in_signal.rate, p->start_time_str, &d, 't');
+ uint64_t in_length = effp->in_signal.length != SOX_UNKNOWN_LEN ?
+ effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN;
+ if (!lsx_parseposition(effp->in_signal.rate, p->start_time_str, &d, (uint64_t)0, in_length, '=') || d == SOX_UNKNOWN_LEN) {
+ lsx_fail("-S option: audio length is unknown");
+ return SOX_EOF;
+ }
start_time = d / effp->in_signal.rate;
p->skip = d;
}
@@ -673,7 +678,7 @@
"\t-c text\tComment text",
"\t-o text\tOutput file name; default `spectrogram.png'",
"\t-d time\tAudio duration to fit to X-axis; e.g. 1:00, 48",
- "\t-S time\tStart the spectrogram at the given time through the input",
+ "\t-S position\tStart the spectrogram at the given input position",
};
static char * usage;
handler.usage = lsx_usage_lines(&usage, lines, array_length(lines));