I was getting tired of analyzing WAVE files by hand with a hex editor. So I wrote a Perl script to do it. It parses through the RIFF file and it’s chunks, making sure the WAVE header exists and that it’s properly formed. Unexpectedly, I found another issue with the Radiohead The King Of Limbs WAVE files. The WAVE header is a couple bytes longer than it needs to be. The “fmt ” chunk, where the WAVE header is stored, is properly formed, so it’s not an error. But from what I’m reading, a number of programs create WAVE files with this quirk (I’ve seen files like this from Sound Forge, and the sound recorder that comes with Windows XP apparently does this as well).
The chunk size is indicated correctly, so it’s not technically wrong, but some programs reportedly have problems with WAVE files created this way, as they assume that everything in the WAVE file is aligned in four-byte intervals. The standard WAVE header is 24 bytes, and the RIFF header is 12 bytes, so the “data” chunk typically starts at byte offset 36, which is four-byte aligned. The two extra bytes in the header would push the data chunk to byte offset 38, which is not four-byte aligned.
You can’t actually make any such assumptions about the internal format of a RIFF (and thus WAVE) file, so this is buggy behavior on the part of any program that does this. But it seems to be common enough that someone wrote a Windows program called FixWAV that trims the extra two bytes off the WAVE header to “fix” it. (My rewrapWAV Perl script does the same thing, by the way.)
Why are these extra bytes added in some cases?
WAVE files are usually used to store PCM audio, but it is actually possible to store compressed audio. There is a “AudioFormat” field of the WAVE header which indicates the kind of audio being used. It’s almost always “1” which indicates PCM audio, but if it is another value, there’s compression of some sort being used, and the header is extended to indicate the type of compression.
If AudioFormat is something other than “1”, the two bytes after the end of the traditional WAVE header is a length of the extra compression information, and the actual information comes after that. These two bytes, called ExtraParamSize, are not expected to be present if AudioFormat is 1, but strictly speaking, it doesn’t hurt if they are there, but set to zero, which means there are not bytes past those. Any program that can generate compressed WAVE files might choose to add this field regardless of the AudioFormat.
The Radiohead WAVE files have these extra bytes.
My WAVE validation tool detects this in the file, as well as the extra JUNK and BWF chunks. Here’s an example of the output: