Problem reading some WAV files using WAV.jl

I have come across a wav file that I cannot read using WAV.jl (or LibSndFile.jl). I can open it in about any other audio program or library (Matlab, R, Raven, Audacity, …). If I read it into Matlab and write it back out, then it reads fine with WAV.jl.

I took two files - the original wav file (mdoc) and a version that was read in and then written out using Matlab (mdoc_rewrite) - and tried to find any differences in the files with hexdump. This is the result (*.txt is hexdump output):

$ diff mdoc.txt mdoc_rewrite.txt 
< 00000000  52 49 46 46 14 22 f9 **01**  57 41 56 45 66 6d 74 20  |RIFF."..WAVEfmt |
> 00000000  52 49 46 46 14 22 f9 **61**  57 41 56 45 66 6d 74 20  |RIFF.".aWAVEfmt |

I believe positions 5-8 are the file chunk size (little endian) and there is a difference. The file size rewritten from Matlab is correct (if the position 8 value is 61, the chunk correctly corresponds to the wav file size minus 8 bytes).

Was this an incorrectly written wav file? Does it not matter if the file size in the header is incorrect with most programs? Or is there something I’m missing in my understanding of WAV.jl or wav file structure.

Thank you - Robert

Update - I tried putting arbitrary numbers in positions 5-8…matlab still read the file

Hey Robert :wave:, subchunk size does seem to affect how the file is being read atm: WAV.jl/WAV.jl at de6615dbf08654d1ddd97ad63c376bb3f867dae7 · dancasimiro/WAV.jl · GitHub,

@Ashwani_Rathee Hi Ashwani… maybe most applications ignore the RIFF part of the WAV file header. Unfortunately, I have many thousands of these files so maybe I’ll just run through them through sox as a batch job. Perhaps an option could be proposed that would have WAV.jl ignore the RIFF part of the header? Or maybe the developers had a reason for requiring the chunk size to be correct…I’m not an expert here. Thanks for the link in the code.