Finding number of samples in a .wav header

梦想的初衷 提交于 2019-12-10 22:54:05

问题


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.



来源:https://stackoverflow.com/questions/5838093/finding-number-of-samples-in-a-wav-header

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!