views:

76

answers:

4

Mabye someone over here can explain to me what am i doing wrong...This is after reading a lot of articles over the net and doing what say said over there...and not working....

My problem is that i am developing a nice little game with a background music and explosion sound, for the explosion i know i need to use threads or my music stops when the first one happens, I am using threads but it is stops....

Here is my code....it is very simple, but i guess that there is a mistake over there....

  1. This is the GLOBAL decleration in the *.h file:

    UINT CMonstersThread(LPVOID Param);

  2. This is the thread function in the *.cpp file:

    UINT CMonstersThread(LPVOID Param) { PlaySoundA("sounds\expl06.wav", NULL, SND_ASYNC); AfxEndThread(0); return FALSE; }

  3. This is the call for the thread every time a "friendly" get hit, (in the same *.cpp file):

    AfxBeginThread(CMonstersThread,NULL,THREAD_PRIORITY_NORMAL,0,0,NULL);

That is all my code.....And from what i got over the web, It sould work...but isn't doing what it sould....

10x in advance,

Erez

A: 

You may want to look at using a more full-featured library for your music and sound playing such as irrKang. I am not sure winmm.dll will get you what you need.

0A0D
A: 

The only problem I see in the code that you posted is that CMonstersThread isn't declared as __stdcall.

You say that some other thread has problems, but without seeing the code it's pretty hard to guess what its problems could be.

Windows programmer
It shouldn't be necessary
0A0D
OK, if the destination function calls AfxEndThread then no other component is going to wait for the destination function to clean up the last part of its stack. But watch out if the destination function terminates in any other way.
Windows programmer
I see where you are coming from but based on the information given, I think his problem is a much simpler issue of a Sound API problem.
0A0D
A: 

I would suggest using XAudio2 from the latest DirectX sdk to play your audio. I will take a little more work & code, but the end result will be better because you will be able to load the sound file separately from playing it.

With 'PlaySound' you will notice a lag in the audio if you try to use it right after an event, like a mouse click or a monster dying / explosion and you won't hit this with XAudio2. I know this from experience.

Since you are already using Visual Studio, I also suggest you try using VS 2010 if possible because the [Concurrency Runtime, Parallel Pattern Library and Agents Library]]1 make threading and tasking take a little less code.

There are samples as well at http://code.msdn.com/concrtextras and you may find something useful here as well.

-Rick

Rick
A: 

I don't think it is possible to play multiple sounds in parallel using any of the Windows functions like PlaySound or sndPlaySound. As was already suggested, you might want to look at DirectSound or similar APIs.

humbagumba