Search code examples
audiowavopenallmms

WAV file headers reporting incorrect size


When decoding a WAV file I'm able to read from the header the following values (formatted neatly):

Channels: 2
BitDepth: 16
SampleRate: 44100
FileSize: 907346
FileType: RIFF
AudioFileType: WAVE
data: [...]
PCM: 0

When I load this into a OpenAL buffer and attempt to play it back, the sound doesn't play. However after a lots of tweaking, I was able to get the sound to play when I hardcode the FileSize to 907300.

This got me thinking that OpenAL most likely needs me to be offset the header when I start loading in the sample data. However a WAV file's header size is only 44 bytes. I'm also assuming that just offsetting by 46 bytes isn't really a long term solution. So where does the extra 2 bytes come from?

Update:

I tested another file which I downloaded of the internet instead of saving from LMMS. It doesn't play at all even after offsetting by 44 or 46 bytes. Its header is identical except for FileSize: 1242448


Solution

  • It turns LMMS decided it does not want to save out .wav file headers the way they are supposed to. Had a quick peek into the .wav file with dhex and the header contains unwanted info. The whole header looks like this:

    RIFFR...WAVEfmt ........D...........LIST&...INFO
    ISFT....LMMS (libsndfile-1.0.27)..data..........
    

    I eventually tested with bfxr and Bosca Ceoil and all of their sounds are playing and the headers look nice a tidy.

    Hope this information will be useful to someone.