shithub: sox

Download patch

ref: bc8d4ef63433f5649e5ce30ec34d58dd43394623
parent: e667358cc4852c31a9191f8082c4e5c4eabc7bf5
author: Ulrich Klauer <ulrich@chirlu.de>
date: Mon Jan 2 15:08:46 EST 2012

Improve default output length calculation for effects

As audio length within the effects chain is given in terms of (non-wide)
samples, it changes for effects that modify the number of channels or
the sample rate even if the actual time for the audio remains the same.

Account for this when calculating a default output length for effects
that have SOX_EFF_CHAN and/or SOX_EFF RATE set, but not SOX_EFF_LENGTH.

--- a/src/effects.c
+++ b/src/effects.c
@@ -147,10 +147,7 @@
         in->precision : SOX_SAMPLE_PRECISION;
   if (!(effp->handler.flags & SOX_EFF_GAIN))
     effp->out_signal.mult = in->mult;
-  if (!(effp->handler.flags & SOX_EFF_LENGTH))
-    effp->out_signal.length = in->length;
 
-
   effp->flows =
     (effp->handler.flags & SOX_EFF_MCHAN)? 1 : effp->in_signal.channels;
   effp->clips = 0;
@@ -171,6 +168,16 @@
   }
   if (in->mult)
     lsx_debug("mult=%g", *in->mult);
+
+  if (!(effp->handler.flags & SOX_EFF_LENGTH)) {
+    effp->out_signal.length = in->length;
+    if (effp->handler.flags & SOX_EFF_CHAN)
+      effp->out_signal.length =
+        effp->out_signal.length / in->channels * effp->out_signal.channels;
+    if (effp->handler.flags & SOX_EFF_RATE)
+      effp->out_signal.length =
+        effp->out_signal.length / in->rate * effp->out_signal.rate + .5;
+  }
 
   *in = effp->out_signal;