Finding the number of samples in the .wav header

The wav file has a header (44 bytes). This header indicates the sampling frequency of the signal, the number of channels, etc., The number of samples from the audio file. I need to know where I can find the amount of sample information in the header.

What will be the formula.

+2
source share
1 answer

Starting from the 40th byte for the next 4 bytes (small end) - the size of Subchunk2. This can also be deduced from the formula:

Subchunk2size = NumSamples * NumChannels * BitsPerSample/8 

NumChannels begin with byte 22 and 2 bytes (a small number) in length. BitsPerSample starts at the 34th byte and has a length of 2 bytes (small end). Replacing all of this, you can get 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

Good reading here.

+2
source

All Articles