Performance drops drastically playing multiple MP3 stream audio files

I have an application that consists of a series of pages. Each page plays a background sound, narration and various sound effects. All of them are MP3. I’m loading the narration using [lua]audio.loadStream[/lua] and the rest with [lua]audio.loadSound[/lua]. When I run the app in the simulator, the first page works perfectly fine. The moment I move forward to the next page, I stop and destroy all the sounds from the first page, and load the sounds for the second page. Performance drops to the floor soon after that. Sounds are very choppy and everything comes down to a crawl.

At some point in the past this worked just fine. Somewhere in the last few months this broke with a combination of Mac OS and Corona updates.

Could someone shed some light into the issue? Can I have multiple MP3 sounds playing at once? Any ideas?

Cheers. [import]uid: 79443 topic_id: 30081 reply_id: 330081[/import]

You can have up to 32 sounds playing at once. It is best to pre-load all of your sound files at the beginning of your application. [import]uid: 75779 topic_id: 30081 reply_id: 120488[/import]

While rmckee282002 is correct, MP3s are special.

The MP3 format is a compressed file, so it takes processing time to read it from disc. iOS has a special chip on it, so it can use separate hardware to decode the MP3 into a proper format to relay to the audio drivers, not taking up any time on the main CPU. The problem is that the chip can only work on one file at a time. When that chip is busy, you end up having to take up regular CPU time to decode that MP3, which is going to slow you down. This makes the first MP3 virtually free, compared to uncompressed formats, but 2 or more MP3s have a significant effect on performance.

If you want to avoid processing time, you can use .WAV files, which are uncompressed. The downside is that they are monstrous memory/disc space hogs. It’s common practice to have 1 main MP3 track streaming that is a long, large file, and to run your shorter effect sounds as .WAVs, that are preloaded.

Not knowing how large your Narration is, you could try MP3 for BG Sound, and Narration, and WAV for sound effects, but it could still be too slow to handle. Worst case you could have to set your Narration as WAVs, and unload/load them on page transition (which could result in a slight framerate hiccup, that you could hopefully visually hide at the beginning/end of the scene). [import]uid: 134101 topic_id: 30081 reply_id: 120498[/import]

To clarify, NTero - is the problem in running two loadStream’ed sounds at once, or is it that if you loadSound and play two mp3 files at once, there will be the same problem? [import]uid: 160496 topic_id: 30081 reply_id: 120514[/import]

This has more information that I could provide.
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html
(The Basics section covers the Hardware-Software decoding quite well)

For your question, it is decoded during the playing of the sound and not the loading.
Although it’s possible Corona did some sort of under the hood voodoo(software convert to a different format on load), though that would be really strange. [import]uid: 134101 topic_id: 30081 reply_id: 120539[/import]

NTero, thanks for the info! [import]uid: 79443 topic_id: 30081 reply_id: 120545[/import]

Don’t know if this pertains to your application, but don’t you have to pay to license the MP3 format for commercial purposes? [import]uid: 172455 topic_id: 30081 reply_id: 120550[/import]

From: http://mp3licensing.com/help/developers.html

A license is needed for commercial (i.e., revenue-generating) use of mp3 in broadcast systems (terrestrial, satellite, cable and/or other distribution channels), streaming applications (via Internet, intranets and/or other networks), other content distribution systems (pay-audio or audio-on-demand applications and the like) or for use of mp3 on physical media (compact discs, digital versatile discs, semiconductor chips, hard drives, memory cards and the like).

However, no license is needed for private, non-commercial activities (e.g., home-entertainment, receiving broadcasts and creating a personal music library), not generating revenue or other consideration of any kind or for entities with associated annual gross revenue less than US$ 100 000.00.

I am not sure if apps fall under the first bolded sentence, but if you’re not generating more than $100K/year from your app, you don’t have to license it anyway. [import]uid: 160496 topic_id: 30081 reply_id: 120551[/import]

That’s a very interesting point regarding licensing. Thanks, I didn’t think of that until you pointed it out. Though, that would be a nice problem to have! :wink: (reaching over $100K/year and having to pay for a license, that is.) [import]uid: 79443 topic_id: 30081 reply_id: 120603[/import]

You can have up to 32 sounds playing at once. It is best to pre-load all of your sound files at the beginning of your application. [import]uid: 75779 topic_id: 30081 reply_id: 120488[/import]

While rmckee282002 is correct, MP3s are special.

The MP3 format is a compressed file, so it takes processing time to read it from disc. iOS has a special chip on it, so it can use separate hardware to decode the MP3 into a proper format to relay to the audio drivers, not taking up any time on the main CPU. The problem is that the chip can only work on one file at a time. When that chip is busy, you end up having to take up regular CPU time to decode that MP3, which is going to slow you down. This makes the first MP3 virtually free, compared to uncompressed formats, but 2 or more MP3s have a significant effect on performance.

If you want to avoid processing time, you can use .WAV files, which are uncompressed. The downside is that they are monstrous memory/disc space hogs. It’s common practice to have 1 main MP3 track streaming that is a long, large file, and to run your shorter effect sounds as .WAVs, that are preloaded.

Not knowing how large your Narration is, you could try MP3 for BG Sound, and Narration, and WAV for sound effects, but it could still be too slow to handle. Worst case you could have to set your Narration as WAVs, and unload/load them on page transition (which could result in a slight framerate hiccup, that you could hopefully visually hide at the beginning/end of the scene). [import]uid: 134101 topic_id: 30081 reply_id: 120498[/import]

To clarify, NTero - is the problem in running two loadStream’ed sounds at once, or is it that if you loadSound and play two mp3 files at once, there will be the same problem? [import]uid: 160496 topic_id: 30081 reply_id: 120514[/import]

This has more information that I could provide.
http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html
(The Basics section covers the Hardware-Software decoding quite well)

For your question, it is decoded during the playing of the sound and not the loading.
Although it’s possible Corona did some sort of under the hood voodoo(software convert to a different format on load), though that would be really strange. [import]uid: 134101 topic_id: 30081 reply_id: 120539[/import]

NTero, thanks for the info! [import]uid: 79443 topic_id: 30081 reply_id: 120545[/import]

Don’t know if this pertains to your application, but don’t you have to pay to license the MP3 format for commercial purposes? [import]uid: 172455 topic_id: 30081 reply_id: 120550[/import]

From: http://mp3licensing.com/help/developers.html

A license is needed for commercial (i.e., revenue-generating) use of mp3 in broadcast systems (terrestrial, satellite, cable and/or other distribution channels), streaming applications (via Internet, intranets and/or other networks), other content distribution systems (pay-audio or audio-on-demand applications and the like) or for use of mp3 on physical media (compact discs, digital versatile discs, semiconductor chips, hard drives, memory cards and the like).

However, no license is needed for private, non-commercial activities (e.g., home-entertainment, receiving broadcasts and creating a personal music library), not generating revenue or other consideration of any kind or for entities with associated annual gross revenue less than US$ 100 000.00.

I am not sure if apps fall under the first bolded sentence, but if you’re not generating more than $100K/year from your app, you don’t have to license it anyway. [import]uid: 160496 topic_id: 30081 reply_id: 120551[/import]

That’s a very interesting point regarding licensing. Thanks, I didn’t think of that until you pointed it out. Though, that would be a nice problem to have! :wink: (reaching over $100K/year and having to pay for a license, that is.) [import]uid: 79443 topic_id: 30081 reply_id: 120603[/import]