# audio - [Introduction](#section11660541593) - [Directory Structure](#section161941989596) - [Available APIs](#section1551164914237) - [Usage Guidelines](#section129654513264) - [Repositories Involved](#section1371113476307) ## Introduction This repository contains a set of HDIs that can be used to: - Manage loading and unloading of sound card drivers. - Create audio renderer and capturer. - Select an audio scene. - Set audio properties. - Set the audio volume and gain. - Start or stop audio playback and recording. **Figure 1** Logic view of modules related to this repository ![](figures/logic-view-of-modules-related-to-this-repository.png "logic-view-of-modules-related-to-this-repository") ## Directory Structure The source code directory structure in this repository is as follows: ``` drivers/peripheral/audio/ └── interfaces # External interfaces provided by the audio driver module └── include # HDIs provided by the audio driver module for application development ``` ### Available APIs The audio driver module provides functions that can be directly called by the audio service. The APIs are used to load or unload an audio adapter, create audio renderer and capturer, start or stop audio playback and recording, and adjust the audio volume. [Table 1](#table1513255710559) describes major HDIs provided by the audio driver module. **Table 1** Audio HDIs

Header File

API

Description

audio_manager.h

int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size);

Obtains the list of all adapters supported by an audio driver.

int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, struct AudioAdapter **adapter);

Loads the driver for an audio adapter.

void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter);

Unloads the driver for an audio adapter.

audio_adapter.h

int32_t (*InitAllPorts)(struct AudioAdapter *adapter);

Initializes all ports of an audio adapter.

int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, const struct AudioSampleAttributes *attrs, struct AudioRender **render);

Creates an AudioRender object.

int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render);

Destroys an AudioRender object.

int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, struct AudioPortCapability *capability);

Obtains the capability set of the port driver for the audio adapter.

int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, enum AudioPortPassthroughMode mode);

Sets the passthrough data transmission mode of the audio port driver.

int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, enum AudioPortPassthroughMode *mode);

Obtains the passthrough data transmission mode of the audio port driver.

audio_render.h

int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes);

Writes a frame of output data (downlink data) into the audio driver for rendering.

int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time);

Obtains the last number of output audio frames.

int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed);

Sets the audio playback speed.

int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed);

Obtains the current playback speed.

int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode);

Sets the channel mode for audio rendering.

int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode);

Obtains the current channel mode for audio rendering.

### Usage Guidelines The core functionalities of this repository are as follows: 1. Provides audio HDIs for audio services to implement basic audio features on applications. 2. Provides standard interfaces for device developers to ensure that the OEM vendor can comply with the HDI adapter standard. This promises a healthy evolution of the ecosystem. For details about the invocation and implementation, see the API reference. ## Repositories Involved [Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md) [drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) [drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) [drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) [drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral)