我正在讀取原始音頻文件(CD曲目翻錄),進行字節交換,然後寫回到wav文件。交換文件中的字節
例程我已正確處理字節,但只能處理大約一半的文件。我是一個VB.NET開發人員,不是真正的C#開發人員,並且此代碼不能正確轉換爲VB.NET(它會發生溢出錯誤)。
這不是一個真正的「交換」,而是一個計算/修剪。 (短)((緩衝[I + 1] * 256)+緩衝[1])
我相信這是寫只有一半的樣品,但我不知道如何解決!
public static short[] SwapBytesArray(string fileName)
{
byte[] buffer = System.IO.File.ReadAllBytes(fileName);
long fileLength = buffer.LongLength;
if ((fileLength & 1) == 1)
{
throw new ArgumentException("File length must be an even number of bytes");
}
System.Collections.Generic.List<short> sList = new System.Collections.Generic.List<short>();
for (long i = 0; i < fileLength - 1; i += 2)
{
byte tmp = buffer[i];
sList.Add((short)((buffer[i + 1] * 256) + buffer[i]));
//buffer[i + 1] = tmp;
}
return sList.ToArray();
}
多虧了這個奇妙的一羣人的答案我已經升級上面的來源,但它仍然只處理一半的音頻。 – 2009-05-31 05:30:03