Archive for the ‘iPhone SDK’ Category

Audio Services Freezing App

Thursday, January 1st, 2009

If you are using Audio Services to play sound effects, then you’re going to have problems if you’re also updating your program state at a high frame rate. 

Although incredibly simple to use, the Audio Services should really only be used for one off alerts or sounds, and never as the sound effect backend of a game or similar. 

Like most Apple APIs, they use the technique of lazy loading.  That is, don’t bother doing anything like setting up audio buffers etc until you actually call the API into action for the first time.  This is useful for faster loading apps, and a smaller average memory footprint. 

But the downside to this is that the first time you try to play a sound, the Audio Services will be initialized and your app will pause for tenths of a second.  After this, however, all will be fine. 

A better way to go is to use OpenAL to handle audio playback.  It is much more flexible, and allows you to call the initialize function when your application loads, to avoid delays when you actually want sound to be played.  

The best place to start with this is to look at the Apple ‘Crash Landing’ example.  It includes a ‘SoundEngine’ module that can pretty much just be copied into your applications for use.  Remember to include the OpenAL framework though.

OpenGL ES 1.1 and the iPhone

Wednesday, December 3rd, 2008

What can make an iPhone developer sulk and refuse to program for two hours?  OpenGL ES is the answer, and it has nothing to do with OpenGL ES per se. 

Largely it’s my fault.  I should have done my research upfront. But with all the talk of the OpenGL ES 2.0 standard, I started to assume that it was supported on the iPhone.  After three hours of learning about vertex and fragment shaders in OpenGL ES 2.0, and writing a few to render a 2D blob for my upcoming iPhone physics engine (more on this later..) I got stuck trying to make it work on the iPhone itself.  

Not surprising really.  The hardware in the iPhone only supports the OpenGL ES 1.1 standard, and as such the API has no calls to any vector or fragment program related goodness.  

Lucky for me, I was just trying to do some shadows and shading of 2D sprites, so I could kinda fake it using some blending and scaling, but I guess the more adventurous effects will just have to wail until the next iPhone generation or later. 

So before you end up crossed armed and sulking as hard as you can at your computer, only do things based on the 1.1 standard, not the 2.0.