developer hint: streaming audio with AudioQueueEnqueueBuffer and iPhone OS 3.1.2

Discussion in 'Public Game Developers Forum' started by mobile1up, Feb 14, 2010.

  1. mobile1up

    mobile1up Well-Known Member

    Nov 6, 2008
    754
    0
    16
    Technical Director
    Munich, Germany
    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.
     
  2. GregH

    GregH Well-Known Member

    Sep 12, 2009
    479
    0
    0
    Really!? I just finished converting from using AVAudioPlayer for the music to using AudioQueue. Yikes!
     
  3. TrueAxis

    TrueAxis Well-Known Member

    Sep 7, 2009
    610
    0
    0
    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.
     
  4. mobile1up

    mobile1up Well-Known Member

    Nov 6, 2008
    754
    0
    16
    Technical Director
    Munich, Germany
    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
     
  5. GregH

    GregH Well-Known Member

    Sep 12, 2009
    479
    0
    0
    Thanks for sharing, I bet that was really hard to track down. I guess I'll start researching AudioUnit :)
     
  6. mobile1up

    mobile1up Well-Known Member

    Nov 6, 2008
    754
    0
    16
    Technical Director
    Munich, Germany
    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.
     

Share This Page