Finding number of samples in a .wav header

2019-07-10 17:33发布

问题:

The wav file has a header (44 bytes). In this header is specified the sample rate of the signal, number of channels and so on, number of samples from the audio file. I need to know where can I find the number of samples information in the header.

What would be the formula.

回答1:

Starting at the 40th byte for the next 4 bytes (little endian) is the Subchunk2 size. This can also be deduced from the formula:

Subchunk2size = NumSamples * NumChannels * BitsPerSample/8

NumChannels start at byte 22 and 2 bytes (little endian) in length. BitsPerSample start at 34th byte and is 2 bytes (little endian) in length. Replacing all these you can get the NumSamples which is the number of samples.

For example: if Subchunksize2=2048, NumChannels=2 and BitsPerSample=16, you get 2048 = NumSamples * 2 * 2 so NumSamples=512

A good read is here.



标签: audio wav