[SlimDX] Simple playback sample

Started by
16 comments, last by Mike.Popoloski 15 years, 9 months ago
Hello! I'm trying to use SlimDX instead of DirectSound because I need to output sounds to 3 stereo channels on a sound card independently but DirectSound doesn't support WAVEFORMATEXTENSIBLE. I tried to reproduce XAudio2BasicSound sample from Microsoft DirectX SDK (March 2008) using DXSlim and C# in VS2005. But the main playback cycle (original Microsoft implementation can be found at XAudio2BasicSound.cpp:186) exits right after the first iteration with no sound played: while (isRunning) { VoiceState state; state = srcVoice.State; isRunning = (state.BuffersQueued > 0); Thread.Sleep(10); } What can be the reason for this? Is there any simple example of using XAudio2 in DXSlim? Thank you!
Advertisement
It's quite possible that there are bugs in XAudio2, as we haven't had a chance to test any of it. I'll try porting a few of the DirectX SDK samples over and see how it goes.
Mike Popoloski | Journal | SlimDX
Thank you for a reply, Mike!

I found a bug in the SlimDX XAudio2 before I was able to run my sample. Actually I don't remember where it's exactly (tested it a month ago just after you mentioned that XAudio2 is almost done). But I rememeber it was an invalid handle release before actual allocation. You'll easily find it trying to reproduce the simpliest example.

It was also a problem to get sound data from a sound file. MS uses an intricate CWaveFile class that is responsible for determening sound file format, bitrate etc and getting exact sound data.

It seems to me that there is neither special function to get sound data from a sound file nor a function to play entire sound file in XAudio2. And this makes it impossible to use managed XAudio2 in SlimDX to play sound files without using some external MS unmanaged code (I mean that awkward CWaveFile).

Thanks again!
Quote:Original post by ThePPK
It seems to me that there is neither special function to get sound data from a sound file nor a function to play entire sound file in XAudio2. And this makes it impossible to use managed XAudio2 in SlimDX to play sound files without using some external MS unmanaged code (I mean that awkward CWaveFile).


Yeah, I just realized that when implementing the sample. I went ahead and ported that CWavFile class from DXUT over to C#, and it's not pretty. The problem is that DX doesn't include media loading functions because Windows already provides a bunch of them. Unfortunately, they are a pain in the neck to use in C#, so I think we are going to end up providing them in the SlimDX library as well. We just need to figure out the best way to incorporate it all.
Mike Popoloski | Journal | SlimDX
Quote:Original post by Mike.Popoloski
Unfortunately, they are a pain in the neck to use in C#, so I think we are going to end up providing them in the SlimDX library as well. We just need to figure out the best way to incorporate it all.


That would be really great to implement them in SlimDX! And it'll make XAudio2 truly managed.
Thank you for an example, Mike!

I updated SlimDX to the trunk and faced some build errors:

1. error C2259: 'SlimDX::XAudio2::VoiceCallbackShim' : cannot instantiate abstract class SlimDX\source\xaudio2\SourceVoice.cpp 89
2. error C2039: 'GlitchesSinceEngineStarted' : is not a member of 'XAUDIO2_PERFORMANCE_DATA' SlimDX\source\xaudio2\PerformanceData.cpp 39

The first error actually appeared 4 times in SourceVoice.cpp on VoiceCallbackShim() constructor calls (lines 44, 59, 74, 89)

Can you suggest how should I correct the errors?

By the way can you please explain how to downgrade project to VS2005?

Thank you!

First, the latest build requires the new June SDK. You can change that back, mostly by following the directions on this page, but as you have seen the DirectX team made some breaking changes, mostly in XAudio2, so you'll have to work around that a bit. I suggest you just update to June, as it contains the latest and greatest in DirectX.

Second, we just got done adding support for downgrading the project to our build system. I don't really understand how it all works; jpetrie and Promit would be the two people to ask. I'll let them know that are looking for more information on the subject. We will mostly likely have a wiki page explaining the process, but like I said it just got finished yesterday, so we haven't had time yet to do so.
Mike Popoloski | Journal | SlimDX
OK, I see! I'm downloading the June SDK now, hope it'll fix all the errors and I'll be able to see the XAudio2 sample that you kindly wrote.

As for the build system I'll wait for the instructions at Wiki page. I tried to build the downgrade project yesterday but without a note I can't understand how it works.

I'm going to test XAudio2 implementation in a couple of days, hope you won't mind my questions.

Thank you very much again!


There is a build script called SlimDX.proj in the build directory of the SlimDX repository. It will generate a 2005 .vcproj file when invoked on the command line with MSBuild ("msbuild SlimDX.proj"). Note that msbuild is not normally in your %PATH% so a regular command prompt window from Start -> Run -> cmd.exe won't cut it; you'll want to use the Visual Studio 2005 Command Prompt from the tools submenu in the VS entry in your start menu.
Quote:Original post by jpetrie
There is a build script called SlimDX.proj in the build directory of the SlimDX repository. It will generate a 2005 .vcproj file when invoked on the command line with MSBuild ("msbuild SlimDX.proj"). Note that msbuild is not normally in your %PATH% so a regular command prompt window from Start -> Run -> cmd.exe won't cut it; you'll want to use the Visual Studio 2005 Command Prompt from the tools submenu in the VS entry in your start menu.


Great, it works! Thank you very much JPetrie!

This topic is closed to new replies.

Advertisement