Audio warmup

Audio warmup is the time it takes for the audio amplifier circuit in your device to be fully powered and reach its normal operation state. The major contributors to audio warmup time are power management and any "de-pop" logic to stabilize the circuit.

This document describes how to measure audio warmup time and possible ways to decrease warmup time.

Measure output warmup

AudioFlinger's FastMixer thread automatically measures output warmup and reports it as part of the output of the dumpsys media.audio_flinger command. At warmup, FastMixer calls write() repeatedly until the time between two write()s is the amount expected. FastMixer determines audio warmup by seeing how long a Hardware Abstraction Layer (HAL) write() takes to stabilize.

To measure audio warmup, follow these steps for the built-in speaker and wired headphones and at different times after booting. Warmup times are usually different for each output device and right after booting the device:

  1. Ensure that FastMixer is enabled.
  2. Enable touch sounds by selecting Settings > Sound > Touch sounds on the device.
  3. 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.
  4. Press Home, and you should hear a click sound.
  5. Run the following command to receive the measured warmup:
    adb shell dumpsys media.audio_flinger | grep measuredWarmup

    You should see output like this:

    sampleRate=44100 frameCount=256 measuredWarmup=X ms, warmupCycles=X

    The measuredWarmup=X is X number of milliseconds it took for the first set of HAL write()s to complete.

    The warmupCycles=X is how many HAL write requests it took until the execution time of write() matches what is expected.

  6. 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.

Measure input warmup

There are currently no tools provided for measuring audio input warmup. However, input warmup time can be estimated by observing the time required for startRecording() to return.

Reduce warmup time

Warmup time can usually be reduced by a combination of:

  • Good circuit design
  • Accurate time delays in kernel device driver
  • Performing independent warmup operations concurrently rather than sequentially
  • Leaving circuits powered on or not reconfiguring clocks (increases idle power consumption)
  • Caching computed parameters

However, beware of excessive optimization. You may find that you need to tradeoff between low warmup time versus lack of popping at power transitions.