简体   繁体   English

为什么averagePowerForChannel总是返回-160?

[英]Why does averagePowerForChannel always return -160?

I have these code and both method call are SUCCESS. 我有这些代码,并且两个方法调用均成功。

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

And these code to start recording: 然后这些代码开始记录:

[self.recorder prepareToRecord];
[self.recorder recordForDuration: 60];

I have a timer function to update meters 我有计时器功能来更新仪表

- (void)updateMeters
{
    [self.recorder updateMeters];
    float peakPower = [self.recorder averagePowerForChannel: 0];
    double ALPHA = 0.05;
    double peakPowerForChannel = pow(10, (ALPHA * peakPower));
    self.recordView.progress = peakPowerForChannel;

    NSLog(@"%f", peakPower);
}

But I do not know why peakPower is always 160. I have another demo(from web) can work well, but I can not find any difference between them. 但是我不知道为什么peakPower总是160。我有另一个演示(来自Web)可以很好地工作,但是我发现它们之间没有任何区别。

只需尝试设置:

   recorder.meteringEnabled = YES;

Set the category to AVAudioSessionCategoryPlayAndRecord and check 将类别设置为AVAudioSessionCategoryPlayAndRecord并检查

NSError *error;
[[AVAudioSession sharedInstance] 
    setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];

if (error) {
    NSLog(@"Error description: %@", [error description]);
}

奇怪的是[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &err][[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath: self.recordPath] settings: recordSetting error: NULL]必须具有相同的功能...这就是答案题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AVAudioRecorder averagePowerForChannel始终返回-120.0 - AVAudioRecorder averagePowerForChannel always returns -120.0 为什么indexPathForItemAtPoint总是返回nil - Why does indexPathForItemAtPoint always return nil 为什么NSUserDefaults总是返回nil? - Why does NSUserDefaults always return nil? 为什么 - [UIKeyInput hasText]总是为UITextField返回NO? - Why does -[UIKeyInput hasText] always return NO for UITextField? 为什么 UIView 的 intrinsicContentSize 总是返回 (-1.0, -1.0)? - Why does intrinsicContentSize for UIView always return (-1.0, -1.0)? 为什么我的UITextField总是返回数组中的最后一个值? - Why does my UITextField always return the last value in my array? 为什么UIAccessibilityIsGuidedAccessEnabled()总是返回NO? - why UIAccessibilityIsGuidedAccessEnabled() always return NO? keyWindow并不总是返回UIWindow - keyWindow does not always return a UIWindow 为什么[response expectedContentLength]总是返回-1 - why [response expectedContentLength] always return -1 为什么Bundle.main.path(forResource:fileName,ofType:“ txt”)总是返回nil? - why does Bundle.main.path(forResource: fileName, ofType: “txt”) always return nil?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM