MI AO API

Version 2.17


1. SUMMARY

1.1. Module Description

Audio Output (AO) is mainly used to configure and enable Audio Output devices, send audio frame data, and perform acoustic algorithm processing. Acoustic algorithm processing mainly includes Sample Rate Conversion, Acoustic Noise Reduction, High-Pass Filtering, Equalizer, Automatic Gain Control and so on. In 2.17 and later versions of the API, MI_AO no longer includes the associated algorithm functions. The version info can be viewed in mi_ao.h of the SDK.

1.2. Flow Block Diagram

In the 2.17 and later API versions, MI_AI/MI_AO no longer includes the related algorithm functions, and only the basic capture/playback functions are maintained.

1.3. Keyword Description

  • Device

    Different from Device concepts of other modules, AO Device refers to different external input devices such as Line out, I2S TX, and HDMI.

  • Channel

    AO Channel refers to the number of physical channels.

  • SRC

    SRC refers to Sample Rate Conversion.

  • AGC

    AGC refers to Automatic Gain Control, and is used to control the output gain.

  • EQ

    EQ refers to Equalizer, and is used to process specific frequencies.

  • ANR

    ANR refers to Acoustic Noise Reduction, and is used to remove persistent, constant frequency noise in the environment.

  • HPF

    HPF refers to High-Pass Filtering.


2. API REFERENCE

Audio output (AO) is mainly used to enable audio output devices, send audio frames to output channels and other functions.

Table 2-1: API List

API name Features
MI_AO_SetPubAttr Set AO device properties
MI_AO_GetPubAttr Get AO device properties
MI_AO_Enable Enable AO device
MI_AO_Disable Disable AO device
MI_AO_EnableChn Enable AO channel
MI_AO_DisableChn Disable AO channel
MI_AO_SendFrame Send audio frame
MI_AO_EnableReSmp Enable AO resampling
MI_AO_DisableReSmp Disable AO resampling.
MI_AO_PauseChn Pause AO channel
MI_AO_ResumeChn Restore AO channel
MI_AO_ClearChnBuf Clear the current audio data buffer in the AO channel
MI_AO_QueryChnStat Query the current audio data cache status in the AO channel
MI_AO_SetVolume Set the AO device volume
MI_AO_GetVolume Get the volume of the AO device
MI_AO_SetMute Set the AO device mute status
MI_AO_GetMute Get the OM device mute status
MI_AO_ClrPubAttr Clear AO device properties
MI_AO_SetVqeAttr Set AO's sound quality enhancement related properties
MI_AO_GetVqeAttr Get AO's sound quality enhancement related properties
MI_AO_EnableVqe Enable AO's sound quality enhancements
MI_AO_DisableVqe Disable AO's sound quality enhancements
MI_AO_SetAdecAttr Set AO decoding function related properties
MI_AO_GetAdecAttr Get the AO decoding function related properties
MI_AO_EnableAdec Enable AO decoding.
MI_AO_DisableAdec Disable AO decoding.
MI_AO_SetChnParam Set the parameter of AO channel
MI_AO_GetChnParam Get the parameter of AO channel
MI_AO_SetSrcGain Set AO device as Acoustic Echo Cancellation's gain
MI_AO_InitDev Initialize audio output device
MI_AO_DeinitDev De-initialize audio output device
MI_AO_DupChn Synchronize status of AO channel

2.1. MI_AO_SetPubAttr

  • Features

    Set the AO device properties.

  • Syntax

    MI_S32 MI_AO_SetPubAttr(MI_AUDIO_DEV AoDevId, MI_AUDIO_Attr_t  *pstAttr);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    pstAttr AO device property pointer. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    Audio output device attributes include sampling rate, sampling accuracy, output operation mode, number of sampling points per frame, number of channels and configuration parameters of I2S. If the codec needs to be docked, these attributes should be consistent with the requirements of the codec to be docked.

    Sampling rate

    The sampling rate refers to the number of sampling points in one second. The higher the sampling rate is, the smaller the distortion is and the more data is processed. Generally speaking, 8K sampling rate is used for voice and 32K or above for audio. Currently, only 8/ 11.025/12/16/22.05/24/32/44.1/48kHz sampling rate is supported. If you need to dock codec, please confirm whether the docked audio codec supports the sampling rate to be set when setting.

    Sampling accuracy

    Sampling accuracy refers to the sampling point data width of a channel and determines the channel distribution of the entire device. The sampling accuracy supports 16 bits.

    Operating mode

    Audio input and output currently supports I2S master mode, I2S slave mode, Tdm master mode and Tdm slave mode, but the content supported by each audio device may be different.

    Number of samples per frame

    When the audio sampling rate is high, it is recommended to increase the number of sampling points per frame accordingly. If the sound is intermittent, you can increase the number of samples per frame and the buffer count as deemed necessary.

    Number of channels

    1 for mono and 2 for stereo.

    Configuration of I2S

    The configuration parameters of I2S specify the frequency of I2S MCLK, the data format of I2S transmission, and whether I2S uses 4-wire mode or 6-wire mode, the tdm slot number of I2S, the bit width of I2S.

  • Example

    The following code shows how to initialize the AO device, send a frame of audio data, and uninitialize the AO device.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.    
    9.  stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    10. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    11. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    12. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    13. stAttr.u32PtNumPerFrm = 1024;  
    14. stAttr.u32ChnCnt = 1;  
    15.   
    16. MI_SYS_Init();  
    17.   
    18. /* set ao public attr*/  
    19. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    20. if(MI_SUCCESS != ret)  
    21. {  
    22.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    23.     return ret;  
    24. }  
    25.   
    26. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    27. if(MI_SUCCESS != ret)  
    28. {  
    29.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    30.     return ret;  
    31. }  
    32.   
    33. /* enable ao device*/  
    34. ret = MI_AO_Enable(AoDevId);  
    35. if(MI_SUCCESS != ret)  
    36. {  
    37.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    38.     return ret;  
    39. }  
    40.   
    41. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    42. if (MI_SUCCESS != ret)  
    43. {  
    44.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    45.     return ret;  
    46. }  
    47.   
    48. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    49. stAoSendFrame.u32Len = 1024;  
    50. stAoSendFrame.apVirAddr[0] = u8Buf;  
    51. stAoSendFrame.apVirAddr[1] = NULL;  
    52.   
    53. do{  
    54.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    55. }while(ret == MI_AO_ERR_NOBUF);  
    56.   
    57. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    58. if (MI_SUCCESS != ret)  
    59. {  
    60.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    61.     return ret;  
    62. }  
    63.   
    64. /* disable ao device */  
    65. ret = MI_AO_Disable(AoDevId);  
    66. if(MI_SUCCESS != ret)  
    67. {  
    68.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    69.     return ret;  
    70. }  
    71.   
    72. MI_SYS_Exit();
    

2.2. MI_AO_GetPubAttr

  • Features

    Get the AO device properties.

  • Syntax

    MI_S32 MI_AO_GetPubAttr(MI_AUDIO_DEV AoDevId, MI_AUDIO_Attr_t  *pstAttr);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    pstAttr AO device property pointer. Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • The obtained property is the property of the previous configuration.

    • If the property has never been configured, it returns a Failure.

  • Example

    Refer to the example section of MI_AO_SetPubAttr.

2.3. MI_AO_Enable

  • Features

    Enable AO devices.

  • Syntax

    MI_S32 MI_AO_Enable(MI_AUDIO_DEV AoDevId);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • The AO device attribute must be configured before enabling, otherwise the return attribute is not configured incorrectly.

    • If the AO device is already enabled, it will return directly.

  • Example

    Refer to the example section of MI_AO_SetPubAttr.

2.4. MI_AO_Disable

  • Features

    Disable AO devices.

  • Syntax

    MI_S32 MI_AO_Disable(MI_AUDIO_DEV AoDevId);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • If the AO device is already disabled, it will return directly.

    • All AO channels enabled under this device must be disabled before disabling AO devices

    • You must call this interface before setting device attribute.

  • Example

    Refer to the example section of MI_AO_SetPubAttr.

2.5. MI_AO_EnableChn

  • Features

    Enable AO channel

  • Syntax

    MI_S32 MI_AO_EnableChn(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    Before enabling the AO channel, you must first enable the AO device to which it belongs, otherwise it will return the error code that the device is not started

  • Example

    Refer to the example section of MI_AO_SetPubAttr.

2.6. MI_AO_DisableChn

  • Features

    AI channel disabled

  • Syntax

    MI_S32 MI_AO_DisableChn(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    Before disabling the AO channel, you need to disable the enabled Audio Algorithm on that channel.

  • Example

    Refer to the example section of MI_AO_SetPubAttr.

2.7. MI_AO_SendFrame

  • Features

    Send an AO audio frame.

  • Syntax

    MI_S32 MI_AO_SendFrame(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn,
    MI_AUDIO_Frame_t  *pstData, MI_S32 s32MilliSec);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Only channel 0 is supported. Input
    pstData Audio frame structure pointer. Input
    s32MilliSec Timeout for getting data -1 indicates blocking mode, waiting for no data; 0 means non-blocking mode, when there is no data, it will return an error; >0 means to block s32MilliSec milliseconds, and the timeout will return an error. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • s32MilliSec value must be greater than equal to -1, equal to -1, use blocking mode to send data, equal to 0, use non-blocking mode to send data, when greater than 0, if the transmission is still unsuccessful after blocking s32MilliSec ms, it will return a timeout and report an error.

    • When calling this interface to send audio frames to the AO output, you must first enable the corresponding AO channel.

  • Example

    Refer to the example section of MI_AO_SetPubAttr.

2.8. MI_AO_EnableReSmp

  • Features

    Enable AO resampling

  • Syntax

    MI_S32 MI_AO_EnableReSmp(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AUDIO_SampleRate_e eInSampleRate);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number. Input
    eInSampleRate The input sample rate for audio resampling. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libSRC_LINUX.so

  • Note

    • After AO channels is enabled, call this interface to enable resampling function before binding the AO channels.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    The following code shows how to turn resampling on and off. Input data is 16K, and resample is 8K for playback.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.  MI_AUDIO_SampleRate_e eInSampleRate = E_MI_AUDIO_SAMPLE_RATE_16000;  
    9.    
    10. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    11. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    12. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    13. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    14. stAttr.u32PtNumPerFrm = 1024;  
    15. stAttr.u32ChnCnt = 1;  
    16.   
    17. MI_SYS_Init();  
    18.   
    19. /* set ao public attr*/  
    20. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    21. if(MI_SUCCESS != ret)  
    22. {  
    23.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    24.     return ret;  
    25. }  
    26.   
    27. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    28. if(MI_SUCCESS != ret)  
    29. {  
    30.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    31.     return ret;  
    32. }  
    33.   
    34. /* enable ao device*/  
    35. ret = MI_AO_Enable(AoDevId);  
    36. if(MI_SUCCESS != ret)  
    37. {  
    38.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    39.     return ret;  
    40. }  
    41.   
    42. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    43. if (MI_SUCCESS != ret)  
    44. {  
    45.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    46.     return ret;  
    47. }  
    48.   
    49. ret = MI_AO_EnableReSmp(AoDevId, AoChn, eInSampleRate);  
    50. if (MI_SUCCESS != ret)  
    51. {  
    52.     printf("enable resample ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    53.     return ret;  
    54. }  
    55.   
    56. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    57. stAoSendFrame.u32Len = 1024;  
    58. stAoSendFrame.apVirAddr[0] = u8Buf;  
    59. stAoSendFrame.apVirAddr[1] = NULL;  
    60.   
    61. do{  
    62.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    63. }while(ret == MI_AO_ERR_NOBUF);  
    64.   
    65. ret = MI_AO_DisableReSmp(AoDevId, AoChn);  
    66. if (MI_SUCCESS != ret)  
    67. {  
    68.     printf("disable resample ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    69.     return ret;  
    70. }  
    71.   
    72. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    73. if (MI_SUCCESS != ret)  
    74. {  
    75.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    76.     return ret;  
    77. }  
    78.   
    79. /* disable ao device */  
    80. ret = MI_AO_Disable(AoDevId);  
    81. if(MI_SUCCESS != ret)  
    82. {  
    83.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    84.     return ret;  
    85. }  
    86.   
    87. MI_SYS_Exit();
    

2.9. MI_AO_DisableReSmp

  • Features

    Disable AO resampling

  • Syntax

    MI_S32 MI_AO_DisableReSmp(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libSRC_LINUX.so

  • Note

    • If you no longer use the AO resampling feature, you should call this interface to disable it.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    Refer to the MI_AO_EnableReSmp example section.

2.10. MI_AO_PauseChn

  • Features

    Pause AO channel

  • Syntax

    MI_S32 MI_AO_PauseChn(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    When the AO channel is disabled, it is not allowed to call this interface to suspend the AO channel.

  • Example

    The following code shows how to pause and resume AO playback.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.    
    9.  stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    10. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    11. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    12. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    13. stAttr.u32PtNumPerFrm = 1024;  
    14. stAttr.u32ChnCnt = 1;  
    15.   
    16. MI_SYS_Init();  
    17.   
    18. /* set ao public attr*/  
    19. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    20. if(MI_SUCCESS != ret)  
    21. {  
    22.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    23.     return ret;  
    24. }  
    25.   
    26. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    27. if(MI_SUCCESS != ret)  
    28. {  
    29.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    30.     return ret;  
    31. }  
    32.   
    33. /* enable ao device*/  
    34. ret = MI_AO_Enable(AoDevId);  
    35. if(MI_SUCCESS != ret)  
    36. {  
    37.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    38.     return ret;  
    39. }  
    40.   
    41. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    42. if (MI_SUCCESS != ret)  
    43. {  
    44.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    45.     return ret;  
    46. }  
    47.   
    48. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    49. stAoSendFrame.u32Len = 1024;  
    50. stAoSendFrame.apVirAddr[0] = u8Buf;  
    51. stAoSendFrame.apVirAddr[1] = NULL;  
    52.   
    53. do{  
    54.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    55. }while(ret == MI_AO_ERR_NOBUF);  
    56.   
    57. ret = MI_AO_PauseChn(AoDevId, AoChn);  
    58. if (MI_SUCCESS != ret)  
    59. {  
    60.     printf("pause ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    61.     return ret;  
    62. }  
    63.   
    64. ret = MI_AO_ResumeChn(AoDevId, AoChn);  
    65. if (MI_SUCCESS != ret)  
    66. {  
    67.     printf("resume ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    68.     return ret;  
    69. }  
    70.   
    71. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    72. if (MI_SUCCESS != ret)  
    73. {  
    74.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    75.     return ret;  
    76. }  
    77.   
    78. /* disable ao device */  
    79. ret = MI_AO_Disable(AoDevId);  
    80. if(MI_SUCCESS != ret)  
    81. {  
    82.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    83.     return ret;  
    84. }  
    85.   
    86. MI_SYS_Exit();
    

2.11. MI_AO_ResumeChn

  • Features

    Restore the AO channel.

  • Syntax

    MI_S32 MI_AO_ResumeChn (MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

  • After the AO channel is paused, it can be restored by calling this interface.

  • When the AO channel is in the suspended state or enabled state, calling this interface returns success; otherwise, the call will return an error.

  • Example

    Refer to the MI_AO_PauseChn example section.

2.12. MI_AO_ClearChnBuf

  • Features

    Clear the current audio data buffer in the AO channel.

  • Syntax

    MI_S32 MI_AO_ClearChnBuf (MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number.   Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    This interface is called after the AO channel is successfully enabled.

  • Example

    The following code shows how to get the AO channel buffer status and clear the buffer.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.  MI_AO_ChnState_t stStatus;  
    9.    
    10. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    11. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    12. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    13. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    14. stAttr.u32PtNumPerFrm = 1024;  
    15. stAttr.u32ChnCnt = 1;  
    16.   
    17. MI_SYS_Init();  
    18.   
    19. /* set ao public attr*/  
    20. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    21. if(MI_SUCCESS != ret)  
    22. {  
    23.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    24.     return ret;  
    25. }  
    26.   
    27. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    28. if(MI_SUCCESS != ret)  
    29. {  
    30.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    31.     return ret;  
    32. }  
    33.   
    34. /* enable ao device*/  
    35. ret = MI_AO_Enable(AoDevId);  
    36. if(MI_SUCCESS != ret)  
    37. {  
    38.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    39.     return ret;  
    40. }  
    41.   
    42. /* enable ao chn */  
    43. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    44. if (MI_SUCCESS != ret)  
    45. {  
    46.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    47.     return ret;  
    48. }  
    49.   
    50. /* send frame */  
    51. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    52. stAoSendFrame.u32Len = 1024;  
    53. stAoSendFrame.apVirAddr[0] = u8Buf;  
    54. stAoSendFrame.apVirAddr[1] = NULL;  
    55.   
    56. do{  
    57.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    58. }while(ret == MI_AO_ERR_NOBUF);  
    59.   
    60. /* get chn stat */  
    61. ret = MI_AO_QueryChnStat(AoDevId, AoChn, &stStatus);  
    62. if (MI_SUCCESS != ret)  
    63. {  
    64.     printf("query chn status ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    65.     return ret;  
    66. }  
    67.   
    68. /* clear chn buf */  
    69. ret = MI_AO_ClearChnBuf(AoDevId, AoChn);  
    70. if (MI_SUCCESS != ret)  
    71. {  
    72.     printf("clear chn buf ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    73.     return ret;  
    74. }  
    75.   
    76. /* disable ao chn */  
    77. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    78. if (MI_SUCCESS != ret)  
    79. {  
    80.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    81.     return ret;  
    82. }  
    83.   
    84. /* disable ao device */  
    85. ret = MI_AO_Disable(AoDevId);  
    86. if(MI_SUCCESS != ret)  
    87. {  
    88.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    89.     return ret;  
    90. }  
    91.   
    92. MI_SYS_Exit();
    

2.13. MI_AO_QueryChnStat

  • Features

    Query the current audio data cache status in the AO channel.

  • Syntax

    MI_S32 MI_AO_QueryChnStat(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_ChnState_t  *pstStatus);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number.   Input
    pstStatus Cache state structure pointer. Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    This interface is called after the AO channel is successfully enabled.

  • Example

    Refer to the MI_AO_ClearChnBuf example section.

2.14. MI_AO_SetVolume

  • Features

    Set the volume of the AO device/channel.

  • Syntax

    MI_AO API Version <= 2.13:
    MI_S32 MI_AO_SetVolume(MI_AUDIO_DEV AoDevId, MI_S32 s32VolumeDb);
    
    MI_AO API Version is 2.14:
    MI_S32 MI_AO_SetVolume(MI_AUDIO_DEV AoDevId, MI_S32 s32VolumeDb, MI_AO_GainFading_e eFading);
    
    MI_AO API Version >= 2.15:
    MI_S32 MI_AO_SetVolume(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_S32 s32VolumeDb, MI_AO_GainFading_e eFading);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio channel number Input
    s32VolumeDb Audio device volume size in dB (-60 - 30). Input
    eFading The speed of audio gain changing Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    This interface is called after the AO device is successfully enabled.

  • Example

    The following code shows how to set and get the volume parameters of AO.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.  MI_S32 s32VolumeDb = 0;  
    9.    
    10. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    11. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    12. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    13. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    14. stAttr.u32PtNumPerFrm = 1024;  
    15. stAttr.u32ChnCnt = 1;  
    16.   
    17. MI_SYS_Init();  
    18.   
    19. /* set ao public attr*/  
    20. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    21. if(MI_SUCCESS != ret)  
    22. {  
    23.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    24.     return ret;  
    25. }  
    26.   
    27. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    28. if(MI_SUCCESS != ret)  
    29. {  
    30.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    31.     return ret;  
    32. }  
    33.   
    34. /* enable ao device*/  
    35. ret = MI_AO_Enable(AoDevId);  
    36. if(MI_SUCCESS != ret)  
    37. {  
    38.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    39.     return ret;  
    40. }  
    41.   
    42. /* enable ao chn */  
    43. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    44. if (MI_SUCCESS != ret)  
    45. {  
    46.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    47.     return ret;  
    48. }  
    49.   
    50. /* set ao volume */  
    51. ret = MI_S32 MI_AO_SetVolume(AoDevId, AoChn, s32VolumeDb, E_MI_AO_GAIN_FADING_OFF);  
    52. if (MI_SUCCESS != ret)  
    53. {  
    54.     printf("set volume ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    55.     return ret;  
    56. }  
    57.   
    58. /* get ao volume */ 
    59. ret = MI_S32 MI_AO_GetVolume(AoDevId, AoChn, &s32VolumeDb);  
    60. if (MI_SUCCESS != ret)  
    61. {  
    62.     printf("get volume ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    63.     return ret;  
    64. }  
    65.   
    66. 
    67.   
    68. /* send frame */  
    69. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    70. stAoSendFrame.u32Len = 1024;  
    71. stAoSendFrame.apVirAddr[0] = u8Buf;  
    72. stAoSendFrame.apVirAddr[1] = NULL;  
    73.   
    74. do{  
    75.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    76. }while(ret == MI_AO_ERR_NOBUF);  
    77.   
    78.   
    79. /* disable ao chn */  
    80. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    81. if (MI_SUCCESS != ret)  
    82. {  
    83.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    84.     return ret;  
    85. }  
    86.   
    87. /* disable ao device */  
    88. ret = MI_AO_Disable(AoDevId);  
    89. if(MI_SUCCESS != ret)  
    90. {  
    91.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    92.     return ret;  
    93. }  
    94.   
    95. MI_SYS_Exit();
    

2.15. MI_AO_GetVolume

  • Features

    Get the volume of the AO device/channel.

  • Syntax

    MI_AO API Version <= 2.14:
    MI_S32 MI_AO_GetVolume(MI_AUDIO_DEV AoDevId, MI_S32 *ps32VolumeDb);
    
    MI_AO API Version >= 2.15:
    MI_S32 MI_AO_GetVolume(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_S32 *ps32VolumeDb);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio channel number Input
    ps32VolumeDb Audio device volume size pointer Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    This interface is called after the AO device is successfully enabled.

  • Example

    Refer to the example section of MI_AO_SetVolume.

2.16. MI_AO_SetMute

  • Features

    Set the AO device/channel mute status.

  • Syntax

    MI_AO API Version <= 2.14:
    MI_S32 MI_AO_SetMute(MI_AUDIO_DEV AoDevId, MI_BOOL bEnable);
    
    MI_AO API Version >= 2.15:
    MI_S32 MI_AO_SetMute(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_BOOL bEnable);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio channel number Input
    bEnable Whether the audio device is muted. TRUE : Enable mute function; FALSE : Turn off the mute function. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • This interface is called after the AO device is successfully enabled.
  • Example

    The following code shows how to get and set the mute state.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.  MI_BOOL bMute = TRUE;  
    9.    
    10. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    11. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    12. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    13. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    14. stAttr.u32PtNumPerFrm = 1024;  
    15. stAttr.u32ChnCnt = 1;  
    16.   
    17. MI_SYS_Init();  
    18.   
    19. /* set ao public attr*/  
    20. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    21. if(MI_SUCCESS != ret)  
    22. {  
    23.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    24.     return ret;  
    25. }  
    26.   
    27. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    28. if(MI_SUCCESS != ret)  
    29. {  
    30.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    31.     return ret;  
    32. }  
    33.   
    34. /* enable ao device*/  
    35. ret = MI_AO_Enable(AoDevId);  
    36. if(MI_SUCCESS != ret)  
    37. {  
    38.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    39.     return ret;  
    40. }  
    41.   
    42. /* enable ao chn */  
    43. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    44. if (MI_SUCCESS != ret)  
    45. {  
    46.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    47.     return ret;  
    48. }  
    49.   
    50. /* set ao mute */  
    51. ret = MI_AO_SetMute(AoDevId, AoChn, bMute);  
    52. if (MI_SUCCESS != ret)  
    53. {  
    54.     printf("mute ao dev %d Chn%d err:0x%x\n", AoDevId, AoChn, ret);  
    55.     return ret;  
    56. }  
    57.   
    58. /* get ao mute status */  
    59. ret = MI_AO_GetMute(AoDevId, AoChn, &bMute);  
    60. if (MI_SUCCESS != ret)  
    61. {  
    62.     printf("get mute status ao dev %d Chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    63.     return ret;  
    64. }  
    65.   
    66. /* send frame */  
    67. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    68. stAoSendFrame.u32Len = 1024;  
    69. stAoSendFrame.apVirAddr[0] = u8Buf;  
    70. stAoSendFrame.apVirAddr[1] = NULL;  
    71.   
    72. do{  
    73.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    74. }while(ret == MI_AO_ERR_NOBUF);  
    75.   
    76.   
    77. /* disable ao chn */  
    78. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    79. if (MI_SUCCESS != ret)  
    80. {  
    81.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    82.     return ret;  
    83. }  
    84.   
    85. /* disable ao device */  
    86. ret = MI_AO_Disable(AoDevId);  
    87. if(MI_SUCCESS != ret)  
    88. {  
    89.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    90.     return ret;  
    91. }  
    92.   
    93. MI_SYS_Exit();
    

2.17. MI_AO_GetMute

  • Features

    Get the AO device/channel mute status.

  • Syntax

    MI_AO API Version <= 2.14:
    MI_S32 MI_AO_GetMute(MI_AUDIO_DEV AoDevId, MI_BOOL *pbEnable);
    
    MI_AO API Version >= 2.15:
    MI_S32 MI_AO_GetMute(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_BOOL *pbEnable);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio channel number Input
    pbEnable Audio device mute status pointer. Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    This interface is called after the AO device is successfully enabled.

  • Example

    Refer to the MI_AO_SetMute example section

2.18. MI_AO_ClrPubAttr

  • Features

    Clear AO device properties.

  • Syntax

    MI_S32 MI_AO_ClrPubAttr(MI_AUDIO_DEV AoDevId);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    Before you can clear device properties, you need to stop the device first.

  • Example

    The following code shows how to set and clear the properties of the AO device.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_DEV AoDevId = 0;  
    4.    
    5.  stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    6.  stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    7.  stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    8.  stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    9.  stAttr.u32PtNumPerFrm = 1024;  
    10. stAttr.u32ChnCnt = 1;  
    11.   
    12. MI_SYS_Init();  
    13.   
    14. /* set ao public attr*/  
    15. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    16. if(MI_SUCCESS != ret)  
    17. {  
    18.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    19.     return ret;  
    20. }  
    21.   
    22. /* clear ao public attr */  
    23. ret = MI_AO_ClrPubAttr(AoDevId);  
    24. if (MI_SUCCESS != ret)  
    25. {  
    26.     printf("clear ao %d attr err:0x%x\n", AoDevId, ret);  
    27.     return ret;  
    28. }  
    29.   
    30. MI_SYS_Exit();
    

2.19. MI_AO_SetVqeAttr

  • Features

    Set the AO’s sound quality enhancement related properties.

  • Syntax

    MI_S32 MI_AO_SetVqeAttr(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_VqeConfig_t  *pstVqeConfig);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
    pstVqeConfig Audio output sound quality enhancement configuration structure pointer Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libAPC_LINUX.so

  • Note

    • Before you enable the sound quality enhancement function, you must set the sound quality enhancement related properties of the corresponding AO channel.

    • Before setting the AO's sound quality enhancement function related properties, you must first enable the corresponding AO channel.

    • When the same AO channel sound quality enhancement does Not supported dynamic set properties, re-set the sound quality AO channel enhancement relevant attributes need to turn off the sound quality function AO channel, then set the sound quality AO channel enhancements related attributes.

    • When you set the sound quality enhancement feature, you can select some of the features that are enabled by configuring the corresponding sound quality enhancement properties.

    • All algorithms of Vqe support 8/16K, only ANR/AGC/EQ support 48K.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    The following code shows how to set up and enable the sound quality enhancement.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;.  
    8.  MI_AO_VqeConfig_t stAoSetVqeConfig, stAoGetVqeConfig;  
    9.    
    10. MI_AUDIO_HpfConfig_t stHpfCfg = {  
    11.     .eMode = E_MI_AUDIO_ALGORITHM_MODE_USER,  
    12.     .eHpfFreq = E_MI_AUDIO_HPF_FREQ_150,  
    13. };  
    14.   
    15. MI_AUDIO_AnrConfig_t stAnrCfg = {  
    16.     .eMode = E_MI_AUDIO_ALGORITHM_MODE_MUSIC,  
    17.     .u32NrIntensity = 15,  
    18.     .u32NrSmoothLevel = 10,  
    19.     .eNrSpeed = E_MI_AUDIO_NR_SPEED_MID,  
    20. };  
    21.   
    22. MI_AUDIO_AgcConfig_t stAgcCfg = {  
    23.     .eMode = E_MI_AUDIO_ALGORITHM_MODE_USER,  
    24.     .s32NoiseGateDb = -60,  
    25.     .s32TargetLevelDb = -3,  
    26.     .stAgcGainInfo = {  
    27.         .s32GainInit = 0,  
    28.         .s32GainMax = 20,  
    29.         .s32GainMin = 0,  
    30.     },  
    31.     .u32AttackTime = 1,  
    32.     .s16Compression_ratio_input = {-80, -60, -40, -25, 0},  
    33.     .s16Compression_ratio_output = {-80, -30, -15, -10, -3},  
    34.     .u32DropGainMax = 12,  
    35.     .u32NoiseGateAttenuationDb = 0,  
    36.     .u32ReleaseTime = 3,  
    37. };  
    38.   
    39. MI_AUDIO_EqConfig_t stEqCfg = {  
    40.     .eMode = E_MI_AUDIO_ALGORITHM_MODE_DEFAULT,  
    41.     .s16EqGainDb = {[0 ... 128] = 3},  
    42. };  
    43.   
    44. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    45. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    46. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    47. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    48. stAttr.u32PtNumPerFrm = 1024;  
    49. stAttr.u32ChnCnt = 1;  
    50.   
    51. MI_SYS_Init();  
    52.   
    53. /* set ao public attr*/  
    54. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    55. if(MI_SUCCESS != ret)  
    56. {  
    57.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    58.     return ret;  
    59. }  
    60.   
    61. /* get ao public attr */  
    62. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    63. if(MI_SUCCESS != ret)  
    64. {  
    65.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    66.     return ret;  
    67. }  
    68.   
    69. /* enable ao device*/  
    70. ret = MI_AO_Enable(AoDevId);  
    71. if(MI_SUCCESS != ret)  
    72. {  
    73.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    74.     return ret;  
    75. }  
    76.   
    77. /* enable ao chn */  
    78. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    79. if (MI_SUCCESS != ret)  
    80. {  
    81.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    82.     return ret;  
    83. }  
    84.   
    85. stAoSetVqeConfig.bAgcOpen = TRUE;  
    86. stAoSetVqeConfig.bAnrOpen = TRUE;  
    87. stAoSetVqeConfig.bEqOpen = TRUE;  
    88. stAoSetVqeConfig.bHpfOpen = TRUE;  
    89. stAoSetVqeConfig.s32FrameSample = 128;  
    90. stAoSetVqeConfig.s32WorkSampleRate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    91. memcpy(&stAoSetVqeConfig.stAgcCfg, &stAgcCfg, sizeof(MI_AUDIO_AgcConfig_t));  
    92. memcpy(&stAoSetVqeConfig.stAnrCfg, &stAnrCfg, sizeof(MI_AUDIO_AnrConfig_t));  
    93. memcpy(&stAoSetVqeConfig.stEqCfg, &stEqCfg, sizeof(MI_AUDIO_EqConfig_t));  
    94. memcpy(&stAoSetVqeConfig.stHpfCfg, &stHpfCfg, sizeof(MI_AUDIO_HpfConfig_t));  
    95.   
    96. /* set vqe attr */  
    97. ret = MI_AO_SetVqeAttr(AoDevId, AoChn, &stAoSetVqeConfig);  
    98. if (MI_SUCCESS != s32Ret)  
    99. {  
    100.        printf("set vqe attr ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    101.        return ret;  
    102.    }  
    103.      
    104.    /* get vqe attr */  
    105.    ret = MI_AO_GetVqeAttr(AoDevId, AoChn, &stAoGetVqeConfig);  
    106.    if (MI_SUCCESS != s32Ret)  
    107.    {  
    108.        printf("get vqe attr ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    109.        return ret;  
    110.    }  
    111.      
    112.    /* enable vqe attr */  
    113.    ret = MI_AO_EnableVqe(AoDevId, AoChn);  
    114.    if (MI_SUCCESS != s32Ret)  
    115.    {  
    116.        printf("enable vqe ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    117.        return ret;  
    118.    }  
    119.      
    120.    /* send frame */  
    121.    memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    122.    stAoSendFrame.u32Len = 1024;  
    123.    stAoSendFrame.apVirAddr[0] = u8Buf;  
    124.    stAoSendFrame.apVirAddr[1] = NULL;  
    125.      
    126.    do{  
    127.        ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    128.    }while(ret == MI_AO_ERR_NOBUF);  
    129.      
    130.    /* disable vqe attr */  
    131.    ret = MI_AO_DisableVqe(AoDevId, AoChn);  
    132.    if (MI_SUCCESS != s32Ret)  
    133.    {  
    134.        printf("disable vqe ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    135.        return ret;  
    136.    }  
    137.      
    138.    /* disable ao chn */  
    139.    ret = MI_AO_DisableChn(AoDevId, AoChn);  
    140.    if (MI_SUCCESS != ret)  
    141.    {  
    142.        printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    143.        return ret;  
    144.    }  
    145.      
    146.    /* disable ao device */  
    147.    ret = MI_AO_Disable(AoDevId);  
    148.    if(MI_SUCCESS != ret)  
    149.    {  
    150.        printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    151.        return ret;  
    152.    }  
    153.      
    154.    MI_SYS_Exit();
    

2.20. MI_AO_GetVqeAttr

  • Features

    Get the AO’s sound quality enhancement related properties.

  • Syntax

    MI_S32 MI_AO_GetVqeAttr(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_VqeConfig_t  *pstVqeConfig);
    
  • Parameters

    parameter name description Input/Output
    AiDevId Audio device number Input
    AiChn Audio input channel number. Input
    pstVqeConfig Audio output sound quality enhancement configuration structure pointer Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libAPC_LINUX.so

  • Note

    • Before obtaining the sound quality enhancement related attributes, you must first set the sound quality enhancement related attributes of the corresponding AO channel.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    Refer to the MI_AO_SetVqeAttr example section.

2.21. MI_AO_EnableVqe

  • Features

    Enable AO's sound quality enhancements.

  • Syntax

    MI_S32 MI_AO_EnableVqe(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libAPC_LINUX.so

  • Note

    • The corresponding AO channel must be enabled before enabling the sound quality enhancement.

    • When the sound quality enhancement function of the same AO channel is enabled multiple times, the return is successful.

    • After disabling the AO channel, if you re-enable the AO channel and use the sound quality enhancement feature, you need to call this interface to re-enable sound quality enhancement.

    • All algorithms included in Vqe support 8/16k sampling rate, while only ANR/AGC/EQ support 48K.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    Refer to the MI_AO_SetVqeAttr example section.

2.22. MI_AO_DisableVqe

  • Features

    Disable AO’s sound quality enhancements.

  • Syntax

    MI_S32 MI_AO_DisableVqe(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libAPC_LINUX.so

  • Note

    • When AO sound quality enhancements are no longer used, this interface should be called to disable it.

    • The sound quality enhancement function of the same AO channel is disabled multiple times and the return is successful.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    Refer to the MI_AO_SetVqeAttr example section.

2.23. MI_AO_SetAdecAttr

  • Features

    Set the AO decoding function related properties.

  • Syntax

    MI_S32 MI_AO_SetAdecAttr (MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_AdecConfig_t  *pstAdecConfig);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
    pstAdecConfig Audio decoding configuration structure pointer Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libg711.a libg726.a

  • Note

    • Before setting the properties related to the decoding function of AO, the corresponding AO channel must be enabled first.

    • This interface is no longer supported in API version 2.17 and later.

  • Example

    The following code shows how to set and enable the decoding function.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.  MI_AO_AdecConfig_t stAoSetAdecConfig, stAoGetAdecConfig;  
    9.    
    10.   
    11. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    12. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    13. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    14. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    15. stAttr.u32PtNumPerFrm = 1024;  
    16. stAttr.u32ChnCnt = 1;  
    17.   
    18. MI_SYS_Init();  
    19.   
    20. /* set ao public attr*/  
    21. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    22. if(MI_SUCCESS != ret)  
    23. {  
    24.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    25.     return ret;  
    26. }  
    27.   
    28. /* get ao public attr */  
    29. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    30. if(MI_SUCCESS != ret)  
    31. {  
    32.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    33.     return ret;  
    34. }  
    35.   
    36. /* enable ao device*/  
    37. ret = MI_AO_Enable(AoDevId);  
    38. if(MI_SUCCESS != ret)  
    39. {  
    40.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    41.     return ret;  
    42. }  
    43.   
    44. /* enable ao chn */  
    45. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    46. if (MI_SUCCESS != ret)  
    47. {  
    48.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    49.     return ret;  
    50. }  
    51.   
    52. memset(&stAoSetAdecConfig, 0x0, sizeof(MI_AO_AdecConfig_t));  
    53. stAoSetAdecConfig.eAdecType = E_MI_AUDIO_ADEC_TYPE_G711A;  
    54. stAoSetAdecConfig.stAdecG711Cfg.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    55. stAoSetAdecConfig.stAdecG711Cfg.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    56.   
    57. /* set adec attr */  
    58. ret = MI_AO_SetAdecAttr(AoDevId, AoChn, &stAoSetAdecConfig);  
    59. if (MI_SUCCESS != s32Ret)  
    60. {  
    61.     printf("set adec attr ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    62.     return ret;  
    63. }  
    64.   
    65. /* get adec attr */  
    66. ret = MI_AO_GetAdecAttr(AoDevId, AoChn, &stAoGetAdecConfig);  
    67. if (MI_SUCCESS != s32Ret)  
    68. {  
    69.     printf("get adec attr ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    70.     return ret;  
    71. }  
    72.   
    73. /* enable adec */  
    74. ret = MI_AO_EnableAdec(AoDevId, AoChn);  
    75. if (MI_SUCCESS != s32Ret)  
    76. {  
    77.     printf("enable adec ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    78.     return ret;  
    79. }  
    80.   
    81. /* send frame */  
    82. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    83. stAoSendFrame.u32Len = 1024;  
    84. stAoSendFrame.apVirAddr[0] = u8Buf;  
    85. stAoSendFrame.apVirAddr[1] = NULL;  
    86.   
    87. do{  
    88.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    89. }while(ret == MI_AO_ERR_NOBUF);  
    90.   
    91. /* disable adec */  
    92. ret = MI_AO_DisableAdec(AoDevId, AoChn);  
    93. if (MI_SUCCESS != s32Ret)  
    94. {  
    95.     printf("disable adec ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    96.     return ret;  
    97. }  
    98.   
    99. /* disable ao chn */  
    100.    ret = MI_AO_DisableChn(AoDevId, AoChn);  
    101.    if (MI_SUCCESS != ret)  
    102.    {  
    103.        printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    104.        return ret;  
    105.    }  
    106.      
    107.    /* disable ao device */  
    108.    ret = MI_AO_Disable(AoDevId);  
    109.    if(MI_SUCCESS != ret)  
    110.    {  
    111.        printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    112.        return ret;  
    113.    }  
    114.      
    115.    MI_SYS_Exit();
    

2.24. MI_AO_GetAdecAttr

  • Features

    Get the AO decoding function related properties.

  • Syntax

    MI_S32 MI_AO_GetAdecAttr (MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_AdecConfig_t  *pstAdecConfig);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
    pstAdecConfig Audio decoding configuration structure pointer Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libg711.a libg726.a

  • Note

    • This interface is no longer supported in API version 2.17 and later.
  • Example

    Refer to the MI_AO_SetAdecAttr example section.

2.25. MI_AO_EnableAdec

  • Features

    Enable AO decoding.

  • Syntax

    MI_AO_EnableAdec (MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libg711.a libg726.a

  • Note

    Before enabling the decoding function of AO, the decoding parameters corresponding to AO channel must be set first.

  • Example

    Refer to the MI_AO_SetAdecAttr example section.

2.26. MI_AO_DisableAdec

  • Features

    Disable AO decoding.

  • Syntax

    MI_AO_DisableAdec (MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    parameter name description Input/Output
    AoDevId Audio device number Input
    AoChn Audio output channel number. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so libg711.a libg726.a

  • Note

    • This interface is no longer supported in API version 2.17 and later.
  • Example

    Refer to the MI_AO_SetAdecAttr example section.

2.27. MI_AO_SetChnParam

  • Features

    Set AO channel parameters

  • Syntax

    MI_S32 MI_AO_SetChnParam(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_ChnParam_t  *pstChnParam);
    
  • Parameters

    Parameter Name Description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number. Value range: [0, MI_AUDIO_MAX_CHN_NUM). Input
    pstChnParam Audio parameter structure pointer. Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Dependency

    • Header: mi_ai.h

    • Library: libmi_ao.a/libmi_ao.so

  • Note

    None.

  • Example

    The following code shows how to set and get channel parameters.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.  MI_AO_ChnParam_t stChnParam;  
    9.    
    10.   
    11. stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    12. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    13. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    14. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    15. stAttr.u32PtNumPerFrm = 1024;  
    16. stAttr.u32ChnCnt = 1;  
    17.   
    18. MI_SYS_Init();  
    19.   
    20. /* set ao public attr*/  
    21. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    22. if(MI_SUCCESS != ret)  
    23. {  
    24.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    25.     return ret;  
    26. }  
    27.   
    28. /* get ao public attr */  
    29. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    30. if(MI_SUCCESS != ret)  
    31. {  
    32.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    33.     return ret;  
    34. }  
    35.   
    36. /* enable ao device*/  
    37. ret = MI_AO_Enable(AoDevId);  
    38. if(MI_SUCCESS != ret)  
    39. {  
    40.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    41.     return ret;  
    42. }  
    43.   
    44. /* enable ao chn */  
    45. ret = MI_AO_EnableChn(AoDevId, AoChn);  
    46. if (MI_SUCCESS != ret)  
    47. {  
    48.     printf("enable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    49.     return ret;  
    50. }  
    51.   
    52. memset(&stChnParam, 0x0, sizeof(stChnParam));  
    53. stChnParam.stChnGain.bEnableGainSet = TRUE;  
    54. stChnParam.stChnGain.s16Gain = 0;  
    55.   
    56. /* set chn param */  
    57. ret = MI_AO_SetChnParam(AoDevId, AoChn, &stChnParam);  
    58. if (MI_SUCCESS != ret)  
    59. {  
    60.     printf("set chn param ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    61.     return ret;  
    62. }  
    63.   
    64. memset(&stChnParam, 0x0, sizeof(stChnParam));  
    65.   
    66. ret = MI_AO_GetChnParam(AoDevId, AoChn, &stChnParam);  
    67. if (MI_SUCCESS != ret)  
    68. {  
    69.     printf("get chn param ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    70.     return ret;  
    71. }  
    72.   
    73. /* send frame */  
    74. memset(&stAoSendFrame, 0x0, sizeof(MI_AUDIO_Frame_t));  
    75. stAoSendFrame.u32Len = 1024;  
    76. stAoSendFrame.apVirAddr[0] = u8Buf;  
    77. stAoSendFrame.apVirAddr[1] = NULL;  
    78.   
    79. do{  
    80.     ret = MI_AO_SendFrame(AoDevId, AoChn, &stAoSendFrame, -1);  
    81. }while(ret == MI_AO_ERR_NOBUF);  
    82.   
    83. /* disable ao chn */  
    84. ret = MI_AO_DisableChn(AoDevId, AoChn);  
    85. if (MI_SUCCESS != ret)  
    86. {  
    87.     printf("disable ao dev %d chn %d err:0x%x\n", AoDevId, AoChn, ret);  
    88.     return ret;  
    89. }  
    90.   
    91. /* disable ao device */  
    92. ret = MI_AO_Disable(AoDevId);  
    93. if(MI_SUCCESS != ret)  
    94. {  
    95.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    96.     return ret;  
    97. }  
    98.   
    99. MI_SYS_Exit();
    

2.28. MI_AO_GetChnParam

  • Features

    Get AO channel parameters

  • Syntax

    MI_S32 MI_AO_GetChnParam(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn, MI_AO_ChnParam_t  *pstChnParam);
    
  • Parameters

    Parameter Name Description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number. Value range: [0, MI_AUDIO_MAX_CHN_NUM). Input
    pstChnParam Audio parameter structure pointer. Output
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Dependency

    • Header: mi_ai.h

    • Library: libmi_ao.a/libmi_ao.so

  • Example

    Refer to the MI_AO_SetChnParam example section.

2.29. MI_AO_SetSrcGain

  • Features

    Set AO device as Acoustic Echo Cancellation's gain.

  • Syntax

    MI_S32 MI_AO_SetSrcGain(MI_AUDIO_DEV AoDevId, MI_S32 s32VolumeDb);
    
  • Parameters

    Parameter Name Description Input/Output
    AoDevId Audio device number Input
    s32VolumeDb Audio device volume size in dB (-60 - 30) Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    This interface is called after the AO device is successfully enabled.

  • Example

    The following code shows how to set SRC gain.

    1.  MI_S32 ret;  
    2.  MI_AUDIO_Attr_t stAttr;  
    3.  MI_AUDIO_Attr_t stGetAttr;  
    4.  MI_AUDIO_DEV AoDevId = 0;  
    5.  MI_AO_CHN AoChn = 0;  
    6.  MI_U8 u8Buf[1024];  
    7.  MI_AUDIO_Frame_t stAoSendFrame;  
    8.    
    9.  stAttr.eBitwidth = E_MI_AUDIO_BIT_WIDTH_16;  
    10. stAttr.eSamplerate = E_MI_AUDIO_SAMPLE_RATE_8000;  
    11. stAttr.eSoundmode = E_MI_AUDIO_SOUND_MODE_MONO;  
    12. stAttr.eWorkmode = E_MI_AUDIO_MODE_I2S_MASTER;  
    13. stAttr.u32PtNumPerFrm = 1024;  
    14. stAttr.u32ChnCnt = 1;  
    15.   
    16. MI_SYS_Init();  
    17.   
    18. /* set ao public attr*/  
    19. ret = MI_AO_SetPubAttr(AoDevId, &stAttr);  
    20. if(MI_SUCCESS != ret)  
    21. {  
    22.     printf("set ao %d attr err:0x%x\n", AoDevId, ret);  
    23.     return ret;  
    24. }  
    25.   
    26. /* get ao public attr */  
    27. ret = MI_AO_GetPubAttr(AoDevId, &stGetAttr);  
    28. if(MI_SUCCESS != ret)  
    29. {  
    30.     printf("get ao %d attr err:0x%x\n", AoDevId, ret);  
    31.     return ret;  
    32. }  
    33.   
    34. /* enable ao device*/  
    35. ret = MI_AO_Enable(AoDevId);  
    36. if(MI_SUCCESS != ret)  
    37. {  
    38.     printf("enable ao dev %d err:0x%x\n", AoDevId, ret);  
    39.     return ret;  
    40. }  
    41.   
    42. ret = MI_AO_SetSrcGain(AoDevId, 0);  
    43. if(MI_SUCCESS != ret)  
    44. {  
    45.     printf("set src gain ao dev %d err:0x%x\n", AoDevId, ret);  
    46.     return ret;  
    47. }  
    48.   
    49. /* disable ao device */  
    50. ret = MI_AO_Disable(AoDevId);  
    51. if(MI_SUCCESS != ret)  
    52. {  
    53.     printf("disable ao dev %d err:0x%x\n", AoDevId, ret);  
    54.     return ret;  
    55. }  
    56.   
    57. MI_SYS_Exit();
    

2.30. MI_AO_InitDev

  • Features

    Initialize audio output device.

  • Syntax

    MI_S32 MI_AO_InitDev(MI_AO_InitParam_t  *pstInitParam);
    
  • Parameters

    Parameter Name Description Input/Output
    pstInitParam Initialization parameter of audio output device Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • This interface must be used in pair with MI_AO_DeinitDev and cannot be called separately; otherwise, it will return a failure.

    • Only used to reinitialize the AO module after STR take effect.

2.31. MI_AO_DeInitDev

  • Features

    De-initialize audio output device.

  • Syntax

    MI_S32 MI_AO_DeInitDev(void);
    
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • This function must be called after the device is initialized or it will return a failure.

    • If the interface is not called before the app exits, the device will be automatically uninitialized internally.

    • This interface must be used in pair with MI_AO_InitDev and cannot be called separately; otherwise, it will return a failure.

    • This interface parameter setting only takes effect on SSC33X.

2.32. MI_AO_DupChn

  • Features

    Synchronize status of AO channel.

  • Syntax

    MI_S32 MI_AO_DupChn(MI_AUDIO_DEV AoDevId, MI_AO_CHN AoChn);
    
  • Parameters

    Parameter Name Description Input/Output
    AoDevId Audio device number Input
    AoChn Audio input channel number.
    Value range: [0, MI_AUDIO_MAX_CHN_NUM).
    Input
  • Return Value

    • Zero: Successful

    • Non-zero: Failed, see error code for details

  • Requirement

    • Header files: mi_ao.h

    • Library file: libmi_ao.a/libmi_ao.so

  • Note

    • This interface applies only to dual OS environments.The AO channel is initialized in the rtos environment and used to synchronize the status of the AO channel when switching to the Linux environment.

3. AO DATA TYPE

The AO module related data types are defined as follows:

Data type Definition
MI_AUDIO_DEV Define the audio input/output device number
MI_AUDIO_MAX_CHN_NUM Define the maximum number of channels for audio input/output devices
MI_AO_CHN Define the audio output channel
MI_AUDIO_SampleRate_e Define the audio sample rate
MI_AUDIO_Bitwidth_e Define audio sampling accuracy
MI_AUDIO_Mode_e Define the audio input and output working mode
MI_AUDIO_SoundMode_e Define audio channel mode
MI_AUDIO_HpfFreq_e Define the audio high pass filter cutoff frequency
MI_AUDIO_AdecType_e Define the audio decoding type
MI_AUDIO_G726Mode_e DefinitionG726 operating mode
MI_AUDIO_I2sFmt_e I2S format setting
MI_AUDIO_I2sMclk_e I2S MCLK setting
MI_AUDIO_I2sConfig_t Define the I2S attribute structure
MI_AUDIO_Attr_t Defining audio input and output device attribute structures
MI_AO_ChnState_t Data buffer status structure of the audio output channel
MI_AUDIO_Frame_t Defining an audio frame data structure
MI_AUDIO_AecFrame_t Defining echo cancellation reference frame information structure
MI_AUDIO_SaveFileInfo_t Define audio save file function configuration information structure
MI_AO_VqeConfig_t Defining audio output sound quality enhancement configuration information structure
MI_AUDIO_HpfConfig_t Defining an audio high-pass filtering function configuration information structure
MI_AUDIO_AnrConfig_t Define audio voice noise reduction function configuration information structure
MI_AUDIO_NrSpeed_e Define noise convergence speed
MI_AUDIO_AgcConfig_t Defining an audio automatic gain control configuration information structure
AgcGainInfo_t AGC gain value
MI_AUDIO_EqConfig_t Define the audio equalizer function configuration information structure
MI_AO_AdecConfig_t Define the decoding function configuration information structure.
MI_AUDIO_AdecG711Config_t Define the G711 decoding function configuration information structure
MI_AUDIO_AdecG726Config_s Define the G711 decoding function configuration information structure
MI_AUDIO_AlgorithmMode_e Define the operating mode of the audio algorithm
MI_AO_ChnParam_t Define channel parameter structure
MI_AO_ChnGainConfig_t Define channel gain structure

3.1. MI_AUDIO_DEV

  • Description

    Define the audio Input/Output device number.

  • Definition

    Typedef MI_S32 MI_AUDIO_DEV
    
  • Precautions

    The following table is a comparison table of AO Dev ID and physical device of chips.

    0 1 2 3 4 5
    Pretzel Line outDAC0/1 I2s Tx
    Macaron Line outDAC0/1 I2s Tx
    Taiyaki Line outDAC0/1 I2s Tx Hdmi Hdmi + Line out
    Takoyaki Line outDAC0/1 I2s Tx Hdmi Hdmi + Line out
    Pudding Line outDAC0/1 I2s Tx
    Ispahan Line outDAC0/1 I2s Tx
    Tiramisu Line outDAC0/1 I2s Tx DAC0 DAC1 Hdmi+ Line out
    Ikayaki Line outDAC0/1 I2s Tx DAC0 DAC1 HeadPhone

    The following table is the specifications of different series of chips

    Line out I2S Tx Hdmi HeadPhone
    Pretzel Support 2 channel 8/16/32/48KHz sampling rate It supports standard I2S mode and TDM mode. TDM mode can be extended to 8 channels. It supports 4-wire and 6-wire modes and can provide MCLK. It supports 8/16/32/48KHz sampling rate. Not supported Not supported
    Macaron Support 2 channel 8/16/32/48KHz sampling rate Only standard I2S mode is supported and can only be used as master, only 4-wire mode is supported, MCLK is not available. Support 8/16/32/48KHz sampling rate. Not supported Not supported
    Taiyaki Support 2 channel 8/16/32/48KHz sampling rate Only standard I2S mode is supported and can only be used as master, only 4-wire mode is supported, MCLK is not available. Support 8/16/32/48KHz sampling rate. supported Not supported
    Takoyaki Support 2 channel 8/16/32/48KHz sampling rate Only standard I2S mode is supported and can only be used as master, only 4-wire mode is supported, MCLK is not available. Support 8/16/32/48KHz sampling rate. supported Not supported
    Pudding Support 2 channel 8/16/32/48KHz sampling rate It supports standard I2S mode and TDM mode. TDM mode can be extended to 8 channels. It supports 4-wire and 6-wire modes and can provide MCLK. It supports 8/16/32/48KHz sampling rate. Not supported Not supported
    Ispahan Support 2 channel 8/16/32/48KHz sampling rate Only standard I2S mode is supported and can only be used as master, only 4-wire mode is supported, MCLK is not available. Support 8/16/32/48KHz sampling rate. Not supported Not supported
    Tiramisu Support 2 channel 8/16/32/48KHz sampling rate It supports standard I2S mode and TDM mode. TDM mode can be extended to 8 channels. It supports 4-wire and 6-wire modes and can provide MCLK. It supports 8/16/32/48KHz sampling rate. supported Not supported
    Ikayaki Support 2 channel 8/16/32/48KHz sampling rate It supports standard I2S mode and TDM mode. TDM mode can be extended to 8 channels. It supports 4-wire and 6-wire modes and can provide MCLK. It supports 8/16/32/48KHz sampling rate. Not supported supported

3.2. MI_AUDIO_MAX_CHN_NUM

  • Description

    Defines the maximum number of channels for an audio Input/Output device.

  • Definition

    #define MI_AUDIO_MAX_CHN_NUM 16
    

3.3. MI_AO_CHN

  • Description

    Define the audio output channel.

  • Definition

    typedef MI_S32 MI_AO_CHN
    

3.4. MI_AUDIO_SampleRate_e

  • Description

    Define the audio sample rate.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_SAMPLE_RATE_8000 = 8000, /* 8kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_11052 = 11025, /* 11.025kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_12000 = 12000, /* 12kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_16000 = 16000, /* 16kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_22050 = 22050, /* 22.05kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_24000 = 24000, /* 24kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_32000 = 32000, /* 32kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_44100 = 44100, /* 44.1kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_48000 = 48000, /* 48kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_96000 = 96000, /* 96kHz sampling rate */
    
        E_MI_AUDIO_SAMPLE_RATE_INVALID,
    
    }MI_AUDIO_SampleRate_e;
    
  • Member

    Member name description
    E_MI_AUDIO_SAMPLE_RATE_8000 8kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_11025 11.025kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_12000 12kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_16000 16kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_22050 22.05kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_24000 24kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_32000 32kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_44100 44.1kHz sample rate
    E_MI_AUDIO_SAMPLE_RATE_48000 48kHz sampling rate
    E_MI_AUDIO_SAMPLE_RATE_96000 96kHz sampling rate
  • Precautions

    The enumeration value here does not start at 0, but is the same as the actual sample rate value.

  • Related data types and interfaces

    MI_AUDIO_Attr_t.

3.5. MI_AUDIO_Bitwidth_e

  • Description

    Define audio sampling accuracy.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_BIT_WIDTH_16 =0, /* 16bit width */
    
        E_MI_AUDIO_BIT_WIDTH_24 =1, /* 24bit width */
    
        E_MI_AUDIO_BIT_WIDTH_32 =2, /* 32bit width */
    
        E_MI_AUDIO_BIT_WIDTH_MAX,
    
    }MI_AUDIO_BitWidth_e;
    
  • Member

    Member name description
    E_MI_AUDIO_BIT_WIDTH_16 Sampling accuracy is 16bit width
    E_MI_AUDIO_BIT_WIDTH_24 Sampling accuracy is 24bit width
    E_MI_AUDIO_BIT_WIDTH_32 Sampling accuracy is 32bit width
  • Precautions

    Currently the software only supports 16bit bit width.

3.6. MI_AUDIO_Mode_e

  • Description

    Define the audio input and output device operating mode.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_MODE_I2S_MASTER, /* I2S master mode */
    
        E_MI_AUDIO_MODE_I2S_SLAVE, /* I2S slave mode */
    
        E_MI_AUDIO_MODE_TDM_MASTER, /* TDM master mode */
    
        E_MI_AUDIO_MODE_TDM_SLAVE, /* TDM slave mode */
    
        E_MI_AUDIO_MODE_MAX,
    
    }MI_AUDIO_Mode_e;
    
  • Member

    Member name description
    E_MI_AUDIO_MODE_I2S_MASTER I2S master mode
    E_MI_AUDIO_MODE_I2S_SLAVE I2S slave mode
    E_MI_AUDIO_MODE_TDM_MASTER TDM master mode
    E_MI_AUDIO_MODE_TDM_SLAVE TDM slave mode
  • Precautions

    Whether the master mode or the slave mode is supported depends on the chip involved.

  • Related data types and interfaces

    MI_AUDIO_Attr_t.

3.7. MI_AUDIO_SoundMode_e

  • Description

    Define audio channel mode.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_SOUND_MODE_MONO =0, /* mono */
    
        E_MI_AUDIO_SOUND_MODE_STEREO =1, /* stereo */
    
        E_MI_AUDIO_SOUND_MODE_QUEUE =2,
    
        E_MI_AUDIO_SOUND_MODE_MAX,
    
    }MI_AUDIO_SoundMode_e
    
  • Member

    Member name description
    E_MI_AUDIO_SOUND_MODE_MONO Mono
    E_MI_AUDIO_SOUND_MODE_STEREO Two channels
    E_MI_AUDIO_SOUND_MODE_QUEUE For audio input only
  • Precautions

    • For the two-channel mode, only the left channel (that is, the channel whose number is less than half the channel number u32ChnCnt in the device attribute) should be performed.

    • For operation, the SDK will automatically perform corresponding operations on the right channel.

  • Related data types and interfaces

    MI_AUDIO_Attr_t.

3.8. MI_AUDIO_HpfFreq_e

  • Description

    Define the audio high pass filter cutoff frequency.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_HPF_FREQ_80 = 80, /* 80Hz */
    
        E_MI_AUDIO_HPF_FREQ_120 = 120, /* 120Hz */
    
        E_MI_AUDIO_HPF_FREQ_150 = 150, /* 150Hz */
    
        E_MI_AUDIO_HPF_FREQ_BUTT,
    
    } MI_AUDIO_HpfFreq_e;
    
  • Member

    Member name description
    E_MI_AUDIO_HPF_FREQ_80 The cutoff frequency is 80 Hz.
    E_MI_AUDIO_HPF_FREQ_120 The cutoff frequency is 120 Hz.
    E_MI_AUDIO_HPF_FREQ_150 The cutoff frequency is 150 Hz.
  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.9. MI_AUDIO_AdecType_e

  • Description

    Define the audio decoding type.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_ADEC_TYPE_G711A = 0,
    
        E_MI_AUDIO_ADEC_TYPE_G711U,
    
        E_MI_AUDIO_ADEC_TYPE_G726,
    
        E_MI_AUDIO_ADEC_TYPE_INVALID,
    
    }MI_AUDIO_AdecType_e;
    
  • Member

    Member name description
    E_MI_AUDIO_ADEC_TYPE_G711A G711A decoding.
    E_MI_AUDIO_ADEC_TYPE_G711U G711U decoding.
    E_MI_AUDIO_ADEC_TYPE_G726 G726 decoding.
  • Related data types and interfaces

    MI_AO_AdecConfig

3.10. MI_AUDIO_G726Mode_e

  • Description

    DefinitionG726 operating mode.

  • Definition

    typedef enum{
    
        E_MI_AUDIO_G726_MODE_16 = 0,
    
        E_MI_AUDIO_G726_MODE_24,
    
        E_MI_AUDIO_G726_MODE_32,
    
        E_MI_AUDIO_G726_MODE_40,
    
        E_MI_AUDIO_G726_MODE_INVALID,
    
    }MI_AUDIO_G726Mode_e;
    
  • Member

    Member name description
    E_MI_AUDIO_G726_MODE_16 G726 16K bit rate mode.
    E_MI_AUDIO_G726_MODE_24 G726 24K bit rate mode.
    E_MI_AUDIO_G726_MODE_32 G726 32K bit rate mode.
    E_MI_AUDIO_G726_MODE_40 G726 40K bit rate mode.
  • Related data types and interfaces

    MI_AO_AdecConfig_t

3.11. MI_AUDIO_I2sFmt_e

  • Description

    I2S format setting.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_I2S_FMT_I2S_MSB,
    
        E_MI_AUDIO_I2S_FMT_LEFT_JUSTIFY_MSB,
    
    }MI_AUDIO_I2sFmt_e;
    
  • Member

    Member name description
    E_MI_AUDIO_I2S_FMT_I2S_MSB I2S standard format, highest priority
    E_MI_AUDIO_I2S_FMT_LEFT_JUSTIFY_MSB I2S left-aligned format, highest priority
  • Related data types and interfaces

    MI_AUDIO_I2sConfig_t

3.12. MI_AUDIO_I2sMclk_e

  • Description

    I2S MCLK setting

  • Definition

    typedef enum{
    
        E_MI_AUDIO_I2S_MCLK_0,
    
        E_MI_AUDIO_I2S_MCLK_12_288M,
    
        E_MI_AUDIO_I2S_MCLK_16_384M,
    
        E_MI_AUDIO_I2S_MCLK_18_432M,
    
        E_MI_AUDIO_I2S_MCLK_24_576M,
    
        E_MI_AUDIO_I2S_MCLK_24M,
    
        E_MI_AUDIO_I2S_MCLK_48M,
    
    }MI_AUDIO_I2sMclk_e;
    
  • Member

    Member name description
    E_MI_AUDIO_I2S_MCLK_0 Turn off MCLK
    E_MI_AUDIO_I2S_MCLK_12_288M Set MCLK to 12.88M
    E_MI_AUDIO_I2S_MCLK_16_384M Set MCLK to 16.384M
    E_MI_AUDIO_I2S_MCLK_18_432M Set MCLK to 18.432M
    E_MI_AUDIO_I2S_MCLK_24_576M Set MCLK to 24.576M
    E_MI_AUDIO_I2S_MCLK_24M Set MCLK to 24M
    E_MI_AUDIO_I2S_MCLK_48M Set MCLK to 48M
  • Related data types and interfaces

    MI_AUDIO_I2sConfig_t

3.13. MI_AUDIO_I2sConfig_t

  • Description

    Define the I2S attribute structure.

  • Definition

    typedef struct MI_AUDIO_I2sConfig_s
    
    {
    
        MI_AUDIO_I2sFmt_e eFmt;
    
        MI_AUDIO_I2sMclk_e eMclk;
    
        MI_BOOL bSyncClock;
    
    }MI_AUDIO_I2sConfig_t;
    
  • Member

    Member name description
    eFmt I2S format settings. Static attribute.
    eMclk I2S MCLK clock setting Static attribute.
    bSyncClock AO synchronous AI clock Static attribute.
  • Related data types and interfaces

    MI_AUDIO_Attr_t

3.14. MI_AUDIO_Attr_t

  • Description

    Define the audio input and output device attribute structure.

  • Definition

    typedef struct MI_AUDIO_Attr_s
    
    {
    
        MI_AUDIO_SampleRate_e eSamplerate; /*sample rate*/
    
        MI_AUDIO_BitWidth_e eBitwidth; /*bitwidth*/
    
        MI_AUDIO_Mode_e eWorkmode; /*master or slave mode*/
    
        MI_AUDIO_SoundMode_e eSoundmode; /*momo or stereo*/
    
        MI_U32 u32FrmNum; /*frame num in buffer*/
    
        MI_U32 u32PtNumPerFrm; /*number of samples*/
    
        MI_U32 u32CodecChnCnt; /*channel number on Codec */
    
        MI_U32 u32ChnCnt;
    
            union{
    
                MI_AUDIO_I2sConfig_t stI2sConfig;
    
            }WorkModeSetting;
    
    }MI_AUDIO_Attr_t;
    
  • Member

    Member name description
    eSamplerate Audio sample rate. Static attribute.
    eBitwidth Audio sampling accuracy (in slave mode, this parameter must match the sampling accuracy of the audio AD#### ParameterA). Static attribute.
    eWorkmode Audio input and output working mode. Static attribute.
    eSoundmode Audio channel mode. Static attribute.
    u32FrmNum The number of cached frames. Reserved, not used.
    u32PtNumPerFrm The number of sampling points per frame. The value ranges from:128, 128*2,…,128*N. Static attribute.
    u32CodecChnCnt The number of channels supported codec Reserved, not used
    u32ChnCnt The number of channels supported, the maximum number of channels that are actually enabled. Values: 1,2,4, 8,16. (The input supports up to MI_AUDIO_MAX_CHN_NUM channels, and the output supports up to 2channels)
    MI_AUDIO_I2sConfig_t stI2sConfig; Set I2S work properties
    MI_AUDIO_I2sConfig_t stI2sConfig; Set I2S work properties
  • Related data types and interfaces

    MI_AO_SetPubAttr

3.15. MI_AO_ChnState_t

  • Description

    The data buffer status structure of the audio output channel.

  • Definition

    typedef struct MI_AO_ChnState_s
    
    {
    
        MI_U32 u32ChnTotalNum;
    
        MI_U32 u32ChnFreeNum;
    
        MI_U32 u32ChnBusyNum;
    
    } MI_AO_ChnState_t;
    
  • Member

    Member name description
    u32ChnTotalNum The total number of cache bytes for the output channel.
    u32ChnFreeNum The number of free cache bytes available.
    u32ChnBusyNum The number of cache bytes that are occupied.

3.16. MI_AUDIO_Frame_t

  • Description

    Define the audio frame structure.

  • Definition

    MI_AO API Version <= 2.9:
    typedef struct MI_AUDIO_Frame_s
    {
        MI_AUDIO_BitWidth_e eBitwidth;
        MI_AUDIO_SoundMode_e eSoundmode;
        void *apVirAddr[MI_AUDIO_MAX_CHN_NUM];
        MI_U64 u64TimeStamp;
        MI_U32 u32Seq; 
        MI_U32 u32Len; 
        MI_U32 au32PoolId[2];
    }MI_AUDIO_Frame_t;
    
    MI_AO API Version  2.9 ~ 2.14:
    typedef struct MI_AUDIO_Frame_s
    {
        MI_AUDIO_BitWidth_e eBitwidth;
        MI_AUDIO_SoundMode_e eSoundmode;
        void *apVirAddr[MI_AUDIO_MAX_CHN_NUM];
        MI_U64 u64TimeStamp;
        MI_U32 u32Seq;
        MI_U32 u32Len;
        MI_U32 au32PoolId[2];
        void *apSrcPcmVirAddr[MI_AUDIO_MAX_CHN_NUM];
        MI_U32 u32SrcPcmLen; 
    }MI_AUDIO_Frame_t;
    
    MI_AO API Version >= 2.15:
    typedef struct MI_AUDIO_Frame_s
    {
        MI_AUDIO_BitWidth_e eBitwidth;
        MI_AUDIO_SoundMode_e eSoundmode;
        void *apVirAddr[MI_AUDIO_MAX_CHN_NUM];
        MI_U64 u64TimeStamp;
        MI_U32 u32Seq;
        MI_U32 u32Len[MI_AUDIO_MAX_CHN_NUM];
        MI_U32 au32PoolId[2];
        void *apSrcPcmVirAddr[MI_AUDIO_MAX_CHN_NUM];
        MI_U32 u32SrcPcmLen[MI_AUDIO_MAX_CHN_NUM]; 
    }MI_AUDIO_Frame_t;
    
  • Member

    Member name description
    eBitwidth Audio sampling accuracy
    eSoundmode Audio channel mode.
    apVirAddr Audio frame data virtual address.
    u64TimeStamp Audio frame timestamp, in μs
    u32Seq Audio frame number.
    u32Len Audio frame length, in bytes.
    u32PoolId Audio frame buffer pool ID.
    apSrcPcmVirAddr Audio frame original data virtual address. Only for MI_AI module.
    u32SrcPcmLen Audio frame original data length, in bytes. Only for MI_AI module.
  • Precautions

    • u32Len (audio frame length) refers to the data length of a frame when the API version is less than or equal to 2.14.The data length of each channel is recording in u32Len[channel index] when the API version is greater than or equal to 2.15.

    • Mono data is directly stored, Stereo data is interleaved by left and right channels, the sampling points number of each channel is u32PtNumPerFrm, the length is u32Len.

3.17. MI_AUDIO_AecFrame_t

  • Description

    Define an audio echo cancellation reference frame information structure.

  • Definition

    typedef struct MI_AUDIO_AecFrame_s
    
    {
    
        MI_AUDIO_Frame_t stRefFrame; /* aec reference audio frame */
    
        MI_BOOL bValid; /* whether frame is valid */
    
    }MI_AUDIO_AecFrame_t;
    
  • Member

    Member name description
    stRefFrame The echo cancels the reference frame structure.
    bValid The reference frame is valid. Ranges: TRUE:The reference frame is valid. FALSE:The reference frame is invalid. If this is invalid, this reference frame cannot be used for echo cancellation.

3.18. MI_AUDIO_SaveFileInfo_t

  • Description

    Define the audio save file function configuration information structure.

  • Definition

    typedef struct MI_AUDIO_SaveFileInfo_s
    
    {
    
        MI_BOOL bCfg;
    
        MI_U8 szFilePath[256];
    
        MI_U32 u32FileSize; /*in KB*/
    
    } MI_AUDIO_SaveFileInfo_t
    
  • Member

    Member name description
    bCfg Configure the enable switch.
    szFilePath Audio file save path
    u32FileSize File size, ranging from [1, 10240] KB.
  • Related data types and interfaces

    MI_AI_SaveFile

3.19. MI_AO_VqeConfig_t

  • Description

    Define the audio output sound quality enhancement configuration information structure.

  • Definition

    typedef struct MI_AO_VqeConfig_s
    
    {
    
        MI_BOOL bHpfOpen;
    
        MI_BOOL bAnrOpen;
    
        MI_BOOL bAgcOpen;
    
        MI_BOOL bEqOpen;
    
        MI_S32 s32WorkSampleRate;
    
        MI_S32 s32FrameSample;
    
        MI_AUDIO_HpfConfig_t stHpfCfg;
    
        MI_AUDIO_AnrConfig_t stAnrCfg;
    
        MI_AUDIO_AgcConfig_t stAgcCfg;
    
        MI_AUDIO_EqConfig_t stEqCfg;
    
    } MI_AO_VqeConfig_t;
    
  • Member

    Member name description
    bHpfOpen Whether the high-pass filtering function is enabled or not.
    bAnrOpen Whether the voice noise reduction function is enabled.
    bAgcOpen Whether the automatic gain control function enables the flag
    bEqOpen Whether the equalizer function is enabled
    s32WorkSampleRate Working sampling frequency. This parameter is the working sampling rate of the internal function algorithm. Value range: 8KHz / 16KHz. The default is 8KHz.
    s32FrameSample The frame length of VQE, that is, the number of sampling points. Only support 128.
    stHpfCfg High-pass filtering function related configuration information.
    stAnrCfg Configuration information related to the voice noise reduction function.
    stAgcCfg Automatic gain control related configuration information.
    stEqCfg Equalizer related configuration information.

3.20. MI_AUDIO_HpfConfig_t

  • Description

    Define an audio high-pass filtering function configuration information structure.

  • Definition

    typedef struct MI_AUDIO_HpfConfig_s
    
    {
    
        MI_AUDIO_AlgorithmMode_e eMode;
    
        MI_AUDIO_HpfFreq_e eHpfFreq; /*freq to be processed*/
    
    } MI_AUDIO_HpfConfig_t;
    
  • Member

    Member name description
    eMode Audio algorithm operating mode.
    eHpfFreq High pass filter cutoff frequency selection. 80 : The cutoff frequency is 80 Hz ; 120 : The cutoff frequency is 120 Hz; 150 : The cutoff frequency is 150 Hz. The default value is 150.
  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.21. MI_AUDIO_AnrConfig_t

  • Description

    Define the audio voice noise reduction function configuration information structure.

  • Definition

    Because of the update of APC algorithm library, in order to be compatible with the old and new versions of algorithm library, the following description is given for different versions. (You can use the command ‘strings libAPC_LINUX.so | grep APCSET’ to get the version of APC algorithm library, where the APC API version will be recorded in the APIVERSION field.)

    • APC API VERSION 1 (or without APIVERSION field)

      typedef struct MI_AUDIO_AnrConfig_s
      {
          MI_AUDIO_AlgorithmMode_e eMode;
          MI_U32   u32NrIntensity;
          MI_U32   u32NrSmoothLevel;
          MI_AUDIO_NrSpeed_e eNrSpeed;
      } MI_AUDIO_AnrConfig_t;
      
    • APC API VERSION 2

      typedef struct MI_AUDIO_AnrConfig_s
      {
          MI_AUDIO_AlgorithmMode_e eMode;
          MI_U32   u32NrIntensityBand[6];
          MI_U32   u32NrIntensity[7];
          MI_U32   u32NrSmoothLevel;
          MI_AUDIO_NrSpeed_e eNrSpeed;
      } MI_AUDIO_AnrConfig_t;
      
  • Member

    APC API VERSION 1 (or without APIVERSION field)

    Member Name Description
    eMode Audio algorithm operating mode.
    Note: ANR mode will affect the function of AGC to some extent.
    u32NrIntensity Noise reduction strength configuration. The larger the configuration value, the higher the noise reduction, but also the greater the loss/damage of the detail sound.
    Range [0,30] ; step size 1.
    The default value is 20.
    u32NrSmoothLevel Smoothness. The larger the value, the smoother.
    Range [0,10]; step size 1.
    The default value is 10.
    eNrSpeed Noise convergence speed: low speed, medium speed, high speed.
    The default value is medium speed.

    APC API VERSION 2

    Member name description
    eMode Audio algorithm operating mode.
    Note: ANR mode will affect the function of AGC to some extent.
    u32NrIntensityBand Noise reduction frequency range. The latter data must be greater than or equal to the previous data.
    For example: u32NrIntensityBand[0] = 10, then: u32NrIntensityBand[1] must be greater than or equal to 10.
    The maximum frequency corresponding to the current sampling rate is divided into 128 copies on average, and u32NrIntensityBand represents the number of copies constituting a frequency band.
    For example, suppose the current sampling rate is 16K and the corresponding maximum frequency is 8K. Each copy is 63Hz (8000 / 128 ≈ 62.5Hz). In case {4,6,36, 49,50,51}, the frequency range will be {0~4 * 62.5Hz, 4~6 * 62.5Hz, 6~36 * 62.5Hz, 36~49 * 62.5Hz, 49~50 * 62.5Hz, 50~51 * 62.5Hz, 51-127 * 62.5Hz} = {0~250Hz, 250~375Hz, 375~2250Hz, 2250~3062.5Hz, 3062.5~3125Hz, 3125~3178.5Hz, 3178.5Hz~8000Hz}.
    Range [ 1,128 ]; step size 1.
    u32NrIntensity Noise reduction strength configuration, the larger the configuration value, the higher the noise reduction, but also the loss/ damage of the detail sound.
    Range [0,30] ; step size 1
    The default value is 20.
    u32NrSmoothLevel Degree of smoothing
    Range [0,10]; step size 1
    The default value is 10.
    eNrSpeed Noise convergence speed, low speed, medium speed, high speed
    The default value is medium speed.
  • Precautions

    In the case where both ANR and AGC are enabled, if ANR is set to user mode, AGC will process the audio data in frequency domain, and then evaluate the speech signal and make corresponding boost and cut. When ANR is set to default/music mode, AGC will process the audio data in time domain and boost and cut the data in full frequency band.

  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.22. MI_AUDIO_NrSpeed_e

  • Description

    Define noise convergence speed

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_NR_SPEED_LOW,
    
        E_MI_AUDIO_NR_SPEED_MID,
    
        E_MI_AUDIO_NR_SPEED_HIGH
    
    }MI_AUDIO_NrSpeed_e;
    
  • Member

    Member name description
    E_MI_AUDIO_NR_SPEED_LOW Low speed.
    E_MI_AUDIO_NR_SPEED_MID Medium speed.
    E_MI_AUDIO_NR_SPEED_HIGH High speed.
  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.23. MI_AUDIO_AgcConfig_t

  • Description

    Define an audio automatic gain control configuration information structure.

  • Definition

    Because of the update of APC algorithm library, in order to be compatible with the old and new versions of algorithm library, the following description is given for different versions. (You can use the command ‘strings libAPC_LINUX.so | grep APCSET’ to get the version of APC algorithm library, where the APC API version will be recorded in the APIVERSION field.)

    • APC API VERSION 1 (or without APIVERSION field)

      typedef struct MI_AUDIO_AgcConfig_s 
      { 
          MI_AUDIO_AlgorithmMode_e eMode;
          AgcGainInfo_t stAgcGainInfo;
          MI_U32     u32DropGainMax;
          MI_U32     u32AttackTime;
          MI_U32     u32ReleaseTime;
          MI_S16     s16Compression_ratio_input[5];
          MI_S16     s16Compression_ratio_output[5];
          MI_S32     s32TargetLevelDb;
          MI_S32     s32NoiseGateDb;
          MI_U32     u32NoiseGateAttenuationDb;
      } MI_AUDIO_AgcConfig_t;
      
    • APC API VERSION 2

      typedef struct MI_AUDIO_AgcConfig_s 
      { 
          MI_AUDIO_AlgorithmMode_e eMode;
          AgcGainInfo_t stAgcGainInfo;
          MI_U32     u32DropGainMax;
          MI_U32     u32AttackTime;
          MI_U32     u32ReleaseTime;
          MI_S16     s16Compression_ratio_input[7];
          MI_S16     s16Compression_ratio_output[7];
          MI_S32     s32DropGainThreshold;
          MI_S32     s32NoiseGateDb;
          MI_U32     u32NoiseGateAttenuationDb;
      } MI_AUDIO_AgcConfig_t;
      
  • Member

    APC API VERSION 1 (or without APIVERSION field)

    Member Name Description
    eMode Audio algorithm operating mode.
    stAgcGainInfo Define the maximum, minimum, and initial values of the AGC gain.
    u32DropGainMax Maximum gain decrease, to prevent output saturation.
    Range [0,60]; step size 1.
    The default value is 55.
    Note: This value only represents the range that can be reduced, but the minimum value of AGC gain shall be referred to for the specific value that can be reduced.
    u32AttackTime Gain fall time interval length, 1 unit in 16 milliseconds.
    Range [1,20]; step size 1.
    The default value is 0.
    u32ReleaseTime Gain rise time interval length, 1 unit in 16 milliseconds.
    Range [1, 20]; step size 1.
    The default value is 0.
    s16Compression_ratio_input Input RMS energy.
    This parameter should be used together with the compression ratio output.
    The gain curve consists of multiple turning points with different slopes.
    Value range [-80,0]; step size 1.
    s16Compression_ratio_output Output target RMS energy related input energy.
    The gain curve consists of multiple turning points with different slopes.
    Value range [-80,0]; step size 1.
    s32TargetLevelDb Target level, processed maximum level threshold.
    Range [-80,0] dB; step size 1.
    The default value is 0.
    Note: This value can only determine the maximum level that can be achieved, but whether it can be achieved or not depends on the setting of slope curve.
    s32NoiseGateDb Noise floor. When the signal is less than this value, it is treated as noise.
    Range [-80,0]; step size 1.
    Note: When the value is -80, the noise floor will not work.
    The default value is -55.
    u32NoiseGateAttenuationDb The percentage of attenuation of the input source when the noise floor value is effective.
    Range [0,100]; step size 1.
    The default value is 0.

    APC API VERSION 2

    Member Name Description
    eMode Audio algorithm operating mode.
    stAgcGainInfo Define the maximum, minimum, and initial values of the AGC gain.
    u32DropGainMax Maximum gain decrease, to prevent output saturation.
    Range [0,60]; step size 1.
    The default value is 55.
    Note: This value only represents the range that can be reduced, but the minimum value of AGC gain shall be referred to for the specific value that can be reduced.
    u32AttackTime Gain fall time interval length, 1 unit in 16 milliseconds.
    Range [1,20]; step size 1.
    The default value is 0.
    u32ReleaseTime Gain rise time interval length, 1 unit in 16 milliseconds.
    Range [1, 20]; step size 1.
    The default value is 0.
    s16Compression_ratio_input Input RMS energy.
    This parameter should be used together with the compression ratio output.
    The gain curve consists of multiple turning points with different slopes.
    Value range [-80,0]; step size 1.
    s16Compression_ratio_output Output target RMS energy related input energy.
    The gain curve consists of multiple turning points with different slopes.
    Value range [-80,0]; step size 1.
    s32DropGainThreshold Dropping Gain threshold. When the signal amplitude exceeds this value, gain will slowly drop.
    Range [-80,0] dB; step size 1.
    The default value is 0.
    s32NoiseGateDb Noise floor. When the signal is less than this value, it is treated as noise.
    Range [-80,0]; step size 1.
    Note: When the value is -80, the noise floor will not work.
    The default value is -55.
    u32NoiseGateAttenuationDb The percentage of attenuation of the input source when the noise floor value is effective.
    Range [0,100]; step size 1.
    The default value is 0.
  • Precautions

    • In the case where both ANR and AGC are enabled, if ANR is set to user mode, AGC will process the audio data in frequency domain, and then evaluate the speech signal and make corresponding boost and cut. When ANR is set to default/music mode, AGC will process the audio data in time domain and boost and cut the data in full frequency band.

    • S16Compression_ratio_input and s16Compression_ratio_output should be set according to the desired gain curve.

    • As shown in the line graph below, the input gain of -80~0dB is divided into four (APIVERSION 1 or without APIVERSION field) or six (APIVERSION 2) slopes. The first section is -80db ~ -60db. The original gain is maintained within this range and the slope is 1. The second section is -60db ~ -40db, in which the gain needs to be slightly increased and the slope is 1.5. The third section is -40db ~ -20db and the slope in this range is 1.25. The fourth section is -20db ~0dB and the slope in this range is 0.25. Set s16Compression_ratio_input and s16Compression_ratio_output according to the turning point of the curve. If not so many sections of the curve are needed, then fill in 0 for the unwanted parts of the array.

  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.24. AgcGainInfo_t

  • Description

    AGC gain value.

  • Definition

    typedef struct AgcGainInfo_s{
    
        MI_S32 s32GainMax;
    
        MI_S32 S32GainMin;
    
        MI_S32 s32GainInit;
    
    }AgcGainInfo_t;
    
  • Member

    Member name description
    s32GainMax Maximum gain
    Range [0,60]; step size 1
    The default value is 15.
    s32GainMin Minimum gain
    Range [-20,30]; step size 1
    The default value is 0.
    s32GainInit Initial gain
    Range [-20,60]; step size 1
    The default value is 0.
  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.25. MI_AUDIO_EqConfig_t

  • Description

    Define the audio equalizer function configuration information structure.

  • Definition

    typedef struct MI_AUDIO_EqConfig_s
    
    {
    
        MI_AUDIO_AlgorithmMode_e eMode;
    
        MI_S16 s16EqGainDb[129];
    
    } MI_AUDIO_EqConfig_t;
    
  • Member

    Member name description
    eMode Audio algorithm operating mode.
    s16EqGainDb[129] Equalizer gain adjustment value It divides the frequency range of the current sampling rate into 129 parts for adjustment.
    For example, if the current sampling rate is 16K and the corresponding maximum frequency is 8K, then the frequency range of a single adjustment is 62Hz (8000/129≈62Hz), and 0-8k is divided into {0-1 * 62Hz, 1-2 * 62Hz, 2-3 * 62Hz... , 128-129 * 62Hz} = {0-62Hz, 62-124Hz, 124-186Hz..., 7938-8000Hz}, each segment corresponding to a gain value.
  • Related data types and interfaces

    MI_AO_VqeConfig_t

3.26. MI_AO_AdecConfig_t

  • Description

    Define the decoding function configuration information structure.

  • Definition

    typedef struct MI_AO_AdecConfig_s
    
    {
    
        MI_AUDIO_AdecType_e eAdecType;
    
        union
    
        {
    
            MI_AUDIO_AdecG711Config_t stAdecG711Cfg;
    
            MI_AUDIO_AdecG726Config_s stAdecG726Cfg;
    
        };
    
    }MI_AO_AdecConfig_t;
    
  • Member

    Member name description
    eAdecType Audio decoding type.
    stAdecG711Cfg G711 decodes related configuration information.
    stAdecG726Cfg G726 decodes related configuration information.
  • Related data types and interfaces

    MI_AO_SetAdecAttr

3.27. MI_AUDIO_AdecG711Config_t

  • Description

    Define the G711 decoding function configuration information structure.

  • Definition

    typedef struct MI_AUDIO_AdecG711Config_s{
    
        MI_AUDIO_SampleRate_e eSamplerate;
    
        MI_AUDIO_SoundMode_e eSoundmode;
    
    }MI_AUDIO_AdecG711Config_t;
    
  • Member

    Member name description
    eSamplerate Audio sample rate.
    eSoundmode Audio channel mode.
  • Related data types and interfaces

    MI_AO_SetAdecAttr

3.28. MI_AUDIO_AdecG726Config_s

  • Description

    Define the G711 decoding function configuration information structure.

  • Definition

    typedef struct MI_AUDIO_AdecG726Config_s{
    
        MI_AUDIO_SampleRate_e eSamplerate;
    
        MI_AUDIO_SoundMode_e eSoundmode;
    
        MI_AUDIO_G726Mode_e eG726Mode;
    
    }MI_AUDIO_AdecG726Config_t;
    
  • Member

    Member name description
    eSamplerate Audio sample rate.
    eSoundmode Audio channel mode.
    eG726Mode G726 working mode.
  • Related data types and interfaces

    MI_AO_SetAdecAttr

3.29. MI_AUDIO_AlgorithmMode_e

  • Description

    Define the operating mode of the audio algorithm.

  • Definition

    typedef enum
    
    {
    
        E_MI_AUDIO_ALGORITHM_MODE_DEFAULT,
    
        E_MI_AUDIO_ALGORITHM_MODE_USER,
    
        E_MI_AUDIO_ALGORITHM_MODE_MUSIC,
    
        E_MI_AUDIO_ALGORITHM_MODE_INVALID,
    
    }MI_AUDIO_AlgorithmMode_e;
    
  • Member

    Member Name Description
    E_MI_AUDIO_ALGORITHM_MODE_DEFAULT Default mode. Note: When using this mode, the default parameters of the algorithm will be used
    E_MI_AUDIO_ALGORITHM_MODE_USER User mode. Note: When using this mode, the user needs to reset all parameters.
    E_MI_AUDIO_ALGORITHM_MODE_MUSIC Music mode. Note: Only Anr has this mode. When this mode is used, Agc does not perform speech enhancement processing.
  • Note

    In the case where both ANR and AGC are enabled, if ANR is set to user mode, AGC will process the audio data in frequency domain, and then evaluate the speech signal and make corresponding boost and cut. When ANR is set to default/music mode, AGC will process the audio data in time domain and boost and cut the data in full frequency band.

  • Related data types and interfaces

    MI_AUDIO_HpfConfig_t

    MI_AUDIO_AnrConfig_t

    MI_AUDIO_AgcConfig_t

    MI_AUDIO_EqConfig_t

3.30. MI_AO_ChnParam_t

  • Description

    Define the channel parameter structure.

  • Definition

    typedef struct MI_AO_ChnParam_s
    
    {
    
        MI_AO_ChnGainConfig_t stChnGain;
    
        MI_U32 u32Reserved;
    
    } MI_AI_ChnParam_t
    
  • Member

    Member Name Description
    stChnGain AO channel gain setting structure
    u32Reserved Reserved, not used.
  • Related data types and interfaces

    MI_AO_SetChnParam

    MI_AO_GetChnParam

3.31. MI_AO_ChnGainConfig_t

  • Description

    Define the AO channel gain setting structure.

  • Definition

    typedef struct MI_AO_ChnGainConfig_s
    
    {
    
        MI_BOOL bEnableGainSet;
    
        MI_S16 s16Gain;
    
    }MI_AO_ChnGainConfig_t;
    
  • Member

    Member Name Description
    bEnableGainSet Whether enable gain setting
    s16Gain Gain (-60 – 30 dB)
  • Related data types and interfaces

    MI_AO_ChnParam_t

3.32. MI_AO_InitParam_t

  • Description

    Define the initialized parameter of audio output device.

  • Definition

    typedef struct MI_AO_InitParam_s
    {
        MI_U32 u32DevId;
        MI_U8 *u8Data;
    } MI_AO_InitParam_t;
    
  • Member

    Member Name Description
    u32DevId Audio output device ID
    u8Data Initialization parameter pointer (reserved)
  • Related data types and interfaces

    MI_AO_InitDev

3.33. MI_AO_GainFading_e

  • Description

    Define the speed of audio gain changing.

  • Definition

    typedef enum{
        E_MI_AO_GAIN_FADING_OFF = 0,
        E_MI_AO_GAIN_FADING_1_SAMPLE,
        E_MI_AO_GAIN_FADING_2_SAMPLE,
        E_MI_AO_GAIN_FADING_4_SAMPLE,
        E_MI_AO_GAIN_FADING_8_SAMPLE,
        E_MI_AO_GAIN_FADING_16_SAMPLE,
        E_MI_AO_GAIN_FADING_32_SAMPLE,
        E_MI_AO_GAIN_FADING_64_SAMPLE,
    }MI_AO_GainFading_e;
    
  • Member

    Member Name Description
    E_MI_AO_GAIN_FADING_OFF Disable fading function and gain effective immediately
    E_MI_AO_GAIN_FADING_1_SAMPLE Enable fading function and 1 sampling point varies by 0.5dB
    E_MI_AO_GAIN_FADING_2_SAMPLE Enable fading function and 2 sampling point varies by 0.5dB
    E_MI_AO_GAIN_FADING_4_SAMPLE Enable fading function and 4 sampling point varies by 0.5dB
    E_MI_AO_GAIN_FADING_8_SAMPLE Enable fading function and 8 sampling point varies by 0.5dB
    E_MI_AO_GAIN_FADING_16_SAMPLE Enable fading function and 16 sampling point varies by 0.5dB
    E_MI_AO_GAIN_FADING_32_SAMPLE Enable fading function and 32 sampling point varies by 0.5dB
    E_MI_AO_GAIN_FADING_64_SAMPLE Enable fading function and 64 sampling point varies by 0.5dB
  • Related data types and interfaces

    MI_AO_SetVolume


4. Error code

The AO API error codes are shown in the table below:

Error Code Definition Description
0xA0052001 MI_AO_ERR_INVALID_DEVID Invalid audio output device number
0xA0052002 MI_AO_ERR_INVALID_CHNID Invalid audio output channel number
0xA0052003 MI_AO_ERR_ILLEGAL_PARAM Invalid audio output parameter setting
0xA0052006 MI_AO_ERR_NULL_PTR Input parameter empty indicator error
0xA0052007 MI_AO_ERR_NOT_CONFIG Audio output device properties are not set
0xA0052008 MI_AO_ERR_NOT_SUPPORT Operation is not supported
0xA0052009 MI_AO_ERR_NOT_PERM Operation not allowed
0xA005200C MI_AO_ERR_NOMEM Fail to allocate memory
0xA005200D MI_AO_ERR_NOBUF Insufficient audio output buffer
0xA005200E MI_AO_ERR_BUF_EMPTY Audio output buffer is empty
0xA005200F MI_AO_ERR_BUF_FULL Audio output buffer is full
0xA0052010 MI_AO_ERR_SYS_NOTREADY Audio output system is not initialized
0xA0052012 MI_AO_ERR_BUSY Audio output system is busy
0xA0052017 MI_AO_ERR_NOT_ENABLED Audio output device or channel is not enabled
0xA0052120 MI_AO_ERR_VQE_ERR Audio output VQE algorithm failed to process
0xA0052121 MI_AO_ERR_ADEC_ERR Audio output decoding algorithm processing failed