xref: /utopia/UTPA2-700.0.x/modules/audio/api/audio/apiAUDIO.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2008-2009 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94 
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file    apiAUDIO.c
98 /// @brief  audio API functions
99 /// @author MStar Semiconductor Inc.
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101 
102 
103 //-------------------------------------------------------------------------------------------------
104 //  Include Files
105 //-------------------------------------------------------------------------------------------------
106 #ifdef MSOS_TYPE_LINUX_KERNEL
107 #include <linux/string.h>
108 #include <linux/slab.h>
109 #include <linux/delay.h>
110 #include <linux/sched.h>
111 #include <linux/kthread.h>
112 #include <linux/jiffies.h>
113 #else
114 #include <string.h>
115 #endif
116 
117 #include "ULog.h"
118 
119 #include "MsCommon.h"
120 #include "MsIRQ.h"
121 #include "MsOS.h"
122 #include "drvAUDIO_if.h"
123 #include "apiAUDIO.h"
124 #include "apiAUDIO_private.h"
125 #include "drvAUDIO.h"
126 #include "utopia_dapi.h"
127 
128 #include "../drv/audio/internal/drvKTV.h"
129 #include "../drv/audio/internal/drvSIF.h"
130 #include "../drv/audio/internal/drvMAD.h"
131 #include "../drv/audio/internal/drvMAD2.h"
132 #include "../drv/audio/internal/drvSOUND.h"
133 #include "../drv/audio/internal/drvADVSOUND.h"
134 #include "../drv/audio/internal/drvAUDIO_internal.h"
135 #include "../drv/audio/internal/drvAudio_Common.h"
136 #include "drvWDT.h" //Refine power on sequence for earphone & DAC pop noise issue
137 
138 
139 
140 //-------------------------------------------------------------------------------------------------
141 //  Local Compiler Options
142 //-------------------------------------------------------------------------------------------------
143 
144 //-------------------------------------------------------------------------------------------------
145 //  Local Defines
146 //-------------------------------------------------------------------------------------------------
147 #define APIAUDIO_CHECK_SHM_INIT \
148     do { \
149         if (g_AudioVars2 == NULL) \
150         { \
151             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Warning! g_AudioVars2 should not be NULL !!!\n", __FUNCTION__); \
152             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Perform SHM Init here !!!\n", __FUNCTION__); \
153             if (MDrv_AUDIO_SHM_Init() == FALSE) \
154             { \
155                 MS_ASSERT(0); \
156             } \
157         } \
158     } while(0)
159 
160 /*
161  * AEON(MM) and MCU use independent memory space,
162  * so they can not use the same flag
163  */
164 #if defined(MCU_AEON) && !defined(__AEONR2__)
165     /* AEON(MM) */
166     #define APIAUDIO_CHECK_INIT_FLAG(bRet) \
167         do{ \
168             bRet = TRUE; \
169         }while(0)
170 #else
171     /* ARM, MIPS, and AEON_R2(NOS_MCU) */
172     #define APIAUDIO_CHECK_INIT_FLAG(bRet) \
173         do{ \
174             bRet = MDrv_AUDIO_GET_INIT_FLAG(); \
175             if (bRet == FALSE) \
176             { \
177                 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Audio system is not ready yet, please try again later\n", __FUNCTION__); \
178             } \
179         }while(0)
180 #endif
181 
182 #define HINIBBLE(u8Data)    ((u8Data) >> 4)
183 #define LONIBBLE(u8Data)    ((u8Data) << 4)
184 
185 //-------------------------------------------------------------------------------------------------
186 //  Local Structures
187 //-------------------------------------------------------------------------------------------------
188 
189 
190 //------------------------------------------------------------------------------
191 // Local Functions Prototype
192 //------------------------------------------------------------------------------
193 
194 
195 //-------------------------------------------------------------------------------------------------
196 //  Extern Variables
197 //-------------------------------------------------------------------------------------------------
198 extern MS_BOOL g_bDSPLoadCode;
199 extern AUDIO_SHARED_VARS2 * g_AudioVars2;
200 extern MS_S32 _s32AUDIOMutex;
201 extern MS_U8 CheckPlayDoneCnt;
202 
203 //-------------------------------------------------------------------------------------------------
204 //  Local Variables
205 //-------------------------------------------------------------------------------------------------
206 AUDIO_SPDIF_OUTPUT_TYPE     gSpdifOutputType;
207 HDMI_TX_OUTPUT_TYPE         gHdmiOutputType;
208 AUDIOSTATUS                 m_eSifStatus;
209 AUDIOSTANDARD_TYPE          m_eSifStandard;
210 MS_U8                       SpeakerMaxVolume = 0x0C; //(MS_U8)(TvVolumeTable[100]>>8);
211 MS_U8                       DynamicAvl_active_volume = 0x17; // about -12dB for 2Vrms input, value of volume control register
212 
213 static En_DVB_advsndType    u8CurrAdvSndSys = MSAPI_AUD_ADVSND_NONE;
214 static En_DVB_decCmdType    enDecoderStatus;
215 static MS_U8                u8IntTag = 1;
216 MS_U32 g_audioDumpInfo_interval = 500;
217 
218 En_DVB_decSystemType        enCurDecSystem, enCurDecSystem2;
219 
220 
221 static OUTPUT_SOURCE_INFO OutSourceInitSettings=
222 {
223     E_CONNECT_MAIN,  // For Speaker
224     E_CONNECT_MAIN,  // For HP
225     E_CONNECT_MAIN,  // For Monitor out
226     E_CONNECT_SCART,  // For Scart out
227     E_CONNECT_MAIN,  // For Spdif out
228     E_CONNECT_MAIN,   // For HDMI ARC
229     E_CONNECT_MAIN   // For HDMI Tx
230 };
231 
232 Audio_MBOX_BackUp_t MBOXBkUp[] ={{0x112D00, 8, {0}},
233                                                         {0x112D10, 8, {0}},
234                                                         {0x112D20, 8, {0}},
235                                                         {0x112D30, 8, {0}},
236                                                         {0x112D40, 8, {0}},
237                                                         {0x112D50, 8, {0}},
238                                                         {0x112D80, 8, {0}},
239                                                         {0x112D90, 8, {0}},
240                                                         {0x112DC0, 8, {0}},
241                                                         {0x112DD0, 8, {0}},
242                                                         {0x112C60, 8, {0}},
243                                                         //{0x112CE0, 8, {0}},
244                                                         {0x112E20, 4, {0}},
245                                                         {0x112E80, 8, {0}},
246                                                         {0x112E90, 8, {0}},
247                                                         {0x160380, 8, {0}},
248                                                         {0x160390, 4, {0}},
249                                                          /* Add above only, the last one must be null. */
250                                                         {0,             0, {0},}
251                                                         };
252 
253 //-------------------------------------------------------------------------------------------------
254 //  Debug Functions
255 //-------------------------------------------------------------------------------------------------
256 
257 //-------------------------------------------------------------------------------------------------
258 //  Local Functions
259 //-------------------------------------------------------------------------------------------------
260 
_ApiDecCmd_To_DrvDecCmd(En_DVB_decCmdType enDecComamnd,AU_DVB_DECCMD * u8DecCmd)261 static void _ApiDecCmd_To_DrvDecCmd(En_DVB_decCmdType enDecComamnd, AU_DVB_DECCMD *u8DecCmd)
262 {
263     switch(enDecComamnd)
264     {
265         case MSAPI_AUD_DVB_DECCMD_STOP:
266             *u8DecCmd = AU_DVB_DECCMD_STOP;
267             break;
268 
269         case MSAPI_AUD_DVB_DECCMD_PLAY:
270             *u8DecCmd = AU_DVB_DECCMD_PLAY;
271             break;
272 
273         case MSAPI_AUD_DVB_DECCMD_RESYNC:
274             *u8DecCmd = AU_DVB_DECCMD_RESYNC;
275             break;
276 
277         case MSAPI_AUD_DVB_DECCMD_FREE_RUN:
278             *u8DecCmd = AU_DVB_DECCMD_FREERUN;
279             break;
280 
281         case MSAPI_AUD_DVB_DECCMD_AVSYNC:
282             *u8DecCmd = AU_DVB_DECCMD_AVSYNC;
283             break;
284 
285         case MSAPI_AUD_DVB_DECCMD_PLAYFILE:
286              *u8DecCmd = AU_DVB_DECCMD_PLAYFILE;
287             break;
288 
289         case MSAPI_AUD_DVB_DECCMD_PAUSE:
290             *u8DecCmd = AU_DVB_DECCMD_PAUSE;
291             break;
292 
293         case MSAPI_AUD_DVB_DECCMD_PLAYFILETSP:
294             *u8DecCmd = AU_DVB_DECCMD_PLAYFILETSP;
295             break;
296 
297         case MSAPI_AUD_DVB_DECCMD_STARTBROWSE:
298             *u8DecCmd = AU_DVB_DECCMD_STARTBROWSE;
299             break;
300 
301         case MSAPI_AUD_DVB_DECCMD_PLAYFRAME:
302             *u8DecCmd = AU_DVB_DECCMD_PLAYFRAME;
303             break;
304 
305         case MSAPI_AUD_DVB_DECCMD_PLAYFRAME_STAGE:
306             *u8DecCmd = AU_DVB_DECCMD_PLAYFRAME_STAGE;
307             break;
308 
309         case MSAPI_AUD_DVB_DECCMD_PLAYFRAME_GS:
310             *u8DecCmd = AU_DVB_DECCMD_PLAYFRAME_GS;
311             break;
312 
313         case MSAPI_AUD_DVB_DECCMD_PLAYMM_FILE2:
314             *u8DecCmd = AU_DVB_DECCMD_PLAYFILE2_PTS;
315             break;
316 
317         case MSAPI_AUD_DVB_DECCMD_PLAY_AD:
318             *u8DecCmd = AU_DVB_DECCMD_PLAY_AD;
319             break;
320 
321         case MSAPI_AUD_DVB_DECCMD_STOP_AD:
322             *u8DecCmd = AU_DVB_DECCMD_STOP_AD;
323             break;
324 
325         case MSAPI_AUD_DVB_DECCMD_SKIP:
326             *u8DecCmd = AU_DVB_DECCMD_SKIP;
327             break;
328 
329         default:
330             // Need refine
331             *u8DecCmd = AU_DVB_DECCMD_STOP;
332             break;
333     }
334     return;
335 }
336 
337 //-------------------------------------------------------------------------------------------------
338 //  Global Functions
339 //-------------------------------------------------------------------------------------------------
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 //
343 //         AUDIO_SYSTEM RELATIONAL API FUNCTION
344 //
345 ////////////////////////////////////////////////////////////////////////////////
346 
347 ////////////////////////////////////////////////////////////////////////////////
348 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_RX_GetHdmiInAudioStatus()
349 /// @brief \b Function \b Description:  Return audio status.
350 /// @return MS_U16     \b : return structure which include pcm, non pcm, sampling rate.
351 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_RX_GetHdmiInAudioStatus(ST_HDMI_AUDIO_STATUS * p_hdmiAudioSts)352 MS_BOOL _MApi_AUDIO_HDMI_RX_GetHdmiInAudioStatus( ST_HDMI_AUDIO_STATUS *p_hdmiAudioSts)
353 {
354     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
355     return(MDrv_AUDIO_HDMI_RX_GetHdmiInAudioStatus(p_hdmiAudioSts));
356 }
357 
358 ////////////////////////////////////////////////////////////////////////////////
359 /// @brief \b Function \b Name: MApi_AUDIO_SetPowerOn()
360 /// @brief \b Function \b Description: This routine is used to execute DSP power on/down setting.
361 /// @param bFlag       \b : TRUE --power on;
362 ///                         FALSE--power off
363 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetPowerOn(MS_BOOL bFlag)364 void _MApi_AUDIO_SetPowerOn(MS_BOOL bFlag)
365 {
366     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
367     MDrv_AUDIO_SetPowerOn(bFlag);
368 }
369 
370 ////////////////////////////////////////////////////////////////////////////////
371 /// @brief \b Function \b Name: MApi_AUD_Initialize()
372 /// @brief \b Function \b Description: Audio initialize function incluing DSP power on and load code.
373 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_Initialize(void)374 void _MApi_AUDIO_Initialize(void)
375 {
376     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
377 
378     if (MDrv_AUDIO_SHM_Init() == FALSE)
379     {
380         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "MApi_AUDIO_Initialize failes to get SHM buffer\n");
381         return;
382     }
383 
384     if (MDrv_AUDIO_Mutex_Init() == FALSE)
385     {
386         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : fails to init Audio Mutex\n", __FUNCTION__);
387         return;
388     }
389 
390     APIAUDIO_CHECK_SHM_INIT;
391 
392     //Init common PCM I/O
393     MDrv_AUDIO_PCM_Init();
394 
395     OS_OBTAIN_MUTEX(_s32AUDIOMutex, MSOS_WAIT_FOREVER);
396 
397     if (MDrv_AUDIO_GET_INIT_FLAG() == TRUE)
398     {
399         /* Patch for multi-process, some audio utopia call back function did not register */
400         /* so if share memory have already init, check call back function again,          */
401         /* if call back function is NULL, register it !!                                  */
402         MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_Set_CallBackFunc, 0, 0);
403 
404         /* Patch for multi-process, MMIO Base address need to setup for different process */
405         MDrv_AUDIO_Init();
406 
407         OS_RELEASE_MUTEX(_s32AUDIOMutex);
408 
409         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "MApi_AUDIO_Initialize doesn't need to init again\n");
410         return;
411     }
412 
413     g_AudioVars2->eAudioSource = E_AUDIO_INFO_ADC_IN;
414     g_AudioVars2->g_R2ShmInitFlag = FALSE;
415 
416     memcpy(&(g_AudioVars2->AudioOutputSourceInfo), &OutSourceInitSettings, sizeof(g_AudioVars2->AudioOutputSourceInfo));
417     MDrv_AUDIO_Init();
418     MsOS_DelayTask(10);    //Refine power on sequence for earphone & DAC pop noise issue
419 
420     MDrv_AUDIO_WriteInitTable();
421 
422     MDrv_AUDIO_SetPowerOn(TRUE);
423 
424     MDrv_MAD_SetMemInfo();
425     MDrv_MAD2_SetMemInfo();
426 
427     // Load DSP DEC Code
428     MDrv_SIF_Init();
429     MDrv_SOUND_Init();
430 
431     // Load SIF DSP code stage
432     MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_STOP);
433 
434     MDrv_MAD_Init();
435 
436     MDrv_AUDIO_DecoderLoadCode();  // Load decoder main code
437 
438     MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_FS, SPDIF_CS_FS_48K);
439 
440     if (g_AudioVars2->AudioSystemInfo.dtv_system == AUDIO_DTV_DVB)
441         MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_DVB);
442     else if (g_AudioVars2->AudioSystemInfo.dtv_system == AUDIO_DTV_ATSC)
443         MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_ATSC);
444     else if (g_AudioVars2->AudioSystemInfo.dtv_system == AUDIO_DTV_ISDB)
445         MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_ISDB);
446     else
447         MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_NONE);
448 
449     MDrv_AUDIO_SetAC3PInfo(Audio_AC3P_infoType_LoudnessMatching, (MS_U32)g_AudioVars2->g_dolbyLoudness_Enable, (MS_U32)g_AudioVars2->AudioSystemInfo.dtv_system);
450 
451    // MApi_AUDIO_SetAdvSndSys(MSAPI_AUD_ADVSND_SRS);
452 
453     if ( g_AudioVars2->AudioPathInfo.HpOut != AUDIO_PATH_NULL )
454     {
455         MDrv_AUDIO_SetInputPath(AUDIO_SRC_INPUT, g_AudioVars2->AudioPathInfo.HpOut);
456     }
457 
458     MDrv_SOUND_EnableBalance(TRUE);   // Enable Speaker Balance function in audio init .
459     //MApi_AUDIO_SetEncInit(AU_DVB_ENCBR_192K, 16);
460 
461     //Refine power on sequence for earphone & DAC pop noise issue
462     MDrv_AUDIO_EnaEarphone_LowPower_Stage();
463 
464 //================================================
465 //  Execute Output Path connection
466 //================================================
467      _MApi_AUDIO_SetOutConnectivity();
468 //================================================
469 
470     //Attach audio interrupts for DEC/SND DSP to MCU
471     MDrv_AUDIO_AttachInterrupt(TRUE);
472 
473     //Rise init flag
474     MDrv_AUDIO_SET_INIT_FLAG(TRUE);
475 
476     OS_RELEASE_MUTEX(_s32AUDIOMutex);
477 
478 }
479 
480 
481 ////////////////////////////////////////////////////////////////////////////////
482 /// @brief \b Function \b Name: MApi_AUDIO_SIF_Shift()
483 /// @brief \b Function \b Description: This function is used to provide a API for application to choose what kind of VIF mdoe.
484 ///
485 ////////////////////////////////////////////////////////////////////////////////
486 
_MApi_AUDIO_SIF_Shift(En_AUD_VIF_Type type)487 void _MApi_AUDIO_SIF_Shift(En_AUD_VIF_Type type)
488 {
489     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
490 
491     if(MDrv_SIF_SendCmd(AU_SIF_CMD_GET_VIF_PATCH_ENABLE, NULL, NULL) == 0)
492     {
493         return;
494     }
495 
496     switch (type)
497     {
498         case MSAPI_AUD_SIF_42M:
499             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_SIF_SHIFT_CLK, 0x00, NULL);
500             break;
501 
502         case MSAPI_AUD_SIF_43M:
503             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_SIF_SHIFT_CLK, 0x01, NULL);
504             break;
505 
506         case MSAPI_AUD_SIF_44M:
507             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_SIF_SHIFT_CLK, 0x02, NULL);
508             break;
509 
510         default:
511             break;
512     }
513 }
514 
515 ////////////////////////////////////////////////////////////////////////////////
516 /// @brief \b Function \b Name: MApi_Audio_Monitor()
517 /// @brief \b Function \b Description: This function is used to monitor DSP while-loop and ISR running counter.
518 ///                                  If these counters stop longer than a certain period of time in any abnormal condition, DSP reboot will be launched to alive DSP process again.
519 ////////////////////////////////////////////////////////////////////////////////
_MApi_Audio_Monitor(void)520 void _MApi_Audio_Monitor(void)
521 {
522     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
523 
524     MS_BOOL bRet = FALSE;
525     MS_BOOL bRecoveryOn = FALSE;
526     MS_U8 u8CurrentSeWhile = 0;
527     MS_U8 u8CurrentSeISR = 0;
528     MS_U8 u8CurrentDecR2While = 0;
529     MS_U8 u8CurrentDecR2Timer = 0;
530     MS_U8 u8CurrentSndR2While = 0;
531     MS_U8 u8CurrentSndR2Timer = 0;
532     MS_U32 u32Delay_Counter = 0;
533     MS_BOOL bASND_R2_SUPPORT = MDrv_AUDIO_Check_AsndR2_SupportStatus();
534 
535     static MS_U8  u8LastSeWhile = 1;
536     static MS_U8  u8LastSeISR = 1;
537     static MS_U8  u8LastDecR2While = 1;
538     static MS_U8  u8LastDecR2Timer = 1;
539     static MS_U8  u8LastSndR2While = 1;
540     static MS_U8  u8LastSndR2Timer = 1;
541     static MS_U8  u8SeWhileFailCount = 0;
542     static MS_U8  u8SeISRFailCount = 0;
543     static MS_U8  u8DecR2WhileFailCount = 0;
544     static MS_U8  u8DecR2TimerFailCount = 0;
545     static MS_U8  u8SndR2WhileFailCount = 0;
546     static MS_U8  u8SndR2TimerFailCount = 0;
547     static MS_U32 Waittime = 0;
548     static MS_U32 Waittime2 = 0;
549 
550     APIAUDIO_CHECK_INIT_FLAG(bRet);
551     if (bRet == FALSE)
552     {
553         return;
554     }
555 
556     APIAUDIO_CHECK_SHM_INIT;
557 
558     MDrv_AUDIO_SPDIF_Monitor_SamplingRate();    // used in U4 for SPDIF raw out ADC clock setting
559 
560     if ( MsOS_Timer_DiffTimeFromNow(Waittime2) > g_audioDumpInfo_interval)
561     {
562         Waittime2 = MsOS_GetSystemTime();
563         MDrv_AUDIO_DumpDspInfo();
564     }
565 
566     if (MsOS_Timer_DiffTimeFromNow(Waittime) < 100)
567     {
568         return;
569     }
570 
571     if (g_bDSPLoadCode== TRUE)
572     {
573         return;
574     }
575 
576     Waittime = MsOS_GetSystemTime();
577 
578     if((u8SeWhileFailCount >= 7) || (u8SeISRFailCount >= 7)||(u8SndR2WhileFailCount>=7)||(u8SndR2TimerFailCount>=7))
579     {
580         u32Delay_Counter = u8LastSndR2While + u8LastSndR2Timer + u8LastSeWhile + u8LastSeISR;
581         MsOS_DelayTaskUs(u32Delay_Counter);
582     }
583 
584     u8CurrentSeWhile = MDrv_AUDIO_ReadDspCounter(DSP_SE_MAIN_COUNTER);
585     u8CurrentSeISR = MDrv_AUDIO_ReadDspCounter(DSP_SE_ISR_COUNTER);
586     u8CurrentDecR2While = MDrv_AUDIO_ReadDspCounter(DEC_R2_MAIN_COUNTER);
587     u8CurrentDecR2Timer = MDrv_AUDIO_ReadDspCounter(DEC_R2_TIMER_COUNTER);
588     u8CurrentSndR2While =  MDrv_AUDIO_ReadDspCounter(SND_R2_MAIN_COUNTER);
589     u8CurrentSndR2Timer = MDrv_AUDIO_ReadDspCounter(SND_R2_TIMER_COUNTER);
590 
591 
592     // Checking Decoder DSP counter
593     if ( u8CurrentSeWhile == u8LastSeWhile )
594     {
595         u8SeWhileFailCount++;
596     }
597     else
598     {
599         u8SeWhileFailCount = 0;
600     }
601 
602     if ( u8CurrentSeISR == u8LastSeISR )
603     {
604         u8SeISRFailCount++;
605     }
606     else
607     {
608         u8SeISRFailCount = 0;
609     }
610 
611     if ( u8CurrentDecR2While == u8LastDecR2While)
612     {
613         u8DecR2WhileFailCount++;
614     }
615     else
616     {
617         u8DecR2WhileFailCount = 0;
618     }
619 
620     if ( u8CurrentDecR2Timer == u8LastDecR2Timer)
621     {
622         u8DecR2TimerFailCount++;
623     }
624     else
625     {
626         u8DecR2TimerFailCount = 0;
627     }
628 
629     if ( u8CurrentSndR2While == u8LastSndR2While)
630     {
631         u8SndR2WhileFailCount++;
632     }
633     else
634     {
635         u8SndR2WhileFailCount = 0;
636     }
637 
638     if ( u8CurrentSndR2Timer == u8LastSndR2Timer)
639     {
640         u8SndR2TimerFailCount++;
641     }
642     else
643     {
644         u8SndR2TimerFailCount = 0;
645     }
646 
647     if(((u8SeWhileFailCount+u8SeISRFailCount)==3)||((u8SndR2WhileFailCount+u8SndR2TimerFailCount)==3))
648     {
649         MsOS_DelayTask(1);    //Fix counter mis-detection problem
650     }
651     else if(((u8SeWhileFailCount+u8SeISRFailCount)==7)||((u8SndR2WhileFailCount+u8SndR2TimerFailCount)==7))
652     {
653         MsOS_DelayTask(1);
654     }
655 
656     if ( (u8SeWhileFailCount >= 10) || (u8SeISRFailCount >= 10) )//Checking if rebooting SE DSP
657     {
658         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "u8SeWhileFailCount = %x\n",(MS_U16)u8SeWhileFailCount);
659         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "u8SeISRFailCount = %x\n",(MS_U16)u8SeISRFailCount);
660 
661         bRecoveryOn = TRUE;
662 
663         u8SeWhileFailCount = 0;
664         u8SeISRFailCount = 0;
665         u8DecR2WhileFailCount = 0;
666         u8DecR2TimerFailCount = 0;
667         u8SndR2WhileFailCount = 0;
668         u8SndR2TimerFailCount = 0;
669 
670         MDrv_AUDIO_DspReboot(0);
671 
672         if (!MDrv_AUDIO_IsDTV())
673         {
674             //msAPI_AuWriteSIFThresholdTbl();
675         }
676     }
677     else if ((u8DecR2WhileFailCount>=10)||(u8DecR2TimerFailCount>=10))//Checking if rebooting Decoder R2
678     {
679         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "u8DecR2WhileFailCount = %x\n",(MS_U16)u8DecR2WhileFailCount);
680         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "u8DecR2TimerFailCount = %x\n",(MS_U16)u8DecR2TimerFailCount);
681 
682         bRecoveryOn = TRUE;
683 
684         u8SeWhileFailCount = 0;
685         u8SeISRFailCount = 0;
686         u8DecR2WhileFailCount = 0;
687         u8DecR2TimerFailCount = 0;
688         u8SndR2WhileFailCount = 0;
689         u8SndR2TimerFailCount = 0;
690 
691         MDrv_AUDIO_DspReboot(0);
692 
693         if (!MDrv_AUDIO_IsDTV())
694         {
695             //msAPI_AuWriteSIFThresholdTbl();
696         }
697     }
698     else if ((bASND_R2_SUPPORT) &&
699         ((u8SndR2WhileFailCount>=10)||(u8SndR2TimerFailCount>=10)))//Checking if rebooting SE R2
700     {
701         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "u8SndR2WhileFailCount = %x\n",(MS_U16)u8SndR2WhileFailCount);
702         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "u8SndR2TimerFailCount = %x\n",(MS_U16)u8SndR2TimerFailCount);
703 
704         bRecoveryOn = TRUE;
705 
706         u8SeWhileFailCount = 0;
707         u8SeISRFailCount = 0;
708         u8DecR2WhileFailCount = 0;
709         u8DecR2TimerFailCount = 0;
710         u8SndR2WhileFailCount = 0;
711         u8SndR2TimerFailCount = 0;
712 
713         MDrv_AUDIO_DspReboot(0);
714 
715         if(!MDrv_AUDIO_IsDTV())
716         {
717             //msAPI_AuWriteSIFThresholdTbl();
718         }
719     }
720 
721     if (bRecoveryOn == TRUE)
722     {
723         MS_S32 s32DeviceId = 0;
724 
725         // check which PCM device is inused, then re-open it due to DSP is just reset
726         for (s32DeviceId = 0; s32DeviceId < AUDIO_PCM_MAXNUM; s32DeviceId++)
727         {
728             if (g_AudioVars2->g_PcmInfo[s32DeviceId].u8ConnectFlag == TRUE)
729             {
730                 AUDIO_PCM_INFO_t sPcmInfoTmp;
731 
732                 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Warning! Re-Open PCM device (%d) due to DSP is just reset!\n", s32DeviceId);
733 
734                 memset(&sPcmInfoTmp, 0x00, sizeof(AUDIO_PCM_INFO_t));
735                 sPcmInfoTmp.u32StructVersion = AUDIO_PCM_INFO_VERSION;
736                 sPcmInfoTmp.u32StructSize = sizeof(AUDIO_PCM_INFO_t);
737                 MDrv_AUDIO_PCM_Get(s32DeviceId, AUDIO_PCM_CMD_ALL, &sPcmInfoTmp);
738                 MDrv_AUDIO_PCM_Close(s32DeviceId);
739                 MDrv_AUDIO_PCM_Open(&sPcmInfoTmp);
740             }
741         }
742     }
743 
744     // save status
745     u8LastSeWhile = u8CurrentSeWhile;
746     u8LastSeISR = u8CurrentSeISR;
747     u8LastDecR2While = u8CurrentDecR2While;
748     u8LastDecR2Timer = u8CurrentDecR2Timer;
749     u8LastSndR2While = u8CurrentSndR2While;
750     u8LastSndR2Timer = u8CurrentSndR2Timer;
751 }
752 
753 ////////////////////////////////////////////////////////////////////////////////
754 /// @brief \b Function \b Name: MApi_AUDIO_SetOutConnectivity()
755 /// @brief \b Function \b Description:  Set the TV output connectivity information from APP layer
756 ///                                                   to audio driver .  Then audio driver will set the audio output
757 ///                                                   port with these information automatically.
758 ///////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetOutConnectivity(void)759 void _MApi_AUDIO_SetOutConnectivity(void)
760 {
761     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
762 
763     AUDIO_PATH_GROUP_TYPE Audio_pathgroup_status;
764     MS_BOOL bRet = FALSE;
765 
766     APIAUDIO_CHECK_SHM_INIT;
767 
768     APIAUDIO_CHECK_INIT_FLAG(bRet);
769     if (bRet == FALSE)
770     {
771         return;
772     }
773 
774     Audio_pathgroup_status = MDrv_AUDIO_GetPathGroup();
775 
776     if (Audio_pathgroup_status == AUDIO_PATH_GROUP_1)
777     {   // used in U3, T2, T4, Janus,
778         if ( g_AudioVars2->AudioOutputInfo.SpeakerOut==AUDIO_I2S_OUTPUT )   // I2S Amp.
779         {
780             MDrv_AUDIO_SetOutputPath(AUDIO_PATH_MAIN, AUDIO_I2S_OUTPUT);
781         }
782         else                                                                               // Analog Amp
783         {
784             MDrv_AUDIO_SetOutputPath(g_AudioVars2->AudioPathInfo.SpeakerOut, g_AudioVars2->AudioOutputInfo.SpeakerOut);
785             MDrv_AUDIO_SetInputPath(AUDIO_SRC_INPUT, AUDIO_PATH_0);
786         }
787 
788         if ( g_AudioVars2->AudioOutputInfo.HpOut != AUDIO_NULL_OUTPUT )
789         {
790             MDrv_AUDIO_SetOutputPath(g_AudioVars2->AudioPathInfo.HpOut, g_AudioVars2->AudioOutputInfo.HpOut);
791         }
792 
793         if ( g_AudioVars2->AudioOutputInfo.MonitorOut != AUDIO_NULL_OUTPUT )
794         {
795             MDrv_AUDIO_SetOutputPath(g_AudioVars2->AudioPathInfo.MonitorOut, g_AudioVars2->AudioOutputInfo.MonitorOut);
796         }
797 
798         if ( g_AudioVars2->AudioOutputInfo.ScartOut != AUDIO_NULL_OUTPUT )
799         {
800             MDrv_AUDIO_SetOutputPath(g_AudioVars2->AudioPathInfo.ScartOut, g_AudioVars2->AudioOutputInfo.ScartOut);
801         }
802         MDrv_AUDIO_SetOutputPath(g_AudioVars2->AudioPathInfo.SpdifOut, AUDIO_SPDIF_OUTPUT);
803     }
804     else
805     {   // used in U4, T3, T8, T9, T11, T12, T13, J2, A1, A2, A5,
806      //Set path for Speaker out
807         if (  g_AudioVars2->eAudioSource  == E_AUDIO_INFO_KTV_IN )
808         {
809             MDrv_AUDIO_SetInternalPath(INTERNAL_MIXER, g_AudioVars2->AudioOutputInfo.SpeakerOut);
810             MDrv_AUDIO_SetInternalPath(INTERNAL_MIXER, g_AudioVars2->AudioOutputInfo.HpOut);
811             MDrv_AUDIO_SetInternalPath(INTERNAL_MIXER, g_AudioVars2->AudioOutputInfo.MonitorOut);
812             MDrv_AUDIO_SetInternalPath(INTERNAL_MIXER, g_AudioVars2->AudioOutputInfo.ScartOut);
813             MDrv_AUDIO_SetInternalPath(INTERNAL_MIXER, g_AudioVars2->AudioOutputInfo.SpdifOut);
814         }
815         else  // Normal case
816         {
817      //Set path for Speaker out
818             if( (g_AudioVars2->AudioOutputSourceInfo.SpeakerOut == E_CONNECT_SUB) && (g_AudioVars2->eSubAudioSource != AUDIO_NULL_INPUT)) //PIP on case
819             {
820                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.SpeakerOut);
821             }
822             else
823             {
824                 MDrv_AUDIO_SetInternalPath(INTERNAL_PCM_SE, g_AudioVars2->AudioOutputInfo.SpeakerOut);
825             }
826      //Set path for HP out
827             if ( (g_AudioVars2->AudioOutputSourceInfo.HpOut == E_CONNECT_SUB) && ( g_AudioVars2->eSubAudioSource != AUDIO_NULL_INPUT) ) //PIP on case
828             {
829                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.HpOut);
830             }
831             else
832             {
833                 MDrv_AUDIO_SetInternalPath(INTERNAL_TEST, g_AudioVars2->AudioOutputInfo.HpOut);
834             }
835      //Set path for Monitor out
836             if ( (g_AudioVars2->AudioOutputSourceInfo.MonitorOut == E_CONNECT_SUB) && (g_AudioVars2->eSubAudioSource != AUDIO_NULL_INPUT) ) //PIP on case
837             {
838                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.MonitorOut);
839             }
840             else
841             {
842                 MDrv_AUDIO_SetInternalPath(INTERNAL_PCM_DELAY, g_AudioVars2->AudioOutputInfo.MonitorOut);
843             }
844      //Set path for Scart out
845             if ( (g_AudioVars2->AudioOutputSourceInfo.ScartOut == E_CONNECT_SUB) || (g_AudioVars2->AudioOutputSourceInfo.ScartOut == E_CONNECT_SCART) )
846             {
847                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.ScartOut);
848             }
849             else
850             {
851                 MDrv_AUDIO_SetInternalPath(INTERNAL_PCM_DELAY, g_AudioVars2->AudioOutputInfo.ScartOut);
852             }
853      //Set path for SPDIF out
854             if ( (g_AudioVars2->AudioOutputSourceInfo.SpdifOut == E_CONNECT_SUB) && (g_AudioVars2->eSubAudioSource != AUDIO_NULL_INPUT) ) //PIP on case
855             {
856                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.SpdifOut);
857             }
858             else
859             {
860                 MDrv_AUDIO_SetInternalPath(INTERNAL_PCM, g_AudioVars2->AudioOutputInfo.SpdifOut); // For new mixer mode . AD sound is mixed in Inter_PCM
861             }
862      //Set path for ARC out
863             if ( (g_AudioVars2->AudioOutputSourceInfo.ArcOut== E_CONNECT_SUB) && (g_AudioVars2->eSubAudioSource != AUDIO_NULL_INPUT) ) //PIP on case
864             {
865                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.ArcOut);
866             }
867             else
868             {
869                 MDrv_AUDIO_SetInternalPath(INTERNAL_PCM, g_AudioVars2->AudioOutputInfo.ArcOut);
870             }
871 
872             if( (g_AudioVars2->AudioOutputSourceInfo.HDMIOut == E_CONNECT_SUB) && (g_AudioVars2->eSubAudioSource != AUDIO_NULL_INPUT)) //PIP on case
873             {
874                 MDrv_AUDIO_SetInternalPath(INTERNAL_SCART, g_AudioVars2->AudioOutputInfo.HDMIOut);
875             }
876             else
877             {
878                 MDrv_AUDIO_SetInternalPath(INTERNAL_PCM_SE, g_AudioVars2->AudioOutputInfo.HDMIOut);
879             }
880 
881             MDrv_AUDIO_SetInternalPath(INTERNAL_LRDIV2, AUDIO_I2S2_OUTPUT);
882         }
883     }
884 
885     MDrv_DBXTV_SetVolPath(g_AudioVars2->AudioOutputInfo.SpeakerOut);
886 }
887 
888 ////////////////////////////////////////////////////////////////////////////////
889 /// @brief \b Function \b Name: MApi_AUDIO_SetOutputInfo()
890 /// @brief \b Function \b Description:  Get audio output information from APP
891 /// @param pout_info   \b : Audio output path information structure pointer.
892 ///                                    Please refer  AUDIO_OUT_INFO   in header file
893 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetOutputInfo(AUDIO_OUT_INFO * pout_info)894 void _MApi_AUDIO_SetOutputInfo(AUDIO_OUT_INFO *pout_info)
895 {
896     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
897 
898     APIAUDIO_CHECK_SHM_INIT;
899 
900     g_AudioVars2->AudioOutputInfo.SpeakerOut = pout_info->SpeakerOut;
901     g_AudioVars2->AudioOutputInfo.HpOut = pout_info->HpOut;
902     g_AudioVars2->AudioOutputInfo.MonitorOut = pout_info->MonitorOut;
903     g_AudioVars2->AudioOutputInfo.ScartOut = pout_info->ScartOut;
904 
905     if(pout_info->SpeakerOut == AUDIO_SPDIF_OUTPUT)
906     {
907         g_AudioVars2->AudioOutputInfo.SpdifOut = AUDIO_NULL_OUTPUT;
908     }
909     else
910     {
911     g_AudioVars2->AudioOutputInfo.SpdifOut = AUDIO_SPDIF_OUTPUT;
912     }
913 
914     g_AudioVars2->AudioOutputInfo.ArcOut = AUDIO_HDMI_ARC_OUTPUT;
915     g_AudioVars2->AudioOutputInfo.HDMIOut = AUDIO_HDMI_OUTPUT;
916 }
917 
918 ////////////////////////////////////////////////////////////////////////////////
919 /// @brief \b Function \b Name: MApi_AUDIO_SetSystemInfo()
920 /// @brief \b Function \b Description:  Function for Driver layer to get the system compile option
921 ///                                                  (TV system , Audio system ....)
922 /// @param pau_info    \b : Audio output path information structure pointer
923 ///                                    Please refer  AUDIO_INIT_INFO   in header file
924 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSystemInfo(AUDIO_INIT_INFO * pau_info)925 void _MApi_AUDIO_SetSystemInfo(AUDIO_INIT_INFO *pau_info)
926 {
927     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
928 
929     APIAUDIO_CHECK_SHM_INIT;
930 
931     g_AudioVars2->AudioSystemInfo.tv_system = pau_info->tv_system;
932     g_AudioVars2->AudioSystemInfo.dtv_system = pau_info->dtv_system;
933     g_AudioVars2->AudioSystemInfo.au_system_sel = pau_info->au_system_sel;
934     g_AudioVars2->AudioSystemInfo.miu = pau_info->miu;
935 
936     if (MDrv_AUDIO_GET_INIT_FLAG() == TRUE)
937     {
938         if (g_AudioVars2->AudioSystemInfo.dtv_system == AUDIO_DTV_DVB)
939             MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_DVB);
940         else if (g_AudioVars2->AudioSystemInfo.dtv_system == AUDIO_DTV_ATSC)
941             MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_ATSC);
942         else if (g_AudioVars2->AudioSystemInfo.dtv_system == AUDIO_DTV_ISDB)
943             MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_ISDB);
944         else
945             MDrv_AUDIO_SPDIF_SetChannelStatus(SPDIF_CHANNEL_STATUS_CATEGORY,SPDIF_CS_CATEGORY_NONE);
946 
947         MDrv_AUDIO_SetAC3PInfo(Audio_AC3P_infoType_LoudnessMatching, (MS_U32)g_AudioVars2->g_dolbyLoudness_Enable, (MS_U32)g_AudioVars2->AudioSystemInfo.dtv_system);
948     }
949 }
950 
951 ////////////////////////////////////////////////////////////////////////////////
952 /// @brief \b Function \b Name: MApi_AUDIO_SetPathInfo()
953 /// @brief \b Function \b Description:  Get audio output path information from APP
954 /// @param path_info   \b : path information structure pointer
955 ///                                    for Speaker , Head phone , Monitor out , Scart out and SPDIF out
956 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetPathInfo(AUDIO_PATH_INFO * path_info)957 void _MApi_AUDIO_SetPathInfo(AUDIO_PATH_INFO *path_info)
958 {
959     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
960 
961     APIAUDIO_CHECK_SHM_INIT;
962 
963     g_AudioVars2->AudioPathInfo.SpeakerOut=path_info->SpeakerOut;
964     g_AudioVars2->AudioPathInfo.HpOut=path_info->HpOut;
965     g_AudioVars2->AudioPathInfo.MonitorOut=path_info->MonitorOut;
966     g_AudioVars2->AudioPathInfo.ScartOut=path_info->ScartOut;
967     g_AudioVars2->AudioPathInfo.SpdifOut=path_info->SpdifOut;
968     g_AudioVars2->AudioPathInfo.ArcOut=AUDIO_PATH_NULL;
969     g_AudioVars2->AudioPathInfo.HDMIOut= AUDIO_T3_PATH_HDMI;
970 }
971 
972 ////////////////////////////////////////////////////////////////////////////////
973 /// @brief \b Function \b Name: MApi_AUDIO_GetPathInfo()
974 /// @brief \b Function \b Description:  Get audio output path information from APP
975 /// @param path_info   \b : path information structure pointer
976 ///                                    for Speaker , Head phone , Monitor out , Scart out and SPDIF out
977 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetPathInfo(AUDIO_PATH_INFO * path_info)978 void _MApi_AUDIO_GetPathInfo(AUDIO_PATH_INFO *path_info)
979 {
980     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
981 
982     APIAUDIO_CHECK_SHM_INIT;
983 
984     path_info->SpeakerOut=g_AudioVars2->AudioPathInfo.SpeakerOut;
985     path_info->HpOut=g_AudioVars2->AudioPathInfo.HpOut;
986     path_info->MonitorOut=g_AudioVars2->AudioPathInfo.MonitorOut;
987     path_info->ScartOut=g_AudioVars2->AudioPathInfo.ScartOut;
988     path_info->SpdifOut=g_AudioVars2->AudioPathInfo.SpdifOut;
989     path_info->ArcOut=g_AudioVars2->AudioPathInfo.ArcOut;
990     path_info->HDMIOut=g_AudioVars2->AudioPathInfo.HDMIOut;
991 }
992 
993 ////////////////////////////////////////////////////////////////////////////////
994 /// @brief \b Function \b Name: MApi_AUDIO_SetOutputSourceInfo()
995 /// @brief \b Function \b Description:  Set audio output source information
996 /// @param path_info   \b : output port source information structure pointer
997 ///                                    for Speaker , Head phone , Monitor out , Scart out and SPDIF out
998 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetOutputSourceInfo(OUTPUT_SOURCE_INFO * pSourceInfo)999 void _MApi_AUDIO_SetOutputSourceInfo(OUTPUT_SOURCE_INFO *pSourceInfo)
1000 {
1001 
1002     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1003 
1004     APIAUDIO_CHECK_SHM_INIT;
1005 
1006     g_AudioVars2->AudioOutputSourceInfo.SpeakerOut = pSourceInfo->SpeakerOut;
1007     g_AudioVars2->AudioOutputSourceInfo.HpOut = pSourceInfo->HpOut;
1008     g_AudioVars2->AudioOutputSourceInfo.MonitorOut = pSourceInfo->MonitorOut;
1009     g_AudioVars2->AudioOutputSourceInfo.ScartOut = pSourceInfo->ScartOut;
1010     g_AudioVars2->AudioOutputSourceInfo.SpdifOut = pSourceInfo->SpdifOut;
1011     g_AudioVars2->AudioOutputSourceInfo.ArcOut = pSourceInfo->ArcOut;
1012     g_AudioVars2->AudioOutputSourceInfo.HDMIOut = pSourceInfo->HDMIOut;
1013 }
1014 
1015 ////////////////////////////////////////////////////////////////////////////////
1016 /// @brief \b Function \b Name: MApi_AUDIO_GetOutputSourceInfo()
1017 /// @brief \b Function \b Description:  Get audio output path information from APP
1018 /// @param pSourceInfo   \b : output port source information structure pointer
1019 ///                                    for Speaker , Head phone , Monitor out , Scart out and SPDIF out
1020 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetOutputSourceInfo(OUTPUT_SOURCE_INFO * pSourceInfo)1021 void  _MApi_AUDIO_GetOutputSourceInfo(OUTPUT_SOURCE_INFO *pSourceInfo)
1022 {
1023     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1024 
1025     APIAUDIO_CHECK_SHM_INIT;
1026 
1027     memcpy(pSourceInfo, &(g_AudioVars2->AudioOutputSourceInfo), sizeof(g_AudioVars2->AudioOutputSourceInfo));
1028 }
1029 
1030 ////////////////////////////////////////////////////////////////////////////////
1031 /// @brief \b Function \b Name: MApi_AUDIO_SetSourceInfo()
1032 /// @brief \b Function \b Description:  For driver layer to get audio source information from APP
1033 /// @param eSourceType   \b : information structure pointer ==>AUDIO_SOURCE_INFO_TYPE
1034 ///                         - E_AUDIO_INFO_DTV_IN,
1035 ///                         - E_AUDIO_INFO_ATV_IN,
1036 ///                         - E_AUDIO_INFO_HDMI_IN,
1037 ///                         - E_AUDIO_INFO_ADC_IN,
1038 ///                         - E_AUDIO_INFO_MM_IN,
1039 ///                         - E_AUDIO_INFO_SPDIF_IN,
1040 ///                         - E_AUDIO_INFO_KTV_IN,
1041 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSourceInfo(AUDIO_SOURCE_INFO_TYPE eSourceType)1042 void _MApi_AUDIO_SetSourceInfo(AUDIO_SOURCE_INFO_TYPE eSourceType)
1043 {
1044     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1045 
1046     APIAUDIO_CHECK_SHM_INIT;
1047 
1048     g_AudioVars2->eAudioSource = eSourceType;
1049 
1050 }
1051 
1052 ////////////////////////////////////////////////////////////////////////////////
1053 /// @brief \b Function \b Name: MApi_AUDIO_InputSwitch()
1054 /// @brief \b Function \b Description:  Set audio Input connectivity (for S7 serious only)
1055 /// @param enSource   \b :  Please refer  AUDIO_INPUT_TYPE  enum in header file
1056 ///@param  enGroup  \b : Please refer  AUDIO_SWITCH_GROUP  enum in header file
1057 ///////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_InputSwitch(AUDIO_INPUT_TYPE enSource,AUDIO_SWITCH_GROUP enGroup)1058 void _MApi_AUDIO_InputSwitch(AUDIO_INPUT_TYPE enSource, AUDIO_SWITCH_GROUP enGroup)
1059 {
1060     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1061 
1062     AUDIO_PATH_GROUP_TYPE Audio_pathgroup_status;
1063     MS_U8  u8input_src = LONIBBLE(enSource);
1064 
1065     APIAUDIO_CHECK_SHM_INIT;
1066 
1067     Audio_pathgroup_status = MDrv_AUDIO_GetPathGroup();
1068 
1069     if (Audio_pathgroup_status == AUDIO_PATH_GROUP_1)
1070     {   // used in U3, T2, T4, Janus,
1071         if(enGroup==E_AUDIO_GROUP_MAIN)
1072         {
1073             MDrv_AUDIO_SetInputPath(enSource , AUDIO_PATH_MAIN);
1074             MDrv_AUDIO_SetInputPath(enSource , g_AudioVars2->AudioPathInfo.MonitorOut);
1075             MDrv_AUDIO_SetInputPath(enSource , g_AudioVars2->AudioPathInfo.SpdifOut);
1076         }
1077         else  if(enGroup==E_AUDIO_GROUP_SCART)
1078         {
1079             MDrv_AUDIO_SetInputPath(enSource , g_AudioVars2->AudioPathInfo.ScartOut);
1080         }
1081 
1082         if ( g_AudioVars2->eAudioSource == E_AUDIO_INFO_KTV_IN )
1083         {
1084             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "\r\n==Source=KTV ==\r\n");
1085             MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_KTV);
1086         }
1087         else if ( g_AudioVars2->eAudioSource == E_AUDIO_INFO_GAME_IN )
1088         {
1089             MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_GAME);
1090         }
1091         else
1092         {
1093             MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_DTV);
1094         }
1095     }
1096     else
1097     {   // used in U4, T3, T8, T9, T11, T12, T13, J2, A1, A2, A5,
1098         if(enGroup==E_AUDIO_GROUP_MAIN)
1099         {
1100             MDrv_AUDIO_SetInputPath(enSource , AUDIO_PATH_4); // fixed in this path
1101             g_AudioVars2->eMainAudioSource = enSource;
1102         }
1103         else  if(enGroup==E_AUDIO_GROUP_SCART)
1104         {
1105             MDrv_AUDIO_SetInputPath(enSource , AUDIO_PATH_6); //fixed in this path
1106             g_AudioVars2->eScartAudioSource = enSource;
1107         }
1108         else if(enGroup==E_AUDIO_GROUP_SUB)  // PIP SUB or HP source
1109         {
1110             /*
1111              *
1112              * In TVOS environment, if PIP on and MM is main, Ch5 input should set to another NULL source.
1113              * Otherwise, sub input source sound would be mixed together to main input source.
1114              */
1115             if (((g_AudioVars2->eAudioSource == E_AUDIO_INFO_MM_IN) || (g_AudioVars2->eAudioSource == E_AUDIO_INFO_GAME_IN)) &&
1116                 (MDrv_MAD_GetDecCmd(DVB_Audio_Decoder2) == AU_DVB_DECCMD_PLAYFRAME_GS))
1117             {
1118                 if (u8input_src == AUDIO_DSP1_INPUT)
1119                 {
1120                     MDrv_AUDIO_SetInputPath(AUDIO_DSP3_DVB_INPUT , AUDIO_PATH_4);
1121                 }
1122                 else if (u8input_src == AUDIO_DSP3_INPUT)
1123                 {
1124                     MDrv_AUDIO_SetInputPath(AUDIO_DSP1_DVB_INPUT , AUDIO_PATH_4);
1125                 }
1126             }
1127 
1128             switch(enSource)  // Use 2nd ADC in sub mode
1129             {
1130                case AUDIO_AUIN0_INPUT:
1131                    enSource=AUDIO_ADC2_AUIN0_INPUT;
1132                    break;
1133                case AUDIO_AUIN1_INPUT:
1134                    enSource=AUDIO_ADC2_AUIN1_INPUT;
1135                    break;
1136                case AUDIO_AUIN2_INPUT:
1137                    enSource=AUDIO_ADC2_AUIN2_INPUT;
1138                    break;
1139                case AUDIO_AUIN3_INPUT:
1140                    enSource=AUDIO_ADC2_AUIN3_INPUT;
1141                    break;
1142                case AUDIO_AUIN4_INPUT:
1143                    enSource=AUDIO_ADC2_AUIN4_INPUT;
1144                    break;
1145                case AUDIO_AUIN5_INPUT:
1146                    enSource=AUDIO_ADC2_AUIN5_INPUT;
1147                    break;
1148                case AUDIO_AUMIC_INPUT:
1149                    enSource=AUDIO_ADC2_AUMIC_INPUT;
1150                    break;
1151                default:
1152                    break;
1153             }
1154             MDrv_AUDIO_SetInputPath(enSource , AUDIO_PATH_6); // PIP shared the same path with Scart
1155             g_AudioVars2->eSubAudioSource = enSource;
1156         }
1157 
1158         // Set output source
1159         switch ( g_AudioVars2->eAudioSource )
1160         {
1161             case E_AUDIO_INFO_KTV_IN:
1162                 MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_KTV);
1163                 break;
1164 
1165             case E_AUDIO_INFO_GAME_IN:
1166                 MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_GAME);
1167                 break;
1168 
1169             case E_AUDIO_INFO_KTV_STB_IN:
1170                 MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_KTV_STB);
1171                 break;
1172 
1173             case E_AUDIO_INFO_ATV_IN:
1174                 // ATV should not effected by entertainment mode
1175                 break;
1176 
1177             default:
1178                 MDrv_AUDIO_SetEntertainmentMode(AUDIO_ETMODE_DTV);
1179                 break;
1180         }
1181 
1182         MDrv_AUDIO_InputSwitch(enGroup);
1183 
1184         //Reconnect audio output port again .
1185         _MApi_AUDIO_SetOutConnectivity();
1186     }
1187 }
1188 
1189 ////////////////////////////////////////////////////////////////////////////////
1190 /// @brief \b Function \b Name: MApi_AUDIO_ReadMailBox()
1191 /// @brief \b Function \b Description:  This routine is used to read the DSP mail box value
1192 /// @param bDspType    \b : Select audio DEC/SE DSP
1193 /// @param u8ParamNum  \b : Mail box address
1194 /// @return MS_U16     \b : Mail Box value
1195 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ReadMailBox(MS_BOOL bDspType,MS_U8 u8ParamNum)1196 MS_U16 _MApi_AUDIO_ReadMailBox(MS_BOOL bDspType, MS_U8 u8ParamNum)
1197 {
1198     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1199 
1200     if(bDspType==DSP_DEC)
1201     {
1202         return (MDrv_AUDIO_ReadDecMailBox(u8ParamNum));
1203     }
1204     else
1205     {
1206         return (MDrv_AUDIO_ReadSeMailBox(u8ParamNum));
1207     }
1208 }
1209 
1210 ////////////////////////////////////////////////////////////////////////////////
1211 /// @brief \b Function \b Name: MDrv_AUDIO_WriteDecMailBox()
1212 /// @brief \b Function \b Description:  This routine is used to write DSP mail box
1213 /// @param bDspType    \b : Select audio DEC/SE DSP
1214 /// @param u8ParamNum  \b : Mail box address
1215 /// @param u16Data     \b : value
1216 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_WriteMailBox(MS_BOOL bDspType,MS_U8 u8ParamNum,MS_U16 u16Data)1217 void _MApi_AUDIO_WriteMailBox(MS_BOOL bDspType, MS_U8 u8ParamNum, MS_U16 u16Data)
1218 {
1219     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1220 
1221     if(bDspType==DSP_DEC)
1222     {
1223         _MDrv_AUDIO_WriteDecMailBox(u8ParamNum, u16Data);
1224     }
1225     else
1226     {
1227         MDrv_AUDIO_WriteSeMailBox(u8ParamNum, u16Data);
1228     }
1229 
1230 }
1231 
1232 ////////////////////////////////////////////////////////////////////////////////
1233 /// @brief \b Function \b Name: MApi_AUDIO_FwTriggerDSP()
1234 /// @brief \b Function \b Description:  This routine send a PIO interrupt to DSP with a command .
1235 /// @param u16Cmd      \b :    0xF0-- for MHEG5 file protocol
1236 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FwTriggerDSP(MS_U16 u16Cmd)1237 void _MApi_AUDIO_FwTriggerDSP(MS_U16 u16Cmd)
1238 {
1239     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1240 
1241     MDrv_AUDIO_FwTriggerDSP(u16Cmd);
1242 }
1243 
1244 ////////////////////////////////////////////////////////////////////////////////
1245 /// @brief \b Function \b Name: MApi_AUDIO_SetFwStatus()
1246 /// @brief \b Function \b Description:  FW set DSP load/reload code from DDR or Flash
1247 /// @param bBootOnDDR  \b :
1248 ///                     - TRUE==> Boot from DDR;
1249 ///                     - FALSE==> Boot from Flash
1250 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetFwStatus(MS_BOOL bBootOnDDR)1251 void _MApi_AUDIO_SetFwStatus(MS_BOOL bBootOnDDR)
1252 {
1253     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1254 
1255     MDrv_AUDIO_DspBootOnDDR(bBootOnDDR);
1256     //audio_FW_Status = bBootOnDDR;
1257 }
1258 
1259 ////////////////////////////////////////////////////////////////////////////////
1260 /// @brief \b Function \b Name: MApi_AUDIO_ExitAudioSystem()
1261 /// @brief \b Function \b Description: This routine is used to exit audio system
1262 ///                                  by performing DSP power down setting.
1263 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ExitAudioSystem(void)1264 void _MApi_AUDIO_ExitAudioSystem(void)
1265 {
1266     MS_BOOL bRet = FALSE;
1267 
1268     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1269 
1270     APIAUDIO_CHECK_SHM_INIT;
1271 
1272     APIAUDIO_CHECK_INIT_FLAG(bRet);
1273 
1274     if (bRet == FALSE)
1275     {
1276         return;
1277     }
1278 
1279     MDrv_AUDIO_SetPowerOn(FALSE);
1280 }
1281 
1282 ////////////////////////////////////////////////////////////////////////////////
1283 /// @brief \b Function \b Name: MApi_AUDIO_RebootDsp(void)
1284 /// @brief \b Function \b Description:  This routine reboot DSP.
1285 /// @param bDspType    \b : 0- DEC DSP; 1- SNDEff DSP
1286 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_RebootDsp(MS_BOOL bDspType)1287 void _MApi_AUDIO_RebootDsp(MS_BOOL bDspType)
1288 {
1289     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1290 
1291     MDrv_AUDIO_RebootDSP(bDspType);
1292 }
1293 
1294 ////////////////////////////////////////////////////////////////////////////////
1295 /// @brief \b Function \b Name: MApi_AUDIO_SendIntrupt()
1296 /// @brief \b Function \b Description: This routine send a PIO8 interrupt to DSP.
1297 /// @param bDspType    \b :  0- DEC DSP; 1- SNDEff DSP
1298 /// @param u8Cmd       \b :  0xE0, for MHEG5 file protocol
1299 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SendIntrupt(MS_BOOL bDspType,MS_U8 u8Cmd)1300 void _MApi_AUDIO_SendIntrupt(MS_BOOL bDspType,MS_U8 u8Cmd)
1301 {
1302     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1303 
1304     MDrv_AUDIO_SendIntrupt(bDspType,u8Cmd);
1305 }
1306 
1307 ////////////////////////////////////////////////////////////////////////////////
1308 /// @brief \b Function \b Name: MApi_AUDIO_I2S_SetMode()
1309 /// @brief \b Function \b Description:  This routine is used to Set the I2S output mode.
1310 /// @param u8Mode      \b : I2S mode select
1311 ///                       - AUDIO_I2S_MCLK               ==>Set I2S MCLK
1312 ///                       - AUDIO_I2S_WORD_WIDTH, ==>Set I2S Word-width
1313 ///                       - AUDIO_I2S_SOURCE_CH,    ==>Set I2S channel Source
1314 ///                       - AUDIO_I2S_FORMAT            ==>Set  I2S format
1315 /// @param u8Val      \b : I2S mode value
1316 ///                      - I2S_MCLK_64FS=0x04,               ==> MCLK=64 Fs ;
1317 ///                      - I2S_MCLK_128FS=0x05,             ==> MCLK=128 Fs ;
1318 ///                      - I2S_MCLK_256FS=0x06,             ==> MCLK=256 Fs ; default setting
1319 ///                      - I2S_MCLK_384FS=0x07,             ==> MCLK=384 Fs ;
1320 ///                      - I2S_WORD_WIDTH_16BIT=0x4,  ==>Word width=16bit;
1321 ///                      - I2S_WORD_WIDTH_24BIT=0x5,  ==>Word width=24bit;
1322 ///                      - I2S_WORD_WIDTH_32BIT=0x6,  ==>Word width=32bit; default setting
1323 ///                      - I2S_FORMAT_STANDARD=0,       ==>I2S  in Standard format
1324 ///                      - I2S_FORMAT_LEFT_JUSTIFIED=1 ==> I2S in Left-justify format
1325 ///////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_I2S_SetMode(AUDIO_I2S_MODE_TYPE u8Mode,AUDIO_I2S_MODE_VALUE u8Val)1326 void _MApi_AUDIO_I2S_SetMode(AUDIO_I2S_MODE_TYPE u8Mode, AUDIO_I2S_MODE_VALUE  u8Val)
1327 {
1328     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1329 
1330    MDrv_AUDIO_I2S_SetMode((MS_U8)u8Mode, (MS_U8)u8Val);
1331 }
1332 
1333 ////////////////////////////////////////////////////////////////////////////////
1334 /// @brief \b Function \b Name: MApi_AUDIO_WritePreInitTable()
1335 /// @brief \b Function \b Description: This routine is to set power on DAC sequence before setting init table.
1336 ////////////////////////////////////////////////////////////////////////////////
1337 //Refine power on sequence for earphone & DAC pop noise issue
_MApi_AUDIO_WritePreInitTable(void)1338 void _MApi_AUDIO_WritePreInitTable(void)
1339 {
1340     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1341 
1342     APIAUDIO_CHECK_SHM_INIT;
1343 
1344     MDrv_AUDIO_InitMMIO();
1345 
1346     if (MDrv_AUDIO_SHM_Init() == FALSE)
1347     {
1348         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : fails to init Audio SHM\n", __FUNCTION__);
1349         return;
1350     }
1351 
1352     if (MDrv_AUDIO_Mutex_Init() == FALSE)
1353     {
1354         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : fails to init Audio Mutex\n", __FUNCTION__);
1355         return;
1356     }
1357 
1358     OS_OBTAIN_MUTEX(_s32AUDIOMutex, MSOS_WAIT_FOREVER);
1359 
1360     if (MDrv_AUDIO_GET_INIT_FLAG() == TRUE)
1361     {
1362         OS_RELEASE_MUTEX(_s32AUDIOMutex);
1363         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "%s() : doesn't need to init again\n", __FUNCTION__);
1364         return;
1365     }
1366 
1367     if (g_AudioVars2->g_Audio_PreInitFlag == FALSE)
1368     {
1369         MDrv_AUDIO_SwResetMAD();
1370 
1371         MDrv_AUDIO_WritePreInitTable();
1372         g_AudioVars2->g_Audio_PreInitFlag = TRUE;
1373     }
1374 
1375     OS_RELEASE_MUTEX(_s32AUDIOMutex);
1376 
1377     return;
1378 }
1379 
1380 ////////////////////////////////////////////////////////////////////////////////
1381 /// @brief \b Function \b Name: MApi_AUDIO_SetPowerOn()
1382 /// @brief \b Function \b Description: This routine is used to enable earphone low power stage.
1383 ////////////////////////////////////////////////////////////////////////////////
1384 //Refine power on sequence for earphone & DAC pop noise issue
_MApi_AUDIO_EnaEarphone_LowPower_Stage(void)1385 void _MApi_AUDIO_EnaEarphone_LowPower_Stage(void)
1386 {
1387     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1388 
1389     MDrv_AUDIO_EnaEarphone_LowPower_Stage();
1390     MDrv_AUDIO_EnaEarphone_HighDriving_Stage();
1391     return;
1392 }
1393 
1394 ////////////////////////////////////////////////////////////////////////////////
1395 /// @brief \b Function \b Name: MApi_AUDIO_SetPowerOn()
1396 /// @brief \b Function \b Description: This routine is used to enable earphone high driving stage.
1397 ////////////////////////////////////////////////////////////////////////////////
1398 //Refine power on sequence for earphone & DAC pop noise issue
_MApi_AUDIO_EnaEarphone_HighDriving_Stage(void)1399 void _MApi_AUDIO_EnaEarphone_HighDriving_Stage(void)
1400 {
1401     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1402 
1403 	AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "-->>NEW POWER ON SEQ: MApi_AUDIO_EnaEarphone_HighDriving_Stage\n\r");
1404     MDrv_AUDIO_EnaEarphone_HighDriving_Stage();
1405     return;
1406 }
1407 
1408 ////////////////////////////////////////////////////////////////////////////////
1409 //
1410 //          AUDIO_DTV RELATIONAL API FUNCTION
1411 //
1412 ////////////////////////////////////////////////////////////////////////////////
1413 ////////////////////////////////////////////////////////////////////////////////
1414 /// @brief \b Function \b Name: MApi_AUDIO_SetSystem()
1415 /// @brief \b Function \b Description:  This function will load
1416 ///                                     different audio decoder to audio system.
1417 ///
1418 ///                                     In Mstar audio system, we can support 1 or 2 decoders.
1419 ///                                     One is for main DTV audio or Multimedia audio player.
1420 ///                                     Another is for second audio decode (ex: used for Audio Description purpose)
1421 ///
1422 /// @param enDecSystem  \b : (En_DVB_decSystemType) decoder type
1423 ///                        - parameter type "MSAPI_AUD_DVB_XXXX" is decoder type for main audio decoder
1424 ///                        - parameter type "MSAPI_AUD_DVB2_XXXX" is decoder type for second audio decoder
1425 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSystem(En_DVB_decSystemType enDecSystem)1426 MS_BOOL _MApi_AUDIO_SetSystem(En_DVB_decSystemType enDecSystem)
1427 {
1428     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1429 
1430     MS_BOOL bRet = FALSE;
1431 
1432     APIAUDIO_CHECK_INIT_FLAG(bRet);
1433     if (bRet == FALSE)
1434     {
1435         return bRet;
1436     }
1437 
1438     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "apiAud>> enDecSystem %d enCurDecSystem = %d\n", (MS_U8)enDecSystem, (MS_U8)enCurDecSystem);
1439 
1440     if ((enDecSystem & 0xf0) == 0xb0)
1441     {
1442         bRet = MDrv_SIF_SetSystem(enDecSystem);
1443     }
1444     else
1445     {
1446         if (enDecSystem >= 0x20)
1447         {
1448             enCurDecSystem2 = enDecSystem;
1449         }
1450         else
1451         {
1452             enCurDecSystem = enDecSystem;
1453         }
1454         bRet = MDrv_AUDIO_SetSystem(enDecSystem);
1455     }
1456 
1457     return bRet;
1458 }
1459 ////////////////////////////////////////////////////////////////////////////////
1460 /// @brief \b Function \b Name: MApi_AUDIO_SetDecodeSystem()
1461 /// @brief \b Function \b Description:  This function will set DecId decoder as  structure p_AudioDecStatus
1462 /// @param\b DecId  \b : Decoder ID to be controled
1463 /// @param\b p_AudioDecStatus  \b : decoder status structure pointer
1464 /// @return\b MS_BOOL  \b : set decoder system process status FALSE-> fail TRUE-> Success
1465 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetDecodeSystem(AUDIO_DEC_ID DecId,AudioDecStatus_t * p_AudioDecStatus)1466 MS_BOOL _MApi_AUDIO_SetDecodeSystem(AUDIO_DEC_ID DecId,  AudioDecStatus_t * p_AudioDecStatus)
1467 {
1468     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1469 
1470     MS_BOOL bRet = FALSE;
1471 
1472     APIAUDIO_CHECK_SHM_INIT;
1473 
1474     APIAUDIO_CHECK_INIT_FLAG(bRet);
1475     if (bRet == FALSE)
1476     {
1477         return bRet;
1478     }
1479 
1480     if (NULL == p_AudioDecStatus)
1481     {
1482         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : AudioDecStatus is null\n", __FUNCTION__);
1483         return bRet;
1484     }
1485 
1486     if ((AU_DEC_INVALID == DecId) || (AU_DEC_MAX == DecId))
1487     {
1488         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Invalid Dec ID = %d,  %s() %d\n",DecId,__FUNCTION__,__LINE__);
1489         return bRet;
1490     }
1491 
1492     if ((MSAPI_AUD_DVB_INVALID == p_AudioDecStatus->eAudFormat) ||
1493         (MSAPI_AUD_DVB_NONE == p_AudioDecStatus->eAudFormat))
1494     {
1495         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "Invalid Decoder Type %s() %d\n",__FUNCTION__,__LINE__);
1496         return bRet;
1497     }
1498 
1499     if (FALSE == g_AudioVars2->AudioDecStatus[DecId].bConnect)
1500     {
1501         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "DecID %d not connected %s() %d\n",DecId,__FUNCTION__,__LINE__);
1502         return bRet;
1503     }
1504 
1505     bRet = MDrv_AUDIO_SetDecodeSystem(DecId, p_AudioDecStatus);
1506 
1507     return bRet;
1508 }
1509 
1510 ////////////////////////////////////////////////////////////////////////////////
1511 /// @brief \b Function \b Name: MApi_AUDIO_GetDecodeSystem()
1512 /// @brief \b Function \b Description:  This function will get DecId decoder status
1513 /// @param DecId  \b : Decoder ID to get status
1514 /// @param p_AudioDecStatus  \b : return status to p_AudioDecStatus pointer
1515 /// @return\b MS_BOOL  \b : set decoder system process status FALSE-> fail TRUE-> Success
1516 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetDecodeSystem(AUDIO_DEC_ID DecId,AudioDecStatus_t * p_AudioDecStatus)1517 MS_BOOL _MApi_AUDIO_GetDecodeSystem(AUDIO_DEC_ID DecId,  AudioDecStatus_t * p_AudioDecStatus)
1518 {
1519     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1520 
1521     MS_BOOL bRet = FALSE;
1522 
1523     APIAUDIO_CHECK_SHM_INIT;
1524 
1525     APIAUDIO_CHECK_INIT_FLAG(bRet);
1526     if (bRet == FALSE)
1527     {
1528         return bRet;
1529     }
1530 
1531     if (NULL == p_AudioDecStatus)
1532     {
1533         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : AudioDecStatus is null\n", __FUNCTION__);
1534         return bRet;
1535     }
1536 
1537     if ((AU_DEC_INVALID == DecId) || (AU_DEC_MAX == DecId))
1538     {
1539         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "Invalid Dec ID %d %s() %d\n",DecId,__FUNCTION__,__LINE__);
1540         return bRet;
1541     }
1542 
1543     if (FALSE == g_AudioVars2->AudioDecStatus[DecId].bConnect)
1544     {
1545         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "DecID %d not connected %s() %d\n",DecId,__FUNCTION__,__LINE__);
1546         return bRet;
1547     }
1548 
1549     // copy Dec status
1550     memcpy(p_AudioDecStatus,&g_AudioVars2->AudioDecStatus[DecId], sizeof(AudioDecStatus_t));
1551 
1552     return TRUE;
1553 }
1554 
1555 ////////////////////////////////////////////////////////////////////////////////
1556 /// @brief \b Function \b Name: MApi_AUDIO_OpenDecodeSystem()
1557 /// @brief \b Function \b Description:  This function will open decode system according audio dec status
1558 /// @param p_AudioDecStatus  \b : decoder status stucture
1559 /// @return\b AUDIO_DEC_ID  \b : return available decoder ID
1560 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_OpenDecodeSystem(AudioDecStatus_t * p_AudioDecStatus)1561 AUDIO_DEC_ID _MApi_AUDIO_OpenDecodeSystem(AudioDecStatus_t * p_AudioDecStatus)
1562 {
1563     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1564     AUDIO_DEC_ID DecRet = AU_DEC_INVALID;
1565     MS_BOOL init_flag = FALSE;
1566 
1567     APIAUDIO_CHECK_SHM_INIT;
1568 
1569     APIAUDIO_CHECK_INIT_FLAG(init_flag);
1570     if (init_flag == FALSE)
1571     {
1572         return DecRet;
1573     }
1574 
1575     if (NULL == p_AudioDecStatus)
1576     {
1577         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : p_AudioDecStatus is NULL\n", __FUNCTION__);
1578         return DecRet;
1579     }
1580 
1581     if ((MSAPI_AUD_DVB_INVALID == p_AudioDecStatus->eAudFormat) ||
1582         (MSAPI_AUD_DVB_NONE == p_AudioDecStatus->eAudFormat))
1583     {
1584         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() %d\n",__FUNCTION__,__LINE__);
1585         return DecRet;
1586     }
1587 
1588     if (p_AudioDecStatus->bIsAD) // Decide AD decoder
1589     {
1590         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() %d\n",__FUNCTION__,__LINE__);
1591     }
1592 
1593     if ((p_AudioDecStatus->eSourceType == E_AUDIO_INFO_ADC_IN) ||
1594        (p_AudioDecStatus->eSourceType == E_AUDIO_INFO_SPDIF_IN))
1595     {
1596         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() %d\n",__FUNCTION__,__LINE__);
1597         return DecRet;
1598     }
1599 
1600     // Open Decode system
1601     DecRet = MDrv_AUDIO_OpenDecodeSystem(p_AudioDecStatus);
1602 
1603     if (DecRet != AU_DEC_INVALID)
1604     {
1605         switch (p_AudioDecStatus->eSourceType)
1606         {
1607             case E_AUDIO_INFO_ATV_IN:
1608                 if (DecRet == AU_DEC_ID1)
1609                 {
1610                     g_AudioVars2->g_u8SifDspType = DSP_DEC;
1611                 }
1612                 else
1613                 {
1614                     g_AudioVars2->g_u8SifDspType = DSP_SE;
1615                 }
1616                 break;
1617 
1618             case E_AUDIO_INFO_HDMI_IN:
1619                 if (DecRet == AU_DEC_ID3)
1620                 {
1621                     MDrv_AUDIO_SetAC3PInfo(Audio_AC3P_infoType_hdmiAC3inSE, TRUE, 0);
1622                 }
1623                 else
1624                 {
1625                     MDrv_AUDIO_SetAC3PInfo(Audio_AC3P_infoType_hdmiAC3inSE, FALSE, 0);
1626                 }
1627                 break;
1628 
1629             default:
1630                 break;
1631         }
1632 
1633         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "DecRet = %d %s() %d \n",DecRet,__FUNCTION__,__LINE__);
1634 
1635         // reload DSP code, and back up AudioDecStatus
1636         MDrv_AUDIO_SetDecodeSystem(DecRet, p_AudioDecStatus);
1637 
1638         // Update status
1639         g_AudioVars2->AudioDecStatus[DecRet].bConnect = TRUE;
1640 
1641         if (DecRet == AU_DEC_ID3)
1642         {
1643             g_AudioVars2->AudioDecStatus[DecRet].eDSPId = AUDIO_DSP_ID_SND;
1644         }
1645         else if (DecRet == AU_DEC_ID1)
1646         {
1647             g_AudioVars2->AudioDecStatus[DecRet].eDSPId = AUDIO_DSP_ID_DEC;
1648         }
1649         else if (DecRet == AU_DEC_ID2)
1650         {
1651              // AU_DEC_ID2 only for ATV SIF
1652              // For other case should not use AU_DEC_ID2
1653             // Don't know how to set for ATV case
1654             g_AudioVars2->AudioDecStatus[DecRet].eDSPId = AUDIO_DSP_ID_ALL;
1655         }
1656 
1657     }
1658 
1659     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "Dec Id %d opened %s() %d \n",DecRet,__FUNCTION__,__LINE__);
1660     return DecRet;
1661 }
1662 
1663 ////////////////////////////////////////////////////////////////////////////////
1664 /// @brief \b Function \b Name: MApi_AUDIO_SetDecodeCmd()
1665 /// @brief \b Function \b Description:  This function will send decode command to DecId decoder
1666 /// @param DecId  \b : Decoder ID to be controled
1667 /// @param enDecComamnd  \b : decoder command
1668 /// @return\b MS_BOOL  \b : set decoder system process status FALSE-> fail TRUE-> Success
1669 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetDecodeCmd(AUDIO_DEC_ID DecId,En_DVB_decCmdType enDecComamnd)1670 MS_BOOL _MApi_AUDIO_SetDecodeCmd(AUDIO_DEC_ID DecId, En_DVB_decCmdType enDecComamnd)
1671 {
1672     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1673 
1674     MS_BOOL bRet = FALSE;
1675 
1676     APIAUDIO_CHECK_SHM_INIT;
1677 
1678     APIAUDIO_CHECK_INIT_FLAG(bRet);
1679     if (bRet == FALSE)
1680     {
1681         return bRet;
1682     }
1683 
1684     if ((AU_DEC_INVALID == DecId) || (AU_DEC_MAX == DecId))
1685     {
1686         return FALSE;
1687     }
1688 
1689     if (FALSE == g_AudioVars2->AudioDecStatus[DecId].bConnect)
1690     {
1691         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "DecID %d not connected %s() %d\n",DecId,__FUNCTION__,__LINE__);
1692         return FALSE;
1693     }
1694 
1695     //Convert Api dec command to Drv dec command
1696     AU_DVB_DECCMD u8DecCmd;
1697     _ApiDecCmd_To_DrvDecCmd(enDecComamnd,&u8DecCmd);
1698 
1699     MDrv_MAD_DecoderCmd(DecId,u8DecCmd);
1700     return TRUE;
1701 }
1702 
1703 ////////////////////////////////////////////////////////////////////////////////
1704 /// @brief \b Function \b Name: MApi_AUDIO_ReleaseDecodeSystem()
1705 /// @brief \b Function \b Description:  This function will release/close decode system
1706 /// @param DecId  \b : Decoder ID to be released
1707 /// @return\b MS_BOOL  \b : set decoder system process status FALSE-> fail TRUE-> Success
1708 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ReleaseDecodeSystem(AUDIO_DEC_ID DecId)1709 MS_BOOL _MApi_AUDIO_ReleaseDecodeSystem(AUDIO_DEC_ID DecId)
1710 {
1711     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1712 
1713     MS_BOOL bRet = FALSE;
1714 
1715     APIAUDIO_CHECK_SHM_INIT;
1716 
1717     APIAUDIO_CHECK_INIT_FLAG(bRet);
1718     if (bRet == FALSE)
1719     {
1720         return bRet;
1721     }
1722 
1723     if ((AU_DEC_INVALID == DecId) || (AU_DEC_MAX == DecId))
1724     {
1725         return bRet;
1726     }
1727 
1728     // Stop when release
1729     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "DecID %d disconnect %s() %d\n",DecId,__FUNCTION__,__LINE__);
1730     MDrv_MAD_DecoderCmd(DecId,AU_DVB_DECCMD_STOP);
1731     memset(&g_AudioVars2->AudioDecStatus[DecId],  0, sizeof(AudioDecStatus_t));
1732 
1733     return bRet;
1734 }
1735 ////////////////////////////////////////////////////////////////////////////////
1736 /// @brief \b Function \b Name: MApi_AUDIO_GetDecSysSupportStatus()
1737 /// @brief \b Function \b Description: This function will report Audio Decoder support feature status when giving DecSystem type
1738 /// @param <IN>        \b   enDecSystem : Decoder type
1739 /// @param <RET>       \b   BOOL        : True or False
1740 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetDecSysSupportStatus(En_DVB_decSystemType enDecSystem)1741 MS_BOOL _MApi_AUDIO_GetDecSysSupportStatus(En_DVB_decSystemType enDecSystem)
1742 {
1743     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1744 
1745     return(MDrv_AUDIO_GetDecSysSupportStatus(enDecSystem));
1746 }
1747 
1748 ////////////////////////////////////////////////////////////////////////////////
1749 /// @brief \b Function \b Name: MApi_AUDIO_SetH264StreamID_Mod()
1750 /// @brief \b Function \b Description: This routine is used to AC3 Stream ID mod.
1751 /// @param stream_id_mod  \b : DTV stream ID
1752 ///                          - stream_id_mod = 0, video MPEG mode;
1753 ///                          - stream_id_mod = 1, video H264 mode
1754 ////////////////////////////////////////////////////////////////////////////////
MApi_AUDIO_SetH264StreamID_Mod(MS_U8 stream_id_mod)1755 void MApi_AUDIO_SetH264StreamID_Mod(MS_U8 stream_id_mod)    //Non-Used
1756 {
1757     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1758 
1759     //MDrv_MAD_SetH264StreanID_Mod(stream_id_mod);
1760 }
1761 
1762 ////////////////////////////////////////////////////////////////////////////////
1763 /// @brief \b Function \b Name: MApi_AUDIO_IsMadLock()
1764 /// @brief \b Function \b Description: This function show DTV Audio stream lock status
1765 /// @return MS_BOOL    \b :       1 : lock  ; 0 : unlock
1766 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_IsMadLock(void)1767 MS_BOOL _MApi_AUDIO_IsMadLock(void)
1768 {
1769     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1770 
1771     return _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DecStatus);
1772 }
1773 
1774 ////////////////////////////////////////////////////////////////////////////////
1775 /// @brief \b Function \b Name: MApi_AUDIO_GetDecStatus()
1776 /// @brief \b Function \b Description: This routine is used to get the decoder's status (paly or stop)
1777 /// @return En_DVB_decCmdType \b : Decoder status (paly or stop)
1778 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetDecStatus(void)1779 En_DVB_decCmdType _MApi_AUDIO_GetDecStatus(void)
1780 {
1781     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1782 
1783     return enDecoderStatus;
1784 }
1785 
1786 ////////////////////////////////////////////////////////////////////////////////
1787 /// @brief \b Function \b Name: MApi_AUDIO_SetCommand()
1788 /// @brief \b Function \b Description: Set decoder Command for Digital Audio module
1789 /// @param enDecComamnd \b : deccoder command for DVB Audio
1790 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetCommand(En_DVB_decCmdType enDecComamnd)1791 void _MApi_AUDIO_SetCommand(En_DVB_decCmdType enDecComamnd)
1792 {
1793     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1794 
1795     MS_BOOL bRet = FALSE;
1796 
1797     APIAUDIO_CHECK_SHM_INIT;
1798 
1799     APIAUDIO_CHECK_INIT_FLAG(bRet);
1800     if (bRet == FALSE)
1801     {
1802         return;
1803     }
1804 
1805     switch ( enDecComamnd )
1806     {
1807         //////////////////////////////////////////////////////
1808         //
1809         //     Command for Audio decoder 1
1810         //
1811         //////////////////////////////////////////////////////
1812         case MSAPI_AUD_DVB_DECCMD_PLAY:
1813             enDecoderStatus = MSAPI_AUD_DVB_DECCMD_PLAY;
1814             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAY);
1815             break;
1816 
1817         case MSAPI_AUD_DVB_DECCMD_STOP:
1818             enDecoderStatus = MSAPI_AUD_DVB_DECCMD_STOP;
1819             g_AudioVars2->g_bMMPlayFlag = FALSE;
1820             u8IntTag = 1;
1821             MDrv_AUDIO_SetPlayFileFlag(DSP_DEC, 0);    // Clear file mode interrupt variable
1822             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_STOP);
1823             break;
1824 
1825         case MSAPI_AUD_DVB_DECCMD_RESYNC:
1826             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_RESYNC);
1827             break;
1828 
1829         case MSAPI_AUD_DVB_DECCMD_FREE_RUN:
1830             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_FREERUN);
1831             break;
1832 
1833         case MSAPI_AUD_DVB_DECCMD_AVSYNC:
1834             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_AVSYNC);
1835             break;
1836 
1837         case MSAPI_AUD_DVB_DECCMD_PLAYFILE:     // start/continue playing file based audio in MHEG5
1838             MDrv_AUDIO_HDMI_AC3_PathCFG(FALSE);
1839             g_AudioVars2->g_bMMPlayFlag = TRUE;
1840             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAYFILE);
1841             break;
1842 
1843         case MSAPI_AUD_DVB_DECCMD_PAUSE:    // pause playing file based audio in MHEG5
1844             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PAUSE);
1845             break;
1846 
1847         case MSAPI_AUD_DVB_DECCMD_PLAYFILETSP:     // start/continue playing file based audio in MHEG5
1848             MDrv_AUDIO_HDMI_AC3_PathCFG(FALSE);
1849             g_AudioVars2->g_bMMPlayFlag = TRUE;
1850             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAYFILETSP);
1851             break;
1852 
1853         case MSAPI_AUD_DVB_DECCMD_STARTBROWSE:
1854             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_STARTBROWSE);
1855             break;
1856 
1857         case MSAPI_AUD_DVB_DECCMD_PLAYFRAME:
1858                 g_AudioVars2->u16DecodeFrmCnt[AU_DEC_ID1] = 0;
1859             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAYFRAME);
1860             break;
1861 
1862         case MSAPI_AUD_DVB_DECCMD_PLAYFRAME_STAGE:
1863                 g_AudioVars2->u16DecodeFrmCnt[AU_DEC_ID1] = 0;
1864             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAYFRAME_STAGE);
1865             break;
1866 
1867         case MSAPI_AUD_DVB_DECCMD_PLAYFRAME_GS:
1868                 g_AudioVars2->u16DecodeFrmCnt[AU_DEC_ID1] = 0;
1869             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAYFRAME_GS);
1870             break;
1871 
1872         case MSAPI_AUD_DVB_DECCMD_PLAYMM_FILE2:
1873             MDrv_AUDIO_HDMI_AC3_PathCFG(FALSE);
1874             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAYFILE2_PTS);
1875             break;
1876 
1877         case MSAPI_AUD_DVB_DECCMD_SKIP:
1878             MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_SKIP);
1879             break;
1880         //////////////////////////////////////////////////////
1881         //
1882         //     Command for Audio decoder 2
1883         //
1884         //////////////////////////////////////////////////////
1885         case MSAPI_AUD_DVB2_DECCMD_PLAY:
1886             MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD_PLAY);
1887             break;
1888 
1889         case MSAPI_AUD_DVB2_DECCMD_STOP:
1890             MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD_STOP);
1891             break;
1892 
1893         case MSAPI_AUD_DVB2_DECCMD_RESYNC:
1894             MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD_RESYNC);
1895             break;
1896 
1897         case MSAPI_AUD_DVB2_DECCMD_FREE_RUN:
1898             MDrv_MAD2_SetFreeRun(AU_DVB2_FreeRunMode_FreeRun);
1899             break;
1900 
1901         case MSAPI_AUD_DVB2_DECCMD_AVSYNC:
1902             MDrv_MAD2_SetFreeRun(AU_DVB2_FreeRunMode_AVsync);
1903             break;
1904 
1905         case MSAPI_AUD_DVB2_DECCMD_PLAYFILE:     // start/continue playing file based audio in MHEG5
1906             MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD_PLAYFILE);
1907             break;
1908 
1909         case MSAPI_AUD_DVB2_DECCMD_PAUSE:    // pause playing file based audio in MHEG5
1910             MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD_PAUSE);
1911             break;
1912 
1913         case MSAPI_AUD_DVB2_DECCMD_PLAYFILETSP:     // start/continue playing file based audio in MHEG5
1914             MDrv_MAD2_SetDecCmd(AU_DVB2_DECCMD_PLAYFILETSP);
1915             break;
1916 
1917         default:
1918             break;
1919     }
1920 }
1921 
1922 ///////////////////////////////////////////////////////////////////////////////////////
1923 /// @brief \b Function \b Name: MApi_AUDIO_GetCommand()
1924 /// @brief \b Function \b Description: This routine is to get  the DVB1 decode command.
1925 /// @return AU_DVB_DECCMD \b :
1926 ///                          - AU_DVB_DECCMD_STOP,        //0
1927 ///                         - AU_DVB_DECCMD_PLAY,        //1
1928 ///                         - AU_DVB_DECCMD_PLAYFILETSP, //2
1929 ///                          - AU_DVB_DECCMD_RESYNC,
1930 ///                                 ....etc
1931 ///////////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetCommand(En_DVB_AudioDecoder AdoDecoderNo)1932 AU_DVB_DECCMD _MApi_AUDIO_GetCommand(En_DVB_AudioDecoder AdoDecoderNo)
1933 {
1934     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1935 
1936     if ((AdoDecoderNo != DVB_Audio_Decoder1) && (AdoDecoderNo != DVB_Audio_Decoder2))
1937     {
1938         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] Error! Not support AdoDecoderNo(%u)!\n", __FUNCTION__,AdoDecoderNo);
1939         return 0;
1940     }
1941 
1942     return MDrv_MAD_GetDecCmd(AdoDecoderNo);
1943 }
1944 
1945 ////////////////////////////////////////////////////////////////////////////////
1946 /// @brief \b Function \b Name: MApi_AUDIO_GetMAD_LOCK()
1947 /// @brief \b Function \b Description: This routine is used to report decoder lock information.
1948 /// @retun MS_U8      \b the decoder status
1949 ///////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetMAD_LOCK(void)1950 MS_BOOL _MApi_AUDIO_GetMAD_LOCK(void)
1951 {
1952     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1953 
1954     MS_U8   lock_id_reg = 0;
1955     MS_BOOL mad_lock_status = FALSE;
1956 
1957     lock_id_reg = MDrv_MAD_Rpt_DTVES() & 0x0F;
1958 
1959     if (lock_id_reg == 0x0)
1960     {
1961         mad_lock_status = FALSE;
1962     }
1963     else
1964     {
1965         mad_lock_status = TRUE;
1966     }
1967 
1968     return  mad_lock_status;
1969 }
1970 
1971 ////////////////////////////////////////////////////////////////////////////////
1972 /// @brief \b Function \b Name: MApi_AUDIO_SetADOutputMode()
1973 /// @brief \b Function \b Description: Set AD output mode
1974 /// @param out_mode    \b : out_mode:
1975 ///                       - AD_OUT_SPEAKER
1976 ///                       - AD_OUT_HP
1977 ///                       - AD_OUT_BOTH
1978 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetADOutputMode(MS_U8 out_mode)1979 void _MApi_AUDIO_SetADOutputMode (MS_U8 out_mode)
1980 {
1981     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
1982 
1983     switch (out_mode)
1984     {
1985     case AD_OUT_SPEAKER:
1986     case AD_OUT_HP:
1987     case AD_OUT_BOTH:
1988         MDrv_MAD_SetAdMixMode (AD_MIX_MAIN, MIX_ON);   // Decoder2 mix
1989         break;
1990 
1991     case AD_OUT_NONE:
1992     default:
1993         MDrv_MAD_SetAdMixMode (AD_MIX_MAIN, MIX_OFF);  // Decoder2 don't mix
1994         break;
1995     }
1996 }
1997 
1998 ////////////////////////////////////////////////////////////////////////////////
1999 /// @brief \b Function \b Name: MApi_AUDIO_SetADAbsoluteVolume()
2000 /// @brief \b Function \b Description: This routine is used to set the absolute u8Volume of AD.
2001 /// @param AbsVolume   \b : MSB 7-bit register value of 10-bit u8Volume
2002 ///                         range from 0x00 to 0x7E , gain: +12db to   -114db (-1 db per step)
2003 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetADAbsoluteVolume(MS_U8 AbsVolume)2004 void _MApi_AUDIO_SetADAbsoluteVolume (MS_U8 AbsVolume)
2005 {
2006     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2007 
2008     MDrv_SOUND_SetAdAbsoluteVolume(AbsVolume, 0);
2009 }
2010 
2011 
2012 ////////////////////////////////////////////////////////////////////////////////
2013 /// @brief \b Function \b Name: MApi_AUDIO_ADSetMute()
2014 /// @brief \b Function \b Description: This routine is used to set AD mute.
2015 /// @param EnMute      \b :     TRUE --Mute AD;
2016 ///                             FALSE--Unmute AD
2017 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ADSetMute(MS_BOOL EnMute)2018 void _MApi_AUDIO_ADSetMute(MS_BOOL EnMute)
2019 {
2020     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2021 
2022     MDrv_SOUND_SetAdMute(EnMute);
2023 }
2024 
2025 ////////////////////////////////////////////////////////////////////////////////
2026 ////////////////////////////////////////////////////////////////////////////////
2027 ////////////////////////////////////////////////////////////////////////////////
2028 //
2029 //           AUDIO_PVR RELATIONAL API FUNCTION
2030 //
2031 ////////////////////////////////////////////////////////////////////////////////
2032 ////////////////////////////////////////////////////////////////////////////////
2033 ////////////////////////////////////////////////////////////////////////////////
2034 
2035 ////////////////////////////////////////////////////////////////////////////////
2036 /// @brief \b Function \b Name: MDrv_AUDIO_SetEncodeInit()
2037 /// @brief \b Function \b Description:  This function is used to set Encod init
2038 /// @param BitRate \b :   Encode Output Bitrate
2039 ///                      -  AU_DVB_ENCBR_192K,    // 0
2040 ///                      -  AU_DVB_ENCBR_384K,    // 1
2041 ///                      -  AU_DVB_ENCBR_128K,    // 2
2042 ///                      -  AU_DVB_ENCBR_64K      // 3
2043 /// @param EncFrameNum \b :   Frame number per interrupt
2044 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetEncInit(AU_DVB_ENCBR BitRate,MS_U8 u8EncFrameNum)2045 void _MApi_AUDIO_SetEncInit(AU_DVB_ENCBR BitRate, MS_U8 u8EncFrameNum)
2046 {
2047     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2048 
2049     MDrv_AUDIO_SetEncodeInit(BitRate, u8EncFrameNum);
2050 }
2051 
2052 ////////////////////////////////////////////////////////////////////////////////
2053 /// @brief \b Function   \b Name: MApi_AUDIO_SetEncCommand()
2054 /// @brief \b Function   \b Description: Set Encoder Command for Digital Audio module
2055 /// @param enEnccComamnd \b : Encoder command for DVB Audio
2056 ///                                       -   AU_DVB_ENCCMD_STOP,      //0
2057 ///                                       -   AU_DVB_ENCCMD_START      // 1
2058 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetEncCommand(AU_DVB_ENCCMD enEncComamnd)2059 void _MApi_AUDIO_SetEncCommand(AU_DVB_ENCCMD enEncComamnd)
2060 {
2061     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2062 
2063     MDrv_MAD_SetEncCmd(enEncComamnd);
2064 }
2065 
2066 ////////////////////////////////////////////////////////////////////////////////
2067 /// @brief \b Function \b Name: MDrv_AUDIO_GetEncodeFrameInfo()
2068 /// @brief \b Function \b Description:  This function is used to get the Encoded frame info
2069 /// @param input       \b EncFrameInfo:   structure to store encoded frame info
2070 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetEncodeFrameInfo(AU_DVB_ENC_FRAME_INFO * EncFrameInfo)2071 void _MApi_AUDIO_GetEncodeFrameInfo(AU_DVB_ENC_FRAME_INFO *EncFrameInfo)
2072 {
2073     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2074 
2075     MDrv_AUDIO_GetEncodeFrameInfo(EncFrameInfo);
2076 }
2077 
2078 ////////////////////////////////////////////////////////////////////////////////
2079 /// @brief \b Function \b Name: MApi_AUDIO_GetEncodeDoneFlag()
2080 /// @brief \b Function \b Description:  This function is used to get check encode done flag
2081 /// @param input       \b None
2082 /// @param output      \b BOOL  TRUE/FALSE
2083 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetEncodeDoneFlag(void)2084 MS_BOOL _MApi_AUDIO_GetEncodeDoneFlag(void)
2085 {
2086     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2087 
2088     return (MDrv_AUDIO_GetEncodeDoneFlag());
2089 }
2090 
2091 ////////////////////////////////////////////////////////////////////////////////
2092 ////////////////////////////////////////////////////////////////////////////////
2093 ////////////////////////////////////////////////////////////////////////////////
2094 //
2095 //           AUDIO_ATV RELATIONAL API FUNCTION
2096 //
2097 ////////////////////////////////////////////////////////////////////////////////
2098 ////////////////////////////////////////////////////////////////////////////////
2099 ////////////////////////////////////////////////////////////////////////////////
2100 
2101 ////////////////////////////////////////////////////////////////////////////////
2102 /// @brief \b Function \b Name: MApi_AUDIO_SIF_SetCommand()
2103 /// @brief \b Function \b Description: Set decoder Command for ATV module
2104 /// @param enDecComamnd \b : deccoder command for ATV AUDIO
2105 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_SendCmd(En_AUD_SIF_CmdType enAudSifCommand,MS_U8 comm_arg1,MS_U8 comm_arg2)2106 void _MApi_AUDIO_SIF_SendCmd(En_AUD_SIF_CmdType enAudSifCommand, MS_U8 comm_arg1, MS_U8 comm_arg2)
2107 {
2108     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2109 
2110     switch( enAudSifCommand )
2111     {
2112         case MSAPI_AUD_SIF_CMD_SET_STOP:
2113             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_STOP, NULL, NULL);
2114             break;
2115         case MSAPI_AUD_SIF_CMD_SET_PLAY:
2116             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_PLAY, NULL, NULL);
2117             break;
2118         case MSAPI_AUD_SIF_CMD_ENABLE_HIDEV:
2119             // comm_arg1 = TRUE or FALSE.
2120             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_HIDEV, comm_arg1, NULL);
2121             break;
2122         case MSAPI_AUD_SIF_CMD_SET_HIDEV_FILTER_BW_LEVEL:
2123             // comm_arg1 = MSAPI_AUD_SIF_HIDEV_FILTER_BW_L1 ~ MSAPI_AUD_SIF_HIDEV_FILTER_BW_L3 or MSAPI_AUD_SIF_HIDEV_FILTER_BW_DEFAULT
2124             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_HIDEV_FILTER_BW_LEVEL, comm_arg1, NULL);
2125             break;
2126         case MSAPI_AUD_SIF_CMD_RESET_FC_TRACKING:
2127             MDrv_SIF_SendCmd(AU_SIF_CMD_RESET_FC_TRACKING, NULL, NULL);
2128             break;
2129         case MSAPI_AUD_SIF_CMD_ENABLE_FC_TRACKING:
2130             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_FC_TRACKING, comm_arg1, NULL);
2131             break;
2132         case MSAPI_AUD_SIF_CMD_SET_ADC_FROM_VIF_PATH:
2133             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_ADC_FROM_VIF_PATH, comm_arg1, comm_arg2);
2134             break;
2135         case MSAPI_AUD_SIF_CMD_ENABLE_AUTO_MUTE:
2136             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_AUTO_MUTE, comm_arg1, NULL);
2137             break;
2138         case MSAPI_AUD_SIF_CMD_ENABLE_AUTO_SOUNDMODE:
2139             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_AUTO_SOUNDMODE, comm_arg1, NULL);
2140             break;
2141         case MSAPI_AUD_SIF_CMD_ENABLE_BEEPER_FUNCTION:
2142             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_BEEPER_FUNCTION, comm_arg1, comm_arg2);
2143             break;
2144         case MSAPI_AUD_SIF_CMD_SET_BEEPER_TONE:
2145             // comm_arg1 = tone, comm_arg2 = volume
2146             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_BEEPER_TONE, comm_arg1, comm_arg2);
2147             break;
2148         case MSAPI_AUD_SIF_CMD_ENABLE_AGC:
2149             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_AGC, comm_arg1, comm_arg2);
2150             break;
2151         case MSAPI_AUD_SIF_CMD_RESET_AGC:
2152             MDrv_SIF_SendCmd(AU_SIF_CMD_RESET_AGC, comm_arg1, comm_arg2);
2153             break;
2154         case MSAPI_AUD_SIF_STANDARD_RESET:
2155             MDrv_SIF_SendCmd(AU_SIF_CMD_STANDARD_RESET, NULL, NULL);
2156             break;
2157         case MSAPI_AUD_SIF_CMD_DETECT_MAIN_STD_ONLY:
2158             MDrv_SIF_SendCmd(AU_SIF_CMD_DETECT_MAIN_STD_ONLY, comm_arg1, NULL);
2159             break;
2160         case MSAPI_AUD_SIF_CMD_FMTX_SET_PREEMP:
2161             MDrv_SIF_SendCmd(AU_SIF_CMD_FMTX_SET_PREEMP, comm_arg1, NULL);
2162             break;
2163         case MSAPI_AUD_SIF_CMD_SET_ENC_CMD:
2164             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_ENC_CMD, comm_arg1, NULL);
2165             break;
2166         case MSAPI_AUD_SIF_CMD_SET_ENC_Input_attenuation:
2167             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_ENC_Input_attenuation, comm_arg1, comm_arg2);
2168             break;
2169         case MSAPI_AUD_SIF_CMD_SET_ENC_Output_scaling:
2170             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_ENC_Output_scaling, comm_arg1, comm_arg2);
2171             break;
2172         case MSAPI_AUD_SIF_CMD_SET_BTSC_Enc_M_Gain:
2173             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_BTSC_Enc_M_Gain, comm_arg1, comm_arg2);
2174             break;
2175         case MSAPI_AUD_SIF_CMD_SET_BTSC_Enc_D_Gain:
2176             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_BTSC_Enc_D_Gain, comm_arg1, comm_arg2);
2177             break;
2178         case MSAPI_AUD_SIF_CMD_SET_BTSC_Enc_SAP_Gain:
2179             MDrv_SIF_SendCmd(AU_SIF_CMD_SET_BTSC_Enc_SAP_Gain, comm_arg1, comm_arg2);
2180             break;
2181         default:
2182             break;
2183     }
2184 }
2185 
2186 //******************************************************************************
2187 //Function name:    MApi_AUDIO_SIF_SetPrescale
2188 //Passing  para:    gain_type:  MSAPI_BTSC_GAIN
2189 //                          MSAPI_FM_StdM_GAIN
2190 //                  db_value:   The prescale value, unit is 0.25dB.
2191 //                                  0: 0db, 1:  0.25dB,  2:  0.5dB, ...,   4: 1.0dB, ...,   8:  2dB
2192 //                              -1:-0.25dB, -2:-0.5dB, ..., -4:-1.0dB, ..., -8:-2dB
2193 //Return parameter: none
2194 //Description:          SIF output level = (original level add db_value gain)
2195 //******************************************************************************
_MApi_AUDIO_SIF_SetPrescale(MS_U8 gain_type,MS_S32 db_value)2196 void _MApi_AUDIO_SIF_SetPrescale(MS_U8 gain_type, MS_S32 db_value)
2197 {
2198     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2199 
2200     MDrv_SIF_SetPrescale((AUDIO_SIF_GAIN_TYPE)gain_type, db_value);
2201 }
2202 
2203 
2204 ////////////////////////////////////////////////////////////////////////////////
2205 /// @brief \b Function \b Name: MApi_AUDIO_SIF_IsPALType()
2206 /// @brief \b Function \b Description: Check the DSP type is pal_type or not
2207 /// @return MS_BOOL    \b : TRUE/FALSE
2208 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_IsPALType(AUDIO_SIF_PAL_TYPE pal_type)2209 MS_BOOL _MApi_AUDIO_SIF_IsPALType(AUDIO_SIF_PAL_TYPE pal_type)
2210 {
2211     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2212 
2213     return MDrv_SIF_IsPALType(pal_type);
2214 }
2215 
2216 ////////////////////////////////////////////////////////////////////////////////
2217 /// @brief \b Function \b Name: MApi_AUDIO_SIF_SetPALType()
2218 /// @brief \b Function \b Description: Set DSP type to pal_type
2219 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_SetPALType(AUDIO_SIF_PAL_TYPE pal_type)2220 void _MApi_AUDIO_SIF_SetPALType(AUDIO_SIF_PAL_TYPE pal_type)
2221 {
2222     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2223 
2224     MDrv_SIF_SetPALType(pal_type);
2225 }
2226 
2227 ////////////////////////////////////////////////////////////////////////////////
2228 /// @brief \b Function \b Name: MApi_AUDIO_SIF_SetStandard()
2229 /// @brief \b Function \b Description: Set SIF standard
2230 /// @param system_type \b : standard type
2231 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_SetStandard(AUDIOSTANDARD_TYPE standard_type)2232 void _MApi_AUDIO_SIF_SetStandard(AUDIOSTANDARD_TYPE standard_type)
2233 {
2234     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2235 
2236     if (MDrv_SIF_CheckDecSys(MSAPI_AUD_ATV_PAL))
2237     {
2238         if(standard_type == E_AUDIOSTANDARD_L)
2239         {   // disable SIF AGC for AM
2240             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_AGC, FALSE, NULL);
2241             MDrv_SIF_SendCmd(AU_SIF_CMD_RESET_AGC, NULL, NULL);
2242         }
2243         else
2244         {
2245             MDrv_SIF_SendCmd(AU_SIF_CMD_ENABLE_AGC, TRUE, NULL);
2246         }
2247     }
2248 
2249     switch(standard_type)
2250     {
2251     case E_AUDIOSTANDARD_BG:
2252     case E_AUDIOSTANDARD_BG_A2:
2253         MDrv_SIF_SetStandardType(AU_SYS_BG_A2);
2254         break;
2255 
2256     case E_AUDIOSTANDARD_BG_NICAM:
2257         MDrv_SIF_SetStandardType(AU_SYS_BG_NICAM);
2258         break;
2259 
2260     case E_AUDIOSTANDARD_I:
2261         MDrv_SIF_SetStandardType(AU_SYS_I_NICAM);
2262         break;
2263 
2264     case E_AUDIOSTANDARD_DK:
2265     case E_AUDIOSTANDARD_DK1_A2:
2266         MDrv_SIF_SetStandardType(AU_SYS_DK1_A2);
2267         break;
2268 
2269     case E_AUDIOSTANDARD_DK2_A2:
2270         MDrv_SIF_SetStandardType(AU_SYS_DK2_A2);
2271         break;
2272 
2273     case E_AUDIOSTANDARD_DK3_A2:
2274         MDrv_SIF_SetStandardType(AU_SYS_DK3_A2);
2275         break;
2276 
2277     case E_AUDIOSTANDARD_DK_NICAM:
2278         MDrv_SIF_SetStandardType(AU_SYS_DK_NICAM);
2279         break;
2280 
2281     case E_AUDIOSTANDARD_L:
2282         MDrv_SIF_SetStandardType(AU_SYS_L_NICAM);
2283         break;
2284 
2285     case E_AUDIOSTANDARD_M:
2286     case E_AUDIOSTANDARD_M_A2:
2287         // MDrv_SIF_ReLoadCode(AU_SIF_PALSUM);
2288         MDrv_SIF_SetStandardType(AU_SYS_M_A2);
2289         break;
2290 
2291     case E_AUDIOSTANDARD_M_BTSC:
2292         MDrv_SIF_SetSystem(MSAPI_AUD_ATV_BTSC);
2293         MDrv_SIF_SetStandardType(AU_SYS_M_BTSC);
2294         break;
2295 
2296     case E_AUDIOSTANDARD_M_EIA_J:
2297         MDrv_SIF_SetSystem(MSAPI_AUD_ATV_EIAJ);
2298         MDrv_SIF_SetStandardType(AU_SYS_M_EIAJ);
2299         break;
2300 
2301     default:
2302         return;
2303     }
2304 
2305     m_eSifStandard = standard_type;
2306 }
2307 
2308 ////////////////////////////////////////////////////////////////////////////////
2309 /// @brief \b Function \b Name: MApi_AUDIO_SIF_SetSoundMode()
2310 /// @brief \b Function \b Description: Set sound mode for ATV source.
2311 /// @param u8SifSoundMode  \b : sound mode type
2312 ///                           - AU_MODE_MONO
2313 ///                           - AU_MODE_STEREO
2314 ///                           - AU_MODE_SAP
2315 ///                           - AU_MODE_LANG_A
2316 ///                           - AU_MODE_LANG_B
2317 ///                           - AU_MODE_NICAM_MONO, ...etc
2318 /// @return MS_BOOL    \b : success / fail
2319 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_SetSoundMode(MS_U8 u8SifSoundMode)2320 MS_BOOL _MApi_AUDIO_SIF_SetSoundMode(MS_U8 u8SifSoundMode)
2321 {
2322     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2323 
2324     switch(u8SifSoundMode)
2325     {
2326         case E_AUDIOMODE_MONO:
2327         case E_AUDIOMODE_FORCED_MONO:
2328             MDrv_SIF_SetSoundMode(AU_MODE_MONO);
2329             break;
2330 
2331         case E_AUDIOMODE_G_STEREO:
2332         case E_AUDIOMODE_K_STEREO:
2333             MDrv_SIF_SetSoundMode(AU_MODE_STEREO);
2334             break;
2335 
2336         case E_AUDIOMODE_MONO_SAP:
2337         case E_AUDIOMODE_STEREO_SAP:
2338             MDrv_SIF_SetSoundMode(AU_MODE_SAP);
2339             break;
2340 
2341         case E_AUDIOMODE_DUAL_A:
2342             MDrv_SIF_SetSoundMode(AU_MODE_LANG_A);
2343             break;
2344 
2345         case E_AUDIOMODE_DUAL_B:
2346             MDrv_SIF_SetSoundMode(AU_MODE_LANG_B);
2347             break;
2348 
2349         case E_AUDIOMODE_DUAL_AB:
2350             MDrv_SIF_SetSoundMode(AU_MODE_LANG_AB);
2351             break;
2352 
2353         case E_AUDIOMODE_NICAM_MONO:
2354             MDrv_SIF_SetSoundMode(AU_MODE_NICAM_MONO);
2355             break;
2356 
2357         case E_AUDIOMODE_NICAM_STEREO:
2358             MDrv_SIF_SetSoundMode(AU_MODE_STEREO);
2359             break;
2360 
2361         case E_AUDIOMODE_NICAM_DUAL_A:
2362             MDrv_SIF_SetSoundMode(AU_MODE_LANG_A);
2363             break;
2364 
2365         case E_AUDIOMODE_NICAM_DUAL_B:
2366             MDrv_SIF_SetSoundMode(AU_MODE_LANG_B);
2367             break;
2368 
2369         case E_AUDIOMODE_NICAM_DUAL_AB:
2370             MDrv_SIF_SetSoundMode(AU_MODE_LANG_AB);
2371             break;
2372 
2373         case E_AUDIOMODE_LEFT_LEFT:
2374             MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_SoundMode, MSAPI_AUD_MODE_LL, 0);
2375             break;
2376 
2377         case E_AUDIOMODE_RIGHT_RIGHT:
2378             MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_SoundMode, MSAPI_AUD_MODE_RR, 0);
2379             break;
2380 
2381         case E_AUDIOMODE_LEFT_RIGHT:
2382             MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_SoundMode, MSAPI_AUD_MODE_STEREO, 0);
2383             break;
2384         default:
2385             break;
2386 
2387     }
2388     return TRUE;
2389 }
2390 
2391 ////////////////////////////////////////////////////////////////////////////////
2392 /// @brief \b Function \b Name: MApi_AUDIO_SIF_GetSoundMode()
2393 /// @brief \b Function \b Description: Get SIF BTSC sound mode type
2394 /// @return MS_U8      \b : Sound mode type
2395 ///                       - MS_U8 = 0x0 : Mute
2396 ///                       - bit 0 : Mono
2397 ///                       - bit 1 : Stereo
2398 ///                       - bit 2 : SAP
2399 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_GetSoundMode(void)2400 MS_U8 _MApi_AUDIO_SIF_GetSoundMode(void)
2401 {
2402     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2403 
2404     AUDIOSTATUS eCurrentAudioStatus;
2405 
2406     if ((m_eSifStandard ==E_AUDIOSTANDARD_M_A2)||(m_eSifStandard ==E_AUDIOSTANDARD_M_EIA_J)||(m_eSifStandard ==E_AUDIOSTANDARD_M_BTSC))
2407         _MApi_AUDIO_SIF_GetAudioStatus(&eCurrentAudioStatus);
2408 
2409     eCurrentAudioStatus = E_STATE_AUDIO_NO_CARRIER;
2410 
2411     // coverity 8854
2412     if (m_eSifStatus & E_STATE_AUDIO_PRIMARY_CARRIER)
2413         eCurrentAudioStatus |= E_STATE_AUDIO_PRIMARY_CARRIER;
2414 
2415     if (m_eSifStatus & E_STATE_AUDIO_SECONDARY_CARRIER)
2416         eCurrentAudioStatus |= E_STATE_AUDIO_SECONDARY_CARRIER;
2417 
2418     if (m_eSifStatus & E_STATE_AUDIO_NICAM)
2419         eCurrentAudioStatus |= E_STATE_AUDIO_NICAM;
2420 
2421     if (m_eSifStatus & E_STATE_AUDIO_STEREO)
2422         eCurrentAudioStatus |= E_STATE_AUDIO_STEREO;
2423 
2424     if (m_eSifStatus & E_STATE_AUDIO_BILINGUAL)
2425         eCurrentAudioStatus |= E_STATE_AUDIO_BILINGUAL;
2426 
2427     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "\r\n MApi_AUDIO_SIF_GetSoundMode standard= %x",m_eSifStandard);
2428     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "\r\n eCurrentAudioStatus= %x",eCurrentAudioStatus);
2429     switch( m_eSifStandard )
2430     {
2431         case E_AUDIOSTANDARD_M_A2:
2432         case E_AUDIOSTANDARD_M_EIA_J:
2433             if ((eCurrentAudioStatus == E_STATE_AUDIO_PRIMARY_CARRIER) ||
2434                 (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_SECONDARY_CARRIER)) )
2435             {
2436                 return E_AUDIOMODE_MONO;
2437             }
2438             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_SECONDARY_CARRIER|E_STATE_AUDIO_STEREO) )
2439             {
2440                 return E_AUDIOMODE_K_STEREO;
2441             }
2442             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_SECONDARY_CARRIER|E_STATE_AUDIO_BILINGUAL) )
2443             {
2444                 return E_AUDIOMODE_DUAL_A;
2445             }
2446 
2447             return E_AUDIOMODE_INVALID;
2448 
2449         case E_AUDIOSTANDARD_M_BTSC:
2450             if(eCurrentAudioStatus == E_STATE_AUDIO_PRIMARY_CARRIER)
2451             {
2452                 return E_AUDIOMODE_MONO;
2453             }
2454             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_STEREO))
2455             {
2456                 return E_AUDIOMODE_K_STEREO;//E_AUDIOMODE_K_STEREO;
2457             }
2458             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_BILINGUAL) )
2459             {
2460                 return E_AUDIOMODE_MONO_SAP;
2461             }
2462             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_STEREO|E_STATE_AUDIO_BILINGUAL) )
2463             {
2464                 return E_AUDIOMODE_STEREO_SAP;
2465             }
2466             return E_AUDIOMODE_INVALID;
2467 
2468         default:
2469             if ((eCurrentAudioStatus == E_STATE_AUDIO_PRIMARY_CARRIER) ||
2470                 (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_SECONDARY_CARRIER)) )
2471             {
2472                 return E_AUDIOMODE_MONO;
2473             }
2474             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_SECONDARY_CARRIER|E_STATE_AUDIO_STEREO) )
2475             {
2476                 return E_AUDIOMODE_G_STEREO;
2477             }
2478             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_SECONDARY_CARRIER|E_STATE_AUDIO_BILINGUAL) )
2479             {
2480                 return E_AUDIOMODE_DUAL_A;
2481             }
2482             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_NICAM) )
2483             {
2484                 return E_AUDIOMODE_NICAM_MONO;
2485             }
2486             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_NICAM|E_STATE_AUDIO_STEREO) )
2487             {
2488                 return E_AUDIOMODE_NICAM_STEREO;
2489             }
2490             else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_NICAM|E_STATE_AUDIO_BILINGUAL) )
2491             {
2492                 return E_AUDIOMODE_NICAM_DUAL_A;
2493             }
2494 
2495             return E_AUDIOMODE_INVALID;
2496     }
2497 }
2498 
2499 ////////////////////////////////////////////////////////////////////////////////
2500 /// @brief \b Function \b Name: MApi_AUDIO_SIF_GetAudioStatus()
2501 /// @brief \b Function \b Description: Get the current audio status.
2502 ///                                    It can be used for getting available sound modes and real-time audio standard monitor.
2503 /// @param eAudioStatus \b : audio status pointer
2504 /// @return MS_BOOL     \b : TRUE/FALSE
2505 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_GetAudioStatus(AUDIOSTATUS * eAudioStatus)2506 MS_BOOL _MApi_AUDIO_SIF_GetAudioStatus(AUDIOSTATUS * eAudioStatus)
2507 {
2508     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2509 
2510     MS_U8 ucValue;
2511     m_eSifStatus = E_STATE_AUDIO_NO_CARRIER;
2512 
2513     if (MDrv_SIF_CheckDecSys(MSAPI_AUD_ATV_BTSC))
2514     {
2515         ucValue = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_BTSC_MODE_STATUS, NULL, NULL);
2516 
2517         if (ucValue & _STATUS_MOD_MONO_EXIST)
2518             m_eSifStatus = E_STATE_AUDIO_PRIMARY_CARRIER;
2519         if (ucValue & _STATUS_MOD_STEREO_EXIST)
2520             m_eSifStatus |= E_STATE_AUDIO_STEREO;
2521         if (ucValue & _STATUS_MOD_DUAL_EXIST)
2522             m_eSifStatus |= E_STATE_AUDIO_BILINGUAL;
2523 
2524         *eAudioStatus = m_eSifStatus;
2525         return TRUE;
2526     }
2527 
2528     if (MDrv_SIF_IsPALType(AU_SIF_PAL_A2)) {
2529         ucValue = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL);
2530 
2531         if( (ucValue & _STATUS_MOD_A2_PRIMARY_EXIST) != _STATUS_MOD_A2_PRIMARY_EXIST )
2532         {
2533             *eAudioStatus = E_STATE_AUDIO_NO_CARRIER;
2534             //debugASPPrint("E_STATE_AUDIO_NO_CARRIER\r\n",0);
2535             return TRUE;
2536         }
2537 
2538         m_eSifStatus = E_STATE_AUDIO_PRIMARY_CARRIER;
2539 
2540         if( ucValue & _STATUS_MOD_A2_SECONDARY_EXIST )
2541             m_eSifStatus |= E_STATE_AUDIO_SECONDARY_CARRIER;
2542         else
2543         {
2544             *eAudioStatus = m_eSifStatus;
2545             return TRUE;
2546         }
2547 
2548         if(ucValue & _STATUS_MOD_A2_PILOT_EXIST)
2549             m_eSifStatus |= E_STATE_AUDIO_PILOT;
2550         else
2551         {
2552                 *eAudioStatus = m_eSifStatus;
2553                 return TRUE;
2554         }
2555 
2556         if( ucValue & _STATUS_MOD_STEREO_EXIST )
2557             m_eSifStatus |= E_STATE_AUDIO_STEREO;
2558         else if( ucValue & _STATUS_MOD_DUAL_EXIST )
2559             m_eSifStatus |= E_STATE_AUDIO_BILINGUAL;
2560 
2561         *eAudioStatus = m_eSifStatus;
2562 
2563         return TRUE;
2564     }
2565     else if (MDrv_SIF_IsPALType(AU_SIF_PAL_NICAM)) {
2566         ucValue = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_NICAM_MODE_STATUS, NULL, NULL);
2567 
2568         if ((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_MONO_NOT_EXIST )
2569         {
2570             *eAudioStatus = E_STATE_AUDIO_NO_CARRIER;
2571             //debugASPPrint("E_STATE_AUDIO_NO_CARRIER1\r\n",0);
2572             return TRUE;
2573         }
2574 
2575         m_eSifStatus = E_STATE_AUDIO_PRIMARY_CARRIER;
2576 
2577         if ((ucValue & _MASK_NICAM_STATUS_INFO) != _NICAM_SOUND_MODE_LOCK_STATE )
2578         {
2579             *eAudioStatus = m_eSifStatus;
2580             return TRUE;
2581         }
2582 
2583         m_eSifStatus |= E_STATE_AUDIO_NICAM;
2584 
2585         if (((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_NICAM_STEREO) ||
2586             ((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_MONO_n_NICAM_STEREO) )
2587         {
2588             m_eSifStatus |= E_STATE_AUDIO_STEREO;
2589         }
2590         else if (((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_NICAM_DUAL) ||
2591                  ((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_MONO_n_NICAM_DUAL) )
2592         {
2593             m_eSifStatus |= E_STATE_AUDIO_BILINGUAL;
2594         }
2595 
2596         *eAudioStatus = m_eSifStatus;
2597 
2598         return TRUE;
2599     }
2600     else {
2601         ucValue = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL);
2602 
2603         if ((ucValue & _STATUS_MOD_A2_PRIMARY_EXIST) != _STATUS_MOD_A2_PRIMARY_EXIST )
2604         {
2605             *eAudioStatus = E_STATE_AUDIO_NO_CARRIER;
2606             //debugASPPrint("E_STATE_AUDIO_NO_CARRIER4\r\n",0);
2607             return TRUE;
2608         }
2609 
2610         m_eSifStatus = E_STATE_AUDIO_PRIMARY_CARRIER;
2611 
2612         if (ucValue & _STATUS_MOD_A2_SECONDARY_EXIST )
2613             m_eSifStatus |= E_STATE_AUDIO_SECONDARY_CARRIER;
2614         else
2615         {
2616             ucValue = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_NICAM_MODE_STATUS, NULL, NULL);
2617 
2618             if ((ucValue & _MASK_NICAM_STATUS_INFO) != _NICAM_SOUND_MODE_LOCK_STATE )
2619             {
2620                 *eAudioStatus = m_eSifStatus;
2621                 return TRUE;
2622             }
2623 
2624             m_eSifStatus |= E_STATE_AUDIO_NICAM;
2625 
2626             if (((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_NICAM_STEREO) ||
2627                 ((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_MONO_n_NICAM_STEREO) )
2628             {
2629                 m_eSifStatus |= E_STATE_AUDIO_STEREO;
2630             }
2631             else if (((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_NICAM_DUAL) ||
2632                      ((ucValue & _MASK_NICAM_SOUND_MODE_INFO) == _NICAM_SOUND_MOD_MONO_n_NICAM_DUAL) )
2633             {
2634                 m_eSifStatus |= E_STATE_AUDIO_BILINGUAL;
2635             }
2636 
2637             *eAudioStatus = m_eSifStatus;
2638 
2639             return TRUE;
2640         }
2641 
2642         //Add pilot, DK2, DK3 status, C.P.Chen 2008/01/03
2643         if (ucValue & _STATUS_MOD_A2_PILOT_EXIST)
2644             m_eSifStatus |= E_STATE_AUDIO_PILOT;
2645         else
2646         {
2647             *eAudioStatus = m_eSifStatus;
2648             return TRUE;
2649         }
2650 
2651         if (ucValue & _STATUS_MOD_A2_DK2_EXIST)
2652             m_eSifStatus |= E_STATE_AUDIO_DK2;
2653         else if( ucValue & _STATUS_MOD_A2_DK3_EXIST)
2654             m_eSifStatus |= E_STATE_AUDIO_DK3;
2655 
2656         if (ucValue & _STATUS_MOD_STEREO_EXIST )
2657             m_eSifStatus |= E_STATE_AUDIO_STEREO;
2658         else if( ucValue & _STATUS_MOD_DUAL_EXIST )
2659             m_eSifStatus |= E_STATE_AUDIO_BILINGUAL;
2660 
2661         *eAudioStatus = m_eSifStatus;
2662 
2663         return TRUE;
2664     }
2665 }
2666 
2667 ////////////////////////////////////////////////////////////////////////////////
2668 /// @brief \b Function \b Name: MApi_AUDIO_SIF_StartAutoStandardDetection()
2669 /// @brief \b Function \b Description: To start automatic detection about input audio standard
2670 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_StartAutoStandardDetection(void)2671 void _MApi_AUDIO_SIF_StartAutoStandardDetection(void)
2672 {
2673     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2674 
2675     if (m_eSifStandard != E_AUDIOSTANDARD_L)
2676     {
2677         MDrv_SIF_StartAutoDetection ();
2678     }
2679 }
2680 
2681 ////////////////////////////////////////////////////////////////////////////////
2682 /// @brief \b Function \b Name: MApi_AUDIO_SIF_GetResultOfAutoStandardDetection()
2683 /// @brief \b Function \b Description: To get result of audio standard after automatic detection called by MDrv_ASP_StartAutoStandardDetection.
2684 /// @return AUDIOSTANDARD_TYPE \b :
2685 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_GetResultOfAutoStandardDetection(void)2686 AUDIOSTANDARD_TYPE _MApi_AUDIO_SIF_GetResultOfAutoStandardDetection(void)
2687 {
2688     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2689 
2690     MS_U8 cResult, i=0;
2691     AUDIOSTANDARD_TYPE eStandard;
2692 
2693     cResult = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_STANDARD_STATUS, NULL, NULL);
2694 
2695     while(cResult==0x80)
2696     {
2697         i++;
2698         if(i>=40)
2699             break;
2700         MsOS_DelayTask(10);
2701         cResult = MDrv_SIF_SendCmd(AU_SIF_CMD_GET_STANDARD_STATUS, NULL, NULL);
2702     }
2703 
2704     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "AutoStandardDetection Check Times = %x\r\n",i);
2705 
2706     if (i>=40)
2707     {
2708         //debugASPPrint("Detected Audio NO Standard ",0);
2709         return E_AUDIOSTANDARD_NOTSTANDARD;
2710     }
2711     //debugASPPrint("Detected Audio System:0x%x",cResult);
2712 
2713     switch (cResult)
2714     {
2715     case _STD_SEL_M_BTSC:
2716         eStandard = E_AUDIOSTANDARD_M_BTSC;
2717         break;
2718 
2719     case _STD_SEL_M_EIAJ:
2720         eStandard = E_AUDIOSTANDARD_M_EIA_J;
2721         break;
2722 
2723     case _STD_SEL_M_A2:
2724         if( MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL) & _STATUS_MOD_A2_SECONDARY_EXIST )
2725             eStandard = E_AUDIOSTANDARD_M_A2;
2726         else
2727             eStandard = E_AUDIOSTANDARD_M;
2728         break;
2729 
2730     case _STD_SEL_BG_A2:
2731         if( MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL) & _STATUS_MOD_A2_SECONDARY_EXIST )
2732             eStandard = E_AUDIOSTANDARD_BG_A2;
2733         else
2734             eStandard = E_AUDIOSTANDARD_BG;
2735         break;
2736 
2737     case _STD_SEL_DK1_A2:
2738         if( MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL) & _STATUS_MOD_A2_SECONDARY_EXIST )
2739             eStandard = E_AUDIOSTANDARD_DK1_A2;
2740         else
2741             eStandard = E_AUDIOSTANDARD_DK;
2742         break;
2743 
2744     case _STD_SEL_DK2_A2:
2745         if( MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL) & _STATUS_MOD_A2_SECONDARY_EXIST )
2746             eStandard = E_AUDIOSTANDARD_DK2_A2;
2747         else
2748             eStandard = E_AUDIOSTANDARD_DK;
2749         break;
2750 
2751     case _STD_SEL_DK3_A2:
2752         if( MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_A2_MODE_STATUS, NULL, NULL) & _STATUS_MOD_A2_SECONDARY_EXIST )
2753             eStandard = E_AUDIOSTANDARD_DK3_A2;
2754         else
2755             eStandard = E_AUDIOSTANDARD_DK;
2756         break;
2757 
2758     case _STD_SEL_BG_NICAM:
2759         eStandard = E_AUDIOSTANDARD_BG_NICAM;
2760         break;
2761 
2762     case _STD_SEL_DK_NICAM:
2763         eStandard = E_AUDIOSTANDARD_DK_NICAM;
2764         break;
2765 
2766     case _STD_SEL_I_NICAM:
2767         eStandard = E_AUDIOSTANDARD_I;
2768         break;
2769 
2770     case _STD_SEL_L_NICAM:
2771         eStandard = E_AUDIOSTANDARD_L;
2772         break;
2773 
2774     default:
2775         eStandard = E_AUDIOSTANDARD_NOTSTANDARD;
2776         break;
2777     }
2778 
2779     return eStandard;
2780 }
2781 
2782 ////////////////////////////////////////////////////////////////////////////////
2783 /// @brief \b Function \b Name: MApi_AUDIO_SIF_ConvertToBasicAudioStandard()
2784 /// @brief \b Function \b Description: Convert the audio standard to the basic standard
2785 /// @param eStandard   \b : Please refer AUDIOSTANDARD_TYPE enum in header file
2786 /// @return AUDIOSTANDARD_TYPE \b : basic standard
2787 ///                               - E_AUDIOSTANDARD_BG
2788 ///                               - E_AUDIOSTANDARD_I
2789 ///                               - E_AUDIOSTANDARD_DK
2790 ///                               - E_AUDIOSTANDARD_L
2791 ///                               - E_AUDIOSTANDARD_M
2792 ///                               - E_AUDIOSTANDARD_NOTSTANDARD
2793 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_ConvertToBasicAudioStandard(AUDIOSTANDARD_TYPE eStandard)2794 AUDIOSTANDARD_TYPE _MApi_AUDIO_SIF_ConvertToBasicAudioStandard(AUDIOSTANDARD_TYPE eStandard)
2795 {
2796     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2797 
2798     switch(eStandard)
2799     {
2800     case E_AUDIOSTANDARD_BG:
2801     case E_AUDIOSTANDARD_BG_A2:
2802     case E_AUDIOSTANDARD_BG_NICAM:
2803         return E_AUDIOSTANDARD_BG;
2804 
2805     case E_AUDIOSTANDARD_I:
2806         return E_AUDIOSTANDARD_I;
2807 
2808     case E_AUDIOSTANDARD_DK:
2809     case E_AUDIOSTANDARD_DK1_A2:
2810     case E_AUDIOSTANDARD_DK2_A2:
2811     case E_AUDIOSTANDARD_DK3_A2:
2812     case E_AUDIOSTANDARD_DK_NICAM:
2813         return E_AUDIOSTANDARD_DK;
2814 
2815     case E_AUDIOSTANDARD_L:
2816         return E_AUDIOSTANDARD_L;
2817 
2818     case E_AUDIOSTANDARD_M:
2819     case E_AUDIOSTANDARD_M_A2:
2820     case E_AUDIOSTANDARD_M_BTSC:
2821     case E_AUDIOSTANDARD_M_EIA_J:
2822         return E_AUDIOSTANDARD_M;
2823     default:
2824         break;
2825     }
2826 
2827     return E_AUDIOSTANDARD_NOTSTANDARD;
2828 }
2829 
2830 ////////////////////////////////////////////////////////////////////////////////
2831 /// @brief \b Function \b Name: MApi_AUDIO_SIF_SetThreshold()
2832 /// @brief \b Function \b Description:  This routine is used to set SIF threshold
2833 /// @param ThrTbl  \b : SIF thresholds Table
2834 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SIF_SetThreshold(THR_TBL_TYPE * ThrTbl)2835 void _MApi_AUDIO_SIF_SetThreshold(THR_TBL_TYPE *ThrTbl)
2836 {
2837     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2838 
2839     if (MDrv_SIF_CheckDecSys(MSAPI_AUD_ATV_BTSC))
2840     {
2841        MDrv_SIF_SetThreshold(ThrTbl, BTSC_TBL_INDEX, BTSC_TBL_LENGTH, BTSC_STANDARD);
2842     }
2843     else if (MDrv_SIF_CheckDecSys(MSAPI_AUD_ATV_FM_RADIO))
2844     {
2845        MDrv_SIF_SetThreshold(ThrTbl, FM_RADIO_TBL_INDEX, FM_RADIO_TBL_LENGTH, FM_RADIO_STANDARD);
2846     }
2847     else if (MDrv_SIF_CheckDecSys(MSAPI_AUD_ATV_PAL))
2848     {
2849         MDrv_SIF_SetThreshold(ThrTbl, A2_M_TBL_INDEX, A2_M_TBL_LENGTH, A2_M_STANDARD);
2850         MDrv_SIF_SetThreshold(ThrTbl, A2_BG_TBL_INDEX, A2_BG_TBL_LENGTH, A2_BG_STANDARD);
2851         MDrv_SIF_SetThreshold(ThrTbl, A2_DK_TBL_INDEX, A2_DK_TBL_LENGTH, A2_DK_STANDARD);
2852         MDrv_SIF_SetThreshold(ThrTbl, FM_I_TBL_INDEX, FM_I_TBL_LENGTH, A2_I_STANDARD);
2853         MDrv_SIF_SetThreshold(ThrTbl, AM_TBL_INDEX, AM_TBL_LENGTH, AM_STANDARD);
2854         MDrv_SIF_SetThreshold(ThrTbl, NICAM_BG_TBL_INDEX, NICAM_BG_TBL_LENGTH, NICAM_BG_STANDARD);
2855         MDrv_SIF_SetThreshold(ThrTbl, NICAM_I_TBL_INDEX, NICAM_I_TBL_LENGTH, NICAM_I_STANDARD);
2856         MDrv_SIF_SetThreshold(ThrTbl, HIDEV_M_TBL_INDEX, HIDEV_M_TBL_LENGTH, HIDEV_M_STANDARD);
2857         MDrv_SIF_SetThreshold(ThrTbl, HIDEV_BG_TBL_INDEX, HIDEV_BG_TBL_LENGTH, HIDEV_BG_STANDARD);
2858         MDrv_SIF_SetThreshold(ThrTbl, HIDEV_DK_TBL_INDEX, HIDEV_DK_TBL_LENGTH, HIDEV_DK_STANDARD);
2859         MDrv_SIF_SetThreshold(ThrTbl, HIDEV_I_TBL_INDEX, HIDEV_I_TBL_LENGTH, HIDEV_I_STANDARD);
2860 
2861         if (((ThrTbl[HIDEV_I_TBL_INDEX+HIDEV_I_TBL_LENGTH].HiByteValue == 0x5A) && (ThrTbl[HIDEV_I_TBL_INDEX+HIDEV_I_TBL_LENGTH].LowByteValue == 0x5A))  &&
2862             ((ThrTbl[HIDEV_I_TBL_INDEX+HIDEV_I_TBL_LENGTH+1].HiByteValue == 0xA5) && (ThrTbl[HIDEV_I_TBL_INDEX+HIDEV_I_TBL_LENGTH+1].LowByteValue == 0xA5)))
2863         {
2864             MS_U16 value;
2865             MS_U16 i = HIDEV_I_TBL_INDEX+HIDEV_I_TBL_LENGTH+2;
2866             MS_U16 j = 0;
2867 
2868             // A2_M Extension threshold
2869             while (ThrTbl[i].HiByteValue != 0xFF)
2870             {
2871                 value = ( (0x00FF & ThrTbl[i].HiByteValue) <<8)|(0x00FF & ThrTbl[i].LowByteValue);
2872                 MDrv_SIF_AccessThreshold(A2_M_STANDARD|WRITE_THRESHOLD, A2_M_TBL_LENGTH+j, value);
2873                 i++;
2874                 j++;
2875             }
2876             i++;
2877             j = 0;
2878             // A2_BG Extension threshold
2879             while (ThrTbl[i].HiByteValue != 0xFF)
2880             {
2881                 value = ( (0x00FF & ThrTbl[i].HiByteValue) <<8)|(0x00FF & ThrTbl[i].LowByteValue);
2882                 MDrv_SIF_AccessThreshold(A2_BG_STANDARD|WRITE_THRESHOLD, A2_BG_TBL_LENGTH+j, value);
2883                 i++;
2884                 j++;
2885             }
2886             i++;
2887             j = 0;
2888             // A2_DK Extension threshold
2889             while (ThrTbl[i].HiByteValue != 0xFF)
2890             {
2891                 value = ( (0x00FF & ThrTbl[i].HiByteValue) <<8)|(0x00FF & ThrTbl[i].LowByteValue);
2892                 MDrv_SIF_AccessThreshold(A2_DK_STANDARD|WRITE_THRESHOLD, A2_DK_TBL_LENGTH+j, value);
2893                 i++;
2894                 j++;
2895             }
2896         }
2897     }
2898 }
2899 
2900 ////////////////////////////////////////////////////////////////////////////////
2901 //
2902 //        AUDIO_SPDIF RELATIONAL API FUNCTION
2903 //
2904 ////////////////////////////////////////////////////////////////////////////////
2905 
2906 ////////////////////////////////////////////////////////////////////////////////
2907 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_HWEN()
2908 /// @brief \b Function \b Description:  This routine is used to enable S/PDIF output (Hardware)
2909 /// @param spdif_en    \b :    0--Disable S/PDIF out;
2910 ///                            1--Enable S/PDIF out
2911 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_HWEN(MS_BOOL spdif_en)2912 void _MApi_AUDIO_SPDIF_HWEN(MS_BOOL spdif_en)
2913 {
2914     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2915 
2916     MDrv_AUDIO_SPDIF_HWEN(spdif_en);
2917 }
2918 
2919 ////////////////////////////////////////////////////////////////////////////////
2920 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_SetMute()
2921 /// @brief \b Function \b Description:  This routine is used to enable S/PDIF output (Hardware)
2922 /// @param mute_en     \b :    0--Disable mute;
2923 ///                            1--Enable mute
2924 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_SetMute(MS_BOOL mute_en)2925 void _MApi_AUDIO_SPDIF_SetMute(MS_BOOL mute_en)
2926 {
2927     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2928 
2929     MDrv_AUDIO_SPDIF_SetMute(mute_en);
2930 }
2931 
2932 ////////////////////////////////////////////////////////////////////////////////
2933 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_SetMode()
2934 /// @brief \b Function \b Description:  This routine is used to set S/PDIF mode.
2935 /// @param spdif_mode  \b : PCM or Non-PCM mode
2936 ///                - spdif_mode = 0x0 : SPDIF enable, PCM mode
2937 ///                - spdif_mode = 0x1 : SPDIF off
2938 ///                - spdif_mode = 0x2 : SPDIF enable, nonPCM mode
2939 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_SetMode(MS_U8 spdif_mode)2940 void _MApi_AUDIO_SPDIF_SetMode(MS_U8 spdif_mode)
2941 {
2942     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2943 
2944     MS_U8 u8Source = 0;
2945 
2946     APIAUDIO_CHECK_SHM_INIT;
2947 
2948     u8Source = (MS_U8)g_AudioVars2->eAudioSource;
2949     gSpdifOutputType = spdif_mode;
2950 
2951     MDrv_AUDIO_SPDIF_SetMode(spdif_mode, u8Source);
2952 }
2953 
2954 ////////////////////////////////////////////////////////////////////////////////
2955 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_GetMode()
2956 /// @brief \b Function \b Description:  This routine is used to get S/PDIF mode.
2957 /// @return MS_U8      \b :  register SPDIF_CTRL value
2958 ///                       - 0x0 : SPDIF enable, PCM mode
2959 ///                       - 0x1 : SPDIF OFF
2960 ///                       - 0x2 : SPDIF enable, non-PCM mode
2961 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_GetMode(void)2962 MS_U8 _MApi_AUDIO_SPDIF_GetMode(void)
2963 {
2964     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2965 
2966     return(MDrv_AUDIO_SPDIF_GetMode());
2967 }
2968 
2969 ////////////////////////////////////////////////////////////////////////////////
2970 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_SetSCMS()
2971 /// @brief \b Function \b Description:  This routine is used to set SPDIF SCMS.
2972 /// @param C_bit_en  \b : copy right control bit
2973 /// @param L_bit_en  \b : generation bit
2974 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_SetSCMS(MS_U8 C_bit_en,MS_U8 L_bit_en)2975 void _MApi_AUDIO_SPDIF_SetSCMS(MS_U8 C_bit_en, MS_U8 L_bit_en)
2976 {
2977     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2978 
2979     MDrv_AUDIO_SPDIF_SetSCMS(C_bit_en, L_bit_en);
2980 }
2981 
2982 ////////////////////////////////////////////////////////////////////////////////
2983 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_GetSCMS()
2984 /// @brief \b Function \b Description:  This routine is used to get SPDIF SCMS.
2985 /// @return MS_U8      \b :  SCMS[0] = C bit status, SCMS[1] = L bit status
2986 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_GetSCMS(void)2987 MS_U8 _MApi_AUDIO_SPDIF_GetSCMS(void)
2988 {
2989     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
2990 
2991     return(MDrv_AUDIO_SPDIF_GetSCMS());
2992 }
2993 
2994 ////////////////////////////////////////////////////////////////////////////////
2995 /// @brief \b Function \b Name: MApi_AUDIO_SPDIF_ChannelStatus_CTRL()
2996 /// @brief \b Function \b Description:
2997 /// @param pau_info    \b :  AUDIO INIT STRUCTURE
2998 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SPDIF_ChannelStatus_CTRL(AUDIO_SPDIF_CS_TYPE cs_mode,AUDIO_SPDIF_CS_TYPE_STATUS status)2999 MS_BOOL _MApi_AUDIO_SPDIF_ChannelStatus_CTRL(AUDIO_SPDIF_CS_TYPE cs_mode, AUDIO_SPDIF_CS_TYPE_STATUS status)
3000 {
3001     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3002 
3003     return(MDrv_AUDIO_SPDIF_ChannelStatus_CTRL(cs_mode, status));
3004 }
3005 
3006 ////////////////////////////////////////////////////////////////////////////////
3007 /// @brief \b Function \b Name: MApi_Audio_SPDIF_Monitor()
3008 /// @brief \b Function \b Description:
3009 /// @param pau_info    \b :  AUDIO INIT STRUCTURE
3010 ////////////////////////////////////////////////////////////////////////////////
_MApi_Audio_SPDIF_Monitor(void)3011 void _MApi_Audio_SPDIF_Monitor(void)
3012 {
3013     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3014 
3015     MS_BOOL bRet = FALSE;
3016 
3017     APIAUDIO_CHECK_INIT_FLAG(bRet);
3018     if (bRet == FALSE)
3019     {
3020         return;
3021     }
3022 
3023     if (g_bDSPLoadCode== TRUE)
3024     {
3025         return;
3026     }
3027 
3028     MDrv_AUD_Monitor_SPDIF_NONPCM_SmpRate();
3029 }
3030 
3031 ////////////////////////////////////////////////////////////////////////////////
3032 /// @brief \b Function \b Name: HAL_AUDIO_Digital_Out_SetChannelStatus()
3033 /// @brief \b Function \b Description: This routine is used to set SPDIF/HDMI/ARC channel status.
3034 /// @param <IN>        \b   eType   :
3035 /// @param <OUT>       \b NONE    :
3036 /// @param <RET>       \b NONE    :
3037 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DigitalOut_SetChannelStatus(DIGITAL_OUTPUT_TYPE ePath,Digital_Out_Channel_Status_t * stChannelStatus)3038 MS_BOOL _MApi_AUDIO_DigitalOut_SetChannelStatus(DIGITAL_OUTPUT_TYPE ePath, Digital_Out_Channel_Status_t *stChannelStatus)
3039 {
3040     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3041 
3042     return(Mdrv_AUDIO_DigitalOut_SetChannelStatus(ePath, stChannelStatus));
3043 }
3044 
3045 ////////////////////////////////////////////////////////////////////////////////
3046 /// @brief \b Function \b Name: MApi_AUDIO_DigitalOut_SetDeviceCapability()
3047 /// @brief \b Function \b Description: This routine is used to set output device capability.
3048 /// @param <IN>        \b eoutType: output type (ARC_OUTPUT or HDMI_OUTPUT)
3049 /// @param <IN>        \b ecodecType: kind of codec
3050 /// @param <IN>        \b *p_codecCapability: codec support capability structure
3051 /// @param <RET>       \b bRet: return api setting success or fail
3052 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DigitalOut_SetDeviceCapability(DIGITAL_OUTPUT_TYPE eoutType,AUDIO_FORMAT_CODE ecodecType,Digital_Out_Device_Capability_t * p_codecCapability)3053 MS_BOOL _MApi_AUDIO_DigitalOut_SetDeviceCapability(DIGITAL_OUTPUT_TYPE eoutType, AUDIO_FORMAT_CODE ecodecType, Digital_Out_Device_Capability_t *p_codecCapability)
3054 {
3055     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3056 
3057     APIAUDIO_CHECK_SHM_INIT;
3058     MS_BOOL bRet = FALSE;
3059 
3060     if(ecodecType>CODEC_MAX-1)
3061     {
3062         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Invalid ecodecType parameter\n", __FUNCTION__);
3063         return bRet;
3064     }
3065     switch(eoutType)
3066         {
3067         case DIGITAL_HDMI_ARC_OUTPUT:
3068             memcpy(&(g_AudioVars2->stDigitalOutCodecCapability[0][ecodecType]), p_codecCapability, sizeof(Digital_Out_Device_Capability_t));
3069             bRet = TRUE;
3070             break;
3071 
3072         case DIGITAL_HDMI_OUTPUT:
3073             memcpy(&(g_AudioVars2->stDigitalOutCodecCapability[1][ecodecType]), p_codecCapability, sizeof(Digital_Out_Device_Capability_t));
3074             bRet = TRUE;
3075             break;
3076 
3077         default:
3078             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Invalid eoutType parameter\n", __FUNCTION__);
3079             break;
3080         }
3081 
3082     return bRet;
3083 }
3084 
3085 ////////////////////////////////////////////////////////////////////////////////
3086 //
3087 //         AUDIO_HDMI RELATIONAL API FUNCTION
3088 //
3089 ////////////////////////////////////////////////////////////////////////////////
3090 ////////////////////////////////////////////////////////////////////////////////
3091 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_Tx_SetMute()
3092 /// @brief \b Function \b Description:  This routine is used to enable HDMI Tx output (Software)
3093 /// @param mute_en     \b :    0--Disable mute;
3094 ///                            1--Enable mute
3095 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_Tx_SetMute(MS_BOOL mute_en)3096 void _MApi_AUDIO_HDMI_Tx_SetMute(MS_BOOL mute_en)
3097 {
3098     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3099 
3100     MDrv_AUDIO_HDMI_Tx_SetMute(mute_en);
3101 }
3102 
3103 ////////////////////////////////////////////////////////////////////////////////
3104 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_Tx_GetStatus()
3105 /// @brief \b Function \b Description:  This routine is used to get HDMI Tx status
3106 /// @param onOff     \b : HDMI tx function is availible in this chip ?
3107 /// @param hdmi_SmpFreq \b : Audio current sample freq for tx
3108 /// @param outType \b   : PCM mode or nonPCM mode
3109 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_Tx_GetStatus(MS_BOOL * onOff,AUDIO_FS_TYPE * hdmi_SmpFreq,HDMI_TX_OUTPUT_TYPE * outType)3110 void _MApi_AUDIO_HDMI_Tx_GetStatus(MS_BOOL *onOff, AUDIO_FS_TYPE *hdmi_SmpFreq, HDMI_TX_OUTPUT_TYPE *outType )
3111 {
3112     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3113 
3114     if ((onOff == NULL) || (hdmi_SmpFreq == NULL) || (outType == NULL))
3115     {
3116         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s() : Invalid parameter\n", __FUNCTION__);
3117         return;
3118     }
3119 
3120     MDrv_AUDIO_HDMI_Tx_GetStatus( onOff, hdmi_SmpFreq, outType );
3121 }
3122 
3123 ////////////////////////////////////////////////////////////////////////////////
3124 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_Monitor()
3125 /// @brief \b Function \b Description: This function report HDMI non-PCM or PCM format (register STATUS_INPUT)
3126 /// @return MS_U8      \b :
3127 ///                     - non-PCM --> register STATUS_INPUT[7:6]= 0x1;
3128 ///                     - PCM   --> register STATUS_INPUT[7:6]= 0x0
3129 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_Monitor(void)3130 MS_U8 _MApi_AUDIO_HDMI_Monitor(void)
3131 {
3132     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3133 
3134     MS_BOOL bRet = FALSE;
3135 
3136     APIAUDIO_CHECK_INIT_FLAG(bRet);
3137     if (bRet == FALSE)
3138     {
3139         return bRet;
3140     }
3141 
3142     return((MS_U8)MDrv_AUDIO_HDMI_NonpcmMonitor());
3143 }
3144 
3145 ////////////////////////////////////////////////////////////////////////////////
3146 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_SetOutputType()
3147 /// @brief \b Function \b Description:  To set HDMI output type independently
3148 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_TX_SetMode(HDMI_TX_OUTPUT_TYPE outType)3149 void _MApi_AUDIO_HDMI_TX_SetMode(HDMI_TX_OUTPUT_TYPE outType)
3150 {
3151     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3152 
3153     APIAUDIO_CHECK_SHM_INIT;
3154 
3155     gHdmiOutputType = (outType & HDMI_OUT_NONPCM) ? HDMI_OUT_NONPCM : HDMI_OUT_PCM;
3156     MDrv_AUDIO_HDMI_TX_SetMode(outType, g_AudioVars2->eAudioSource);
3157 }
3158 
3159 ////////////////////////////////////////////////////////////////////////////////
3160 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_GetNonpcmFlag()
3161 /// @brief \b Function \b Description: This function report HDMI non-PCM or PCM format (register STATUS_INPUT)
3162 /// @return MS_BOOL    \b :
3163 ///                     - TRUE : non-PCM --> register STATUS_INPUT[7:6]= 0x1 ;
3164 ///                     - FALSE : PCM     --> register STATUS_INPUT[7:6]= 0x0
3165 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_GetNonpcmFlag(void)3166 MS_BOOL _MApi_AUDIO_HDMI_GetNonpcmFlag(void)
3167 {
3168     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3169 
3170     return(MDrv_AUDIO_HDMI_NonpcmMonitor());
3171 }
3172 
3173 ////////////////////////////////////////////////////////////////////////////////
3174 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_SetNonpcm()
3175 /// @brief \b Function \b Description: This function setting HDMI non-PCM or PCM relational register
3176 /// @param nonPCM_en   \b :    1: nonPCM; 0: PCM
3177 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_SetNonpcm(MS_U8 nonPCM_en)3178 void _MApi_AUDIO_HDMI_SetNonpcm(MS_U8 nonPCM_en)
3179 {
3180     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3181 
3182     MDrv_AUDIO_HDMI_SetNonpcm(nonPCM_en);
3183 }
3184 
3185 
3186 ////////////////////////////////////////////////////////////////////////////////
3187 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_RX_SetNonpcm()
3188 /// @brief \b Function \b Description: This function setting HDMI non-PCM or PCM relational register
3189 /// @param nonPCM_en   \b :    1: nonPCM; 0: PCM
3190 /// @return AUDIO_HDMI_RX_TYPE \b : Return HDMI RX Type
3191 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_RX_SetNonpcm(MS_U8 nonPCM_en)3192 AUDIO_HDMI_RX_TYPE _MApi_AUDIO_HDMI_RX_SetNonpcm(MS_U8 nonPCM_en)
3193 {
3194     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3195 
3196     return(MDrv_AUDIO_HDMI_SetNonpcm(nonPCM_en));
3197 }
3198 
3199 ////////////////////////////////////////////////////////////////////////////////
3200 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_RX_SetNonpcm()
3201 /// @brief \b Function \b Description: This function setting HDMI non-PCM or PCM relational register
3202 /// @param nonPCM_en   \b :    1: nonPCM; 0: PCM
3203 /// @return AUDIO_HDMI_RX_TYPE \b : Return HDMI RX Type
3204 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_RX_GetNonPCM(void)3205 AUDIO_HDMI_RX_TYPE _MApi_AUDIO_HDMI_RX_GetNonPCM(void)
3206 {
3207     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3208 
3209     MS_U8 HDMI_PC_Status;
3210     HDMI_PC_Status = MDrv_AUDIO_HDMI_DolbyMonitor();
3211 
3212     if(FALSE == MDrv_AUDIO_HDMI_NonpcmMonitor())
3213     {
3214         return(HDMI_RX_PCM);
3215     }
3216 
3217     if (HDMI_PC_Status == 0x1)
3218     {
3219         return(HDMI_RX_DD);
3220     }
3221     else if (HDMI_PC_Status == 0xB)
3222     {
3223         return(HDMI_RX_DTS);
3224     }
3225     else if (HDMI_PC_Status == 0x15)
3226     {
3227         return(HDMI_RX_DDP);
3228     }
3229     else if (HDMI_PC_Status == 0x0)
3230     {
3231         return(HDMI_RX_PCM);
3232     }
3233     else
3234     {
3235         return(HDMI_RX_Other);
3236     }
3237 }
3238 
3239 ////////////////////////////////////////////////////////////////////////////////
3240 /// @brief \b Function \b Name: MApi_AUDIO_DTV_HDMI_CFG()
3241 /// @brief \b Function \b Description:  Set DVB/HDMI AC3 path configure
3242 /// @param ctrl    \b : 0: DVB2_AD path;
3243 ///                     1: HDMI path
3244 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DTV_HDMI_CFG(MS_U8 ctrl)3245 void _MApi_AUDIO_DTV_HDMI_CFG(MS_U8 ctrl)
3246 {
3247     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3248 
3249     MDrv_AUDIO_HDMI_AC3_PathCFG(ctrl);
3250 }
3251 
3252 ////////////////////////////////////////////////////////////////////////////////
3253 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_GetSynthFreq()
3254 /// @brief \b Function \b Description:  Audio HDMI CTS-N synthesizer input signal detect.
3255 /// @return MS_U16     \b : return freq. If no signal, return 0
3256 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_GetSynthFreq(void)3257 MS_U16 _MApi_AUDIO_HDMI_GetSynthFreq(void)
3258 {
3259     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3260 
3261     return MDrv_AUDIO_HDMI_GetSynthFreq();
3262 }
3263 
3264 ////////////////////////////////////////////////////////////////////////////////
3265 /// @brief \b Function \b Name: MApi_AUDIO_HDMI_SetDownSample()
3266 /// @brief \b Function \b Description:  set HDMI downsample rate
3267 /// @param ratio       \b : donwsample ratio
3268 ///                       - 00: Normal (from 1x to 1x).
3269 ///                       - 01: Down sample from 2x to 1x.
3270 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_HDMI_SetDownSample(MS_U8 ratio)3271 void _MApi_AUDIO_HDMI_SetDownSample(MS_U8 ratio)
3272 {
3273     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3274 
3275     MDrv_AUDIO_HDMI_SetDownSample(ratio);
3276 }
3277 
3278 
3279 
3280 
3281 
3282 ////////////////////////////////////////////////////////////////////////////////
3283 //
3284 //         AUDIO_SOUND RELATIONAL API FUNCTION
3285 //
3286 ////////////////////////////////////////////////////////////////////////////////
3287 
3288 ////////////////////////////////////////////////////////////////////////////////
3289 /// @brief \b Function \b Name: MApi_SND_ProcessEnable()
3290 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
3291 ////////////////////////////////////////////////////////////////////////////////
_MApi_SND_ProcessEnable(Sound_ENABLE_Type Type,MS_BOOL enable)3292 MS_BOOL _MApi_SND_ProcessEnable(Sound_ENABLE_Type Type, MS_BOOL enable)
3293 {
3294     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3295 
3296     return(MDrv_SND_ProcessEnable(Type, enable));
3297 }
3298 
3299 ////////////////////////////////////////////////////////////////////////////////
3300 /// @brief \b Function \b Name: MApi_SND_SetParam1()
3301 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
3302 /// @return MS_BOOL     \b : True / False
3303 ////////////////////////////////////////////////////////////////////////////////
_MApi_SND_SetParam1(Sound_SET_PARAM_Type Type,MS_U16 param1,MS_U16 param2)3304 MS_BOOL _MApi_SND_SetParam1( Sound_SET_PARAM_Type Type, MS_U16 param1, MS_U16 param2)
3305 {
3306     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3307 
3308     //if(Type == Sound_SET_PARAM_DCOffet)
3309     //{
3310     //    AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO,  "-->>NEW POWER ON SEQ: Sound_SET_PARAM_DCOffet\n\r");
3311     //}
3312     return(MDrv_SND_SetParam(Type,  param1,  param2));
3313 }
3314 
3315 ////////////////////////////////////////////////////////////////////////////////
3316 /// @brief \b Function \b Name: HAL_AUDIO_SOUND_SetParam()
3317 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
3318 /// @return MS_BOOL     \b : True / False
3319 ////////////////////////////////////////////////////////////////////////////////
_MApi_SND_GetParam1(Sound_GET_PARAM_Type Type,MS_U16 param1)3320 MS_U16 _MApi_SND_GetParam1( Sound_GET_PARAM_Type Type, MS_U16 param1)
3321 {
3322     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3323 
3324     return MDrv_SND_GetParam(Type, param1);
3325 }
3326 
3327 //******************************************************************************
3328 /// @brief \b Function \b Name: MApi_AUDIO_SOUND_SetParam()
3329 /// @brief \b Function \b Description: This routine is used for adjust Common Sound parameters
3330 /// @return MS_BOOL     \b : True / False
3331 //******************************************************************************
_MApi_AUDIO_SOUND_SetParam(Sound_SET_Type Type,MS_U32 * p_param)3332 MS_BOOL _MApi_AUDIO_SOUND_SetParam( Sound_SET_Type Type, MS_U32 *p_param )
3333 {
3334     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] [Type 0x%x] [0]: 0x%x [1]: 0x%x \n", __FUNCTION__, (int)Type, (int)*p_param, (int)*(p_param+1));
3335 
3336     return MDrv_SOUND_SetParam(Type, p_param);
3337 }
3338 
3339 ////////////////////////////////////////////////////////////////////////////////
3340 /// @brief \b Function \b Name: MApi_AUDIO_SeInit()
3341 /// @brief \b Function \b Description: This routine is the initialization for Audio sound effect module.
3342 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SeInit(void)3343 void _MApi_AUDIO_SeInit(void)
3344 {
3345     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3346 
3347     MDrv_SOUND_Init();
3348 }
3349 
3350 
3351 ////////////////////////////////////////////////////////////////////////////////
3352 /// @brief \b Function \b Name: MDrv_SOUND_AbsoluteVolume()
3353 /// @brief \b Function \b Description: This routine is used to set the absolute u8Volume of audio u8Path.
3354 /// @param u8Path      \b : for audio u8Path0 ~ u8Path6
3355 /// @param u8Vol1      \b : MSB 7-bit register value of 10-bit u8Volume
3356 ///                         range from 0x00 to 0x7E , gain: +12db to   -114db (-1 db per step)
3357 /// @param u8Vol2      \b : LSB 3-bit register value of 10-bit u8Volume
3358 ///                         range from 0x00 to 0x07 , gain:  -0db to -0.875db (-0.125 db per step)
3359 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetAbsoluteVolume(MS_U8 u8Path,MS_U8 u8Vol1,MS_U8 u8Vol2)3360 void _MApi_AUDIO_SetAbsoluteVolume( MS_U8 u8Path, MS_U8 u8Vol1, MS_U8 u8Vol2  )
3361 {
3362     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3363 
3364     MDrv_SOUND_AbsoluteVolume(u8Path, u8Vol1, u8Vol2);
3365 }
3366 
3367 ////////////////////////////////////////////////////////////////////////////////
3368 /// @brief \b Function \b Name: MApi_AUDIO_SetPreScale()
3369 /// @brief \b Function \b Description: This routine is used to set the prescale of audio u8Path.
3370 /// @param u8Path      \b : for audio u8Path0 ~ u8Path5
3371 /// @param u8PreScale  \b : range from 0x01 to 0xFF , gain: -13.75db to +18db (0.125 db per step)
3372 ///                       - 0x00: disable pre-scale
3373 ///                       - 0x6F: gain = 0db
3374 ///                       - 0xFF: gain = +18db
3375 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetPreScale(MS_U8 u8Path,MS_U8 u8PreScale)3376 void _MApi_AUDIO_SetPreScale( MS_U8 u8Path, MS_U8 u8PreScale )
3377 {
3378     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3379 	AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "apiAud>> pre-scale: Path = %d, PreScale = %d\n", u8Path, u8PreScale);
3380     MDrv_SOUND_SetPreScale(u8Path, u8PreScale);
3381 }
3382 
3383 ////////////////////////////////////////////////////////////////////////////////
3384 /// @brief \b Function \b Name: MApi_AUDIO_SourceConnect()
3385 /// @brief \b Function \b Description: This routine is used to set audio mute by processor
3386 /// @param u8Path      \b : eProcessor: Set Main/Sub processor,
3387 /// @param EnMute      \b : TRUE --Mute;
3388 ///                                    FALSE--Unmute
3389 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SourceConnect(AUDIO_OUTPORT_SOURCE_TYPE eConnectSourceType,MS_BOOL bConnect)3390 void _MApi_AUDIO_SourceConnect(AUDIO_OUTPORT_SOURCE_TYPE eConnectSourceType, MS_BOOL bConnect )
3391 {
3392     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3393 
3394     MS_BOOL EnMute = FALSE;
3395 
3396     APIAUDIO_CHECK_SHM_INIT;
3397 
3398     if (bConnect == FALSE)
3399     {
3400         EnMute = TRUE;
3401     }
3402     else
3403     {
3404         EnMute = FALSE;
3405     }
3406 
3407     //Set mute for Speaker out
3408     if(g_AudioVars2->AudioOutputSourceInfo.SpeakerOut == eConnectSourceType)
3409     {
3410         MDrv_SOUND_SetMute( g_AudioVars2->AudioPathInfo.SpeakerOut, EnMute);
3411     }
3412 
3413     //Set mute for HP out
3414     if(g_AudioVars2->AudioOutputSourceInfo.HpOut == eConnectSourceType)
3415     {
3416         MDrv_SOUND_SetMute( g_AudioVars2->AudioPathInfo.HpOut, EnMute);
3417     }
3418 
3419     //Set mute for Monitor out
3420     if(g_AudioVars2->AudioOutputSourceInfo.MonitorOut == eConnectSourceType)
3421     {
3422         MDrv_SOUND_SetMute( g_AudioVars2->AudioPathInfo.MonitorOut, EnMute);
3423     }
3424 
3425     //Set mute for Scart out
3426     if(g_AudioVars2->AudioOutputSourceInfo.ScartOut == eConnectSourceType)
3427     {
3428         MDrv_SOUND_SetMute( g_AudioVars2->AudioPathInfo.ScartOut, EnMute);
3429     }
3430 
3431     //Set mute for SPDIF out
3432     if(g_AudioVars2->AudioOutputSourceInfo.SpdifOut == eConnectSourceType)
3433     {
3434         MDrv_SOUND_SetMute( g_AudioVars2->AudioPathInfo.SpdifOut, EnMute);
3435     }
3436 
3437     //Set mute for ARC out
3438     if(g_AudioVars2->AudioOutputSourceInfo.ArcOut== eConnectSourceType)
3439     {
3440         //MDrv_AUDIO_HDMI_Tx_SetMute( EnMute);
3441     }
3442 
3443     //Set mute for HDMI out
3444     if(g_AudioVars2->AudioOutputSourceInfo.HDMIOut== eConnectSourceType)
3445     {
3446         MDrv_AUDIO_HDMI_Tx_SetMute( EnMute);
3447     }
3448 }
3449 
3450 ////////////////////////////////////////////////////////////////////////////////
3451 /// @brief \b Function \b Name: MApi_AUDIO_SetMute()
3452 /// @brief \b Function \b Description: This routine is used to set audio path S/W mute.
3453 /// @param u8Path      \b : for audio path0 ~ path6
3454 /// @param EnMute      \b : TRUE --Mute;
3455 ///                         FALSE--Unmute
3456 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetMute(MS_U8 u8Path,MS_BOOL EnMute)3457 void _MApi_AUDIO_SetMute(MS_U8 u8Path, MS_BOOL EnMute )
3458 {
3459     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3460 
3461     MDrv_SOUND_SetMute( u8Path, EnMute);
3462 }
3463 
3464 ////////////////////////////////////////////////////////////////////////////////
3465 /// @brief \b Function \b Name: MApi_AUDIO_SetBalance()
3466 /// @brief \b Function \b Description: This routine is used to set  balance value
3467 /// @param u8Balance   \b : balance (0~100)
3468 ///                       - 0    :  R channel is muted ...
3469 ///                       - 50   :  L & R channel output the same level...
3470 ///                       -  100 :  L channel is muted .
3471 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetBalance(MS_U8 u8Balance)3472 void _MApi_AUDIO_SetBalance( MS_U8 u8Balance )
3473 {
3474     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3475 
3476     MDrv_SOUND_SetBalance(u8Balance);
3477 }
3478 
3479 ////////////////////////////////////////////////////////////////////////////////
3480 /// @brief \b Function \b Name: MApi_AUDIO_EnableEQ()
3481 /// @brief \b Function \b Description: This routine is used to enable EQ function.
3482 /// @param EnEQ        \b : TRUE --Enable EQ;
3483 ///                                   FALSE--Disable EQ
3484 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnableEQ(MS_BOOL EnEQ)3485 void _MApi_AUDIO_EnableEQ(MS_BOOL EnEQ)
3486 {
3487     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3488 
3489     MDrv_SOUND_EnableEQ(EnEQ);
3490 }
3491 
3492 ////////////////////////////////////////////////////////////////////////////////
3493 /// @brief \b Function \b Name: MApi_AUDIO_EnableTone()
3494 /// @brief \b Function \b Description: This routine is used to enable Bass/Treble function.
3495 /// @param EnTone      \b : TRUE --Enable Bass/Treble;
3496 ///                         FALSE--Disable Bass/Treble
3497 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnableTone(MS_BOOL EnTone)3498 void _MApi_AUDIO_EnableTone(MS_BOOL EnTone)
3499 {
3500     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3501 
3502     MDrv_SOUND_EnableTone(EnTone);
3503 }
3504 
3505 ////////////////////////////////////////////////////////////////////////////////
3506 /// @brief \b Function \b Name: MApi_AUDIO_EnableAutoVolume()
3507 /// @brief \b Function \b Description: This routine is used to enable auto volume(AVC) function.
3508 /// @param EnAVC       \b : TRUE --Enable AVC;
3509 ///                        FALSE--Disable AVC
3510 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnableAutoVolume(MS_BOOL EnAVC)3511 void _MApi_AUDIO_EnableAutoVolume(MS_BOOL EnAVC)
3512 {
3513     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3514 
3515    MDrv_SOUND_EnableAutoVolume(EnAVC);
3516 }
3517 
3518 ////////////////////////////////////////////////////////////////////////////////
3519 /// @brief \b Function \b Name: MApi_AUDIO_EnableBalance()
3520 /// @brief \b Function \b Description: This routine is used to enable Balance function.
3521 /// @param EnBalance   \b : Balance Enable bits
3522 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnableBalance(MS_BOOL EnBalance)3523 void _MApi_AUDIO_EnableBalance(MS_BOOL EnBalance)
3524 {
3525     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3526 
3527     MDrv_SOUND_EnableBalance(EnBalance);
3528 }
3529 
3530 ////////////////////////////////////////////////////////////////////////////////
3531 /// @brief \b Function \b Name: MApi_AUDIO_EnableSurround()
3532 /// @brief \b Function \b Description: This routine is used to enable surround function.
3533 /// @param EnSurround   \b : TRUE --Enable Surround;
3534 ///                          FALSE--Disable Surround
3535 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnableSurround(MS_BOOL EnSurround)3536 void _MApi_AUDIO_EnableSurround(MS_BOOL EnSurround)
3537 {
3538     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3539 
3540     MDrv_SOUND_EnableSurround(EnSurround);
3541 }
3542 
3543 
3544 ////////////////////////////////////////////////////////////////////////////////
3545 /// @brief \b Function \b Name: MApi_AUDIO_SetDynamicBass()
3546 /// @brief \b Function \b Description: This routine is used to set DynamicBass level.
3547 /// @param u8Bass      \b :
3548 ///
3549 ///
3550 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetDynamicBass(MS_U8 u8DynamicBass)3551 void _MApi_AUDIO_SetDynamicBass( MS_U8 u8DynamicBass )
3552 {
3553     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3554 
3555       MDrv_SOUND_SetDynamicBass(u8DynamicBass);
3556 
3557 }
3558 
3559 ////////////////////////////////////////////////////////////////////////////////
3560 /// @brief \b Function \b Name: MApi_AUDIO_SetBass()
3561 /// @brief \b Function \b Description: This routine is used to set Bass level.
3562 /// @param u8Bass      \b :Bass Level (0~100)
3563 ///                       - CHIP_FAMILY_U3 & S4LE==>mapping to -16 ~ +15 dB Gain
3564 ///                       - CHIP_FAMILY_S7 ==>mapping to -12 ~ +12 dB Gain
3565 ///                       - CHIP_FAMILY_S7J       ==> mapping to -16 ~ +15 dB Gain
3566 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetBass(MS_U8 u8Bass)3567 void _MApi_AUDIO_SetBass( MS_U8 u8Bass )
3568 {
3569     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3570 
3571     MDrv_SOUND_SetBass(u8Bass);
3572 }
3573 
3574 ////////////////////////////////////////////////////////////////////////////////
3575 /// @brief \b Function \b Name: MApi_AUDIO_AbsoluteBass()
3576 /// @brief \b Function \b Description: This routine is used to set abs. Bass value.
3577 /// @param u8Bass      \b : register value
3578 ///                       - CHIP_FAMILY_U3 & S4LE ==>mapping to -16 ~ +15 dB Gain
3579 ///                       - CHIP_FAMILY_S7 ==>mapping to -12 ~ +12 dB Gain
3580 ///                       - CHIP_FAMILY_S7J       ==> mapping to -16 ~ +15 dB Gain
3581 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_AbsoluteBass(MS_U8 u8Bass)3582 void _MApi_AUDIO_AbsoluteBass(MS_U8 u8Bass)
3583 {
3584     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3585 
3586     MDrv_SOUND_AbsoluteBass(u8Bass);
3587 }
3588 
3589 ////////////////////////////////////////////////////////////////////////////////
3590 /// @brief \b Function \b Name: MApi_AUDIO_SetTreble()
3591 /// @brief \b Function \b Description: This routine is used to set Treble level.
3592 /// @param u8Treble    \b :Treble Level (0~100)
3593 ///                       - CHIP_FAMILY_U3 & S4LE ==>mapping to -16 ~ +15 dB Gain
3594 ///                       - CHIP_FAMILY_S7 ==>mapping to -12 ~ +12 dB Gain
3595 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetTreble(MS_U8 u8Treble)3596 void _MApi_AUDIO_SetTreble ( MS_U8 u8Treble )
3597 {
3598     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3599 
3600     MDrv_SOUND_SetTreble(u8Treble);
3601 }
3602 
3603 ////////////////////////////////////////////////////////////////////////////////
3604 /// @brief \b Function \b Name: MApi_AUDIO_AbsoluteTreble()
3605 /// @brief \b Function \b Description: This routine is used to set abs. Treble value.
3606 /// @param u8Treble    \b : register value
3607 ///                       - CHIP_FAMILY_U3 & S4LE ==> mapping to -16 ~ +15 dB Gain
3608 ///                       - CHIP_FAMILY_S7        ==> mapping to -12 ~ +12 dB Gain
3609 ///                       - CHIP_FAMILY_S7J       ==> mapping to -16 ~ +15 dB Gain
3610 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_AbsoluteTreble(MS_U8 u8Treble)3611 void _MApi_AUDIO_AbsoluteTreble( MS_U8 u8Treble )
3612 {
3613     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3614 
3615     MDrv_SOUND_AbsoluteTreble(u8Treble);
3616 }
3617 
3618 ////////////////////////////////////////////////////////////////////////////////
3619 /// @brief \b Function \b Name: MApi_AUDIO_SetEq()
3620 /// @brief \b Function \b Description: This routine is used to set the the 5-band EQ level  .
3621 /// @param u8band      \b :  EQ band 0~4
3622 /// @param u8level     \b :  Absolute EQ register value  ;
3623 ///                       - 0011-0000: +12.00db. (Max)
3624 ///                       - 0000-0001: +0.25db.
3625 ///                       - 0000-0000: +0.00db.
3626 ///                       - 1111-1111: -0.25db.
3627 ///                       - 1101-0000: -12.00db. (Min)
3628 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetEq(MS_U8 u8band,MS_U8 u8level)3629 void _MApi_AUDIO_SetEq(MS_U8 u8band, MS_U8 u8level)
3630 {
3631     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3632 
3633     MDrv_SOUND_SetEq(u8band,  u8level);
3634 }
3635 
3636 
3637 ////////////////////////////////////////////////////////////////////////////////
3638 /// @brief \b Function \b Name: MApi_AUDIO_SetEq_7band()
3639 /// @brief \b Function \b Description: This routine is used to set the the 7-band EQ level  .
3640 /// @param u8band      \b :  EQ band 0~6
3641 /// @param u8level     \b :  Absolute EQ register value  ;
3642 ///                          0011-0000: +12.00db. (Max)
3643 ///                          0000-0001: +0.25db.
3644 ///                          0000-0000: +0.00db.
3645 ///                          1111-1111: -0.25db.
3646 ///                          1101-0000: -12.00db. (Min)
3647 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetEq_7band(MS_U8 u8band,MS_U8 u8level)3648 void _MApi_AUDIO_SetEq_7band(MS_U8 u8band, MS_U8 u8level)
3649 {
3650     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3651 
3652     MDrv_SOUND_SetEq7(u8band,  u8level);
3653 }
3654 
3655 ////////////////////////////////////////////////////////////////////////////////
3656 /// @brief \b Function \b Name: MApi_AUDIO_SetAvcThreshold()
3657 /// @brief \b Function \b Description: This routine is used to set the AVC  threshold level.
3658 /// @param Level       \b :  AVC threshold level
3659 ///                       - 0x00--  0    dBFS
3660 ///                       - 0x01--  -0.5    dBFS
3661 ///                       - 0x20--  -16    dBFS
3662 ///                       - 0x50--  -40    dBFS
3663 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetAvcThreshold(MS_U8 Level)3664 void _MApi_AUDIO_SetAvcThreshold(MS_U8 Level)
3665 {
3666     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3667 
3668     MDrv_SOUND_SetAVCThreshold(Level);
3669 }
3670 
3671 ////////////////////////////////////////////////////////////////////////////////
3672 /// @brief \b Function \b Name: MApi_AUDIO_SetAvcMode()
3673 /// @brief \b Function \b Description: This routine is used to set the AVC mode.
3674 /// @param <IN>        \b u8AvcMode    :  AVC u8Mode
3675 ///                                    - 0: L mode
3676 ///                                    - 1: S mode
3677 ///                                    - 2: M mode
3678 /// @image html L_mode.JPG "L mode"
3679 /// @image html S_mode.JPG "S mode"
3680 /// @image html M_mode.JPG "M mode"
3681 /// @param <OUT>       \b NONE    :
3682 /// @param <RET>       \b NONE    :
3683 /// @param <GLOBAL>    \b NONE    :
3684 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetAvcMode(MS_U8 AvcMode)3685 void _MApi_AUDIO_SetAvcMode( MS_U8 AvcMode )
3686 {
3687     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3688 
3689     MDrv_SOUND_SetAvcMode( AvcMode );
3690 }
3691 
3692 ////////////////////////////////////////////////////////////////////////////////
3693 /// @brief \b Function \b Name: MApi_AUDIO_SetAvcAT()
3694 /// @brief \b Function \b Description: This routine is used to set the AVC  attack time .
3695 /// @param AvcAT       \b :  AVC attack time
3696 ///                       - AvcAT = 0 --> 20  ms
3697 ///                       - AvcAT = 1 --> 100 ms
3698 ///                       - AvcAT = 2 --> 200 ms
3699 ///                       - AvcAT = 3 --> 1 sec
3700 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetAvcAT(MS_U8 AvcAT)3701 void _MApi_AUDIO_SetAvcAT( MS_U8 AvcAT )
3702 {
3703     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3704 
3705     MDrv_SOUND_SetAvcAT( AvcAT );
3706 }
3707 
3708 ////////////////////////////////////////////////////////////////////////////////
3709 /// @brief \b Function \b Name: MApi_AUDIO_SetAvcRT()
3710 /// @brief \b Function \b Description: This routine is used to set the AVC  release time .
3711 /// @param AvcRT       \b :  AVC release time
3712 ///                       - AvcRT = 0 --> 1 sec
3713 ///                       - AvcRT = 1 --> 2 sec
3714 ///                       - AvcRT = 2 --> 100 ms
3715 ///                       - AvcRT = 3 --> 200 ms
3716 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetAvcRT(MS_U8 AvcRT)3717 void _MApi_AUDIO_SetAvcRT( MS_U8 AvcRT )
3718 {
3719     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3720 
3721     MDrv_SOUND_SetAvcRT( AvcRT );
3722 }
3723 
3724 ////////////////////////////////////////////////////////////////////////////////
3725 /// @brief \b Function \b Name: MApi_AUDIO_SetBufferProcess()
3726 /// @brief \b Function \b Description: sets the value of audio delay time (ms)..
3727 /// @param DelayTime   \b : 0x00~0xFA(0~250), each step=1 ms , 0~250 ms
3728 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetBufferProcess(MS_U8 DelayTime)3729 void _MApi_AUDIO_SetBufferProcess(MS_U8 DelayTime)
3730 {
3731     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3732 
3733     MDrv_SOUND_SetCH1AudioDelay(DelayTime);
3734 }
3735 
3736 ////////////////////////////////////////////////////////////////////////////////
3737 /// @brief \b Function \b Name: MApi_AUDIO_SetSurroundXA()
3738 /// @brief \b Function \b Description: This routine is used to set the Surround xA echo Gain.
3739 /// @param <IN>        \b mode    :     A Gain : register SURROUND[3:2]
3740 ///                       - 0 :    x0.1
3741 ///                       - 1 :    x0.15
3742 ///                       - 2 :    x0.2
3743 ///                       - 3 :    x0.25
3744 /// @param <OUT>       \b NONE    :
3745 /// @param <RET>       \b NONE    :
3746 /// @param <GLOBAL>    \b NONE
3747 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSurroundXA(MS_U8 mode)3748 void _MApi_AUDIO_SetSurroundXA( MS_U8 mode )
3749 {
3750     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3751 
3752     MDrv_SOUND_SetSurroundXA(mode);
3753 }
3754 
3755 ////////////////////////////////////////////////////////////////////////////////
3756 /// @brief \b Function \b Name: MApi_AUDIO_SetSurroundXB()
3757 /// @brief \b Function \b Description: This routine is used to set the Surround xB echo Gain.
3758 /// @param <IN>        \b mode    :   B Gain : register SURROUND[5:4]
3759 ///                       - 0 :    x0.25
3760 ///                       - 1 :    x0.3
3761 ///                       - 2 :    x0.35
3762 ///                       - 3 :    x0.45
3763 /// @param <OUT>       \b NONE    :
3764 /// @param <RET>       \b NONE    :
3765 /// @param <GLOBAL>    \b NONE
3766 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSurroundXB(MS_U8 mode)3767 void _MApi_AUDIO_SetSurroundXB( MS_U8 mode )
3768 {
3769     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3770 
3771     MDrv_SOUND_SetSurroundXB(mode);
3772 }
3773 
3774 ////////////////////////////////////////////////////////////////////////////////
3775 /// @brief \b Function \b Name: MApi_AUDIO_SetSurroundXK()
3776 /// @brief \b Function \b Description: This routine is used to set the Surround xK feedback Gain.
3777 /// @param <IN>        \b mode    :     K Gain : register SURROUND[10:8]
3778 ///                       - 0 :    x0.1
3779 ///                       - 1 :    x0.2
3780 ///                       - 2 :    x0.3
3781 ///                       - 3 :    x0.4
3782 ///                       - 4 :    x0.5
3783 ///                       - 5 :    x0.6
3784 ///                       - 6 :    x0.7
3785 ///                       - 7 :    x0.8
3786 /// @param <OUT>       \b NONE    :
3787 /// @param <RET>       \b NONE    :
3788 /// @param <GLOBAL>    \b NONE
3789 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSurroundXK(MS_U8 mode)3790 void _MApi_AUDIO_SetSurroundXK( MS_U8 mode )
3791 {
3792     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3793 
3794     MDrv_SOUND_SetSurroundXK(mode);
3795 }
3796 
3797 ////////////////////////////////////////////////////////////////////////////////
3798 /// @brief \b Function \b Name: MApi_AUDIO_SetSurroundLPFGain()
3799 /// @brief \b Function \b Description: This routine is used to set the Surround LPF Gain.
3800 /// @image html surround.JPG "Surround block diagram"
3801 /// @param <IN>        \b mode    : LPF Gain : register SURROUND[7:6]
3802 ///                       - 0 :    0 dB
3803 ///                       - 1 :    2 dB
3804 ///                       - 2 :    4 dB
3805 ///                       - 3 :    un-support
3806 /// @param <OUT>       \b NONE    :
3807 /// @param <RET>       \b NONE    :
3808 /// @param <GLOBAL>    \b NONE
3809 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSurroundLPFGain(MS_U8 mode)3810 void _MApi_AUDIO_SetSurroundLPFGain( MS_U8 mode )
3811 {
3812     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3813 
3814     MDrv_SOUND_SetSurroundLPFGain(mode);
3815 }
3816 
3817 /////////////////////////////////////////////////////////////////////////////////
3818 /// @brief \b Function \b Name: MApi_AUDIO_ConvertVolumeUnit()
3819 /// @brief \b Function \b Description: Convert UI Volume to Absolute Volume.
3820 ///                                                  valid value of UiVolume is between 0 and 100
3821 /// @param UiVolume    \b :    UI Volume 0 -> 62, 50 -> 12, 100 -> 7
3822 /// @param MS_U8       \b :    register value
3823 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ConvertVolumeUnit(MS_U8 UiVolume)3824 MS_U8 _MApi_AUDIO_ConvertVolumeUnit(MS_U8 UiVolume)
3825 {
3826     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3827 
3828     MS_U8 tmpVolume = 0;
3829 
3830     if (UiVolume > 100)
3831     {
3832         tmpVolume = 7;
3833     }
3834     else if (UiVolume >= 50)
3835     {
3836         tmpVolume = (12 - ((UiVolume-50)/10));
3837     }
3838     else
3839     {
3840         tmpVolume = (12 + (50 - UiVolume));
3841     }
3842 
3843     return tmpVolume;
3844 }
3845 
3846 ////////////////////////////////////////////////////////////////////////////////
3847 //
3848 //           AUDIO_ADVANCE_SOUND RELATIONAL API FUNCTION
3849 //
3850 ////////////////////////////////////////////////////////////////////////////////
3851 
3852 
3853 ////////////////////////////////////////////////////////////////////////////////
3854 /// @brief \b Function \b Name: MApi_AUDIO_ADVSOUND_ProcessEnable
3855 /// @brief \b Function \b Description: This routine is used to enable process of advanced sound effect.
3856 /// @param <IN>        \b ADVSND_TYPE type
3857 /// @param <OUT>       \b NONE  :
3858 /// @param <RET>       \b  NONE :
3859 /// @param <GLOBAL>    \b NONE
3860 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ADVSOUND_ProcessEnable(ADVSND_TYPE type)3861 MS_BOOL _MApi_AUDIO_ADVSOUND_ProcessEnable(ADVSND_TYPE type)
3862 {
3863 	AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3864     return MDrv_ADVSOUND_ProcessEnable(type);
3865 }
3866 
3867 ////////////////////////////////////////////////////////////////////////////////
3868 /// @brief \b Function \b Name: MApi_AUDIO_ADVSOUND_SubProcessEnable(ADVFUNC proc, BOOL enable)
3869 /// @brief \b Function \b Description: This routine is used to enable subprocess of advanced sound effect.
3870 /// @param <IN>        \b proc, enable
3871 /// @param <OUT>       \b NONE  :
3872 /// @param <RET>       \b  NONE :
3873 /// @param <GLOBAL>    \b NONE
3874 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ADVSOUND_SubProcessEnable(ADVFUNC proc,MS_BOOL enable)3875 MS_BOOL _MApi_AUDIO_ADVSOUND_SubProcessEnable(ADVFUNC proc, MS_BOOL enable)
3876 {
3877 	AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3878     return MDrv_ADVSOUND_SubProcessEnable(proc, enable);
3879 }
3880 
3881 ////////////////////////////////////////////////////////////////////////////////
3882 /// @brief \b Function \b Name: MApi_AUDIO_ADVSOUND_SetParam(ADVSND_PARAM param, U16 value1, U16 value2)
3883 /// @brief \b Function \b Description: This routine is used to set paramters advanced sound effect.
3884 /// @param <IN>        \b param, value1, value2
3885 /// @param <OUT>       \b NONE  :
3886 /// @param <RET>       \b  NONE :
3887 /// @param <GLOBAL>    \b NONE
3888 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ADVSOUND_SetParam(ADVSND_PARAM param,MS_U16 u16value1,MS_U16 u16value2)3889 MS_BOOL _MApi_AUDIO_ADVSOUND_SetParam(ADVSND_PARAM param, MS_U16 u16value1, MS_U16 u16value2)
3890 {
3891     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3892 
3893     return MDrv_ADVSOUND_SetParam(param, (MS_U32)u16value1, u16value2);
3894 }
3895 
3896 ////////////////////////////////////////////////////////////////////////////////
3897 /// @brief \b Function \b Name: MApi_AUDIO_ADVSOUND_SetParam(ADVSND_PARAM param, U32 value1, U16 value2)
3898 /// @brief \b Function \b Description: This routine is used to set paramters advanced sound effect.
3899 /// @param <IN>        \b param, u32value1, u16value2
3900 ///                              \b Parameter u32value1: range 0~0x7FFFFF
3901 ///                              \b Parameter u16value2: 0/1,
3902 ///                              - 0 : if u32value1 is u16, none fix point 24 bit parameter
3903 ///                              - 1 : if u32value1 is u32, fix point 24 bit parameter
3904 /// @param <OUT>       \b NONE  :
3905 /// @return <OUT>       \b FALSE : Setting Fail
3906 ///                               \b TRUE  : Setting OK
3907 /// @param <GLOBAL>    \b NONE
3908 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ADVSND_SetParam(ADVSND_PARAM param,MS_U32 u32value1,MS_U16 u16value2)3909 MS_BOOL _MApi_AUDIO_ADVSND_SetParam(ADVSND_PARAM param, MS_U32 u32value1, MS_U16 u16value2)
3910 {
3911     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3912 
3913     return MDrv_ADVSOUND_SetParam(param, u32value1, u16value2);
3914 }
3915 ////////////////////////////////////////////////////////////////////////////////
3916 /// @brief \b Function \b Name: MApi_DBXTV_SetMode(DBXTV_TotSonMode TotSonMode, DBXTV_TotVolMode TotVolMode, DBXTV_TotSurMode TotSurMode)
3917 /// @brief \b Function \b Description: This routine is used to set dbx TV mode
3918 /// @param <IN>        \b param, TotSonMode, TotVolMode, TotSurMode
3919 /// @param <OUT>       \b NONE    :
3920 /// @param <RET>       \b  NONE    :
3921 /// @param <GLOBAL>    \b NONE
3922 ////////////////////////////////////////////////////////////////////////////////
_MApi_DBXTV_SetMode(EN_DBXTV_TotSonMode totsonmode,EN_DBXTV_TotVolMode totvolmode,EN_DBXTV_TotSurMode totsurmode,MS_U32 enable)3923 void _MApi_DBXTV_SetMode(EN_DBXTV_TotSonMode totsonmode, EN_DBXTV_TotVolMode totvolmode, EN_DBXTV_TotSurMode totsurmode,MS_U32 enable)
3924 {
3925     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3926 
3927      MDrv_DBXTV_SetMode(totsonmode, totvolmode, totsurmode,enable);
3928 }
3929 
3930 ////////////////////////////////////////////////////////////////////////////////
3931 /// @brief \b Function \b Name: MApi_AUDIO_ADVSOUND_GetInfo()
3932 /// @brief \b Function \b Description: This routine is used for Get ADV Sound info
3933 /// @return MS_BOOL     \b : True / False
3934 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ADVSOUND_GetInfo(AdvSound_GET_Type Type)3935 MS_U32 _MApi_AUDIO_ADVSOUND_GetInfo( AdvSound_GET_Type Type)
3936 {
3937     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3938 
3939     return (MDrv_ADVSOUND_GetInfo(Type));
3940 }
3941 
3942 ////////////////////////////////////////////////////////////////////////////////
3943 /// @brief \b Function \b Name: MApi_AUDIO_AseSetBinAddress()
3944 /// @brief \b Function \b Description:  This function is used to assign Bin address of advanced sound effect
3945 /// @param u8Index     \b : type index
3946 /// @param BinAddr     \b : address of Bin file
3947 ////////////////////////////////////////////////////////////////////////////////
MApi_AUDIO_AseSetBinAddress(MS_U8 u8Index,MS_U32 BinAddr)3948 void MApi_AUDIO_AseSetBinAddress(MS_U8 u8Index, MS_U32 BinAddr)
3949 {
3950     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3951 
3952     MDrv_SOUND_AseSetBinAddress(u8Index, BinAddr);
3953 }
3954 
3955 ////////////////////////////////////////////////////////////////////////////////
3956 /// @brief \b Function \b Name: MApi_AUDIO_SetAdvSndSys()
3957 /// @brief \b Function \b Description: Check Advance sound mod and reload code
3958 /// @param u8AdvSurrMod \b : Audio Advance Sound system mod
3959 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetAdvSndSys(En_DVB_advsndType u8AdvSurrMod)3960 void _MApi_AUDIO_SetAdvSndSys(En_DVB_advsndType u8AdvSurrMod)
3961 {
3962     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
3963 
3964      // Marked by coverity_0446
3965     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, "apiAud chk u8AdvSurrMod/u8CurrAdvSndSys = %s / %s\n", u8AdvSurrMod, u8CurrAdvSndSys);
3966 
3967     if (!En_DVB_advsndType_Compare(u8AdvSurrMod, u8CurrAdvSndSys))
3968     {
3969         // set advance surround sound system
3970         // 0: PL2,  1:BBE,  2: SRS  3:VDS, 4:VSPK, 5:SUPV, 6:TSHD, 7:XEN
3971         if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_BBE))
3972         {
3973             MDrv_ADVSOUND_ProcessEnable(BBE);
3974             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_BBE;
3975         }
3976         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_SRS))
3977         {
3978             MDrv_ADVSOUND_ProcessEnable(SRS_TSXT);
3979             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_SRS;
3980         }
3981         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_VDS))
3982         {
3983             MDrv_ADVSOUND_ProcessEnable(DOLBY_PL2VDS);
3984             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_VDS;
3985         }
3986         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_VSPK))
3987         {
3988             MDrv_ADVSOUND_ProcessEnable(DOLBY_PL2VDPK);
3989             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_VSPK;
3990         }
3991         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_SUPV))
3992         {
3993             MDrv_ADVSOUND_ProcessEnable(SUPER_VOICE);
3994             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_SUPV;
3995         }
3996         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_TSHD))
3997         {
3998             MDrv_ADVSOUND_ProcessEnable(SRS_TSHD);
3999             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_TSHD;
4000         }
4001         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_DTS_ULTRATV))
4002         {
4003             MDrv_ADVSOUND_ProcessEnable(DTS_ULTRATV);
4004             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_DTS_ULTRATV;
4005         }
4006         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_AUDYSSEY))
4007         {
4008             MDrv_ADVSOUND_ProcessEnable(DTS_ULTRATV);
4009             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_AUDYSSEY;
4010         }
4011         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_DBX))
4012         {
4013             MDrv_ADVSOUND_ProcessEnable(DBX);
4014             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_DBX;
4015         }
4016         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_SSHD_TSHD))
4017         {
4018             MDrv_ADVSOUND_ProcessEnable(SRS_THEATERSOUND);
4019             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_SSHD_TSHD;
4020         }
4021         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_PURESND))
4022         {
4023             MDrv_ADVSOUND_ProcessEnable(SRS_PURESND);
4024             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_PURESND;
4025         }
4026         else if (En_DVB_advsndType_Compare(u8AdvSurrMod, MSAPI_AUD_ADVSND_BONGIOVI_DPS))
4027         {
4028             MDrv_ADVSOUND_ProcessEnable(BONGIOVI_DPS);
4029             u8CurrAdvSndSys = MSAPI_AUD_ADVSND_BONGIOVI_DPS;
4030         }
4031     }
4032 }
4033 
4034 ////////////////////////////////////////////////////////////////////////////////
4035 /// @brief \b Function \b Name: MApi_AUDIO_VDS()
4036 /// @brief \b Function \b Description: Dolby Virtual Surround
4037 /// @param u8enVDS     \b :   1: enable;  0: disable
4038 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetVDS(MS_U8 u8enVDS)4039 void _MApi_AUDIO_SetVDS(MS_U8 u8enVDS)
4040 {
4041     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4042 
4043     MDrv_SOUND_VDS_Enable(u8enVDS);
4044 }
4045 
4046 ////////////////////////////////////////////////////////////////////////////////
4047 /// @brief \b Function \b Name: MApi_AUDIO_SetVSPK()
4048 /// @brief \b Function \b Description: Dolby Virtual Speaker
4049 /// @param u8enVSPK    \b :   1: enable;  0: disable
4050 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetVSPK(MS_U8 u8enVSPK)4051 void _MApi_AUDIO_SetVSPK(MS_U8 u8enVSPK)
4052 {
4053     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4054 
4055     MDrv_SOUND_VSPK_Enable(u8enVSPK);
4056 }
4057 
4058 ////////////////////////////////////////////////////////////////////////////////
4059 /// @brief \b Function \b Name: MApi_AUDIO_SetSRS()
4060 /// @brief \b Function \b Description: SRS TruSurr
4061 /// @param u8enSRS     \b :   1: enable;  0: disable
4062 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSRS(MS_U8 u8enSRS)4063 void _MApi_AUDIO_SetSRS(MS_U8 u8enSRS)
4064 {
4065     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4066 
4067     if(u8enSRS)
4068     {
4069         MDrv_SOUND_SRS_Enable(TRUE);
4070     }
4071     else
4072     {
4073         MDrv_SOUND_SRS_Enable(FALSE);
4074     }
4075 }
4076 
4077 ////////////////////////////////////////////////////////////////////////////////
4078 /// @brief \b Function \b Name: MApi_SOUND_SRS_SetTsxtPara()
4079 /// @brief \b Function \b Description:  This function is used to set paramters of SRS-TSXT
4080 /// @param u8mode      \b : parameter mode
4081 /// @param u8value     \b : parameter value
4082 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SRS_SetTsxtPara(MS_U8 u8mode,MS_U8 u8value)4083 void  _MApi_AUDIO_SRS_SetTsxtPara(MS_U8 u8mode, MS_U8 u8value)
4084 {
4085     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4086 
4087     MDrv_SOUND_SRS_SetTsxtPara(u8mode, u8value);
4088 }
4089 
4090 ////////////////////////////////////////////////////////////////////////////////
4091 /// @brief \b Function \b Name: MApi_AUDIO_SetSRSTSHD()
4092 /// @brief \b Function \b Description: SRS TruSurround HD
4093 /// @param u8enSRS     \b :   1: enable;  0: disable
4094 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSRSTSHD(MS_U8 u8enTSHD)4095 void _MApi_AUDIO_SetSRSTSHD(MS_U8 u8enTSHD)
4096 {
4097     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4098 
4099     if(u8enTSHD)
4100     {
4101         MDrv_SOUND_TSHD_Enable(TRUE);
4102     }
4103     else
4104     {
4105         MDrv_SOUND_TSHD_Enable(FALSE);
4106     }
4107 }
4108 
4109 ////////////////////////////////////////////////////////////////////////////////
4110 /// @brief \b Function \b Name: MApi_SOUND_SRS_SetTshdPara()
4111 /// @brief \b Function \b Description:  This function is used to set paramters of SRS-TSHD
4112 /// @param u8mode      \b : parameter mode
4113 /// @param u8value     \b : parameter value
4114 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SRS_SetTshdPara(MS_U8 u8mode,MS_U8 u8value)4115 void  _MApi_AUDIO_SRS_SetTshdPara(MS_U8 u8mode, MS_U8 u8value)
4116 {
4117     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4118 
4119     MDrv_SOUND_SRS_SetTshdPara(u8mode, u8value);
4120 }
4121 
4122 ////////////////////////////////////////////////////////////////////////////////
4123 /// @brief \b Function \b Name: MApi_AUDIO_SetBBE()
4124 /// @brief \b Function \b Description: BBE Surround
4125 /// @param u8enBBE     \b :   1: enable;  0: disable
4126 /// @param u8BBEMode   \b :
4127 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetBBE(MS_U8 u8enBBE,MS_U8 u8BBEMode)4128 void _MApi_AUDIO_SetBBE(MS_U8 u8enBBE , MS_U8 u8BBEMode)
4129 {
4130     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4131 
4132     MDrv_SOUND_BBE_SetBbeMode(u8enBBE,u8BBEMode);
4133 }
4134 
4135 ////////////////////////////////////////////////////////////////////////////////
4136 /// @brief \b Function \b Name: MApi_AUDIO_VSPK_WMod()
4137 /// @brief \b Function \b Description: Dolby Virtual Speaker Wide Mod
4138 /// @param u8VSPK_WMode \b : 0: reference mod; 1: wide mod
4139 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_VSPK_WMod(MS_U8 u8VSPK_WMode)4140 void _MApi_AUDIO_VSPK_WMod(MS_U8 u8VSPK_WMode)
4141 {
4142     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4143 
4144     MDrv_SOUND_VSPK_SetWMod(u8VSPK_WMode);
4145 }
4146 
4147 ////////////////////////////////////////////////////////////////////////////////
4148 /// @brief \b Function \b Name: MApi_AUDIO_VSPK_SMod()
4149 /// @brief \b Function \b Description: Dolby Virtual Speaker Surround Mod
4150 /// @param u8VSPK_SMode \b : 0: movie mod; 1: music mod
4151 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_VSPK_SMod(MS_U8 u8VSPK_SMode)4152 void _MApi_AUDIO_VSPK_SMod(MS_U8 u8VSPK_SMode)
4153 {
4154     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4155 
4156     MDrv_SOUND_VSPK_SetSMod(u8VSPK_SMode);
4157 }
4158 
4159 ////////////////////////////////////////////////////////////////////////////////
4160 /// @brief \b Function \b Name: MApi_AUDIO_SRS_DC()
4161 /// @brief \b Function \b Description: SRS Dialog Clarity
4162 /// @param u8SRSenDC   \b :   1: enable;  0: disable
4163 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SRS_DC(MS_U8 u8SRSenDC)4164 void _MApi_AUDIO_SRS_DC(MS_U8 u8SRSenDC)
4165 {
4166     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4167 
4168     MDrv_SOUND_SRS_DC(u8SRSenDC);
4169 }
4170 
4171 ////////////////////////////////////////////////////////////////////////////////
4172 /// @brief \b Function \b Name: MApi_AUDIO_SRS_TruBass()
4173 /// @brief \b Function \b Description:  SRS TruBass
4174 /// @param u8SRSenTruBass \b :   1: enable;  0: disable
4175 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SRS_TruBass(MS_U8 u8SRSenTruBass)4176 void _MApi_AUDIO_SRS_TruBass(MS_U8 u8SRSenTruBass)
4177 {
4178     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4179 
4180     MDrv_SOUND_SRS_TruBass(u8SRSenTruBass);
4181 }
4182 
4183 ////////////////////////////////////////////////////////////////////////////////
4184 /// @brief \b Function \b Name: MApi_AUDIO_TSHD_TruBass()
4185 /// @brief \b Function \b Description:  This function is used to enable/disable SRS-HD Trubass
4186 /// @param u8TSHDenTruBass \b :  1: enable, 0: disable
4187 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_TSHD_TruBass(MS_U8 u8TSHDenTruBass)4188 void  _MApi_AUDIO_TSHD_TruBass(MS_U8 u8TSHDenTruBass)
4189 {
4190     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4191 
4192     MDrv_SOUND_TSHD_TruBass(u8TSHDenTruBass);
4193 }
4194 
4195 ////////////////////////////////////////////////////////////////////////////////
4196 /// @brief \b Function \b Name: MApi_AUDIO_TSHD_Definition()
4197 /// @brief \b Function \b Description:  This function is used to enable/disable SRS-HD Definition
4198 /// @param u8TSHDenDefinition \b :  1: enable, 0: disable
4199 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_TSHD_Definition(MS_U8 u8TSHDenDefinition)4200 void  _MApi_AUDIO_TSHD_Definition(MS_U8 u8TSHDenDefinition)
4201 {
4202     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4203 
4204     MDrv_SOUND_TSHD_Definition(u8TSHDenDefinition);
4205 }
4206 
4207 ////////////////////////////////////////////////////////////////////////////////
4208 /// @brief \b Function \b Name: MApi_AUDIO_TSHD_Clarity()
4209 /// @brief \b Function \b Description:  This function is used to enable/disable SRS-HD DC
4210 /// @param u8TSHDenClarity \b :  1: enable, 0: disable
4211 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_TSHD_Clarity(MS_U8 u8TSHDenClarity)4212 void  _MApi_AUDIO_TSHD_Clarity(MS_U8 u8TSHDenClarity)
4213 {
4214     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4215 
4216     MDrv_SOUND_TSHD_Clarity(u8TSHDenClarity);
4217 }
4218 
4219 ////////////////////////////////////////////////////////////////////////////////
4220 /// @brief \b Function \b Name: MApi_AUDIO_COPY_Parameter()
4221 /// @brief \b Function \b Description: Copy parameter from APP level
4222 /// @param u8enVSPK    \b :
4223 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_COPY_Parameter(ADVSND_PARAM type,void * Parameter_ptr,MS_U32 size)4224 void _MApi_AUDIO_COPY_Parameter(ADVSND_PARAM type, void* Parameter_ptr, MS_U32 size)
4225 {
4226     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4227 
4228     MDrv_AUDIO_COPY_Parameter( type, Parameter_ptr, size);
4229 }
4230 
4231 ////////////////////////////////////////////////////////////////////////////////
4232 //
4233 //           AUDIO_KTV RELATIONAL API FUNCTION
4234 //
4235 ////////////////////////////////////////////////////////////////////////////////
4236 
4237 ////////////////////////////////////////////////////////////////////////////////
4238 /// @brief \b Function \b Name: MApi_AUDIO_SetKTVInfo()
4239 /// @brief \b Function \b Description: Set KTV parameter
4240 /// @param modelType   \b : KTV model type
4241 /// @param infoType    \b : KTV infomation type
4242 /// @param param1      \b :
4243 /// @param param2      \b :
4244 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetKTVInfo(AUDIO_KTV_MODEL modelType,AUDIO_KTV_PARAMTYPE paramType,MS_U32 param1,MS_U32 param2)4245 MS_BOOL _MApi_AUDIO_SetKTVInfo (AUDIO_KTV_MODEL modelType, AUDIO_KTV_PARAMTYPE paramType, MS_U32 param1, MS_U32 param2)
4246 {
4247     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4248 
4249     return MDrv_AUDIO_SetKTVInfo (modelType, paramType, param1, param2);
4250 }
4251 
4252 ////////////////////////////////////////////////////////////////////////////////
4253 /// @brief \b Function \b Name: MApi_AUDIO_GetKTVInfo()
4254 /// @brief \b Function \b Description: Get KTV parameter
4255 /// @param modelType   \b : KTV model type
4256 /// @param infoType    \b : KTV infomation type
4257 /// @return MS_U32     \b : return KTV value
4258 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetKTVInfo(AUDIO_KTV_MODEL modelType,AUDIO_KTV_INFOTYPE infoType)4259 MS_U32 _MApi_AUDIO_GetKTVInfo (AUDIO_KTV_MODEL modelType, AUDIO_KTV_INFOTYPE infoType)
4260 {
4261     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4262 
4263     return (MDrv_AUDIO_GetKTVInfo (modelType, infoType));
4264 }
4265 
4266 ////////////////////////////////////////////////////////////////////////////////
4267 /// @brief \b Function \b Name: MApi_AUDIO_SetMixModeVolume()
4268 /// @brief \b Function \b Description: This routine is used to set the absolute u8Volume of mix mode.
4269 /// @param eSourceType \b : for audio source
4270 /// @param VolType     \b : for audio vol type
4271 /// @param u8Vol1      \b : MSB 7-bit register value of 10-bit u8Volume
4272 ///                         range from 0x00 to 0x7E , gain: +12db to   -114db (-1 db per step)
4273 /// @param u8Vol2      \b : LSB 3-bit register value of 10-bit u8Volume
4274 ///                         range from 0x00 to 0x07 , gain:  -0db to -0.875db (-0.125 db per step)
4275 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetMixModeVolume(AUDIO_SOURCE_INFO_TYPE eSourceType,AUDIO_MIX_VOL_TYPE VolType,MS_U8 u8Vol1,MS_U8 u8Vol2)4276 void _MApi_AUDIO_SetMixModeVolume(AUDIO_SOURCE_INFO_TYPE eSourceType, AUDIO_MIX_VOL_TYPE VolType, MS_U8 u8Vol1, MS_U8 u8Vol2  )
4277 {
4278     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4279 
4280       MDrv_SOUND_SetMixModeVolume(eSourceType, VolType, u8Vol1, u8Vol2);
4281 }
4282 
4283 ////////////////////////////////////////////////////////////////////////////////
4284 /// @brief \b Function \b Name: MApi_AUDIO_SetMixModeMute()
4285 /// @brief \b Function \b Description: This routine is used to set audio mix mode mute
4286 /// @param eSourceType \b : for audio source
4287 /// @param VolType     \b : for audio vol type
4288 /// @param EnMute      \b : TRUE --Mute;
4289 ///                         FALSE--Unmute
4290 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetMixModeMute(AUDIO_SOURCE_INFO_TYPE eSourceType,AUDIO_MIX_VOL_TYPE VolType,MS_BOOL EnMute)4291 void _MApi_AUDIO_SetMixModeMute(AUDIO_SOURCE_INFO_TYPE eSourceType, AUDIO_MIX_VOL_TYPE VolType, MS_BOOL EnMute )
4292 {
4293     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4294 
4295     MDrv_SOUND_SetMixModeMute(eSourceType, VolType, EnMute);
4296 }
4297 
4298 ////////////////////////////////////////////////////////////////////////////////
4299 /// @brief \b Function \b Name: MApi_AUDIO_PlayMenuSound()
4300 /// @brief \b Function \b Description: This routine is used to Play Menu Sound.
4301 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PlayMenuSound(void)4302 void _MApi_AUDIO_PlayMenuSound(void)
4303 {
4304     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4305 
4306      MDrv_SOUND_PlayMenuSound();
4307 }
4308 
4309 
4310 
4311 
4312 ////////////////////////////////////////////////////////////////////////////////
4313 //
4314 //           AUDIO_OTHERS RELATIONAL FUNCTION (Temp)
4315 //
4316 ////////////////////////////////////////////////////////////////////////////////
4317 
4318 ////////////////////////////////////////////////////////////////////////////////
4319 /// @brief \b Function \b Name: MApi_AUDIO_SetCertMode()
4320 /// @brief \b Function \b Description:
4321 /// @param CertType    \b :
4322 /// @param enable      \b :
4323 ///
4324 ////////////////////////////////////////////////////////////////////////////////
MApi_AUDIO_SetCertMode(Audio_CertMode CertType,Audio_CertEnable enCert)4325 MS_BOOL MApi_AUDIO_SetCertMode( Audio_CertMode CertType,Audio_CertEnable enCert )
4326 {
4327     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4328 
4329     return(MDrv_AUDIO_SetCertMode(CertType, enCert));
4330 }
4331 
4332 /*
4333 ////////////////////////////////////////////////////////////////////////////////
4334 /// @brief \b Function \b Name: MApi_AUDIO_SetMaxClipping()
4335 /// @brief \b Function \b Description: Limit output if volume setting is high and output is going to exceed maximum power.
4336 ///                                    It should be used only when OSD AVL option is Off.
4337 /// @param MaxClippingValue \b : AVC threshold level for maximum volume
4338 /// @param Volume           \b : Current volume value
4339 ////////////////////////////////////////////////////////////////////////////////
4340 void MApi_AUDIO_SetMaxClipping( MS_U8 MaxClippingValue, MS_U16 Volume )
4341 {
4342     MS_U8 value1,value2;
4343     MS_U16 AVL, VOL_Int, VOL_Fra;
4344     MS_U8 SpeakerMaxVolume = 0x0C; //(MS_U8)(TvVolumeTable[100]>>8);
4345     MS_U8 DynamicAvl_active_volume = 0x17; // about -12dB for 2Vrms input, value of volume control register
4346 
4347     value1 = (MS_U8)(Volume>>8) & 0x7F;
4348     value2 =(MS_U8)((Volume&0x00FF)>>4);
4349 
4350     // Dynamic AVL clipping algorithm
4351     if(value1 < DynamicAvl_active_volume)
4352     {
4353         VOL_Int= (value1 - SpeakerMaxVolume)*2;  //0.5*2 = 1
4354         VOL_Fra= (value2)/4;       //0.125*4 = 0.5
4355         if((VOL_Int + VOL_Fra) < MaxClippingValue)
4356             AVL = MaxClippingValue - (VOL_Int + VOL_Fra);
4357         else
4358             AVL = 0;
4359     }
4360     else  // value1 >= DynamicAvl_active_volume
4361         AVL = 0;
4362 
4363     MApi_AUDIO_SetAvcThreshold(AVL);
4364     //debugAudioPrint ("VOL_int [%d]\r\n", VOL_Int);
4365     //debugAudioPrint ("VOL_Fra [%d]\r\n", VOL_Fra);
4366     //debugAudioPrint ("AVL [%d]\r\n", AVL);
4367 
4368 }
4369 */
4370 
4371 ////////////////////////////////////////////////////////////////////////////////
4372 /// @brief \b Function \b Name: MApi_AUDIO_SetPEQCoef()
4373 /// @brief \b Function \b Description: This routine is used to set PEQ Coefficient.
4374 /// @param <IN>        \b peq_coef
4375 /// @param <OUT>       \b NONE  :
4376 /// @param <RET>       \b  NONE :
4377 /// @param <GLOBAL>    \b NONE
4378 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetPEQCoef(AUDIO_PEQ_COEF * peq_coef)4379 void _MApi_AUDIO_SetPEQCoef(AUDIO_PEQ_COEF *peq_coef)
4380 {
4381     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4382 
4383     MDrv_SOUND_SetPEQCoef(peq_coef);
4384 }
4385 
4386 ////////////////////////////////////////////////////////////////////////////////
4387 /// @brief \b Function \b Name: MApi_AUDIO_EnablePEQ()
4388 /// @brief \b Function \b Description: This routine is used to eable PEQ.
4389 /// @param <IN>        \b Enpeq
4390 /// @param <OUT>       \b NONE  :
4391 /// @param <RET>       \b  NONE :
4392 /// @param <GLOBAL>    \b NONE
4393 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnablePEQ(MS_BOOL Enpeq)4394 void _MApi_AUDIO_EnablePEQ(MS_BOOL Enpeq)
4395 {
4396     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4397 
4398     MDrv_SOUND_EnablePEQ(Enpeq);
4399 }
4400 
4401 ////////////////////////////////////////////////////////////////////////////////
4402 /// @brief \b Function \b Name: MApi_AUDIO_EnableDcRemove()
4403 /// @brief \b Function \b Description: This routine is used to eable PEQ.
4404 /// @param <IN>        \b EnDcRemove
4405 /// @param <OUT>       \b True / False
4406 /// @param <RET>       \b  NONE :
4407 /// @param <GLOBAL>    \b NONE
4408 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_EnableDcRemove(MS_BOOL EnDcRemove)4409 MS_BOOL _MApi_AUDIO_EnableDcRemove(MS_BOOL EnDcRemove)
4410 {
4411     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4412 
4413     return MDrv_SOUND_EnableDcRemove(EnDcRemove);
4414 }
4415 
4416 ////////////////////////////////////////////////////////////////////////////////
4417 //
4418 //         AUDIO_MM RELATIONAL API FUNCTION
4419 //
4420 ////////////////////////////////////////////////////////////////////////////////
4421 //******************************************************************************
4422 /// @brief \b Function \b Name: MApi_AUDIO_SetCommAudioInfo()
4423 /// @brief \b Function \b Description: This routine is used for adjust Common Audio decoder parameters
4424 /// @return MS_BOOL     \b : True / False
4425 //******************************************************************************
_MApi_AUDIO_SetCommAudioInfo(Audio_COMM_infoType infoType,MS_VIRT param1,MS_VIRT param2)4426 MS_BOOL _MApi_AUDIO_SetCommAudioInfo( Audio_COMM_infoType infoType, MS_VIRT param1, MS_VIRT param2 )
4427 {
4428     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4429 
4430     return MDrv_AUDIO_SetCommAudioInfo(infoType, param1, param2);
4431 }
4432 
4433 //******************************************************************************
4434 /// @brief \b Function \b Name: MApi_AUDIO_SetMpegInfo()
4435 /// @brief \b Function \b Description: This routine is used for adjust MPEG Audio decoder parameters
4436 /// @return MS_BOOL     \b : True / False
4437 //******************************************************************************
_MApi_AUDIO_SetMpegInfo(Audio_MPEG_infoType infoType,MS_VIRT param1,MS_VIRT param2)4438 MS_BOOL _MApi_AUDIO_SetMpegInfo( Audio_MPEG_infoType infoType, MS_VIRT param1, MS_VIRT param2 )
4439 {
4440     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4441     return MDrv_AUDIO_SetMpegInfo(infoType, param1, param2);
4442 }
4443 
4444 //******************************************************************************
4445 /// @brief \b Function \b Name: MApi_AUDIO_SetAC3Info()
4446 /// @brief \b Function \b Description: This routine is used for adjust AC3 Audio decoder parameters
4447 /// @return MS_BOOL     \b : True / False
4448 //******************************************************************************
_MApi_AUDIO_SetAC3Info(Audio_AC3_infoType infoType,MS_VIRT param1,MS_VIRT param2)4449 MS_BOOL _MApi_AUDIO_SetAC3Info( Audio_AC3_infoType infoType, MS_VIRT param1, MS_VIRT param2 )
4450 {
4451     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4452     return MDrv_AUDIO_SetAC3Info(infoType, param1, param2);
4453 }
4454 
4455 //******************************************************************************
4456 /// @brief \b Function \b Name: MApi_AUDIO_SetAC3PInfo()
4457 /// @brief \b Function \b Description: This routine is used for adjust AC3+ Audio decoder parameters
4458 /// @return MS_BOOL     \b : True / False
4459 //******************************************************************************
_MApi_AUDIO_SetAC3PInfo(Audio_AC3P_infoType infoType,MS_VIRT param1,MS_VIRT param2)4460 MS_BOOL _MApi_AUDIO_SetAC3PInfo( Audio_AC3P_infoType infoType, MS_VIRT param1, MS_VIRT param2 )
4461 {
4462     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4463     return MDrv_AUDIO_SetAC3PInfo(infoType, param1, param2);
4464 }
4465 
4466 //******************************************************************************
4467 /// @brief \b Function \b Name: MApi_AUDIO_SetAACInfo()
4468 /// @brief \b Function \b Description: This routine is used for adjust AAC Audio decoder parameters
4469 /// @return MS_BOOL     \b : True / False
4470 //******************************************************************************
_MApi_AUDIO_SetAACInfo(Audio_AAC_infoType infoType,MS_VIRT param1,MS_VIRT param2)4471 MS_BOOL _MApi_AUDIO_SetAACInfo( Audio_AAC_infoType infoType, MS_VIRT param1, MS_VIRT param2 )
4472 {
4473     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4474     return MDrv_AUDIO_SetAACInfo(infoType, param1, param2);
4475 }
4476 
4477 //******************************************************************************
4478 /// @brief \b Function \b Name: MApi_AUDIO_SetWmaInfo()
4479 /// @brief \b Function \b Description: This routine is used for adjust WMA Audio decoder parameters
4480 /// @return MS_BOOL     \b : True / False
4481 //******************************************************************************
_MApi_AUDIO_SetWmaInfo(Audio_WMA_infoType infoType,MS_VIRT param1,MS_VIRT param2)4482 MS_BOOL _MApi_AUDIO_SetWmaInfo( Audio_WMA_infoType infoType, MS_VIRT param1, MS_VIRT param2 )
4483 {
4484     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4485     return MDrv_AUDIO_SetWmaInfo(infoType, param1, param2);
4486 }
4487 
4488 //******************************************************************************
4489 /// @brief \b Function \b Name: MApi_AUDIO_SetDTSCommonCtrl()
4490 /// @brief \b Function \b Description: This routine is used for adjust DTS Audio decoder control
4491 /// @return MS_BOOL     \b : True / False
4492 //******************************************************************************
_MApi_AUDIO_SetDTSCommonCtrl(Audio_DTS_infoType infoType,Audio_DTS_CtrlType ctrl_type)4493 MS_BOOL _MApi_AUDIO_SetDTSCommonCtrl( Audio_DTS_infoType infoType, Audio_DTS_CtrlType ctrl_type )
4494 {
4495     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4496     return MDrv_AUDIO_SetDTSCommonCtrl(infoType, ctrl_type);
4497 }
4498 
4499 
4500 
4501 //******************************************************************************
4502 /// @brief \b Function \b Name: MApi_AUDIO_GetCommAudioInfo()
4503 /// @brief \b Function \b Description: This routine will return the 64bit Common info according to info type
4504 /// @return MS_U64     \b : 64bit info
4505 //******************************************************************************
_MApi_AUDIO_GetCommAudioInfo(Audio_COMM_infoType infoType)4506 MS_U64 _MApi_AUDIO_GetCommAudioInfo( Audio_COMM_infoType infoType )
4507 {
4508     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4509 
4510     return MDrv_AUDIO_GetCommAudioInfo(infoType);
4511 }
4512 
4513 //******************************************************************************
4514 /// @brief \b Function \b Name: MApi_AUDIO_GetMpegInfo()
4515 /// @brief \b Function \b Description: This routine will return the 32bit mpeg info according to info type
4516 /// @return MS_U32     \b : 32bit info
4517 //******************************************************************************
_MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType infoType)4518 MS_U32 _MApi_AUDIO_GetMpegInfo( Audio_MPEG_infoType infoType )
4519 {
4520     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4521 
4522     return MDrv_AUDIO_GetMpegInfo(infoType);
4523 }
4524 
4525 //******************************************************************************
4526 /// @brief \b Function \b Name: MApi_AUDIO_GetAC3Info()
4527 /// @brief \b Function \b Description: This routine will return the 32bit ac3 info according to info type
4528 /// @return MS_U32     \b : 32bit info
4529 //******************************************************************************
_MApi_AUDIO_GetAC3Info(Audio_AC3_infoType infoType)4530 MS_U32 _MApi_AUDIO_GetAC3Info( Audio_AC3_infoType infoType )
4531 {
4532     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4533 
4534     return MDrv_AUDIO_GetAC3Info(infoType);
4535 }
4536 
4537 
4538 //******************************************************************************
4539 /// @brief \b Function \b Name: MApi_AUDIO_GetAC3PInfo()
4540 /// @brief \b Function \b Description: This routine will return the 32bit ac3+ info according to info type
4541 /// @return MS_U32     \b : 32bit info
4542 //******************************************************************************
_MApi_AUDIO_GetAC3PInfo(Audio_AC3P_infoType infoType)4543 MS_U32 _MApi_AUDIO_GetAC3PInfo( Audio_AC3P_infoType infoType )
4544 {
4545     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4546 
4547     return MDrv_AUDIO_GetAC3PInfo(infoType);
4548 }
4549 
4550 
4551 //******************************************************************************
4552 /// @brief \b Function \b Name: MApi_AUDIO_GetAACInfo()
4553 /// @brief \b Function \b Description: This routine will return the 32bit AAC info according to info type
4554 /// @return MS_U32     \b : 32bit info
4555 //******************************************************************************
_MApi_AUDIO_GetAACInfo(Audio_AAC_infoType infoType)4556 MS_U32 _MApi_AUDIO_GetAACInfo( Audio_AAC_infoType infoType )
4557 {
4558     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4559 
4560     return MDrv_AUDIO_GetAACInfo(infoType);
4561 }
4562 
4563 //******************************************************************************
4564 /// @brief \b Function \b Name: MApi_AUDIO_GetWmaInfo()
4565 /// @brief \b Function \b Description: This routine will return the 32bit wma info according to info type
4566 /// @return MS_U32     \b : 32bit info
4567 //******************************************************************************
_MApi_AUDIO_GetWmaInfo(Audio_WMA_infoType infoType)4568 MS_U32 _MApi_AUDIO_GetWmaInfo( Audio_WMA_infoType infoType )
4569 {
4570     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4571 
4572     return MDrv_AUDIO_GetWmaInfo(infoType);
4573 }
4574 
4575 //******************************************************************************
4576 /// @brief \b Function \b Name: MApi_AUDIO_GetDTSInfo()
4577 /// @brief \b Function \b Description: This routine will return the 32bit DTS info according to info type
4578 /// @return MS_U32     \b : 32bit info
4579 //******************************************************************************
_MApi_AUDIO_GetDTSInfo(Audio_DTS_infoType infoType)4580 MS_U32 _MApi_AUDIO_GetDTSInfo( Audio_DTS_infoType infoType )
4581 {
4582     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4583 
4584     return MDrv_AUDIO_GetDTSInfo(infoType);
4585 }
4586 
4587 ////////////////////////////////////////////////////////////////////////////////
4588 /// @brief \b Function \b Name: MApi_AUDIO_XPCM_Param()
4589 /// @brief \b Function \b Description: This routine configures necessary parameters when playing XPCM data
4590 /// @param audioType      \b :    1--lpcm;
4591 ///                               2--MS-ADPCM;
4592 ///                               17--IMA-ADPCM
4593 /// @param channels       \b :    0-- mono;
4594 ///                               1-- stereo
4595 /// @param sampleRate     \b :    8, 11.025, 16, 22.05, 44.1 and 48 (KHz)
4596 /// @param bitsPerSample  \b :    8--8 bits;
4597 ///                               16--16 bits
4598 /// @param blockSize      \b :    block size
4599 /// @param samplePerBlock \b :    samples per block
4600 /// @return MS_U8         \b :    TRUE--parameters are correct;
4601 ///                               FALSE--parameters are incorrect
4602 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_XPCM_Param(XPCM_TYPE audioType,MS_U8 channels,MS_U16 sampleRate,MS_U8 bitsPerSample,MS_U16 blockSize,MS_U16 samplePerBlock)4603 MS_U8 _MApi_AUDIO_XPCM_Param(XPCM_TYPE audioType, MS_U8  channels, MS_U16 sampleRate, MS_U8  bitsPerSample, MS_U16 blockSize, MS_U16 samplePerBlock)
4604 {
4605     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4606      return(MDrv_MAD_XPCM_setParam(audioType, channels, sampleRate, bitsPerSample, blockSize, samplePerBlock));
4607 }
4608 
4609 ////////////////////////////////////////////////////////////////////////////////
4610 /// @brief \b Function \b Name: MApi_AUDIO_XPCM2_Param()
4611 /// @brief \b Function \b Description: This routine configures necessary parameters when playing XPCM data
4612 /// @param audioType      \b :    1--lpcm;
4613 ///                               2--MS-ADPCM;
4614 ///                               17--IMA-ADPCM
4615 /// @param channels       \b :    0-- mono;
4616 ///                               1-- stereo
4617 /// @param sampleRate     \b :    8, 11.025, 16, 22.05, 44.1 and 48 (KHz)
4618 /// @param bitsPerSample  \b :    8--8 bits;
4619 ///                               16--16 bits
4620 /// @param blockSize      \b :    block size
4621 /// @param samplePerBlock \b :    samples per block
4622 /// @return MS_U8         \b :    TRUE--parameters are correct;
4623 ///                               FALSE--parameters are incorrect
4624 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_XPCM2_Param(XPCM_TYPE audioType,MS_U8 channels,MS_U16 sampleRate,MS_U8 bitsPerSample,MS_U16 blockSize,MS_U16 samplePerBlock)4625 void _MApi_AUDIO_XPCM2_Param(XPCM_TYPE audioType, MS_U8  channels, MS_U16 sampleRate, MS_U8  bitsPerSample, MS_U16 blockSize, MS_U16 samplePerBlock)
4626 {
4627     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4628 
4629      MDrv_MAD2_XPCM_setParam(audioType, channels, sampleRate, bitsPerSample, blockSize, samplePerBlock);
4630 }
4631 
4632 ////////////////////////////////////////////////////////////////////////////////
4633 /// @brief \b Function \b Name: MApi_AUDIO_XPCM2_CheckIntStatus()
4634 /// @brief \b Function \b Description: This routine is used to Read DSP internal sram value for int status by IDMA
4635 /// @param <OUT>       \b NONE    :
4636 /// @param <RET>       \b MS_U16  :     sram value for interrupt status
4637 /// @param <GLOBAL>    \b NONE    :
4638 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_XPCM2_CheckIntStatus(void)4639 MS_U16 _MApi_AUDIO_XPCM2_CheckIntStatus(void)
4640 {
4641     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4642 
4643     return MDrv_MAD2_XPCM2_CheckIntStatus();
4644 }
4645 
4646 ////////////////////////////////////////////////////////////////////////////////
4647 /// @brief \b Function \b Name: MApi_AUDIO_RA8_Param()
4648 /// @brief \b Function \b Description: This routine configures necessary parameters when playing RA8 LBR data
4649 /// @param mNumCodecs  \b :    1--stereo or mono
4650 ///                            2~5-- multi channels
4651 /// @param mSamples    \b :    output samples--256, 512, 1024
4652 /// @param mSampleRate \b :    8, 11.025, 16, 22.05, 44.1 (KHz)
4653 /// @param Channels    \b :    1-- mono
4654 ///                                    2-- stereo
4655 /// @param cplStart    \b :    0 ~ 51
4656 /// @param Regions     \b :    0 ~ 31
4657 /// @param cplQbits    \b :    0, 2, 3, 4, 5, 6
4658 /// @param FrameSize   \b :    bitstream size of every NumCodes (bytes)
4659 ///                                    Range--0 ~ 65535
4660 /// @return MS_U8      \b :    TRUE--parameters are correct;
4661 ///                            FALSE--parameters are incorrect
4662 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_RA8_Param(MS_U16 mNumCodecs,MS_U16 mSamples,MS_U16 mSampleRate,MS_U16 * Channels,MS_U16 * Regions,MS_U16 * cplStart,MS_U16 * cplQbits,MS_U16 * FrameSize)4663 MS_U8 _MApi_AUDIO_RA8_Param(MS_U16 mNumCodecs, MS_U16 mSamples, MS_U16 mSampleRate, MS_U16* Channels, MS_U16* Regions, MS_U16* cplStart, MS_U16* cplQbits, MS_U16* FrameSize)
4664 {
4665     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4666 
4667      return(MDrv_MAD_RA8_setParam(mNumCodecs, mSamples, mSampleRate, Channels, Regions, cplStart, cplQbits, FrameSize));
4668 }
4669 
4670 /******************************************************************************/
4671 // Comomon Function for MM
4672 /******************************************************************************/
4673 ////////////////////////////////////////////////////////////////////////////////
4674 /// @brief \b Function \b Name: MApi_AUDIO_Init()
4675 /// @brief \b Function \b Description: MM Music mode Initial Audio decoder
4676 /// @param <IN>        \b enDecSystem: Audio decoder type
4677 /// @param <OUT>       \b NONE    :
4678 /// @param <GLOBAL>    \b NONE    :
4679 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_Init(En_DVB_decSystemType enDecSystem)4680 void _MApi_AUDIO_Init(En_DVB_decSystemType enDecSystem)
4681 {
4682     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4683 
4684     // need mute by APP
4685 
4686     _MApi_AUDIO_SetCommand(MSAPI_AUD_DVB_DECCMD_STOP);
4687 
4688     u8IntTag = 1;
4689     MDrv_AUDIO_SetPlayFileFlag(DSP_DEC, 0);
4690 
4691     _MApi_AUDIO_SetSystem(enDecSystem);
4692 
4693     // need unmute by APP
4694 }
4695 
4696 ////////////////////////////////////////////////////////////////////////////////
4697 /// @brief \b Function \b Name: MApi_AUDIO_StartDecode()
4698 /// @brief \b Function \b Description: start play MM file
4699 /// @param <IN>        \b NONE    :
4700 /// @param <OUT>       \b NONE    :
4701 /// @param <GLOBAL>    \b NONE    :
4702 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_StartDecode(void)4703 void _MApi_AUDIO_StartDecode(void)
4704 {
4705     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4706 
4707     _MApi_AUDIO_SetCommand(MSAPI_AUD_DVB_DECCMD_PLAYFILE);//MDrv_MAD_SetDecCmd(0x04);
4708 }
4709 
4710 ////////////////////////////////////////////////////////////////////////////////
4711 /// @brief \b Function \b Name: MApi_AUDIO_StartBrowse()
4712 /// @brief \b Function \b Description: start browse file
4713 /// @param <IN>        \b NONE    :
4714 /// @param <OUT>       \b NONE    :
4715 /// @param <GLOBAL>    \b NONE    :
4716 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_StartBrowse(void)4717 void _MApi_AUDIO_StartBrowse(void)
4718 {
4719     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4720 
4721     // decode data but output no sound
4722     _MApi_AUDIO_SetCommand(MSAPI_AUD_DVB_DECCMD_STARTBROWSE);//MDrv_MAD_SetDecCmd(0x05);
4723 }
4724 
4725 ////////////////////////////////////////////////////////////////////////////////
4726 /// @brief \b Function \b Name: MApi_AUDIO_StopDecode()
4727 /// @brief \b Function \b Description: Stop decoder
4728 /// @param <IN>        \b NONE    :
4729 /// @param <OUT>       \b NONE    :
4730 /// @param <GLOBAL>    \b NONE    :
4731 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_StopDecode(void)4732 void _MApi_AUDIO_StopDecode(void)
4733 {
4734     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4735 
4736     _MApi_AUDIO_SetCommand(MSAPI_AUD_DVB_DECCMD_STOP);// MDrv_MAD_SetDecCmd(0x00);
4737 }
4738 
4739 ////////////////////////////////////////////////////////////////////////////////
4740 /// @brief \b Function \b Name: MApi_AUDIO_PauseDecode()
4741 /// @brief \b Function \b Description: pause decoder
4742 /// @param <IN>        \b NONE    :
4743 /// @param <OUT>       \b NONE    :
4744 /// @param <GLOBAL>    \b NONE    :
4745 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PauseDecode(void)4746 void _MApi_AUDIO_PauseDecode(void)
4747 {
4748     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4749 
4750     _MApi_AUDIO_SetCommand(MSAPI_AUD_DVB_DECCMD_PAUSE);//MDrv_MAD_SetDecCmd(0x06);
4751 }
4752 
4753 ////////////////////////////////////////////////////////////////////////////////
4754 /// @brief \b Function \b Name: MApi_AUDIO_CheckPlayDone()
4755 /// @brief \b Function \b Description: Check file play done. If file play done, will return TRUE
4756 /// @param <IN>        \b NONE    :
4757 /// @param <OUT>       \b MS_U8   : TRUE or FALSE
4758 /// @param <GLOBAL>    \b NONE    :
4759 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_CheckPlayDone(void)4760 MS_U8 _MApi_AUDIO_CheckPlayDone(void)
4761 {
4762 	AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4763 
4764     if (MDrv_AUDIO_CheckPlayDone() == TRUE)
4765     {
4766         _MApi_AUDIO_StopDecode();
4767         return TRUE;
4768     }
4769     return FALSE;
4770 }
4771 
4772 ////////////////////////////////////////////////////////////////////////////////
4773 /// @brief \b Function \b Name: MApi_AUDIO_GetResidualBufferSize()
4774 /// @brief \b Function \b Description: Get ES buffer level.
4775 /// @param <IN>        \b NONE    :
4776 /// @param <OUT>       \b MS_U16 : ES buffer level
4777 /// @param <GLOBAL>    \b NONE    :
4778 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetResidualBufferSize(void)4779 MS_U16 _MApi_AUDIO_GetResidualBufferSize(void)
4780 {
4781     return MDrv_AUDIO_ReadDecMailBox(0) << 3; // line size is 8
4782 }
4783 
4784 ////////////////////////////////////////////////////////////////////////////////
4785 /// @brief \b Function \b Name: MApi_AUDIO_GetPCMBufferSize()
4786 /// @brief \b Function \b Description: Get MP3 PCM buffer level.
4787 /// @param <IN>        \b u16BitRate    : Bit Rate
4788 /// @param <OUT>       \b MS_U16 : MP3 PCM buffer level
4789 /// @param <GLOBAL>    \b NONE    :
4790 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetPCMBufferSize(MS_U16 u16BitRate)4791 MS_U16 _MApi_AUDIO_GetPCMBufferSize(MS_U16 u16BitRate)
4792 {
4793     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4794 
4795     MS_U32 u32Tmp;
4796 
4797     u32Tmp = (MS_U32)MDrv_AUDIO_ReadDecMailBox(1);
4798     // line size is 8, 1 sample 2 bytes and 2 channels (Left & Right)
4799     //u32Tmp = ((u32Tmp << 1) * ((U32)u16BitRate * 1000 / 8))/MDrv_MAD_MPEG_GetSampleRate();
4800     if (_MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType_SampleRate) != 0)
4801         u32Tmp = ((u32Tmp << 1) * ((MS_U32)u16BitRate * 1000 / 8))/_MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType_SampleRate);
4802     return (MS_U16)u32Tmp;
4803 }
4804 
4805 ////////////////////////////////////////////////////////////////////////////////
4806 /// @brief \b Function \b Name: MApi_AUDIO_GetPCMBufferSize2()
4807 /// @brief \b Function \b Description: Get PCM buffer level.
4808 /// @param <IN>        \b u16BitRate : Bit Rate;
4809 /// @param <IN>        \b u16SampleRate : Sample Rate
4810 /// @param <OUT>       \b MS_U16 : PCM buffer level
4811 /// @param <GLOBAL>    \b NONE    :
4812 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetPCMBufferSize2(MS_U16 u16BitRate,MS_U16 u16SampleRate)4813 MS_U16 _MApi_AUDIO_GetPCMBufferSize2(MS_U16 u16BitRate,MS_U16 u16SampleRate)
4814 {
4815     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4816 
4817     MS_U32 u32Tmp;
4818 
4819     u32Tmp = (MS_U32)MDrv_AUDIO_ReadDecMailBox(1);
4820     // line size is 8, 1 sample 2 bytes and 2 channels (Left & Right)
4821     if(u16SampleRate != 0)//UT
4822         u32Tmp = ((u32Tmp << 1) * ((MS_U32)u16BitRate * 1000 / 8))/u16SampleRate;
4823 
4824     return (MS_U16)u32Tmp;
4825 }
4826 
4827 ////////////////////////////////////////////////////////////////////////////////
4828 /// @brief \b Function \b Name: MApi_AUDIO_SetInput()
4829 /// @brief \b Function \b Description: This function will inform DSP that MCU already write data to ES buffer by interrupt.
4830 /// @param <IN>        \b NONE    :
4831 /// @param <OUT>       \b NONE    :
4832 /// @param <GLOBAL>    \b NONE    :
4833 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetInput(void)4834 void _MApi_AUDIO_SetInput(void)
4835 {
4836     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4837 
4838     MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_DEC1_MMTag, (MS_U32)u8IntTag, 0);
4839     MDrv_AUDIO_SendIntrupt(DSP_DEC, 0xE0);
4840     u8IntTag++;
4841 }
4842 
4843 ////////////////////////////////////////////////////////////////////////////////
4844 /// @brief \b Function \b Name: MApi_AUDIO_SetSampleRateIndex()
4845 /// @brief \b Function \b Description: Set AAC sample rate index.
4846 /// @param <IN>        \b u16Index    :
4847 /// @param <OUT>       \b NONE    :
4848 /// @param <GLOBAL>    \b NONE    :
4849 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetSampleRateIndex(MS_U16 u16Index)4850 void _MApi_AUDIO_SetSampleRateIndex(MS_U16 u16Index)
4851 {
4852     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4853 
4854     _MDrv_AUDIO_WriteDecMailBox(4,u16Index);
4855 }
4856 
4857 ////////////////////////////////////////////////////////////////////////////////
4858 /// @brief \b Function \b Name: MApi_AUDIO_SetXPCMParam()
4859 /// @brief \b Function \b Description: Set XPCM paramaters
4860 /// @param <IN>        \b audioType :
4861 /// @param <IN>        \b channels :
4862 /// @param <IN>        \b sampleRate :
4863 /// @param <IN>        \b bitsPerSample :
4864 /// @param <IN>        \b samplePerBlock :
4865 /// @param <OUT>       \b NONE    :
4866 /// @param <GLOBAL>    \b NONE    :
4867 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetXPCMParam(XPCM_TYPE audioType,MS_U8 channels,MS_U16 sampleRate,MS_U8 bitsPerSample,MS_U16 blockSize,MS_U16 samplePerBlock)4868 void _MApi_AUDIO_SetXPCMParam(XPCM_TYPE audioType, MS_U8 channels, MS_U16 sampleRate, MS_U8 bitsPerSample, MS_U16 blockSize, MS_U16 samplePerBlock)
4869 {
4870     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4871 
4872     //MDrv_MAD_XPCM_setParam(audioType, channels, sampleRate, bitsPerSample, blockSize, samplePerBlock);
4873     _MApi_AUDIO_XPCM_Param(audioType, channels, sampleRate, bitsPerSample, blockSize, samplePerBlock);
4874 }
4875 
4876 ////////////////////////////////////////////////////////////////////////////////
4877 /// @brief \b Function \b Name: MApi_AUDIO_FileEndNotification()
4878 /// @brief \b Function \b Description: This function will inform DSP that file end
4879 /// @param <IN>        \b NONE    :
4880 /// @param <OUT>       \b NONE    :
4881 /// @param <GLOBAL>    \b NONE    :
4882 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FileEndNotification(void)4883 void _MApi_AUDIO_FileEndNotification(void)
4884 {
4885     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4886 
4887     CheckPlayDoneCnt = 0;
4888 
4889     _MDrv_AUDIO_WriteDecMailBox(6, (MS_U16)u8IntTag);
4890     MDrv_AUDIO_FwTriggerDSP(0xe0);        // should change to MDrv_AUDIO_FwTriggerDSP
4891 }
4892 
4893 ////////////////////////////////////////////////////////////////////////////////
4894 /// @brief \b Function \b Name: MApi_AUDIO_FileEndDataHandle()
4895 /// @brief \b Function \b Description: Info DSP that the last ES data left size.
4896 /// @param <IN>        \b u32DataLeft    :
4897 /// @param <OUT>       \b NONE    :
4898 /// @param <GLOBAL>    \b NONE    :
4899 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FileEndDataHandle(MS_U32 u32DataLeft)4900 void _MApi_AUDIO_FileEndDataHandle(MS_U32 u32DataLeft)
4901 {
4902     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4903 
4904     _MDrv_AUDIO_WriteDecMailBox(5,(MS_U16)(u32DataLeft>>3));
4905 }
4906 
4907 ////////////////////////////////////////////////////////////////////////////////
4908 /// @brief \b Function \b Name: MApi_AUDIO_CheckInputRequest()
4909 /// @brief \b Function \b Description: If MCU receive DSP interrupt, this function will return TRUE and report requested ES data buffer address and size
4910 /// @param <IN>        \b pU32WrtAddr    :
4911 /// @param <IN>        \b pU32WrtBytes   :
4912 /// @param <OUT>       \b MS_U8          : TRUE or FALSE
4913 /// @param <GLOBAL>    \b NONE    :
4914 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_CheckInputRequest(MS_PHY * pPHYWrtAddr,MS_U32 * pU32WrtBytes)4915 MS_U8 _MApi_AUDIO_CheckInputRequest(MS_PHY *pPHYWrtAddr, MS_U32 *pU32WrtBytes)
4916 {
4917     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4918 
4919     if((pPHYWrtAddr == NULL) || (pU32WrtBytes == NULL))//UT
4920         return FALSE;
4921     if (MDrv_AUDIO_GetPlayFileFlag(DSP_DEC))
4922     {
4923         MDrv_AUDIO_SetPlayFileFlag(DSP_DEC, 0);
4924         *pPHYWrtAddr = _MDrv_AUDIO_GetDspMadBaseAddr(DSP_DEC)+_MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DEC1_BufferAddr);
4925         *pU32WrtBytes = _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DEC1_BufferSize);
4926         return TRUE;
4927     }
4928     return FALSE;
4929 }
4930 
4931 ////////////////////////////////////////////////////////////////////////////////
4932 /// @brief \b Function \b Name: MApi_AUDIO_GetPlayTick()
4933 /// @brief \b Function \b Description: Get Play Time stamp
4934 /// @param <IN>        \b NONE    :
4935 /// @param <OUT>       \b NONE    :
4936 /// @param <GLOBAL>    \b NONE    :
4937 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetPlayTick(void)4938 MS_U32 _MApi_AUDIO_GetPlayTick(void)
4939 {
4940     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4941 
4942     return _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_1ms_PTS);
4943 }
4944 
4945 ////////////////////////////////////////////////////////////////////////////////
4946 /// @brief \b Function \b Name: MApi_AUDIO_GetEsMEMCnt()
4947 /// @brief \b Function \b Description: Get ES Bufffer size
4948 /// @param <IN>        \b NONE    :
4949 /// @param <OUT>       \b MS_U16  : ES Bufffer size
4950 /// @param <GLOBAL>    \b NONE    :
4951 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetEsMEMCnt(void)4952 MS_U16 _MApi_AUDIO_GetEsMEMCnt(void)
4953 {
4954     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4955 
4956     return MDrv_AUDIO_ReadDecMailBox(0);
4957 }
4958 
4959 ////////////////////////////////////////////////////////////////////////////////
4960 /// @brief \b Function \b Name: MApi_AUDIO_GetSampleRate()
4961 /// @brief \b Function \b Description: Get Sample Rate
4962 /// @param <IN>        \b NONE    :
4963 /// @param <OUT>       \b MS_U16 : Sample Rate
4964 /// @param <GLOBAL>    \b NONE    :
4965 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetSampleRate(void)4966 MS_U16 _MApi_AUDIO_GetSampleRate(void)
4967 {
4968     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4969 
4970     MS_U16 samplerate = 0;
4971     switch (enCurDecSystem)
4972     {
4973         case MSAPI_AUD_DVB_MPEG:
4974         case MSAPI_AUD_DVB_MP3:
4975             samplerate = _MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType_SampleRate);
4976             break;
4977         case MSAPI_AUD_DVB_WMA:
4978             samplerate = _MApi_AUDIO_GetWmaInfo(Audio_WMA_infoType_SampleRate);
4979             break;
4980         default:
4981             break;
4982     }
4983     return samplerate;
4984 }
4985 
4986 ////////////////////////////////////////////////////////////////////////////////
4987 /// @brief \b Function \b Name: MApi_AUDIO_GetBitRate()
4988 /// @brief \b Function \b Description: Get Bit Rate
4989 /// @param <IN>        \b NONE    :
4990 /// @param <OUT>       \b MS_U32  : Bit Rate
4991 /// @param <GLOBAL>    \b NONE    :
4992 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetBitRate(void)4993 MS_U32 _MApi_AUDIO_GetBitRate(void)
4994 {
4995     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
4996 
4997     MS_U32 bitrate = 0;
4998     switch (enCurDecSystem)
4999     {
5000         case MSAPI_AUD_DVB_MPEG:
5001         case MSAPI_AUD_DVB_MP3:
5002             bitrate = _MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType_BitRate);
5003             break;
5004         case MSAPI_AUD_DVB_WMA:
5005             bitrate = _MApi_AUDIO_GetWmaInfo(Audio_WMA_infoType_BitRate);
5006             break;
5007         default:
5008             break;
5009     }
5010     return bitrate;
5011 }
5012 
5013 /******************************************************************************/
5014 //  for MP3
5015 /******************************************************************************/
5016 ////////////////////////////////////////////////////////////////////////////////
5017 /// @brief \b Function \b Name: MApi_AUDIO_GetLayer()
5018 /// @brief \b Function \b Description: Get MP3 Layer
5019 /// @param <IN>        \b NONE    :
5020 /// @param <OUT>       \b Audio_MP3_LAYER : MPEG Layer
5021 /// @param <GLOBAL>    \b NONE    :
5022 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetLayer(void)5023 Audio_MP3_LAYER _MApi_AUDIO_GetLayer(void)
5024 {
5025     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5026 
5027     // MDrv_MAD_MPEG_GetLayer() return the layer of music. 1 & 2 for layer mpeg 1 & 2. 3 is for mp3
5028     Audio_MP3_LAYER enLayer = Audio_MP3_LAYER_NOT_DETERMINE_YET;
5029 
5030     switch(_MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType_Layer))
5031     {
5032         case 1:
5033             enLayer = Audio_MP3_LAYER_1;
5034             break;
5035         case 2:
5036             enLayer = Audio_MP3_LAYER_2;
5037             break;
5038         case 3:
5039             enLayer = Audio_MP3_LAYER_3;
5040             break;
5041         default:
5042             break;
5043     }
5044     return(enLayer);
5045 }
5046 
5047 ////////////////////////////////////////////////////////////////////////////////
5048 /// @brief \b Function \b Name: MApi_AUDIO_GetCurrentFrameNumber()
5049 /// @brief \b Function \b Description: Get MP3 Current Frame Number
5050 /// @param <IN>        \b NONE    :
5051 /// @param <OUT>       \b MS_U32  : Current Frame Number
5052 /// @param <GLOBAL>    \b NONE    :
5053 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetCurrentFrameNumber(void)5054 MS_U32 _MApi_AUDIO_GetCurrentFrameNumber(void)
5055 {
5056     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5057 
5058     return _MApi_AUDIO_GetMpegInfo(Audio_MPEG_infoType_FrameNum);
5059 }
5060 
5061 /******************************************************************************/
5062 //  for WMA
5063 /******************************************************************************/
5064 ////////////////////////////////////////////////////////////////////////////////
5065 /// @brief \b Function \b Name: MApi_AUDIO_SetASFParm()
5066 /// @brief \b Function \b Description: Set WMA ASF Paramaters
5067 /// @param <IN>        \b parm_type  :
5068 /// @param <IN>        \b value   :
5069 /// @param <OUT>       \b NONE    :
5070 /// @param <GLOBAL>    \b NONE    :
5071 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetASFParm(WMA_ASF_PARMTYPE parm_type,MS_U32 value)5072 void _MApi_AUDIO_SetASFParm(WMA_ASF_PARMTYPE parm_type, MS_U32 value)
5073 {
5074     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5075 
5076     _MApi_AUDIO_SetWmaInfo(Audio_WMA_infoType_Asf_Param, parm_type, value);
5077 }
5078 
5079 
5080 /******************************************************************************/
5081 //  for MM File Hand Shake
5082 /******************************************************************************/
5083 ////////////////////////////////////////////////////////////////////////////////
5084 /// @brief \b Function \b Name: MApi_AUDIO_MM_SetInput()
5085 /// @brief \b Function \b Description: MCU send interrupt to decoder1/2 in MM mode
5086 /// @param <IN>        \b AUDDecoderNo  : DVB_Audio_Decoder1 / DVB_Audio_Decoder2
5087 /// @param <IN>        \b u8IntTag   : Interrupt tag, increase by every time
5088 /// @param <OUT>       \b NONE    :
5089 /// @param <GLOBAL>    \b NONE    :
5090 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_MM_SetInput(En_DVB_AudioDecoder AUDDecoderNo,MS_U8 u8IntTag)5091 void _MApi_AUDIO_MM_SetInput (En_DVB_AudioDecoder AUDDecoderNo, MS_U8 u8IntTag)
5092 {
5093     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5094 
5095     if (AUDDecoderNo == DVB_Audio_Decoder1)
5096     {
5097         MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_DEC1_MMTag, (MS_U32)u8IntTag, 0);
5098         MDrv_AUDIO_SendIntrupt(DSP_DEC, 0xE0);
5099     }
5100     else
5101     {
5102         MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_DEC2_MMTag, (MS_U32)u8IntTag, 0);
5103         MDrv_AUDIO_SendIntrupt(DSP_SE, 0xE0);
5104     }
5105 }
5106 
5107 ////////////////////////////////////////////////////////////////////////////////
5108 /// @brief \b Function \b Name: MApi_AUDIO_MM_CheckPlayDone()
5109 /// @brief \b Function \b Description: MCU check audio play end in MM mode
5110 /// @param <IN>        \b AUDDecoderNo  : DVB_Audio_Decoder1 / DVB_Audio_Decoder2
5111 /// @param <OUT>       \b MS_U16    : Value of residual PCM level for file end stop
5112 /// @param <GLOBAL>    \b NONE    :
5113 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_MM_CheckPlayDone(En_DVB_AudioDecoder AUDDecoderNo)5114 MS_U32 _MApi_AUDIO_MM_CheckPlayDone (En_DVB_AudioDecoder AUDDecoderNo)
5115 {
5116     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5117 
5118     if (AUDDecoderNo == DVB_Audio_Decoder1)
5119     {
5120         return((MS_U32)MDrv_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DEC1_MMResidualPCM));
5121     }
5122     else
5123     {
5124         return((MS_U32)MDrv_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DEC2_MMResidualPCM));
5125     }
5126 }
5127 
5128 ////////////////////////////////////////////////////////////////////////////////
5129 /// @brief \b Function \b Name: MApi_AUDIO_MM_CheckInputRequest()
5130 /// @brief \b Function \b Description  : Decoder request input addr & size in MM mode
5131 /// @param <IN>        \b AUDDecoderNo : DVB_Audio_Decoder1 / DVB_Audio_Decoder2
5132 /// @param <IN>        \b pU32WrtAddr  : Request input address in ES1 buffer
5133 /// @param <IN>        \b pU32WrtBytes : Request input size
5134 /// @param <OUT>       \b MS_U8   : return TRUE if ok, else return FALSE
5135 /// @param <GLOBAL>    \b NONE    :
5136 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_MM_CheckInputRequest(En_DVB_AudioDecoder AUDDecoderNo,MS_PHY * pPHYWrtAddr,MS_U32 * pU32WrtBytes)5137 MS_U8 _MApi_AUDIO_MM_CheckInputRequest(En_DVB_AudioDecoder AUDDecoderNo, MS_PHY *pPHYWrtAddr, MS_U32 *pU32WrtBytes)
5138 {
5139     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5140 
5141     if (AUDDecoderNo == DVB_Audio_Decoder1)
5142     {
5143         if (MDrv_AUDIO_GetPlayFileFlag(DSP_DEC))
5144         {
5145             MDrv_AUDIO_SetPlayFileFlag(DSP_DEC, 0);
5146             *pPHYWrtAddr =  _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_ADEC1_esBuf_reqAddr);
5147             *pU32WrtBytes = _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DEC1_BufferSize);
5148             return TRUE;
5149         }
5150         return FALSE;
5151     }
5152     else
5153     {
5154         if (MDrv_AUDIO_GetPlayFileFlag(DSP_SE))
5155         {
5156             MDrv_AUDIO_SetPlayFileFlag(DSP_SE, 0);
5157             *pPHYWrtAddr =  _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_ADEC2_esBuf_reqAddr);
5158             *pU32WrtBytes = _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_DEC2_BufferSize);
5159             return TRUE;
5160         }
5161         return FALSE;
5162     }
5163 }
5164 
5165 
5166 ////////////////////////////////////////////////////////////////////////////////
5167 /// @brief \b Function \b Name: MApi_AUDIO_MM2_initAesInfo()
5168 /// @brief \b Function \b Description  : Initialize AES info
5169 /// @param <IN>        \b dec_id  : Decoder ID
5170 /// @param <OUT>       \b MS_BOOL : return TRUE if ok, else return FALSE
5171 /// @param <GLOBAL>    \b NONE    :
5172 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_MM2_initAesInfo(AUDIO_DEC_ID dec_id)5173 MS_BOOL _MApi_AUDIO_MM2_initAesInfo( AUDIO_DEC_ID dec_id )
5174 {
5175     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5176     return MDrv_AUDIO_MM2_initAesInfo( dec_id );
5177 }
5178 
5179 
5180 ////////////////////////////////////////////////////////////////////////////////
5181 /// @brief \b Function \b Name: MApi_AUDIO_MM2_checkAesInfo()
5182 /// @brief \b Function \b Description  : Get AES info from audio decoder
5183 /// @param <IN>        \b dec_id       : Decoder ID
5184 /// @param <IN>        \b aes_info     : AES info structure pointer
5185 /// @param <OUT>       \b MS_BOOL : return TRUE if ok, else return FALSE
5186 /// @param <GLOBAL>    \b NONE    :
5187 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_MM2_checkAesInfo(AUDIO_DEC_ID dec_id,AES_INFO * aes_info)5188 MS_BOOL _MApi_AUDIO_MM2_checkAesInfo( AUDIO_DEC_ID  dec_id, AES_INFO *aes_info )
5189 {
5190     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5191 
5192     return MDrv_AUDIO_MM2_checkAesInfo( dec_id, aes_info );
5193 }
5194 
5195 
5196 ////////////////////////////////////////////////////////////////////////////////
5197 /// @brief \b Function \b Name: MApi_AUDIO_MM2_inputAesFinished()
5198 /// @brief \b Function \b Description  : Inform DSP how much ES data is sent
5199 /// @param <IN>        \b dec_id	   : Decoder ID
5200 /// @param <IN>        \b es_size  : Size of ES data
5201 /// @param <IN>        \b ptsExist : Whether ES data contains PTS or not
5202 /// @param <IN>        \b pts	   : PTS
5203 /// @param <OUT>       \b MS_BOOL  : return TRUE if ok, else return FALSE
5204 /// @param <GLOBAL>    \b NONE     :
5205 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_MM2_inputAesFinished(AUDIO_DEC_ID dec_id,MS_U32 es_size,MS_BOOL ptsExist,MS_U64 pts)5206 MS_BOOL _MApi_AUDIO_MM2_inputAesFinished( AUDIO_DEC_ID dec_id, MS_U32 es_size, MS_BOOL ptsExist, MS_U64 pts )
5207 {
5208     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5209 
5210     return MDrv_AUDIO_MM2_inputAesFinished( dec_id, es_size, ptsExist, pts );
5211 }
5212 
5213 
5214 ////////////////////////////////////////////////////////////////////////////////
5215 /// @brief \b Function \b Name: MApi_AUDIO_USBPCM_Enable()  @@Need_Modify
5216 /// @brief \b Function \b Description:  Enable/ Disable the path of USB PCM
5217 /// @param <IN>        \b bEnable : on: TRUE, off: FALSE
5218 /// @param <OUT>       \b NONE    :
5219 /// @param <RET>       \b NONE    :
5220 /// @param <GLOBAL>    \b NONE    :
5221 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_USBPCM_Enable(MS_BOOL bEnable)5222 void _MApi_AUDIO_USBPCM_Enable(MS_BOOL bEnable)
5223 {
5224     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5225 
5226     MDrv_AUDIO_USBPCM_Enable(bEnable);
5227 }
5228 
5229 
5230 ////////////////////////////////////////////////////////////////////////////////
5231 /// @brief \b Function \b Name: MApi_AUDIO_USBPCM_SetFlag()  @@Need_Modify
5232 /// @brief \b Function \b Description:  clear interrupt flag for USBPCM function
5233 ///                    \b               (Encoder path)
5234 /// @param <IN>        \b bEnable :  set false to clean interrupt flag
5235 /// @param <OUT>       \b NONE    :
5236 /// @param <RET>       \b NONE    :
5237 /// @param <GLOBAL>    \b NONE    :
5238 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_USBPCM_SetFlag(MS_BOOL bEnable)5239 void _MApi_AUDIO_USBPCM_SetFlag(MS_BOOL bEnable)
5240 {
5241     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5242 
5243     MDrv_AUDIO_USBPCM_SetFlag(bEnable);
5244 }
5245 
5246 ////////////////////////////////////////////////////////////////////////////////
5247 /// @brief \b Function \b Name: MApi_AUDIO_USBPCM_GetFlag()  @@Need_Modify
5248 /// @brief \b Function \b Description:  Get interrupt flag for USBPCM function
5249 ///                    \b               (Encoder path)
5250 /// @param <IN>        \b NONE    :
5251 /// @param <OUT>       \b NONE    :
5252 /// @param <RET>       \b BOOL    :   interrupt flag
5253 /// @param <GLOBAL>    \b NONE    :
5254 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_USBPCM_GetFlag(void)5255 MS_BOOL _MApi_AUDIO_USBPCM_GetFlag(void)
5256 {
5257     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5258 
5259     return MDrv_AUDIO_USBPCM_GetFlag();
5260 }
5261 
5262 ////////////////////////////////////////////////////////////////////////////////
5263 /// @brief \b Function \b Name: MApi_AUDIO_USBPCM_GetMemInfo()  @@Need_Modify
5264 /// @brief \b Function \b Description:  Get memory address and size for USBPCM function
5265 ///                    \b               (Encoder path)
5266 /// @param <IN>        \b NONE    :
5267 /// @param <OUT>       \b MS_U32  : address, size
5268 /// @param <RET>       \b NONE    :
5269 /// @param <GLOBAL>    \b NONE    :
5270 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_USBPCM_GetMemInfo(AUDIO_UPLOAD_INFO * uploadInfo)5271 void    _MApi_AUDIO_USBPCM_GetMemInfo(AUDIO_UPLOAD_INFO *uploadInfo)
5272 {
5273     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5274 
5275     MDrv_AUDIO_USBPCM_GetMemInfo(uploadInfo);
5276 }
5277 
5278 ////////////////////////////////////////////////////////////////////////////////
5279 /// @brief \b Function \b Name: MApi_AUDIO_DmaReader_Init()
5280 /// @brief \b Function \b Description:
5281 /// @param <IN>        \b   eType   : sampleRate
5282 /// @param <OUT>       \b NONE    :
5283 /// @param <RET>       \b NONE    :
5284 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DmaReader_Init(SAMPLE_RATE sampleRate)5285 void _MApi_AUDIO_DmaReader_Init(SAMPLE_RATE sampleRate)
5286 {
5287     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5288 
5289     MDrv_AUDIO_DmaReader_Init(sampleRate);
5290 }
5291 
5292 ////////////////////////////////////////////////////////////////////////////////
5293 /// @brief \b Function \b Name: MApi_AUDIO_DmaReader_AllInput_Init()
5294 /// @brief \b Function \b Description: Used DMA reader in all audio source application
5295 ///                    \b              (ex: Key sound) (CHIP_T8/T12) (48KHz only)
5296 /// @param <IN>        \b   eType   : sampleRate
5297 /// @param <OUT>       \b NONE    :
5298 /// @param <RET>       \b NONE    :
5299 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DmaReader_AllInput_Init(void)5300 void _MApi_AUDIO_DmaReader_AllInput_Init(void)
5301 {
5302     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5303 
5304     MDrv_AUDIO_DmaReader_AllInput_Init();
5305 }
5306 
5307 ////////////////////////////////////////////////////////////////////////////////
5308 /// @brief \b Function \b Name: MApi_AUDIO_DmaReader_WritePCM()
5309 /// @brief \b Function \b Description: This routine is used to write PCM data into DMA reader Buffer
5310 /// @param <IN>        \b   eType   : buffer size (must be multiple of 8 Byte)
5311 /// @param <OUT>       \b MS_BOOL    : TRUE or FALSE
5312 /// @param <RET>       \b NONE    :
5313 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DmaReader_WritePCM(void * buffer,MS_U32 bytes)5314 MS_BOOL _MApi_AUDIO_DmaReader_WritePCM(void* buffer, MS_U32 bytes)
5315 {
5316     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5317 
5318     return(MDrv_AUDIO_DmaReader_WritePCM(buffer,bytes));
5319 }
5320 
5321 ////////////////////////////////////////////////////////////////////////////////
5322 /// @brief \b Function \b Name: MApi_AUDIO_DmaWriter_Init()
5323 /// @brief \b Function \b Description:
5324 /// @param <IN>        \b NONE    :
5325 /// @param <OUT>       \b NONE    :
5326 /// @param <RET>       \b NONE    :
5327 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_DmaWriter_Init()5328 void _MApi_AUDIO_DmaWriter_Init()
5329 {
5330     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5331 
5332     MDrv_AUDIO_DmaWriter_Init();
5333 }
5334 
5335 ////////////////////////////////////////////////////////////////////////////////
5336 /// @brief \b Function \b Name: MApi_AUDIO_VoIP_Config()
5337 /// @brief \b Function \b Description:  This routine is used for VoIP applications
5338 /// @param <IN>        \b AUDIO_VoIP_CONFIG_TYPE : configType
5339 /// @param <IN>        \b MS_U32 : param1
5340 /// @param <IN>        \b MS_U32 : param2
5341 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
5342 /// @param <RET>       \b NONE    :
5343 /// @param <GLOBAL>    \b NONE    :
5344 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_VoIP_Config(AUDIO_VoIP_CONFIG_TYPE configType,MS_U32 param1,MS_U32 param2)5345 MS_BOOL _MApi_AUDIO_VoIP_Config(AUDIO_VoIP_CONFIG_TYPE configType, MS_U32 param1, MS_U32 param2)
5346 {
5347     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5348 
5349     return MDrv_AUDIO_VoIP_Config(configType, param1, param2);
5350 }
5351 
5352 ////////////////////////////////////////////////////////////////////////////////
5353 /// @brief \b Function \b Name: MApi_AUDIO_ALSA_Check()
5354 /// @brief \b Function \b Description:  Check if ALSA Interface is supported
5355 /// @param <IN>        \b bEnable : on: TRUE, off: FALSE
5356 /// @param <OUT>       \b MS_BOOL    : return TRUE if it's supported, else return FALSE
5357 /// @param <RET>       \b NONE    :
5358 /// @param <GLOBAL>    \b NONE    :
5359 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ALSA_Check(void)5360 MS_BOOL _MApi_AUDIO_ALSA_Check(void)
5361 {
5362     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5363 
5364     return MDrv_AUDIO_ALSA_Check();
5365 }
5366 
5367 ////////////////////////////////////////////////////////////////////////////////
5368 /// @brief \b Function \b Name: MApi_AUDIO_ALSA_Enable()
5369 /// @brief \b Function \b Description:  Enable/ Disable the path of ALSA
5370 /// @param <IN>        \b bEnable : on: TRUE, off: FALSE
5371 /// @param <OUT>       \b MS_BOOL    : return TRUE if ok, else return FALSE
5372 /// @param <RET>       \b NONE    :
5373 /// @param <GLOBAL>    \b NONE    :
5374 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ALSA_Enable(MS_BOOL bEnable)5375 MS_BOOL _MApi_AUDIO_ALSA_Enable(MS_BOOL bEnable)
5376 {
5377     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5378 
5379     if (_MApi_AUDIO_ALSA_Check() != TRUE)
5380     {
5381         return FALSE;
5382     }
5383 
5384     if (bEnable == TRUE)
5385     {
5386         _MApi_AUDIO_SetSourceInfo(E_AUDIO_INFO_GAME_IN);
5387         _MApi_AUDIO_InputSwitch(AUDIO_DSP1_DVB_INPUT, E_AUDIO_GROUP_MAIN);
5388     }
5389 
5390     return MDrv_AUDIO_ALSA_Enable(bEnable);
5391 }
5392 
5393 ////////////////////////////////////////////////////////////////////////////////
5394 /// @brief \b Function \b Name: MApi_AUDIO_UNI_CheckDecodeDone()
5395 /// @brief \b Function \b Description  : Decoder report pcm out addr & size in Uniplayer mode
5396 /// @param <IN>        \b pU32WrtAddr  : Request input address in ES1 buffer
5397 /// @param <IN>        \b pU32WrtBytes : Request input size
5398 /// @param <OUT>       \b MS_U8   : return TRUE if ok, else return FALSE
5399 /// @param <GLOBAL>    \b NONE    :
5400 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_UNI_CheckDecodeDone(MS_PHY * pPHYWrtAddr,MS_U32 * pU32WrtBytes)5401 MS_BOOL _MApi_AUDIO_UNI_CheckDecodeDone(MS_PHY *pPHYWrtAddr, MS_U32 *pU32WrtBytes)
5402 {
5403     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5404 
5405     APIAUDIO_CHECK_SHM_INIT;
5406 
5407     if ( g_AudioVars2->u16DecodeFrmCnt[AU_DEC_ID1] != MDrv_AUDIO_GetUniDecodeDoneTag() )
5408     {
5409         g_AudioVars2->u16DecodeFrmCnt[AU_DEC_ID1] = MDrv_AUDIO_GetUniDecodeDoneTag();
5410         *pPHYWrtAddr  = _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_ADEC1_UNI_pcm_wptr);
5411         *pU32WrtBytes = _MApi_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_ADEC1_UNI_pcm_decSize);
5412         return TRUE;
5413     }
5414     else
5415     {
5416         return FALSE;
5417     }
5418 }
5419 
5420 ////////////////////////////////////////////////////////////////////////////////
5421 /// @brief \b Function \b Name: MApi_AUDIO_UNI_SetOutput()
5422 /// @brief \b Function \b Description: MCU send interrupt to decoder1 in Uniplayer mode
5423 /// @param <IN>        \b PCMOutCnt   : Get output PCM count by MCU
5424 /// @param <OUT>       \b NONE    :
5425 /// @param <GLOBAL>    \b NONE    :
5426 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_UNI_SetOutput(MS_U32 PCMOutCnt)5427 void _MApi_AUDIO_UNI_SetOutput (MS_U32 PCMOutCnt)
5428 {
5429     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5430 
5431     MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_ADEC1_UNI_PCMOutCnt, PCMOutCnt, 0);
5432     MDrv_AUDIO_SendIntrupt(DSP_DEC, 0xE3);
5433 }
5434 
5435 ////////////////////////////////////////////////////////////////////////////////
5436 /// @brief \b Function \b Name: MApi_AUDIO_UNI_Set_PCMInputWriteAddr()
5437 /// @brief \b Function \b Description: MCU send DEC1-PCM3 wptr to decoder1 in Uniplayer mode
5438 /// @param <IN>        \b PCMIn_Wptr   : PCM3 write pointer to DSP
5439 /// @param <OUT>       \b NONE    :
5440 /// @param <GLOBAL>    \b NONE    :
5441 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_UNI_Set_PCMInputWriteAddr(MS_U32 PCMIn_Wptr)5442 void _MApi_AUDIO_UNI_Set_PCMInputWriteAddr (MS_U32 PCMIn_Wptr)
5443 {
5444     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5445 
5446     MDrv_AUDIO_SetCommAudioInfo(Audio_Comm_infoType_ADEC1_UNI_PCMInput_Addr, PCMIn_Wptr, 0);
5447 }
5448 
5449 ////////////////////////////////////////////////////////////////////////////////
5450 /// @brief \b Function \b Name: MApi_AUDIO_UNI_Get_OutPCMLevel()
5451 /// @brief \b Function \b Description: Decoder1 report DEC1-PCM3 buffer level in Uniplayer mode
5452 /// @param <OUT>       \b MS_U32  : DEC1-PCM3 buffer level (byte unit)
5453 /// @param <GLOBAL>    \b NONE    :
5454 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_UNI_Get_OutPCMLevel(void)5455 MS_U32 _MApi_AUDIO_UNI_Get_OutPCMLevel (void)
5456 {
5457     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5458 
5459     return (MDrv_AUDIO_GetCommAudioInfo(Audio_Comm_infoType_ADEC1_UNI_OutPCMLevel));
5460 }
5461 
5462 ////////////////////////////////////////////////////////////////////////////////
5463 /// @brief \b Function \b Name: MApi_AUDIO_RingTask()
5464 /// @brief \b Function \b Description :
5465 /// @param <IN>        \b auRingTask  :
5466 /// @param <GLOBAL>    \b NONE        :
5467 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_RingTask(audioRingTask * auRingTask)5468 void _MApi_AUDIO_RingTask(audioRingTask* auRingTask)        // this function is used for auto ring address
5469 {
5470     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5471 
5472     MS_U32 u32Addr_temp;
5473     MS_U32 u32Size_temp;
5474     auRingTask->u8RingStatus = 0;   // 0: no need to ring
5475                                     // 1: not ring, but at the edge of buffer, next time will start from the head of the buf
5476                                     // 2: ring
5477                                     // 3: special case, pointer out or range
5478 
5479     if((auRingTask->u32ReqAddr >= auRingTask->_stBufInfo.u32BufStartAddr)&&(auRingTask->u32ReqAddr <= auRingTask->_stBufInfo.u32BufEndAddr))
5480     {
5481         u32Addr_temp = auRingTask->u32ReqAddr + auRingTask->u32ReqSize; // target end address
5482 
5483         if(u32Addr_temp < auRingTask->_stBufInfo.u32BufEndAddr )   // no need to ring
5484         {
5485             auRingTask->u8RingStatus = 0;
5486             auRingTask->phyRetAddr1 = auRingTask->u32ReqAddr;
5487             auRingTask->u32RetSize1 = auRingTask->u32ReqSize;
5488             auRingTask->_stBufInfo.u32BufWrPtr = u32Addr_temp;
5489         }
5490         else if(u32Addr_temp == auRingTask->_stBufInfo.u32BufEndAddr)   // not ring, just make
5491         {
5492             auRingTask->u8RingStatus = 1;
5493             auRingTask->phyRetAddr1 = auRingTask->u32ReqAddr;
5494             auRingTask->u32RetSize1 = auRingTask->u32ReqSize;
5495             auRingTask->_stBufInfo.u32BufWrPtr = auRingTask->_stBufInfo.u32BufStartAddr;
5496         }
5497         else    // ring
5498         {
5499             auRingTask->u8RingStatus = 2;
5500             auRingTask->phyRetAddr1 = auRingTask->u32ReqAddr;
5501             auRingTask->u32RetSize1 = auRingTask->_stBufInfo.u32BufEndAddr - auRingTask->u32ReqAddr;
5502             auRingTask->phyRetAddr2 = auRingTask->_stBufInfo.u32BufStartAddr;
5503             auRingTask->u32RetSize2 = auRingTask->u32ReqSize -auRingTask->u32RetSize1;
5504             auRingTask->_stBufInfo.u32BufWrPtr = auRingTask->_stBufInfo.u32BufStartAddr + auRingTask->u32RetSize2;
5505         }
5506     }
5507     else if(auRingTask->u32ReqAddr > auRingTask->_stBufInfo.u32BufEndAddr)   // special case, pointer out of range
5508     {
5509         auRingTask->u8RingStatus = 3;
5510         u32Size_temp = auRingTask->u32ReqAddr - auRingTask->_stBufInfo.u32BufEndAddr;
5511         auRingTask->phyRetAddr1 = auRingTask->_stBufInfo.u32BufStartAddr + u32Size_temp;
5512         auRingTask->u32RetSize1 = auRingTask->u32ReqSize;
5513         auRingTask->_stBufInfo.u32BufWrPtr = auRingTask->phyRetAddr1 + auRingTask->u32RetSize1;
5514     }
5515     else
5516     {
5517         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "\r\n @@@ request pointer error, smaller than start address @@@ \r\n");
5518     }
5519 }
5520 
5521 
5522 ////////////////////////////////////////////////////////////////////////////////
5523 /// @brief \b Function \b Name: MApi_AUDIO_Ring_DataTransfer()
5524 /// @brief \b Function \b Description :
5525 /// @param <IN>        \b auRingTask  :
5526 /// @param <GLOBAL>    \b NONE        :
5527 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_Ring_DataTransfer(audioRingTask * auRingTask,audioRingTask * auRingTask_1)5528 void _MApi_AUDIO_Ring_DataTransfer(audioRingTask* auRingTask, audioRingTask* auRingTask_1)
5529 {
5530     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5531 
5532     switch(auRingTask->u8RingStatus)     // copy data from PCM1 to PCM2
5533     {
5534         case 0:     // no need to ring for read
5535         case 1:     // just make, no need to ring
5536             if((auRingTask_1->u8RingStatus == 0)||(auRingTask_1->u8RingStatus == 1))
5537             {
5538                 //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1, auRingTask_1->phyRetAddr1, (MS_U16)auRingTask_1->u32RetSize1);
5539                 AU_memcpy((void *) (MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1)), (void *)MsOS_PA2KSEG1(auRingTask->phyRetAddr1), auRingTask_1->u32RetSize1);
5540             }
5541             else if(auRingTask_1->u8RingStatus == 2) // need to ring
5542             {
5543                 //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1, auRingTask_1->phyRetAddr1, (MS_U16)auRingTask_1->u32RetSize1);
5544                 //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", (auRingTask->phyRetAddr1 + auRingTask_1->u32RetSize1), auRingTask_1->phyRetAddr2, (MS_U16)auRingTask_1->u32RetSize2);
5545                 AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1), auRingTask_1->u32RetSize1);
5546                 AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr2)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1 + auRingTask_1->u32RetSize1), auRingTask_1->u32RetSize2);
5547             }
5548             else
5549             {
5550                AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "\r\n ==== kochien print:  data control error @@@@ \r\n");
5551             }
5552             break;
5553 
5554         case 2:
5555             if((auRingTask_1->u8RingStatus == 0)||(auRingTask_1->u8RingStatus == 1))  // only PCM1 need to ring
5556             {
5557                 //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1, auRingTask_1->phyRetAddr1, (MS_U16)auRingTask->u32RetSize1);
5558                 //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr2, auRingTask_1->phyRetAddr1 + auRingTask->u32RetSize1, (MS_U16)auRingTask->u32RetSize2);
5559                 AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1), auRingTask->u32RetSize1);
5560                 AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1 + auRingTask->u32RetSize1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr2), auRingTask->u32RetSize2);
5561             }
5562             else if(auRingTask_1->u8RingStatus == 2) // both PCM1 and PCM2 need to ring
5563             {
5564                 if(auRingTask->u32RetSize1 == auRingTask_1->u32RetSize1)
5565                 {
5566                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1, auRingTask_1->phyRetAddr1, (MS_U16)auRingTask->u32RetSize1);
5567                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr2, auRingTask_1->phyRetAddr2, (MS_U16)auRingTask->u32RetSize2);
5568                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1), auRingTask->u32RetSize1);
5569                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr2)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr2), auRingTask->u32RetSize2);
5570                 }
5571                 else if(auRingTask->u32RetSize1 > auRingTask_1->u32RetSize1)
5572                 {
5573                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1, auRingTask_1->phyRetAddr1, (MS_U16)auRingTask->u32RetSize1);
5574                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1 + auRingTask_1->u32RetSize1, auRingTask_1->phyRetAddr2, (MS_U16)(auRingTask->u32RetSize1 - auRingTask_1->u32RetSize1));
5575                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr2, auRingTask_1->phyRetAddr2 + auRingTask->u32RetSize1 - auRingTask_1->u32RetSize1, (MS_U16)auRingTask->u32RetSize2);
5576                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1), auRingTask_1->u32RetSize1);
5577                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr2)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1 + auRingTask_1->u32RetSize1), (auRingTask->u32RetSize1 - auRingTask_1->u32RetSize1));
5578                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr2 + auRingTask->u32RetSize1 - auRingTask_1->u32RetSize1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr2), auRingTask->u32RetSize2);
5579                 }
5580                 else
5581                 {
5582                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr1, auRingTask_1->phyRetAddr1, (MS_U16)auRingTask->u32RetSize1);
5583                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", auRingTask->phyRetAddr2, auRingTask_1->phyRetAddr1 + auRingTask->u32RetSize1, (MS_U16)(auRingTask_1->u32RetSize1 - auRingTask->u32RetSize1));
5584                     //AUDIO_PRINT(AUDIO_DEBUG_LEVEL_INFO, " Sr[0x%lx]->Des[0x%lx], size[0x%x]", (auRingTask->phyRetAddr2 + auRingTask_1->u32RetSize1 - auRingTask->u32RetSize1), auRingTask_1->phyRetAddr2, (MS_U16)auRingTask_1->u32RetSize2);
5585                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr1), auRingTask->u32RetSize1);
5586                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr1 + auRingTask->u32RetSize1)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr2), (auRingTask_1->u32RetSize1 - auRingTask->u32RetSize1));
5587                     AU_memcpy((void*)(MsOS_PA2KSEG1(auRingTask_1->phyRetAddr2)), (void*)MsOS_PA2KSEG1(auRingTask->phyRetAddr2 + auRingTask_1->u32RetSize1 - auRingTask->u32RetSize1), auRingTask_1->u32RetSize2);
5588                 }
5589             }
5590             else
5591             {
5592                 //AudioDbgPrint_Uniplayer(AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "\r\n ==== data control error \r\n" ));
5593                 AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "\r\n ==== case2: data control error \r\n");
5594             }
5595             break;
5596 
5597         case 3:
5598         default:
5599             AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "\r\n ==== case3: data control error \r\n");
5600             break;
5601     }
5602     MsOS_FlushMemory();
5603     MsOS_Sync();
5604 }
5605 
5606 ////////////////////////////////////////////////////////////////////////////////
5607 /// @brief \b Function \b Name: MApi_AUDIO_SetDataCaptureSource()
5608 /// @brief \b Function \b Description:  Select source for data capture
5609 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
5610 /// @param <IN>        \b AUDIO_CAPTURE_SOURCE_TYPE : Data Source
5611 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
5612 /// @param <RET>       \b NONE    :
5613 /// @param <GLOBAL>    \b NONE    :
5614 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_SetDataCaptureSource(AUDIO_DEVICE_TYPE eID,AUDIO_CAPTURE_SOURCE_TYPE eSource)5615 MS_BOOL _MApi_AUDIO_SetDataCaptureSource(AUDIO_DEVICE_TYPE eID, AUDIO_CAPTURE_SOURCE_TYPE eSource)
5616 {
5617     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5618 
5619     return MDrv_AUDIO_SetDataCaptureSource(eID, eSource);
5620 }
5621 
5622 ////////////////////////////////////////////////////////////////////////////////
5623 /// @brief \b Function \b Name: MApi_AUDIO_PCMCapture_Init()
5624 /// @brief \b Function \b Description:  Select source for pcm capture
5625 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
5626 /// @param <IN>        \b AUDIO_CAPTURE_SOURCE_TYPE : Data Source
5627 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
5628 /// @param <RET>       \b NONE    :
5629 /// @param <GLOBAL>    \b NONE    :
5630 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCMCapture_Init(const AUDIO_DEVICE_TYPE eID,const AUDIO_CAPTURE_SOURCE_TYPE eSource)5631 MS_BOOL _MApi_AUDIO_PCMCapture_Init(const AUDIO_DEVICE_TYPE eID, const AUDIO_CAPTURE_SOURCE_TYPE eSource)
5632 {
5633     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5634 
5635     return MDrv_AUDIO_PCMCapture_Init(eID, eSource);
5636 }
5637 
5638 ////////////////////////////////////////////////////////////////////////////////
5639 /// @brief \b Function \b Name: MApi_AUDIO_PCMCapture_Start()
5640 /// @brief \b Function \b Description:  captrue pcm data to DDR
5641 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
5642 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
5643 /// @param <RET>       \b NONE    :
5644 /// @param <GLOBAL>    \b NONE    :
5645 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCMCapture_Start(const AUDIO_DEVICE_TYPE eID)5646 MS_BOOL _MApi_AUDIO_PCMCapture_Start(const AUDIO_DEVICE_TYPE eID)
5647 {
5648     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5649 
5650    return MDrv_AUDIO_PCMCapture_Start(eID);
5651 }
5652 
5653 ////////////////////////////////////////////////////////////////////////////////
5654 /// @brief \b Function \b Name: MApi_AUDIO_PCMCapture_Stop()
5655 /// @brief \b Function \b Description:  stop captrue pcm data from DDR
5656 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
5657 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
5658 /// @param <RET>       \b NONE    :
5659 /// @param <GLOBAL>    \b NONE    :
5660 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCMCapture_Stop(const AUDIO_DEVICE_TYPE eID)5661 MS_BOOL _MApi_AUDIO_PCMCapture_Stop(const AUDIO_DEVICE_TYPE eID)
5662 {
5663     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5664 
5665      return MDrv_AUDIO_PCMCapture_Stop(eID);
5666 }
5667 
5668 ////////////////////////////////////////////////////////////////////////////////
5669 /// @brief \b Function \b Name: MApi_AUDIO_PCMCapture_Read()
5670 /// @brief \b Function \b Description:  captrue pcm data from DDR to device
5671 /// @param <IN>        \b AUDIO_DEVICE_TYPE : select 1st or 2nd data capture
5672 /// @param <IN>        \b void* : destination buffer pointer
5673 /// @param <IN>        \b MS_U32 : buffer size need transfered in byte
5674 /// @param <OUT>       \b MS_BOOL    : return TRUE if success, else return FALSE
5675 /// @param <RET>       \b NONE    :
5676 /// @param <GLOBAL>    \b NONE    :
5677 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCMCapture_Read(const AUDIO_DEVICE_TYPE eID,void * buffer,const MS_U32 bytes)5678 MS_BOOL _MApi_AUDIO_PCMCapture_Read(const AUDIO_DEVICE_TYPE eID, void *buffer, const MS_U32 bytes)
5679 {
5680     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5681 
5682     return MDrv_AUDIO_PCMCapture_Read(eID, buffer, bytes);
5683 }
5684 
5685 //====== STAOS PIP START 2012/02/01 ========
5686 
_MApi_AUDIO_SetAudioParam2(AUDIO_DEC_ID DecId,Audio_ParamType paramType,MS_VIRT Param)5687 MS_BOOL _MApi_AUDIO_SetAudioParam2( AUDIO_DEC_ID DecId, Audio_ParamType paramType, MS_VIRT Param )
5688 {
5689     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5690 
5691     MS_BOOL bRet = FALSE;
5692 
5693     APIAUDIO_CHECK_SHM_INIT;
5694 
5695     APIAUDIO_CHECK_INIT_FLAG(bRet);
5696     if (bRet == FALSE)
5697     {
5698         return bRet;
5699     }
5700 
5701     return MDrv_AUDIO_SetAudioParam2(DecId, paramType, Param);
5702 }
5703 
_MApi_AUDIO_GetAudioInfo2(AUDIO_DEC_ID DecId,Audio_InfoType infoType,void * pInfo)5704 MS_BOOL _MApi_AUDIO_GetAudioInfo2( AUDIO_DEC_ID DecId, Audio_InfoType infoType, void * pInfo )
5705 {
5706     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5707 
5708     MS_BOOL bRet = FALSE;
5709 
5710     APIAUDIO_CHECK_SHM_INIT;
5711 
5712     APIAUDIO_CHECK_INIT_FLAG(bRet);
5713     if (bRet == FALSE)
5714     {
5715         return bRet;
5716     }
5717 
5718     if (NULL == pInfo)
5719     {
5720         AUDIO_PRINT(AUDIO_DEBUG_LEVEL_ERROR, "%s: pInfo not be NULL !!\r\n", __FUNCTION__);
5721         return FALSE;
5722     }
5723 
5724     return MDrv_AUDIO_GetAudioInfo2(DecId, infoType, pInfo);
5725 }
5726 
5727 //====== STAOS PIP END 2012/02/01 ========
5728 
5729 ////////////////////////////////////////////////////////////////////////////////
5730 /// @brief \b Function \b Name: MApi_AUDIO_FM_RADIO_GetSoundMode()
5731 /// @brief \b Function \b Description: Getting FM Radio Sound Mode
5732 /// @param <IN>        \b NONE :
5733 /// @param <OUT>       \b MS_U8   : return E_AUDIOMODE_MONO, E_AUDIOMODE_K_STEREO or E_AUDIOMODE_INVALID
5734 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FM_RADIO_GetSoundMode(void)5735 MS_U8 _MApi_AUDIO_FM_RADIO_GetSoundMode(void)
5736 {
5737     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5738 
5739     AUDIOSTATUS eCurrentAudioStatus = E_STATE_AUDIO_NO_CARRIER;
5740 
5741     if (MDrv_SIF_CheckDecSys(MSAPI_AUD_ATV_FM_RADIO))
5742     {
5743         return E_AUDIOMODE_INVALID;
5744     }
5745 
5746     _MApi_AUDIO_SIF_GetAudioStatus(&eCurrentAudioStatus);
5747 
5748     if(m_eSifStatus & E_STATE_AUDIO_PRIMARY_CARRIER)
5749     {
5750         eCurrentAudioStatus |= E_STATE_AUDIO_PRIMARY_CARRIER;
5751     }
5752 
5753     if(m_eSifStatus & E_STATE_AUDIO_STEREO)
5754     {
5755         eCurrentAudioStatus |= E_STATE_AUDIO_STEREO;
5756     }
5757 
5758     if(eCurrentAudioStatus == E_STATE_AUDIO_PRIMARY_CARRIER)
5759     {
5760         return E_AUDIOMODE_MONO;
5761     }
5762     else if (eCurrentAudioStatus == (E_STATE_AUDIO_PRIMARY_CARRIER|E_STATE_AUDIO_STEREO))
5763     {
5764         return E_AUDIOMODE_K_STEREO;
5765     }
5766     else
5767     {
5768         return E_AUDIOMODE_INVALID;
5769     }
5770 }
5771 
5772 ////////////////////////////////////////////////////////////////////////////////
5773 /// @brief \b Function \b Name: MApi_AUDIO_FM_RADIO_SetSoundMode()
5774 /// @brief \b Function \b Description: Setting FM Radio Sound Mode
5775 /// @param <IN>        \b MS_U8 : u8FMRadioSoundMode
5776 /// @param <OUT>       \b NONE :
5777 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FM_RADIO_SetSoundMode(MS_U8 u8FMRadioSoundMode)5778 void _MApi_AUDIO_FM_RADIO_SetSoundMode(MS_U8 u8FMRadioSoundMode)
5779 {
5780     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5781 
5782    switch(u8FMRadioSoundMode)
5783    {
5784         case E_AUDIOMODE_MONO:
5785         case E_AUDIOMODE_FORCED_MONO:
5786             MDrv_SIF_SetSoundMode(AU_MODE_MONO);
5787             break;
5788 
5789         case E_AUDIOMODE_G_STEREO:
5790         case E_AUDIOMODE_K_STEREO:
5791             MDrv_SIF_SetSoundMode(AU_MODE_STEREO);
5792             break;
5793 
5794         default:
5795             break;
5796    }
5797 }
5798 
5799 ////////////////////////////////////////////////////////////////////////////////
5800 /// @brief \b Function \b Name: MApi_AUDIO_FM_RADIO_DeEmphassisOption()
5801 /// @brief \b Function \b Description: FM Radio De-emphassis Option
5802 /// @param <IN>        \b MS_BOOL : Is_Europe
5803 /// @param <OUT>       \b NONE :
5804 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FM_RADIO_DeEmphassisOption(MS_BOOL Is_Europe)5805 void _MApi_AUDIO_FM_RADIO_DeEmphassisOption(MS_BOOL Is_Europe)
5806 {
5807     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5808 
5809     if(Is_Europe)
5810         MDrv_SIF_SendCmd(AU_SIF_CMD_SET_FM_RADIO_DeEmp, 1, NULL);
5811     else
5812         MDrv_SIF_SendCmd(AU_SIF_CMD_SET_FM_RADIO_DeEmp, 0, NULL);
5813 }
5814 
5815 ////////////////////////////////////////////////////////////////////////////////
5816 /// @brief \b Function \b Name: MApi_AUDIO_FM_RADIO_GET_DC_AMP()
5817 /// @brief \b Function \b Description: FM Radio get DC amp
5818 /// @param <IN>        \b NONE
5819 /// @param <OUT>       \b MS_S8 DC amp
5820 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FM_RADIO_GET_DC_AMP(void)5821 MS_S8 _MApi_AUDIO_FM_RADIO_GET_DC_AMP(void)
5822 {
5823     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5824 
5825     return (MS_S8)MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_RADIO_DC_AMP, NULL, NULL);
5826 }
5827 
5828 ////////////////////////////////////////////////////////////////////////////////
5829 /// @brief \b Function \b Name: MApi_AUDIO_FM_RADIO_GET_NSR()
5830 /// @brief \b Function \b Description: FM Radio get NSR
5831 /// @param <IN>        \b NONE
5832 /// @param <OUT>       \b MS_U8 NSR
5833 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FM_RADIO_GET_NSR(void)5834 MS_U8 _MApi_AUDIO_FM_RADIO_GET_NSR(void)
5835 {
5836     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5837 
5838     return MDrv_SIF_SendCmd(AU_SIF_CMD_GET_FM_RADIO_NSR, NULL, NULL);
5839 }
5840 
5841 ////////////////////////////////////////////////////////////////////////////////
5842 /// @brief \b Function \b Name: MApi_AUDIO_GetDDRInfo()
5843 /// @brief \b Function \b Description:  Return Audio DDR info
5844 /// @param <IN>        \b AUDIO_DEC_ID : select audio processor
5845 /// @param <IN>        \b EN_AUDIO_DDRINFO : DDR info
5846 /// @param <OUT>       \b MS_U32  : return DDR info
5847 /// @param <RET>       \b NONE    :
5848 /// @param <GLOBAL>    \b NONE    :
5849 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetDDRInfo(AUDIO_DEC_ID DecId,EN_AUDIO_DDRINFO DDRInfo)5850 MS_PHY _MApi_AUDIO_GetDDRInfo(AUDIO_DEC_ID DecId, EN_AUDIO_DDRINFO DDRInfo)
5851 {
5852     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5853 
5854     return MDrv_AUDIO_GetDDRInfo(DecId, DDRInfo);
5855 }
5856 
5857 ////////////////////////////////////////////////////////////////////////////////
5858 /// @brief \b Function \b Name: MApi_AUDIO_FM_RADIO_RESET()
5859 /// @brief \b Function \b Description: FM Radio reset
5860 /// @param <IN>        \b NONE
5861 /// @param <OUT>       \b NONE
5862 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_FM_RADIO_RESET(void)5863 void _MApi_AUDIO_FM_RADIO_RESET(void)
5864 {
5865     AUDIO_PRINT(AUDIO_DEBUG_LEVEL_DEBUG, "[%s] \n", __FUNCTION__);
5866 
5867     MDrv_SIF_SendCmd(AU_SIF_CMD_FM_RADIO_RESET, NULL, NULL);
5868 }
5869 
5870 ////////////////////////////////////////////////////////////////////////////////
5871 /// @brief \b Function \b Name: MApi_AUDIO_GetCaps()
5872 /// @brief \b Function \b Description: Get Audio Capabilities
5873 /// @param <IN>        \b AUDIO_DEC_ID : select audio processor
5874 /// @param <IN>        \b MS_U32 * : Audio Capabilites pointer
5875 /// @param <OUT>        \b MS_BOOL : return TRUE if success, else return FALSE
5876 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_GetCaps(AUDIO_DEC_ID DecId,MS_U32 * pCaps)5877 MS_U32 _MApi_AUDIO_GetCaps(AUDIO_DEC_ID DecId, MS_U32 *pCaps)
5878 {
5879     MS_U32 ret = FALSE;
5880 
5881     ret = MDrv_AUDIO_GetCaps(DecId, pCaps);
5882 
5883     return ret;
5884 }
5885 
5886 ////////////////////////////////////////////////////////////////////////////////
5887 /// @brief \b Function \b Name: MApi_AUDIO_Suspend()
5888 /// @brief \b Function \b Description: audio suspend
5889 /// @param <IN>        \b : void*
5890 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_Suspend(void)5891 MS_BOOL _MApi_AUDIO_Suspend(void)
5892 {
5893     MS_BOOL ret = TRUE;
5894     int i = 0, j = 0;
5895 
5896     APIAUDIO_CHECK_SHM_INIT;
5897 
5898     APIAUDIO_CHECK_INIT_FLAG(ret);
5899     if (ret == FALSE)
5900     {
5901         return FALSE;
5902     }
5903 
5904     //SerPrintf("\033[32m  [Utopia2K] %s : %d suspending \033[m\n", __FUNCTION__,__LINE__);
5905 
5906     while (MBOXBkUp[i].Address != 0)
5907     {
5908         for ( j = 0; j < MBOXBkUp[i].Length; j++)
5909         {
5910             MBOXBkUp[i].u16Data[j] = MDrv_AUDIO_AbsReadReg((MBOXBkUp[i].Address + (j * 2)));
5911         }
5912 
5913         i++;
5914     }
5915 
5916     _MApi_AUDIO_SetPowerOn(FALSE);
5917 
5918     return TRUE;
5919 }
5920 
5921 ////////////////////////////////////////////////////////////////////////////////
5922 /// @brief \b Function \b Name: MApi_AUDIO_Resume()
5923 /// @brief \b Function \b Description: audio resume
5924 /// @param <IN>        \b : void*
5925 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_Resume(void)5926 MS_BOOL _MApi_AUDIO_Resume(void)
5927 {
5928     MS_BOOL ret = TRUE;
5929     int i = 0, j = 0, DecID=AU_DEC_ID1;
5930     AudioDecStatus_t  stAudioDecStatus;
5931 
5932     APIAUDIO_CHECK_SHM_INIT;
5933 
5934     //printk("\033[32m [Utopia2K] %s : %d Resume \033[m\n", __FUNCTION__,__LINE__);
5935 
5936     g_AudioVars2->g_bHashkeyFlag = FALSE;
5937 
5938     _MApi_AUDIO_WritePreInitTable();
5939     _MApi_AUDIO_Initialize();
5940 
5941     while (MBOXBkUp[i].Address != 0)
5942     {
5943         for (j = 0; j < MBOXBkUp[i].Length; j++)
5944         {
5945             MDrv_AUDIO_AbsWriteReg((MBOXBkUp[i].Address + (j * 2)), MBOXBkUp[i].u16Data[j]);
5946         }
5947 
5948         i++;
5949     }
5950 
5951     MDrv_AUDIO_ResetDspCodeType();
5952 
5953     switch( g_AudioVars2->eMainAudioSource )
5954     {
5955         case AUDIO_DSP1_DVB1_INPUT:
5956         case AUDIO_DSP1_DVB_INPUT:
5957         case AUDIO_DSP4_SIF_INPUT:
5958             for (DecID = 0; DecID < AU_DEC_MAX; DecID++)
5959             {
5960                 if ( (g_AudioVars2->AudioDecStatus[DecID].bConnect == TRUE) && (g_AudioVars2->AudioDecStatus[DecID].eGroup == E_CONNECT_MAIN) )
5961                 {
5962                     memcpy(&stAudioDecStatus, &(g_AudioVars2->AudioDecStatus[DecID]), sizeof(AudioDecStatus_t));
5963                     g_AudioVars2->AudioDecStatus[DecID].eAudFormat = MSAPI_AUD_DVB_NONE;
5964                     MDrv_AUDIO_SetDecodeSystem(DecID, &stAudioDecStatus);
5965                     _MApi_AUDIO_InputSwitch(g_AudioVars2->eMainAudioSource, g_AudioVars2->AudioDecStatus[DecID].eGroup);
5966                     MDrv_MAD_SetDecCmd(AU_DVB_DECCMD_PLAY);
5967                 }
5968             }
5969             break;
5970 
5971             default:
5972                 break;
5973     }
5974 
5975     return ret;
5976 }
5977 
5978 ////////////////////////////////////////////////////////////////////////////////
5979 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Open()
5980 /// @brief \b Function \b Description : Open a PCM interface according to specific capabilities.
5981 /// @param <IN>        \b void : Pointer to a block of memory with PCM information.
5982 /// @param <OUT>       \b NONE :
5983 /// @param <RET>       \b MS_S32 : On success a nonnegative value is returned, and this value is the chosen device-id. On error, a negative value is returned.
5984 /// @param <GLOBAL>    \b NONE :
5985 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Open(void * pData)5986 MS_S32 _MApi_AUDIO_PCM_Open(void *pData)
5987 {
5988     return MDrv_AUDIO_PCM_Open(pData);
5989 }
5990 
5991 ////////////////////////////////////////////////////////////////////////////////
5992 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Close()
5993 /// @brief \b Function \b Description : Close an opened PCM interface.
5994 /// @param <IN>        \b MS_S32 : The chosen device-id.
5995 /// @param <OUT>       \b NONE :
5996 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
5997 /// @param <GLOBAL>    \b NONE :
5998 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Close(MS_S32 s32DeviceId)5999 MS_S32 _MApi_AUDIO_PCM_Close(MS_S32 s32DeviceId)
6000 {
6001     return MDrv_AUDIO_PCM_Close(s32DeviceId);
6002 }
6003 
6004 ////////////////////////////////////////////////////////////////////////////////
6005 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Start()
6006 /// @brief \b Function \b Description : Start an opened PCM interface.
6007 /// @param <IN>        \b MS_S32 : The chosen device-id.
6008 /// @param <OUT>       \b NONE :
6009 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6010 /// @param <GLOBAL>    \b NONE :
6011 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Start(MS_S32 s32DeviceId)6012 MS_S32 _MApi_AUDIO_PCM_Start(MS_S32 s32DeviceId)
6013 {
6014     return MDrv_AUDIO_PCM_Start(s32DeviceId);
6015 }
6016 
6017 ////////////////////////////////////////////////////////////////////////////////
6018 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Stop()
6019 /// @brief \b Function \b Description : Stop a started PCM interface.
6020 /// @param <IN>        \b MS_S32 : The chosen device-id.
6021 /// @param <OUT>       \b NONE :
6022 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6023 /// @param <GLOBAL>    \b NONE :
6024 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Stop(MS_S32 s32DeviceId)6025 MS_S32 _MApi_AUDIO_PCM_Stop(MS_S32 s32DeviceId)
6026 {
6027     return MDrv_AUDIO_PCM_Stop(s32DeviceId);
6028 }
6029 
6030 ////////////////////////////////////////////////////////////////////////////////
6031 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Set()
6032 /// @brief \b Function \b Description : Set configuration to an opened PCM interface.
6033 /// @param <IN>        \b MS_S32 : The chosen device-id.
6034 /// @param <IN>        \b MS_U32 : The command type.
6035 /// @param <IN>        \b void : Pointer to a block of memory with specific configuration, and this memory is not allowed to be updated by this API.
6036 /// @param <OUT>       \b NONE :
6037 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6038 /// @param <GLOBAL>    \b NONE :
6039 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Set(MS_S32 s32DeviceId,MS_U32 u32Cmd,const void * pData)6040 MS_S32 _MApi_AUDIO_PCM_Set(MS_S32 s32DeviceId, MS_U32 u32Cmd, const void *pData)
6041 {
6042     return MDrv_AUDIO_PCM_Set(s32DeviceId, u32Cmd, pData);
6043 }
6044 
6045 ////////////////////////////////////////////////////////////////////////////////
6046 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Get()
6047 /// @brief \b Function \b Description : Get configuration from an opened PCM interface.
6048 /// @param <IN>        \b MS_S32 : The chosen device-id.
6049 /// @param <IN>        \b MS_U32 : The command type.
6050 /// @param <IN>        \b void : Pointer to a block of memory for receiving specific configuration.
6051 /// @param <OUT>       \b NONE :
6052 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6053 /// @param <GLOBAL>    \b NONE :
6054 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Get(MS_S32 s32DeviceId,MS_U32 u32Cmd,void * pData)6055 MS_S32 _MApi_AUDIO_PCM_Get(MS_S32 s32DeviceId, MS_U32 u32Cmd, void *pData)
6056 {
6057     return MDrv_AUDIO_PCM_Get(s32DeviceId, u32Cmd, pData);
6058 }
6059 
6060 ////////////////////////////////////////////////////////////////////////////////
6061 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Read()
6062 /// @brief \b Function \b Description : Read a specific amount of PCM data from a started PCM interface.
6063 /// @param <IN>        \b MS_S32 : The chosen device-id.
6064 /// @param <IN>        \b void : Pointer to a block of memory with PCM data.
6065 /// @param <IN>        \b MS_U32 : The size of PCM data.
6066 /// @param <OUT>       \b NONE :
6067 /// @param <RET>       \b MS_U32 : The total number of PCM data successfully written is returned.
6068 /// @param <GLOBAL>    \b NONE :
6069 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Read(MS_S32 s32DeviceId,void * pBuf,MS_U32 u32Size)6070 MS_U32 _MApi_AUDIO_PCM_Read(MS_S32 s32DeviceId, void *pBuf, MS_U32 u32Size)
6071 {
6072     return MDrv_AUDIO_PCM_Read(s32DeviceId, pBuf, u32Size);
6073 }
6074 
6075 ////////////////////////////////////////////////////////////////////////////////
6076 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Write()
6077 /// @brief \b Function \b Description : Write a specific amount of PCM data to a started PCM interface.
6078 /// @param <IN>        \b MS_S32 : The chosen device-id.
6079 /// @param <IN>        \b void : Pointer to a block of memory with PCM data, and this memory is not allowed to be updated by this API.
6080 /// @param <IN>        \b MS_U32 : The size of PCM data.
6081 /// @param <OUT>       \b NONE :
6082 /// @param <RET>       \b MS_U32 : The total number of PCM data successfully written is returned.
6083 /// @param <GLOBAL>    \b NONE :
6084 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Write(MS_S32 s32DeviceId,const void * pBuf,MS_U32 u32Size)6085 MS_U32 _MApi_AUDIO_PCM_Write(MS_S32 s32DeviceId, const void *pBuf, MS_U32 u32Size)
6086 {
6087     return MDrv_AUDIO_PCM_Write(s32DeviceId, pBuf, u32Size);
6088 }
6089 
6090 ////////////////////////////////////////////////////////////////////////////////
6091 /// @brief \b Function \b Name: MApi_AUDIO_PCM_Flush()
6092 /// @brief \b Function \b Description : Flush an opened PCM interface.
6093 /// @param <IN>        \b MS_S32 : The chosen device-id.
6094 /// @param <OUT>       \b NONE :
6095 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6096 /// @param <GLOBAL>    \b NONE :
6097 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_PCM_Flush(MS_S32 s32DeviceId)6098 MS_S32 _MApi_AUDIO_PCM_Flush(MS_S32 s32DeviceId)
6099 {
6100     return MDrv_AUDIO_PCM_Flush(s32DeviceId);
6101 }
6102 
6103 ////////////////////////////////////////////////////////////////////////////////
6104 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Open()
6105 /// @brief \b Function \b Description : Open an encoder interface according to specific device name.
6106 /// @param <IN>        \b char : Pointer to a string with name.
6107 /// @param <OUT>       \b NONE :
6108 /// @param <RET>       \b MS_S32 : On success a nonnegative value is returned, and this value is the chosen device-id. On error, a negative value is returned.
6109 /// @param <GLOBAL>    \b NONE :
6110 ///
6111 /// Device Name :
6112 ///     "MP3_ENCODER1" : 1st MP3 Encoder
6113 ///     "MP3_ENCODER2" : 2nd MP3 Encoder
6114 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Open(const char * pName)6115 MS_S32 _MApi_AUDIO_ENCODER_Open(const char *pName)
6116 {
6117     return MDrv_AUDIO_ENCODER_Open(pName);
6118 }
6119 
6120 ////////////////////////////////////////////////////////////////////////////////
6121 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Close()
6122 /// @brief \b Function \b Description : Close an opened encoder interface.
6123 /// @param <IN>        \b MS_S32 : The chosen device-id.
6124 /// @param <OUT>       \b NONE :
6125 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6126 /// @param <GLOBAL>    \b NONE :
6127 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Close(MS_S32 s32DeviceId)6128 MS_S32 _MApi_AUDIO_ENCODER_Close(MS_S32 s32DeviceId)
6129 {
6130     return MDrv_AUDIO_ENCODER_Close(s32DeviceId);
6131 }
6132 
6133 ////////////////////////////////////////////////////////////////////////////////
6134 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Start()
6135 /// @brief \b Function \b Description : Start an opened encoder interface.
6136 /// @param <IN>        \b MS_S32 : The chosen device-id.
6137 /// @param <OUT>       \b NONE :
6138 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6139 /// @param <GLOBAL>    \b NONE :
6140 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Start(MS_S32 s32DeviceId)6141 MS_S32 _MApi_AUDIO_ENCODER_Start(MS_S32 s32DeviceId)
6142 {
6143     return MDrv_AUDIO_ENCODER_Start(s32DeviceId);
6144 }
6145 
6146 ////////////////////////////////////////////////////////////////////////////////
6147 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Stop()
6148 /// @brief \b Function \b Description : Stop a started encoder interface.
6149 /// @param <IN>        \b MS_S32 : The chosen device-id.
6150 /// @param <OUT>       \b NONE :
6151 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6152 /// @param <GLOBAL>    \b NONE :
6153 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Stop(MS_S32 s32DeviceId)6154 MS_S32 _MApi_AUDIO_ENCODER_Stop(MS_S32 s32DeviceId)
6155 {
6156     return MDrv_AUDIO_ENCODER_Stop(s32DeviceId);
6157 }
6158 
6159 ////////////////////////////////////////////////////////////////////////////////
6160 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Ioctl()
6161 /// @brief \b Function \b Description : Set/Get configuration to an opened encoder interface.
6162 /// @param <IN>        \b MS_S32 : The chosen device-id.
6163 /// @param <IN>        \b char : Pointer to a string with command name.
6164 /// @param <IN>        \b void : Pointer to a block of memory with specific configuration to deliver, or to receive specific configuration.
6165 /// @param <OUT>       \b NONE :
6166 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6167 /// @param <GLOBAL>    \b NONE :
6168 ///
6169 /// Command String Name :
6170 ///     "GetFrameSize" : Get the size of current encoded frame.
6171 ///     "GetAvailableSize" : Get the size of total available encoded frames.
6172 ///     "GetTimestampHigh32Bit" : Get high 32 bits of timestamp from current encoded frame.
6173 ///     "GetTimestampLow32Bit" : Get low 32 bits of timestamp from current encoded frame.
6174 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Ioctl(MS_S32 s32DeviceId,const char * pCmd,void * pData)6175 MS_S32 _MApi_AUDIO_ENCODER_Ioctl(MS_S32 s32DeviceId, const char *pCmd, void *pData)
6176 {
6177     return MDrv_AUDIO_ENCODER_Ioctl(s32DeviceId, pCmd, pData);
6178 }
6179 
6180 ////////////////////////////////////////////////////////////////////////////////
6181 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Read()
6182 /// @brief \b Function \b Description : Read a specific amount of encoded data from a started encoder interface.
6183 /// @param <IN>        \b MS_S32 : The chosen device-id.
6184 /// @param <IN>        \b void : Pointer to a block of memory with encoded data.
6185 /// @param <IN>        \b MS_U32 : The size of encoded data.
6186 /// @param <OUT>       \b NONE :
6187 /// @param <RET>       \b MS_U32 : The total number of encoded data successfully written is returned.
6188 /// @param <GLOBAL>    \b NONE :
6189 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Read(MS_S32 s32DeviceId,void * pBuf,MS_U32 u32Size)6190 MS_U32 _MApi_AUDIO_ENCODER_Read(MS_S32 s32DeviceId, void *pBuf, MS_U32 u32Size)
6191 {
6192     return MDrv_AUDIO_ENCODER_Read(s32DeviceId, pBuf, u32Size);
6193 }
6194 
6195 ////////////////////////////////////////////////////////////////////////////////
6196 /// @brief \b Function \b Name: MApi_AUDIO_ENCODER_Flush()
6197 /// @brief \b Function \b Description : Flush an opened encoder interface.
6198 /// @param <IN>        \b MS_S32 : The chosen device-id.
6199 /// @param <OUT>       \b NONE :
6200 /// @param <RET>       \b MS_S32 : On success zero is returned. On error, a negative value is returned.
6201 /// @param <GLOBAL>    \b NONE :
6202 ////////////////////////////////////////////////////////////////////////////////
_MApi_AUDIO_ENCODER_Flush(MS_S32 s32DeviceId)6203 MS_S32 _MApi_AUDIO_ENCODER_Flush(MS_S32 s32DeviceId)
6204 {
6205     return MDrv_AUDIO_ENCODER_Flush(s32DeviceId);
6206 }