Preferred mixer attributes on USB devices

Android 14 provides developer APIs that apps can use to query and configure preferred mixer attributes for USB audio playback. These preferred mixer attributes improve the USB audio playback experience by letting apps set the audio format, channel mask, sample rate, and mixer behavior. With the use of the preferred mixer APIs on supported USB devices, users can get lower-latency audio playback and higher-resolution audio content.

This feature also provides support for the optional bit-perfect playback mixer behavior for USB devices. The bit-perfect mode enables playback for master quality authenticated (MQA) and direct stream digital (DSD) formats on compatible digital to analog converters (DACs).

Interface

The Audio Policy Manager handles the mixer attributes in the framework. The AudioMixerAttributes class represents the mixer's attributes. The AudioMixerAttributes class includes an AudioFormat object that describes the audio data format, channel mask, and sample rate for the mixer. By default, the framework determines the mixer behavior, which mixes all audio sources and applies volume control and effects.

If the mixer behavior uses BIT_PERFECT mode, the system sends the audio content without modification through the audio framework, HAL and optionally digital signal processor (DSP), from the API down to the USB device. The BIT_PERFECT mode supports encoded formats, such as MQA or DSD, on which any volume scaling or mixing can destroy the meaning of the data.

When apps configure mixer attributes, the framework reopens the output stream with new attributes, if needed. The following figure shows the interface between the app, framework, and the HAL when mixer attributes are set:

preferred-mixer-attr

Figure 1. Interface between the app, framework, and HAL.

Implementation

Implementation of preferred mixer attributes, other than the BIT_PERFECT attribute, for USB audio is mandatory for Android 14.

Preferred mixer attributes

To support preferred mixer attributes, vendors must support routing USB devices to the dynamic mix port, as follows:

  1. Define the dynamic mix port in usb_audio_policy_configuration.xml.

  2. Declare the ability to route USB devices to dynamic mix ports either in audio policy configuration or in the getAudioPorts and getAudioRoutes AIDL methods.

See the reference implementation for the USB audio HAL under hardware/libhardware/modules/usbaudio. See an example of a dynamic mix port in frameworks/av/services/audiopolicy/config/usb_audio_policy_configuration.xml.

Bit-perfect playback attribute

The bit-perfect playback attribute is optional and is supported only in the AIDL implementation of the Audio HAL. To support bit-perfect playback, vendors must add the bit-perfect output flag AUDIO_OUTPUT_FLAG_BIT_PERFECT to the dynamic mix port that can be routed to the USB device.

The following code sample shows the use of the AUDIO_OUTPUT_FLAG_BIT_PERFECT flag in usb_audio_policy_configuration.xml:

<module name="usb" halVersion="2.0">
    <mixPorts>
        <mixPort name="hifi_output"
                 role="source" flags="AUDIO_OUTPUT_FLAG_BIT_PERFECT">
        </mixPort>
    </mixPorts>
    <devicePorts>
        <devicePort tagName="USB Device Out"
                    type="AUDIO_DEVICE_OUT_USB_DEVICE" role="sink">
        </devicePort>
    </devicePorts>
    <routes>
        <route type="mix" sink="USB Device Out"
               sources="hifi_output"/>
    </routes>
</module>

If the bit-perfect playback attribute is specified, the HAL must ensure that the audio stream is sent to the USB device without any modification, that is, the audio stream must not have any volume scaling, sample rate conversion, or audio processing effects and must not be mixed in the DSP. In this case, the hardware controls the volume as the framework doesn’t provide any software volume control.

Validation

Run the CTS tests in PreferredMixerAttributesTestActivity.java to validate support for preferred mixer attributes for USB devices.

To validate the implementation of the BIT_PERFECT attribute, use USB DACs that support MQA and DSD over pulse-code modulation (PCM) audio formats.