AVAudioRecorder meter delay on iPad

a 夏天 提交于 2019-12-05 13:09:34
krut

I'm sure that most have figured this out but if you want less lag on your metering you need to use AudioQueue or RemoteIO. See the better explanation here:

Confusion with meters in AVAudioRecorder

You can fix this by resetting the meteringEnabled property to YES.

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.

How about using a timer ? it would be mutch quicker after

NSError* error
        if (recorder) {
            recorder.meteringEnabled = YES;
            [recorder record];
            levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.2 target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
    } else
            NSLog(@" error %@",[error description]);
        }

Where levelTimer is the NStimer that calls the function that does what you want(levelTimerCallback:), updates the meters, etc.

   -(IBAction)levelTimerCallback:(NSTimer*)timer
{
     [recorder updateMeters];
        float level = [recorder peakPowerForChannel:0];
        NSLog(@"Vol: %f", level);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!