#83 Need to write word aligned data chunks

closed
nobody
None
5
2011-10-11
2011-02-16
Chris Bagwell
No

The following patch was emailed to me a long time back. It shows that we are kinda accounting for word aligning data chunks when writing of GSM files but not any other type of WAV . This needs to be done always.

--- sox-14.3.0/src/wav.c 2009-04-26 17:40:10.000000000 -0700
+++ sox-14.3.0-patched/src/wav.c 2010-02-26 12:36:29.980160315
-0800
@@ -78,6 +78,7 @@
* greater then 2 Gb and can't be
represented by the
* 32-bit size field. */
/* FIXME: Have some front-end code which sets this flag. */
+ sox_bool needDataChunkPad; /* dwDataLength is odd, so add a pad byte
*/

/* following used by *ADPCM wav files */
unsigned short nCoefs; /* ADPCM: number of coef sets */
@@ -356,14 +357,6 @@
if (wav->gsmindex)
wavgsmflush(ft);

- /* Add a pad byte if amount of written bytes is not even. */
- if (wav->gsmbytecount && wav->gsmbytecount % 2){
- if(lsx_writeb(ft, 0))
- lsx_fail_errno(ft,SOX_EOF,"write error");
- else
- wav->gsmbytecount += 1;
- }
-
wavgsmdestroy(ft);
}

@@ -1368,6 +1361,8 @@
/* dwAvgBytesPerSec <-- this is BEFORE compression, isn't it? guess
not. */
dwAvgBytesPerSec = (double)wBlockAlign*ft->signal.rate /
(double)wSamplesPerBlock + 0.5;

+ wav->needDataChunkPad = dwDataLength & 1; /* if the data chunk needs
a final pad byte */
+
/* figured out header info, so write it */

/* If user specified opposite swap than we think, assume they are
@@ -1522,6 +1517,12 @@
free(wav->samples);
free(wav->lsx_ms_adpcm_i_coefs);

+ /* add final pad byte to data chunk, if needed */
+ if (wav->needDataChunkPad) {
+ if (lsx_writeb(ft, 0))
+ lsx_fail_errno(ft, SOX_EOF, "write error");
+ }
+
/* All samples are already written out. */
/* If file header needs fixing up, for example it needs the */
/* the number of samples in a field, seek back and write them
here. */

Discussion

  • Ulrich Klauer
    Ulrich Klauer
    2011-10-11

    I fixed this independently yesterday, so closing.

     
  • Ulrich Klauer
    Ulrich Klauer
    2011-10-11

    • status: open --> closed