views:

839

answers:

2

Hi.

I have a quick question: I am loading a mp3 file into a NSData object and then I play it using the AVAudioPlayer in my game. Every second or so, the frame rate drops and you can see a stuttering on the screen. It is not a major slowdown, but clearly noticeable and disrupting to the gameplay. Not playing the music track with the AVAudioPlayer shows no slow down at all.

How can I prevent this from happening?

Thank you.

Florian

A: 

The mp3 is an encoded/compressed audio format. You can try either to reduce the sampling rate (for istance, instead of 128 kb/s try 64 kb/s) or switch to a non encoded format such as linear pcm. The cons are: lower audio quality in the former case, higher file size in the latter. But this can help improve the overall performances of your app.

unforgiven
+5  A: 

For future reference, here is the solution:

Setting the audio session category to kAudioSessionCategory_AmbientSound (to allow for iPod music to play simultaneously) somehow disables MP3 hardware acceleration. Setting the audio category to kAudioSessionCategory_SoloAmbientSound fixes this, but doesn't allow for iPod playback. I do now set the audio session category depending on whether background music is enabled or disabled to allow for simultaneous iPod playback.

FlorianZ