★ TouchArcade needs your help. Click here to support us on Patreon.

developer hint: streaming audio with AudioQueueEnqueueBuffer and iPhone OS 3.1.2

02-14-2010, 03:34 PM
#1
Joined: Nov 2008
Location: Munich, Germany
Posts: 754
Send a message via Skype™ to mobile1up
developer hint: streaming audio with AudioQueueEnqueueBuffer and iPhone OS 3.1.2

are you using AudioQueueEnqueueBuffer?

i came across this issue doing a custom marketing application for a client; who happened to have a device running iPhone OS 3.1.2 and we ran into a the case where the first time the application was run; audio was not a problem at all. if you run it a second time; audio is gone. restart the phone; or even do a sync with itunes and the audio comes back.

we debugged this for hours - to no avail. it doesn't happen on all 3.1.2 devices; only a select few (random i think) - and tested every single call, checked every single error code.. nothing. the simulator worked without any problem over and over again - so, i was pulling my hair out for this.

the solution?

dump AudioQueueEnqueueBuffer and use AudioUnit instead - it is relatively the same; but this is obviously a bug somewhere within the AudioQueueXXX API's on the iDevices (to best of my knowledge; iPhone only). it didn't take long to use AudioUnit instead; and it also removed the issue from the devices. all of our games used AudioQueueEnqueueBuffer - so, we are planning updates now.. we also had a few users report that audio stopped working as well.

just a head's up for other developers.

// Aaron Ardiri
Mobile 1UP is a proud indie developer - support us!
developer of Caveman / Caveman HD and GW Series
02-14-2010, 08:09 PM
#2
Joined: Sep 2009
Posts: 479
Really!? I just finished converting from using AVAudioPlayer for the music to using AudioQueue. Yikes!

"when he eats three poops and becomes muscle bound, that was worth the .99 right there." -Super Fly!
Tetris and Bubble Wrap had a baby and named it Super Juicy!
TouchGen Best of 2009 Finalist! 5/5 Best of 2009
02-14-2010, 08:26 PM
#3
Joined: Sep 2009
Posts: 610
Just a warning about using AudioUnit... When you request your buffer size, depending whether you have ear phones in, in silent mode, or speakers you can get different buffer sizes back on a iphone 2g. This is normally fine until you process the samples 8 bytes at a time using the Arm SIMD instructions, where some of the buffer sizes are not divisible by 8, and this will cause a memory fault.

All the other iDevices give you a buffer that is divisible by 8 - I wonder why the iphone 2g is different to the rest?

The first version of Jet Car Stunts had this problem and this was the cause of the crash problem we had on the iphone 2g, where the game would only run with ear phones in or in silent mode.
02-15-2010, 12:09 AM
#4
Joined: Nov 2008
Location: Munich, Germany
Posts: 754
Send a message via Skype™ to mobile1up
Quote:
Originally Posted by GregH View Post
Really!? I just finished converting from using AVAudioPlayer for the music to using AudioQueue. Yikes!
i've had a few users tell me audio just stops - i was stumped.

i checked my code over and over; i was working with a client who had the exact issue - and, i was able to send him debug builds, basically tracking down if there were any error codes - nothing. i built a version with AudioUnit; and it solved everything (i mix my own samples; and i don't use SIMD instructions) :P

// Aaron Ardiri
Mobile 1UP is a proud indie developer - support us!
developer of Caveman / Caveman HD and GW Series
02-15-2010, 12:19 AM
#5
Joined: Sep 2009
Posts: 479
Quote:
Originally Posted by mobile1up View Post
i've had a few users tell me audio just stops - i was stumped.

i checked my code over and over; i was working with a client who had the exact issue - and, i was able to send him debug builds, basically tracking down if there were any error codes - nothing. i built a version with AudioUnit; and it solved everything (i mix my own samples; and i don't use SIMD instructions) :P
Thanks for sharing, I bet that was really hard to track down. I guess I'll start researching AudioUnit :-)

"when he eats three poops and becomes muscle bound, that was worth the .99 right there." -Super Fly!
Tetris and Bubble Wrap had a baby and named it Super Juicy!
TouchGen Best of 2009 Finalist! 5/5 Best of 2009
02-15-2010, 12:24 AM
#6
Joined: Nov 2008
Location: Munich, Germany
Posts: 754
Send a message via Skype™ to mobile1up
Quote:
Originally Posted by GregH View Post
Thanks for sharing, I bet that was really hard to track down. I guess I'll start researching AudioUnit :-)
unless there was something funky i was doing - but, honestly - it worked everywhere else and, it worked first time after a reset/sync on the affected devices. i suspected something was locked etc.. but, not even an error code. AudioUnit on iPhone is a little different from Mac OSX

http://www.idevgames.com/forum/showthread.php?p=155860

SDL seems to also use AudioUnit in RemoteIO mode - as one of the posters shows.

// Aaron Ardiri
Mobile 1UP is a proud indie developer - support us!
developer of Caveman / Caveman HD and GW Series