Jump to content
  • Advertisement
Sign in to follow this  
phil05

PlaySound() question

This topic is 5389 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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().

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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;

}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!