media.playSound() is not optimized for 60fps performance (lags game)

This is on an iPhone 3G, running at 60fps via the config file.

I have been dealing with a drop in FPS that has taken me a very long time to figure out.

After commenting out tons of code to see what the problem was, I commented out media.playSound(…) and ran it on my device.

Finally, I have a reasonably constant FPS… but with no background music.

I preload the music with:
media.playSound(“bob.mp3”) --bob.mp3 is a 64kbit rate, 22hz sound file
media.stopSound()

and then later play it via

media.playSound()

Since its the only sound loaded, playSound starts that one song.

While the music is playing, I get around 55 fps on the iPhone. It is not terrible, but it lags the game a bit and creates a presentation that I am not comfortable with.

Without the music, fps is 59-60 fps, and the game runs smoothly with no frame drops.

I dont know of a way around this. 30 fps and music seems work ok, but 60fps looks to be too fast for Corona’s media player.

Suggestions? [import]uid: 8541 topic_id: 2752 reply_id: 302752[/import]

Just dropping ideas…but:

Tried with a .caf file instead of a MP3 one?
If you insist on using mp3 files, is the mp3 mono or stereo?

nexx
[import]uid: 4572 topic_id: 2752 reply_id: 8316[/import]

Oh, actually, I did not think about trying a different sound file format. I dont really care what format it is, I just want to be able to play with no lag, so I will gladly go with .caf.

I converted the mp3 to mono, thinking it would help, but it did not.

What sound format is the fastest format to play, without lag?

What other formats are available to media.playSound()?

[import]uid: 8541 topic_id: 2752 reply_id: 8319[/import]

I think the slowdown is because it has to uncompress the sound file (MP3) while playing. The media.playSound API supports, AIF, AAC, and CAF formats along with MP3. The key is saving the file as an uncompressed sound file.

-Tom [import]uid: 7559 topic_id: 2752 reply_id: 8643[/import]

Ive read that if you convert a mp3 as a .aiff in iTunes, and then change the extension to .caf, that works just as well.

Anyway, I have been using a .caf file, which has been afconvert’ed from my reduced .mp3 file.

It absolutely makes a difference in performance. So thank you both for mentioning this!

The media.playSound() docs might need to be touched up with the above blurb about supported formats, and that using .mp3 can cause a performance hit.

Question though, out of AIF, CAF, and AAC, which is the faster file format… ie, which one has the least performance hit on Corona’s sound api?

Thanks again!
[import]uid: 8541 topic_id: 2752 reply_id: 8671[/import]