Saturday, March 15, 2008

Still Playing

I started working with the audio toolbox on the iPhone today. This morning, I added sounds to the little dice rolling application I've been writing. I recorded a total of fifteen sounds, five of a single die being rolled, five of two dice being rolled, and five of four dice being rolled. I let my kids roll the dice while I recorded the sounds, which they thought was cool, although they can't understand why I can't put the program on my iPhone. 

Do you hear that, Steve Jobs? You are making my kids sad. Do you really want that on your conscience?  ;) 

Unfortunately, the "Coding How-Tos" on the iPhone web site don't give a full code sample on how to play audio files. They show the command to play a sound, but not how to find and load the file from your application bundle (it may be in the how-tos somewhere, but it wasn't under the section on playing audio). Figuring that out took a little poking around in the documentation and header files (and, of course, a couple of application crashes), but I got it working without too much trouble. 

Boy, it's been a while since I've worked with pointers... I spent way too long working almost exclusively with Java. I don't want to bash Java - I know a lot of people like it, and it's been the basis for a lot of my income over the years - but it just feels so much less elegant than objective-C. 

Since I wrote my first AppleScript Basic program in 1980, I have used literally dozens of different programming and scripting languages, many extensively and as part of my professional life, and I can say that Objective-C and Cocoa (and now Cocoa Touch) are, by far and without a doubt my favorite. They take a little while to understand when you first start using them, but once you get over the "grokking curve" and really start to understand how it all pieces together, coding in objective-C really becomes a pleasurable experience. It's just plain fun. 

In a way, I envy all those people coming to the iPhone from other languages and toolset. They are about to discover something very, very cool if they have the patience to get past the initial obstacles.


Lee said...


Good to see someone else is having problems playing sounds. I have them loaded and playing within a normal project but as soon as I try the same technique in an iphone project it fails to work.

Any clue on how you actually got it working?


agntdrake said...

Hey Jeff,

I've been reading through all of your old blog entries, and I've gotten through half of your Beginning iPhone book (I have to admit I got impatient after chapter 8 or so and just skipped to the OpenGLES example stuff). As someone coming from writing Python all the time (and using Pyglet for OpenGL) I find Objective-C and OpenGLES to be more akin to teeth pulling. It may be better than Java and C++, but I keep running into all these annoying quirks which have been driving me nuts.

Yesterday I discovered (through your NeHe blog posts -- thank you for taking the time to post those) the limitations of only triangle polys and no quads. Before that I wanted to create a singleton using class variables (which turn out to not exist in Objective-C). Before that it was discovering that the GLU extensions don't seem to exist for OpenGLES (I believe someone released some code that implements some of its functionality though), so I had to create circles/oval primitives by hand. I still haven't figured out how I'm going to replace gluProject.

Anyway, I think you're right about there being a "hump" to the learning experience, but unfortunately I feel like I'm still on the uphill side. Everything still feels like it's getting in my way instead of there being rhythm.