2015-01-14 31 views
2

我想用NOVOCAINE來計算dB,所以我的問題是我可以通過計算RMS來測量分貝。其實我想iphone的麥克風作爲輸入和監測周圍的噪音。 我無法解決這個問題。請幫忙。使用NOVOCAINE計算dB

請給出任何例子

+1

dB是功率的對數比率,而不是幅度,因此需要考慮。 RMS只是幅度。 – zaph

+1

可能重複[如何獲得準確的分貝水平與可可?](http://stackoverflow.com/questions/1281494/how-to-obtain-accurate-decibel-leve-with-cocoa) – sbooth

回答

1

基本上,這是背後的分貝滿刻度數學:

Math behind dB fullscale

其中b是位深度,在iOS b = 16More on Wikipedia

這可以在某種程度上來實現,諸如如下:

const float min = 20.0f*log10f(powf(2, 15)); // the "most silent" sample 

Novocaine *audioManager = [Novocaine audioManager]; 
[audioManager setInputBlock:^(float *newAudio, UInt32 numSamples, UInt32 numChannels) 
{ 
    float f = 0.0f; 
    for (int i = 0; i<numSamples; i++) 
    { 
      f += fabsf(newAudio[i]); // we are only interested in non-imaginary values 
    } 
    f /= numSamples; // kind of a poor averaging... 
    float value_dB = 20.0f*log10f(f) - min; // dB in full scale 
    NSLog(@"%f dB for %f", value_dB, f); // or do whatever you want to do... 
}]; 
[audioManager play]; 

但是你應該考慮的採樣頻率和召回,這是分貝滿刻度,不dB SPLdB SIL

+1

這將給你dBFS ,而不是所期望的dB SPL。無需外部校準就無法計算dB SPL。 – sbooth

+0

你是對的,但這個解決方案是沒有校準就可以做到的。 –