views:

142

answers:

3

Hi,

I've been working on a metronome app for quite some time now. Following Apple'e sample Metronome application, I've been using a timer on a (high priority) background thread to play system sounds. My results are okay but far from perfect. Some issues that I face are:

~ the app doesn't really keep time, although it sounds like it does ~ i can't do much on the main thread while the sound thread is running as it gets really sluggish ~ if I press the lock button or volume buttons on the device, the tempo goes haywire. ~ system sounds don't play when the phone is silent

I purchased a metronome on the app store yesterday and found that this app didn't have any of the above issues. It wasn't using system sounds as muting the iPhone didn't stop playback.

Now, I'm wondering if anyone can guide me towards a better, more robust framework for this task?

thanks in advance!

+1  A: 

You can use OpenAL to work with sound. It uses low-level API and works fast. Also you should read Apple's AudioSessionProgrammingGuide. There you will find many answers on your possible questions.

Morion
i am quite intimidated by OpenAL for the time being so I think I'm going to research audio units first.Thanks!
cocoaholic
If you just want to play some music in background without positioning, it is rather simple. You can read this tutorial. http://benbritten.com/2008/11/06/openal-sound-on-the-iphone/comment-page-1/#comment-292
Morion
thanks! i've started going through the tutorial. it looks great!
cocoaholic
+2  A: 

The OSX audio libraries are referred to as "Core Audio". There are a few different ways of interacting with the audio hardware and the Core Audio frameworks. There's OpenAL (as mentioned in another comment) which is a cross-platform standard approach to audio much like OpenGL is for graphics. There is also Audio Unit which is a callback-based interface directly to the audio hardware which allows you to supply raw PCM audio in real-time. Audio Units are extremely time-constrained, so if you're looking for metronomic rhythm, Audio Units can do that for you. There's also a layer on top of Audio Units known as AudioQueue which allows you to schedule a stream of audio for play in real-time. One of the benefits of AudioQueue is that it can automatically decode compressed formats such as MP3 or AAC.

Search on "Core Audio Overview" in the docs to learn more about the various audio frameworks for iPhone.

Neil Mix
thanks Neil. It seems like Audio Units (and possibly Audio Queue) is exactly what I was looking for.
cocoaholic
+1  A: 

I am going to start a flame here, so if you don't like this comment have at it. But did you actually look at the documentation that apple provides for you?

The documentation the "Getting Started with Audio" page lists multiple ways to play audio, one explicitely states "To play sounds with lowest I/O latency, or to provide simultaneous audio input and output, ..." (I am probably violating some NDA here whatever)

At least peak at the docs before you ask a question here

Harald Scheirich
thanks. i've been through more than "Getting Started with Audio" already. i'm a beginner and didn't really understand much about the audio frameworks. i was just looking for a pointer in the right direction with regards to my problem. Now that I've gotten that, I can invest time in getting familiar with the relevant frameworks (specifically Audio Units and Audio Queue).
cocoaholic