如何获取当前音频输出设备的当前声音级别? [英] How can I get the current sound level of the current audio output device?

查看:584
本文介绍了如何获取当前音频输出设备的当前声音级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,在Mac上切换到当前音频输出,然后返回一个表示当前声音级别的值。

I'm looking for a way to tap into the current audio output on a Mac, then return a value representing the current sound level.

通过声音级别,我的意思是输出产生的噪声量。我要求如何获取输出设备的当前音量。

By sound level, I mean the amount of noise being generated by the output. I'm NOT asking how to get the current volume level of the output device.

推荐答案

以下代码摘自 Apple's Sample AVRecorder ...这个特定的代码从这个类的movieFileOutput的连接方法中获取一组连接,获得每个连接的AVCaptureAudioChannel,并基于此计算分贝功率。我会假设,如果你正在寻找一个输出噪音水平,你将能够捕获类似的信息。如果你正在寻找比这低的层次,尝试HAL(硬件抽象层)框架。

the following code is pulled from Apple's Sample AVRecorder … this particular bit of code acquires a set of connections from this class's movieFileOutput's connections methods, gets the AVCaptureAudioChannel for each connection, and calculates decibel power based upon that. i would presume that if you are looking for an output "noise level", you would be able to capture similar information. if you are looking for something lower level than this, try the HAL (Hardware Abstraction Layer) framework.

- (void)updateAudioLevels:(NSTimer *)timer
{
    NSInteger channelCount = 0;
    float decibels = 0.f;

    // Sum all of the average power levels and divide by the number of channels
    for (AVCaptureConnection *connection in [[self movieFileOutput] connections]) {
        for (AVCaptureAudioChannel *audioChannel in [connection audioChannels]) {
            decibels += [audioChannel averagePowerLevel];
            channelCount += 1;
        }
    }

    decibels /= channelCount;

    [[self audioLevelMeter] setFloatValue:(pow(10.f, 0.05f * decibels) * 20.0f)];
}

这篇关于如何获取当前音频输出设备的当前声音级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆