shithub: sox

Download patch

ref: f52cfb29110cd62e70496b2a7b91107f2e988637
parent: 2469faa09760cccf9ac360872613fca7a42836aa
author: Ulrich Klauer <ulrich@chirlu.de>
date: Thu Jan 31 19:05:58 EST 2013

splice: use lsx_parseposition

Use the new lsx_parseposition function for the splice effect and
update the documentation accordingly.

--- a/sox.1
+++ b/sox.1
@@ -3345,7 +3345,7 @@
 .B tempo
 effects.
 .TP
-\fBsplice \fR [\fB\-h\fR\^|\^\fB\-t\fR\^|\^\fB\-q\fR] { \fIposition\fR[\fB,\fIexcess\fR[\fB,\fIleeway\fR]] }
+\fBsplice \fR [\fB\-h\fR\^|\^\fB\-t\fR\^|\^\fB\-q\fR] { \fIposition(=)\fR[\fB,\fIexcess\fR[\fB,\fIleeway\fR]] }
 Splice together audio sections.  This effect provides two things over
 simple audio concatenation: a (usually short) cross-fade is applied at
 the join, and a wave similarity comparison is made to help determine the
@@ -3381,12 +3381,12 @@
 .IR excess
 (before the ideal joining point), plus an additional
 .I leeway
-(default 0\*d005 seconds).  SoX should then be invoked with the two
+(default 0\*d005 seconds).  Any time specification may be used for these
+parameters.  SoX should then be invoked with the two
 audio sections as input files and the
 .B splice
 effect given with the position at which to perform the splice\*mthis is
 length of the first audio section (including the excess).
-Any time specification may be used for these parameters.
 .SP
 The following diagram uses the tape analogy to illustrate the splice
 operation.  The effect simulates the diagonal cuts and joins the two pieces:
--- a/src/splice.c
+++ b/src/splice.c
@@ -119,6 +119,10 @@
   priv_t * p = (priv_t *)effp->priv;
   char const * next;
   size_t i, buffer_size;
+  uint64_t last_seen = 0;
+  const uint64_t in_length = argv ? 0 :
+    (effp->in_signal.length != SOX_UNKNOWN_LEN ?
+     effp->in_signal.length / effp->in_signal.channels : SOX_UNKNOWN_LEN);
 
   p->max_buffer_size = 0;
   for (i = 0; i < p->nsplices; ++i) {
@@ -128,8 +132,10 @@
     p->splices[i].overlap = rate * 0.01 + .5;
     p->splices[i].search = p->fade_type == Cosine_4? 0 : p->splices[i].overlap;
 
-    next = lsx_parsesamples(rate, p->splices[i].str, &p->splices[i].start, 't');
+    next = lsx_parseposition(rate, p->splices[i].str,
+             argv ? NULL : &p->splices[i].start, last_seen, in_length, '=');
     if (next == NULL) break;
+    last_seen = p->splices[i].start;
 
     if (*next == ',') {
       next = lsx_parsesamples(rate, next + 1, &p->splices[i].overlap, 't');
@@ -145,11 +151,13 @@
     p->splices[i].overlap = max(p->splices[i].overlap + 4, 16);
     p->splices[i].overlap &= ~7; /* Make divisible by 8 for loop optimisation */
 
-    if (i > 0 && p->splices[i].start <= p->splices[i-1].start) break;
-    if (p->splices[i].start < p->splices[i].overlap) break;
-    p->splices[i].start -= p->splices[i].overlap;
-    buffer_size = 2 * p->splices[i].overlap + p->splices[i].search;
-    p->max_buffer_size = max(p->max_buffer_size, buffer_size);
+    if (!argv) {
+      if (i > 0 && p->splices[i].start <= p->splices[i-1].start) break;
+      if (p->splices[i].start < p->splices[i].overlap) break;
+      p->splices[i].start -= p->splices[i].overlap;
+      buffer_size = 2 * p->splices[i].overlap + p->splices[i].search;
+      p->max_buffer_size = max(p->max_buffer_size, buffer_size);
+    }
   }
   if (i < p->nsplices)
     return lsx_usage(effp);