audkernel.c
上传用户:caisangzi8
上传日期:2013-10-25
资源大小:15756k
文件大小:9k
- #include "memmap0.h"
- #include "audkernel.h"
- #include "DSP3Codec.inc" // 2004/11/18 yltseng
- #include "NESInit.h"
- /*WMA/HDCD:
- * "This product is protected by certain intellectual property rights of
- * Microsoft and cannot be used or further
- * distributed without a license from Microsoft.
- */
- /***********************************************************************
- * Macro define Session
- ***********************************************************************/
- /*============================================================*/
- // To ease the control of audio clocks,
- // currently PCMBCK, IECBCK, ADCBCK all source from XCK.
- // as a result, when changing sampling frequency, only XCK change is need.
- //
- // note: if there are needs for enable/disable individual clocks
- // we must increase other interfaces
-
- #ifndef SPHE1000
- #ifdef SUPPORT_384_XCK //defined in user_init.h
- static const UINT16 xck_clk_fs_table[] =
- {
- AUDCLK_384XCK_12288, AUDCLK_384XCK_16934, AUDCLK_384XCK_18432, 0, 0,
- AUDCLK_384XCK_33869, AUDCLK_384XCK_36864, 0, 0,
- AUDCLK_384XCK_67736, AUDCLK_384XCK_73728, 0, 0
- };
- #define AUD_BCK_SETTING AUDCLK_64BCK_384
- #define AUD_IEC_SETTING AUDCLK_128IEC_384
- #define AUD_ADC_SETTING AUDCLK_64ADC_384
- #else // 256fs
- static const UINT16 xck_clk_fs_table[] =
- {
- AUDCLK_256XCK_08192, AUDCLK_256XCK_11290, AUDCLK_256XCK_12288, 0, 0,
- AUDCLK_256XCK_22579, AUDCLK_256XCK_24576, 0, 0,
- AUDCLK_256XCK_45158, AUDCLK_256XCK_49152, 0, 0
- };
- #define AUD_BCK_SETTING AUDCLK_64BCK_256
- #define AUD_IEC_SETTING AUDCLK_128IEC_256
- #define AUD_ADC_SETTING AUDCLK_64ADC_256
- #endif
- #else // SPHE1000
- #ifdef SUPPORT_384_XCK //defined in user_init.h
- static const UINT16 xck_clk_fs_table[] =
- {
- AUDCLK_384XCK_12288, AUDCLK_384XCK_18432, AUDCLK_384XCK_18432, 0, 0,
- AUDCLK_384XCK_36864, AUDCLK_384XCK_36864, 0, 0,
- AUDCLK_384XCK_73728, AUDCLK_384XCK_73728, 0, 0
- };
- #define AUD_BCK_SETTING AUDCLK_64BCK_384
- #define AUD_IEC_SETTING AUDCLK_128IEC_384
- #define AUD_ADC_SETTING AUDCLK_64ADC_384
- #else // 256fs
- static const UINT16 xck_clk_fs_table[] =
- {
- AUDCLK_256XCK_08192, AUDCLK_256XCK_12288, AUDCLK_256XCK_12288, 0, 0,
- AUDCLK_256XCK_24576, AUDCLK_256XCK_24576, 0, 0,
- AUDCLK_256XCK_49152, AUDCLK_256XCK_49152, 0, 0
- };
- #define AUD_BCK_SETTING AUDCLK_64BCK_256
- #define AUD_IEC_SETTING AUDCLK_128IEC_256
- #define AUD_ADC_SETTING AUDCLK_64ADC_256
- #endif //#ifdef SUPPORT_384_XCK
- #endif //#ifndef SPHE1000
- #define get_dsp3_im_ptr() get_dsp_im_ptr(0,0)
- #define get_dsp3_pm_ptr() get_dsp_pcm_ptr(0,0)
- #define get_dsp3_dm_ptr() get_dsp_aud_ptr(0,0)
- extern int dsp3_decompress(const BYTE *rom, BYTE *dst);
- #define dsp3_setupim(rom,len) dsp3_decompress(rom,get_dsp3_im_ptr()+0)
- #define dsp3_setupdm(rom,len,off) dsp3_decompress(rom,get_dsp3_dm_ptr()+off)
- #define dsp3_setuppm(rom,len,off) dsp3_decompress(rom,get_dsp3_pm_ptr()+off)
- #define DSP_RESET() (regs0->dsp24_control=RF_DSP24_RESET)
- #define DSP_STALL() (regs0->dsp24_control=RF_DSP24_STALL)
- #define DSP_GO() (regs0->dsp24_control=0)
- extern void dsp3_config(void);
- /***********************************************************************
- * Code Session
- ***********************************************************************/
-
- void AUDKRNL_Init_AudHW_CLK(void)
- {
- AUD_ENABLE_XCK_PAD();
-
- #ifndef NO_AUD_SET_BCK
- AUD_SET_BCK(AUD_BCK_SETTING);
- #endif//#ifndef NO_AUD_SET_BCK
-
- AUD_SET_IEC(AUD_IEC_SETTING);
- AUD_SET_ADC(AUD_ADC_SETTING);
- AUD_SET_XCK(xck_clk_fs_table[FS_48K]);
-
- #ifdef SPHE1000
- AUD_CLR_PLLA();
- AUD_SET_PLLA(1);
- #endif
-
- AUD_ENABLE_XCK_CLK();
- }
- // FUNCTION DESCRIPTION :
- // Set Audio Hardware Clock
- //
- void AUDKRNL_Set_AudHW_SmpRate(unsigned fs)
- {
- int index=0;
-
- #ifndef NO_AUD_SET_BCK
- AUD_SET_BCK(AUD_BCK_SETTING);
- #endif//#ifndef NO_AUD_SET_BCK
- AUD_SET_IEC(AUD_IEC_SETTING);
- AUD_SET_ADC(AUD_ADC_SETTING);
-
- #ifdef SPHE1000
- //printf("cfg6: %x %x %xn", ((fs&0x555)>0), index, fs);
- AUD_CLR_PLLA();
- AUD_SET_PLLA((fs&0x222)>0);
- #endif
- while ((fs&0x1) == 0)
- {
- fs >>= 1;
- index++;
- if (index >= 12)
- break;
- }
- #ifdef CS4334_AUDIO_CLK_DELAY_TURN_ON//gerry add it for avoid cs4334 power on noise,but it is not very good to add it here,2004-7-19 21:26
- delay_1ms(100);
- #endif//CS4334_AUDIO_CLK_DELAY_TURN_ON
- AUD_SET_XCK(xck_clk_fs_table[index]);
- AUD_ENABLE_XCK_CLK();
- }
- //
- // FUNCTION DESCRIPTION
- // generic dsp3 program download
- // 2003/06/06, Bug fixed for AC3->VCD playback switch
- // disable audio output before DSP reset, to cancel any noises of decoder change
- // audio will be enabled automatically by DSP.
- INT16 AUDKRNL_Download_DSP3Codec(const BYTE *rom, int len) //(int dsp3_coding_mode)
- {
- int res=0;
-
- regs0->aud_enable = 0; //disable PCM H/W (PCM, SPDIF, ADC)
- DSP_RESET(); //reset dsp24 always disable audio before dsp_reset
-
- dsp3_config(); //config pdm and audio bitstream buffer
-
- // Move MP3 PM, DM table
- if(rom == DSP3code_MP3)
- {
- #ifdef MP3_JPEG_COWORK//enlarge the audio buffer size
- //refer to line 67
- dsp3_setuppm(DSPMP3DMTab,DSPMP3DMlen,0x1420*3);
- dsp3_setuppm(DSPMP3PMTab,DSPMP3PMlen,0x24c0*3);
- #else
- //refer to line 70
- dsp3_setupdm(DSPMP3PMTab,DSPMP3PMlen,0x0c00*3);
- dsp3_setuppm(DSPMP3DMTab,DSPMP3DMlen,0x1420*3);
- #endif
- }
-
- // copy im
- if ((res=dsp3_setupim(rom,len)) < 0) {
- #ifdef AUDDRV_DBG // MONE_DSP3_ERROR
- auddbg_puts("*ERROR* gunzip dsp code errorn");
- #endif
- }
- else{
- #ifdef SUPPORT_NESGAME
- int i;
- if(rom == DSP3code_NES) {
- for (i=0;i<15;i++)
- regs0->dsp24_port[i]=0;
-
- //DAC initialize format bit8~15, set playback rate(bit-0 ~ bit-1)
- regs0->dsp24_port[4]|=(DACFORMAT<<8)|SOUND_PLAYBACK_ID;
- }
- #endif // end of SUPPORT_NESGAME
- #ifdef NO_AUDIO_DSP
- return res;
- #endif
- #ifdef SETUP_DONT_PAUSE
- #ifdef SUPPORT_NESGAME
- if(coding_mode_now!=AUDIF_CODING_MODE_NES)
- #endif
- regs0->dsp24_port[5]=-1;
- #endif
- DSP_GO();
- }
- return res;
- }
- static inline void AUDKRNL_Set_DSP_Buffer_Addr( const DSP3_CODEC_INFO* pCodecInfo, int coding_mode )
- { // 2004/11/18 yltseng
- #ifdef MOVE_WMA_DSP_CODEC_ADDR//terry,2004/1/12 05:02PM // 2004/09/16 yltseng
- if( (cd_type_loaded==CDROM)&&(coding_mode==AUDIF_CODING_MODE_WMA) )
- set_aud_buf( A_DSP24_WMA_YA, A_DSP24_WMA_YA + pCodecInfo->uiDSPIM, A_DSP24_WMA_YA + pCodecInfo->uiDSPIM + pCodecInfo->uiDSPPM );
- else
- #endif
- #ifdef MOVE_PAL_AUDYA
- if( regs0->mc_compress != 0 )
- set_aud_buf( P_DSP24YA, P_DSP24YA + pCodecInfo->uiDSPIM, P_DSP24YA + pCodecInfo->uiDSPIM + P_DSP24YA + pCodecInfo->uiDSPPM );
- else
- #endif
- set_aud_buf( A_DSP24YA, A_DSP24YA + pCodecInfo->uiDSPIM, A_DSP24YA + pCodecInfo->uiDSPIM + pCodecInfo->uiDSPPM );
- }
- // FUNCTION DESCRIPTION :
- // download specific DSP codec
- //
- void AUDKRNL_Download_Codec(int coding_mode)
- { // 2004/11/18 yltseng
- #ifdef MONE_DOWNLOAD_CODEC //debug msg enhancement
- auddbg_printf("n-------><download - coding_mode:0x%x>n",coding_mode);
- auddbg_printf("-------><0x1:AC3 0x2:PPCM 0x40:DTS 0x100:MP3 0x200:PCM>n");
- auddbg_printf("-------><0x400:MIDI 0x1000:SPDIF 0x2000:DTSCD 0x4000:WMA>n");
- #endif
-
- //??? Is it still necessary? already done in AUDKRNL_Download_DSP3Codec()
- #ifndef SPHE1000 // barry remove it in HE1000 because in dsp3_download had stop it
- regs0->aud_enable = 0; // disable PCM H/W (PCM, SPDIF, ADC)
- DSP_RESET(); // force dsp stop.
- #endif
-
- #if ( defined(SDRAM_16Mb_Mode) && !defined(SDRAM16M_5_1CH) && !defined(RAW_HAVE_ANALOG_OUTPUT) )
- if( ( coding_mode == AUDIF_CODING_MODE_AC3 ) && setup_IsSet2SPDIF_Bitstream() )
- coding_mode = AUDIF_CODING_MODE_SPDIF;
- #endif
-
- UINT32 uiIndex = GetDSPCodecIndex( coding_mode );
- const DSP3_CODEC_INFO* pCodecInfo = GetDSPCodecInfo( uiIndex );
- AUDKRNL_Set_DSP_Buffer_Addr( pCodecInfo, coding_mode );
- AUDKRNL_Download_DSP3Codec( pCodecInfo->pDSPcode, 0 );
- }
- UINT32 AUDKRNL_LPCM_Get_BitDepthParam(UINT32 bitsample)
- {
- switch (bitsample)
- {
- case 8:
- return 4;
- case 20:
- return 1;
- case 24:
- return 2;
- case 32:
- return 3;
- default:
- return 0;
- }
- }
- UINT32 AUDKRNL_LPCM_Get_FrqParam(UINT32 samprate)
- {
- UINT32 s1;
- if (samprate == 0)
- return 0;
- if (samprate<7000) // 5 : 6 kHz
- s1 = 5;
- else if (samprate<9500) // 20 : 8 kHz
- s1 = 20;
- else if (samprate<11500) // 12 : 11.025 kHz
- s1 = 12;
- else if (samprate<14000) // 4 : 12 kHz
- s1 = 4;
- else if (samprate<19000) // 19 : 16 kHz
- s1 = 19;
- else if (samprate<23000) // 11 : 22.05 kHz
- s1 = 11;
- else if (samprate<28000) // 3 : 24 kHz
- s1 = 3;
- else if (samprate<38000) // 16 : 32 kHz
- s1 = 16;
- else if (samprate<46000) // 8 : 44.1 kHz
- s1 = 8;
- else if (samprate<68000) // 0 : 48 kHz
- s1 = 0;
- else if (samprate<92000) // 9 : 88.2 kHz
- s1 = 9;
- else if (samprate<136000) // 1 : 96 kHz
- s1 = 1;
- else if (samprate<184000) // 10 : 176.4 kHz
- s1 = 10;
- else // 2 : 192 kHz
- s1 = 2;
- return s1;
- }