• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## 5.6\. Audio Latency
2
3Audio latency is the time delay as an audio signal passes through a system.
4Many classes of applications rely on short latencies, to achieve real-time
5sound effects.
6
7For the purposes of this section, use the following definitions:
8
9*   **output latency**. The interval between when an application writes a frame
10of PCM-coded data and when the corresponding sound is presented to environment
11at an on-device transducer or signal leaves the device via a port and can be
12observed externally.
13*   **cold output latency**. The output latency for the first frame, when the
14audio output system has been idle and powered down prior to the request.
15*   **continuous output latency**. The output latency for subsequent frames,
16after the device is playing audio.
17*   **input latency**. The interval between when a sound is presented by
18environment to device at an on-device transducer or signal enters the device via
19a port and when an application reads the corresponding frame of PCM-coded data.
20*   **lost input**. The initial portion of an input signal that is unusable or
21unavailable.
22*   **cold input latency**. The sum of lost input time and the input latency
23for the first frame, when the audio input system has been idle and powered down
24prior to the request.
25*   **continuous input latency**. The input latency for subsequent frames,
26while the device is capturing audio.
27*   **cold output jitter**. The variability among separate measurements of cold
28output latency values.
29*   **cold input jitter**. The variability among separate measurements of cold
30input latency values.
31*   **continuous round-trip latency**. The sum of continuous input latency plus
32continuous output latency plus one buffer period. The buffer period allows
33time for the app to process the signal and time for the app to mitigate phase
34difference between input and output streams.
35*   **OpenSL ES PCM buffer queue API**. The set of PCM-related
36[OpenSL ES](https://developer.android.com/ndk/guides/audio/opensl/index.html)
37APIs within [Android NDK](https://developer.android.com/ndk/index.html).
38*   **AAudio native audio API**. The set of
39[AAudio](https://developer.android.com/ndk/guides/audio/aaudio/aaudio.html) APIs
40within [Android NDK](https://developer.android.com/ndk/index.html).
41*   **Timestamp**. A pair consisting of a relative frame position within a
42stream and the estimated time when that frame enters or leaves the
43audio processing pipeline on the associated endpoint.  See also
44[AudioTimestamp](https://developer.android.com/reference/android/media/AudioTimestamp).
45*   **glitch**. A temporary interruption or incorrect sample value in the audio signal,
46typically caused by a
47[buffer underrun](https://en.wikipedia.org/wiki/Buffer_underrun) for output,
48buffer overrun for input, or any other source of digital or analog noise.
49
50If device implementations declare `android.hardware.audio.output`, they
51MUST meet or exceed the following requirements:
52
53*   [C-1-1] The output timestamp returned by
54[AudioTrack.getTimestamp](https://developer.android.com/reference/android/media/AudioTrack.html#getTimestamp(android.media.AudioTimestamp))
55and `AAudioStream_getTimestamp` is accurate to +/- 2 ms.
56*   [C-1-2] Cold output latency of 500 milliseconds or less.
57
58If device implementations declare `android.hardware.audio.output` they are
59STRONGLY RECOMMENDED to meet or exceed the following requirements:
60
61*   [C-SR] Cold output latency of 100 milliseconds or less. Existing and new
62    devices that run this version of Android are VERY STRONGLY RECOMMENDED
63    to meet these requirements now. In a future platform release in 2021, we
64    will require Cold output latency of 200 ms or less as a MUST.
65*   [C-SR] Continuous output latency of 45 milliseconds or less.
66*   [C-SR] Minimize the cold output jitter.
67*   [C-SR] The output timestamp returned by
68[AudioTrack.getTimestamp](https://developer.android.com/reference/android/media/AudioTrack.html#getTimestamp(android.media.AudioTimestamp))
69and `AAudioStream_getTimestamp` is accurate to +/- 1 ms.
70
71If device implementations meet the above requirements, after any initial
72calibration, when using both the OpenSL ES PCM buffer queue and AAudio native audio APIs,
73for continuous output latency and cold output latency over at least one supported audio
74output device, they are:
75
76*   [C-SR] STRONGLY RECOMMENDED to report low-latency audio by declaring
77    `android.hardware.audio.low_latency` feature flag.
78*   [C-SR] STRONGLY RECOMMENDED to meet the requirements for low-latency
79    audio via the AAudio API.
80*   [C-SR] STRONGLY RECOMMENDED to ensure that for streams that return
81    [`AAUDIO_PERFORMANCE_MODE_LOW_LATENCY`](https://developer.android.com/ndk/guides/audio/aaudio/aaudio#performance-mode)
82    from [`AAudioStream_getPerformanceMode()`](https://developer.android.com/ndk/reference/group/audio#aaudiostream_getperformancemode),
83    the value returned by [`AAudioStream_getFramesPerBurst()`](https://developer.android.com/ndk/reference/group/audio#aaudiostream_getframesperburst)
84    is less than or equal to the value returned by [`android.media.AudioManager.getProperty(String)`](https://developer.android.com/reference/android/media/AudioManager.html#getProperty%28java.lang.String%29)
85    for property key [`AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER`](https://developer.android.com/reference/android/media/AudioManager.html#PROPERTY_OUTPUT_FRAMES_PER_BUFFER).
86
87If device implementations do not meet the requirements for low-latency audio
88via both the OpenSL ES PCM buffer queue and AAudio native audio APIs, they:
89
90*   [C-2-1] MUST NOT report support for low-latency audio.
91
92If device implementations include `android.hardware.microphone`, they
93MUST meet these input audio requirements:
94
95*   [C-3-1] Limit the error in input timestamps, as returned by
96[AudioRecord.getTimestamp](https://developer.android.com/reference/android/media/AudioRecord.html#getTimestamp(android.media.AudioTimestamp,%20int))
97or `AAudioStream_getTimestamp`, to +/- 2 ms.
98"Error" here means the deviation from the correct value.
99*   [C-3-2] Cold input latency of 500 milliseconds or less.
100
101If device implementations include `android.hardware.microphone`, they are
102STRONGLY RECOMMENDED to meet these input audio requirements:
103
104   *   [C-SR] Cold input latency of 100 milliseconds or less. Existing and new
105       devices that run this version of Android are VERY STRONGLY RECOMMENDED
106       to meet these requirements now. In a future platform release in 2021 we
107       will require Cold input latency of 200 ms or less as a MUST.
108   *   [C-SR] Continuous input latency of 30 milliseconds or less.
109   *   [C-SR] Continuous round-trip latency of 50 milliseconds or less.
110   *   [C-SR] Minimize the cold input jitter.
111   *   [C-SR] Limit the error in input timestamps, as returned by
112[AudioRecord.getTimestamp](https://developer.android.com/reference/android/media/AudioRecord.html#getTimestamp(android.media.AudioTimestamp,%20int))
113or `AAudioStream_getTimestamp`, to +/- 1 ms.
114