自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
音频预热时间
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
音频预热时间是指设备中的音频放大电路充满电并达到正常运行状态所需的时间。音频预热时间的主要影响因素是电源管理以及用于稳定电路的任何“de-pop”逻辑。
本文档介绍了如何测量音频预热时间以及缩短预热时间的可行方法。
测量输出预热时间
AudioFlinger 的 FastMixer 线程可自动测量输出预热时间,并在 dumpsys media.audio_flinger
命令的输出中报告该信息。在预热期间,FastMixer 会重复调用 write()
,直到两个 write()
之间的时间达到预期值。FastMixer 通过查看硬件抽象层 (HAL) write()
达到稳定状态所需的时间来确定音频预热时间。
如需测量音频预热时间,请在启动后的不同时间针对内置扬声器和有线耳机执行以下操作。每种输出设备的预热时间通常是不同的,启动相应设备之后,请立即执行以下操作:
- 确保 FastMixer 已启用。
- 在设备上依次选择“设置”>“声音”>“触摸提示音”,启用触摸提示音。
- 确保音频至少已关闭三秒钟。五秒钟或更长时间会更好,因为除了 AudioFlinger 的 3 秒钟时间之外,硬件本身可能也存在自己的电源逻辑。
- 按主屏幕按钮,您应该会听到点击声音。
- 运行以下命令以接收测量的预热时间:
adb shell dumpsys media.audio_flinger | grep measuredWarmup
您应该会看到类似以下内容的输出:
sampleRate=44100 frameCount=256 measuredWarmup=X ms, warmupCycles=X
measuredWarmup=X
表示完成第一组 HAL write()
耗用了 X 毫秒。
warmupCycles=X
表示 write()
的执行时间达到预期前发出的 HAL 写入请求的数量。
-
进行五次测量并记录所有值及平均值。如果并非所有值都完全接近,那么可能其中的某次测量不准确。例如,音频关闭后,如果您未等待足够长的时间,将会出现预热时间小于平均值的情况。
目前还没有用于测量音频输入预热时间的工具。
不过,通过观察返回 startRecording() 所需的时间,可估算输入预热时间。
缩短预热时间
通常通过实施以下优化组合,可以缩短预热时间:
- 良好的电路设计
- 内核设备驱动程序中的时间延迟很精确
- 并行(而非按顺序)执行独立的预热操作
- 使电路保持通电状态,或者不重新配置时钟(会增加闲置功耗)
- 缓存经计算的参数
不过,请注意避免过度优化。您可能会发现,您需要在较短预热时间和电源转换时无爆鸣之间进行权衡。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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."]]