Jump to content
  • Advertisement
Sign in to follow this  
sqpat

Directsound multichannelling performance?

This topic is 3786 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive got an ogg player i got from elsewhere running fine (well, mostly) in my little app, utilizing directsound. I plan on also adding .wav based sound effects, implementing 3d sound, and potentially having many playing at the same time. Ive never worked with direct sound; do i have to have a different sound device enumerated for every wav that is playing? Is there a typical maximum number of sound channels supported? Can this hit like double digits or should I be capping it at a certain amount? Does multichanneling give a really big performance hit or does a typical sound card handle most of it? I'm in the process of looking at some wav and 3d sound tutorials but i find no mention of a lot of this multichanneling stuff. Would appreciate a response, thank you!

Share this post


Link to post
Share on other sites
Advertisement
I think most games handle it by having a fixed number of channels, set by user before game starts (like 8, 16, 32, 64, etc).

In my game, I have an unlimited number of channels. So far I have not experienced any performance problems with this approach. However, when several sounds play at the same time, flaws in the sounds themselves start "coming out". I don't know how to explain this, but if one of your sounds has a really tiny noise on the background, and you play several overlapping instances of that sound, perhaps overlaid with other sounds, suddenly the noise gets multiplied many times over, and turns into something really noticeable. Sometimes when you try to start multiple sounds close to each other on time line, you may also hear popping (I guess because of latency).

I know that many sound cards today don't even support hardware buffers, so the mixing of those multiple channels in done on the CPU, then the mixed stream is sent to the video card. Which means you will be physically limited in the number of channels by the CPU rather than the sound card hardware.

Anyways, to play several different sounds at once, you simply call Play() method of the IDirectSoundBuffer8 for each sound. To play the same sound multiple times at the same time, you have to Duplicate() IDirectSoundBuffer8 for each new instance (except for the very first instance, in which case you Play() the original buffer). This doesn't actually copy memory, only makes a "reference" to the original memory. Then you just call Play() for each of those duplicated sound buffers. You will also need to detect when those duplicated instances stop playing, so you can Release() them.

If you are using software sound, use buffer notifications. If you are using hardware sound, buffer notifications are not guaranteed to work (and in fact, probably won't) - so you have to use a different mechanism to figure out when sounds should stop playing. I, for example, conservatively approximate the length of time sound will be playing when I load the WAV file. I take the size of all the WAV samples, and use information about the number of channels, sample rate, and size of each sample, to calculate a floating point number of how many seconds the sound should play. When I create another instance of the sound, I save the time when it started in the instance data, and add the instance to a list. On each engine tick, I loop through the list and check if any of the instances were supposed to stop playing. If so, I remove them from the list. If you were using a fixed number of channels, you would use a [semi]fixed array.

Share this post


Link to post
Share on other sites
thanks a lot. Sounds like its not as bad as i thought. im actually taking a look at this tutorial:

http://www.gamedev.net/reference/articles/article1881.asp

it uses directmusic, but it does make the system look very easy to use.

Share this post


Link to post
Share on other sites
okay this is kind of related and i didnt want to clutter the board up with another topic..


edit!: okay, actually the original version doesnt work either. it still bugs out at the same point (the performance download.) I hear directmusic is deprecated so i'm gonna scrap that whole thing! argh! Oh well :)

[Edited by - sqpat on July 30, 2008 10:56:39 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!