iDevGames Forums
Ambient Music in my app kills performance - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: Ambient Music in my app kills performance (/thread-901.html)



Ambient Music in my app kills performance - AdrianM - Aug 5, 2009 05:42 AM

I have enabled in my little game ambient music(the currently playing music from the iphone library) but i am experiencing some rather hard performance hits. Is optimizing my game the only thing to do?


Ambient Music in my app kills performance - smasher - Aug 5, 2009 12:22 PM

AdrianM Wrote:I have enabled in my little game ambient music(the currently playing music from the iphone library) but i am experiencing some rather hard performance hits. Is optimizing my game the only thing to do?

I noticed that in 3.0, using AVAudioPlayer to play an mp3 with the ambient sound profile causes a big performance hit - apparently it causes AVAudioPlayer to do software decoding instead of hardware. This didn't happen in 2.2.

My solution was to check if music was already playing on startup - if it is, I use the ambient sound category and mute my music (no slowdown.)

If no music is playing, I set the ambientSolo sound category - now my AVAudioPlayer uses hardware decoding, causing no slowdown.

The only flaw is that if someone manages to start their audio AFTER my game is started, all of my audio is silenced. Have not licked that problem.


Ambient Music in my app kills performance - AdrianM - Aug 5, 2009 03:43 PM

smasher Wrote:I noticed that in 3.0, using AVAudioPlayer to play an mp3 with the ambient sound profile causes a big performance hit - apparently it causes AVAudioPlayer to do software decoding instead of hardware. This didn't happen in 2.2.

My solution was to check if music was already playing on startup - if it is, I use the ambient sound category and mute my music (no slowdown.)

If no music is playing, I set the ambientSolo sound category - now my AVAudioPlayer uses hardware decoding, causing no slowdown.

The only flaw is that if someone manages to start their audio AFTER my game is started, all of my audio is silenced. Have not licked that problem.

Sounds interesting, but how do you check if music is already playing?


Ambient Music in my app kills performance - AnotherJake - Aug 5, 2009 06:13 PM

AdrianM Wrote:Sounds interesting, but how do you check if music is already playing?

http://www.idevgames.com/forum/showthread.php?t=16048


Ambient Music in my app kills performance - Newbrof - Aug 7, 2009 01:56 PM

I used this, but my performance is still low:

AudioSessionInitialize ( NULL, NULL,NULL,NULL);

AudioSessionSetActive (true);

UInt32 sessionCategory = kAudioSessionCategory_SoloAmbientSound;

AudioSessionSetProperty ( kAudioSessionProperty_AudioCategory,
sizeof (sessionCategory),
&sessionCategory );

is this even relevant for AVAudioPlayer?

thanks,


Ambient Music in my app kills performance - AnotherJake - Aug 7, 2009 04:56 PM

Newbrof Wrote:is this even relevant for AVAudioPlayer?

Yes, it most definitely is. One of the main issues with iPhone is which compressed audio stream gets to use the built-in audio decompression hardware. Only one stereo track may be using the hardware at any given time. I've tried testing that and got an extremely slow running game, and sometimes the device would lock up.


Ambient Music in my app kills performance - smasher - Aug 11, 2009 07:12 PM

Newbrof Wrote:I used this, but my performance is still low:
AudioSessionInitialize ( NULL, NULL,NULL,NULL);
AudioSessionSetActive (true);
etc etc etc

That's the ticket, but you need to do it before you start any audio, of course.

You should comment out your AVAudioPlayer and test for the slowdown - if it still happens with no AVAudioPlayer alloc'd, then your performance problem is elsewhere. If it only happens with the music playing, the session category may be the answer.


Ambient Music in my app kills performance - Newbrof - Aug 12, 2009 07:23 AM

smasher Wrote:That's the ticket, but you need to do it before you start any audio, of course.

You should comment out your AVAudioPlayer and test for the slowdown - if it still happens with no AVAudioPlayer alloc'd, then your performance problem is elsewhere. If it only happens with the music playing, the session category may be the answer.

yes, with no AVAudioPlayer I get my FPS solid at whatever I have set my NSTimer. With AVAudioplayer I get permanent FPS drop to 40

In a different thread we found out that it is related to MP3 decoding... even with ambient solo category, I occassionaly get permanet 40 FPS (it looks like software decoding is used). Usually I get 40 FPS when I switch one MP3 song to the next MP3 song. Even if I unload/deallocate AVAudioplayer completely.

So, now I use uncompressed WAV files (16 bit Midi-Sound is OK)...

am I the only one who is using OS 3.0 and MP3s for background music? Somebody else should have noticed FPS drops... or maybe everybody else is OK with 40 FPS?

my game looks a bit sluggish when moving with 40 FPS

cheers


Ambient Music in my app kills performance - wonza - Dec 8, 2009 03:50 AM

I'm also having a problem with mp3's affecting performance. I'm using the code here http://www.idevgames.com/forum/showthread.php?t=16048 to see if the sound is playing first and if its not then I activate my music (4Mb, about 4mins duration). If music is playing already my music doesnt play and performance is fine, so I know that its checking correctly.

I'm getting a smooth framerate for about 90% of each second, then it slows right down for the last 10%. This continues on each second. I've tried lower the quality, which helped slightly. I also uncompressed it to WAV and had no performance issues, but that makes the track about 39Mb.

Any ideas?


Ambient Music in my app kills performance - AnotherJake - Dec 8, 2009 08:33 AM

If you're running 3.x, Apple changed the way things work a little bit which turns off hardware decoding when using kAudioSessionCategory_AmbientSound. You'll probably want to use kAudioSessionCategory_SoloAmbientSound (notice the addition of "Solo") to get hardware decoding enabled again. I'll go change my post in that thread for 3.x.

[edit] ... just noticed smasher already mentioned this above ...


Ambient Music in my app kills performance - wonza - Dec 8, 2009 10:10 AM

Awesome, that worked a treat, thanks!