ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
การแปลงอัตราการสุ่มตัวอย่าง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
บทความนี้อธิบายการเปลี่ยนอัตราตัวอย่างหรือที่เรียกว่าการปรับขนาดตัวอย่างภายใน Android
ดูคำศัพท์ที่เกี่ยวข้องกับการเปลี่ยนอัตราตัวอย่างได้ที่คำศัพท์
การแปลงอัตราตัวอย่างคือกระบวนการเปลี่ยนสตรีมตัวอย่างแบบไม่ต่อเนื่องจากอัตราตัวอย่างหนึ่งเป็นสตรีมอื่นที่มีอัตราตัวอย่างอื่น
ตัวแปลงอัตราตัวอย่างหรือตัวแปลงเป็นรูปแบบใหม่คือโมดูลที่ใช้อัตราตัวอย่างแปลง สตรีมต้นฉบับเรียกว่า "สัญญาณต้นทาง" ส่วนสตรีมที่แปลงเป็นรูปแบบใหม่เรียกว่า "สัญญาณปลายทาง"
ระบบใช้โปรแกรมเปลี่ยนรูปแบบหลายแห่งใน Android ตัวอย่างเช่น ไฟล์ MP3 อาจได้รับการเข้ารหัสที่อัตราการสุ่มตัวอย่าง 44.1 kHz แต่ต้องเล่นในอุปกรณ์ Android ที่รองรับเสียง 48 kHz ภายใน ในกรณีนี้ ระบบจะใช้โปรแกรมเปลี่ยนอัตราการสุ่มตัวอย่างเพื่อเพิ่มอัตราการสุ่มตัวอย่างเสียงเอาต์พุต MP3 จากอัตราการสุ่มตัวอย่างแหล่งที่มา 44.1 kHz เป็นอัตราการสุ่มตัวอย่างที่ส่ง 48 kHz ซึ่งใช้ในอุปกรณ์ Android
คุณแสดงลักษณะของโปรแกรมเปลี่ยนอัตราตัวอย่างได้โดยใช้เมตริกต่างๆ ซึ่งรวมถึง
- ระดับการคงไว้ของระดับความกว้างโดยรวมของสัญญาณ
- ระดับการคงแบนด์วิดท์ความถี่ของสัญญาณไว้ ซึ่งขึ้นอยู่กับข้อจำกัดของอัตราตัวอย่างของที่เก็บ
- เวลาในการตอบสนองโดยรวมผ่านตัวแปลง
- เฟสและการหน่วงเวลาของกลุ่มที่สอดคล้องกับความถี่
- ความซับซ้อนในการประมวลผลที่แสดงเป็นรอบของ CPU หรือปริมาณการใช้พลังงาน
- อัตราส่วนอัตราตัวอย่างของแหล่งที่มาและปลายทางที่อนุญาต
- ความสามารถในการเปลี่ยนอัตราส่วนอัตราการสุ่มตัวอย่างแบบไดนามิก
- รูปแบบไฟล์ตัวอย่างเสียงแบบดิจิทัลที่รองรับ
ตัวแปลงสัญญาณที่เหมาะควรจะรักษาแอมพลิจูดและความถี่ของแบนด์วิดท์ของสัญญาณต้นทางไว้อย่างถูกต้อง (ขึ้นอยู่กับข้อจำกัดของอัตราการสุ่มตัวอย่างของปลายทาง) มีความล่าช้าน้อยที่สุดและสอดคล้องกัน มีความซับซ้อนในการคำนวณน้อยที่สุด อนุญาตให้ใช้อัตราส่วนการเปลี่ยนรูปแบบแบบกำหนดเองและแบบไดนามิก และรองรับรูปแบบตัวอย่างเสียงดิจิทัลทั่วไปทั้งหมด ในทางปฏิบัติแล้ว โปรแกรมเปลี่ยนอัตราตัวอย่างที่เหมาะที่สุดนั้นไม่มีอยู่จริง เนื่องจากโปรแกรมเปลี่ยนอัตราตัวอย่างจริงเป็นการประนีประนอมระหว่างลักษณะเหล่านี้ เช่น เป้าหมายด้านคุณภาพที่ยอดเยี่ยมขัดแย้งกับเวลาในการตอบสนองที่สั้นและความซับซ้อนต่ำ
Android มีโปรแกรมเปลี่ยนรูปแบบข้อมูลเสียงที่หลากหลายเพื่อให้สามารถประนีประนอมได้อย่างเหมาะสมตาม Use Case และภาระงานของแอปพลิเคชัน คุณสามารถดูคำอธิบายเกี่ยวกับโปรแกรมเปลี่ยนรูปแบบข้อมูลที่มีได้ในการใช้งานโปรแกรมเปลี่ยนรูปแบบข้อมูล
การใช้งานโปรแกรมเปลี่ยนรูปแบบ
การติดตั้งใช้งานตัวแปลงตัวอย่างที่ใช้ได้มีการเปลี่ยนแปลงอยู่บ่อยครั้ง และ OEM อาจปรับแต่งได้
ตัวแปลงอัตราตัวอย่างเริ่มต้นตามลําดับจากมากไปน้อยของการบิดเบือนสัญญาณและลําดับจากน้อยไปมากของความซับซ้อนในการคํานวณ ได้แก่
- เชิงเส้น
- ลูกบาศก์
- sinc ที่มีค่าสัมประสิทธิ์เดิม
- sinc ที่มีค่าสัมประสิทธิ์ที่แก้ไขแล้ว
โดยทั่วไปแล้ว ตัวแปลงตัวอย่างแบบ sinc เหมาะสําหรับการเล่นเพลงที่มีคุณภาพสูงขึ้น ส่วนตัวแปลงตัวอย่างอื่นๆ ควรสงวนไว้สําหรับกรณีที่คุณภาพมีความสำคัญน้อยกว่า (เช่น "การคลิกแป้นพิมพ์" หรือคล้ายกัน)
การใช้งานตัวแปลงตัวอย่างที่เฉพาะเจาะจงที่เลือกจะขึ้นอยู่กับกรณีการใช้งาน ภาระ และค่าของพร็อพเพอร์ตี้ของระบบ
af.resampler.quality
ดูรายละเอียดได้ที่ซอร์สโค้ดตัวแปลงตัวอย่างเสียงใน AudioFlinger
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# Sample rate conversion\n\nThis article describes sample rate conversion, also known as *resampling* , within Android.\nFor terminology related to sample rate conversion, see\n[Terminology](/docs/core/audio/terminology#srcTerms).\n\n\nSample rate conversion is the process of changing a stream of discrete samples\nfrom one sample rate to another stream at a different sample rate.\nA sample rate converter, or resampler, is a module that implements sample rate\nconversion. With respect to the resampler, the original stream is called the\nsource signal, and the resampled stream is called the sink signal.\n\n\nResamplers are used in several places in Android. For example, an MP3 file may\nbe encoded at 44.1 kHz sample rate but needs to be played back on an Android\ndevice supporting 48 kHz audio internally. In that case, a resampler would be\nused to upsample the MP3 output audio from 44.1 kHz source sample rate to a\n48 kHz sink sample rate used within the Android device.\n\n\nThe characteristics of a resampler can be expressed using metrics, including:\n\n- degree of preservation of the overall amplitude of the signal\n- degree of preservation of the frequency bandwidth of the signal, subject to limitations of the sink sample rate\n- overall latency through the resampler\n- consistent phase and group delay with respect to frequency\n- computational complexity, expressed in CPU cycles or power draw\n- permitted ratios of source and sink sample rates\n- ability to dynamically change sample rate ratios\n- which digital audio sample formats are supported\n\n\nThe ideal resampler would exactly preserve the source signal's amplitude\nand frequency bandwidth (subject to limitations of the sink\nsample rate), have minimal and consistent delay, have minimal\ncomputational complexity, permit arbitrary and dynamic conversion ratios,\nand support all common digital audio sample formats. In practice, ideal\nresamplers do not exist as actual resamplers are a compromise among these\ncharacteristics. For example, goals of ideal quality conflict with short delay\nand low complexity.\n\n\nAndroid includes a variety of audio resamplers, so that appropriate\ncompromises can be made depending on the application use case and load. The\navailable resamplers are explained in [Resampler implementation.](#srcResamplers)\n\nResampler implementations\n-------------------------\n\n\nAvailable resampler implementations change frequently,\nand may be customized by OEMs.\nThe default resamplers, in descending order of signal distortion and ascending order of\ncomputational complexity, include:\n\n- linear\n- cubic\n- sinc with original coefficients\n- sinc with revised coefficients\n\n\nIn general, the sinc resamplers are more appropriate for higher-quality\nmusic playback, and the other resamplers should be reserved for cases\nwhere quality is less important (an example might be \"key clicks\" or similar).\n\n\nThe specific resampler implementation selected depends on\nthe use case, load, and the value of system property\n`af.resampler.quality`. For details,\nconsult the audio resampler source code in\n[AudioFlinger](https://android.googlesource.com/platform/frameworks/av/+/39ec5a7accf61d89a41908999bc789d5c8d0e3d3/services/audioflinger/)."]]