自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
音訊暖機
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
音訊暖機是指裝置中的音訊放大器電路需要多久才能完全啟動,並達到正常運作狀態。影響音訊暖機時間的主要因素是電源管理,以及用於穩定電路的任何「de-pop」邏輯。
本文說明如何評估音訊預熱時間,以及可能縮短預熱時間的方法。
評估輸出內容預熱
AudioFlinger 的 FastMixer 執行緒會自動評估輸出暖機情形,並將結果列為 dumpsys media.audio_flinger
指令的輸出內容。在暖機期間,FastMixer 會重複呼叫 write()
,直到兩個 write()
之間的時間達到預期值。FastMixer 會判斷音訊暖機,方法是查看硬體抽象層 (HAL) write()
穩定所需的時間。
如要測量音訊暖機,請按照下列步驟操作,並在開機後的不同時間測試內建喇叭和有線耳機。每個輸出裝置的暖機時間通常不盡相同,而且在開機後,暖機時間也會有所不同:
- 確認已啟用 FastMixer。
- 在裝置上依序選取「設定」>「音效」>「觸控聲音」,即可啟用觸控聲音。
- 請確認音訊已關閉至少三秒。建議使用五秒或更長的時間,因為硬體本身可能有 AudioFlinger 所需的三秒以外的電源邏輯。
- 按下主畫面按鈕,你應該會聽到喀噠聲。
- 執行下列指令,取得經過評估的暖機作業:
adb shell dumpsys media.audio_flinger | grep measuredWarmup
輸出結果應如下所示:
sampleRate=44100 frameCount=256 measuredWarmup=X ms, warmupCycles=X
measuredWarmup=X
是第一組 HAL write()
完成所需的毫秒數 X。
warmupCycles=X
是指需要多少個 HAL 寫入要求,才能讓 write()
的執行時間符合預期。
-
請測量五次,並記錄所有測量值和平均值。如果這些值不大致相同,則表示測量值可能有誤。舉例來說,如果在音訊關閉後沒有等待足夠的時間,暖機時間就會比平均值短。
目前沒有任何工具可用於測量音訊輸入暖機。不過,您可以觀察 startRecording() 回傳所需的時間,藉此估算輸入暖機時間。
縮短預熱時間
通常,您可以透過以下方式縮短暖機時間:
- 良好的電路設計
- 核心裝置驅動程式中的準確時間延遲
- 並行執行獨立的暖機作業,而非依序執行
- 讓電路保持開啟或未重新設定時鐘 (增加閒置電力消耗)
- 快取已計算的參數
不過,請留意不要過度最佳化。您可能會發現,需要在低暖機時間和電源轉換時不出現彈出效果之間取得平衡。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-03-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-03-26 (世界標準時間)。"],[],[],null,["# Audio warmup is the time it takes for the audio amplifier circuit in your device to\nbe fully powered and reach its normal operation state. The major contributors\nto audio warmup time are power management and any \"de-pop\" logic to stabilize\nthe circuit.\n\nThis document describes how to measure audio warmup time and possible ways to decrease\nwarmup time.\n\nMeasure output warmup\n---------------------\n\n\nAudioFlinger's FastMixer thread automatically measures output warmup\nand reports it as part of the output of the `dumpsys media.audio_flinger` command.\nAt warmup, FastMixer calls `write()`\nrepeatedly until the time between two `write()`s is the amount expected.\nFastMixer determines audio warmup by seeing how long a Hardware Abstraction\nLayer (HAL) `write()` takes to stabilize.\n\nTo measure audio warmup, follow these steps for the built-in speaker and wired headphones\nand at different times after booting. Warmup times are usually different for each output device\nand right after booting the device:\n\n1. Ensure that FastMixer is enabled.\n2. Enable touch sounds by selecting **Settings \\\u003e Sound \\\u003e Touch sounds** on the device.\n3. Ensure that audio has been off for at least three seconds. Five seconds or more is better, because the hardware itself might have its own power logic beyond the three seconds that AudioFlinger has.\n4. Press Home, and you should hear a click sound.\n5. Run the following command to receive the measured warmup: \n\n ```\n adb shell dumpsys media.audio_flinger | grep measuredWarmup\n ```\n\n\n You should see output like this: \n\n ```\n sampleRate=44100 frameCount=256 measuredWarmup=X ms, warmupCycles=X\n ```\n\n\n The `measuredWarmup=X` is X number of milliseconds\n it took for the first set of HAL `write()`s to complete.\n\n\n The `warmupCycles=X` is how many HAL write requests it took\n until the execution time of `write()` matches what is expected.\n6. Take five measurements and record them all, as well as the mean. If they are not all approximately the same, then it's likely that a measurement is incorrect. For example, if you don't wait long enough after the audio has been off, you will see a lower warmup time than the mean value.\n\nMeasure input warmup\n--------------------\n\n\nThere are currently no tools provided for measuring audio input warmup.\nHowever, input warmup time can be estimated by observing\nthe time required for [startRecording()](http://developer.android.com/reference/android/media/AudioRecord.html#startRecording())\nto return.\n\nReduce warmup time\n------------------\n\n\nWarmup time can usually be reduced by a combination of:\n\n- Good circuit design\n- Accurate time delays in kernel device driver\n- Performing independent warmup operations concurrently rather than sequentially\n- Leaving circuits powered on or not reconfiguring clocks (increases idle power consumption)\n- Caching computed parameters\n\n\nHowever, beware of excessive optimization. You may find that you\nneed to tradeoff between low warmup time versus\nlack of popping at power transitions."]]