音频记录类:计算噪音水平

时间:2014-05-20 10:12:45

标签: android audiorecord decibel

我正在尝试使用音频记录类而不是getMaxAmplitude()函数开发一个Android应用程序(声音计)。

我按照这个链接去做了:

Is there any Sound filtering library in android

我对此代码有几个问题:

  1. 如何计算calculatePowerDb()函数的功效?为什么我们做样品的平方米?换句话说,这个等式“power =(sqsum - sum * sum / samples)/ samples”代表什么?
  2. 是输出值“return Math.log10(power)* 10f + FUDGE;”是两个电源(power leve / ref_power)之间的差异?
  3. 事实上,我不明白这个功能:

    public final static double calculatePowerDb(short[] sdata, int off, int samples){
    
    // Calculate the sum of the values, and the sum of the squared values.
    // We need longs to avoid running out of bits.
       double sum = 0;
       double sqsum = 0;
       for (int i = 0; i < samples; i++) {
       final long v = sdata[off + i];
       sum += v; // Ok until here I understand
       sqsum += v * v; //why this??
       }
    
           double power = (sqsum - sum * sum / samples) / samples;//what's this equation?
    
       // Scale to the range 0 - 1.
       power /= MAX_16_BIT * MAX_16_BIT;
    
       // Convert to dB, with 0 being max power.  Add a fudge factor to make
       // a "real" fully saturated input come to 0 dB.
       return Math.log10(power) * 10f + FUDGE; //the value is at decibel? 
                                        //if it is, is it a db(a) value, 
                                        //a power level value 
                                        //or a pressure level value ?
       }
    

    此代码返回负值(希望声功率)并在设备上进行一些校准后工作正常(加/撤比率)

    现在,我想了解这段代码的某些部分(上面已经评论过)。

    感谢您的回复和所有可以做的细节!

1 个答案:

答案 0 :(得分:0)

power 值正在计算信号的方差,并且它被归一化为用于计算它的样本数。基本上,它显示了最高记录样本值的强度与最低值之间的差异,或更准确地说 - 它是设备捕获的样本分布扩散的度量。这是信号功率的常用量度。

如果您的参考功率为 MAX_16_BIT * MAX_16_BIT ,那么当您有信号功率时,返回值只是分贝的标准定义。请在此处查看维基页面的分贝:{{3 }}

您可能还想查看: http://en.wikipedia.org/wiki/Decibel