Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AVAudioRecorder Average PowerForChannel返回的值无效_Ios_Objective C_Iphone_Ipad_Avaudiorecorder - Fatal编程技术网

Ios AVAudioRecorder Average PowerForChannel返回的值无效

Ios AVAudioRecorder Average PowerForChannel返回的值无效,ios,objective-c,iphone,ipad,avaudiorecorder,Ios,Objective C,Iphone,Ipad,Avaudiorecorder,我最近收到一些用户的抱怨:当他们在iOS 10下录音时,麦克风“太敏感”并且“严重失真”。该话筒在其他应用程序和较旧的操作系统版本下运行良好 首先,我将“旧”核心AudioQueueRef解决方案替换为AVAudioRecorder。这并没有帮助,所以我试图深入研究这个问题,并发现了一个有趣的行为:-[AVAudioRecorder averagePowerForChannel:方法在静默环境中至少返回-52db。如果我开始在麦克风周围刮(或吹)框架,该值达到+25db 而苹果的文档说: 返回值

我最近收到一些用户的抱怨:当他们在iOS 10下录音时,麦克风“太敏感”并且“严重失真”。该话筒在其他应用程序和较旧的操作系统版本下运行良好

首先,我将“旧”核心
AudioQueueRef
解决方案替换为
AVAudioRecorder
。这并没有帮助,所以我试图深入研究这个问题,并发现了一个有趣的行为:
-[AVAudioRecorder averagePowerForChannel:
方法在静默环境中至少返回-52db。如果我开始在麦克风周围刮(或吹)框架,该值达到+25db

而苹果的文档说:

返回值

正在录制的声音的当前平均功率,单位为分贝。 0 dB的返回值表示满刻度或最大功率;A. 返回值-160 dB表示最小功率(即接近 沉默)

如果提供给音频记录器的信号超过±满刻度,则 返回值可能超过0(也就是说,它可能输入正值 射程)

static const CGFloat kSilenceDBValue=-160.0;//基于-[AVAudioRecorder Average PowerForChannel]的文档
对于(整数i=0;istatic const CGFloat kSilenceDBValue = -160.0;  // based on the documentation of -[AVAudioRecorder averagePowerForChannel]


for (NSUInteger i = 0; i < ASAudioRecorderNumberOfChannels; ++i) {
    const CGFloat averageLevel = (CGFloat)[self.recorder averagePowerForChannel:i];
    const CGFloat peakLevel = (CGFloat)[self.recorder peakPowerForChannel:i];

    // Assert fires if stressing the mic 
    NSAssert1(kSilenceDBValue <= averageLevel && averageLevel <= 0.0, @"Average level has invalid value: %@", @(averageLevel));
    NSAssert1(kSilenceDBValue <= peakLevel && peakLevel <= 0.0, @"Peak level has invalid value: %@", @(peakLevel));

    ...
}