iPad上的AVAudioRecorder米延迟 [英] AVAudioRecorder meter delay on iPad

查看:181
本文介绍了iPad上的AVAudioRecorder米延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从AVAudioRecorder获得准确的抄表(在iPad上进行测试)。

I am having trouble getting an accurate meter reading from the AVAudioRecorder (testing on iPad).

当音量上升时似乎工作正常,但是当音量下降时会发生延迟。例如:我对着麦克风说话,然后慢慢抬起我的声音。正如我所希望的那样,读数从-35.567增加到-34.678到-10.579,但是当我停止说话时,它会延迟1到2秒,然后再下降到-35.567(或者无论发生什么)。
NSLog继续从循环更新但是在延迟期间仪表编号保持不变,即使声音已经结束了。

It seems to work fine while the volume is rising, however a delay happens when the volume drops. For example: I speak into the mic and slowly raise my voice. The readings increment from -35.567 to -34.678 up to -10.579 as I would hope, but when I stop talking there is a delay of 1 - 2 seconds before it drops back down to -35.567 (or whatever it happens to be). The NSLog continues to update from the loop but the meter number stays the same during the delay even though the sound has long ended.

我添加了要点下面的代码,如果需要的话,很乐意提供完整的代码。

I have added the gist of the code below and would be happy to supply full code if need be.

我像这样初始化录像机:

I initialize the recorder like so:

AVAudioSession * audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error: &error];
[audioSession setActive:YES error: &error];

NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory()  stringByAppendingPathComponent: [NSString stringWithString: @"Recording.caf"]]];

recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder setMeteringEnabled:YES];

[recorder record];

并循环更新仪表:

-(void) loop:(ccTime)dt 
{
    if(isRecording == YES)
    {        
        //get volume levels
        [recorder updateMeters];
        float level = [recorder peakPowerForChannel:0];
        NSLog(@"Vol: %f", level);
    }
}

已编辑:我应该还提到我使用循环的Cocos2d计划:

edited: I should also mention that I am using the Cocos2d schedule for the loop:

[self schedule:@selector(loop:)];

为什么会出现如此长的延迟?

Any ideas why there would be such a long delay?

编辑:我尝试过使用平均峰值功率,这没有延迟。所以我可以用它作为一种解决方法。但是我宁愿不使用和平均峰值功率,也很好理解发生了什么。

edited: I have tried using the average peak power and this has no delay. So I could possibly use that as a work around. However I would rather not use and averaged peak power and it would be nice to understand what is going on.

推荐答案

我是确定大多数人已经想到了这一点,但如果你想减少计量延迟,你需要使用AudioQueue或RemoteIO。请在此处查看更好的解释:

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:

混淆AVAudioRecorder中的米数

这篇关于iPad上的AVAudioRecorder米延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆