1# audio<a name="EN-US_TOPIC_0000001078525242"></a> 2 3- [Introduction](#section11660541593) 4- [Directory Structure](#section161941989596) 5 - [Available APIs](#section1551164914237) 6 - [Usage Guidelines](#section129654513264) 7 8- [Repositories Involved](#section1371113476307) 9 10## Introduction<a name="section11660541593"></a> 11 12This repository contains a set of HDIs that can be used to: 13 14- Manage loading and unloading of sound card drivers. 15- Create audio renderer and capturer. 16- Select an audio scene. 17- Set audio properties. 18- Set the audio volume and gain. 19- Start or stop audio playback and recording. 20 21**Figure 1** Logic view of modules related to this repository<a name="fig3672817152110"></a> 22 23 24## Directory Structure<a name="section161941989596"></a> 25 26The source code directory structure in this repository is as follows: 27 28``` 29drivers/peripheral/audio/ 30└── interfaces # External interfaces provided by the audio driver module 31 └── include # HDIs provided by the audio driver module for application development 32``` 33 34### Available APIs<a name="section1551164914237"></a> 35 36The 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. 37 38[Table 1](#table1513255710559) describes major HDIs provided by the audio driver module. 39 40**Table 1** Audio HDIs 41 42<a name="table1513255710559"></a> 43<table><thead align="left"><tr id="row171321857155517"><th class="cellrowborder" valign="top" width="10.721072107210723%" id="mcps1.2.4.1.1"><p id="p6132957115511"><a name="p6132957115511"></a><a name="p6132957115511"></a>Header File</p> 44</th> 45<th class="cellrowborder" valign="top" width="66.36663666366637%" id="mcps1.2.4.1.2"><p id="p14132125715552"><a name="p14132125715552"></a><a name="p14132125715552"></a>API</p> 46</th> 47<th class="cellrowborder" valign="top" width="22.912291229122914%" id="mcps1.2.4.1.3"><p id="p18132205755516"><a name="p18132205755516"></a><a name="p18132205755516"></a>Description</p> 48</th> 49</tr> 50</thead> 51<tbody><tr id="row13132357165514"><td class="cellrowborder" rowspan="3" valign="top" width="10.721072107210723%" headers="mcps1.2.4.1.1 "><p id="p15132185775510"><a name="p15132185775510"></a><a name="p15132185775510"></a>audio_manager.h</p> 52<p id="p18132157175510"><a name="p18132157175510"></a><a name="p18132157175510"></a></p> 53<p id="p2133757135510"><a name="p2133757135510"></a><a name="p2133757135510"></a></p> 54</td> 55<td class="cellrowborder" valign="top" width="66.36663666366637%" headers="mcps1.2.4.1.2 "><p id="p11132857135517"><a name="p11132857135517"></a><a name="p11132857135517"></a>int32_t (*GetAllAdapters)(struct AudioManager *manager, struct AudioAdapterDescriptor **descs, int32_t *size);</p> 56</td> 57<td class="cellrowborder" valign="top" width="22.912291229122914%" headers="mcps1.2.4.1.3 "><p id="p213285715558"><a name="p213285715558"></a><a name="p213285715558"></a>Obtains the list of all adapters supported by an audio driver.</p> 58</td> 59</tr> 60<tr id="row9132135715515"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16133957155517"><a name="p16133957155517"></a><a name="p16133957155517"></a>int32_t (*LoadAdapter)(struct AudioManager *manager, const struct AudioAdapterDescriptor *desc, struct AudioAdapter **adapter);</p> 61</td> 62<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p113315745519"><a name="p113315745519"></a><a name="p113315745519"></a>Loads the driver for an audio adapter.</p> 63</td> 64</tr> 65<tr id="row171330575555"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p913315573557"><a name="p913315573557"></a><a name="p913315573557"></a>void (*UnloadAdapter)(struct AudioManager *manager, struct AudioAdapter *adapter);</p> 66</td> 67<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1413365765514"><a name="p1413365765514"></a><a name="p1413365765514"></a>Unloads the driver for an audio adapter.</p> 68</td> 69</tr> 70<tr id="row1513316577554"><td class="cellrowborder" rowspan="6" valign="top" width="10.721072107210723%" headers="mcps1.2.4.1.1 "><p id="p15133657185517"><a name="p15133657185517"></a><a name="p15133657185517"></a>audio_adapter.h</p> 71<p id="p1513315717555"><a name="p1513315717555"></a><a name="p1513315717555"></a></p> 72<p id="p81331057125513"><a name="p81331057125513"></a><a name="p81331057125513"></a></p> 73<p id="p18703206155812"><a name="p18703206155812"></a><a name="p18703206155812"></a></p> 74<p id="p17186692581"><a name="p17186692581"></a><a name="p17186692581"></a></p> 75<p id="p28322099581"><a name="p28322099581"></a><a name="p28322099581"></a></p> 76</td> 77<td class="cellrowborder" valign="top" width="66.36663666366637%" headers="mcps1.2.4.1.2 "><p id="p1213365714550"><a name="p1213365714550"></a><a name="p1213365714550"></a>int32_t (*InitAllPorts)(struct AudioAdapter *adapter);</p> 78</td> 79<td class="cellrowborder" valign="top" width="22.912291229122914%" headers="mcps1.2.4.1.3 "><p id="p201331557185512"><a name="p201331557185512"></a><a name="p201331557185512"></a>Initializes all ports of an audio adapter.</p> 80</td> 81</tr> 82<tr id="row171331657185514"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p913305715553"><a name="p913305715553"></a><a name="p913305715553"></a>int32_t (*CreateRender)(struct AudioAdapter *adapter, const struct AudioDeviceDescriptor *desc, const struct AudioSampleAttributes *attrs, struct AudioRender **render);</p> 83</td> 84<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p161332570553"><a name="p161332570553"></a><a name="p161332570553"></a>Creates an <strong id="b110819501338"><a name="b110819501338"></a><a name="b110819501338"></a>AudioRender</strong> object.</p> 85</td> 86</tr> 87<tr id="row41331557165518"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p6133145713559"><a name="p6133145713559"></a><a name="p6133145713559"></a>int32_t (*DestroyRender)(struct AudioAdapter *adapter, struct AudioRender *render);</p> 88</td> 89<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p131331557175510"><a name="p131331557175510"></a><a name="p131331557175510"></a>Destroys an <strong id="b1528712211157"><a name="b1528712211157"></a><a name="b1528712211157"></a>AudioRender</strong> object.</p> 90</td> 91</tr> 92<tr id="row77021769584"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p77031566584"><a name="p77031566584"></a><a name="p77031566584"></a>int32_t (*GetPortCapability)(struct AudioAdapter *adapter, const struct AudioPort *port, struct AudioPortCapability *capability);</p> 93</td> 94<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1470315695811"><a name="p1470315695811"></a><a name="p1470315695811"></a>Obtains the capability set of the port driver for the audio adapter.</p> 95</td> 96</tr> 97<tr id="row71857914585"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1318619155811"><a name="p1318619155811"></a><a name="p1318619155811"></a>int32_t (*SetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, enum AudioPortPassthroughMode mode);</p> 98</td> 99<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1186597589"><a name="p1186597589"></a><a name="p1186597589"></a>Sets the passthrough data transmission mode of the audio port driver.</p> 100</td> 101</tr> 102<tr id="row18831119115815"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p48323975814"><a name="p48323975814"></a><a name="p48323975814"></a>int32_t (*GetPassthroughMode)(struct AudioAdapter *adapter, const struct AudioPort *port, enum AudioPortPassthroughMode *mode);</p> 103</td> 104<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p15832129135813"><a name="p15832129135813"></a><a name="p15832129135813"></a>Obtains the passthrough data transmission mode of the audio port driver.</p> 105</td> 106</tr> 107<tr id="row1452521025813"><td class="cellrowborder" rowspan="8" valign="top" width="10.721072107210723%" headers="mcps1.2.4.1.1 "><p id="p12525910165811"><a name="p12525910165811"></a><a name="p12525910165811"></a>audio_render.h</p> 108<p id="p1929018168192"><a name="p1929018168192"></a><a name="p1929018168192"></a></p> 109<p id="p99515179192"><a name="p99515179192"></a><a name="p99515179192"></a></p> 110<p id="p11331918201913"><a name="p11331918201913"></a><a name="p11331918201913"></a></p> 111<p id="p209341981918"><a name="p209341981918"></a><a name="p209341981918"></a></p> 112<p id="p1996019191197"><a name="p1996019191197"></a><a name="p1996019191197"></a></p> 113<p id="p2812720131919"><a name="p2812720131919"></a><a name="p2812720131919"></a></p> 114<p id="p942322013262"><a name="p942322013262"></a><a name="p942322013262"></a></p> 115</td> 116<td class="cellrowborder" valign="top" width="66.36663666366637%" headers="mcps1.2.4.1.2 "><p id="p105259109581"><a name="p105259109581"></a><a name="p105259109581"></a>int32_t (*RenderFrame)(struct AudioRender *render, const void *frame, uint64_t requestBytes, uint64_t *replyBytes);</p> 117</td> 118<td class="cellrowborder" valign="top" width="22.912291229122914%" headers="mcps1.2.4.1.3 "><p id="p752531095814"><a name="p752531095814"></a><a name="p752531095814"></a>Writes a frame of output data (downlink data) into the audio driver for rendering.</p> 119</td> 120</tr> 121<tr id="row172902161193"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p16290141681918"><a name="p16290141681918"></a><a name="p16290141681918"></a>int32_t (*GetRenderPosition)(struct AudioRender *render, uint64_t *frames, struct AudioTimeStamp *time);</p> 122</td> 123<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p1929141611198"><a name="p1929141611198"></a><a name="p1929141611198"></a>Obtains the last number of output audio frames.</p> 124</td> 125</tr> 126<tr id="row1948179195"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p1395181710193"><a name="p1395181710193"></a><a name="p1395181710193"></a>int32_t (*SetRenderSpeed)(struct AudioRender *render, float speed);</p> 127</td> 128<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p169531741912"><a name="p169531741912"></a><a name="p169531741912"></a>Sets the audio playback speed.</p> 129</td> 130</tr> 131<tr id="row1331121813197"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p533121871912"><a name="p533121871912"></a><a name="p533121871912"></a>int32_t (*GetRenderSpeed)(struct AudioRender *render, float *speed);</p> 132</td> 133<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p4331131817195"><a name="p4331131817195"></a><a name="p4331131817195"></a>Obtains the current playback speed.</p> 134</td> 135</tr> 136<tr id="row1393181951920"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p79410191191"><a name="p79410191191"></a><a name="p79410191191"></a>int32_t (*SetChannelMode)(struct AudioRender *render, enum AudioChannelMode mode);</p> 137</td> 138<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p17948193197"><a name="p17948193197"></a><a name="p17948193197"></a>Sets the channel mode for audio rendering.</p> 139</td> 140</tr> 141<tr id="row12422102092613"><td class="cellrowborder" valign="top" headers="mcps1.2.4.1.1 "><p id="p194231720102610"><a name="p194231720102610"></a><a name="p194231720102610"></a>int32_t (*GetChannelMode)(struct AudioRender *render, enum AudioChannelMode *mode);</p> 142</td> 143<td class="cellrowborder" valign="top" headers="mcps1.2.4.1.2 "><p id="p342315202267"><a name="p342315202267"></a><a name="p342315202267"></a>Obtains the current channel mode for audio rendering.</p> 144</td> 145</tr> 146</tbody> 147</table> 148 149### Usage Guidelines<a name="section129654513264"></a> 150 151The core functionalities of this repository are as follows: 152 1531. Provides audio HDIs for audio services to implement basic audio features on applications. 1542. 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. 155 156For details about the invocation and implementation, see the API reference. 157 158## Repositories Involved<a name="section1371113476307"></a> 159 160[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver.md) 161 162[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md) 163 164[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md) 165 166[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md) 167 168[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral) 169 170