我正在尝试在SlimDX应用程序中设置基本声音,并正在尝试播放音乐。
我注意到我的当前配置会导致应用在文件大小超过400k左右时崩溃。我已经尝试了一些实验来确定问题,但我是Xaudio2的新手,所以有点迷失。
这是我目前播放声音的方法:
public void PlayPCM(XAudio2 device, string fileName)
{
var fileStream = System.IO.File.OpenRead(fileName);
WaveStream stream = new WaveStream(fileStream);
fileStream.Close(); // Close the file stream
AudioBuffer buffer = new AudioBuffer();
buffer.AudioData = stream; // Set data of object to the stream we created from a file
buffer.AudioBytes = (int)stream.Length; // Set the length based on that same file. AudioBytes is an INT.
buffer.Flags = BufferFlags.EndOfStream;
SourceVoice sourceVoice = new SourceVoice(device, stream.Format);
sourceVoice.SubmitSourceBuffer(buffer);
sourceVoice.Start();
}
XAudio2和MasteringVoice对象的设置如下(非常基本):
soundDevice = new XAudio2();
masteringVoice = new MasteringVoice(soundDevice);
我想也许这是一个缓冲区问题,但是因为这是从流(它本身是基于文件)派生的,所以缓冲区的大小肯定会正确吗?
我正在寻找的是一种播放全高品质MP3的机制,因此400k的限制并不实用。
崩溃本身似乎与XAudio2一起,Windows报告:
Problem signature:
Problem Event Name: APPCRASH
Application Name: BasicWindow_1.exe
Application Version: 1.0.4922.32663
Application Timestamp: 51c739ae
Fault Module Name: XAudio2_7.dll
Fault Module Version: 9.29.1962.0
Fault Module Timestamp: 4c0641e5
Exception Code: c0000005
Exception Offset: 0004f9b3
OS Version: 6.1.7601.2.1.0.768.3
Locale ID: 2057
Additional Information 1: 6407
Additional Information 2: 6407583d8bf58366f2379b7d6ccdbdf7
Additional Information 3: e40a
Additional Information 4: e40a5f9d027c6ccb4d641ab5c450613f
提前致谢