OneLoneCoder / olcSoundWaveEngine

A single file, easy to use, audio playback and synthesis framework
90 stars 18 forks source link

WAV loader is not dealing with possible 'JUNK' chunk and therefore might fail in file loading. #23

Open MaGetzUb opened 1 year ago

MaGetzUb commented 1 year ago

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.