Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to listen to mic input and analyse in real time?

Hi unfortunately I've not been able to figure out audio on the iPhone. The best I've come close to are the AVAudioRecorder/Player classes and I know that they are no good fo audio processing.

So i'm wondering if someone would be able to explain to me how to "listen" to the iPhone's mic input in chunks of say 1024 samples, analyse the samples and do stuff. And just keep going like that until my app terminates or tells it to stop. I'm not looking to save any data, all I want is to analyse the data in real time and do stuff in real time with it.

I've attempted to try and understand apples "aurioTouch" example but it's just way too complicated for me to understand.

So can someone explain to me how I should go about this?

like image 782
Christian Gossain Avatar asked Nov 21 '10 17:11

Christian Gossain


People also ask

Should I choose line in or mic in?

Mic-in is used for directly plugging in microphones, and line-in is for consumer and pro-grade gear. Mic-level signals are weak and line-level signals are strong. Mic inputs use a female XLR connector. Line inputs require RCA, ¼” phone jack, or 3.5 mm phone jack.


3 Answers

If you want to analyze audio input in real-time, it doesn't get a lot simpler than Apple's aurioTouch iOS sample app with source code (there is also a mirror site). You can google a bit more info on using the Audio Unit RemoteIO API for recording, but you'll still have to figure out the real-time analysis DSP portion.

The Audio Queue API is a slight bit simpler for getting input buffers of raw PCM audio data from the mic, but not much simpler, and it has a higher latency.

Added later: There's also a version of aurioTouch converted to Swift here: https://github.com/ooper-shlab/aurioTouch2.0-Swift

like image 162
hotpaw2 Avatar answered Sep 23 '22 13:09

hotpaw2


AVAudioPlayer/Recorder class won't take you there if you wanna do any real time audio processing. The Audio Toolbox and Audio Unit frameworks are the way to go. Check here for apple's audio programming guide to see which framework suits your need. And believe me, these low level stuff is not easy and is poorly documented. CocoaDev has some tutorials where you can find sample codes. Also, there is an audio DSP library DIRAC I recently discovered for tempo and pitch manipulation. I haven't looked into it much but you might find it useful.

like image 2
saurb Avatar answered Sep 22 '22 13:09

saurb


If all you want is samples with a minimum amount of processing by the OS, you probably want the Audio Queue API; see Audio Queue Services Programming Guide.

AVAudioRecorder is designed for recording to a file, and AudioUnit is more for "pluggable" audio processing (and on the Mac side of things, AU Lab is actually pretty cool).

like image 1
tc. Avatar answered Sep 20 '22 13:09

tc.