Page 1 of 1

How is number of samples calculated for a wav file?

Posted: 26 Oct 2020 22:31
by nathalieraffray
Hi, pardon me and let me know if this is the wrong forum to post this in.

I have a technical question regarding how the number of samples is calculated when I open a .wav file in VLC.

I have an uncompressed wav file whose "data" chunk is corrupted. Although its a song that lasts 6 minutes, the chunk size in the "data" chunk is set to the maximum value: max(uint32_t), e.g. 4294967295.
The "fmt" chunk of my .wav file tells us that:
blockAlign = 4
sampleFrequency = 44100 Hz.

With this header information, this implies the duration of the song to be:
duration = nbSamples / sampleFrequency;
where
nbSamples = dataChunkSize / blockAlign

==> duration = (4294967295 / 4) / 44100 = 24347s = ~6hours!!
However the song only lasts 6 minutes!

Hope you are following till here :(
Now the interesting part:
I noticed that opening this wav file VLC 3.0.4 will show the duration of the song as 6 hours.
However opening it in VLC 3.0.5 will show the duration as 6 minutes!

I was wondering how you account for this sort of corrupted data chunk size in a wav file. How do you calculate the right number of samples, and therefore the right duration of a song?
Do you systematically "count" the actual number of samples and not rely on the chunk size of a "data" chunk? Could you point me to the location in the source code where this is done? Cheers~ have a wonderful day :P