我想要做的就是在我的通用应用程序中随机播放WAV。如果有更直接的方法来做到这一点,需要SharpDX告诉我!
private void PlayTone(float randomPitch)
{
var xAudio = new XAudio2();
var masteringVoice = new MasteringVoice(xAudio);
var nativeFileStream = new NativeFileStream("Assets/440tone2.wav", NativeFileMode.Open, NativeFileAccess.Read, NativeFileShare.Read);
var stream = new SoundStream(nativeFileStream);
var waveFormat = stream.Format;
var buffer = new AudioBuffer
{
Stream = stream.ToDataStream(),
AudioBytes = (int)stream.Length,
Flags = BufferFlags.EndOfStream
};
var sourceVoice = new SourceVoice(xAudio, waveFormat, true);
sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
// sourceVoice.SetFrequencyRatio(200.0f);
sourceVoice.Start();
}
答案 0 :(得分:0)
我不得不切换这些
sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
sourceVoice.SetFrequencyRatio(200.0f);