I was wondering, if MP3 can be played via hardware decoder on iPhone.
It was recently announced that it should work, but with the latest FMOD version it still seems not to be implemented yet.
Currently I’m working on a big project and although only one MP3 in addition to lots of sound effects is beeing played at one time, the MP3 is routed through the FMOD mixer (on the mp3 is no DSP effect only fade in and out is used…).
Is there a way to use the iPhone hardware decoder in FMOD or do I still have to waite a little longer untill FMOD can handle this?
Thanks in advance for you replies.
- 3xg asked 8 years ago
As Pete said, we do support hardware decoding of MP3. As there is only one hardware decoder in the iPhone devices, only one MP3 stream will decode in hardware. If you are playing iPod music or have an audio session set that permits iPod playback you will not be able to access the hardware.
Also note that with iOS 3.0 and newer, the devices support software codecs which kick in when the hardware is in use.
I just upgraded to the latest version of fmod for iphone (4.32), and my application, which was playing 2 mp3 at the same time with an older version of fmod, crash now with the error "Unsupported file or audio format" when i try to load the second file. I used the flag FMOD_SOFTWARE in the createStream call, so i thought i could bypass the hardware decoder limit. How can I use the software decoder for my second mp3 ?
- pbat answered 8 years ago
The default behavior is to use the new AudioQueue codec, which defaults to hardware decoding. If you have an iOS 3.0 or newer it will use AudioQueue software codecs when you request additional simultaneous MP3 streams.
If you don’t have iOS 3.0 or newer you will get FMOD_ERR_FORMAT, you can get around this by using the old FMOD software MPEG decoder. You do this by using FMOD_CREATESOUNDEXINFO and setting the suggestsoundtype member to FMOD_SOUND_TYPE_MPEG.
I have some performance issues on the first generation iPhone/iPod, and it may come from mp3 decoder.
To make it simple, in the example "playstream", I changed this line:
result = system->createStream(buffer, FMOD_SOFTWARE | FMOD_LOOP_NORMAL, NULL, &sound);
result = system->createStream(buffer, FMOD_HARDWARE, NULL, &sound);
but when I call system->getCPUUsage, I have the same (bad) result with software or hardware. anyone has an idea to make it work with hardware? how to be really sure that the mp3 is decoded with the hardware?
(i am using fmod 4.33.00)
i tried this:
FMOD_CREATESOUNDEXINFO exinfo; FMOD_AUDIOQUEUE_EXTRACODECDATA codecData; codecData.codecPolicy = FMOD_AUDIOQUEUE_CODECPOLICY_HARDWAREONLY; memset(&exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO)); exinfo.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); exinfo.extracodecdata = static_cast<void*>(&codecData); result = system->createStream(buffer, FMOD_HARDWARE | FMOD_LOOP_NORMAL, &exinfo, &sound);
but it does not seem to change anything. getCPUUsage give me a total result between 20 and 30% (all in stream). I am using an iPhone 3G with iOS 3.1.3, and FMOD 4.33.00
It will default to using hardware, the second method you listed will ensure that only hardware is ever used, i.e. if hardware isn’t available or is in use then the create sound will fail.
The getCPUUsage values for hardware can be a bit misleading. Essentially the FMOD code will call a function that decodes in hardware (that function blocks until the hardware is done) then it returns. So from FMODs perspective via getCPUUsage it looks expensive, but actually that time is spent blocking while the hardware chip decodes the data, so in essence it not using CPU cycles.
thanks Mathew. it makes sense. when I use the following line I notice a constant 15% CPU usage, is it better to use it to decode mp3?:
m_ExInfo.suggestedsoundtype = FMOD_SOUND_TYPE_MPEG;
Also, playing a mp3 seems to decrease the framerate of our game on the old iPhones, even with hardware decoder. (and it is not worst with FMOD_SOFTWARE, what explains my questions)
In our previous game, we used AVAudioPlayer. Do you think FMOD should be as fast as AVAudioPlayer, or should I make a try with AVAudioPlayer to increase the framerate? I use FMOD mainly for events (and it is really great!) but for music I only need to play a mp3 as fast as possible…
Also, if FMOD use the hardware "only" to decode, I guess FMOD makes the final mix, so maybe I should set the system’s sample rate to 44100 to match the mp3?
Using the suggested sound type MPEG will invoke FMODs software MPEG decoder, it will cost more real CPU time than using the audio queue sound type. You best bet for performance is to leave it as default. If actual MP3 decoding time is the most important I recommend using FMOD_AUDIOQUEUE_CODECPOLICY_SOFTWAREONLY (only for iOS 3.0 and newer).
FMOD_HARDWARE vs FMOD_SOFTWARE means nothing on iPhone since these flags control whether the channel is in hardware or software (the iPhone doesn’t have hardware mixing) so the default is always FMOD_SOFTWARE regardless.
AVAudioPlayer if memory serves is a high level wrapper for AudioQueue which is what we use for hardware decoding, there shouldn’t be much of a performance difference if you used it yourself.
Setting FMOD to run at 44100 will probably incur more expense than you would like for all the other sounds you have playing. You would need to do some tests to get exact performance figures, but setting FMOD to 44100 would double the cost of most other playback.
Please login first to submit.