Jump to content
  • Advertisement
Sign in to follow this  
TheWanderer

DirectSound, DirectMusic, or both for games?

This topic is 4721 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

I'm relatively new to the DirectX API and have been studying it's components so as to include them in a game engine which I am coding. I've recently reached the sound system and had a question about sound. There are two Sound COM Objects in DirectX: DirectSound and DirectMusic. I've read the description on the board and while it gives me an understanding of what they are, it leaves with the question of whether one should implement one, the other, or both for a game. Hmm... likely the answer to this one will be "depends on what you want to do", but to forestall that answer, let me reword the question: What is each object most appropriate for? (i.e. in which situation would you use what?) Thanks for readin' :)

Share this post


Link to post
Share on other sites
Advertisement
In simplest terms, DirectMusic would be most suitable for background music and DirectSound would be used for game sound effects.

According to the SDK docs, DirectSound is better suited for cases where low latency is important. For background music, latency doesn't usually matter, but for sound effects, it would be an issue.

Share this post


Link to post
Share on other sites
Yeah, DirectSound plays sound that is stored in memory, this is good for short sound effects, but playing background music through DirectSound would consume quite a bit of memory.

Share this post


Link to post
Share on other sites
I actually use DirectShow for my background music, but that lags a whole bunch when you switch audio files.

Share this post


Link to post
Share on other sites
I use DirectSound for both.
Quote:
Original post by pichu
Yeah, DirectSound plays sound that is stored in memory, this is good for short sound effects, but playing background music through DirectSound would consume quite a bit of memory.

this is a problem indead. You should NOT load a whole music file into your DirectSound Buffer, only do this for short sounds.
Well how do you solve this then?
Streaming Sound.
The main idea of streaming sound is to load small portions of sound into a part of the buffer while playing a different part, this way, you only have a small portion of your music data in your memory at one time.

I'm not going to fully explain here, because that would require a very big post, but there are articles on the site that explain sound streaming with DirectSound. Here's one
http://www.gamedev.net/reference/articles/article710.asp
I haven't read it yet, but the title sais the right thing ^^

Share this post


Link to post
Share on other sites
The old DX81 SDK had some sample code for streaming as well I think.

Usually I just used DirectMusic for the BGM, and keep the short sound effects to DirectSound.

That way I can have MIDI (or WAV) files or whatever playing in the background..

hth,

Share this post


Link to post
Share on other sites
As of DirectX9 it's quite reasonable to do sound effects in DirectMusic as well: it has good support for loading them and they can be fully scripted. Of course you won't be able to do any low-level manipulation, and I think you forgo using 3D sound if you using DirectMusic for effects.

If you're using pre-recorded music, it's probably easiest just to use DirectSound for everything. If you're using dynamic music, DirectMusic is a fantastic way to do it, and if you're already using DirectMusic for that, it may just be easier to use it for everything.

That said the 2 APIs work seamlessly together, so it's a win-win really.

Share this post


Link to post
Share on other sites
Thanks for the input. I really appreciate it. :)

From the above posts (and what I've read so far), it seems like the true strength of DirectMusic is the ability to play MIDI as well as to create dymaic music. One can always use streaming sounds in DirectSound to play WAV style background music (although a WAV format for music would be quite large :P).

Now, if one where coding up an audio engine, what are some suggestions for integrating both of these API's together?

Share this post


Link to post
Share on other sites
No need for overkill here IMHO. I just made a wrapper object around the CSoundManager and CMusicManager objects from the sdk common framework.
(from the DX81/DX90 SDK)...

I've got two std::map containers which store CSound and CMusic objects to dynamically load any audio data..

that's really about it.

Share this post


Link to post
Share on other sites
I gotcha. Given the similarity between the two API's I was wondering what a nice, clean way of presenting their functionality to the end-user might be.

Out of curiosity, why a map and not a vector?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!