PDA

View Full Version : PlaySound() pauses game problem



20thCenturyBoy
09-22-2004, 11:49 PM
Hi all,

I have written my first game using Win32 and C, the old fashioned way. I know, I must be a masochist. Anyway, I want to add a sound effect when a row is completed (can you guess the genre yet?!). So I use PlaySound() to load the .wav from my resources and play it asynchronously. This works, but the first time it is played there is a noticeable pause in the game as the sound is loaded. It pauses for about one second. After that I guess the sound is cached because it plays quickly. Anyway, how can I fix the pause when the sound is loaded? Is there a way to preload sounds at the beginning of the game, without actually playing them?

If I must use DirectX, can I just use the audio part and nothing else?

Thanks,
20thCB

MirekCz
09-23-2004, 12:45 AM
Don't know exaclty how playsound works, but rather avoid it.

You can use only Dx part responsible for sound/music playback (if you do so, use as old version of dx as possible to avoid possible problems with "you need to install dx9 in order to run this game...")

Another idea is to simply find a simple sound-playback source and use it. Loading Wav's and playing them is pretty straightforward

Ok here's a tutorial with sample code for using both waveout method and dsound to play sound.

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

Generally Waveout is better for you as you don't need dx for it, but for more advance functions (which you don't seem to need atm) you will want to consider dsound.

princec
09-23-2004, 01:07 AM
I'd seriously consider FMOD, BASS or OpenAL to do your sound for you. No headaches, it's all Good Stuff.

Cas :)

20thCenturyBoy
09-23-2004, 05:08 AM
FMOD looks great. $2,000 per title?! :eek:
Phew, there's a hobbyist licence :rolleyes:

princec
09-23-2004, 06:36 AM
I believe there's a cheapass license for shareware devs at $100 isn't there...?

Cas :)

Mark Fassett
09-23-2004, 09:51 AM
Yes - down the page a bit.

patrox
09-23-2004, 10:07 AM
Hi all,

I have written my first game using Win32 and C, the old fashioned way. I know, I must be a masochist. Anyway, I want to add a sound effect when a row is completed (can you guess the genre yet?!). So I use PlaySound() to load the .wav from my resources and play it asynchronously. This works, but the first time it is played there is a noticeable pause in the game as the sound is loaded. It pauses for about one second. After that I guess the sound is cached because it plays quickly. Anyway, how can I fix the pause when the sound is loaded? Is there a way to preload sounds at the beginning of the game, without actually playing them?

If I must use DirectX, can I just use the audio part and nothing else?

Thanks,
20thCB

LockResource on the sound will do it ;)

pat.