Search code examples
c#debuggingaudiodirectsound

Why wont DirectSound Buffer play under debug conditions?


My wave won't play under debug. If I hit CTRL+F5 I get a nice WAV and the Console writes out the file cursor position (buf.PlayPosition) and then the method exits when the sound is over. Under debug (when I just hit F5) there is no audio output, however the file cursor position is still increased in the console window and the method exits without exception.

using Microsoft.DirectX.DirectSound;

public void Play()
    {
        var fileName = "bass.wav";
        using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
        {       
            using (var dev = new Device())
            {
                dev.SetCooperativeLevel(this, CooperativeLevel.Priority);
                using (Buffer buf = new Buffer(stream, dev))
                {
                    buf.Volume = 0;
                    buf.Play(0, BufferPlayFlags.Default);
                    while (buf.Status.Playing)
                    {
                        System.Console.WriteLine("playing " + buf.PlayPosition);
                    }
                }
            }
        }
    }

Any ideas?


Solution

  • I disabled the Visual Studio Hosting Process and this seems to have fixed the problem.