[SlimDX] Best way to stream music?
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!
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.
We're looking into this. Forum threads are difficult to keep track of, so I've opened an issue on our issue tracker here. You can subscribe to that issue to receive updates whenever we make progress.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement