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

Started by
3 comments, last by Lucas W 16 years, 2 months ago
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
-----------------------------------------------------I demand more toasties!
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.
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
-----------------------------------------------------I demand more toasties!
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.
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
-----------------------------------------------------I demand more toasties!

This topic is closed to new replies.

Advertisement