Audio HAL

Android's audio Hardware Abstraction Layer (HAL) connects the higher-level, audio-specific framework APIs in android.media to the underlying audio drivers and hardware. The Audio HAL defines the standard interface that audio services call into. It must be implemented for the audio hardware to function correctly.

This page gives an overview of the audio HAL and provides details of its API and implementation requirements.

Audio HAL interface

The audio HAL interface is defined using HIDL in .hal files and XSD schemas for the configuration files, shown as follows:

audio_hal

Figure 1: Audio HAL interface

Configuration files

Audio policy and audio effects XML configuration files are considered to be part of the Audio HAL interface. These files must conform to their schemas, and the conformance is verified by VTS tests.

As part of implementing the audio HAL, you must create an audio policy configuration file that describes the audio topology. Audio HAL capabilities must be declared in the audio_policy_configuration.xml file for the framework to use them.

Audio HAL API

The audio HAL contains the following APIs:

  • Core HAL
  • Effects HAL
  • Common HAL

Each of these APIs is described in the following sections.

Core HAL

The Core HAL is the main API used by AudioFlinger to play audio and control the audio routing. Some of the key interfaces are as follows:

  • IDeviceFactory.hal is the entry point into the API.
  • IDevice.hal and IPrimaryDevice.hal contain methods such as setMasterVolume or openInputStream.
  • Streams are unidirectional and are used by AudioFlinger to send or receive audio to and from the HAL through IStream.hal, IStreamOut.hal and IStreamIn.hal.

The following table lists the location of useful Core HAL components:

Core HAL component Location
Latest version of API /hardware/interfaces/audio/6.0
Types specific to the latest Core HAL API /hardware/interfaces/audio/6.0/types.hal
Audio policy configuration file XSD schema /hardware/interfaces/audio/6.0/config/audio_policy_configuration.xsd

The default implementation of the Core HAL API (/hardware/interfaces/audio/core/all-versions/default/) is a wrapper around pre-Treble HAL implementation using legacy shared libraries. The default implementation can also be considered as a reference when implementing new versions of audio HALs that interact with kernel drivers directly.

Effects HAL

The Effects HAL API is used by the effects framework to control audio effects. You can also configure pre-processing effects such as automatic gain control and noise suppression through the Effects HAL API.

The following table lists the location of useful Effects HAL components:

Effects HAL component Location
Latest version of API /hardware/interfaces/audio/effect/6.0/
Effect configuration file XSD schema /hardware/interfaces/audio/effect/6.0/xml/audio_effects_conf.xsd

For more information, see a sample implementation of the Effects API (/hardware/interfaces/audio/effect/all-versions/default/) and the Audio Effects section.

Common HAL

The Common HAL is a library of common data types used by the Core and Effects HAL APIs. It has no interfaces and contains the following:

  • Definitions (/hardware/interfaces/audio/common/6.0/types.hal) shared by the Core and Effect APIs.
  • Utilities (/hardware/interfaces/audio/common/all-versions) used to help coding against HIDL APIs for implementations, clients and tests.

Requirements

In addition to implementing the audio HAL and creating the audio policy configuration file, the following HAL requirements must be adhered to:

  • If capture for Sound Trigger (capture from hotword DSP buffer) is supported by one input profile, the implementation must support the number of active streams on this profile corresponding to the number of concurrent sessions supported by Sound Trigger HAL.
  • Concurrency of voice call TX and capture from the application processor as detailed on the Concurrent Capture page.

Version information

The following table lists the HAL version number for each Android release.

Android version HAL version
Android 11 6.0
Android 10 5.0
Android 9 4.0
Android 8 2.0