Why I am getting Negative Decibels (around -70dB) where Normal Speech around 60dB

Hi all…

I try to monitor sound decibels using this [scripts][1]
but why i am getting Negative Decibels ?

in [theory][2], sound from Normal Conversation will result 60db and even silent room will make 10-20dB…

any idea ?

Result of Decibels Calculation :
![alt text][3]

Below are my source :

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class VR_SoundMonitor : MonoBehaviour {

//===>PUBLIC
	public float DecibleValue;
	public float RmsValue; // { get; set; }
	public float PitchValue;// { get; set; }
	private AudioSource audioSourceObject;

//===>PRIVATE
	private float[] _spectrum;
	private float[] _samples;
	private float _fSample;

//===>KONSTANTA
	const int QSamples = 1024;
	const float RefValue = 0.1f;
	const float Threshold = 0.02f;

	// Pre Initialization...
	void Awake(){

	}

	// Use this for initialization
	void Start () {
		audioSourceObject = GetComponent<AudioSource> ();
		InitVariable ();
		InitMicrophone ();
	}

	//Nyalakan Microphone
	private void InitMicrophone()
	{
		
//		audioSourceObject.pitch = 1.0f;
		audioSourceObject.clip = Microphone.Start ("SoundMonitoring", false, 60, 44100);
		while (!(Microphone.GetPosition(null) > 0)) { }    //TODO: untoggle
		audioSourceObject.Play();
//		audioSourceObject.mute = true;

	}

	private void InitVariable()
	{
		_samples = new float[QSamples]; //use constanta (3 below)
		_spectrum = new float[QSamples];
		_fSample = AudioSettings.outputSampleRate;
	}

	// Update is called once per frame
	void Update () {
		CalculateAnalyzeSound (audioSourceObject);
		Debug.Log ("Decibels="+DecibleValue+" ## RmsVal="+RmsValue);
	}

	public void CalculateAnalyzeSound(AudioSource audio)
	{
//===>VARIABLE...
 		float _RmsValue;
 		float _DbValue;
 		float _PitchValue;

//===>IMPORT DATA...
		audio.GetOutputData(_samples, 0);
		int i = 0;
		float sum = 0;

		for (i = 0; i < QSamples; i++)
		{
			sum += _samples <em>* _samples*; // sum squared samples*</em>

* }*

//===>CALCULATE
* _RmsValue = Mathf.Sqrt(sum / QSamples); // rms = square root of average*
_DbValue = 20 * Mathf.Log10(_RmsValue / RefValue); // calculate dB
* if (_DbValue < -160) _DbValue = -160; // clamp it to -160dB min*

// //(OLD) GetComponent().GetSpectrumData(_spectrum, 0, FFTWindow.BlackmanHarris);
// audio.GetSpectrumData (_spectrum, 0, FFTWindow.BlackmanHarris);
//
// float maxV = 0;
// var maxN = 0;
// for (i = 0; i < QSamples; i++)
// { // find max
// if (!(spectrum > maxV) || !(spectrum > Threshold))
// continue;

//
// maxV = spectrum*;*
// maxN = i; // maxN is the index of max
// }
// float freqN = maxN; // pass the index to a float variable
// if (maxN > 0 && maxN < QSamples - 1)
// { // interpolate index using neighbours
// var dL = _spectrum[maxN - 1] / _spectrum[maxN];
// var dR = _spectrum[maxN + 1] / _spectrum[maxN];
// freqN += 0.5f * (dR * dR - dL * dL);
// }_

// _PitchValue = freqN * (_fSample / 2) / QSamples; // convert index to frequency

//===>RETURN VALUES (FINAL)
* RmsValue = RmsValue;
DecibleValue = DbValue;
// PitchValue = PitchValue;
}//end_CoreAnalyzeSound(…)
}//end_All*

*[1]: http://answers.unity3d.com/questions/157940/getoutputdata-and-getspectrumdata-they-represent-t.html*_

*[2]: http://www.noisehelp.com/noise-level-chart.html*_

*[3]: http://i.imgur.com/wrCgUCO.png*_

Decibels are relative measurement units: 10 times the log10 of output power/reference power, or 20 times log10 of output voltage/reference voltage.
Since the samples are directly proportional to the output voltage, I’ve adopted 20*log10(samplesRMS/refValue). But the value adopted as refValue is totally arbitrary - there’s no fixed relationship between sample value and the actual output power because it depends on the hardware, the master volume, the speakers etc.

You can get bigger dB values by simply reducing refValue: if refValue is reduced from 0.1f to 0.01f, for instance, the results will get 20dB higher; if reduced to 0.001f, the results will grow 40dB.

@aldonaletto Thank you so much for your expertise in this. I have been trying to find the decibel value of an audio input through my Microphone but get a value of -160(it shows a value -infinity when clamping is removed).
What do you think I must change ? Reducing the RefValue doesn’t make a difference.

Hoping for your quick response,
Thanks in advance.

@Bunny83 Thank you for your response ! Yes, that makes sense. So it turns out that I have to play the audio clip I recorded from the microphone with a delay of at least one second to see some sort of an increase in Db Value.
Is there a way I can analyse the microphone input to calculate the Db value without a play back ?

Thanks,
Udit Khiraiya.