Hello everyone. I'm writing a game for iphone, and without background music it runs smoothly at 30 fps. But if I add music (using AudioQueues or AVAudioPlayer, both give similar effect), framerate periodically drops to 10 (about once per second), and then returns to 30. Music is mp3@128kps, 44kHz. It degrades performance not constantly, but at certain moments in time, which causes very jerky gameplay. Did anyone meet such problem? Is there any way to make cpu load for mp3 decoding/playing back more uniform? I'd rather have constanly 29 fps than 30 fps most of the time, and 10 once per second.
You need to profile your app.
I'm getting 60fps regardless of bitrate.
Maybe you could increase the priority of your rendering thread? Or take it into a different Run Loop (if that is how you're doing animation).
It would be best if you showed us your code. Have you checked into the audio buffer options, it might not be optimal for what you need. Are you comfortable with audio Units?
Couple of thoughts:
1) It might be work trying converting your files into another format and see if you still have this issue. I have had great success with using CAF files, just run afconvert over them.
afconvert -f caff -d ima4 <your mp3 file>
2) Also, is there any connection between the slowdown and track changes? I have often seen similar things when changing tracks (or restarting tracks). I think it has to do with the load it takes to read the file from 'disk'.
This is most probably caused by using the AmbientSound
audio session category, see this question. You can easily solve the problem by switching to the SoloAmbientSound
category.