开发者

Confusion with meters in AVAudioRecorder

Simply put, I'm trying to lip-sync something based on the decibel reading from the mic input stream of an iPhone, and the values I'm getting aren't quite what I'm after. I'm using AVAudioRecorder's peakPowerForChannel and averagePowerForChannel. (I'm aware that this is a rather simplistic lip-sync technique, but quality isn't a major concern).

When the number of decibels increases, the meters react as I'd like them to (higher valu开发者_Go百科e when louder, so I can map this to the open-ness of the mouth) but when the sound stops quickly, the values decrease slowly, as though the sound was trailing off (i.e. fading to silence over a second or two) - not what I'd like.

Is there a way of configuring the AVAudioRecorder so that it doesn't have this 'fade' effect, or can I do something with the values that it gives me to get the desired output? Alternatively, is there another tool I can use?

Thanks!


You can reset the meteringEnabled property to YES, like this:

yourRecorderName.meteringEnabled = YES

Call this every time you want the levels to reset to ambient levels. This takes about 0.02 seconds, and in that time the levels will briefly drop down to 0, or -120 dB before resetting to ambient.

Alternatively, you can use:

[yourRecorderName stop]
[yourRecorderName record]

This takes about 0.05 seconds, but the levels won't drop down to 0 in the wait time. In fact, nothing will happen because in this case, it actually takes the recorder object 0.05 seconds to stop and start recording again.


The meter ballistics on AVAudioPlayer are what you'd expect for displaying traditional audio meters: Instantaneous for increases in amplitude, but lowpassed for decreases.

For the Talking Carl-type thing where you animate a character based on recorded audio you'll have to get at the raw audio and tweak your own metering response as appropriate. If you're animating the character live (i.e., while the user talks in the device's microphone) you'll probably want to use AudioQueue or RemoteIO to get at the audio data. Otherwise, if you're just processing an audio file after it's been recorded, you can get the data you need using ExtAudioFile.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜