10.3. API Reference

This section describes how to use the API of each module of CVI_AUDIO in order.

Note that when using CVI_AUDIO, please confirm CVI_SYS_Init has been called to ensure that the corresponding system component is initialized.

CVI_AUDIO_Init must also be called to ensure that the software in the audio module has been initialized.

Users should pay attention to that CVI_AUDIO_Init only needs to be called once.

Please confirm the relevant modules of CVI_AUDIO has been disabled

when exiting Audio, and call CVI_SYS_Exit subsequently.

10.3.1. Module Properties API:

10.3.1.1. CVI_AUDIO_INIT

【Description】

Initialize the audio module.

【Syntax】

CVI_S32 CVI_AUDIO_INIT(void);

【Parameter】

Parameter

Description

Input/Output

None

No need to enter a value.

-

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

The initialization through this API is required before using the audio module.

Otherwise, the functionality may be abnormal or the memory may be accessed incorrectly.

10.3.1.2. CVI_AUDIO_DEINIT

【Description】

Initialize the audio module.

【Syntax】

CVI_S32 CVI_AUDIO_DEINIT(void);

【Parameter】

Parameter

Description

Input/Output

None

No need to enter a value.

-

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Before exiting the audio module, it is necessary to release the module using this API.

Otherwise, the functionality may be abnormal or the memory data may be corrupted.

10.3.1.3. CVI_AUDIO_SetModParam

【Description】

Set the audio module properties.

【Syntax】

CVI_S32 CVI_AUDIO_SetModParam(const AUDIO_MOD_PARAM_S *pstModParam);

【Parameter】

Parameter

Description

Input/Output

pstModParam

Audio module property pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Before using each audio sub-module, initialization is required through this API.

【Example】

None.

10.3.1.4. CVI_AUD_SYS_Bind

【Description】

Set the audio module binding properties.

【Syntax】

CVI_S32 CVI_AUD_SYS_Bind(const MMF_CHN_S *pstSrcChn, const MMF_CHN_S *pstDestChn);

【parameters】

Parameter

Description

Input/Output

pstSrcChn

Audio bind source pointer.

Input

pstDestChn

Audio bind destination pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  1. The binding objects supported are:

(AudIn -> AudEnc),

(AudDec ->AudOut),

  1. See SAMPLE_AUDIO_AiAenc and SAMPLE_AUDIO_AdecAo in cvi_sample_audio.c to understand the binding usage.

【Example】

None.

10.3.1.5. CVI_AUDIO_GetModParam

【Description】

Get the properties of the audio module.

【Syntax】

CVI_S32 CVI_AUDIO_GetModParam(AUDIO_MOD_PARAM_S *pstModParam);

【Parameter】

Parameter

Description

Input/Output

pstModParam

Audio module property pointer.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Before using each audio sub-module, initialization is required through this API.

【Example】

None.

10.3.1.6. CVI_AUDIO_RegisterVQEModule

【Description】

Register VQE module.

【Syntax】

CVI_S32 CVI_AUDIO_RegisterVQEModule(const AUDIO_VQE_REGISTER_S *pstVqeRegister);

【Parameter】

Parameter

Description

Input/Output

pstVqeRegister

VQE related property pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_vqe.so, libaec.so

【Note】

This api is deprecated.

Please use CVI_AI_SetTalkVqeAttr and CVI_AI_EnableVqe.

【Example】

None.

10.3.1.7. CVI_AENC_RegisterExternalEncoder

【Description】

Register audio encoding module.

【Syntax】

CVI_S32 CVI_AENC_RegisterExternalEncoder(CVI_S32 *ps32Handle, const AAC_AENC_ENCODER_S *pstEncoder);

【Parameter】

Parameter

Description

Input/Output

ps32Handle

parameter property pointer

Input

pstEncoder

Encoding module function pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h, cvi_audio_aac_adp.h

  • Library files: libcvi_audio.a, libaacenc2.so

【Note】

  • This function is used for AAC audio encoding.

  • Before registering the function, make sure that the function pointer in pstEncoder is not null, otherwise there will be errors when calling it internally.

  • Related examples can refer to sample/audio/aac_sample/cvi_audio_aac_adp.c

  • This function only supports AAC code registration, please use CVI_AENC_CreateChn for related G7xx series coding. See SAMPLE_AUDIO_AiAenc in cvi_sample_audio.c for reference.

【Example】

None.

10.3.1.8. CVI_AENC_UnRegisterExternalEncoder

【Description】

Cancel the encoder.

【Syntax】

CVI_S32 CVI_AENC_UnRegisterExternalEncoder(CVI_S32 s32Handle);

【Parameter】

Parameter

Description

Input/Output

s32Handle

Register handle (the handle obtained when registering the encoder).

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h, cvi_audio_aac_adp.h

  • Library files: libcvi_audio.a, libaacenc2.so

【Note】

  • This function is used for AAC audio coding.

    • Before unregistering the encoder, all encoding channels created through this encoder must be destroyed. Calling this interface without destroying all channels will result in an error.

【Example】

None.

10.3.1.9. CVI_ADEC_RegisterExternalDecoder

【Description】

Register audio decoding module.

【Syntax】

CVI_S32 CVI_ADEC_RegisterExternalDecoder(CVI_S32 *ps32Handle, const ADEC_DECODER_S *pstDecoder);

【Parameter】

Parameter

Description

Input/Output

ps32Handle

parameter property pointer

Input/Output

pstDecoder

Encoding module function pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h , cvi_audio_aac_adp.h

  • Library files: libcvi_audio.a, libaadec2.so

【Note】

  • This function is used for AAC audio decoding.

  • Before registering the function, make sure that the function pointer in pstEncoder is not null, otherwise there will be errors when calling it internally.

  • Related examples can refer to sample/audio/aac_sample/cvi_audio_aac_adp.c

  • This function only supports AAC code registration, please use CVI_AENC_CreateChn for related G7xx series coding. See SAMPLE_AUDIO_AiAenc in cvi_sample_audio.c for reference.

【Example】

None.

10.3.1.10. CVI_ADEC_UnRegisterExternalDecoder

【Description】

Cancel audio decoding module.

【Syntax】

CVI_S32 CVI_ADEC_UnRegisterExternalDecoder(CVI_S32 s32Handle);

【Parameter】

Parameter

Description

Input/Output

s32Handle

Register handle

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h, cvi_audio_aac_adp.h

  • Library files: libcvi_audio.a, libaadec2.so

【Note】

  • This function is used for AAC audio decoding.

【Example】

None.

10.3.2. Audio Input

The audio input realizes the functions of configuring and enabling the audio input device and acquiring the audio frame data.

The function module provides the following APIs.

10.3.2.1. CVI_AI_SetPubAttr

【Description】

Set Audio Input device properties.

【Syntax】

CVI_S32 CVI_AI_SetPubAttr(AUDIO_DEV AiDevId,  const AIO_ATTR_S *pstAttr);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio Input device number

Input

pstAttr

Audio Input device attribute pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

The properties of audio input device determine the format of input data.

The properties of input device include working mode, sampling rate, sampling precision, buffer size, sampling points per frame, extended flag, clock selection and channel number.

These properties should be consistent with the timing of docking codec configuration, that is, they can be successfully docked.

AiDevId is set to 0 by default. If amplification is not required, an error will be returned if it exceeds 2.

enBitwidth :

the bit depth is 8bit, 16bit or 24bit.

In practical application, the sampling accuracy is limited by Audio Codec.

The u32frmnum item in Buffer size AIO_ATTR_S is used to configure the audio of the block used to receive audio data in Audio Input.

UsrFrmDept :

block voice box, it is recommended to be greater than or equal to 5.

enSamplerate: When the audio sampling rate is high, it is recommended to increase the number of sampling points per frame accordingly.

If you want to encode the collected audio data, you should ensure that the duration of each frame is not less than 10ms (For example, the number of sampling points of each frame should be set to at least 160 at the sampling frequency of 16K).

Otherwise there may be abnormal sound after decoding.

enSoundmode :

two channel or single channel voice frame setting.

u32ChnCnt :

channel number.

Channel number refers to the number of Audio Input channels of the current input device, which should be consistent with the configuration of the audio codec to be connected.

It supports 1 channel and 2 channels.

u32EXFlag :

the extended flag is invalid for Audio Input devices.

u32ClkSel :

clock setting.

In this processor CV1835, there is no special setting, just note that Audio Input/Output attribute should be set consistently in Audio Input / Audio Output.

../_images/image1.png

【Example】

None.

10.3.2.2. CVI_AI_GetPubAttr

【Description】

Get Audio Input device properties.

【Syntax】

CVI_S32 CVI_AI_GetPubAttr(AUDIO_DEV AiDevId, AIO_ATTR_S*pstAttr);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number

Input

pstAttr

Audio Input device attribute pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

If not initialized or CVI_AI_SetPubAttr has not been called, the user will get the pointer and value with the content of 0.

AiDevId is set to 0 by default.

If amplification is not required, an error will be returned if it exceeds 2.

【Example】

None.

10.3.2.3. CVI_AI_Enable

【Description】

Enable Audio Input device.

【Syntax】

CVI_S32 CVI_AI_Enable(AUDIO_DEV AiDevId);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

This API is the last function to enable Audio Input.

Please confirm that the relevant properties have been set before calling.

【Example】

Audio In Examples:
CVI_S32 i;
CVI_S32 s32Ret;

s32Ret = CVI_AI_SetPubAttr(AiDevId, pstAioAttr);
if (s32Ret) {
printf("%s: CVI_AI_SetPubAttr(%d) failed with %#x\n"
, __func__,
AiDevId,
s32Ret);
                  return s32Ret;
}

s32Ret = CVI_AI_Enable(AiDevId);
if (s32Ret) {
                    printf("%s: CVI_AI_Enable(%d) failed with %#x\n", __func__, AiDevId,
                            s32Ret);
                    return s32Ret;
}
for (i = 0; i < s32AiChnCnt >> pstAioAttr->enSoundmode; i++) {
                    s32Ret = CVI_AI_EnableChn(AiDevId, i / (pstAioAttr->enSoundmode + 1));
                    if (s32Ret) {
                                printf("%s: CVI_AI_EnableChn(%d,%d) failed with %#x\n", __func__,
                                      AiDevId, i, s32Ret);
                                return s32Ret;
                    }

                    if (bResampleEn == CVI_TRUE) {
                    s32Ret = CVI_AI_EnableReSmp(AiDevId, i, enOutSampleRate);
                    if (s32Ret) {
                    printf("%s: CVI_AI_EnableReSmp(%d,%d) failed with %#x\n",
__func__,
                              AiDevId, i,
s32Ret);
                                return s32Ret;
                    }
                    }

                    if (pstAiVqeAttr != NULL) {
                                CVI_BOOL bAiVqe = CVI_TRUE;
                                s32Ret = CVI_AI_SetTalkVqeAttr(
                                          0,
                                          0,
                                          0,
                                          0,
                                          (AI_TALKVQE_CONFIG_S *)pstAiVqeAttr);
                                          break;
                    }

                    if (s32Ret) {
                    printf("%s: SetAiVqe%d(%d,%d) failed with %#x\n",
                            __func__,
u32AiVqeType,
                            AiDevId, i, s32Ret);
                            return s32Ret;
                    }

                    if (bAiVqe) {
                    s32Ret = CVI_AI_EnableVqe(AiDevId, i);
                    if (s32Ret) {
                    printf("%s: CVI_AI_EnableVqe(%d,%d) failed with %#x\n", __func__,
                                                            AiDevId, i, s32Ret);
                    return s32Ret;
                    }
                    }
          }

10.3.2.4. CVI_AI_Disable

【Description】

Disable Audio Input device.

【Syntax】

CVI_S32 CVI_AI_Disable(AUDIO_DEV AiDevId);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

This API is the last program to stop an Audio Input device.

Before you disable an Audio Input device, you must disable all enabled Audio Input channels under the device.

If there is an AENC or Audio Output connection, please stop the association with it before calling this API.

【Example】

None.

10.3.2.5. CVI_AI_EnableChn

【Description】

Enable Audio Input channel.

【Syntax】

CVI_S32 CVI_AI_EnableChn(AUDIO_DEV AiDevId, AI_CHN AiChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Before enabling an Audio Input channel, you must first enable its Audio Input device.

【Example】

None.

10.3.2.6. CVI_AI_DisableChn

【Description】

Disable Audio Input channel.

【Syntax】

CVI_S32 CVI_AI_DisableChn(AUDIO_DEV AiDevId, AI_CHN AiChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Please call this API before CVI_AI_Disable to avoid channel parameter residue.

【Example】

None.

10.3.2.7. CVI_AI_GetFrame

【Description】

Get the audio frame.

【Syntax】

CVI_S32 CVI_AI_GetFrame(AUDIO_DEV AiDevId, AI_CHN AiChn, AUDIO_FRAME_S *pstFrm, AEC_FRAME_S *pstAecFrm , CVI_S32 s32MilliSec);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstFrm

Audio frame structure pointer. The user obtains the voice frame from the structure pointer.

Output

pstAecFrm

Echo cancellation reference frame structure pointer.

Output

s32MilliSec

The timeout of data acquisition - 1 indicates blocking mode, waiting all the time when there is no data; 0 indicates non-blocking mode, reporting an error and returning when there is no data; > 0 indicates blocking s32MilliSec MS, reporting an error and returning when there is a timeout

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • The value of s32MilliSec must be greater than or equal to -1. The data shall be obtained in blocking mode when it is equal to -1; non-blocking mode shall be used when it is equal to 0; when greater than 0, it will block s32MilliSec for millisecond and will return timeout and report an error if there is no data.

  • Before acquiring audio frame data, the corresponding Audio Input channel must be enabled.

  • To get the AEC frame, please make sure that the AEC in VQE is turned on.

【Example】

None.

10.3.2.8. CVI_AI_ReleaseFrame

【Description】

Release the audio frame.

【Syntax】

CVI_S32 CVI_AI_ReleaseFrame(AUDIO_DEV AiDevId, AI_CHN AiChn, const AUDIO_FRAME_S *pstFrm, const AEC_FRAME_S *pstAecFrm);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstFrm

Audio frame structure pointer. The user obtains the voice frame from the structure pointer.

Input

pstAecFrm

Echo cancellation reference frame structure pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

If there is no need to release the echo cancellation reference frame, set pstAecFrm to null.

【Example】

None.

10.3.2.9. CVI_AI_SetChnParam

【Description】

Set Audio Input channel parameters.

【Syntax】

CVI_S32 CVI_AI_SetChnParam(AUDIO_DEV AiDevId, AI_CHN AiChn, const AI_CHN_PARAM_S *pstChnParam);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstChnParam

Audio channel parameters

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

At present, the channel parameter has only one member variable, which is used to set the block depth for the user to obtain the audio frame.

The default depth is 0.

The value of the member variable cannot be greater than 30.

【Example】

None.

10.3.2.10. CVI_AI_GetChnParam

【Description】

Get Audio Input channel parameters.

【Syntax】

CVI_S32 CVI_AI_GetChnParam(AUDIO_DEV AiDevId, AI_CHN AiChn, AI_CHN_PARAM_S *pstChnParam);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstChnParam

Audio channel parameters

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

    The audio module mentioned in this file is one of the interfaces of Middleware multimedia layer.

  • Library files: libcvi_audio.a

【Note】

At present, the channel parameter has only one member variable, which is used to set the block depth of the audio frame.

【Example】

None.

10.3.2.11. CVI_AI_EnableReSmp

【Description】

Enable Audio Input resampling.

【Syntax】

CVI_S32 CVI_AI_EnableReSmp(AUDIO_DEV AiDevId, AI_CHN AiChn, AUDIO_SAMPLE_RATE_E enOutSampleRate);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

enOutSampleRat

The output sampling rate of audio resampling.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_vqe.so, libcvi_RES1.so

【Note】

This API is not supported when CVI_AUD_SYS_Bind is used.

The sample rate supported is as follows.

typedef enum _AUDIO_SAMPLE_RATE_E {
  AUDIO_SAMPLE_RATE_8000   = 8000,    /* 8K samplerate*/
  AUDIO_SAMPLE_RATE_11025  = 11025,   /* 11.025K samplerate*/
  AUDIO_SAMPLE_RATE_16000  = 16000,   /* 16K samplerate*/
  AUDIO_SAMPLE_RATE_22050  = 22050,   /* 22.050K samplerate*/
  AUDIO_SAMPLE_RATE_24000  = 24000,   /* 24K samplerate*/
  AUDIO_SAMPLE_RATE_32000  = 32000,   /* 32K samplerate*/
  AUDIO_SAMPLE_RATE_44100  = 44100,   /* 44.1K samplerate*/
  AUDIO_SAMPLE_RATE_48000  = 48000,   /* 48K samplerate*/
  AUDIO_SAMPLE_RATE_64000  = 64000,   /* 64K samplerate*/
  AUDIO_SAMPLE_RATE_BUTT,
} AUDIO_SAMPLE_RATE_E;

【Example】

None.

10.3.2.12. CVI_AI_DisableReSmp

【Description】

Disable Audio Input resampling.

【Syntax】

CVI_S32 CVI_AI_DisableReSmp(AUDIO_DEV AiDevId, AI_CHN AiChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so

【Note】

Please disable the AENC channel and Audio Output channel that use the corresponding Audio Input device audio data before calling this interface, otherwise this interface may fail.

【Example】

None.

10.3.2.13. CVI_AI_ClrPubAttr

【Description】

Clear the Pub property.

【Syntax】

CVI_S32 CVI_AI_ClrPubAttr(AUDIO_DEV AiDevId);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

You need to stop the device before clearing its properties.

Before clearing the device properties, it is recommended to stop all internal connected or user-get mode actions to avoid abnormal behavior caused by the bottom layer still moving audio frames.

【Example】

None.

10.3.2.14. CVI_AI_SaveFile

【Description】

Enable audio input file recording functionality

【Syntax】

CVI_S32 CVI_AI_SaveFile(AUDIO_DEV AiDevId, AI_CHN AiChn, const AUDIO_SAVE_FILE_INFO_S *pstSaveFileInfo);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstSaveFileInfo

Pointer to audio recording file property structure

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

This interface is only used for dumping Audio Input in Audio Input-AENC and Audio Input-Audio Output non-system binding mode.

【Example】

None.

10.3.2.15. CVI_AI_QueryFileStatus

【Description】

Query the status of the audio input channel for saving to file.

【Syntax】

CVI_S32 CVI_AI_QueryFileStatus(AUDIO_DEV AiDevId, AI_CHN AiChn, AUDIO_FILE_STATUS_S *pstFileStatus);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstFileStatus

Pointer to file status property structure

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • This interface is mainly used for debugging, which is not used in general processes.

  • This interface is only used for dumping Audio Input in Audio Input-AENC and Audio Input-Audio Output non-system binding mode.

  • This interface is used to query whether the audio input channel is in the state of saving files after users call CVI_AI_SaveFile to save files.

    If bSaving of pstFileStatus is CVI_TRUE, it indicates that specified size has not been reached;

    CVI_FALSE indicates that it has reached the specified size.

【Example】

None.

10.3.2.16. CVI_AI_EnableAecRefFrame

【Description】

When the AEC is not turned on, the user can also get the AEC reference

frame.

【Syntax】

CVI_S32 CVI_AI_EnableAecRefFrame(AUDIO_DEV AiDevId, AI_CHN AiChn, AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

AoDevId

Audio Output device number used to obtain AEC reference frame.

Input

AoChn

Audio Output channel number used to obtain AEC reference frame.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

None.

【Example】

None.

10.3.2.17. CVI_AI_DisableAecRefFrame

【Description】

When the AEC is not turned on, it is forbidden to obtain the AEC reference

frame.

【Syntax】

CVI_S32 CVI_AI_DisableAecRefFrame(AUDIO_DEV AiDevId, AI_CHN AiChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

None.

【Example】

None.

10.3.2.18. CVI_AI_SetVolume

【Description】

Set the input volume.

【Syntax】

CVI_S32 CVI_AI_SetVolume(AUDIO_DEV AiDevId, CVI_S32 s32VolumeStep);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

s32VolumeStep

Step size for input volume amplification [24-0, 0:mute].

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a/libcvi_audio.so

【Note】

None.

【Example】

None.

10.3.2.19. CVI_AI_GetVolume

【Description】

Get the input volume.

【Syntax】

CVI_S32 CVI_AI_GetVolume(AUDIO_DEV AiDevId, CVI_S32 *ps32VolumeStep);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

ps32VolumeStep

Pointer to step size for input volume amplification [24-0, 0:mute].

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a/libcvi_audio.so

【Note】

None.

【Example】

None.

10.3.3. Voice Quality Enhancement API

10.3.3.1. CVI_AI_SetVqeAttr

【Description】

Set Audio Input voice quality enhancement related attributes.

【Syntax】

CVI_S32 CVI_AI_SetVqeAttr(AUDIO_DEV AiDevId, AI_CHN AiChn, AUDIO_DEV AoDevId, AO_CHN AoChn, AI_VQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

AoDevId

Audio Output device number for echo cancellation.

Input

AoChn

Audio Output channel number for echo cancellation.

Input

pstVqeConfig

Pointer to Audio Input sound quality enhancement configuration structure.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so,

【Note】

Before enabling the sound quality enhancement function, you must first set the relevant properties of the sound quality enhancement function of the corresponding Audio Input channel.

Before setting the relevant attributes of Audio Input sound quality enhancement function, the corresponding Audio Input channel must be enabled.

The sound quality enhancement function of the same Audio Input channel does not support dynamic setting of attributes.

To reset the relevant attributes of the sound quality enhancement function of the Audio Input channel, you need to turn off the sound quality function of the Audio Input channel first, and then set the relevant attributes of the sound quality enhancement function of the Audio Input channel.

【Example】

None.

10.3.3.2. CVI_AI_SetTalkVqeAttr

【Description】

Set voice-related properties of Audio Input speech quality enhancement function.

【Syntax】

CVI_S32 CVI_AI_SetTalkVqeAttr(AUDIO_DEV AiDevId, AI_CHN AiChn, AUDIO_DEV AoDevId, AO_CHN AoChn, AI_TALKVQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

AoDevId

Audio Output device number for echo cancellation.

Input

AoChn

Audio Output channel number for echo cancellation.

Input

pstVqeConfig

Audio input sound quality enhancement configuration structure pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

Talk VQE is mainly used in IPC scenarios.

The sound quality enhancement function of the same Audio Input channel does not support dynamic setting of attributes.

To reset the relevant attributes of the sound quality enhancement function of the Audio Input channel, you need to turn off the sound quality function of the Audio Input channel first, and then set the relevant attributes of the sound quality enhancement function of the Audio Input channel.

【Example】

None.

10.3.3.3. CVI_AI_GetTalkVqeAttr

【Description】

Get voice-related properties of Audio Input speech quality enhancement function.

【Syntax】

CVI_S32 CVI_AI_GetTalkVqeAttr(AUDIO_DEV AiDevId, AI_CHN AiChn, AI_TALKVQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstVqeConfig

Audio input sound quality enhancement configuration structure pointer.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

Before acquiring the sound quality enhancement related attributes, it is necessary to set the sound quality enhancement related attributes of the corresponding Audio Input channel.

【Example】

None.

10.3.3.4. CVI_AI_SetRecordVqeAttr

【Description】

Set voice-related properties of Audio Input recording quality enhancement function

【Syntax】

CVI_S32 CVI_AI_SetRecordVqeAttr(AUDIO_DEV AiDevId, AI_CHN AiChn, const AI_RECORDVQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstVqeConfig

Audio input sound quality enhancement configuration structure pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

At present, the voice algorithm of CVI182X is mainly set by calling CVI_AI_SetTalkVqeAttr.

That Users use this RecordVqeAttr (CVI_AI_SetRecordVqeAttr/ GetRecordVqeAttr) may not support the algorithm or cannot be set, so it is not recommended.

【Example】

None.

10.3.3.5. CVI_AI_GetRecordVqeAttr

【Description】

Get voice-related properties of Audio Input recording quality enhancement function

【Syntax】

CVI_AI_GetRecordVqeAttr (AUDIO_DEV AiDevId, AI_CHN AiChn, const AI_RECORDVQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

pstVqeConfig

Audio input sound quality enhancement configuration structure pointer.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

At present, the voice algorithm of CVI182x is mainly set by calling CVI_AI_SetTalkVqeAttr.

That Users use this RecordVqeAttr (CVI_AI_SetRecordVqeAttr/ GetRecordVqeAttr) may not support the algorithm or cannot be set, so it is not recommended.

【Example】

None.

10.3.3.6. CVI_AI_EnableVqe

【Description】

Enable Audio Input voice quality enhancement.

【Syntax】

CVI_S32 CVI_AI_EnableVqe(AUDIO_DEV AiDevId, AI_CHN AiChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

  • Before enabling the sound quality enhancement function, the corresponding Audio Input channel must be enabled.

  • When the sound quality enhancement function of the same Audio Input channel is enabled several times, Success is returned.

  • After Audio Input channel is disabled, if Audio Input channel is re enabled and sound quality enhancement is used, this interface should be called to re enable sound quality enhancement.

【Example】

None.

10.3.3.7. CVI_AI_DisableVqe

【Description】

Disable Audio Input voice quality enhancement.

【Syntax】

CVI_S32 CVI_AI_DisableVqe(AUDIO_DEV AiDevId, AI_CHN AiChn);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AiChn

Audio input channel number. It is independent of the sound mode enSoundmode. Users can obtain the same audio source through different AiChn under the same AiDevId.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

  • When Audio Input sound quality enhancement is no longer used, this interface should be called to disable it.

【Example】

None.

10.3.3.8. CVI_AI_SetTrackMode

【Description】

Set Audio Input channel mode.

【Syntax】

CVI_S32 CVI_AI_SetTrackMode(AUDIO_DEV AiDevId, AUDIO_TRACK_MODE_E enTrackMode);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

enTrackMode

typedef enum _AUDIO_TRACK_MODE_E { AUDIO_TRACK_NORMAL = 0, AUDIO_TRACK_BOTH_LEFT = 1, AUDIO_TRACK_BOTH_RIGHT = 2, AUDIO_TRACK_EXCHANGE = 3, AUDIO_TRACK_MIX = 4, AUDIO_TRACK_LEFT_MUTE = 5, AUDIO_TRACK_RIGHT_MUTE = 6, AUDIO_TRACK_BOTH_MUTE = 7, AUDIO_TRACK_BUTT } AUDIO_TRACK_MODE_E;

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

  • It supports acquiring channel mode when Audio Input device works in I2S mode,

but not in PCM mode.

  • Call this interface after Audio Input device is enabled successfully.

  • TrackMode capability is related to audio codec.

    If the client uses its own codec, the settings may be different.

【Example】

None.

10.3.3.9. CVI_AI_GetTrackMode

【Description】

Get Audio Input channel mode.

【Syntax】

CVI_S32 CVI_AI_GetTrackMode(AUDIO_DEV AiDevId, AUDIO_TRACK_MODE_E *penTrackMode);

【Parameter】

Parameter

Description

Input/Output

AiDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

enTrackMode

typedef enum _AUDIO_TRACK_MODE_E { AUDIO_TRACK_NORMAL = 0, AUDIO_TRACK_BOTH_LEFT = 1, AUDIO_TRACK_BOTH_RIGHT = 2, AUDIO_TRACK_EXCHANGE = 3, AUDIO_TRACK_MIX = 4, AUDIO_TRACK_LEFT_MUTE = 5, AUDIO_TRACK_RIGHT_MUTE = 6, AUDIO_TRACK_BOTH_MUTE = 7, AUDIO_TRACK_BUTT } AUDIO_TRACK_MODE_E;

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a, libcvi_RES1.so, libcvi_vqe.so, libaec.so

【Note】

  • It supports acquiring channel mode when Audio Input device works in I2S mode,but not in PCM mode.

  • Call this interface after Audio Input device is enabled successfully.

  • TrackMode capability is related to audio codec.

    If the client uses its own codec, the settings may be different.

【Example】

None.

10.3.3.10. CVI_AO_SetVqeAttr

【Description】

Set the voice quality enhancement attributes of Audio Output

【Syntax】

CVI_S32 CVI_AO_SetVqeAttr(AUDIO_DEV AoDevId, AO_CHN AoChn, AO_VQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number

Input

pstVqeConfig

Audio output sound quality enhancement configuration structure pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a、libaec.so、libcvi_RES1.so

【Note】

  • Before enabling the sound quality enhancement, you must first set the sound quality enhancement related properties of the corresponding AP channel.

  • The corresponding Audio Output channel must be enabled before setting the related attributes of the sound quality enhancement function of Audio Output.

【Example】

None.

10.3.3.11. CVI_AO_GetVqeAttr

【Description】

Get the voice quality enhancement attributes of Audio Output

【Syntax】

CVI_S32 CVI_AO_GetVqeAttr(AUDIO_DEV AoDevId, AO_CHN AoChn, AO_VQE_CONFIG_S *pstVqeConfig);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number

Input

pstVqeConfig

Audio output sound quality enhancement configuration structure pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a、libaec.so、libcvi_RES1.so、libcvi_vqe.so

【Note】

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

【Example】

None.

10.3.3.12. CVI_AO_EnableVqe

【Description】

Enable the voice quality enhancement of Audio Output

【Syntax】

CVI_S32 CVI_AO_EnableVqe(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a、libaec.so、libcvi_RES1.so、libcvi_vqe.so

【Note】

  • The corresponding Audio Output channel must be enabled before enabling sound quality enhancement.

  • After the Audio Output channel is disabled, if you re enable the Audio Output channel again and use the sound quality enhancement function, you need to call this interface to re enable the sound quality enhancement function.

【Example】

None.

10.3.3.13. CVI_VQE_PathSelect

【Description】

Setting VQE algorithm path.

【Syntax】

CVI_S32 CVI_VQE_PathSelect(E_VQE_ALGO_PATH eVqePath);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a、libaec.so、libcvi_RES1.so、libcvi_vqe.so

【Note】

This API is only available on ICs that support it and must be enabled before use.

【Example】

None.

10.3.4. Audio Output

Audio output (AO) mainly realizes the functions of enabling audio output device and sending audio frame to output channel.

The API is listed below with additional details.

10.3.4.1. CVI_AO_SetPubAttr

【Description】

Set Audio Output device properties.

【Syntax】

CVI_S32 CVI_AO_SetPubAttr(AUDIO_DEV AoDevId,const AIO_ATTR_S *pstAttr);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

pstAttr

Audio output device properties.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Before setting properties, you need to ensure that Audio Output is disabled. If it is enabled, you need to disable Audio Output devices first.

  • Audio Output must cooperate with DA in order to work normally. Users must know the relationship between the data format and channel sent by DA in order to send data from the correct channel.

  • u32ClkSel does not need to be configured under CV182x processor.

  • In the main mode of Audio Output device, the key configuration items that determine the output clock of Audio Output device are sampling rate, sampling precision and number of channels.

    The sampling precision multiplied by the number of channels is the bit width of one sampling of the timing sequence of Audio Output device.

  • CV182x extended flag is invalid for Audio Output device, so it does not need to be set.

  • For other items in Audio Output device attribute structure, please refer to the description of related interfaces in Audio Input module.

【Example】

None.

10.3.4.2. CVI_AO_GetPubAttr

【Description】

Get Audio Output device properties.

【Syntax】

CVI_S32 CVI_AO_GetPubAttr(AUDIO_DEV AoDevId, AIO_ATTR_S *pstAttr);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

pstAttr

Audio output device properties.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: -cvi_comm_aio.h, cvi_audio.h

  • Library files: ibcvi_audio.a

【Note】

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

  • If the property has never been configured, the error that the property is not configured is returned.

【Example】

CVI_S32 s32ret;
AUDIO_DEV AoDevId = 0;
AIO_ATTR_S stAttr;

s32ret = CVI_AO_GetPubAttr(AoDevId, &stAttr);
if(s32ret != CVI_SUCCESS) {
printf("get ao %d attr err:0x%x\n", AoDevId,s32ret);
return s32ret; }

10.3.4.3. CVI_AO_Enable

【Description】

Enables Audio Output devices.

【Syntax】

CVI_S32 CVI_AO_Enable(AUDIO_DEV AoDevId);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Require Audio Output device properties to be configured before enabling, otherwise an error with properties not configured will be returned.

  • If the Audio Output device is enabled, Success is returned.

【Example】

CVI_S32 i;
CVI_S32 s32Ret;

s32Ret = CVI_AO_SetPubAttr(AoDevId, pstAioAttr);
if (s32Ret != CVI_SUCCESS) {
          printf("%s: CVI_AO_SetPubAttr(%d) failed with %#x!\n", __func__,
                  AoDevId, s32Ret);
          return CVI_FAILURE;
}

s32Ret = CVI_AO_Enable(AoDevId);
if (s32Ret != CVI_SUCCESS) {
          printf("%s: CVI_AO_Enable(%d) failed with %#x!\n", __func__, AoDevId,
                  s32Ret);
          return CVI_FAILURE;
}

for (i = 0; i < s32AoChnCnt; i++) {
          s32Ret = CVI_AO_EnableChn(AoDevId, i / (pstAioAttr->enSoundmode + 1));
          if (s32Ret != CVI_SUCCESS) {
                    printf("%s: CVI_AO_EnableChn(%d) failed with %#x!\n", __func__, i,
                            s32Ret);
                    return CVI_FAILURE;
          }

          if (bResampleEn == CVI_TRUE) {
                    s32Ret = CVI_AO_DisableReSmp(AoDevId, i);
                    s32Ret |= CVI_AO_EnableReSmp(AoDevId, i, enInSampleRate);
                    if (s32Ret != CVI_SUCCESS) {
                                printf("%s: CVI_AO_EnableReSmp(%d,%d) failed with %#x!\n", __func__,
                                      AoDevId, i, s32Ret);
                                return CVI_FAILURE;
                    }
          }

}

s32Ret = CVI_AO_EnableChn(AoDevId, AO_SYSCHN_CHNID);
if (s32Ret != CVI_SUCCESS) {
          printf("%s: CVI_AO_EnableChn(%d) failed with %#x!\n", __func__, i,
                  s32Ret);
          return CVI_FAILURE;
}

10.3.4.4. CVI_AO_Disable

【Description】

Deactivate Audio Output device.

【Syntax】

CVI_S32 CVI_AO_Disable(AUDIO_DEV AoDevId);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number.

The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

All Audio Output channels under the device must be disabled before the Audio Output device can be disabled.

【Example】

None.

10.3.4.5. CVI_AO_EnableChn

【Description】

Enable Audio Output channel.

【Syntax】

CVI_S32 CVI_AO_EnableChn(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Before enabling the Audio Output channel, the Audio Output device to which it belongs must be enabled, otherwise an error code that the device did not start is returned.

【Example】

None.

10.3.4.6. CVI_AO_DisableChn

【Description】

Disable Audio Output channel.

【Syntax】

CVI_S32 CVI_AO_DisableChn(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

none

【Example】

None.

10.3.4.7. CVI_AO_SendFrame

【Description】

Send Audio Output audio frame.

【Syntax】

CVI_S32 _AO_SendFrame(AUDIO_DEV AoDevId, AO_CHN AoChn, const AUDIO_FRAME_S *pstData, CVI_S32 s32MilliSec);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

pstData

Pointer to Audio frame structure.

Input

s32MilliSec

The timeout for sending data -1 indicates blocking mode; 0 means non-blocking mode; >0 indicates blocking s32MilliSec 毫秒 Returning an error if a timeout occurs.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • This interface is used to actively send audio frames to Audio Output output.

  • The Audio Output channel has been bound to Audio Input or ADEC through the system binding (CVI_SYS_Bind) interface, and calling this interface is not necessary and not recommended.

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

【Example】

None.

10.3.4.8. CVI_AO_EnableReSmp

【Description】

Enable Audio Output resampling.

【Syntax】

CVI_S32 CVI_AO_EnableReSmp(AUDIO_DEV AoDevId, AO_CHN AoChn, AUDIO_SAMPLE_RATE_E enInSampleRate);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

enInSampleRate

Input sampling rate for audio resampling.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • This API is not supported when CVI AUD SYS Bind is used

  • This interface should be called to enable resampling after the Audio Output channel is enabled and before binding the Audio Output channel.

  • Resampling is allowed to be enabled repeatedly, but the resampled input sampling rate of the post-configuration must be guaranteed to be the same as the previously configured resampled input sampling rate.

  • If the Audio Output channel is disabled and the resampling function is enabled again, you need to invoke this interface to enable resampling again.

  • The input sampling rate for Audio Output resampling must be different from the sampling rate for the Audio Output device property configuration.

【Example】

None.

10.3.4.9. CVI_AO_DisableReSmp

【Description】

Disable Audio Output resampling.

【Syntax】

CVI_S32 CVI_AO_DisableReSmp(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

If Audio Output resampling is no longer used, this interface should be called to disable it.

【Example】

None.

10.3.4.10. CVI_AO_PauseChn

【Description】

Pause Audio Output channel.

【Syntax】

CVI_S32 CVI_AO_PauseChn(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

When the Audio Output channel is paused, if the bound ADEC channel continues to send audio frame data to this channel, the transmitted audio frame data will be blocked.

If the bound Audio Input channel continues to send audio frame data to this channel, the audio frame is put into the buffer when the channel buffer is not full, and the audio frame is discarded when it is full.

Calling this interface to pause the Audio Output channel is not allowed when the Audio Output channel is disabled.

【Example】

None.

10.3.4.11. CVI_AO_ResumeChn

【Description】

Restore Audio Output channel.

【Syntax】

CVI_S32 CVI_AO_ResumeChn(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • The Audio Output channel can be restored by calling when this interface is paused.

  • If the Audio Output channel is in the suspended or enabled state, the interface is invoked successfully.

    Otherwise the call will return an error.

【Example】

None.

10.3.4.12. CVI_AO_ClearChnBuf

【Description】

Clear the current audio data buffer in the Audio Output channel.

【Syntax】

CVI_S32 CVI_AO_ClearChnBuf(AUDIO_DEV AoDevId, AO_CHN AoChn);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Call this interface after the Audio Output channel is successfully enabled.

  • In order to completely clear all buffer data on decoding playback path, this interface should be used in conjunction with the CVI_ADEC_ClearChnBuf interface.

【Example】

None.

10.3.4.13. CVI_AO_QueryChnStat

【Description】

Query the current status of audio data block in the Audio Output channel.

【Syntax】

CVI_S32 CVI_AO_QueryChnStat(AUDIO_DEV AoDevId, AO_CHN AoChn, AO_CHN_STATE_S *pstStatus);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio Output device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

AoChn

Audio output channel number.The supported channel range is determined by the maximum number of channels u32ChnCnt in the Audio Output device properties and the channel mode enSoundmode.

Input

pstStatus

Pointer to block status structure

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Call this interface after the Audio Output channel is successfully enabled.

【Example】

None.

10.3.4.14. CVI_AO_SetTrackMode

【Description】

Set Audio Output device channel mode.

【Syntax】

CVI_S32 CVI_AO_SetTrackMode(AUDIO_DEV AoDevId, AUDIO_TRACK_MODE_E enTrackMode);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

enTrackMode

Audio device channel mode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Call this interface after the Audio Output device is successfully enabled.

  • Audio Output supports setting the channel mode when it works in I2S mode, but does not support setting the channel mode when it works in PCM mode.

【Example】

CVO_S32 s32Ret;
AUDIO_DEV AoDev = 0;
AUDIO_TRACK_MODE_E enTrackMode = AUDIO_TRACK_NORMAL;
AUDIO_TRACK_MODE_E temp;

s32Ret = CVI_AO_SetTrackMode(AoDev, enTrackMode);

if (CVI_SUCCESS != s32Ret) {
printf("Ao set track mode failure! AoDev: %d, enTrackMode: %d, s32Ret: 0x%x.\n", AoDev, enTrackMode, s32Ret);
return s32Ret;
}

s32Ret = CVI_AO_GetTrackMode(AoDev, &temp);
if (s32Ret!=CVI_SUCCESS)  {
printf("Ao get track mode failure! AoDev: %d, s32Ret: 0x%x.\n", AoDev, s32Ret);
return s32Ret;
}

10.3.4.15. CVI_AO_GetTrackMode

【Description】

Gets the channel mode of the Audio Output device.

【Syntax】

CVI_S32 CVI_AO_GetTrackMode(AUDIO_DEV AoDevId, AUDIO_TRACK_MODE_E *penTrackMode);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

enTrackMode

Audio device channel mode.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Call this interface after the Audio Output device is successfully enabled.

  • Audio Output supports setting the channel mode when it works in I2S mode, but does not support setting the channel mode when it works in PCM mode.

【Example】

None.

10.3.4.16. CVI_AO_SetVolume

【Description】

Set Audio Output device volume.

【Syntax】

CVI_S32 CVI_AO_SetVolume(AUDIO_DEV AoDevId, CVI_S32 s32VolumeDb);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

s32VolumeDb

The volume range is from 32 to 0, which corresponds to a gain range from 0dB to -22.5dB, with a decrease of 1.5dB for each step.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Call this interface after the Audio Output device is successfully enabled.

【Example】

None.

10.3.4.17. CVI_AO_GetVolume

【Description】

Gets the volume size of the Audio Output device.

【Syntax】

CVI_S32 CVI_AO_GetVolume(AUDIO_DEV AoDevId, CVI_S32 *ps32VolumeDb);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

ps32VolumeDb

Pointer to the Ao device volume. The volume range is from 32 to 0, which corresponds to a gain range from 0dB to -22.5dB, with a decrease of 1.5dB for each step.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

Call this interface after the Audio Output device is successfully enabled.

【Example】

None.

10.3.4.18. CVI_AO_SetMute

【Description】

Set the mute status of an Audio Output device

【Syntax】

CVI_S32 CVI_AO_SetMute(AUDIO_DEV AoDevId, CVI_BOOL bEnable, const AUDIO_FADE_S *pstFade);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

bEnable

Whether the audio device is muted.

CVI_TRUE: Enable mute function;

CVI_FALSE: Turn off mute function

Input

pstFade

Fade in and out structure pointers.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Call this interface after the Audio Output device is successfully enabled.

【Example】

None.

10.3.4.19. CVI_AO_GetMute

【Description】

Gets the mute status of the Audio Output device.

【Syntax】

CVI_S32 CVI_AO_GetMute(AUDIO_DEV AoDevId, CVI_BOOL *pbEnable, AUDIO_FADE_S *pstFade);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

bEnable

Audio device mute state pointer.

Output

pstFade

Fade in and out structure pointers.

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Call this interface after the Audio Output device is successfully enabled.

【Example】

None.

10.3.4.20. CVI_AO_SaveFile

【Description】

This function is not supported at present. Users can use

CVI_AO_SendFrame to save files.

【Syntax】

CVI_S32 CVI_AO_SaveFile(AUDIO_DEV AoDevId, AO_CHN AoChn, AUDIO_SAVE_FILE_INFO_S *pstSaveFileInfo);

【Parameter】

【Return Value】

【Requirement】

  • Header files:

  • Library files:

【Note】

【Example】

None.

10.3.4.21. CVI_AO_ClrPubAttr

【Description】

Clear Audio Output device properties.

【Syntax】

CVI_S32 CVI_AO_ClrPubAttr(AUDIO_DEV AoDevId);

【Parameter】

Parameter

Description

Input/Output

AoDevId

Audio device number. The device number is preset to 0, and setting it to a value greater than 2 will return an error, unless customization requires expansion.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • You need to stop the device before clearing its properties.

  • Audio Input device and Audio Output device clocks do not need to be set.

【Example】

None.

10.3.5. Audio Encoding

Audio encoding is mainly dedicated to voice frame data conversion.

Cvitek supports G.711, G.726, LDPCM-related encoding.

The encoded voice frame data is small, but the voice encoding belongs to lossy compression, which results in different sound quality.

The bit rate/sample rate used by different encoding varies.

Users need to know the specifications of the encoding protocol and set the corresponding API.

Otherwise the function will return an error.

Codec

Sampling Rat e(KHZ)

Ban dwidth(kbps)

Nominal Ban dwidth(kbps)

License

G.711*

8

64

87.2

Open Source

G.726

8

16/24/32/40

47.2/55.2

Open Source

*G.711 include a-law/mu-law

The AENC module provides the following APIs:

10.3.5.1. CVI_AENC_CreateChn

【Description】

Create an audio encoding channel.

【Syntax】

CVI_S32 CVI_AENC_CreateChn(AENC_CHN AeChn, const AENC_CHN_ATTR_S *pstAttr);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Range of values: [0, AENC_MAX_CHN_NUM]

Input

pstAttr

Encoded Channel Property Pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h, cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Currently supports G711, G726, ADPCM

  • The format supports 16-bit S16LE, and others are not supported.

    Set Audio Input attribute/AENC attribute.

    If you want to use it after VQE, set the length of the sound frame to a multiple of 160.

    To comply with the Cvitek VQE specification.

  • Some of the attributes of audio encoding need to match the attributes of the input audio data, such as sampling rate, frame length (number of sampling points per frame), etc.

  • The buffer size is expressed in frames.

    The Value range is [2, MAX_BUFFERING_DEPTH].

    You are advised to set the value to more than 10.

    Too small buffer configuration may cause exceptions such as frame loss.

【Example】

None.

10.3.5.2. CVI_AENC_DestroyChn

【Description】

Destroy audio codec pass.

【Syntax】

CVI_S32 CVI_AENC_DestroyChn(AENC_CHN AeChn);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Value

Range: [0, AENC_MAX_CHN_NUM]

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • The call to this function is invalid if the channel is not created.

  • If the channel is destroyed while obtaining/releasing the stream or sending the frame, a failure will be returned.

  • Users should pay attention when synchronizing the process

【Example】

None.

10.3.5.3. CVI_AENC_SendFrame

【Description】

Send audio encoded audio frames.

【Syntax】

CVI_S32 CVI_AENC_SendFrame(AENC_CHN AeChn, const AUDIO_FRAME_S *pstFrm, const AEC_FRAME_S *pstAecFrm);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Range of values: [0, AENC_MAX_CHN_NUM]

Input

pstFrm

Audio frame structure pointer.

Input

pstAecFrm

Echo cancellation reference frame structure pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • The call to this function is invalid if the channel is not created.

  • pstAecFrm can be set to NULL if echo cancellation is not required.

  • This interface is used to actively send audio frames for encoding. If the AENC channel is already bound to Audio Input through the system binding (CVI_SYS_Bind) interface, calling this interface is unnecessary and not advised.

【Example】

s32Ret = CVI_AI_GetChnParam(AiDev, AiChn, &stAiChnPara);
if (s32Ret != CVI_SUCCESS) {
          printf("%s: Get ai chn param failed\n", __func__);
          return NULL;
}

stAiChnPara.u32UsrFrmDepth = 10;
s32Ret = CVI_AI_SetChnParam( AiDev,  AiChn, &stAiChnPara);
if (s32Ret != CVI_SUCCESS) {
          printf("%s: set ai chn param failed\n", __func__);
          return NULL;
}

while ( 1) {
          /* get frame from ai chn */
          memset(&stAecFrm, 0, sizeof(AEC_FRAME_S));
          s32Ret = CVI_AI_GetFrame( AiDev,  AiChn, &stFrame,
                                                &stAecFrm, CVI_FALSE);
          if (s32Ret != CVI_SUCCESS) {
                    printf("CVI_AI_GetFrame none!!\n");
                    continue;
          }
          /* send frame to encoder */
          if ( bSendAenc == CVI_TRUE) {
                    s32Ret = CVI_AENC_SendFrame( AencChn, &stFrame, &stAecFrm);
                    if (s32Ret != CVI_SUCCESS) {
                                printf("%s: CVI_AENC_SendFrame(%d), failed with %#x!\n",
                                      __func__,  AencChn, s32Ret);
                                bStart = CVI_FALSE;
                                return NULL;
                    }
          }
          /* send frame to ao */
          /* If owner toggle bSendAenc, do not toggle bSendAo */
          /* You cannot send encode frame to CVI_AO_SendFrame */
          /* It cannot play out encode frame by only AO_SendFrame*/
          if ( bSendAo == CVI_TRUE) {
                    s32Ret = CVI_AO_SendFrame( AoDev,  AoChn, &stFrame, 1000);
                    if (s32Ret != CVI_SUCCESS) {
                                printf("%s: CVI_AO_SendFrame(%d, %d), failed with %#x!\n",
                                      __func__,  AoDev,  AoChn, s32Ret);
                                bStart = CVI_FALSE;
                                return NULL;
                    }
          }

          /* finally you must release the stream */
          s32Ret = CVI_AI_ReleaseFrame( AiDev,  AiChn, &stFrame,
                                                      &stAecFrm);

          if (s32Ret != CVI_SUCCESS) {
                    printf("%s: CVI_AI_ReleaseFrame(%d, %d), failed with %#x!\n",
                                __func__,  AiDev,  AiChn, s32Ret);
                      bStart = CVI_FALSE;
                    return NULL;
          }
}

10.3.5.4. CVI_AENC_GetStream

【Description】

Gets the encoded stream.

【Syntax】

CVI_S32 CVI_AENC_GetStream(AENC_CHN AeChn, AUDIO_STREAM_S *pstStream, CVI_S32 s32MilliSec);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Range of values: [0, AENC_MAX_CHN_NUM]

Input

pstStream

The obtained audio stream.

Output

s32MilliSec

Timeout to acquring data

1 indicates blocking mode and waits until there is no data;

0 means non-blocking mode, error returns when no data is available;

>0 indicates blocking s32MilliSec milliseconds.

Returning an error if a timeout occurs

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • The code stream can be obtained only after the channel is created. Otherwise, a direct failure is returned.

    If the channel is destroyed in the process of obtaining the code stream, a failure is returned immediately.

  • The value of s32MilliSec must be greater than or equal to -1, blocking mode for data when the value is equal to -1, non-blocking mode for data when it is equal to 0, and blocking s32MilliSec milliseconds when greater than 0, returning a timeout and reporting if no data.

【Example】

None.

10.3.5.5. CVI_AENC_ReleaseStream

【Description】

Release the stream obtained from the audio encoding channel.

【Syntax】

CVI_S32 CVI_AENC_ReleaseStream(AENC_CHN AeChn, const AUDIO_STREAM_S *pstStream);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Range of values: [0, AENC_MAX_CHN_NUM]

Input

pstStream

Pointer to the audio stream.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • It is best to release the code stream immediately after use.

    If not released in time, the coding process will be blocked.

  • The code stream to be released must be the code stream obtained from the channel.

    Do not modify the code stream information structure; otherwise, the code stream cannot be released, the buffer of the code stream will be lost, and even program exceptions will be caused.

  • When releasing the stream, ensure that the channel has been created.

    Otherwise, a direct failure is returned.

    If the channel is destroyed during the release process, an immediate failure is returned.

【Example】

None.

10.3.5.6. CVI_AENC_SaveFile

【Description】

Enabling channel file recording functionality before audio encoding

【Syntax】

CVI_S32 CVI_AENC_SaveFile(AENC_CHN AeChn, const AUDIO_SAVE_FILE_INFO_S *pstSaveFileInfo);

【Parameter】

Parameter

Description

Input/Output

AeChn

Audio encoding channel number. Range of values: [0, AENC_MAX_CHN_NUM].

Input

pstSaveFileInfo

Audio save file property structure pointer.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Cvitek does not support this API.

    -Please use CVI_AI_SaveFile.

【Example】

None.

10.3.5.7. CVI_AENC_QueryFileStatus

【Description】

Checking the file storage status of the audio encoding channel

【Syntax】

CVI_S32 CVI_AENC_QueryFileStatus(AENC_CHN AeChn, AUDIO_FILE_STATUS_S *pstFileStatus);

【Parameter】

Parameter

Description

Input/Output

AeChn

Audio encoding channel number. Range of values: [0, AENC_MAX_CHN_NUM].

Input

pstFileStatus

Pointer to status attribute structure

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Cvitek does not support this API.

  • Please use CVI_AI_SaveFile/CVI_AI_QueryFileStatus

【Example】

None.

10.3.5.8. CVI_AENC_GetStreamBufInfo

【Description】

Get information about the audio stream buffer.

【Syntax】

CVI_S32 CVI_AENC_GetStreamBufInfo(AENC_CHN AeChn, CVI_U32 *pu32PhysAddr, CVI_U32 *pu32Size);

【Parameter】

Parameter

Description

Input/Output

AeChn

Audio encoding channel number.

Range of values: [0, AENC_MAX_CHN_NUM].

Input

pu32PhysAddr

The physical address of the audio stream buffer.

Output

pu32Size

Length of audio stream buffer in byte

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

None.

【Example】

None.

10.3.5.9. CVI_AENC_SetMute

【Description】

Set AENC mute state

【Syntax】


CVI_AENC_SetMute(AENC_CHN AeChn,CVI_BOO; bEnable);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Range of values: [0, AENC_MAX_CHN_NUM]

Input

bEnable

Whether the audio device is muted.

CVI_TRUE: Enable mute function;

CVI_FALSE: Turn off mute function

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_audio.h,

  • Library files: libcvi_audio.a

【Note】

  • Use only after AENC creates a device channel.

【Example】

None.

10.3.5.10. CVI_AENC_GetMute

【Description】

Get the mute status of an AENC (Audio Encode) channel

【Syntax】

CVI_AENC_GetMute(AENC_CHN AeChn, CVI_BOOL *pbEnable);

【Parameter】

Parameter

Description

Input/Output

AeChn

Encoding device channel number.

Range of values: [0, AENC_MAX_CHN_NUM]

Input

pbEnable

Pointer to audio device mute status

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_audio.h

  • Library files: libcvi_audio.a

【Note】

  • Use only after AENC creates a device channel

【Example】

None.

libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

10.3.6. Audio Decoding

The main functions of audio decoding include creating decoding channels, decoding audio streams, and obtaining decoded audio frames

The supported APIs and details are listed below:

10.3.6.1. CVI_ADEC_CreateChn

【Description】

Create an audio decoding channel.

【Syntax】

CVI_S32 CVI_ADEC_CreateChn(ADEC_CHN AdChn, const ADEC_CHN_ATTR_S *pstAttr);

【Parameter】

Parameter

Description

Input/Output

AdChn

Channel number.

Range: [0, ADEC_MAX_CHN_NUM].

Input

pstAttr

Channel property pointer.

Input

【Return Value】

Parameter

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Currently support G711, G726, ADPCM.

  • Some properties of audio decoding need to match those of the output device, such as sampling rate, frame length (number of sampling points per frame), etc.

【Example】

None.

10.3.6.2. CVI_ADEC_DestroyChn

【Description】

Destroy the audio decoding channel.

【Syntax】

CVI_S32 CVI_ADEC_DestroyChn(ADEC_CHN AdChn);

【Parameter】

Parameter

Description

Input/Output

AdChn

Channel number.

Range: [0, ADEC_MAX_CHN_NUM].

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Calling this interface without channel creation returns Success.

  • If a stream is being acquired/released or a frame is being sent, destroying the channel will return failure immediately.

【Example】

None.

10.3.6.3. CVI_ADEC_SendStream

【Description】

Sends a stream to an audio decoding channel.

【Syntax】

CVI_S32 CVI_ADEC_SendStream(ADEC_CHN AdChn, const AUDIO_STREAM_S *pstStream, CVI_BOOL bBlock);

【Parameter】

Parameter

Description

Input/Output

AdChn

Channel number.

Range: [0, ADEC_MAX_CHN_NUM].

Input

pstStream

Audio stream

Input

bBlock

CVI_TRUE: Blocked. CVI_FALSE: Non-blocking.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • The stream mode is inefficient and may have delay when the bitstream packet size is not determined to be one frame (greater than or equal to one frame);

  • Ensure that a channel has been created before sending data.

    Otherwise, a direct failure is returned.

    If the channel is destroyed during data sending, a failure is returned immediately.

  • Ensure the correctness of the stream data sent to the ADEC channel, otherwise the decoder may exit abnormally.

【Example】

None.

10.3.6.4. CVI_ADEC_ClearChnBuf

【Description】

Clear the current audio data block in the ADEC channel.

【Syntax】

CVI_S32 CVI_ADEC_ClearChnBuf(ADEC_CHN AdChn);

【Parameter】

Parameter

Description

Input/Output

AdChn

Channel number.

Range: [0, ADEC_MAX_CHN_NUM].

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Decoding channel has been created is required.

  • Stream decoding is not recommended when using this interface.When using streaming decoding to clear blocks, the user needs to ensure that after clearing blocks, the data sent to the decoder must be a complete frame stream, otherwise the decoder may not operate properly.

  • Regardless of whether stream decoding is utilized, it is crucial to ensure synchronization between the data feeding operation and the buffer clearing operation.

【Example】

none

10.3.6.5. CVI_ADEC_GetFrame

【Description】

Gets the decoded audio frame.

【Syntax】

CVI_S32 CVI_ADEC_GetFrame(ADEC_CHN AdChn, AUDIO_FRAME_INFO_S *pstFrmInfo, CVI_BOOL bBlock);

【Parameter】

Parameter

Description

Input/Output

AdChn

Audio decoding channel.

Input

pstFrmInfo

Audio frame data structure.

Output

bBlock

Whether to retrieve data in a blocking mode.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: -cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files:-libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • Must be called after the ADEC channel is created.

  • When using this interface to obtain decoded frame data, it is recommended to send the stream by frame.

  • When using this interface to obtain audio data, unbind ADEC from Audio Output, otherwise the frames are discontinuous.

  • When you use this interface to obtain audio frame data, ensure that the decoded frame data is obtained in a timely manner if the sent code stream is sent as stream. Otherwise, an exception may occur.

【Example】

None.

10.3.6.6. CVI_ADEC_ReleaseFrame

【Description】

Release the acquired audio decoded frame data.

【Syntax】

CVI_S32 CVI_ADEC_ReleaseFrame(ADEC_CHN AdChn, AUDIO_FRAME_INFO_S *pstFrmInfo);

【Parameter】

Parameter

Description

Input/Output

AdChn

Audio decoding channel.

Input

pstFrmInfo

Audio frame data structure.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

  • This interface must be used together with the CVI_ADEC_GetFrame interface.

-Must be called after the ADEC channel is created.

【Example】

None.

10.3.6.7. CVI_ADEC_SendEndOfStream

【Description】

Sending the end-of-stream (EOS) marker to the decoder and clearing the stream buffer.

【Syntax】

CVI_S32 CVI_ADEC_SendEndOfStream (ADEC_CHN AdChn, CVI_BOOL bInstant);

【Parameter】

Parameter

Description

Input/Output

AdChn

Audio decoding channel.

Input

bInstant

The parameter specifies in whether to immediately clear the internal buffer data of the decoder.

The Value range is: - CVI_FALSE: Delayed clearing.

The decoder’s internal buffer data will not be cleared immediately, and the decoding process will continue until the remaining buffer is not enough

for one frame of data.

The clearing operation will then be performed.

CVI_TRUE: Immediate clearing of the decoder’s internal buffer data.”

Input/Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_comm_aenc.h

  • Library files: libcvi_audio.a, libcvi_transcode.so, libcvi_RES1.so

【Note】

None.

【Example】

None.

10.3.7. Built-in Codec

The built-in audio codec is mainly operated through ioctl to manipulate the hardware device. The ioctl calls are used to read and write to the registers of the built-in audio codec.

Built-in audio codec standard function cmd

10.3.7.1. ACODEC_SOFT_RESET_CTRL

【Description】

Restore Codec to its default setting.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SOFT_RESET_CTRL);

【Parameter】

Parameter

Description

Input/Output

fd

File Description of Audio Codec Device

Input

ACODEC_SOFT_RESET_CTRL

Ioctl Number

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

if (ioctl(Acodec_Fd, ACODEC_SOFT_RESET_CTRL))
{
    printf("ioctl reset err!\n");
}

10.3.7.2. ACODEC_SET_INPUT_VOL

【Description】

Total input volume control. Configure the user’s desired gain to the digital gain control register.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_INPUT_VOL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

File Description of Audio Codec Device

Input

ACODEC_SET_INPUT_VOL

Ioctl Number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

  • The input volume ranges from [24 to 0]. If the input value is 0, it is mute.

  • Both left and right channels are in effect during adjustment.

【Example】

CVI_U32 vol = 20;
if (ioctl(Acodec_Fd, ACODEC_SET_INPUT_VOL, &vol))
{
  printf("ioctl err!\n");
}

10.3.7.3. ACODEC_GET_INPUT_VOL

【Description】

Gets the total input volume.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_INPUT_VOL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_GET_INPUT_VOL

Ioctl Number

Input

arg

Unsigned integer pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

  • The input volume ranges from [24 to 0]. If the input value is 0, it is mute.

【Example】

CVI_U32 vol;
if (ioctl(Acodec_Fd, ACODEC_SET_INPUT_VOL, &vol))
{
  printf("ioctl err!\n");
}

10.3.7.4. ACODEC_SET_OUTPUT_VOL

【Description】

Total output volume control. Configure the user’s desired gain to the digital gain control register.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_OUTPUT_VOL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_SET_OUTPUT_VOL

Ioctl Number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

  • The output volume ranges from [32 to 0].

  • Both left and right channels are in effect during adjustment.

【Example】

CVI_U32 vol = 7;
if (ioctl(Acodec_Fd, ACODEC_SET_OUTPUT_VOL, &vol))
{
  printf("ioctl err!\n");
}

10.3.7.5. ACODEC_GET_OUTPUT_VOL

【Description】

Get the total output volume

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_OUTPUT_VOL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_GET_OUTPUT_VOL

Ioctl Number

Input

arg

Unsigned integer pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

The output volume range is [32~0].

【Example】

CVI_U32 vol;
if (ioctl(Acodec_Fd, ACODEC_SET_INPUT_VOL, &vol))
{
  printf("ioctl err!\n");
}

10.3.7.6. ACODEC_SET_GAIN_MICL

【Description】

Analog Gain Control of Left Channel MIC Input

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_GAIN_MICL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_SET_GAIN_MICL

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

  • When using passive audio signal input, it is necessary to appropriately increase the analog gain.

  • The input volume range is [24~0]. The input value 0 represent mute.

【Example】

CVI_U32 gain_mic;
gain_mic = 5;
if (ioctl(Acodec_Fd, ACODEC_SET_GAIN_MICL, &gain_mic))
{
printf("ioctl err!\n");
}

10.3.7.7. ACODEC_SET_GAIN_MICR

【Description】

Analog Gain Control of Right Channel MIC Input

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_GAIN_MICR, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_SET_GAIN_MICR

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files:acodec.h

【Note】

  • When using passive audio signal input, it is necessary to appropriately increase the analog gain.

-The input volume range is [24~0]. The input value 0 represent mute.

【Example】

CVI_U32 gain_mic;
gain_mic = 5;
if (ioctl(Acodec_Fd, ACODEC_SET_GAIN_MICR, &gain_mic))
{
printf("ioctl err!\n");
}

10.3.7.8. ACODEC_SET_DACL_VOL

【Description】

Left channel output volume control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_DACL_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_SET_DACL_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

Output volume ranges from [32 to 0].

If vol_ctrl_ctrl_mute is set to 1, the mute will be enabled.

If vol_ctrl.vol_ctrl_mute is set to 0, the mute will be disabled.

【Example】

struct cvi_vol_ctrl vol_ctrl;
vol_ctrl.vol_ctrl_mute = 0x0;
vol_ctrl.vol_ctrl = 0x05;
if (ioctl(Acodec_Fd, ACODEC_SET_DACL_VOL, &vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.9. ACODEC_SET_DACR_VOL

【Description】

Right channel output volume control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_DACR_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio Codec Device File Description

Input

ACODEC_SET_DACR_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

Output volume ranges from [32 to 0]. If vol_ctrl_ctrl_mute is set to 1, the mute will be enabled. If vol_ctrl.vol_ctrl_mute is set to 0, the mute will be disabled.

【Example】

struct cvi_vol_ctrl vol_ctrl;
vol_ctrl.vol_ctrl_mute = 0x0;
vol_ctrl.vol_ctrl = 0x05;
if (ioctl(Acodec_Fd, ACODEC_SET_DACR_VOL, &vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.10. ACODEC_SET_ADCL_VOL

【Description】

Left channel input volume control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_ADCL_VOL, struct cvi_vol_ctrl *arg);

【Paramters】

Parameter

Description

Input/Output

fd

Audio Codec device file description

Input

ACODEC_SET_ADCL_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files:acodec.h

【Note】

  • When the Input is configured as MIC in, the input volume range is [24~0]. If the value of vol_ctrl.vol_ctrl_mute is 1, it will be muted, and if the value is 0, the mute will be cancelled.

【Example】

struct cvi_vol_ctrl vol_ctrl;
vol_ctrl.vol_ctrl_mute = 0x0;
vol_ctrl.vol_ctrl = 0x05;
if (ioctl(Acodec_Fd, ACODEC_SET_ADCL_VOL, &vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.11. ACODEC_SET_ADCR_VOL

【Description】

Right channel input volume control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_ADCR_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_ADCR_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

  • When the Input is configured as MIC in, the input volume range is [24~0]. If the value of vol_ctrl.vol_ctrl_mute is 1, it will be muted, and if the value is 0, the mute will be cancelled.

【Example】

struct cvi_vol_ctrl vol_ctrl;
vol_ctrl.vol_ctrl_mute = 0x0;
vol_ctrl.vol_ctrl = 0x05;
if (ioctl(Acodec_Fd, ACODEC_SET_ADCR_VOL, &vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.12. ACODEC_SET_MICL_MUTE

【Description】

Left channel MIC input mute control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_MICL_MUTE, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_MICL_MUTE

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

The arg parameter ranges from 0 to 1, where 0 means unmute and 1 means mute.

【Example】

CVI_U32 mic_mute;
mic_mute = 0;
if (ioctl(Acodec_Fd, ACODEC_SET_MICL_MUTE, &mic_mute))
{
printf("ioctl err!\n");
}

10.3.7.13. ACODEC_SET_MICR_MUTE

【Description】

Right channel MIC input mute control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_MICR_MUTE, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_MICR_MUTE

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

The arg parameter ranges from 0 to 1, where 0 means unmute and 1 means mute.

【Example】

CVI_U32 mic_mute;
mic_mute = 0;
if (ioctl(Acodec_Fd, ACODEC_SET_MICR_MUTE, &mic_mute))
{
printf("ioctl err!\n");
}

10.3.7.14. ACODEC_SET_DACL_MUTE

【Description】

Left channel output mute control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_DACL_MUTE, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_DACL_MUTE

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

The arg parameter ranges from 0 to 1, where 0 means unmute and 1 means mute.

【Example】

CVI_U32 mute;
mute = 0;
if (ioctl(Acodec_Fd, ACODEC_SET_DACL_MUTE, &mute))
{
printf("ioctl err!\n");
}

10.3.7.15. ACODEC_SET_DACR_MUTE

【Description】

Right channel output mute control.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_DACR_MUTE, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_DACR_MUTE

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

The arg parameter ranges from 0 to 1, where 0 means unmute and 1 means mute.

【Example】

CVI_U32 mute;
mute = 0;
if (ioctl(Acodec_Fd, ACODEC_SET_DACR_MUTE, &mute))
{
printf("ioctl err!\n");
}

10.3.7.16. ACODEC_GET_GAIN_MICL

【Description】

Get Analog Gain of Left Channel MIC Input

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_GAIN_MICL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_GET_GAIN_MICL

Ioctl number

Input

arg

Unsigned integer pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

CVI_U32 gain_mic;
mute = 0;
if (ioctl(Acodec_Fd, ACODEC_GET_GAIN_MICL, &gain_mic))
{
printf("ioctl err!\n");
}

10.3.7.17. ACODEC_GET_GAIN_MICR

【Description】

Get Analog Gain of Right Channel MIC Input .

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_GAIN_MICR, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_GET_GAIN_MICR

Ioctl number

Input

arg

Unsigned integer pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

CVI_U32 gain_mic;
mute = 0;
if (ioctl(Acodec_Fd, ACODEC_GET_GAIN_MICR, &gain_mic))
{
printf("ioctl err!\n");
}

10.3.7.18. ACODEC_GET_DACL_VOL

【Description】

Get the volume control of the left channel output.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_DACL_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_GET_DACL_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

struct cvi_vol_ctrl vol_ctrl;
if (ioctl(Acodec_Fd, ACODEC_GET_DACL_VOL, & vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.19. ACODEC_GET_DACR_VOL

【Description】

Gets the volume control of the right channel output.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_DACR_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_GET_DACR_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

struct cvi_vol_ctrl vol_ctrl;
if (ioctl(Acodec_Fd, ACODEC_GET_DACR_VOL, & vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.20. ACODEC_GET_ADCL_VOL

【Description】

Gets the volume control of the left channel input.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_ADCL_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_GET_ADCL_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

struct cvi_vol_ctrl vol_ctrl;
if (ioctl(Acodec_Fd, ACODEC_GET_ADCL_VOL, & vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.21. ACODEC_GET_ADCR_VOL

【Description】

Gets the volume control of the right channel input.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_GET_ADCR_VOL, struct cvi_vol_ctrl *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_GET_ADCR_VOL

Ioctl number

Input

arg

cvi_vol_ctrl structure pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

None.

【Example】

struct cvi_vol_ctrl vol_ctrl;
if (ioctl(Acodec_Fd, ACODEC_GET_ADCR_VOL, & vol_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.22. ACODEC_SET_PD_DACL

【Description】

Power-Off Control of Left Channel Output .

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_PD_DACL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_PD_DACL

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

This interface can be called when not using DACL to power down DACL.

The arg parameter ranges from 0 to 1.

0 means power up, and 1 means power down.

【Example】

CVI_U32 pd_ctrl;
pd_ctrl = 0x1;
if (ioctl(Acodec_Fd, ACODEC_SET_PD_DACL, &pd_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.23. ACODEC_SET_PD_DACR

【Description】

Power-Off Control of Right Channel Output .

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_PD_DACR, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_PD_DACR

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

This interface can be called when not using DACL to power down DACL.

The arg parameter ranges from 0 to 1.

0 means power up, and 1 means power down.

【Example】

CVI_U32 pd_ctrl;
pd_ctrl = 0x1;
if (ioctl(Acodec_Fd, ACODEC_SET_PD_DACR, &pd_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.24. ACODEC_SET_PD_ADCL

【Description】

Power-Off Control of Left Channel Input .

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_PD_ADCL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_PD_ADCL

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

This interface can be called when not using DACL to power down DACL.

The arg parameter ranges from 0 to 1.

0 means power up, and 1 means power down.

【Example】

CVI_U32 pd_ctrl;
pd_ctrl = 0x1;
if (ioctl(Acodec_Fd, ACODEC_SET_PD_ADCL, &pd_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.25. ACODEC_SET_PD_ADCR

【Description】

Power-Off Control of Right Channel Input .

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_PD_ADCR, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_PD_ADCR

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

This interface can be called when not using DACL to power down DACL.

The arg parameter ranges from 0 to 1.

0 means power up, and 1 means power down.

【Example】

CVI_U32 pd_ctrl;
pd_ctrl = 0x1;
if (ioctl(Acodec_Fd, ACODEC_SET_PD_ADCR, &pd_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.26. ACODEC_SET_PD_LINEINL

【Description】

Power-Off Control of Left Channel LINEIN input.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_PD_LINEINL, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_PD_LINEINL

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

This interface can be called when not using LINEIN to power down LINEIN.

The arg parameter ranges from 0 to 1.

0 means power up, and 1 means power down.

【Example】

CVI_U32 pd_ctrl;
pd_ctrl = 0x1;
if (ioctl(Acodec_Fd, ACODEC_SET_PD_LINEINL, &pd_ctrl))
{
printf("ioctl err!\n");
}

10.3.7.27. ACODEC_SET_PD_LINEINR

【Description】

Power-Off Control of Right Channel LINEIN input.

【Syntax】

CVI_S32 ioctl (CVI_S32 fd, ACODEC_SET_PD_LINEINR, CVI_U32 *arg);

【Parameter】

Parameter

Description

Input/Output

fd

Audio codec device file description

Input

ACODEC_SET_PD_LINEINR

Ioctl number

Input

arg

Unsigned integer pointer

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: acodec.h

【Note】

This interface can be called when not using LINEIN to power down LINEIN.

The arg parameter ranges from 0 to 1.

0 means power up, and 1 means power down.

【Example】

CVI_U32 pd_ctrl;
pd_ctrl = 0x1;
if (ioctl(Acodec_Fd, ACODEC_SET_PD_LINEINR, &pd_ctrl))
{
printf("ioctl err!\n");
}

10.3.8. Resampling

The Resampler module provides independent resampling processing.

When a client needs to resample data in the upper layer, this module can be used.

The following are related API and detailed description.

10.3.8.1. CVI_Resampler_Create

【Description】

Create a resampling module.

【Syntax】

CVI_VOID *CVI_Resampler_Create(CVI_S32 s32Inrate, CVI_S32 s32Outrate, CVI_S32 s32Chans);

【Parameter】

Parameter

Description

Input/Output

s32Inrate

Input sampling rate.

Value Range: 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000.

Input

s32Outrate

Output sampling rate.

Value Range: 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000.

Input

s32Chans

Number of processing channels (currently Cvitek supports mono channel);

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_resample_api.h

  • Library files: libcvi_audio.a, libcvi_RES1.so

【Note】

The input sampling rate and output sampling rate should be different.

【Example】

None.

10.3.8.2. CVI_Resampler_Process

【Description】

Process one frame of resampled data.

【Syntax】

CVI_S32 CVI_Resampler_Process(CVI_VOID *inst, CVI_S16 *s16Inbuf, CVI_S32 s32Insamps, CVI_S16 *s16Outbuf);

【Parameter】

Parameter

Description

Input/Output

inst

Resample module handle.

Input

s16Inbuf

Input data buf pointer.

Input

s32Insamps

Number of input sample points.

Value Range: [0, 2048].

Input

s16Outbuf

Output data buf pointer

Output

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_resample_api.h

  • Library files: libcvi_audio.a, libcvi_RES1.so

【Note】

The maximum number of input sample points should be less than 2048.

【Example】

None.

10.3.8.3. CVI_Resampler_Destroy

【Description】

Destroy a resampling module instance.

【Syntax】

CVI_VOID CVI_Resampler_Destroy(CVI_VOID *inst);

【Parameter】

Parameter

Description

Input/Output

inst

Resampling module handle.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_resample_api.h

  • Library files: libcvi_audio.a, libcvi_RES1.so

【Note】

None.

【Example】

None.

10.3.8.4. CVI_Resampler_GetMaxOutputNum

【Description】

Get the maximum number of output sample points (per channel).

【Syntax】

CVI_S32 CVI_Resampler_GetMaxOutputNum(CVI_VOID *inst, CVI_S32 s32Insamps);

【Parameter】

Parameter

Description

Input/Output

inst

Resampling module handle.

Input

s32Insamps

Input sampling points for each channel.

Input

【Return Value】

Return Value

Description

0

Success.

Non 0

Failure. For details, please refer to Error Codes.

【Requirement】

  • Header files: cvi_comm_aio.h, cvi_audio.h、cvi_resample_api.h

  • Library files: libcvi_audio.a, libcvi_RES1.so

【Note】

None.

【Example】

None.