AVF 4 - 音频测量

AVF 4 - 音频测量


关于 metering

AVAudioPlayer 和 AVAudioRecorder 都有 metering 相关方法,用于音频测量

/* metering */

@property(getter=isMeteringEnabled) BOOL meteringEnabled; /* turns level metering on or off. default is off. */  

- (void)updateMeters; /* call to refresh meter values */  // 更新音频测量值,注意如果要更新音频测量值必须设置meteringEnabled为YES,通过音频测量值可以即时获得音频分贝等信息

- (float)peakPowerForChannel:(NSUInteger)channelNumber; /* returns peak power in decibels for a given channel */  // 获得指定声道的分贝峰值,注意如果要获得分贝峰值必须在此之前调用updateMeters方法

- (float)averagePowerForChannel:(NSUInteger)channelNumber; /* returns average power in decibels for a given channel */  // 获得指定声道的分贝平均值,注意如果要获得分贝平均值必须在此之前调用updateMeters方法

/* The channels property lets you assign the output to play to specific channels as described by AVAudioSession's channels property */
/* This property is nil valued until set. */
/* The array must have the same number of channels as returned by the numberOfChannels property. */
@property(nonatomic, copy, nullable) NSArray<AVAudioSessionChannelDescription *> *channelAssignments API_AVAILABLE(ios(7.0), watchos(2.0), tvos(9.0)) API_UNAVAILABLE(macos) ; /* Array of AVAudioSessionChannelDescription objects */

@end


使用

[self.recorder updateMeters];
float avgPower = [self.recorder averagePowerForChannel:0];
float peakPower = [self.recorder peakPowerForChannel:0];
发布了43 篇原创文章 · 获赞 8 · 访问量 4562

猜你喜欢

转载自blog.csdn.net/weixin_45390999/article/details/104558931
今日推荐