Jump to content
  • Advertisement
Sign in to follow this  
Lucas W

How do you handle FMOD-processing in your game loop?

This topic is 3965 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

Hello all! Since Im not getting any useful answers in the FMOD forum, you're my only hope. Im implementing FMOD into my game Engine, but its not working as it should. The sound is getting blurry, and the return value of system->playSound() is FMOD_ERR_MEMORY (but im only loading 1 mp3 file here). It works well if I do the same in a console application, but when it comes to a window application Im getting the error. At the FMOD forum, they told me:
Quote:
You are running your code in such a tight loop that you are stalling the whole operating system. Put a sleep somewhere in your loop.
Im using FMOD like this inside my gameloop:
//game loop
if(PeekMessage(&msg, 0, 0, 0, PM_REMOVE)
{
   //bla bla
}
else
{
   mInput->Update();
   
   if(mInput->KeyDown(SPACE))
      fmod_system->playSound(FMOD_CHANNEL_FREE, fmod_sound, false, 0);

   fmod_system->update(); //Im guessing that this is causing the OS stalling.
}

But a Sleep() call inside my gameloop would be horrible for the frame rate. So my question to you is: How do you update / play your sound in your gameloop? Some code would be great! Thanks

Share this post


Link to post
Share on other sites
Advertisement
A sleep(0) call should have minimal effect on your frame rate and might get rid of whatever problems you are having.

It's advisable to try suggested fixes before looking for more. :)

In my game I have a sleep(0) call and I'm using FMOD for music and 3D positional audio. We're still hitting 60 FPS no problem.

Share this post


Link to post
Share on other sites
Thanks alot for your reply :)

What do you mean to try suggested fixes before looking for more?
I dont get it :)

I have tried to put a Sleep(50) in my loop, but the sound just gets blurry (no error message tho).

Could you please post some example code to illustrate your gameloop? Thats the best way I learn :)

Thank you

Share this post


Link to post
Share on other sites
else
{
mInput->Update();

if(mInput->KeyDown(SPACE))
fmod_system->playSound(FMOD_CHANNEL_FREE, fmod_sound, false, 0);

fmod_system->update(); //Im guessing that this is causing the OS stalling.
}

Try the following;

Load the sound into a channel in the paused state at app start
fmod_system->playSound(FMOD_CHANNEL_FREE, fmod_sound, true, channel1);

then just update its status instead of reloading.

else
{
mInput->Update();

if(mInput->KeyDown(SPACE))
channel1 ->setPaused(false);

}

fmod_system->update(); //Put this at end of loop


Let me know if this works for i haven't played with sound for around 6 months so i might be wrong.

Share this post


Link to post
Share on other sites
That did the trick :)

If you lived in sweden I would kiss you ^^

I've been on the net for weeks trying to solve this.

Thanks alot

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!