shithub: sox

Download patch

ref: 96150e81b51f6e57cddc8cf31b501f3f31baf862
parent: 6b89e47023c9b5fbb84eff99a348a9e24d2ab068
author: rrt <rrt>
date: Sun Sep 14 06:44:08 EDT 2008

Apply bug-fix from Silas Brown to write data out correctly. That's
where the glitches were coming from!

Also reformat code in that area slightly for clarity. The actual fix
is to change "buf" to "bug + written" in the call to sox_adpcm_write.

--- a/src/prc.c
+++ b/src/prc.c
@@ -363,21 +363,23 @@
   /* Psion Record seems not to be able to handle frames > 800 samples */
   size_t written = 0;
   sox_debug_more("length now = %d", p->nsamp);
-  if (ft->encoding.encoding == SOX_ENCODING_IMA_ADPCM) while (written < nsamp) {
-    size_t written1, samp = min(nsamp - written, 800);
+  if (ft->encoding.encoding == SOX_ENCODING_IMA_ADPCM) {
+    while (written < nsamp) {
+      size_t written1, samp = min(nsamp - written, 800);
 
-    write_cardinal(ft, (unsigned) samp);
-    /* Write compressed length */
-    write_cardinal(ft, (unsigned) ((samp / 2) + (samp % 2) + 4));
-    /* Write length again (seems to be a BListL) */
-    sox_debug_more("list length %lu", (unsigned long)samp);
-    lsx_writedw(ft, (unsigned) samp);
-    sox_adpcm_reset(&p->adpcm, ft->encoding.encoding);
-    written1 = sox_adpcm_write(ft, &p->adpcm, buf, samp);
-    if (written1 != samp)
-      break;
-    sox_adpcm_flush(ft, &p->adpcm);
-    written += written1;
+      write_cardinal(ft, (unsigned) samp);
+      /* Write compressed length */
+      write_cardinal(ft, (unsigned) ((samp / 2) + (samp % 2) + 4));
+      /* Write length again (seems to be a BListL) */
+      sox_debug_more("list length %lu", (unsigned long)samp);
+      lsx_writedw(ft, (unsigned) samp);
+      sox_adpcm_reset(&p->adpcm, ft->encoding.encoding);
+      written1 = sox_adpcm_write(ft, &p->adpcm, buf + written, samp);
+      if (written1 != samp)
+        break;
+      sox_adpcm_flush(ft, &p->adpcm);
+      written += written1;
+    }
   } else
     written = lsx_rawwrite(ft, buf, nsamp);
   p->nsamp += written;