www.pudn.com > 8202S.rar > auddrv.c
/***********************************************************************
* 2004.10 System Dept.VI Oliver Chen
*
* This file is all about audio related driver interface.
* Please control the audio h/w, DSP, board, and pin config
* through these APIs.
***********************************************************************/
#include "auddrv.h"
#include "gpio.h"
#include "kinf.h"
#include "ninf.h"
#include "file_if.h" //for Wave format related APIs
#include "setup_def.h"
extern UINT8 setup_sel[MAX_SETUP_PAGE + MAX_CUSTM_SETUP_PAGE][MAX_PAGE_ITEM];
extern const UINT8 setup_item[MAX_SETUP_PAGE + MAX_CUSTM_SETUP_PAGE][MAX_PAGE_ITEM][MAX_ITEM_SEL];
#include "setup_page.h"
extern UINT8 power_on_mute;
#ifdef SPHE1000 //bktesng, 2004/12/09, To get audio info for Linux AP.
#include "driver/message.h"
extern share_info_t *pDVB;
#endif
extern void delay_srv_10ms(int tms);
extern BYTE wait_dsp_port0_5(int port0,int port5,int val,UINT32 risc_waiting_dsp_tm);
extern int ReadFromI2c(int,int,BYTE *,int);
#ifdef SUPPORT_MP4
extern BYTE GetCurrentFileType();
int mp4_aud_channel_flg=0;
int mp4_aud_channel=0;
#endif
#ifdef SUPPORT_MIDI
extern UINT8 gIsMidiSelMenu;
#ifdef SUPPORT_MIDIDISK_TITLE
extern BYTE bIsPlayMidiTitle;
#endif
#endif
INT8 mic_volume=8;
/***********************************************************************
* Code Session
***********************************************************************/
// FUNCTION DESCRIPTION : wait until turn to STOP(ready) status
//
void AUDIF_Wait_DSPReady(int dspChanged)
{
//delay_srv_10ms(2);//2004/3/8 11:40PM,terry
wait_dsp_port0_5(0,1,0,200000);//terry,2003/8/8 03:46AM
//If AC3, we need to set some configure(subwoofer, speaker gain, speaker delay)
if(coding_mode_now==AUDIF_CODING_MODE_AC3) {
setup_SetAC3Config();
}
if(dspChanged) {
//set common audio configure when DSP audio change
if((cd_type_loaded==CDDA)&&(coding_mode_now==AUDIF_CODING_MODE_DTSCD)){ //Jeff 20020719
delay_srv_10ms(15);
}
#ifdef SUPPORT_DSPMUTE
regs0->dsp24_port[14] = 0x0; // for dsp mute benson 2004/7/12 01:13¤U¤È
#endif
}
#if defined(SUPPORT_AUDIO_RESET)&&defined(HANYANG_4340_AUDRESET)
regs0->sft_cfg3 &= ~(0x1 << 4);
regs0->gpio_master[60 / 16] |= (0x01 << (60 % 16));
regs0->gpio_oe[60 / 16] |= (0x01 << (60 % 16));
regs0->gpio_out[60 / 16] |= (0x01 << (60 % 16));
delay_srv_10ms(30);
#endif
// gpio demute
if(power_on_mute==0){//terry,2003-8-5 3:16
GPIO_DEMUTE();
}
AUDIF_Set_Play();
//do extra mute when we switch to SPDIF/BITSTREAM, Jeff 20021202
if(setup_IsSet2SPDIF_Bitstream() && (coding_mode_now==AUDIF_CODING_MODE_PCM)) {
extern BYTE audioNotContinuous;
audioNotContinuous=20;
AUDIF_Set_Volume(0);
}
}
//Audio DSP SPDIF control command ( 0:OFF, 1:PCM, 2:BITSTREAM )
inline int AUDIF_Set_SPDIF(UINT32 mode)
{
return (DSP_AudioIOControl(SPDIF, mode, 0));
}
//Audio DSP Output Mode control command
//0x01:Stereo(L/R), 0x02:L/L, 0x03:R/R, 0x04:Auto-L, 0x05:Auto-R,
//0x06:5.1 channel, 0x07:2 channel, 0x08:DownMix Lx,Rx(for ProLogic)
//0x10:RF_MODE-K3, 0x20:LINE_MODE-K2, 0x30:no vocal, 0x40:left vocal,
//0x50:right vocal, 0x60:both vocal
inline int AUDIF_Set_OutputMode(UINT32 outmode, UINT32 outparam)
{
return (DSP_AudioIOControl(OUTMODE, outmode, outparam));
}
#ifdef TEST_BASS_COMMAND
UINT16 gBass_Config; // for storing the bass config as a global value
inline void AUDIF_Set_BassConfig(UINT16 spktype, INT16 setupvalue) //(UINT8 ufront, UINT8 ucenter, UINT8 usurround, UINT8 usub)
{
UINT16 bass_config = 0;
int front,center,surround,sub;
#ifdef DVD_SETUP_REENG
front = setup_VA[SETUP_VA_FSPK]-MIN_ITEM_SEL;
center = setup_VA[SETUP_VA_CSPK]-MIN_ITEM_SEL;
surround = setup_VA[SETUP_VA_SSPK]-MIN_ITEM_SEL;
sub = setup_VA[SETUP_VA_SUBWOOFER]-MIN_ITEM_SEL;
#else
front = SETUP_SPK_FRONT-2;
center = SETUP_SPK_CENTER-2;
surround = SETUP_SPK_SURROUND-2;
sub = SETUP_SPK_SUBWOOFER-2;
#endif
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : Bass Config:front=%d,center=%d,surround=%d,sub=%d\n",front,center,surround,sub);
#endif
if(spktype==FRNT_SPK && setupvalue==front)
return;
else if(spktype==CNTR_SPK && setupvalue==center)
return;
else if(spktype==SRND_SPK && setupvalue==surround)
return;
else if(spktype==SBWF_SPK && setupvalue==sub)
return;
else{
//mapping table
switch (front)
{
case 0: //Front Large
if (surround==0){ //Surround Large
if ((sub==0)||((sub==1)&&(center==1)))
bass_config = 3; //config3
else
bass_config = 0; //x
}
else if(surround==2){ //Surround None
if (center==1) //Center Small
bass_config = 2; //simplified
else //Center Large or None
bass_config = 0; //x
}
else{ //Surround Small
bass_config = 2; //simplified
}
break;
case 1: //Front Small
if (surround==0) //Surround Large
bass_config = 4; //car-simplified
else
bass_config = 1; //config1;
break;
}
}
gBass_Config = 0x00ffff & ((front<<12)+(center<<8)+(surround<<4)+bass_config);
DSP_AudioIOControl(BASSMANAGEMENT,0,gBass_Config);
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : return bass_config = %x,%d\n",bass_config,bass_config);
#endif
return;
}
inline UINT16 AUDIF_Get_BassConfig(void)
{
return gBass_Config;
}
#else
inline void AUDIF_Set_BassConfig(UINT16 spktype, INT16 setupvalue) {}
inline UINT16 AUDIF_Get_BassConfig(void) {}
#endif //#ifdef TEST_BASS_COMMAND
#ifdef OP_UI
inline int AUDIF_Set_SpkSize(UINT32 spktype, UINT32 size)
{
int res = DSP_AudioIOControl(SPKSIZE, spktype, size);
return res;
}
inline int AUDIF_Set_SpkDistance(UINT32 spktype, UINT32 distance)
{
int res = DSP_AudioIOControl(SPKDISTANCE, spktype, distance);
return res;
}
#else
inline int AUDIF_Set_SpkSize(UINT32 spktype, UINT32 size) {return 0;}
inline int AUDIF_Set_SpkDistance(UINT32 spktype, UINT32 distance) {return 0;}
#endif
//Audio DSP Front Speaker Gain control command ( 0~8(0:off) )
inline int AUDIF_Set_FSPKGain(UINT32 val)
{
return (DSP_AudioIOControl(FSPKGAIN, val, 0));
}
//Audio DSP Center Speaker Gain control command ( 0~8(0:off) )
inline int AUDIF_Set_CSPKGain(UINT32 val)
{
return (DSP_AudioIOControl(CSPKGAIN, (val*2), 0));
}
//Audio DSP Surround Speaker Gain control command ( 0~8(0:off) )
inline int AUDIF_Set_SSPKGain(UINT32 val)
{
return (DSP_AudioIOControl(SSPKGAIN, val, 0));
}
//Audio DSP 5 Speaker Gain control command ( s:speaker_type x:gain)
inline int AUDIF_Set_5SPKGain(UINT32 spktype, UINT32 val)
{
return (DSP_AudioIOControl(spktype, val, 0));
}
//Audio DSP Sub-woof control command //0:OFF, 1:ON
void AUDIF_Set_SubWoof(UINT8 ustatus)
{
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : Set Sub Woof %d\n",ustatus);
#endif
DSP_AudioIOControl(SUBWOOF, ustatus, 0);
#ifdef TEST_BASS_MANAGEMENT
#ifdef TEST_BASS_COMMAND
AUDIF_Set_BassConfig(SBWF_SPK, ustatus);
#else
AUDIF_Reset_DSP();
#endif
#endif
return;
}
int AUDIF_Set_FastForward(BYTE speed)
{
int iRes = 0;
BYTE cFF = AUDIOFF2X;
switch (speed)
{
case 2:
cFF = AUDIOFF2X; break;
case 4:
cFF = AUDIOFF4X; break;
case 5://nono 4-2-10 20:27
cFF = AUDIOFF4X; break;
case 8:
cFF = AUDIOFF8X; break;
case 10://nono 4-2-10 20:27
cFF = AUDIOFF8X; break;
case 20:
cFF = AUDIOFF20X; break;
case 16:
cFF = AUDIOFF16X; break;
case 30://nono 4-2-10 20:27
cFF = AUDIOFF20X; break;
case 32:
cFF = AUDIOFF32X; break;
case 60://nono 4-2-10 20:27
cFF = AUDIOFF32X; break;
}
iRes = DSP_AudioIOControl(FLOW, cFF, 0);
return iRes;
}
// FUNCTION DESCRIPTION : Send Play command to DSP
// return 1: success 0: fail
int AUDIF_Set_Play(void)
{
int i, iRes=1;
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : set play in\n");
#endif
if(show_logo==1)
return iRes;
i = regs0->dsp24_port[5];
if(i==1) {//DSP is under PLAY mode
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : DSP is under PLAY mode\n");
#endif
return iRes;
}
AUDIF_RampUp_DSP(1);
if(!user_mute) {
#ifdef MP3_CD_FF1_BF1_MUTE//YX822BC//nono 2-8-23 18:39
//mix YUXING822BC when ff||fbX2,pressing SELECT,demute will be run.
if(!adv_search_time)
#else
//terry,2002/4/29 05:10PM
//cdda,mix vcd and cdda,cdrom in ff>=4 bf<=-4, demute cannot be run
if((audio_only==0)||((adv_search_time<4)&&(adv_search_time>(-4))))
#endif
{
AUDIF_Demute();
}
}
//for MP3
if (cd_type_loaded == CDROM) {
iRes = DSP_AudioIOControl(FLOW, AUDIOPLAY, 1); //PLAY command
} else {
iRes = DSP_AudioIOControl(FLOW, AUDIOPLAY, 0); //PLAY command
}
//Jeff 20020411
if((adv_search_time>1) && ((cd_type_loaded==CDROM)||(cd_subtype==CD_DTS))){
AUDIF_Set_FastForward(adv_search_time); //set DSP to FF mode
}
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : set play end\n\n");
#endif
return iRes;
}
// FUNCTION DESCRIPTION : Send Pause command to DSP
// return 1: success 0: fail
int AUDIF_Set_Pause(void)
{
int iRes;
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : set pause in\n");
#endif
#ifdef MP3_JPEG_COWORK
if(pFsJpeg->gifsFuncBtn==FS_FUNC_JPEG)//if JPEG, then do not pause
return 0;
#endif
//to check DSP mode
if (regs0->dsp24_port[5]==2) {
//The status of DSP in under PAUSE, so we skip this command
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : DSP in under PAUSE mode\n");
#endif
return 1;
}
iRes = DSP_AudioIOControl(FLOW, AUDIOPAUSE, 0); //PAUSE command
//wait until DSP enters PAUSE mode
wait_dsp_port0_5(1,1,2,100000);//terry,2003/8/8 03:45AM
AUDIF_Set_Volume(0);//terry,2002/5/10 12:05am, no audio when pause
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : set pause end\n\n");
#endif
return iRes;
}
// FUNCTION DESCRIPTION : Send Stop command to DSP
// return 1: success 0: fail
int AUDIF_Set_Stop(void)
{
int iRes=1,stop;
if (show_logo==1)
return iRes;
// Check DSP mode
// If DSP status is STOP(0), skip this command
if (regs0->dsp24_port[5]==0)
return iRes;
AUDIF_RampDown_DSP(1);//2004AUDDRV dsp3_ramp_down(1);
AUDIF_RampWait_DSP();//2004AUDDRV dsp3_ramp_wait();
iRes = DSP_AudioIOControl(FLOW, AUDIOSTOP, 0); //STOP command
//wait until DSP enters STOP mode
stop = wait_dsp_port0_5(1,1,0,100000);//terry,2003/8/8 03:45AM
if ( (iRes>0) && stop ) {
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : Audio Set Stop SUCCEEDED\n");
#endif
} else {
iRes = 0;
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : Audio Set Stop FAILED\n");
#endif
}
return iRes;
}
//Send Continue command to DSP
// return 1: success 0: fail
int AUDIF_Set_Continue(void)
{
int iRes=1;
#ifdef MP3_JPEG_COWORK
if(pFsJpeg->gifsFuncBtn==FS_FUNC_JPEG)//if JPEG, then do not continue
return 0;
#endif
if(show_logo==1)
return iRes;
AUDIF_RampUp_DSP(1);//2004AUDDRV dsp3_ramp_up(1);
// Check DSP mode
// IF DSP is in STOP mode, send PLAY command to DSP
if (regs0->dsp24_port[5]==0) {
DSP_AudioIOControl(FLOW, AUDIOPLAY, 0);
return iRes;
}
iRes = DSP_AudioIOControl(FLOW, AUDIOCONTINUE, 0); //CONTINUE command
return iRes;
}
// AUDIF_Reset_DSP
//
void AUDIF_Reset_DSP(void)
{
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : AUDIF_Reset_DSP:coding_mode_now=%x\n",coding_mode_now);
#endif
AUDIF_Set_Stop();//2004AUDDRV AudioSetStop();
regs0->dsp24_port[5] = -1;
//force to re-load same DSP audio decoder
buf_barrier_size = (coding_mode_now == AUDIF_CODING_MODE_LPCM) ? 1024:8;
AUDKRNL_Download_Codec(coding_mode_now);//2004AUDDRV
//wait until DSP Audio is ready to receive command
wait_dsp_port0_5(0,1,0,200000);//terry,2003/8/8 03:46AM
if (coding_mode_now==AUDIF_CODING_MODE_AC3) {
//If it is AC3, we need to set some configure(subwoofer, speaker gain, speaker delay)
setup_SetAC3Config();
setup_SetAC3PCMConfig();
}
delay_srv_10ms(10);
AUDIF_Set_Play();//2004AUDDRV AudioSetPlay();
}
//#ifdef SUPPORT_RECEIVER
void AUDIF_Init_NewDSPCodec(UINT32 coding_mode)
//#else
//void AUDIF_Init_NewDSPCodec(UINT16 coding_mode)
//#endif
{
AUDIF_RampDown_DSP(1);//2004AUDDRV dsp3_ramp_down(1);
AUDIF_RampWait_DSP();//2004AUDDRV dsp3_ramp_wait();
regs0->dsp24_port[5] = -1;
AUDKRNL_Download_Codec(coding_mode);
AUDIF_RampUp_DSP(1);//2004AUDDRV dsp3_ramp_up(1);
buf_barrier_size = ((coding_mode==AUDIF_CODING_MODE_LPCM) ? 1024:8);
AUDIF_Set_Play();//2004AUDDRV AudioSetPlay();
}
// FUNCTION DESCRIPTION : sampling rate setting
// nibble 3 nibble 2 nibble 1 nibble 0
// bit resolution 4x 2x 1x
// nibble 0 1 2
// 32k 44k 48k
#define MASKTBL_MAXSIZE 3
const UINT16 MaskTable[MASKTBL_MAXSIZE]={0x0007, 0x0067, 0x0667}; //we only support 44k/48k multiples
UINT16 AUDIF_Set_FrqMsk(UINT16 mask)
{
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : set Frequency Mask:sel %x\n",mask);
#endif
if(maskdsp24_port[13] = 0x03; // set default to "no copy allowed"
if(ninf_get_dvd_CPM())
regs0->dsp24_port[13] = ninf_get_dvd_CGMS();
audsid = stream_audio;
audchn = audio_chan_num;
#ifdef SUPPORT_MP4
if (GetCurrentFileType() == CDROM_MP4) {
if (audchn != chn) {
mp4_aud_channel_flg = 1;
audio_chan_num = chn;
}
}
#endif
switch(coding_mode_now)
{
case AUDIF_CODING_MODE_AC3:
audsid = 0x80 | chn;
break;
case AUDIF_CODING_MODE_DTS:
audsid = 0x88 | chn;
break;
case AUDIF_CODING_MODE_LPCM:
case AUDIF_CODING_MODE_PPCM:
audsid = 0xa0 | chn;
break;
case AUDIF_CODING_MODE_SDDS: //Jeff 20010816
audsid = 0x90 | chn;
break;
case AUDIF_CODING_MODE_JPG:
case AUDIF_CODING_MODE_NES:
case AUDIF_CODING_MODE_PCM:
case AUDIF_CODING_MODE_WMA:
#ifdef SUPPORT_AAC
case AUDIF_CODING_MODE_AAC:
#endif
case AUDIF_CODING_MODE_DTSCD:
#ifdef SUPPORT_SPDIF_IN
case AUDIF_CODING_MODE_SPDIFINCD: // benson modify 2004/2/25 02:11¤W¤È
case AUDIF_CODING_MODE_SPDIFINAC3:
case AUDIF_CODING_MODE_SPDIFINDTS:
#endif
#ifdef SUPPORT_AV_IN
case AUDIF_CODING_MODE_TUNER:
#endif
break;
default: // mpeg audio
audsid = 0xc0 | chn;
if(cd_type_loaded!=CDDVD) __mpeg_audio = 1;
break;
}
mpeg_audio = __mpeg_audio;
if(stream_audio!=audsid) {
stream_audio = audsid;
changed = 1;
}
ki_set_au_stream(audsid);
if((changed)&&(cd_type_loaded!=CDSVCD)){//nono 4-2-25 23:58
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : audio channel changed,run audio stop\n");
#endif
#ifndef CNTR_5SPK_VOLUME //for 5_1ch,wangfeng 2004-2-4 15:15
AUDIF_Set_Stop();
#endif
#ifdef SUPPORT_NESGAME
if(coding_mode_now!=AUDIF_CODING_MODE_NES)//terry,2004/5/12 04:38PM
#endif
resync_audio_bitstream();
#ifndef CNTR_5SPK_VOLUME //for 5_1ch,wangfeng 2004-2-4 15:15
AUDIF_Set_Play();
#endif
}
}
int AUDIF_AutoDownload_Codec(UINT8 chn)
{
int res=0;
UINT8 stream_id,codec_id;
//print_block(stream_audio_table,8);
if(stream_audio_table[chn]==0)
chn=0;
stream_id=stream_audio_table[chn];
if(stream_id>=0x80)
{
res=1;
codec_id=CODING_MODE_MP2;
if(stream_id<0x88)
{//AC3
codec_id=CODING_MODE_AC3;
}else if(stream_id<0x90)
{//DTS
codec_id=CODING_MODE_DTS;
}else if(stream_id<0xa8)
{//LPCM
codec_id=CODING_MODE_LPCM;
}
AUDIF_Set_CodingMode(1<>= 4;
if (t1 <= 0)
break;
}
// frequency not supported
if ((t1&frequency_mask) == 0)
t1 = FS_DEFAULT;
if (t2 != frequency_multiple)
{
frequency_multiple = t2;
AUDIF_Init_NewDSPCodec(coding_mode_now);
AUDIF_Wait_DSPReady(0);//wait_dsp_busy(0);
}
AUDKRNL_Set_AudHW_SmpRate(t1);
smp_rate_now = smp_rate_down = smp_rate;
#ifdef PCM1742 //Jeff 20030917
dac_set_fs(smp_rate);
#endif
#ifdef EASTWIN_PORTABLE_DVD
#include "setup_page.h"
setup_SetFreqMaskConfig();//tulijuan040915
//audif_set_frequency_mask(2);//SETUP_FREQ_MASK-2);//tulijuan040915
#endif
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : smp_rate=%x smp_rate_now=%x smp_rate_down=%x frequency_multiple=%x\n",
smp_rate, smp_rate_now, smp_rate_down, frequency_multiple);
auddbg_printf("AUDDRV : set Sample Rate:%x\n",t1);
#endif
}
void AUDIF_Set_SmpRate(UINT32 freq)
{
#ifdef AUDDRV_DBG
auddbg_printf("AUDDRV : AUDIF_Set_SmpRate:%x\n", freq);
#endif
if((freq>=(8000-500) && freq<=(8000+500)) ||
(freq>=(16000-500)&& freq<=(16000+500))||
(freq>=(32000-500)&& freq<=(32000+500))) {
AUDIF_Set_SampleRate(FS_32K);
}
else if((freq>=(11025-500) && freq<=(11025+500))||
(freq>=(22050-500) && freq<=(22050+500))||
(freq>=(44100-500) && freq<=(44100+500))) {
AUDIF_Set_SampleRate(FS_44K);
}
else{
AUDIF_Set_SampleRate(FS_48K);
}
aud_frequency = freq;
}
/***********************************************************************
* DSP Macro & Declaration Session
***********************************************************************/
#ifdef USE_MIC_ECHO_PARAM
// decay : 0 ~ 127
// delay : 0 ~ 12000
#ifdef ECHO_SPECIAL_PARA
UINT16 echo_para_tbl[9][2]={
{0,0}, {76,2976}, // decay : 76/128= 0.6 , delay: 2976/44100=67ms
{79,3648}, {81,4320},
{84,4992}, {87,5664},
{89,6336}, {92,7008},
{94,7680},
};
#elif defined(SUPPORT_MIDI) //Jeff 20040303
UINT16 echo_para_tbl[9][2]={
{0,0}, {7,12000},
{15,13000}, {23,12000},
{31,12000}, {39,12000},
{47,12000}, {55,12000},
{63,12000},
};
#else//ECHO_SPECIAL_PARA
UINT16 echo_para_tbl[9][2]={
{0,0}, {7,10000},
{15,10000}, {23,10000},
{31,10000}, {39,10000},
{47,10000}, {55,10000},
{63,10000},
};
#endif//ECHO_SPECIAL_PARA
inline int AUDIF_Set_EchoPara(UINT16 x)
{
int res;
res = AUDIF_Set_Echo(echo_para_tbl[x][0],echo_para_tbl[x][1] );
return res;
}
#else
inline int AUDIF_Set_EchoPara(UINT16 x) {}
#endif //ifdef USE_MIC_ECHO_PARAM
//Audio DSP MIC control command
//threshold://(0~0xff:0x55:for Yuxing, 0x35 for small board, 0x25 for large board)
//sensitivity:(1~7:default=1)
//on:threshold=0, sensitivity=0 //off:threshold=0xff, sensitivity=0xff
inline int AUDIF_Set_MICStatus(UINT32 threshold, UINT32 sensitivity)
{
return (DSP_AudioIOControl(MIC, threshold, sensitivity));
}
//Audio DSP MIC Vol(gain) control command ( 0~8(0:off) )
inline int AUDIF_Set_MICVol(UINT32 tblval)
{
return (DSP_AudioIOControl(AD, tblval, 0));
}
inline int AUDIF_Set_MICVol2(UINT32 tblval)
{
return (DSP_AudioIOControl(AD_2, tblval, 0));
}
//Pro LogicII control
inline int AUDIF_Set_ProLogicII(UINT32 mode)
{
return (DSP_AudioIOControl(PROLOGIC, mode, 0));
}
//Audio DSP Speaker Delay control command
//spk : 1(center spk), 2(surround spk)
//delay: time(ms)
inline int AUDIF_Set_SpkDelay(UINT32 spk, UINT32 delay)
{
return (DSP_AudioIOControl(SPKDELAY, spk, delay));
}
int AUDIF_Set_Volume(UINT16 x)
{
int res;
res = DSP_AudioIOControl(VOLUME, x, 0);
#ifdef NO_AUD_MIC_OFF
if(x) AUDIF_Set_MICVol(mic_volume);
#elif defined(NO_AUD_ECHO_OFF)
if(x) AUDIF_Set_Echo(echo_level, echo_level);
#endif
return res;
}
/* Oliver : modified as above
#ifdef NO_AUD_MIC_OFF
int AUDIF_Set_Volume(UINT16 x)
{
int res=DSP_AudioIOControl(VOLUME, x, 0);
if(x)
AUDIF_Set_MICVol(mic_volume);
return res;
}
#endif
#ifdef NO_AUD_ECHO_OFF
int AUDIF_Set_Volume(UINT16 x)
{
int res=DSP_AudioIOControl(VOLUME, x, 0);
if(x)
AUDIF_Set_Echo(echo_level, echo_level);
return res;
}
#endif
*/
int AUDIF_Demute()
{
int iRes;
user_mute = 0;
#ifdef MUTE_EXECUTE_MIC
#ifdef MIC_2CHANNEL//nono 4-1-5 11:51
AUDIF_Set_MICVol2(setup_GetMICVol2());
AUDIF_Set_MICVol(setup_GetMICVol());
#else
AUDIF_Set_MICVol(mic_volume);
#endif//#ifdef MIC_2CHANNEL
#endif//#ifdef MUTE_EXECUTE_MIC
#ifdef CNTR_5SPK_VOLUME
{//terry,2004/2/17 10:57AM
int i;
for (i=0; i<7; i++)
{
iRes=ReadFromI2c(0xa0,ADDR_I2C_VOLUME+i,(BYTE *)&audio_volume,sizeof(audio_volume));//terry,2004/2/17 10:56AM
if(i==0)
{
#ifdef CNTR_5SPK_TYPE_2 //linrc add 2004-10-12 9:51
if(IS_AUDIF_CODING_MODE_LPCM || IS_AUDIF_CODING_MODE_DTS
|| IS_AUDIF_CODING_MODE_PCM || IS_AUDIF_CODING_MODE_WMA
|| IS_AUDIF_CODING_MODE_DTSCD)
{
iRes = AUDIF_Set_Volume(volume_5SPK[0]);
}
else
iRes = AUDIF_Set_Volume(15);
#else
iRes = AUDIF_Set_Volume(volume_5SPK[0]);
#endif
}
else
DSP_AudioIOControl(FLSPKGAIN+i-1,volume_5SPK[i],0);
}
}
#else//#ifdef CNTR_5SPK_VOLUME
#ifndef AC3_BASS_MANAGEMENT
if(downmix_off){
iRes = AUDIF_Set_Volume(audio_volume);
//set front speaker gain
AUDIF_Set_FSPKGain(fspk_volume/2);
//set center speaker gain
AUDIF_Set_CSPKGain(cspk_volume/2);
//set surround speaker gain
AUDIF_Set_SSPKGain(sspk_volume/2);
}
else
#endif
iRes = AUDIF_Set_Volume(audio_volume);//wangap
#endif//#ifdef CNTR_5SPK_VOLUME
return iRes;
}
//Audio DSP key-shift control command ( 1~15 )
inline int AUDIF_Set_Key(UINT32 keyshift)
{
return (DSP_AudioIOControl(KEY, keyshift, 0));
}
//Audio DSP 3D-Surround control command ( 0:off, 1~..:type )
inline int AUDIF_Set_Surround(UINT32 stype)
{
return(DSP_AudioIOControl(SURROUND, stype, 0));
}
//Audio DSP set EQ type command (0:standard, 0x0010:user-defined )
inline int AUDIF_Set_EQType(UINT32 eqtype)
{
return (DSP_AudioIOControl(EQ, eqtype, 0));
}
//Audio DSP ECHO control command ( level:0(off) (light)1~8(heavy) )
inline int AUDIF_Set_Echo(UINT32 delay, UINT32 decay)
{
return (DSP_AudioIOControl(ECHO, delay, decay));
}
inline int AUDIF_Flush_Buffer(void)
{
return (DSP_AudioIOControl(FLOW, AUDIOFLUSH, 0));
}
inline int AUDIF_Set_VCDFF2PLAY(void)
{
return (DSP_AudioIOControl(FLOW, AUDIOFF2PLAY, 0));
}
// AUDIF_Init_Audio
// FUNCTION DESCRIPTION :
// initialize all audio hw/sw/decoder related parameters/variables/configurations.
inline void AUDIF_Init_Audio(void)
{
/*
#ifdef DVD_SETUP_REENG
int res;
UINT16 P, I;
P=setup_getItemPos(STR_OS_SUBWOOFER);
I=P&0xff;
P=P>>8;
if(setup_item[P][I][setup_VA[SETUP_VA_SUBWOOFER]]==STR_OS_ON)
res=1;
else
res=0;
#endif
*/
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : audio initial setup\n");
#endif
// audio gpio mute if needed
AUDKRNL_Init_AudHW_CLK();//oliver 20041006 audhw_clk_init();
coding_mode_now = AUDIF_CODING_MODE_DEFAULT; // reset (force coding-mode setup)
smp_rate_now = 0xff; // reset (force sample-rate setup)
smp_rate_down = 0xff;
frequency_mask = 0xffff;
frequency_multiple = 0x1;
AUDIF_Set_SampleRate(FS_DEFAULT); // force set default frequency
//init_audio_dsp_coding_mode();
AUDIF_Set_Channel(0x00);
#ifdef NEW_UART_COMMAND //lijinhai solve for fuss ac3
first_init_disk_audio=1;
#endif
}
// AUDIF_Init_CDDA
//
inline void AUDIF_Init_CDDA(void)
{
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : initial CDDA\n");
#endif
AUDIF_Set_SampleRate(FS_44K);
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_PCM);
//we use PCM as CDDA ans DTS-CD SPDIF/BITSTREAM DSP decoder
//so, we use AudioSetSPDIF command to distinguish them
//parameter 1:CDDA, 2:DTS-CD
if(setup_IsSet2SPDIF_Bitstream()) { //Jeff 20020719
AUDIF_Set_SPDIF(2);//AudioSetSPDIF(2); //ycwen : 2004/08/24, we don't need to use this command to distinguish CDDA/DTSCD anymore.
}
}
// AUDIF_Init_DTSCD
//
inline void AUDIF_Init_DTSCD(void)
{
AUDIF_Set_SampleRate(FS_44K); //Jeff 20020805
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_DTSCD);
//we use PCM as CDDA ans DTS-CD SPDIF/BITSTREAM DSP decoder
//so, we use AudioSetSPDIF command to distinguish them
//parameter 1:CDDA, 2:DTS-CD
if(setup_IsSet2SPDIF_Bitstream()) { //Jeff 20020719
AUDIF_Set_SPDIF(2);
}
}
#ifndef SUPPORT_AC3_CD_DISC //terry,2004/2/17 06:35PM
inline void AUDIF_Init_AC3CD(void) {}
#else
inline void AUDIF_Init_AC3CD(void)
{
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : AC3-CD setup\n");
#endif
AUDIF_Set_SampleRate(FS_44K);
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_AC3);
}
#endif
#ifndef SUPPORT_MIDI
inline void AUDIF_Init_MIDI(void) {}
#else
inline void AUDIF_Init_MIDI(void) //Jeff 20030318
{
UINT32 i;
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : midi audio setup\n");
#endif
AUDIF_Set_SampleRate(FS_44K);
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_MIDI);
for (i=0; i<0xfffffff0; i++) {
if (regs0->dsp24_port[0] != 0xffffffff)
break;
}
}
#endif
#ifndef SUPPORT_WMA
inline void AUDIF_Init_WMA(void) {}
#else
inline void AUDIF_Init_WMA(void)
{
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : WMA audio setup\n");
#endif
coding_mode_now = 0; //ycwen 2004/09/29 : To prevent DSP from sync error (4444) , we force codec download everytime.
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_WMA);
#ifdef SDRAM_16Mb_Mode //terry,2004/4/13 05:28PM
asf_init_wma();
#endif
}
#endif
#ifndef SUPPORT_AAC
inline void AUDIF_Init_AAC(void) {}
#else
inline void AUDIF_Init_AAC(void)
{
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : AAC audio setup\n");
#endif
AUDIF_Set_SampleRate(FS_44K);
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_AAC);
}
#endif
void AUDIF_Init_MP3(void) //Jeff 20010806
{
#ifdef AUDDRV_DBG
auddbg_puts("AUDDRV : MP3 audio setup\n");
#endif
AUDIF_Set_SampleRate(FS_44K);
#ifdef SDRAM_16Mb_Mode
#ifdef BBK_AMP_NOISE_PROBLEM_GBM
if(cd_type_loaded==CDSVCD||cd_type_loaded==CDVCD20||cd_type_loaded==CDVCD10){//gerry add,2004-6-10 13:33
coding_mode_now = 0;//nono add 2004-5-15 15:48
delay_srv_10ms(130);
}
#else
if(cd_type_loaded!=CDSVCD)//gerry add,2004-6-10 13:33
coding_mode_now = 0;//nono add 2004-5-15 15:48
#endif
#endif //SDRAM_16Mb_Mode
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_MP3);
}
#ifndef JPGDSP
inline void AUDIF_Init_JPG(void) {}
#else
inline void AUDIF_Init_JPG(void)
{
#ifdef AUDDRV_DBG
auddbg_puts("UDDRV : jpeg setup\n");
#endif
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_JPG);
}
#endif
// FUNCTION
// AUDIF_LPCM_Init_Parm
//
// DESCRIPTION
// initialize LPCM DM with playback specific parameters
// DSP DM setting meanings for LPCM decoder:
// 64: channel numbers, not used in AOB/CDDA
// 65: mode: AOB/VOB/WAVE/CDDA + AOB channel status bit
// 66: sample resolution: 0: 16, 1: 20, 2: 24, 3: 32, 4: 8 bit
// 67: sampling rate:
// 68: group 2 sample resolution
// 69: group 2 sampling rate
void AUDIF_LPCM_Init_Parm(UINT32 mode, WAVFORMATMACRO wfmt)
{
set_dsp3_pcm_value(64, wfmt.wfx.nChannels);
set_dsp3_pcm_value(65, mode);
switch (mode & LPCM_MODE_MASK)
{
case LPCM_MODE_AOB:
set_dsp3_pcm_value(66, wfmt.reserve[0]);
set_dsp3_pcm_value(67, wfmt.reserve[1]);
set_dsp3_pcm_value(68, wfmt.reserve[2]);
set_dsp3_pcm_value(69, wfmt.reserve[3]);
set_dsp3_pcm_value(70, wfmt.reserve[4]);
break;
case LPCM_MODE_VOB:
set_dsp3_pcm_value(66, wfmt.reserve[0]);
set_dsp3_pcm_value(67, wfmt.reserve[1]);
break;
default:
set_dsp3_pcm_value(66, AUDKRNL_LPCM_Get_BitDepthParam(wfmt.wfx.wBitsPerSample));
set_dsp3_pcm_value(67, AUDKRNL_LPCM_Get_FrqParam(wfmt.wfx.nSamplesPerSec));
break;
}
AudioSetEndPoint(abv_size);
regs0->dsp24_port[0] = 0x0f01;
regs0->dsp24_port[1] = 0;
}
// FUNCTION
// AUDIF_Init_Wave_Audio
//
// DESCRIPTION
// initialize audio with waveformat header
int AUDIF_Init_Wave_Audio(WAVFORMATMACRO wfmt)
{
SUB_FILE_MEDIA_FLAG(FILE_AUDIO_VBR);
AUDIF_Set_SmpRate(wfmt.wfx.nSamplesPerSec);
aud_frame_size = 0;
switch (wfmt.wfx.wFormatTag) {
case WAVE_FORMAT_PCM:
//avi_printf("PCM\n");
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_LPCM);
AUDIF_LPCM_Init_Parm(LPCM_MODE_WAVE, wfmt);
break;
case WAVE_FORMAT_MPEG:
case WAVE_FORMAT_MPEGLAYER3:
//avi_printf("mpg audio\n");
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_MP3);
if (wfmt.wfx.nBlockAlign == 1152)
{
ADD_FILE_MEDIA_FLAG(FILE_AUDIO_VBR);
aud_frame_size = 1152;
}
break;
case WAVE_FORMAT_DOLBY_AC3:
//avi_printf("ac3\n");
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_AC3);
break;
case WAVE_FORMAT_DOLBY_DTS:
//avi_printf("dts\n");
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_DTS);
break;
#ifdef SUPPORT_WMA
case WAVE_FORMAT_WMA_STEREO:
{
extern void asf_init_wma();
extern WMAHEADER wma_header;
extern BYTE wmabuf[8];
extern UINT32 ploadlen;
extern UINT32 pldcnt;
extern BYTE wmambn;
extern BYTE apf;
WMAUDIO2WAVEFORMAT wma_wave;
AUDIF_Set_CodingMode(AUDIF_CODING_MODE_WMA);
memcpy(&wma_wave, &wfmt, sizeof(WMAHEADER));
wma_header.wFormatTag = wma_wave.wfx.wFormatTag;
wma_header.dwSampRate = wma_wave.wfx.nSamplesPerSec;
wma_header.dwBytePerSec = wma_wave.wfx.nAvgBytesPerSec;
wma_header.wBlockAlign = wma_wave.wfx.nBlockAlign;
wma_header.wReserve1 = (wma_wave.wfx.wBitsPerSample<<8) | (wma_wave.wfx.nChannels);
wma_header.dwSampPerBlk = wma_wave.dwSamplesPerBlock;
wma_header.wEncOption = wma_wave.wEncodeOptions;
wma_header.wTag = 0;
wmambn = 0;
pldcnt = 0;
apf = 0;
ploadlen = wma_wave.wfx.nBlockAlign;
wmabuf[6] = ploadlen & 0xff;
wmabuf[7] = ploadlen >> 8;
asf_init_wma();
}
break;
#endif // SUPPORT_WMA
default:
//avi_printf("Unknown audio format %x\n", wfmt.wfx.wFormatTag);
return 0;
}
#ifdef SPHE1000 //bktesng, 2004/12/09, To get audio info for Linux AP.
pDVB->audio_codec = wfmt.wfx.wFormatTag;
#endif
return 1;
}