I have been trying out a wav joiner program in vb.net to join wav files and although it's working fine some of the time, often the resultant wav file doesn't play. After peeking into the original wav files, I noticed that the data subchunk where the word 'data' is was starting at offset 38 instead of 36. That is what's messing up the joiner which assumes offset 36. When I reexported that wav file from audacity, it fixed it up and the data subchunk starts at 36. All programs play the original file fine so I guess it's valid. Why are there two extra 00 bytes values right before the word 'data' in those wav files?
-
Is sub-chunk 1 size correct in the one with the two extra bytes? https://ccrma.stanford.edu/courses/422/projects/WaveFormat/ 26 instead of 24? When you've got a size field, you don't need to assume the size is always the same, and its presence is a hint that it may not be. – 15ee8f99-57ff-4f92-890c-b56153 May 07 '14 at 02:52
-
Yes you're right, the subchunk size is 18 as opposed to 16 in the other files. I just noticed another post about this after posting: http://stackoverflow.com/questions/19991405/how-can-i-detect-whether-a-wav-file-has-a-44-or-46-byte-header – nlehman May 07 '14 at 02:57
1 Answers
This is a guess, but have you looked at the four-byte number which is at offset 16 in the files where data
starts at offset 38?
The fmt
sub-chunk is of variable size, and its size is specified in a dword at offset 16 relative to the chunk ID, which is at zero in your files. That dword value is the size of the remainder of the sub-chunk, exclusive of the ID field and of the size field itself. My guess is that if you look there, the ones with the two extra bytes will say that their fmt
sub-chunk is 18 bytes long rather than 16 (thanks ooga for catching my error on that).
https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
When there's a size field, always use it. There's no need to jump to fixed offsets in the file on faith if the file format will tell you how big things are. And if it is telling you the size of things, take that as a warning that the size may change.

- 36,786
- 7
- 62
- 114
-
1
-
@ooga Quite right, it's the size of the *remainder* of the sub-chunk, exclusive of the ID and size fields. My bad, I'll fix that. Thanks! – 15ee8f99-57ff-4f92-890c-b56153 May 07 '14 at 03:01