ref: d6e47684f70c9ca1ffb9cd48c82f9513ef88eddd
parent: b4ee498064d4c43799d835f5a0ada856bf3f6838
author: Ulrich Klauer <ulrich@chirlu.de>
date: Wed Oct 17 21:05:17 EDT 2012
fade: use lsx_parseposition Use the new lsx_parseposition function for the fade effect and update the documentation accordingly.
--- a/sox.1
+++ b/sox.1
@@ -2120,7 +2120,7 @@
.SP
See also \fBbass\fR and \fBtreble\fR for shelving equalisation effects.
.TP
-\fBfade\fR [\fItype\fR] \fIfade-in-length\fR [\fIstop-time\fR [\fIfade-out-length\fR]]
+\fBfade\fR [\fItype\fR] \fIfade-in-length\fR [\fIstop-position(=)\fR [\fIfade-out-length\fR]]
Apply a fade effect to the beginning, end, or both of the audio.
.SP
An optional \fItype\fR can be specified to select the shape of the fade
@@ -2134,20 +2134,24 @@
no fade-in is wanted.
.SP
For fade-outs, the audio will be truncated at
-.I stop-time
+.I stop-position
and the signal level will be ramped from full volume down to 0 over an
-interval of \fIfade-out-length\fR before the \fIstop-time\fR. If
+interval of \fIfade-out-length\fR before the \fIstop-position\fR. If
.I fade-out-length
is not specified, it defaults to the same value as
\fIfade-in-length\fR.
No fade-out is performed if
-.I stop-time
+.I stop-position
is not specified.
If the audio length can be determined from the input file header and any
-previous effects, then \fB0\fR may be specified for
-.I stop-time
+previous effects, then \fB\-0\fR (or, for historical reasons, \fB0\fR) may
+be specified for
+.I stop-position
to indicate the usual case of a fade-out that ends at the end of the input
-audio stream. Any time specification may be used for these parameters.
+audio stream.
+.SP
+Any time specification may be used for \fIfade-in-length\fR and
+\fIfade-out-length\fR.
.SP
See also the
.B splice
--- a/src/fade.c
+++ b/src/fade.c
@@ -90,7 +90,7 @@
fade->out_stop_str = lsx_strdup(argv[t_argno]);
/* Do a dummy parse to see if it will fail */
- n = lsx_parsesamples(0., fade->out_stop_str, &samples, 't');
+ n = lsx_parseposition(0., fade->out_stop_str, NULL, (uint64_t)0, (uint64_t)0, '=');
if (!n || *n)
return lsx_usage(effp);
fade->out_stop = samples;
@@ -119,6 +119,8 @@
priv_t * fade = (priv_t *) effp->priv;
sox_bool truncate = sox_false;
uint64_t samples;
+ uint64_t in_length = effp->in_signal.length != SOX_UNKNOWN_LEN ?
+ effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN;
/* converting time values to samples */
fade->in_start = 0;
@@ -132,9 +134,12 @@
if (fade->out_stop_str)
{
fade->do_out = 1;
- if (lsx_parsesamples(effp->in_signal.rate, fade->out_stop_str,
- &samples, 't') == NULL)
- return lsx_usage(effp);
+ if (!lsx_parseposition(effp->in_signal.rate, fade->out_stop_str,
+ &samples, (uint64_t)0, in_length, '=') ||
+ samples == SOX_UNKNOWN_LEN) {
+ lsx_fail("audio length is unknown");
+ return SOX_EOF;
+ }
fade->out_stop = samples;
if (!(truncate = !!fade->out_stop)) {
@@ -376,7 +381,7 @@
static sox_effect_handler_t sox_fade_effect = {
"fade",
- "[ type ] fade-in-length [ stop-time [ fade-out-length ] ]\n"
+ "[ type ] fade-in-length [ stop-position [ fade-out-length ] ]\n"
" Time is in hh:mm:ss.frac format.\n"
" Fade type one of q, h, t, l or p.",
SOX_EFF_MCHAN | SOX_EFF_LENGTH,