Archived

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

Koobazaur

Win32: Playing sounds without a delay ???

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
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
quote:
Original post by Koobazaur
Well, yeah, I thought about finishing my game just as it is and looking at OpenAL later...


I think that would be best. It''s always handy to know when you should be using GDI or external libraries. Can''t hurt anyway.

-hellz

Share this post


Link to post
Share on other sites
quote:
Original post by hellz
I think that would be best. It''s always handy to know when you should be using GDI or external libraries. Can''t hurt anyway.



at the same time, openAL takes maybe 1-2 days to download, install, configure AND put into your game. i.e. it''s the easiest thing in the world as far as APIs go. while doing so you instantly get all the benifits of a robust audio library. i dunno, i guess i''m saying whatever floats your boat and just pointing out that putting openAL into a game isn''t really a chore like implementing some other APIs can be.

i have no idea why i''m suddenly this big openAL proselytizer, but there you go.

-me

Share this post


Link to post
Share on other sites
quote:
Original post by Palidine
quote:
Original post by hellz
I think that would be best. It''s always handy to know when you should be using GDI or external libraries. Can''t hurt anyway.



at the same time, openAL takes maybe 1-2 days to download, install, configure AND put into your game. i.e. it''s the easiest thing in the world as far as APIs go. while doing so you instantly get all the benifits of a robust audio library. i dunno, i guess i''m saying whatever floats your boat and just pointing out that putting openAL into a game isn''t really a chore like implementing some other APIs can be.

i have no idea why i''m suddenly this big openAL proselytizer, but there you go.

-me




That is very true, but when you''re first learning win32 and you''re having to remember everything from what each member in a WNDCLASSEX struct does and all of the relevant flags for those data members, to what a message handler is, I think it''s definitely best not to over-complicate things and start throwing in other APIs and such.

Sure, once you''ve got those things down then by all means check out other libraries, but learning too much at once isn''t always a great idea.

That''s my take on it anyway. Guess we''ll have to agree to disagree.

Glad PlaySound() worked, Koobazaur; had a feeling it might.

-hellz

Share this post


Link to post
Share on other sites
Quick question:
If I were to implement DirectSound into one of my programs, I just need to add in the stuff for sound, correct? I shouldn't have to deal with anything non sound related? (just wondering)

Also, do the mcdoogles (tech language) that implement/create/etc sound automaticly thread the sound? Or if I made a background music would I have to do something special?

[edited by - RyoxSinfar on March 25, 2004 11:28:22 AM]

Share this post


Link to post
Share on other sites