是否可以使用 DirectSound 的托管版本向后读取声音?
如果没有,是否有另一个库可以轻松实现?
您可以使用 WaveFileReader 和 WaveFileWriter 类NAudio http://www.codeplex.com/naudio反转 WAV 文件。您需要确保使用 WaveFormat 的 BlockAlign 属性来读取单个样本的所有字节(对于立体声 16 位音频为 4)。
public static void ReverseWaveFile(string inputFile, string outputFile)
{
using (WaveFileReader reader = new WaveFileReader(inputFile))
{
int blockAlign = reader.WaveFormat.BlockAlign;
using (WaveFileWriter writer = new WaveFileWriter(outputFile, reader.WaveFormat))
{
byte[] buffer = new byte[blockAlign];
long samples = reader.Length / blockAlign;
for (long sample = samples - 1; sample >= 0; sample--)
{
reader.Position = sample * blockAlign;
reader.Read(buffer, 0, blockAlign);
writer.WriteData(buffer, 0, blockAlign);
}
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)