Android音量曲線分析

來源:互聯網
上載者:User

前段時間仔細研究了一下音量曲線的問題。眾所周知,人耳對聲音強度的感知不是線性,而是具有對數關係。所以理想的音量曲線應該是音量級數調節與音量大小的對數成線性關係。即:

-20lg(y) = a * (x - b) 

 

假設音量級數為M,則有: x = M 時 -20lg(y) = 0dB ==> b = M  

 

由此得到: -20lg(y) = a * (x - M)

 

假設最大音量範圍為N dB, 則有: x = 0時, -20lg(y) = -NdB ==> a =  N / M

由此得: -20lg(y) = (N/M) * (x - M)

 

從上面的計算,我們得到兩個有趣的係數: 

 

    1. a = N / M
    2. a * ln(10) / 20

 

閱讀Android代碼發現M = 100, N = 50

 

由此得到: a = 0.5     a * ln(10) / 20 = 0.5 * 2.302585093 / 20  

 

以下是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 / 20.0f;
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;
}

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.