Archived

This topic is now archived and is closed to further replies.

Kheteris

Sound & Choppyness

Recommended Posts

Hi, I have a sound file play in my program (an explosion for this game) and whenever I play the sound file the game gets really slow for a few seconds while the sound is playing... why does it do this? And how can I make it so it''s smooth? Here''s the code : if ((keys[VK_TAB]) || (wspeed <= -30) || (wspeed >=30) || ((5.0 >= wspeed >= -5.0) && ( 40 >= w2speed >= 30))) PlaySound("Data/Die.wav", NULL, SND_SYNC);

Share this post


Link to post
Share on other sites
Well, with playsound, you must check your wav file to make sure it is not too big.

Because the entire waveform has to be completely loaded before playback even starts, with large files, this can result in a significant delay before the audio actually starts. An exception to this is using the SND_MEMORY flag described later.


The PlaySound function can''t really be used simultaneously by multiple threads in the same process. It provides no means to arbitrate your threads'' calls to PlaySound(), so unless you do that yourself, results may be unpredictable.


But if you must, try the SND_ASYNC to let the app run in the background while your sound plays.

Hope this helps.

Here is a good link playsound

Share this post


Link to post
Share on other sites
You might want to try using something other than PlaySound() to do your sound effects. PlaySound() is a very slow function, and is not really made for graphics programming but rather applications and such. Take a look at fmod and OpenAL, they support sound functions that are fast enough for your game and will come in handy when trying to play larger sound files (remember, PlaySound has to read/cache the entire sound file before actually playing it, so calling it in the middle of your rendering loop will lag your computer). FMOD is probably your best choice...check out tutorials on it at http://www.gametutorials.com/Tutorials/c++/Cpp_Pg5.htm

Share this post


Link to post
Share on other sites