shithub: sox

Download patch

ref: ab9e321c07728b9c4b70785bb496949e390fa752
parent: 55272cd7e8ed79f7e5caaaa04ab8486d1afa2fb0
author: cbagwell <cbagwell>
date: Tue Oct 12 20:44:23 EDT 2004

WAV GSM fix for even byte padding.

--- a/Changelog
+++ b/Changelog
@@ -58,6 +58,7 @@
     from -1:1.
   o Modifed .au handler to be able to read and write 32-bit
     and 64-bit float data.  Only tested reading so far.
+  o WAV with GSM data now always pads data to even number of bytes.
   o Added support for writing 32-bit audio to AIFF.
 
 sox-12.17.5
--- a/src/wav.c
+++ b/src/wav.c
@@ -321,7 +321,7 @@
     return done;
 }
 
-static int wavgsmflush(ft_t ft, int pad)
+static int wavgsmflush(ft_t ft)
 {
     gsm_byte    frame[65];
     wav_t       wav = (wav_t) ft->priv;
@@ -342,16 +342,6 @@
     wav->gsmbytecount += 65;
 
     wav->gsmindex = 0;
-
-    if (pad & wav->gsmbytecount){
-        /* pad output to an even number of bytes */
-        if(st_writeb(ft, 0))
-        {
-            st_fail_errno(ft,ST_EOF,"write error");
-            return (ST_EOF);
-        }
-        wav->gsmbytecount += 1;
-    }
     return (ST_SUCCESS);
 }
 
@@ -371,7 +361,7 @@
         if (wav->gsmindex < 160*2)
             break;
 
-        rc = wavgsmflush(ft, 0);
+        rc = wavgsmflush(ft);
         if (rc)
             return 0;
     }     
@@ -383,10 +373,18 @@
 {
     wav_t       wav = (wav_t) ft->priv;
 
-        ft->st_errno = ST_SUCCESS;
+    ft->st_errno = ST_SUCCESS;
 
     if (wav->gsmindex)
-        wavgsmflush(ft, 1);
+        wavgsmflush(ft);
+
+    /* Add a pad byte if amount of written bytes is not even. */
+    if (wav->gsmbytecount && wav->gsmbytecount % 2){
+        if(st_writeb(ft, 0))
+            st_fail_errno(ft,ST_EOF,"write error");
+        else
+            wav->gsmbytecount += 1;
+    }
 
     wavgsmdestroy(ft);
 }