Background Music & Sound Effects Performance Problem

I added bgmusic and sound effects to my game. But after adding, my game started to have instant fps drops. To solve the problem, I guess I had to upload music and effects to AppDelegete and call it from there. But I couldn’t figure out how.

  1. show code of what you tried and failed at

  2. show code of what works for you now.

  3. you can surely pre-load music outside of AppDelegate.

My bgmusic code on GameScene.cpp:

CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("Audio/GameMusic.mp3");
CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("Audio/GameMusic.mp3", true);

My sound effect code on GameScene.cpp:

CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Audio/Item.wav");
CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Audio/Impact.wav");
CocosDenshion::SimpleAudioEngine::getInstance()->preloadEffect("Audio/Jump.wav");

and:

bool GameScene::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)
{
    	character->Fly();
    	this->scheduleOnce(schedule_selector(GameScene::StopFlying), CHAR_FLY_DURATION);
    	CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Audio/Jumper.wav");
    	return true;
}

What’s the problem?

Any console errors?

You are pre-loading Audio/Jump.wav but trying to play Audio/Jumper.wav, btw.

Whenever i jump the game freeze just a little.

And you think it is because of playing the sound effect? Simulator or hardware?

Yep. Before i added sounds everything works good.

Simulator or hardware?

Simulator. I’m making this game for windows.

perhaps try mp3.

I tried. Result is the same :confused:

I suffered from similar momentary fps drops when I play audio in Cocos Creator 1.9.3 on Win32. Fps drop dramatically increases if computer was open for a long time. I solved the issue by using mono and short sound effects. I kept sound effects length under 9 seconds it seems fine for me.

I tried your advice, but sadly result is the same :confused:

I think that we need more to go on. I don’t seem to be suffering in this same way. Perhaps post an example that I can download and work with.

@Refetizm If you start a new project, add sounds, and play them, is the issue still present? Basically, create a very simple test case to reproduce this issue, one that you can link in your post, so others can test it out.

Switch to AudioEngine.

I uploaded all my source code to gitHub: https://github.com/Refetizm/Fly-To-Masomo

In the gitHub page there is a link for resources too.

@Refetizm Just had a quick look, and have to ask, why are you setting the animation interval to 240 frames per second?

    // set FPS. the default value is 1.0/60 if you don't call this
    director->setAnimationInterval(1.0f / 240);

Now, knowing that this is the value you’ve set, let’s go back to your first post in this thread. Explain precisely what you mean by “instant fps drops” when you play sound. What exactly are you seeing?

1 Like

I changed fps because i think if i raise fps maybe the fps drop problem could solve but it didn’t work. if you watch gameplay video, you will see the problem. Whenever i pick an item the problem showing itself.

@Refetizm I see what you mean. It’s too bad you don’t have stats on so we could see in the lower left corner.

Would you mind if I downloaded the project and resources and tried to build this on iOS or macOS?