How to convert a float between -1.0 and +1.0 to dB

2019-09-19 14:02发布

This question already has an answer here:

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));

2条回答
甜甜的少女心
2楼-- · 2019-09-19 14:52

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.

查看更多
▲ chillily
3楼-- · 2019-09-19 15:05

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.

查看更多
登录 后发表回答