Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple audio input API on a Mac?

Tags:

macos

audio

I'd like to pull a stream of PCM samples from a Mac's line-in or built-in mic and do a little live analysis (the exact nature doesn't pertain to this question, but it could be an FFT every so often, or some basic statistics on the sample levels, or what have you).

What's a good fit for this? Writing an AudioUnit that just passes the sound through and incidentally hands it off somewhere for analysis? Writing a JACK-aware app and figuring out how to get it to play with the JACK server? Ecasound?

This is a cheesy proof-of-concept hobby project, so simplicity of API is the driving factor (followed by reasonable choice of programming language).

like image 967
Erin Dees Avatar asked Sep 01 '08 06:09

Erin Dees


3 Answers

The principal framework for audio development in Mac OS X is Core Audio; it's the basis for all audio I/O. There are layers on top of it like Audio Toolbox, Audio Queue Services, QuickTime, and QTKit that you can use if you want a simplified API for common tasks.

To just pull a stream of samples, you'd probably want to use Audio Queue Services; the AudioQueueNewInput function will set up recording of PCM data and pass it to a callback you supply.

On your Mac there's a set of Core Audio examples in /Developer/Examples/CoreAudio/SimpleSDK that includes a use (AQRecord in AudioQueueTools) of the Audio Queue Services recording APIs.

like image 63
Chris Hanson Avatar answered Nov 03 '22 00:11

Chris Hanson


I think portaudio is what you need. Reading from the mike from a console app is a 10 line C file (see patests in the portaudio distrib).

like image 40
diciu Avatar answered Nov 02 '22 23:11

diciu


Apple provides sample code for reading and writing audio data. Additionally there is a lot of good information in the Audio section of the Apple Developer site.

like image 3
Mark Harrison Avatar answered Nov 03 '22 00:11

Mark Harrison