Tuesday, October 07, 2008

Next step: audio

Now that the first test app works and I somewhat understand what outlets are, I wonder what would be the next step? At least I should know how to have multiple views and change between them using a tab bar or similar control. So I should learn basic navigation.

As a brief detour though I am curious about how recording sound works. I have some ideas for apps that need sound recording, upload and download, but am a bit concerned that it might be a bit difficult. At least the network part. How do I know if the net connection is on? How do I show a progress bar for download/upload? Should there be a cancel button in case transfer is taking forever, for example if it happens over normal GPRS? What about compression, is there some basic compression algorithm included in the API?

I recall seeing some example code about sound recording, let's dig that up.

The example is called SpeakHere. Seems that there is no simple recordAudioOKThxBye-style function, but you have to stream it to a file yourself. Fair enough, it doesn't seem to be all that complicated to do, and is probably something I will eventually have to learn how to do anyway. There seems to be PCM encoding built in. Saw passing mention of MP3. I wonder which ones iPhone supports. MP3 would be sweet for shortening transfer times and also using the same files later when playing back from Flash, but is it possible?

Read up on "Audio Queue Services". Documentation mentioned the following "kAudioFormatMPEGLayer3 - MPEG-1/2, Layer 3 audio. Uses no flags. Available in iPhone OS 2.0 and later.", so it would appear the encoder is present. It's a bit overwhelming to set all of the structures at once and hope that I don't miss any vital flags or attributes, so I'll try to start with something really simple. Simplest thing I can imagine is setting up a callback function for sound playback and just fill the buffers with rand(), hopefully white noise can then be heard from the speaker.

Found a useful tutorial on the subject.