0

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

CdrTomalak
  • 479
  • 1
  • 4
  • 15
  • 1
    Can't reproduce that crash here with a wav file much much larger than 400k on Windows 7 and x64. I happen to be using vb.net. You can pass the path of a sound file to the constructor of wavestream, does this help? – RobS Jun 24 '13 at 10:36
  • Interesting - thanks for running the test! I'll give your suggestion a go. Do you know what the sample and bit rates were for your wav file - just so I can match it up? – CdrTomalak Jun 25 '13 at 07:47
  • 1
    I've tested with a 3mb wav file at 48k sampling rate, 1536kbps. – RobS Jun 26 '13 at 08:28
  • I experimented with various sample rates - couldn't fix it. Decided to whack in NAudio and got music playing in 20 minutes. Nice library that. – CdrTomalak Jun 27 '13 at 20:43

0 Answers0