Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Koobazaur

Win32: Playing sounds without a delay ???

This topic is 5175 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''ve been working on a simple pong clone lately and wanted to make it play a "bounce" sound whenever the ball bounces off a pad. I use MCI to play sounds (mciSendCommand MCI_OPEN, MCI_PLAY, MCI_CLOSE etc...) . But I soon noticed that whenever my ball hit the pad, it would appear to stick to it, be jumpy or choppy. The animation smoothed out when I removed the play sound function... appearantly, sending the play command slowed my program down, making the animations look choppy and poor... so, what''s a good alternative way of playing sounds quickly and efficiently?

Share this post


Link to post
Share on other sites
Advertisement
i dunno about the MCI system that you''re using, but openAL is incrediably easy to setup and use. I haven''t ever noticed any delays with animations or sound playing in that system.

-me

Share this post


Link to post
Share on other sites
I don''t know much about MCI either, but it seems like it''s a pretty poor choice for in-game use (judging from your description of how it performs). You might want to give DirectSound a try, or some other API.

Share this post


Link to post
Share on other sites
Are you specifying your sound to sync with the program? You want it to be asynchronus.

When you play the sound synchronously, it stops your program until the sound is done. If you play it asynchronusly, the sound goes ''in the background'' and continues to run the app while its being played.

Could be a source of your problem.

Share this post


Link to post
Share on other sites
I think all you need to include is windows.h and possibly link with winmm.lib

PlaySound("bounce.wav", NULL, SND_ASYNC|SND_NODEFAULT);

Edit:

I used that function to play the sound fx in a pong game that I made and there is no lag

[edited by - eFoDay on March 23, 2004 10:41:41 PM]

Share this post


Link to post
Share on other sites
The problem is that somehow he needs to preload the sound. Windows is loading it in the play command, and as you can imagine, that''s not exactly fast.

I don''t know how to preload stuff like that, unfortunately

Share this post


Link to post
Share on other sites
MCI is very, very sluggish. It''s not the right choice for an interactive, asynchronous sound player.

PlaySound is also not really that great.

I suggest using an API that lets you pre-load the sounds to play, and then trigger them. OpenAL is one such library; DirectSound is another; FMOD, BASS, and a phletora of others also exist.

The ideal API should have entry points to:

1) initialize the sound system (say what sample rate to use, etc)

2) pre-load a sound and give you some kind of handle to it

3) start playing a sound, given a pre-loaded handle

4) unload a sound handle when you will no longer need it (which is when you quit the program)

That''s really it. More than that isn''t really necessary, and probably just complicates things. If you''re OK with the whole COM/DirectX thing, I suggest DirectSound (use static buffers for effects); else use OpenAL.

Share this post


Link to post
Share on other sites
quote:
Original post by Koobazaur
Thanks for all the replies! :D

I''ll go with OpenAL cause I''m not using DirectX, just win32 (GDI and stuff)...


If this is your first game, and it''s not really for commercial use, then might I suggest trying the PlaySound() function suggested above, before trying OpenAL? I never had a problem with PlaySound() with simple games like this before.

Obviously, learning OpenAL would be a good thing, but maybe concentrate solely on GDI and everything that comes with it first, before learning external libraries?

Just a thought.

-hellz

Share this post


Link to post
Share on other sites

  • 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!