xref: /OK3568_Linux_fs/external/rockit/mpi/example/common/test_comm_ao.cpp (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright 2021 Rockchip Electronics Co. LTD
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun  * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun  * You may obtain a copy of the License at
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun  * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun  * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun  * limitations under the License.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include "rk_mpi_ao.h"
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun #include "rk_debug.h"
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #ifdef __cplusplus
22*4882a593Smuzhiyun #if __cplusplus
23*4882a593Smuzhiyun extern "C" {
24*4882a593Smuzhiyun #endif
25*4882a593Smuzhiyun #endif /* End of #ifdef __cplusplus */
26*4882a593Smuzhiyun 
TEST_AO_Start(AUDIO_DEV AoDev,AIO_ATTR_S * pstAoAttr,RK_U32 u32ChnCnt,AUDIO_SAMPLE_RATE_E * pEnSmpRates)27*4882a593Smuzhiyun RK_S32 TEST_AO_Start(AUDIO_DEV AoDev, AIO_ATTR_S *pstAoAttr, RK_U32 u32ChnCnt, AUDIO_SAMPLE_RATE_E *pEnSmpRates) {
28*4882a593Smuzhiyun     RK_S32 s32Ret = RK_SUCCESS;
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun     s32Ret = RK_MPI_AO_SetPubAttr(AoDev, pstAoAttr);
31*4882a593Smuzhiyun     if (s32Ret != RK_SUCCESS) {
32*4882a593Smuzhiyun         RK_LOGE("failed with 0x%x!", s32Ret);
33*4882a593Smuzhiyun         return s32Ret;
34*4882a593Smuzhiyun     }
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun     s32Ret = RK_MPI_AO_Enable(AoDev);
37*4882a593Smuzhiyun     if (s32Ret != RK_SUCCESS) {
38*4882a593Smuzhiyun         RK_LOGE("failed with 0x%x!", s32Ret);
39*4882a593Smuzhiyun         return s32Ret;
40*4882a593Smuzhiyun     }
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun     for (RK_S32 i = 0; i < u32ChnCnt; i++) {
43*4882a593Smuzhiyun         s32Ret =  RK_MPI_AO_EnableChn(AoDev, i);
44*4882a593Smuzhiyun         if (s32Ret != RK_SUCCESS) {
45*4882a593Smuzhiyun             RK_LOGE("failed with 0x%x!", s32Ret);
46*4882a593Smuzhiyun             return s32Ret;
47*4882a593Smuzhiyun         }
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun         // set sample rate of input data
50*4882a593Smuzhiyun         s32Ret = RK_MPI_AO_EnableReSmp(AoDev, i, pEnSmpRates[i]);
51*4882a593Smuzhiyun         if (s32Ret != RK_SUCCESS) {
52*4882a593Smuzhiyun             RK_LOGE("failed with 0x%x!", s32Ret);
53*4882a593Smuzhiyun             return s32Ret;
54*4882a593Smuzhiyun         }
55*4882a593Smuzhiyun     }
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun     return RK_SUCCESS;
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun 
TEST_AO_Stop(AUDIO_DEV aoDevId,RK_U32 u32ChnCnt)60*4882a593Smuzhiyun RK_S32 TEST_AO_Stop(AUDIO_DEV aoDevId, RK_U32 u32ChnCnt) {
61*4882a593Smuzhiyun     RK_S32 s32Ret = RK_SUCCESS;
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun     for (RK_S32 i = 0; i < u32ChnCnt; i++) {
64*4882a593Smuzhiyun         s32Ret = RK_MPI_AO_DisableReSmp(aoDevId, i);
65*4882a593Smuzhiyun         if (s32Ret != RK_SUCCESS) {
66*4882a593Smuzhiyun             RK_LOGE("failed with 0x%x!", s32Ret);
67*4882a593Smuzhiyun             return RK_FAILURE;
68*4882a593Smuzhiyun         }
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun         s32Ret = RK_MPI_AO_DisableChn(aoDevId, i);
71*4882a593Smuzhiyun         if (s32Ret != RK_SUCCESS) {
72*4882a593Smuzhiyun             RK_LOGE("failed with 0x%x!", s32Ret);
73*4882a593Smuzhiyun             return RK_FAILURE;
74*4882a593Smuzhiyun         }
75*4882a593Smuzhiyun     }
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun     s32Ret =  RK_MPI_AO_Disable(aoDevId);
78*4882a593Smuzhiyun     if (s32Ret != RK_SUCCESS) {
79*4882a593Smuzhiyun         RK_LOGE("failed with 0x%x!", s32Ret);
80*4882a593Smuzhiyun         return RK_FAILURE;
81*4882a593Smuzhiyun     }
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun     return RK_SUCCESS;
84*4882a593Smuzhiyun }
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #ifdef __cplusplus
87*4882a593Smuzhiyun #if __cplusplus
88*4882a593Smuzhiyun }
89*4882a593Smuzhiyun #endif
90*4882a593Smuzhiyun #endif /* End of #ifdef __cplusplus */
91*4882a593Smuzhiyun 
92