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.
Starting at the 40th byte for the next 4 bytes (little endian) is the Subchunk2 size. This can also be deduced from the formula:
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 get2048 = NumSamples * 2 * 2
soNumSamples=512
A good read is here.