📄 msapi_audio.c
字号:
////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2006-2007 MStar Semiconductor, Inc.
// All rights reserved.
//
// Unless otherwise stipulated in writing, any and all information contained
// herein regardless in any format shall remain the sole proprietary of
// MStar Semiconductor Inc. and be kept in strict confidence
// (¨MStar Confidential Information〃) by the recipient.
// Any unauthorized act including without limitation unauthorized disclosure,
// copying, use, reproduction, sale, distribution, modification, disassembling,
// reverse engineering and compiling of the contents of MStar Confidential
// Information is unlawful and strictly prohibited. MStar hereby reserves the
// rights to any and all damages, losses, costs and expenses resulting therefrom.
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// [Doxygen]
/// @file msAPI_Audio.h
/// @brief API for Audio Control
/// @author MStar Semiconductor, Inc.
//
////////////////////////////////////////////////////////////////////////////////
#define _MSAPI_AUDIO_C_
#include "board.h"
#include "sysinfo.h"
#include "hwreg.h"
#include "drvAuCommon.h"
#include "drvAuDvb.h"
#include "drvAuSif.h"
#include "drvAuProcess.h"
#include "msGPIO.h"
#include "drvGPIO.h"
#include "drvmiu.h"
#include "drvsys.h"
#include "msAPI_Audio.h"
#include "msAPI_miu.h"
#define AUD_DEBUG(msg) //msg
/******************************************************************************/
/* Local */
/******************************************************************************/
static En_DVB_decSystemType enCurDecSystem;
static EN_AudioInputType enCurAuInputSel;
static En_DVB_soundModeType enCurSoundMode;
static EN_SOUND_MTS_TYPE enCurSifSoundMode;
static En_SIF_systemType enCurSifSystem;
static U8 bCurrentSoundMode;
static U8 bPreviousSoundMode;
static En_DVB_decCmdType enDecoderStatus;
extern XDATA U8 g_u8MuteStatus;
//******************************************************************************
//Function name: msAPI_AUD_SetDecSystem
//Passing parameter: decoder type (MPEG/AC3/JPEG/TONE)
//Return parameter: none
//Description: Set decoder Command for DVB Audio module
// and reset I/O memory buffer if enDecSystem =
// MSAPI_AUD_DVB_MPEG/MSAPI_AUD_DVB_AC3 and MSAPI_AUD_DVB_JPEG
// [Doxygen]
/// Set decoder Command for DVB Audio module
/// and reset I/O memory buffer if enDecSystem =
/// MSAPI_AUD_DVB_MPEG/MSAPI_AUD_DVB_AC3 and MSAPI_AUD_DVB_JPEG
/// @param enDecSystem \b IN decoder type (MPEG/AC3/JPEG/TONE)
//******************************************************************************
// procedures of change decoder System
// 0. MDrv_AuProcessSetMute( AUDIO_PATH_0, ENABLE )
// 1. MDrv_AuDvb_setDecCmd( AU_DVB_DECCMD_STOP )
// 2. MDrv_AuDvb_setMemInfo(U32 InputBufferStartAddr, U32 InputBufferEndAddr, U32 OutputBufferStartAddr, U32 OutputBufferEndAddr)
// 3. MDrv_AuDvbSetSystem( AU_DVB_SYS_MPEG )
// 4. MDrv_AuDvbSetSoundMode( AU_DVB_MODE_STEREO )
// 5. MDrv_AuDvb_setDecCmd( AU_DVB_DECCMD_RESYNC )
// 6. MDrv_AuDvb_setDecCmd( AU_DVB_DECCMD_PLAY )
// 7. MDrv_AuSetNormalPath(AUDIO_PATH_0, AUDIO_SIF_INPUT, AUDIO_MASTER_OUTPUT)
// 8. MDrv_AuProcessSetMute( AUDIO_PATH_0, DISABLE )
void msAPI_AUD_SetDecSystem(En_DVB_decSystemType enDecSystem)
{
AUD_DEBUG(printf("apiAud>> enDecSystem %bu enCurDecSystem = %bu\n", (U8)enDecSystem, (U8)enCurDecSystem));
#if (CHANNEL_SCAN_AUTO_TEST == 0)
//printf("apiAud>> enDecSystem %bu enCurDecSystem = %bu\n", (U8)enDecSystem, (U8)enCurDecSystem);
#endif
if ( enDecSystem != enCurDecSystem )
{
// set decoder system
switch ( enDecSystem )
{
case MSAPI_AUD_DVB_MPEG:
MDrv_AuDvbSetSystem(AU_DVB_SYS_MPEG);
break;
case MSAPI_AUD_DVB_AC3:
MDrv_AuDvbSetSystem(AU_DVB_SYS_AC3);
break;
case MSAPI_AUD_DVB_MP3:
MDrv_AuDvbSetSystem(AU_DVB_SYS_MP3);
break;
case MSAPI_AUD_DVB_TONE:
MDrv_AuDvbSetSystem(AU_DVB_SYS_TONE);
break;
case MSAPI_AUD_DVB_NONE:
//change channel from digital to analog
break;
}
enCurDecSystem = enDecSystem;
}
}
//******************************************************************************
//Function name: msAPI_AUD_SetDecCommand
//Passing parameter: deccoder command for DVB Audio
//Return parameter: none
//Description: Set decoder Command for DVB Audio module
// [Doxygen]
/// Set decoder Command for DVB Audio module
/// @param enDecComamnd \b IN deccoder command for DVB Audio
//******************************************************************************
void msAPI_AUD_SetDecCommand(En_DVB_decCmdType enDecComamnd)
{
switch ( enDecComamnd )
{
case MSAPI_AUD_DVB_DECCMD_STOP:
enDecoderStatus = MSAPI_AUD_DVB_DECCMD_STOP;
MDrv_AuDvb_setDecCmd(AU_DVB_DECCMD_STOP);
// AC3 about 3x ms will closed after stop cmd, 50ms is safe
// TODO: review is needed
MDrv_Timer_Delayms(50);
// Disable MIU Request
MDrv_AuWriteMaskByte(0x2DE0, 0x40, 0x40 );
MDrv_Timer_Delayms(1);
// Reset MAD module
MDrv_AuWriteMaskByte(0x2DE0, 0x80, 0x80 );
MDrv_Timer_Delayms(2);
// Set MAD module
MDrv_AuWriteMaskByte(0x2DE0, 0x80, 0x00 );
// Enable MIU Request
MDrv_AuWriteMaskByte(0x2DE0, 0x40, 0x00 );
break;
case MSAPI_AUD_DVB_DECCMD_PLAY:
enDecoderStatus = MSAPI_AUD_DVB_DECCMD_PLAY;
// Disable MIU Request
MDrv_AuWriteMaskByte(0x2DE0, 0x40, 0x40 );
MDrv_Timer_Delayms(1);
// Reset MAD module
MDrv_AuWriteMaskByte(0x2DE0, 0x80, 0x80 );
MDrv_Timer_Delayms(2);
// Set MAD module
MDrv_AuWriteMaskByte(0x2DE0, 0x80, 0x00 );
// Enable MIU Request
MDrv_AuWriteMaskByte(0x2DE0, 0x40, 0x00 );
MDrv_AuDvb_setDecCmd(AU_DVB_DECCMD_PLAY);
break;
case MSAPI_AUD_DVB_DECCMD_RESYNC:
MDrv_AuDvb_setDecCmd(AU_DVB_DECCMD_RESYNC);
break;
}
}
//******************************************************************************
//Function name: msAPI_AUD_SetFreeRun
//Passing parameter: Free-Run mode for DVB Audio
//Return parameter: none
//Description: Set Free-Run mode for DVB Audio module
// [Doxygen]
/// Set Free-Run mode for DVB Audio module
/// @param enFreeRun \b IN Free-Run mode for DVB Audio
//******************************************************************************
void msAPI_AUD_SetFreeRun(En_DVB_FreeRunMode enFreeRun)
{
switch ( enFreeRun )
{
case MSAPI_AUD_DVB_FreeRunMode_AVsync:
MDrv_AuDvb_setFreeRun(AU_DVB_FreeRunMode_AVsync);
break;
case MSAPI_AUD_DVB_FreeRunMode_FreeRun:
MDrv_AuDvb_setFreeRun(AU_DVB_FreeRunMode_FreeRun);
break;
}
}
/******************************************************************************/
/// -This routine is to execute DSP power on/down setting.
/// @param bFlag \b IN:
/// - 0: Power down
/// - 1: Power on
/******************************************************************************/
void msAPI_AuSetPowerOn(BOOLEAN bFlag)
{
MDrv_AuSetPowerOn(bFlag);
}
//******************************************************************************
//Function name: msAPI_AUD_GetMPEGHeaderInfo
//Passing parameter: none
//Return parameter: 32bit mpeg header or 0(fail)
//Description: Get 32bits audio mpeg header (for deugging only)
// [Doxygen]
/// Get 32bits audio mpeg header (for deugging only)
/// @return 32bit mpeg header or 0(fail)
//******************************************************************************
U32 msAPI_AUD_GetMPEGHeaderInfo(void)
{
return MDrv_AuDvb_mpeg_getHeaderInfo();
}
//******************************************************************************
//Function name: msAPI_AUD_SetSoundMode
//Passing parameter: Output Channel Mode
//Return parameter: none
//Description: Set sound mode for DVB audio module
// [Doxygen]
/// Set sound mode for DVB audio module
/// @param enSoundMode \b IN dOutput Channel Mode
//******************************************************************************
void msAPI_AUD_SetSoundMode(En_DVB_soundModeType enSoundMode)
{
if ( enSoundMode != enCurSoundMode )
{
switch ( enSoundMode )
{
case MSAPI_AUD_DVB_SOUNDMODE_STEREO:
default:
MDrv_AuDvbSetSoundMode(AU_DVB_MODE_STEREO);
break;
case MSAPI_AUD_DVB_SOUNDMODE_LEFT:
MDrv_AuDvbSetSoundMode(AU_DVB_MODE_LL);
break;
case MSAPI_AUD_DVB_SOUNDMODE_RIGHT:
MDrv_AuDvbSetSoundMode(AU_DVB_MODE_RR);
break;
}
enCurSoundMode = enSoundMode;
}
AUD_DEBUG(printf("apiAud>> enCurSoundMode = %bu\n", (U8)enCurSoundMode));
}
#if( (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_BTSC) || (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_A2) )
BOOLEAN msAPI_AUD_IsSifSoundModeExist(EN_SOUND_MTS_TYPE enSifSoundMode)
{
switch ( enSifSoundMode )
{
case SOUND_MTS_MONO:
return (BOOLEAN)(AU_STATUS_MONO&bCurrentSoundMode);
case SOUND_MTS_STEREO:
return (BOOLEAN)(AU_STATUS_STEREO&bCurrentSoundMode);
#if (TV_SYSTEM == TV_NTSC)
case SOUND_MTS_SAP:
return (BOOLEAN)(AU_STATUS_SAP&bCurrentSoundMode);
#endif
default:
return FALSE;
}
}
BOOLEAN msAPI_AUD_IsSifSoundModeChanged(void)
{
return (BOOLEAN)(bCurrentSoundMode != bPreviousSoundMode);
}
#endif //#if (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_BTSC)
//******************************************************************************
//Function name: msAPI_AUD_SifGetSoundMode
//Passing parameter: none
//Return parameter: Sound mode type
//Description: Get SIF current sound mode type
// [Doxygen]
/// Get SIF current sound mode type
/// @return Sound mode type
//******************************************************************************
En_SIF_soundModeType msAPI_AUD_SifGetSoundMode(void)
{
#if( (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_BTSC) || (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_A2) )
bCurrentSoundMode = MDrv_AuSifGetSoundMode();
return MSAPI_AUD_SIF_SOUNDMODE_AUTO;
#else //#if (AUDIO_SYSTEM_SEL == AUDIO_SYSTEM_BTSC) // use TV_SYSTEM be the condition in the future
BYTE ucMtsStatus;
ucMtsStatus = MDrv_AuSifGetSoundMode();
AUD_DEBUG(printf("MDrv_AuSifGetSoundMode = %x\r\n", (U8)ucMtsStatus));
switch ( ucMtsStatus )
{
case AU_STATUS_MONO:
return MSAPI_AUD_SIF_SOUNDMODE_MONO;
case AU_STATUS_STEREO:
return MSAPI_AUD_SIF_SOUNDMODE_STEREO;
case AU_STATUS_SAP:
return MSAPI_AUD_SIF_SOUNDMODE_SAP;
#if( TV_SYSTEM == TV_PAL )
case AU_STATUS_NICAM:
return MSAPI_AUD_SIF_SOUNDMODE_NICAM;
#endif
default:
return MSAPI_AUD_SIF_SOUNDMODE_MONO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -