本文介绍了为什么averagePowerForChannel总是返回-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];

这些代码开始记录:

[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);
}

但是我不知道为什么peakPower总是160.我有另一个演示(来自Web)可以很好地工作,但是我发现它们之间没有任何区别.

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.

推荐答案

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

It is strange that [audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: &err] and [[AVAudioRecorder alloc] initWithURL: [NSURL fileURLWithPath: self.recordPath] settings: recordSetting error: NULL] must in the same function...It is the answer of this question.

这篇关于为什么averagePowerForChannel总是返回-160?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 01:32