PlaySound() question

Started by
5 comments, last by CrystalClear 19 years, 6 months ago
I'm reading a book on the subject. Nothing talks about playing two sounds at once. Like my duck hunt game, I can shoot the duck, but i can't reload my gun til after the gun shoots. It makes sense, but anyway, my question is lost now. I just need it to play two sounds at once instead of one finishing, then allow another to be played. DirectX is later in the book so I'm just wondering if its possible with PlaySound().
Advertisement
its been a while but i think there is an ASYNC option in the playsound() function.

EDIT: a quick google says SND_ASYNC is the flag.
FTA, my 2D futuristic action MMORPG
It's already in PlaySound() and it hasn't done anything to correct the problem.
well, if anything, you cold edit the sound in some sound editing program (audacity or something), and make it so the shooting sound file has a gun firing with a reloading sound following it.. that way you just play one sound and it does what you want...
---Current project - Duck Hunt 2: Free at Last!http://www.duckhunt2.cjb.net
PlaySound doesn't do any mixing of samples. It will play whatever sounds you throw at it concurrently. To play more than one sound at once you will need to mix the waveforms in real-time (or play them on different channels -- most sound cards have multiple channels nowadays). However to do this you'll have to use a lower level API like the MCI waveform API or the DirectSound API.

Here's an introduction to using PlaySound (it also describes its limitations).

cheers
sam


Yeah, PlaySound() is nice for something like a Tetris clone (without music!), but it has little use elsewhere.

The only time you can get away with using it is for very simple games that you will only be playing one sound (or maybe two, but you will notice the overlap) at a time.

-Greven
Use FMOD, something like this

FSOUND_SAMPLE *Sound_To_Play_1 = NULL;
FSOUND_SAMPLE *Sound_To_Play_2 = NULL;
FSOUND_SAMPLE *Sound_To_Play_3 = NULL;

bool Play_Sound(long Channel, int Sound, int Mode, int Loaded) // We play a sound
{

if (Sound==EXTRA_COIN)
{
// Sound to play
Sound_To_Play_1 = FSOUND_Sample_Load(2,"data/sounds/coin.mp3",FSOUND_STEREO, 0);
// We play the sound
FSOUND_PlaySound(Channel,Sound_To_Play_1);
}

if (Sound==EXTRA_NONE)
{
// Sound to play
Sound_To_Play_2 = FSOUND_Sample_Load(2,"data/sounds/chinese.mp3",FSOUND_STEREO, 0);
// We play the sound
FSOUND_PlaySound(Channel,Sound_To_Play_2);
}

if (Sound==EXTRA_KEY)
{
// Sound to play
Sound_To_Play_3 = FSOUND_Sample_Load(2,"data/sounds/key.mp3",FSOUND_STEREO, 0);
// We play the sound
FSOUND_PlaySound(Channel,Sound_To_Play_3);
}

return true;

}

This topic is closed to new replies.

Advertisement