Why some .wav files don't work

Date: Mon, 20 Nov 1995 18:02:18 -0600
From: "Joseph W. DeVincentis"
On the .wav that doesn't work for Preston, the similar sox command for .wav files (just replace aiff with wav) tells me "missing data portion." When I was using wavplay, I found that if you modified the code to be more generous in the allowed error between the data length encoded in the file and the actual length, that it plays many of the .wav files that seem to be encoded with the wrong length. In the wavplay source, near the top of recplay.c, you can set the condition to be more generous. For whatever reason, the author of wavplay set this to only allow an error of 1 byte, but somebody out there is making .wav files with differences of up to 100 or so bytes in the data length. I switched to using Sox because wavplay did a poor job of handling 16-bit .wav's (at least for playing on an 8-bit sound card).

However, the file on Preston's web page is worse, because the data length is set to only 24 bytes! I did some digging to find out why such a stupid thing would be done, by looking at this file in emacs.

In fact, this file seems to contain two "segments" with the first being a 24 byte "comment". Actually, there is a 3rd segment labeled "WAVE" which contains info about the type of sample, which always seems to come first. The sound data is in a segment which begins with "data" and the data length; the comment is in a segment which begins with "INFO" and the comment length.

If you remove the comment (for those of you following along at home, delete 32 bytes starting at byte 36) then the file plays fine. If this sort of comment is a legitimate feature of a .wav file, then the players/convertors should support it, by skipping ahead to the data track. (If they wanted to be fancy, they could print out the comment...) I suspect that the .wav's I found before for which wavplay reported a "wrong length difference" where the difference was around 50-100 bytes probably had a similar comment at the *end* of the file, though I don't have any such files handy to verify this.

I am sending copies of this article to the authors of wavplay and sox. Hopefully we can see new versions of these programs that handle such comments in the file.