拙网论坛

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 237|回复: 2

通过pcm音频数据计算分贝

[复制链接]

949

主题

1001

帖子

3736

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3736
发表于 2018-7-30 20:09:25 | 显示全部楼层 |阅读模式

https://blog.csdn.net/cabbage2008/article/details/52043646
https://www.jianshu.com/p/d3745dd23056

很多场合我们需要动态显示实时声音分贝,下面列举三种计算分贝的算法。(以双声道为例,也就是一个short类型,最大能量值为32767)
1:计算分贝  音频数据与大小首先我们分别累加每个采样点的数值,除以采样个数,得到声音平均能量值。
然后再将其做100与32767之间的等比量化。得到1-100的量化值。
通常情况下,人声分布在较低的能量范围,这样就会使量化后的数据大致分布在1-20的较小区间,不能够很敏感的感知变化。
所以我们将其做了5倍的放大,当然计算后大于100的值,我们将其赋值100.

3:获取音频数据最大的振幅(即绝对值最大)(0-32767),除以1000,得到(0-32)。从数组中获取相应索引所对应的分贝值。(提取自webrtc)

作者:今忆Zoe
链接:https://www.jianshu.com/p/d3745dd23056
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

db的定义

首先,DB(Decibel,分贝)1是一个表征相对值的大小的单位,即两种电或声功率之比或两种电压或电流值或类似声量之比。它还是一种测量声音相对响度的单位。
(1)表示两种电或声功率之比的一种单位,它等于功率比的常用对数的10倍。dB = 10lgX,常用于按功率来计算的带宽;-3db是指功率变为原来的1/2,10lg0.5= -3,-3dB在10进制中等同于0.5;下降3dB也就是功率下降一半,-3dB点指的是半功率点。此参数多用于二维图形解析。
(2)表示两种电压或电流值或类似声量(如声压或质点速度)之比的一种单位,等于电压或电流比的常用对数的20倍,如果两种电压或电流是在相同电阻上测得的话。dB = 20lgX,常用于电压/电流增益;-3db是指幅度变为原来的(根号2)/2,就是0.707倍,20lg((根号2)/2)= -3。

db的意义

其实再简单不过了,就是把一个很大(后面跟一长串0的)或者很小(前面有一长串0的)的数比较简短地表示出来[2]。dB的引入是为了将乘除关系变为加减关系,更便于工程运算。如:
X = 1000000000000000= 10lgX = 150 dB
X = 0.000000000000001 = 10lgX = -150 dB
[例1] 甲功率比乙功率大一倍,那么10lg(甲功率/乙功率)=10lg2=3dB。也就是说,甲的功率比乙的功率大3 dB。
[例2] 7/8英寸GSM900馈线的100米传输损耗约为3.9dB。
[例3] 如果甲的功率为46dBm,乙的功率为40dBm,则可以说,甲比乙大6 dB。
[例4] 如果甲天线为12dBd,乙天线为14dBd,可以说甲比乙小2 dB。

lg的计算

lg就是以10为底的log。
(1)10lg2 = lg2^10 = lg1024,又因为lg1000 = 3,所以10lg2≠3,但非常接近[3]。
(2)lg4=lg(2×2)=lg2+lg2=2lg2≈0.6
(3)lg4=lg(2^2) =2lg2≈0.6
(4)10lg0.5=10 lg(2^(-1))=-10lg2≈-3

分贝毫瓦dBm

dBm[4]全写为 decibel relative to one milliwatt , 为功率的绝对值,而不同于dB只是一个相对值。
任意功率P(mW)与x(dBm)换算的公式如下:
例如,1毫瓦(1 mW)换算成分贝毫瓦为0dBm;1瓦(1 Watt)换算成分贝毫瓦则为30dBm。






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

949

主题

1001

帖子

3736

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3736
 楼主| 发表于 2018-7-30 20:13:26 | 显示全部楼层

Make sure that you use this formula



dB (SPL) = 10 log (P/Pref)^2 = 20 log (ABS(P/Pref))



CoastalMaineBird wrote



"Note also that you can't measure SPL unless you have a calibrated microphone and a known amplification path.  Measuring volts by itself will not be accurate unless you can  A) verify the gain between the mike and the measurement, and B) verify the mike's pressure -to-signal conversion ratio.  Your typical computer's microphone and amplifier are not intended for precise measurements of this sort. "



This is absolutly correct. You are NOT able to measure the correct value of any sound related physical value without using sophisticated measurment equipment AND sophisticated measurment environment like isolated sound chambers etc.! Forget it to get values related to real world using the build in soundcard of your computer.



The formula refers the measured sound pressure to a reference pressure. This makes it possible to compare the dB values of different measurement, but the dB values you get have nothing to do with "real" values measured with professional equipment or taken from datasheets. Common condensator microphones convert the sound pressure to voltage, i.e. the value (=voltage) you get from the soundcard input is proportional to the sound pressure, but there maybe a frequency depending sensitivity of the microphone.



To calibrate the setup you need a standard sound source, e.g. your systems soundcard output and a speaker,  AND of at least same importance a standard measurement setup, i.e. always the same geometry/distances/environment between speaker and microphone. Make sure to damp environmental noise as far as possible!!
回复

使用道具 举报

949

主题

1001

帖子

3736

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
3736
 楼主| 发表于 2018-7-31 09:27:37 | 显示全部楼层


[deleted]
3 points
·
4 years ago
dB is your measure of amplitude - in sound, it's db SPL (sound pressure level) which ranges from 0 onwards. In Digital audio, it'd be db FS (full scale) which would be from -infinity to 0. in this case 0 db FS would be the max you can go (typically means you've filled all the 24 bits). So all WAV files essentially have this information in dB FS. You don't need any conversion as db is just a measure of your amplitude. All DAWs have a meter to show roughly what level of db FS you might be recording at.

Share
Save


yeayoushookme
2 points
·
4 years ago
·
edited 4 years ago
Correction: dB SPL goes from negative infinity (-inf dB SPL = 0Pa) and doesn't have a high bound. Practically it's limited by air's thermal noise, so you can't go few dozen dB SPL below zero.

Atmospheric pressure is 190dB SPL, or 105 Pa, so everything above that is no longer sound, but a shockwave

Share
Save


[deleted]
2 points
·
4 years ago
·
edited 4 years ago
you're right, and thanks for the correction. But what I meant was (which i didn't explain upon) that since we consider hearing threshold at 0 db, we generally say that db SPL starts from 0 for all practical purposes. But thanks for the correction

Share
Save


[deleted]
1 point
·
4 years ago
Thanks!

Share
Save


yeayoushookme
2 points
·
4 years ago
·
edited 4 years ago
You would need a reference, which could be attained with a calibrated SPL meter. You start playing back a sound on a speaker, and you measure it with both mics at the same position. E. G. if the sound is 50dB SPL, as shown by the sound pressure meter, and the recording is at -24dBFS, then you can get the SPL value by adding 74dB to the recorded level.

Share
Save


[deleted]
1 point
·
4 years ago
Thanks!

Share
Save
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|抱朴守拙BBS

GMT+8, 2025-5-26 04:17 , Processed in 0.195620 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表