AVAudioPlayer and SystemSoundId... conflict?

Discussion in 'Public Game Developers Forum' started by arkanigon, Aug 25, 2009.

  1. arkanigon

    arkanigon Well-Known Member

    Dec 24, 2008
    439
    0
    0
    I'm using AVAudioPlayer for music... and systemsound for sound effects... what happens sometimes is, the sound effects stop working while music is playing... seems to happen when I start my game... I notice that when I drop the volume on my iphone completely down to 0... then raise it up, the sound effects work for a second, then stop working again...

    Anyone else experience this? Appreciate any help. Thanks.
     
  2. I've battled this as well. Here's what I think happens:

    The volume of a SystemSoundId effect is relative to the system (ringer) volume you had your phone at before starting the app. This means, in the extreme case of having the ringer all the way down for ex., that the volume switch wont affect SystemSoundId volume at all while your app is running.

    The AVAudioPlayer on the other hand is independent of the ringer volume and will have the full range of volume mapped to the volume switch.

    I haven't found any way around this and will notify my costumers to put the ringer volume up before launching the app.
     
  3. arkanigon

    arkanigon Well-Known Member

    Dec 24, 2008
    439
    0
    0
    Thanks dromsynt! :) That is very helpful. I wouldn't have figured it out on my own. At least now I know what's happening. I'll do the same thing, and probably put a message in my app description for the customers.
     
  4. arkanigon

    arkanigon Well-Known Member

    Dec 24, 2008
    439
    0
    0
    I ended up using SoundEngine.cpp from the CrashLanding app. Solved this problem plus removed a lot of lag time...
     
  5. xother

    xother Active Member

    Aug 18, 2009
    26
    0
    0
    Watch out though with using SoundEngine.cpp, there are some memory leaks in it, which is why apple discourages developers from using it.
     
  6. arkanigon

    arkanigon Well-Known Member

    Dec 24, 2008
    439
    0
    0
    Hmmm... so what is the best option... should I try AVAudioPlayer for both music and sound effects?
     
  7. xother

    xother Active Member

    Aug 18, 2009
    26
    0
    0
    If your music is just a background track playing, AVAudioPlayer is good for just that. If you want music to change dynamically, I would recommend AudioQueues or AudioUnits. With the lag of AVAudioPlayer I wouldn't recommend it for sound effects. I've had good results with openAL, the openAL implementation is based on AudioUnits, so it has low latency and a low system usage. OpenAL is also well documented on the web, there are many tutorials to get you going.
     
  8. arkanigon

    arkanigon Well-Known Member

    Dec 24, 2008
    439
    0
    0
    Thanks. Is there a tutorial you'd recommend? I've seen a lot of openal stuff, but I've been a bit overwhelmed by it...
     
  9. xother

    xother Active Member

    Aug 18, 2009
    26
    0
    0
    Some good tutorials:
    iPhone specific implementation.
    For a general understanding, the devmaster series.
    A few tips in the apple QA.

    I would advice to get your implementation working with wav files first and then switch to IMA4 or compressed formats. You can use AudioFileReadPackets to get the raw data (PCM) from a compressed file.
     
  10. arkanigon

    arkanigon Well-Known Member

    Dec 24, 2008
    439
    0
    0
    Thanks.
     

Share This Page