| <html devsite><head> |
| <title>音频延迟时间(适用于应用开发者)</title> |
| <meta name="project_path" value="/_project.yaml"/> |
| <meta name="book_path" value="/_book.yaml"/> |
| </head> |
| <body> |
| <!-- |
| Copyright 2017 The Android Open Source Project |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| |
| <p>为了尽可能缩短音频延迟时间,我们建议您使用基于 OpenSL ES 1.0.1 的 Android 原生音频。</p> |
| |
| <h2 id="implementation">实现核对清单</h2> |
| |
| <p>要使用 Android 原生音频,请执行以下操作:</p> |
| |
| <ol> |
| |
| <li> |
| 下载并安装 <a href="https://developer.android.com/tools/sdk/ndk/index.html">Android NDK</a>。在本文档的其余部分,我们将假设 <code>NDKroot</code> 是您安装 NDK 所使用的目录。</li> |
| |
| <li> |
| 阅读<a href="#supporting">支持文档</a>。 |
| </li> |
| |
| <li> |
| 确认 API 级别不低于 9 级。 |
| </li> |
| |
| <li> |
| 检查 <a href="http://developer.android.com/guide/topics/manifest/uses-feature-element.html#hw-features">android.hardware.audio.low_latency</a> 功能。 |
| </li> |
| |
| <li> |
| 使用由以下对象返回的建议的原生缓冲区空间和采样率:<a href="http://developer.android.com/reference/android/media/AudioManager.html#getProperty(java.lang.String)">android.media.AudioManager.getProperty(java.lang.String)</a> |
| <p> <strong>注意</strong>:输入时,还应使用相同的缓冲区空间和采样率。</p> |
| </li> |
| |
| <li> |
| 通常 1 个 OpenSL ES 缓冲区就足够了。 |
| </li> |
| |
| <li> |
| 确保您的回调处理程序比较短,没有突发的 CPU 占用或不受控制的阻塞。避免<a href="avoiding_pi.html">优先级反转</a>。 |
| </li> |
| |
| <li> |
| 考虑使用<a href="avoiding_pi.html#nonBlockingAlgorithms">非阻塞算法</a>,以在输入和输出回调处理程序之间以及回调处理程序与您应用的其余部分之间进行通信。 |
| </li> |
| |
| </ol> |
| |
| <h2 id="supporting">支持文档</h2> |
| |
| <h3 id="opensl_es_1_0_1">OpenSL ES 1.0.1</h3> |
| |
| <p> |
| 使用 PDF 查看器查看 <a href="https://www.khronos.org/registry/sles/specs/OpenSL_ES_Specification_1.0.1.pdf">OpenSL 1.0.1 规范</a>。这份参考资料很长,并非所有内容都适用于您;不过,您需要查阅这份参考资料来了解有关 API 的详细信息。</p> |
| |
| <p class="note"> |
| <strong>注意</strong>:本文档介绍了完整的 OpenSL ES 1.0.1,但 Android 原生音频实际上是基于 OpenSL ES 1.0.1 的一个子集,而该子集含有一些特定于 Android 的扩展程序。 |
| </p> |
| |
| <p> |
| 更高版本的 OpenSL ES(如 1.1)的说明文档与 Android 不相关。 |
| </p> |
| |
| <h3 id="opensl_es_for_android">OpenSL ES for Android</h3> |
| |
| <p>NDK 的安装文件中提供了“OpenSL ES for Android”文档,该文档目前没有在线提供。在浏览器中打开此链接:</p> |
| |
| <pre class="devsite-click-to-copy"> |
| NDKroot/docs/Additional_library_docs/opensles/index.html |
| </pre> |
| |
| <p> |
| 您需要浏览整篇文档,但要特别注意“编程注释”部分的“性能”子部分。 |
| </p> |
| |
| <p> |
| “OpenSL ES 1.0.1 中受支持的功能”部分介绍了 Android 所支持的子集。 |
| </p> |
| |
| <p> |
| “Android 扩展程序”部分介绍了底层 OpenSL ES 1.0.1 中没有的特定于 Android 的扩展程序。 |
| </p> |
| |
| <h3 id="relationship">与 OpenSL ES 1.0.1 的关系</h3> |
| |
| <p> |
| 该维恩图显示了 Android 原生音频与 OpenSL ES 1.0.1 之间的关系。 |
| </p> |
| |
| <img src="images/venn.png" alt="维恩图" id="figure1"/> |
| <p class="img-caption"> |
| <strong>图 1.</strong> 维恩图</p> |
| |
| <h2 id="resources">其他资源</h2> |
| |
| <h3 id="source_android_com">source.android.com</h3> |
| |
| <p> |
| <a href="/">source.android.com</a> 网站主要面向制造 Android 设备的原始设备制造商 (OEM),以及为这些原始设备制造商提供组件的 SoC 供应商。</p> |
| |
| <p> |
| 不过,该网站上提供了大量有关延迟时间的实用信息,因此您可能需要查看这些信息。请查看<a href="latency.html">音频延迟时间</a>的相关文章。 |
| </p> |
| |
| <h3 id="android_ndk">android-ndk</h3> |
| |
| <p> |
| 如果您对如何使用 Android 原生音频有疑问,请在 <a href="https://groups.google.com/forum/#!forum/android-ndk">android-ndk</a> 论坛中提问。 |
| </p> |
| |
| <h3 id="videos">视频</h3> |
| |
| <dl> |
| |
| <dt><a href="https://youtu.be/d3kfEeMZ65c">Android 上的高性能音频</a>(2013 年 Google I/O 大会)</dt> |
| <dd>整个视频都是关于延迟时间的。</dd> |
| |
| <dt><a href="https://youtu.be/92fgcUNCHic">在 Android 上打造出色的多媒体体验</a>(2014 年 Google I/O 大会)</dt> |
| <dd>前 14 分钟大致介绍了一下音频,尤其是输入延迟时间。</dd> |
| |
| <dt><a href="https://youtu.be/PnDK17zP9BI">音频延迟时间:缓冲区空间</a> (100 Days of Google Dev)</dt> |
| <dd>介绍音频延迟时间、缓冲区空间和任务工作表之间的关系。</dd> |
| |
| </dl> |
| |
| </body></html> |