Question about optimizing audio streams

Started by
1 comment, last by xelanoimis 16 years, 1 month ago
Hello, I have a question about how to optimze streaming in an audio lib. I have my own audio lib (build on DirectSound) and I have support for streaming sound/music (wav, ogg, mod, ym, etc). In my current implementation, each stream creates and manages it's own thread, used to push data in the audio double buffer, when needed. I was wondering if it's a better idea to have only one thread (except the main thread), created when the audio lib is initialized, and use it to check all playing streams. And if user wants to avoid threads, to have no thread at all, and call explicite some AudioUpdateStreams() (supposing the fps can handle it). I have some issues with creating and destroying threads, for example when the music changes during gameplay, and I want to optimize it. The playing stream has to be stopped and distroyed . Waiting for the thread to end, might create a small glitch on some computers (possibly because single processor). I tricked that, puting the stream in a 'garbage can' and delete it later, but the creation of an additional thread (the third one at that moment) might cause small delays in frame. I think I'll try and see how it goes with a single audio stream, but if anyone has experience with this practice, let me know. Thanks! Alex
Advertisement
You should only have one thread manage all your streaming sound sources. If you create a thread for each sound source you will swamp the system with context switches (especially a single core system). Also, make sure you put some appropriate thread-wait procedure in place. I've found you can get a pretty big performance bump in a multi-core system by not just having threads sit around and spin.
-----------------------------------Indium Studios, Inc.
Thanks, I guessed that's the way to do it, but I just wanted to be sure.

This topic is closed to new replies.

Advertisement