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

AVAudioPlayer and SystemSoundId... conflict?

08-25-2009, 12:48 AM
#1
Joined: Dec 2008
Posts: 439
AVAudioPlayer and SystemSoundId... conflict?

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.
08-25-2009, 05:49 AM
#2
Joined: Jun 2009
Location: Stockholm, Sweden
Posts: 31
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.

08-25-2009, 05:10 PM
#3
Joined: Dec 2008
Posts: 439
Quote:
Originally Posted by dromsynt View Post
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.
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.
09-04-2009, 10:36 AM
#4
Joined: Dec 2008
Posts: 439
I ended up using SoundEngine.cpp from the CrashLanding app. Solved this problem plus removed a lot of lag time...
09-04-2009, 11:45 AM
#5
Joined: Aug 2009
Posts: 26
Quote:
Originally Posted by arkanigon View Post
I ended up using SoundEngine.cpp from the CrashLanding app. Solved this problem plus removed a lot of lag time...
Watch out though with using SoundEngine.cpp, there are some memory leaks in it, which is why apple discourages developers from using it.
09-05-2009, 04:09 AM
#6
Joined: Dec 2008
Posts: 439
Quote:
Originally Posted by xother View Post
Watch out though with using SoundEngine.cpp, there are some memory leaks in it, which is why apple discourages developers from using it.
Hmmm... so what is the best option... should I try AVAudioPlayer for both music and sound effects?
09-05-2009, 08:25 AM
#7
Joined: Aug 2009
Posts: 26
Quote:
Originally Posted by arkanigon View Post
Hmmm... so what is the best option... should I try AVAudioPlayer for both music and sound effects?
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.
09-05-2009, 09:21 AM
#8
Joined: Dec 2008
Posts: 439
Quote:
Originally Posted by xother View Post
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.
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...
09-06-2009, 12:01 PM
#9
Joined: Aug 2009
Posts: 26
Quote:
Originally Posted by arkanigon View Post
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...
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.
09-06-2009, 12:04 PM
#10
Joined: Dec 2008
Posts: 439
Quote:
Originally Posted by xother View Post
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.
Thanks.