Sometimes WAV encoders might add an additional 'JUNK' chunk into .wav files to ensure byte alignment with the pcm data (so I'd think at least). 'JUNK' chunk might appear before 'fmt ' chunk, and therefore some action should be taken, to prevent the decoder from failing.
My suggestion is to read 4 bytes, compare it to 'JUNK' first, if it exist then read the next four bytes to acquire the chunk size, and then skip the number chunk size bytes, and then proceed to deal with 'fmt ' chunk. If the 'JUNK' chunk didn't exist, seek back last 4bytes, and then proceed read and to deal with 'fmt ' chunk.
Sometimes WAV encoders might add an additional 'JUNK' chunk into .wav files to ensure byte alignment with the pcm data (so I'd think at least). 'JUNK' chunk might appear before 'fmt ' chunk, and therefore some action should be taken, to prevent the decoder from failing.
My suggestion is to read 4 bytes, compare it to 'JUNK' first, if it exist then read the next four bytes to acquire the chunk size, and then skip the number chunk size bytes, and then proceed to deal with 'fmt ' chunk. If the 'JUNK' chunk didn't exist, seek back last 4bytes, and then proceed read and to deal with 'fmt ' chunk.