本文介绍了落后的阅读声音的DirectSound的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
时,才可以使用的DirectSound的托管版本落后读取声音?
如果不是有另一种库,允许使它容易吗?
Is it possible to read a sound backward with the managed version of DirectSound?If not is there another library allowing to make it easily?
推荐答案
You can use the WaveFileReader and WaveFileWriter classes from NAudio to reverse a WAV file. You need to make sure you use the BlockAlign property of the WaveFormat to read all the bytes for a single sample (4 for stereo 16 bit audio).
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);
}
}
}
}
这篇关于落后的阅读声音的DirectSound的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!