Getting the sound output ‘right’

September 19, 2008

There’s at least three ways to do sound for the iPhone. The simplest way however – using System Sound Services – is not recommended for games, where you want to be playing multiple, and potentially long, sounds.

So for our needs, we were basically left with a choice between Audio Queue services, which seems to be the generally recommended way to do sound in games, and with using the SoundEngine class from Apple’s CrashLanding example, which uses the Open Audio Library, which also has the potential advantage of supposedly being cross-platform.

I tried both using Audio Queue services and the SoundEngine. It turns out that the Audio Queue services have the advantage that you can at least hear something in the simulator when using. The disadvantage that I found however was that it was tricky to get working nicely, and had some issues I was never able to solve, for example if I played stereo sounds then there were audible audio artifacts whenever I stopped/started them, even though doing everything the same with mono sounds there were no problems, which seemed to indicate the problem was internal.

So I went for using this SoundEngine class. It turns out this is very simple to use and basically just works. In our first release of Fuzzle, we released with this, however we then discovered one problem – by default, it fades out, and stops any existing music playback, when the application starts. Turns out a number of games have this same problem …. the user can always, after application start, double-tap the home key and restart the music, however then the game sounds stop working, and most importantly, some users don’t realize this and complain in reviews!

The fix for this, which is in our next update already, turns out to be the following three lines of code, which should come immediate before the call to SoundEngine_Initialize(…):

    AudioSessionInitialize (NULL,NULL,NULL,NULL);
    UInt32 sessionCategory = kAudioSessionCategory_AmbientSound;
        sizeof( sessionCategory ),
        &sessionCategory );

And with this code added, the game seems to co-exist perfectly happily with background music. Of course, if your application/game has its own music etc, then it may make sense to leave the default method of stopping any existing music playback. And once this update has been out, we’ll see if any other problems surface, but at the moment this seems to be the ‘right way’ to handle this 🙂


My iPhone development story

September 18, 2008

Having worked on developing an iphone app for the past month or so, I thought it worth sharing some of my story …. so I’ll be posting here a number of tips to try to save developers some of the hassle I went through getting all the basic things working for my first iphone game Fuzzle and subsequent games. Plus you might be hearing a little about our rollercoaster ride in the crazy world of the appstore as we try to generate sales+visibility for our apps within Apple’s system.