I carefully studied the problem of the volume curve some time ago. As we all know, the voice perception of human ears is not linear, but logarithm. Therefore, the ideal volume curve should be a linear relationship between the adjustment of the volume level and the logarithm of the volume size. That is:
-20lg (y) = A * (X-B)
Assuming the volume level is m, the following values are: x = m-20lg (y) = 0db => B = m
-20lg (y) = A * (X-m)
Assume that the maximum volume range is n dB. For example, if x = 0,-20lg (y) =-NDB => A = N/m.
-20lg (y) = (N/m) * (X-m)
From the above calculation, we get two interesting coefficients:
- A = N/m
- A * ln (10)/20
After reading the android code, I found M = 100, n = 50.
The result is as follows: a = 0.5 A * ln (10)/20 = 0.5*2.302585093/20.
The following functions are used to calculate the volume in Android:
// Convert volume steps to natural log scale
// Change this value to change volume Scaling
Static const float dbperstep = 0.5f;
// Shouldn't need to touch these
Static const float dbconvert =-dbperstep * 2.302585093f/20366f;
Static const float dbconvertinverse = 1.0f/dbconvert;
Float audiosystem: lineartolog (INT volume)
{
// Float v = Volume? Exp (float (100-volume) * dbconvert): 0;
// Logd ("lineartolog (% d) = % F", volume, V );
// Return V;
Return volume? Exp (float (100-volume) * dbconvert): 0;
}