I'm trying to set up basic sound in my SlimDX application, and am experimenting with playing music.
I have noted that my current configuration causes the app to crash when the file size exceeds something around 400k. I have tried a number of experiments to identify the problem, but I'm new to Xaudio2 so am a bit lost.
Here is my current method for playing sound:
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();
}
The XAudio2 and MasteringVoice objects are set up as follows (very basic):
soundDevice = new XAudio2();
masteringVoice = new MasteringVoice(soundDevice);
I thought perhaps this was a buffer problem, but since this is derived from the stream (which itself is based on the file), the buffer would be sized correctly surely?
What I'm looking for is a mechanism to play a full high quality MP3, so a limitation of 400k is not really practical.
The crash itself seems to be with XAudio2, with windows reporting:
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
Thanks in advance