ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
เวลาในการตอบสนองของเสียงสำหรับนักพัฒนาแอป
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เราขอแนะนำให้ใช้ Oboe เพื่อให้เวลาในการตอบสนองของเสียงต่ำที่สุด
ปี่โอโบ
Oboe ใช้เสียงแบบเนทีฟและสร้างขึ้นจาก AAudio สำหรับ Android 8.1 ขึ้นไป และ OpenSL ES สำหรับ Android เวอร์ชันเก่า หากต้องการลดเวลาในการตอบสนองของอุปกรณ์ให้เหลือน้อยที่สุด ให้ตั้งค่า setPerformanceMode(oboe::PerformanceMode::LowLatency)
และ setSharingMode(oboe::SharingMode::Exclusive)
ดูข้อมูลเพิ่มเติมเกี่ยวกับ Oboe ได้ในคู่มือเริ่มต้นใช้งาน, README.md
และคู่มือฉบับเต็ม ดูตัวอย่างแอปที่ใช้ Oboe ได้ในแอป Soundboard
หมายเหตุ: หากใช้ AudioTrack เพื่อสร้างสตรีมเสียงเอาต์พุตใน Java สําหรับแอปพลิเคชันที่ไวต่อเวลาในการตอบสนอง ให้ใช้โหมด PERFORMANCE_MODE_LOW_LATENCY
รายการตรวจสอบการติดตั้งใช้งาน
วิธีใช้เสียงแบบเนทีฟของ Android
-
ดาวน์โหลดและติดตั้ง Android NDK
-
ทำตามคู่มือเริ่มต้นใช้งานสำหรับ Oboe
-
โทรหา
setPerformanceMode(oboe::PerformanceMode::LowLatency)
และ setSharingMode(oboe::SharingMode::Exclusive)
ในเครื่องมือสร้าง Oboe
-
ใช้ขนาดบัฟเฟอร์และอัตราตัวอย่างแบบเนทีฟที่แนะนําซึ่งแสดงผลโดย android.media.AudioManager.getProperty(java.lang.String)
หมายเหตุ: ควรใช้ขนาดบัฟเฟอร์และอัตราตัวอย่างเดียวกันกับอินพุตด้วย
-
เขียนตัวแฮนเดิลการเรียกกลับให้สั้นๆ โดยไม่มีการใช้งาน CPU แบบฉับพลันหรือการบล็อกแบบไม่จำกัด หลีกเลี่ยงการเปลี่ยนลําดับความสําคัญ
-
ลองใช้อัลกอริทึมแบบไม่บล็อกเพื่อสื่อสารระหว่างตัวแฮนเดิลการเรียกคืนอินพุตและเอาต์พุต และระหว่างตัวแฮนเดิลการเรียกคืนกับแอปพลิเคชันส่วนที่เหลือ
ทรัพยากรอื่นๆ
source.android.com
เว็บไซต์ source.android.com ออกแบบมาเพื่อ OEM ที่สร้างอุปกรณ์ Android และผู้จำหน่าย SoC ที่ส่งชิ้นส่วนให้กับ OEM เหล่านี้เป็นหลัก
อย่างไรก็ตาม เว็บไซต์นี้มีข้อมูลที่เป็นประโยชน์มากมายเกี่ยวกับเวลาในการตอบสนอง คุณจึงควรอ่านข้อมูลดังกล่าว ดูบทความที่หัวข้อเวลาในการตอบสนองของเสียง
android-ndk
หากมีคำถามเกี่ยวกับวิธีใช้เสียงแบบเนทีฟของ Android โปรดถามในกลุ่มสนทนา android-ndk
รายงานข้อบกพร่องใน Oboe
หากพบปัญหาในการใช้ Oboe คุณสามารถรายงานข้อบกพร่องได้
วิดีโอ
- เริ่มต้นใช้งาน Oboe
- เสียงที่มีเวลาในการตอบสนองต่ำ - เพราะหูของคุณมีค่าควรแก่การฟัง
- Android Dev Summit 2018
- การประสบความสำเร็จใน Android - วิธีเพิ่มประสิทธิภาพแอปเสียงสำหรับ Android
- Android Developer Challenge 2018
- เสียงประสิทธิภาพสูงใน Android
(Google I/O 2013)
- วิดีโอทั้งเรื่องเกี่ยวกับเวลาในการตอบสนอง
- การสร้างประสบการณ์การใช้งานมัลติมีเดียที่ยอดเยี่ยมบน Android
(Google I/O 2014)
- ช่วง 14 นาทีแรกเป็นเรื่องเกี่ยวกับเสียงโดยทั่วไปและเวลาในการตอบสนองของอินพุตโดยเฉพาะ
- เวลาในการตอบสนองของเสียง: ขนาดบัฟเฟอร์
(100 Days of Google Dev)
- อธิบายความสัมพันธ์ระหว่างเวลาในการตอบสนองของเสียง ขนาดบัฟเฟอร์ และการกําหนดเวลางาน
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-03-26 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],null,["# Audio latency for app developers\n\nFor the lowest possible audio latency, we recommend you use [Oboe](https://developer.android.com/games/sdk/oboe).\n\nOboe\n----\n\n[Oboe](https://github.com/google/oboe) uses native audio and is built\non AAudio for Android 8.1+ and OpenSL ES for older versions of Android. To achieve the lowest\npossible latency for a device, set `setPerformanceMode(oboe::PerformanceMode::LowLatency)`\nand `setSharingMode(oboe::SharingMode::Exclusive)`.\nSee the [Getting started guide](https://github.com/google/oboe/blob/main/docs/GettingStarted.md),\n[`README.md`](https://github.com/google/oboe/blob/main/README.md),\nand [Full guide](https://github.com/google/oboe/blob/main/docs/FullGuide.md) for more\ninformation on Oboe. Refer to the [Soundboard app](https://github.com/google/oboe/tree/main/samples/SoundBoard)\nfor a sample app using Oboe.\n\n**Note:** If you use [AudioTrack](https://developer.android.com/reference/android/media/AudioTrack)\nfor creating output audio streams in Java for latency sensitive applications, use the [`PERFORMANCE_MODE_LOW_LATENCY`](https://developer.android.com/reference/android/media/AudioTrack#PERFORMANCE_MODE_LOW_LATENCY)\nmode.\n\n\u003cbr /\u003e\n\nImplementation checklist\n------------------------\n\nTo use Android native audio:\n\n1. Download and install the [Android NDK](https://developer.android.com/tools/sdk/ndk/index.html).\n2. Follow the [Getting started guide](https://github.com/google/oboe/blob/main/docs/GettingStarted.md) for Oboe.\n3. Call `setPerformanceMode(oboe::PerformanceMode::LowLatency)` and `setSharingMode(oboe::SharingMode::Exclusive)` on the Oboe builder.\n4. Use the recommended native buffer size and sample rate returned by [android.media.AudioManager.getProperty(java.lang.String)](http://developer.android.com/reference/android/media/AudioManager.html#getProperty(java.lang.String)).\n\n **Note:** The same buffer size and sample rate should also be used for input.\n5. Keep your callback handlers short, without bursty CPU usage or unbounded blocking. Avoid [priority inversion.](/docs/core/audio/avoiding_pi)\n6. Consider using [non-blocking algorithms](/docs/core/audio/avoiding_pi#nonBlockingAlgorithms) to communicate between input and output callback handlers, and between the callback handlers and the rest of your application.\n\nOther resources\n---------------\n\n### source.android.com\n\n\nThe site [source.android.com](/)\nis primarily designed for OEMs building Android\ndevices, and the SoC vendors who supply components to these OEMs.\n\n\nHowever, there is a wealth of useful information about latency at this site, so\nyou may want to review it. See the articles at\n[Audio latency.](/docs/core/audio/latency/latency)\n\n### android-ndk\n\n\nIf you have questions about how to use Android native audio, you can ask at the discussion group\n[android-ndk](https://groups.google.com/forum/#!forum/android-ndk).\n\n### Report bugs on Oboe\n\n\nIf you have issues using Oboe, you can\n[file a bug](https://github.com/google/oboe/issues).\n\n### Videos\n\n[Getting started with Oboe](https://www.youtube.com/playlist?list=PLWz5rJ2EKKc_duWv9IPNvx9YBudNMmLSa)\n[Low Latency Audio - Because Your Ears Are Worth It](https://www.youtube.com/watch?v=8vOf_fDtur4)\n: Android Dev Summit 2018.\n\n[Winning on Android - How to optimize an Android audio app](https://www.youtube.com/watch?v=tWBojmBpS74)\n: Android Developer Challenge 2018.\n\n[High performance audio on Android](https://youtu.be/d3kfEeMZ65c)\n(Google I/O 2013)\n: The whole video is about latency.\n\n[Building great multi-media experiences on Android](https://youtu.be/92fgcUNCHic)\n(Google I/O 2014)\n: The first 14 minutes are about audio in general and input latency in particular.\n\n[Audio latency: buffer sizes](https://youtu.be/PnDK17zP9BI)\n(100 Days of Google Dev)\n: Describes the relationship between audio latency, buffer sizes, and task scheduling."]]