This question already has an answer here:
-
How can I calculate audio dB level?
7 answers
Using
WaveFileReader wfr = new WaveFileReader(file);
float[] d = wfr.ReadNextSampleFrame();
I get a float array d
. When iterating through d
using foreach (float s in d)
I get floats between -1.0 and +1.0. How do I convert them to dB(A) of sound pressure?
EDIT: I solved it using double db = 20 * Math.Log10(Math.Abs(s));
The dBA scale is a measure of relative air-pressure.
In this context, we are talking about an audio reproduction system that takes samples at its input and has some type of apparatus that results in sound pressure waves.
Assuming the system is a linear system, there will be a single value of gain for the whole system, and it will depend on electrical and physical design characteristics.
Output = Gain * input
In order to compute a sound pressure value for any given input you will need to conduct an experiment to measure the output pressure of the system, for a given value of Input.
Considering that a sample-value becomes an output voltage at the output of a DAC, and that the output power of the system is proportional to the sound pressure:
(1) V=IR
and (2) P = IV
, with a little rearrangement we find that P=V*V/R
Therefore Power varies with the square of voltage (or the sample value).
A decibel value is a relative measurement:
Sdb = 10*log10(S/Sref)
Where Sref
the reference measurement point.
Since we have a power relationship between input and output, we get
Sdb = 10*log10(S*S/Sref) == 20*log10(S/Sref)
Now, dBA also happens to be a frequency weighted scale, so you will need to apply the filter described here to the samples for truly accurate values.
There is no answer to this.
Sound pressure level may be 0 for the total silence (deep space or total vacuum), but a negative value just doesn't make sense.