计算分贝 [英] Calculate decibels

查看:145
本文介绍了计算分贝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用XNA库(我不认为这真的是具体的技术,但它绝不会伤害)录制麦克风输入。每当我得到的样本,我想计算分贝。我已经做了很多的搜索在互联网上,并没有找到一个坚如磐石的例子...

I'm recording mic input using the XNA library (I don't think this is really technology specific, but it never hurts). Every time I get a sample I would like to calculate the decibels. I have done many searches on the internet and not found a rock solid example...

下面是我从样本计算分​​贝的尝试:

Here is my attempt at calculating decibels from a sample:

        double peak = 0;

        for (var i = 0; i < _buffer.Length; i = i + 2)
        {
            var sample = BitConverter.ToInt16(_buffer, i);
            if (sample > peak)
                peak = sample;
            else if (sample < -peak)
                peak = -sample;
        }

        var decibel = (20 * Math.Log10(peak/32768));

如果我输出的分贝值在屏幕上,我可以看到的价值观得到更高的,因为我得到响亮,下为我说话柔和。然而,它始终徘徊在-40时,我绝对安静......我会假设这将是-90。我必须有一个计算错误在上面的块?从我读过一些网站-40相当于软说话......然而,这是完全安静。

If I output the decibel value to the screen I can see the values get higher as I get louder and lower as I speak softer. However, it always hovers around -40 when I'm absolutely quiet...I would assume it would be -90. I must have a calculation wrong in the block above?? from what I have read on some sites -40 is equivalent to "soft talking"...however, it's totally quiet.

另外,如果我静音我的麦克风,它直接为-90。

Also, If I mute my mic it goes straight to -90.

难道我做错了?

推荐答案

在测量声音信号的电平,你应该从RMS值计算分贝。在您的样品你正在寻找的绝对峰值电平。单(峰值)采样值决定了你的分贝值,即使在其他所有样品中是完全0。

When measuring the level of a sound signal, you should calculate the dB from the RMS value. In your sample you are looking at the absolute peak level. A single (peak) sample value determines your dB value, even when all other samples are exactly 0.

试试这个:

double sum = 0;
for (var i = 0; i < _buffer.length; i = i + 2)
{
    double sample = BitConverter.ToInt16(_buffer, i) / 32768.0;
    sum += (sample * sample);
}
double rms = Math.Sqrt(sum / (_buffer.length / 2));
var decibel = 20 * Math.Log10(rms);

有关'瞬间'分贝水平,你通常会在20-50毫秒段计算RMS。
注意,计算出的dB值是相对于满刻度。对于声音的分贝值应该与20 UPA,你将需要校准信号,找到的数字值pressure值正确转换。

For 'instantaneous' dB levels you would normally calculate the RMS over a segment of 20-50 ms. Note that the calculated dB value is relative to full-scale. For sound the dB value should be related to 20 uPa, and you will need to calibrate your signal to find the proper conversion from digital values to pressure values.

这篇关于计算分贝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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