我想以秒为单位计算wave PCM文件的持续时间,用C#发现这个描述wave文件头的https://ccrma.stanford.edu/courses/422/projects/WaveFormat/链接我使用了这个但是这个方法不会返回正确的答案
public static int GetDuration(this byte[] waveFile)
{
int bitRate = BitConverter.ToInt32(waveFile, 28) * 8;
int sampleRate = BitConverter.ToInt32(waveFile, 24);
int headerSize = 36;
short channels = BitConverter.ToInt16(waveFile, 22);
return ((waveFile.Length - headerSize) / (sampleRate * (bitRate / 8))) / channels;
}
答案 0 :(得分:1)
应该有一个32位数字,其中包含偏移量0x1C
每秒的平均字节数。只需将file - 0x2C
的长度除以average bytes per second
即可。看看这个:http://s14.directupload.net/images/140428/7suewylj.png(来自维基百科)。
此方法适用于大多数波形文件。