我很討厭這段代碼。 我試圖讓averagePowerForChannel和peakPowerForChannel同時錄製音頻,但每次我得到它爲0.0在AVAudioRecorder中爲Channel獲取AveragePower和PeakPower
下面是我錄製音頻代碼:
NSMutableDictionary *recordSetting =[[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithFloat: 22050.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatLinearPCM], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
[NSNumber numberWithInt:32],AVLinearPCMBitDepthKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsBigEndianKey,
[NSNumber numberWithBool:NO],AVLinearPCMIsFloatKey,
nil];
recorder1 = [[AVAudioRecorder alloc] initWithURL:[NSURL fileURLWithPath:audioFilePath] settings:recordSetting error:&err];
recorder1.meteringEnabled = YES;
recorder1.delegate=self;
[recorder1 prepareToRecord];
[recorder1 record];
levelTimer = [NSTimer scheduledTimerWithTimeInterval: 0.3f target: self selector: @selector(levelTimerCallback:) userInfo: nil repeats: YES];
- (void)levelTimerCallback:(NSTimer *)timer {
[recorder1 updateMeters];
NSLog(@"Peak Power : %f , %f", [recorder1 peakPowerForChannel:0], [recorder1 peakPowerForChannel:1]);
NSLog(@"Average Power : %f , %f", [recorder1 averagePowerForChannel:0], [recorder1 averagePowerForChannel:1]);
}
什麼是在代碼中的錯誤? ??
謝謝!我不能相信我錯過了這一點。 (這就是'meteringEnabled'。頻道數量無關緊要,我很肯定。) – Kalle 2012-08-14 20:53:00