shithub: sox

Download patch

ref: fc15f7f570f412df4292290a9e70fac188ce45ab
parent: 1ecdbf558c5af9da1a148520d51a2c2b2a104778
author: robs <robs>
date: Sat Nov 18 12:45:42 EST 2006

Fix synth length accuracy.
Fix synth block size error.

--- a/Changelog
+++ b/Changelog
@@ -34,6 +34,10 @@
     leading 0. (robs)
   o Fix nul file hander ignoring other format options if rate
     option has not been given. (robs)
+  o Fix synth length accuracy. (robs)
+  o Fix broken audio when using synth as follows:
+    sox -t nul /dev/null -c 1 output.wav synth 1 sine
+    (robs)
 
 sox-12.18.2
 -----------
--- a/src/synth.c
+++ b/src/synth.c
@@ -253,7 +253,7 @@
     
 
     /* read length if given ( if first par starts with digit )*/
-    if( isdigit((int)argv[argn][0])) {
+    if( isdigit((int)argv[argn][0]) || argv[argn][0] == '.') {
         synth->length_str = (char *)malloc(strlen(argv[argn])+1);
         if (!synth->length_str)
         {
@@ -683,9 +683,10 @@
 {
     synth_t synth = (synth_t) effp->priv;
     int len; /* number of input samples */
-    int done;
+    int done = 0;
     int c;
     int chan=effp->ininfo.channels;
+    int result = ST_SUCCESS;
 
     if(chan > MAXCHAN ){
         st_fail("synth: can not operate with more than %d channels",MAXCHAN);
@@ -694,7 +695,8 @@
 
     len = ((*isamp > *osamp) ? *osamp : *isamp) / chan;
 
-    for(done = 0; done < len ; done++){
+    while (done < len && result == ST_SUCCESS)
+    {
         for(c=0;c<chan;c++){
             /* each channel is independent, but the algorithm is the same */
 
@@ -702,18 +704,15 @@
         }
         ibuf+=chan;
         obuf+=chan;
+        ++done;
         synth->samples_done++;
-        if(synth->length > 0 ){
-            if( synth->samples_done > synth->length){
-                *osamp = done*chan;
-                return ST_EOF;
-                break;
-
-            }
+        if (synth->length > 0 && synth->samples_done == synth->length)
+        {
+            result = ST_EOF;
+        }
     }
-        
-    }
-    return (ST_SUCCESS);
+    *isamp = *osamp = done * chan;
+    return result;
 }
 
 /*
--- a/src/tests.sh
+++ b/src/tests.sh
@@ -55,3 +55,11 @@
 convertToAndFrom hcom
 rate=8000
 convertToAndFrom voc wve flac
+
+./sox -c 1 -t nul /dev/null output.ub synth .01 sine
+if [ `wc -c <output.ub` = 441 ]; then
+  echo "ok     synth size"
+else
+  echo "*FAIL* synth size"
+fi
+rm output.ub