Android Volume Curve Analysis

Source: Internet
Author: User
Tags natural log

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:

 

    1. A = N/m
    2. 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;
}

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.