开发者

iPhone audio analysis

I'm looking int开发者_运维问答o developing an iPhone app that will potentially involve a "simple" analysis of audio it is receiving from the standard phone mic. Specifically, I am interested in the highs and lows the mic pics up, and really everything in between is irrelevant to me.

Is there an app that does this already (just so I can see what its capable of)? And where should I look to get started on such code?

Thanks for your help.


Look in the Audio Queue framework. This is what I use to get a high water mark:

AudioQueueRef audioQueue; // Imagine this is correctly set up
UInt32 dataSize = sizeof(AudioQueueLevelMeterState) * recordFormat.mChannelsPerFrame;
AudioQueueLevelMeterState *levels = (AudioQueueLevelMeterState*)malloc(dataSize);

float channelAvg = 0;

OSStatus rc = AudioQueueGetProperty(audioQueue, kAudioQueueProperty_CurrentLevelMeter, levels, &dataSize);
if (rc) {
    NSLog(@"AudioQueueGetProperty(CurrentLevelMeter) returned %@", rc);
} else {    
    for (int i = 0; i < recordFormat.mChannelsPerFrame; i++) {
        channelAvg += levels[i].mPeakPower;
    }
}
free(levels);

// This works because one channel always has an mAveragePower of 0.
return channelAvg;

You can get peak power in either dB Free Scale (with kAudioQueueProperty_CurrentLevelMeterDB) or simply as a float in the interval [0.0, 1.0] (with kAudioQueueProperty_CurrentLevelMeter).


Don't forget to activate level metering for AudioQueue first:

UInt32 d = 1;
OSStatus status = AudioQueueSetProperty(mQueue, kAudioQueueProperty_EnableLevelMetering, &d, sizeof(UInt32));


Check the 'SpeakHere' sample code. it will show you how to record audio using the AudioQueue API. It also contains some code to analyze the audio realtime to show a level meter.

You might actually be able to use most of that level meter code to respond to 'highs' and 'lows'.


The AurioTouch example code performs Fourier analysis on the mic input. Could be a good starting point:

https://developer.apple.com/iPhone/library/samplecode/aurioTouch/index.html

Probably overkill for your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜