我只想在我的通用应用程序中以随机音高播放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();
}
我不得不切换这些
sourceVoice.SubmitSourceBuffer(buffer, stream.DecodedPacketsInfo);
sourceVoice.SetFrequencyRatio(200.0f);