Win32 Programming: How do I handle sound?

Started by
9 comments, last by Utwo 21 years, 2 months ago
I, of course, want to have sound effects in music in my game. My goal is to complete this game using Win32, and without using DirectX or SDL. I''ve noticed that there is a PlaySound function, but the function doesn''t seem to return until the sound is done playing, therefore stalling my program until it is complete. Additionally, I have no idea how to implement background music in a program that''s continuosly looping. Can anyone push me in the right direction?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Advertisement
Check the manual again. Especially the SND_ASYNC flag.
You might want to try FMod, it''s simple... you can find it at www.fmod.org, it supperts several platforms and is quite easy to use.

Example:

FSOUND_Init(44100,16,0);

FSOUND_SAMPLE *hello=FSOUND_Sample_Load(FSOUND_FREE,"a.wav",FSOUND_LOOP_OFF,0);
FSOUND_PlaySound(FSOUND_FREE,hello);

// do some stuff here...

FSOUND_Close();

The function returns immediately, you don''t have to wait for the sound to end. And it can load MP3s as well, among other file formats. And you can play background music!

So maybe that''s all you need...
Thanks guys!

I haven''t checked the manual, but I supposed "ASYNC" is self-explanatory. Looks like it will help. Would that make PlaySound a valid solution for background music?

Also, Fmode looks incredible. I''d like to take a look at its implementation if possible. :-D
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Double post.

j/k :-p
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Just for background music... you can´t play two sounds simultaneously using playsound.
Gaiomard Dragon-===(UDIC)===-
quote:Original post by Outworlder:
you can´t play two sounds simultaneously using playsound.


Maybe you could try launching a tiny background program that would specifically play background music. I would think that two seperate applications could both call PlaySound() at the same time successfully.

-Mike
Well I''m sure that Microsoft must have forseen that Win32 would be used for game program, and therefore they must have provided a solution for playing background music and sound effects. Or were they THAT myopic?

My goal here is to learn game programming in Win32, as unreasonable as that sounds, and so I don''t want to use any third-party libraries or APIs. I tried looking the functions needed up on MSDN however it doesn''t seemed to be organized that way. I was just wondering if anyone could point me to the names of the functions I would need so that I then can go look them up and research how to use them.
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox
Yeah, I suppose the MSDN can be a little tricky to navigate when you''re not used to it. A quick search reveals this.
Ok, you''re a Godsend. Bless you.

For future reference, what search criteria did you use?
---signature---" Actually, at the time, I didn't give a damn about the FoxNews issue... just that you would come swooping in with your Super Mith cape flapping behind you and debunk it just because it didn't happen in your living room." - InnocuousFox

This topic is closed to new replies.

Advertisement