Finding number of samples in .wav file and Hex Editor

james picture james · May 2, 2011 · Viewed 9.6k times · Source

Need help with Hex Editor and audio files.I am having trouble figuring out the formula to get the number of samples in my .wav files.

I downloaded StripWav which tells me the number of samples in the .waves,but still cannot figure out the formula.

Can you please download these two .wavs,open them in a hex editor and tell me the formula to get the number of samples.

If you so kindly do this for me,pleas tell me the number of samples for each .wav so I can make sure the formula is correct.

http://sinewavemultimedia.com/1wav.wav http://sinewavemultimedia.com/2wav.wav

Here is a problem I have two programs,

One reads the wav data and the other shows the numsamples here is the data

RIFF 'WAVE' (wave file)
        <fmt > (format description)
                PCM format
                2 channel
                44100 frames per sec
                176400 bytes per sec
                4 bytes per frame
                16 bits per sample
        <data> (waveform data - 92252 bytes)

But the other program says NumSamples is

23,063 samples

/*******UPDATE*********/ One more thing I did the calculation with 2 files This one is correct

92,296 bytes and num samples is 23,063` 

But this other one is not coming out correctly it is over 2 megs i just subracted 44 bytes and I doing it wrong here? here is the filesize

2,473,696 bytes 

But the correct numsamples is

 617,400

Answer

Jason Williams picture Jason Williams · May 2, 2011

WAVE format

You must read the fmt header to determine the number of channels and bits per sample, then read the size of the data chunk to determine how many bytes of data are in the audio. Then:

NumSamples = NumBytes / (NumChannels * BitsPerSample / 8)