意思是在C#中的.wav幅度 [英] Mean amplitude of a .wav in C#
本文介绍了意思是在C#中的.wav幅度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有谁知道一种方式来获得使用C#(即使这意味着在调用外部命令行程序和解析输出).wav文件的平均幅度?谢谢!
Does anyone know a way to get the mean amplitude of a .wav file using C# (even if it means calling an outside command line program and parsing the output)? Thanks!
推荐答案
下面是读取立体声WAV并把数据在两个数组剪断。
这是未经检验的,因为我不得不删除一些code(转换为单声道,并计算移动平均)
Here is a snip that reads in a stereo wav and puts the data in two arrays. It's untested because I had to remove some code (converting to mono and calculate a moving average)
/// <summary>
/// Read in wav file and put into Left and right array
/// </summary>
/// <param name="fileName"></param>
private void ReadWavfiles(string fileName)
{
byte[] fa = File.ReadAllBytes(fileName);
int startByte = 0;
// look for data header
{
var x = 0;
while (x < fa.Length)
{
if (fa[x] == 'd' && fa[x + 1] == 'a' &&
fa[x + 2] == 't' && fa[x + 3] == 'a')
{
startByte = x + 8;
break;
}
x++;
}
}
// Split out channels from sample
var sLeft = new short[fa.Length / 4];
var sRight = new short[fa.Length / 4];
{
var x = 0;
var length = fa.Length;
for (int s = startByte; s < length; s = s + 4)
{
sLeft[x] = (short)(fa[s + 1] * 0x100 + fa[s]);
sRight[x] = (short)(fa[s + 3] * 0x100 + fa[s + 2]);
x++;
}
}
// do somthing with the wav data in sLeft and sRight
}
这篇关于意思是在C#中的.wav幅度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文