public static byte[] AudioFloat2Byte(float[] floatData)
{
float[] samples = floatData;
//audio.clip.GetData(samples, 0);
short[] intData = new short[samples.Length];
byte[] byteData = new byte[samples.Length * 2];
int rescaleFactor = 32767;
for (int i = 0; i < samples.Length; i++)
{
intData[i] = (short)(samples[i] * rescaleFactor);
byte[] byteArr = new byte[2];
byteArr = BitConverter.GetBytes(intData[i]);
byteArr.CopyTo(byteData, i * 2);
}
return byteData;
}
附加一个byte[] 分割方法
public List<byte[]> SplitList(byte[] superbyte, int size)
{
List<byte[]> result = new List<byte[]>();
int length = superbyte.Length;
int count = length / size;
int r = length % size;
for (int i = 0; i < count; i++)
{
byte[] newbyte = new byte[size];
newbyte = superbyte.Skip(size * i).Take(size).ToArray();
result.Add(newbyte);
}
if (r != 0)
{
byte[] newbyte = new byte[r];
newbyte = superbyte.Skip(length - r).Take(r).ToArray();
result.Add(newbyte);
}
return result;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)