Sign in to follow this  
x4000

[SlimDX] Best way to stream music?

Recommended Posts

Hi, I'm using SlimDX for my current project, but in the past I've always used DirectShow for music. I've been unhappy with a lot of things about DirectShow, but it was very low latency on playback and very light on memory. In SlimDX, I've put together two solutions, one based on DirectSound and the other based on XAudio2. I have a way of loading ogg files as a stream (using another component), and that works fine and is plenty fast. However, the issue with DirectSound is that I have to load the entirety of the compressed stream into a memory stream, then convert that into a byte array, then pass that into a secondary buffer. This creates a really huge amount of wasted memory, on the order of 60-70 MB for a one or two minute music file (2MB as compressed ogg). It would be really nice if I could just somehow plug my stream into DirectSound in SlimDX, then set how much prebuffering I want it to do. I don't see anything like that in the SlimDX DirectSound classes, though... On the XAudio2 side, the streaming is of course very straightforward, and memory usage is vastly better. It seems like a very efficient solution overall. However, the big problem that I have is latency with this one. In the game, of course sometimes the CPU is very busy, and whenever there is a particularly long game cycle (where the video hitches slightly) the audio also hitches. This is completely unacceptable, especially since it does not hitch at all with DirectSound. I'm running this on a quad core, to boot -- there's plenty of CPU power available, just not on the primary thread at those instants. In DirectSound you can set the priority of the DirectSound processing, but in XAudio2 you don't seem to be able to. In XAudio2 you can set what processor it should run on, but that seems to have no effect. The XAudio2 hitching might also be an IO contention issue, I'm not sure. If that was the case, then I need to be able to set how much prebuffering gets done in XAudio2. From some of the MSDN docs it sounds like that should be possible, but I see no such settings in the SlimDX implementation. I guess all that is handled internally to your library? Any chances of us getting access to it? A solution to the issues with either approach would make me happy, I'm not picky. I basically just need the quality/performance that I'm getting with Directsound, with the memory efficiency / streaming of XAudio2. If there is no solution available, then I guess I'll just have to live with the memory wasted by the DirectSound approach. Any help is much appreciated!

Share this post


Link to post
Share on other sites
Note: On the DirectSound side, if I take out the memory stream (and thus the conversion from that to an array), that save a lot of memory. Of course, then I'm wasting memory because I've got one static array that I use for prebuffering (before creating a secondary Buffer). That array needs to be 50MB in order to handle the largest uncompressed ogg files I'm likely to have. At the very least, it's way easier on the garbage collector, so that's something -- but I'd still prefer something more like what XAudio2 is doing, just without the performance tanking.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this