MFC calculates decibels

One definition of the decibel is a unit that expresses the ratio of power quantities, which is equal to 10 times the common logarithm of the ratio of power intensities;

Mainly used to measure sound intensity, usually expressed in dB;

Its calculation is an excerpt from a piece of information on the Internet;

The decibel value of a sound can be calculated by the following formula:
dB = 10 log10(P / P0)
Among them, P represents the power of the sound (watts), P0 represents the power of the reference sound (usually 10^-12 watts), and log10 represents the power of the sound in 10 base logarithm.

Knowing that the power of the sound is P, the decibel value can be calculated according to the following steps:
1. Divide P by the reference sound power P0 to get a value
2. Take the logarithm of this value and take the base 10 as the base
3. Multiply by 10 to get the decibel value

For example, if the power of the sound is 1 watt and the reference sound power is 10^-12 watts, the decibel value can be calculated as follows: 1.
1 / 10^-12 = 1e+12
2. log10(1e+12) = 12
3. 12 * 10 = 120 dB
Therefore, the decibel value of this sound is 120 dB;

Let's do it with MFC; VC6 creates a new dialog project;

Design the following interface and add member variables to the edit box,

First define the reference power,

    #define ZEROPOWER 10E-12

And include <math.h>;

button click code;

void CDbDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	m_result = 10 * log10(m_wt / ZEROPOWER);
	//m_result = m_wt / ZEROPOWER;
    UpdateData(FALSE);	
}

Run it; calculate it once, 

 

Calculate again;

 

 At 1 watt, his is 120dB. I calculated why it is 110dB; I don’t know whether the reference power is 10^-12 watts; I will look at it when I have time;

The decibel reference of the loudness of some common sounds is excerpted as follows;

10 decibels: a very quiet room, the rustling of leaves by the wind
20 decibels: a country night
30 decibels: a clock ticking in a quiet office
40-60 decibels: normal conversation, human voices about an arm's length away
About 50 decibels: the working sound of the washing machine
70 decibels: the working sound of the vacuum cleaner 3 meters away 80 decibels: the roar
of vehicles passing by 3 meters away sound of pain

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/132158497