简体   繁体   English

从 iOS 和 Objective C 中录制的音频中获取分贝数据

[英]Get Decibels data from recorded audio in iOS and Objective C

I am trying to get decibels values from a recorded audio sample in order to make a wave chart and process its peaks.我正在尝试从录制的音频样本中获取分贝值,以制作波形图并处理其峰值。 At the moment I'm using AVAudioRecorder to record an audio file and access its DB values by using [recorder averagePowerForChannel:0] , called by a timer, however I am facing a limitation.目前,我正在使用AVAudioRecorder录制音频文件并使用由计时器调用的[recorder averagePowerForChannel:0]访问其 DB 值,但是我面临一个限制。 Since I need to be the most precise as possible I have set the timer to repeating at 0.001s, however calling [recorder averagePowerForChannel:0] at each tick outputs the same value multiple times.由于我需要尽可能精确,因此我将计时器设置为以 0.001 秒重复,但是在每个滴答声中调用[recorder averagePowerForChannel:0]会多次输出相同的值。 It seems like the recorder is not able to update the values below 0.2s.似乎记录器无法更新低于 0.2s 的值。 How could I overcome this limitation?我怎样才能克服这个限制?

This is the recorder setting:这是录音机设置:

NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                                  [NSNumber numberWithFloat: 44000.0],                 AVSampleRateKey,
                                  [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                                  [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                                  [NSNumber numberWithInt: AVAudioQualityMax],         AVEncoderAudioQualityKey,
                                  nil];

Then I setup the recorder然后我设置了录音机

recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
    [recorder setMeteringEnabled:YES];
    [recorder prepareToRecord];
    [recorder record];
    timer = [NSTimer scheduledTimerWithTimeInterval:0.001f target:self selector: @selector(cllBack:) userInfo: nil repeats: YES];

And in cllBack I call在 cllBack 我打电话

[recorder updateMeters];
[recorder averagePowerForChannel:0];

Thanks in advance for any help!提前感谢您的帮助!

Solved using AVAudioEngine by installing a tap on bus and analyzing the data.通过在总线上安装分接头并分析数据,使用 AVAudioEngine 解决。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM