AVAudioPlayer - Drop in Framerate

I have a quick question: I upload an mp3 file to an NSData object and then play it using AVAudioPlayer in my game. Every second, the frame rate drops, and you can see the stutter on the screen. This is not a serious slowdown, but obviously a noticeable violation of the gameplay. Not playing a music track using AVAudioPlayer does not slow down.

How can I prevent this?

Thanks.

Florian

+3
source share
2 answers

For future reference, here is a solution:

Setting the audio session category to kAudioSessionCategory_AmbientSound (to play iPod music at the same time) somehow disables MP3 hardware acceleration. Setting the audio category to kAudioSessionCategory_SoloAmbientSound fixes this, but does not allow iPod playback. Now I set the audio session category depending on whether background music is turned on or off to allow iPod to play simultaneously.

+7
source

MP3 is an encoded / compressed audio format. You can either try to reduce the sampling rate (for istance, and instead of 128 kbit / s try 64 kbit / s) or switch to an unencrypted format such as linear pcm. Disadvantages: poor sound quality in the former case, higher file size in the latter. But it can help improve the overall performance of your application.

0
source

All Articles