Android 錄音getMaxAmplitude()

來源:互聯網
上載者:User

標籤:

這個方法是用來擷取在前一次調用此方法之後錄音中出現的最大振幅,文檔解釋如下:

Returns the maximum absolute amplitude that was sampled since the last call to this method. Call this only after the setAudioSource().

很多人遇到問題,說是傳回值為0,文檔中解釋如下:the maximum absolute amplitude measured since the last call, or 0 when called for the first time。

 

所以這個方法是需要間隔一段時間調用一次的,也就是說,需要放線上程裡面調用的。第一次調用會返回0。

 

最近需要使用這個方法擷取音量的變化,對其傳回值很好奇,查了一些資料(from stackoverflow),解釋如下:

 

The MediaRecorder.getMaxAmplitude() function returns unsigned 16-bit integer values (0-32767). Which is probably just the abs() of the CD-quality sample values that range from -32768 to 32767. This means that they probably represent a 16-bit digitalization of the electrical output from 0-100% maximum voltage range of the microphone build into that mobile phone. Since even in one brand of mobile these microphones sometimes vary in their precise range not even to similar phones will necessarily return the same value given the same distance to the same sound source.This value however correlates to sound pressure in Pascal since it‘s also a linear quantisation of the solund pressure, in the area where sound can be measured with the given microphone (which will not cover the entire sprectrum due to the limitations of the phone).

 

然後看了一下小米錄音機的源碼,它其中就有一段代碼是用來反映錄音音量大小的,關鍵代碼如下:

 

int vuSize = MAX_VU_SIZE * mRecorder.getMaxAmplitude() / 32768;

 

其中MAX_VU_SIZE是小米將音量分的等級數,然後可以將獲得的振幅處以32768(關於這個數字,前面一段資料裡面有解釋),這樣子就能獲得音量所處的等級。

 

Android 錄音getMaxAmplitude()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.