views:

1170

answers:

3

I'm due to work on a small application that captures audio from the Mac's Audio Queue and needs to save it to disk in some reasonable audio format.

Does anyone have a some decent sample code (Cocoa / Objective-C) that they can share?

I specifically need to capture the audio that is being passed to the Built-in Output device in order to record it. Any insights? The answers so far have been helpful, but have not helped me understand how the data going to the output can be captured, agnostic of the input source.

+4  A: 

Working with audio in Mac OS X involves interfacing with Core Audio. For a quick overview, take a look at the Core Audio Overview.

You will need to interface with the AUHAL to perform input and output; a technical note exists detailing the steps required to do so. This code seems to usually be written in C++, as that is the procedure taken in the SimplePlayThru demo.

This doesn't cover the actual steps required to capture that audio input. However, these links should provide you with enough sample code to begin interfacing with your input device. I'll post more links in this answer if I happen across them.


Take a look at /Developer/Example/CoreAudio/Services/AudioFileTools. Specifically, look at afrecord.cpp. Admittedly, this is not Cocoa per se; Cocoa itself doesn't seem to have any specific capabilities for recording. If you'll want to interface with the C++ file there, you'll likely need to write some Objective C++ like in SimplePlayThru.

Wesley
Thanks! I knew about Core Audio and had taken a peek. I'm very interested if anyone has done something similar that I can take a look up. Thumbs up for the response, regardless...
Demi
+2  A: 

There is a good example code at Ulli Kusterers website
Cocoadev also has an article about that topic. The source code at the bottom of the page uses QuickTimes Sequence Grabber API. I would go with Core Audio.

weichsel
This is good information. Thanks!
Demi
A: 

Re: "Ulli Kusterers website"

  • That code shows how to capture from regular inputs which is easy there are many apple dev samples that support that. The original question was how to capture from the audio output device so that the code could be agnostic of input devices.

"I specifically need to capture the audio that is being passed to the Built-in Output device in order to record it. ... how the data going to the output can be captured, agnostic of the input source."

  • I could also use some help with this, has the original poster since found a solution they may want to share? Thanks.
Thamster
Sadly, no. I have moved on to other projects and let the dust settle on that one.
Demi