如何用 Cocoa 获得准确的分贝值?

发布于 2024-08-02 12:11:39 字数 714 浏览 8 评论 0原文

我们正在创建一个应用程序,它可以记录周围的声音,并在声音超过指定分贝时采取必要的措施。

为了实现应用程序目标,我们使用 AudioQueueObject.h 中的以下方法

- (void) getAudioLevels: (Float32 *) levels peakLevels: (Float32 *) peakLevels {

UInt32 propertySize = audioFormat.mChannelsPerFrame * sizeof (AudioQueueLevelMeterState);
AudioQueueGetProperty(
self.queueObject,
(AudioQueuePropertyID)kAudioQueueProperty_CurrentLevelMeterDB,
self.audioLevels,
&propertySize);

levels[0] = self.audioLevels[0].mAveragePower;
peakLevels[0] = self.audioLevels[0].mPeakPower;
}

我们有以下一组查询

  1. 录制的声音显示从 -60 开始的分贝值。当声音变大时,该值会继续增加。该对象记录的最大值为 0.0000。请向我们解释如何解释这些值。

根据文档,它说我们得到的值是数字分贝,需要转换为模拟分贝,请建议是否有任何方法可以做到这一点。

提前致谢

We are creating an application which records the surrounding sound and take necessary action if the sound crosses specified Decibel.

In order to achieve the application objective we are using following method from AudioQueueObject.h

- (void) getAudioLevels: (Float32 *) levels peakLevels: (Float32 *) peakLevels {

UInt32 propertySize = audioFormat.mChannelsPerFrame * sizeof (AudioQueueLevelMeterState);
AudioQueueGetProperty(
self.queueObject,
(AudioQueuePropertyID)kAudioQueueProperty_CurrentLevelMeterDB,
self.audioLevels,
&propertySize);

levels[0] = self.audioLevels[0].mAveragePower;
peakLevels[0] = self.audioLevels[0].mPeakPower;
}

We have the following set of queries

  1. The recorded sound shows the value in Decibel starting from -60. This value goes on increasing the moment sound gets louder. Maximum value recorded with this object is 0.0000. Please explain us how to interpret these values.

as per the documentation it says the values which we are getting is in digital decibels which needs to be converted to analog ,please suggest if there is any way of doing that.

thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵性 2024-08-09 12:11:39

我认为您的部分困惑涉及分贝一词:分贝是一个对数单位,表示相对于参考值的大小(请参阅分贝)。尽管 dB 经常用于表示声压或声级,但分贝有许多不同的种类。

kAudioQueueProperty_CurrentLevelMeterDB 返回的值以 dBFS(满量程分贝)为单位。 dBFS 是纯数字测量,其中 0 表示样本可以包含的最大值(浮点数为 1.0,16 位样本为 32767 等),所有其他值均为负值。因此,值为 0.5 的浮点样本将记录为 -6 dBFS,因为 20 * log10 (0.5 / 1.0) = -6.02

您想要做的是将 dBFS(数字测量)转换为 dBu 或 dB SPL(都是模拟测量) - dBu 参考 0.775 伏 RMS,dB SPL 参考 20 µPa 声压)。

由于 dB SPL 不是 SI 单位,因此我的意思是在耳朵处测量的声源与参考之间的测量声压之比的 20 * log10。这些是喷气发动机、手提钻、耳语、枪声等给出的正常值。

您无法准确地执行您想要的转换,因为 dBFS 只是数字信号值相对于它可以包含的最大值的度量 - 它承受与 dBu 或 dB SPL 或任何其他声压或响度测量没有直接关系。

使用校准系统可以确定两个值之间的关系,但对于用于一般消费的应用程序,我不确定如何解决这个问题。一种可能的方法是测量麦克风对于各种已知频率和声级的输入电平,然后将数据与您所看到的相关联。

I think part of your confusion concerns the term decibel: a decibel is a logarithmic unit that expresses the magnitude of a value relative to a reference (see Decibel). Although dB is frequently used to mean sound pressure or sound level, there are many different kinds of decibels.

The values returned by kAudioQueueProperty_CurrentLevelMeterDB are in dBFS (decibels full scale). dBFS is a digital-only measurement where 0 represents the maximum value a sample can contain (1.0 for floats, 32767 for 16 bit samples, etc), and all other values will be negative. So a float sample with a value of 0.5 would register as -6 dBFS since 20 * log10 (0.5 / 1.0) = -6.02

What you want to do is convert from dBFS (a digital measure) to dBu or dB SPL (both analog measures- dBu is referenced to 0.775 volts RMS and dB SPL to 20 µPa sound pressure).

Since dB SPL is not an SI unit, I mean 20 * log10 of the ratio of measured sound pressure between a source and a reference as measured at the ear. These are the normal values given for jet engines, jackhammers, whispers, gunshots, etc.

You can't accurately perform the conversion you want because dBFS is simply a measure of a digital signal's value relative to the maximum value it can contain- it bears no direct relation to dBu or dB SPL or any other measure of sound pressure or loudness.

It would be possible with a calibrated system to determine the relationship between the two values, but for an application meant for general consumption I'm not sure how you can attack this. One possible approach would be to measure the input level of the microphone for various known frequencies and sound levels and then correlate the data to what you are seeing.

一人独醉 2024-08-09 12:11:39

数字音频由具有特定绝对范围的样本值组成(对于 CD 类型音频为 32767 到 -32768,或者对于浮点为 +1.0 到 -1.0)。我假设 Cocoa 生成浮点音频数据。

分贝值是音量的相对对数度量。分贝值 0 表示音量尽可能大,这对应于 +1.0 或 -1.0 的绝对样本值。 这个较早的问题给出了将分贝值转换为增益的公式(增益与分贝相反,是音量的简单线性乘数)。根据公式,-20 dB 的分贝值对应于 0.1 的增益,这意味着您的绝对样本值为 +0.1 或 -0.1。 -40 dB 相当于 0.01 增益,-60 dB 相当于 0.001 增益。

Digital audio consists of sample values with a particular absolute range (32767 to -32768 for CD-type audio, or +1.0 to -1.0 for floating-point). I'll assume Cocoa produces floating point audio data.

Decibel values are a relative logarithmic measure of volume. A decibel value of 0 means that the volume is as loud as it can possibly be, which corresponds to absolute sample values of +1.0 or -1.0. This earlier question gives a formula for converting decibel values to gain (gain, in contrast to decibels, is a simple linear multiplier of volume). From the formula, a decibel value of -20 dB corresponds to a gain of .1, which means your absolute sample value would be +0.1 or -0.1. -40 dB is the equivalent of a .01 gain, and -60 dB is the equivalent of a .001 gain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文