» Site Navigation |
|
|
» Advertisements |

Visit our friends over at The App Show! Steve and Dave produce a weekly show shining a light on the iPhone 2.0 software and the applications being developed by the amazing development community for the iPhone SDK!
|
» Online Users: 115 |
| 22 members and 93 guests |
| backwardselvis, cjgogo, CommanderData, cyikeda, cyunker, detz, dicklacara, dshaffer, Flipmode, jeff_lamarche, kuba1234, mcurtis, Moose, MXStudios, pfhorte, pritam_prasad, raysms, RickMaddy, snatch, twentythree, vanb777 |
| Most users ever online was 207, 10-24-2008 at 09:29 AM. |
» Stats |
Members: 3,915
Threads: 5,614
Posts: 23,254
Top Poster: scottiphone (705)
|
| Welcome to our newest member, raysms |
|
 |
08-20-2008, 12:42 PM
|
#1 (permalink)
|
|
Code Monkey
Join Date: Aug 2008
Location: San Jose
Posts: 7
|
Can't play more than one compressed sample on the iPhone itself
I'm writing an app that needs to play a variety of audio samples of different lengths back to back, but only one at a time. The system I came up with works great when using WAV files or whenever running on the simulator no matter what audio type, but on the iPhone itself the logic breaks if I use a compressed audio format like MP3 or AAC. I don't want to ship 5MB of audio when it could be 500K, so this is a serious problem for me!
I think the bugs have to do with the iPhone's hardware acceleration for compressed audio, and certain playback behaviors changing in this context, but I'm not positive.
Basically, I have a list of 18 samples. I load each into it's own queueable object with it's own queue reference and buffers. If nothing is playing, I pick the first object randomly and play it, wait for it's queue's isRunning property to go false, then play the next sample upon completion. Fine, right?
However, when using MP3s, the first sample I play works just fine, but all the other sounds fail to play, stopping immediately (messing up my event logic). Interestingly, when I loop all the way back around to the original sample, it plays again just fine! It doesn't matter which file I play first... the first file always works great, but appears to block the output of all the other sounds that come later, even though it can be correctly played again itself.
The return codes for all of my AudioQueue calls are 0, even when the audio for a sample doesn't play, and I see a reasonable number of buffering messages as if it's reading and enqueueing each and every file correctly. I'm even flushing the object's queue before calling stop, and resetting the object's queue after the 'isRunning' property goes false, to no avail.
Can anybody describe the magic incantation that allows multiple compressed audio files to be played through the AudioQueue engine, one at a time, without them blocking each other's output? Am I missing something simple?
Help!
|
|
|
08-21-2008, 12:05 AM
|
#2 (permalink)
|
|
Member
Join Date: Aug 2008
Posts: 39
|
apple iphone is limited to one sound if compressed
The apple specs clearly state that the hardware accelerator chip that is handling sound decompression can only handle one stream at a time, and so if you want to mix two or more tracks of sound they gotta be in linear PCM format or IMA4:1 otherwise no go. I can live with one track of MP3 background sound, and use PCM for my bleeps, etc.
I just couldn't get a compressed sound to play using their SpeakHere example, evidently you have to add some additional calls to get it to work.
|
|
|
08-21-2008, 11:14 AM
|
#3 (permalink)
|
|
Code Monkey
Join Date: Aug 2008
Location: San Jose
Posts: 7
|
The thing is, I'm only ever trying to play one sound at a time. I never play a new sound until the old one has stopped completely. My next step is going to be trying to load the sounds into the same queueable object as needed, instead of into lots of their own little queueables objects, disposing of the queue references between playing each sound. That seems horribly innefficient, though... I'd think it would be much better to just swap queueables than reallocate them every time, but I saw some other code where someone was opening a url, allocating the necessary objects, then cleaning up afterwards on every play. if it works... why not?
Did you happen to see my response to your mp3 playback thread? I know which calls you need to add to SpeakHere to get mp3s to play in the simulator (and one to play on the phone, at least)!
Last edited by PKMousie; 08-21-2008 at 11:17 AM.
|
|
|
08-28-2008, 06:50 PM
|
#4 (permalink)
|
|
Junior Member
Join Date: Aug 2008
Posts: 1
|
You can play more than one file at a time even if one of those files is an MP3. Just make certain that the other files are not compressed LEI16 works best (i.e. you can only play one MP3 at a time).
That said, you have to remember to completely remove one file prior to starting another or it will sit in the queue as a "stopped" track. I'd reference the sample code for CrashLander to find an example audio queue services that works with mp3 files out of the box.
|
|
|
08-31-2008, 09:41 AM
|
#5 (permalink)
|
|
Junior Member
Join Date: Aug 2008
Posts: 2
|
Hi,
I stumbled upon this post when google-ing around and your problem is the same as my problem I think.
I created my app and added the SpeakHere example's audioplayer. Wav played fine and after some small changes I managed to support mp3. However, when I click the stop button and I restart the mp3, the application has weird behaviour: it crashes after some user interaction (most of the time), it crashes immediately (only happened 1 or 2 times) or sometimes it just works (also 1 or 2 times). After crashing I even have to restart my application and play a .wav file first before I can play an mp3 file again.
With .wav everything is working great: seek();, pause();, stop();, play();, resume();,...
Did you find a solution already?
Did the "clean up & reallocate on every play" do the job? As this seems rather inefficient to me + my application won't even work after a simple restart (like I said, I have to play a wav file first before I can play any mp3 again), so I'm not sure if cleaning everything up would do the job.
Thanks in advance,
bratax
|
|
|
 |
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|