Android 14 提供開發人員 API,應用程式可使用這些 API 查詢及設定 USB 音訊播放的偏好混合器屬性。這些偏好調音器屬性可讓應用程式設定音訊格式、通道遮罩、取樣率和調音器行為,進而改善 USB 音訊播放體驗。在支援的 USB 裝置上使用偏好的混音器 API,使用者就能享有更低延遲的音訊播放功能和更高解析度的音訊內容。
這項功能也支援 USB 裝置的選用位元完美播放調音盤行為。在相容的數位至類比轉換器 (DAC) 上,位元完美模式可讓您播放經過認證的母帶品質 (MQA) 和直接串流數位 (DSD) 格式。
[[["容易理解","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-07-26 (世界標準時間)。"],[],[],null,["# Preferred mixer attributes on USB devices\n\nAndroid 14 provides [developer APIs](https://developer.android.com/reference/android/media/AudioMixerAttributes)\nthat apps can use to query and configure preferred mixer attributes for USB\naudio playback. These [preferred mixer attributes](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/android16-release/media/java/android/media/AudioMixerAttributes.java)\nimprove the USB audio playback experience by letting apps set the audio format,\nchannel mask, sample rate, and mixer behavior. With the use of the preferred\nmixer APIs on supported USB devices, users can get lower-latency audio playback\nand higher-resolution audio content.\n\nThis feature also provides support for the optional bit-perfect playback mixer\nbehavior for USB devices. The bit-perfect mode enables playback for master\nquality authenticated (MQA) and direct stream digital (DSD) formats on\ncompatible digital to analog converters (DACs).\n\nInterface\n---------\n\nThe Audio Policy Manager handles the mixer attributes in the framework. The\n[`AudioMixerAttributes`](https://developer.android.com/reference/android/media/AudioMixerAttributes)\nclass represents the mixer's attributes. The `AudioMixerAttributes` class includes an\n[`AudioFormat`](https://developer.android.com/reference/android/media/AudioFormat)\nobject that describes the audio data format, channel mask, and sample rate for\nthe mixer. By default, the framework determines the mixer behavior, which mixes\nall audio sources and applies volume control and effects.\n\nIf the mixer behavior uses `BIT_PERFECT` mode, the system sends the audio\ncontent without modification through the audio framework, HAL and optionally\ndigital signal processor (DSP), from the API down to the USB device. The\n`BIT_PERFECT` mode supports encoded formats, such as MQA or DSD, on which any\nvolume scaling or mixing can destroy the meaning of the data.\n\nWhen apps configure mixer attributes, the framework reopens the output stream\nwith new attributes, if needed. The following figure shows the interface between\nthe app, framework, and the HAL when mixer attributes are set:\n\n**Figure 1.** Interface between the app, framework, and HAL.\n\nImplementation\n--------------\n\nImplementation of preferred mixer attributes, other than the `BIT_PERFECT`\nattribute, for USB audio is mandatory for Android 14.\n\n### Preferred mixer attributes\n\nTo support preferred mixer attributes, vendors must support routing USB devices\nto the dynamic mix port, as follows:\n\n1. Define the dynamic mix port in [`usb_audio_policy_configuration.xml`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml).\n\n2. Declare the ability to route USB devices to dynamic mix ports either in\n [audio policy configuration](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/audiopolicy/config/audio_policy_configuration.xml)\n or in the [`getAudioPorts`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/audio/aidl/android/hardware/audio/core/IModule.aidl;drc=0abca2170b9e49c23f511ff1a6a99e5db8ab4104;l=267) and [`getAudioRoutes`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/interfaces/audio/aidl/android/hardware/audio/core/IModule.aidl;drc=0abca2170b9e49c23f511ff1a6a99e5db8ab4104;l=279) AIDL methods.\n\n| **Note:** If the USB audio functionality is migrated to the primary HAL, define the dynamic mix port and USB audio routing in the [audio policy configuration](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/audiopolicy/config/audio_policy_configuration.xml) file for your primary HAL.\n\nSee the reference implementation for the USB audio HAL under [`hardware/libhardware/modules/usbaudio`](https://cs.android.com/android/platform/superproject/+/android-latest-release:hardware/libhardware/modules/usbaudio/).\nSee an example of a dynamic mix port in [`frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml`](https://cs.android.com/android/platform/superproject/+/android-latest-release:frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml).\n| **Note:** Only USB devices are allowed to set preferred mixer attributes.\n\n### Bit-perfect playback attribute\n\nThe bit-perfect playback attribute is optional and is supported only in the AIDL\nimplementation of the Audio HAL. To support bit-perfect playback, vendors must\nadd the bit-perfect output flag `AUDIO_OUTPUT_FLAG_BIT_PERFECT` to the dynamic\nmix port that can be routed to the USB device.\n\nThe following code sample shows the use of the `AUDIO_OUTPUT_FLAG_BIT_PERFECT`\nflag in `usb_audio_policy_configuration.xml`: \n\n \u003cmodule name=\"usb\" halVersion=\"2.0\"\u003e\n \u003cmixPorts\u003e\n \u003cmixPort name=\"hifi_output\"\n role=\"source\" flags=\"AUDIO_OUTPUT_FLAG_BIT_PERFECT\"\u003e\n \u003c/mixPort\u003e\n \u003c/mixPorts\u003e\n \u003cdevicePorts\u003e\n \u003cdevicePort tagName=\"USB Device Out\"\n type=\"AUDIO_DEVICE_OUT_USB_DEVICE\" role=\"sink\"\u003e\n \u003c/devicePort\u003e\n \u003c/devicePorts\u003e\n \u003croutes\u003e\n \u003croute type=\"mix\" sink=\"USB Device Out\"\n sources=\"hifi_output\"/\u003e\n \u003c/routes\u003e\n \u003c/module\u003e\n\nIf the bit-perfect playback attribute is specified, the HAL must ensure that the\naudio stream is sent to the USB device without any modification, that is, the\naudio stream must not have any volume scaling, sample rate conversion, or audio\nprocessing effects and must not be mixed in the DSP.\nIn this case, the hardware controls the volume as the framework doesn't provide\nany software volume control.\n| **Note:** Without the bit-perfect playback attribute, apps can't stream high-resolution content, such as DSD and MQA, through the audio framework.\n\nValidation\n----------\n\nRun the CTS tests in\n[`PreferredMixerAttributesTestActivity.java`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/apps/CtsVerifier/src/com/android/cts/verifier/audio/PreferredMixerAttributesTestActivity.java)\nto validate support for preferred mixer attributes for USB devices.\n\nTo validate the implementation of the `BIT_PERFECT` attribute, use USB DACs that\nsupport MQA and DSD over pulse-code modulation (PCM) audio formats."]]