Android 14 提供了开发者 API,应用可以使用这些 API 来查询和配置 USB 音频播放的首选混音器属性。这些首选混音器属性让应用可以设置音频格式、声道掩码、采样率和混音器行为,从而改善 USB 音频播放体验。通过在受支持的 USB 设备上使用首选混音器 API,用户可以获得延迟更低的音频播放和分辨率更高的音频内容。
此功能还支持 USB 设备的可选位完美播放混音器行为。位元完美模式支持在兼容的数字转模拟转换器 (DAC) 上播放母版经过身份验证的 (MQA) 和直接流数字 (DSD) 格式。
[null,null,["最后更新时间 (UTC):2025-03-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."]]