private static void PlayWithoutStreaming(IWaveSource waveSource) { using (var xaudio2 = XAudio2.CreateXAudio2()) using (var masteringVoice = xaudio2.CreateMasteringVoice()) //ALWAYS create at least one masteringVoice. using (var sourceVoice = xaudio2.CreateSourceVoice(waveSource.WaveFormat)) { var buffer = waveSource.ToByteArray(); using (var sourceBuffer = new XAudio2Buffer(buffer.Length)) { using (var stream = sourceBuffer.GetStream()) { stream.Write(buffer, 0, buffer.Length); } sourceVoice.SubmitSourceBuffer(sourceBuffer); } sourceVoice.Start(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); sourceVoice.Stop(); } }
private static void PlayWithoutStreaming(IWaveSource waveSource) { using (var xaudio2 = XAudio2.CreateXAudio2()) using (var masteringVoice = xaudio2.CreateMasteringVoice()) //ALWAYS create at least one masteringVoice. using (var sourceVoice = xaudio2.CreateSourceVoice(waveSource.WaveFormat)) { var buffer = waveSource.ToByteArray(); using (var sourceBuffer = new XAudio2Buffer(buffer.Length)) { using (var stream = sourceBuffer.GetStream()) { stream.Write(buffer, 0, buffer.Length); } sourceVoice.SubmitSourceBuffer(sourceBuffer); } sourceVoice.Start(); Console.WriteLine("Press any key to exit."); Console.ReadKey(); sourceVoice.Stop(); } }