Nav_sacd.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:32k
- /*
- file: nav_sacd.c
- desc: Implements event handler for SACD.
- Created on: Nov 7, 2003
- */
- #include "config.h"
- #if D_SUPPORT_SACD
- #ifdef _DEBUG
- #undef IFTARCE
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include "IncludeSysDefs.h"
- #include "Kernelker_api.h"
- #include "KernelEventDef.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "Playcoreplaymodeplaymode.h"
- #include "Playcorenav_sacdpe_sacd.h"
- #include "Playcorescpadscmgr.h"
- #include "PlaycorescpadScPadAlloc.h"
- #include "Playcorenav_sacdsacd_uart.h"
- #include "PlaycoreSAMPsamp_gen.h"
- #include "PlaycoreSAMPsamp_nav.h"
- #include "PlaycoreSAMPsamp_apm.h"
- #include "PlaycoreSAMPsamp_sdm.h"
- #include "Playcorenav_sacdhweval_zoran.h"
- #include "Playcorenav_sacdnav_sacd.h"
- extern BOOL g_in_full_stop;
- static SAMP(ErrCode) Constructor(void);
- static void Destructor(void);
- static void SampCallback(SAMP(BitSet32) Event, void * EventData);
- static void NavCallback(SAMP(BitSet32) Event, void * EventData);
- #ifndef SACD_AREA_INFO_INSDRAM
- static void SaveSACDAreaInfo(SAMP(SAMP_AreaInfoDef) *stereo,SAMP(SAMP_AreaInfoDef) *multi);
- #endif
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // int SACD_Navigator(HDLR_OP Op, EVENT Event, void *Param) -
- // The main router for SACD-Navigation Events.
- //
- // Input:
- // Op - The type of operation being invoked
- // Event - The event to route
- // Param - An optional parameter for the event being routed
- //
- // Output:
- // Zero if the routing is successful.
- int SACD_Navigator(HDLR_OP Op, EVENT Event, void *Param)
- {
- SAMP(ErrCode) err = SAMP(ERR_OK);
- switch (Op)
- {
- case HDLR_ENTER: Constructor();
- //<<ZKR ML:033104 Aviod pop sound when loading sacd
- #ifdef EXINO2
- DAC_SACD_SetMute(FALSE);
- #endif
- //>>ZKR ML:033104
- break;
- case HDLR_EXIT: Destructor();
- break;
- case HDLR_EVENT:
- switch (Event)
- {
- case IE_CORE_PAUSE:
- err = SAMP(NAV_Pause)();
- break;
- case IE_CORE_STOP:
- //todo: check how to do full stop.
- SAMP(NAV_Stop)();
- g_in_full_stop = TRUE; /* forces next PLAY to be mapped to RESTART */
- // PE_SACD_AbortPlayback(0); //todo check later.
- break;
- case IE_CORE_PLAY:
- if(gcs.pstate == PST_PAUSE || gcs.pstate== PST_SCAN)
- {
- //only valid when it's pause or trick mode state.
- err = SAMP(NAV_ResumePlay)();
- break;
- }
- //fall through
- case IE_CORE_RESTART:
- if(PM_IsPlaybackProgram(PM_GetPlaybackMode()))
- err = SAMP(NAV_PlayTrack)(SACD_GLOBALS.ProgramList.tracks[0], SACD_GLOBALS.gbPlayPauseArea? 0:1);
- else
- err = SAMP(NAV_PlayTrack)(1, SACD_GLOBALS.gbPlayPauseArea? 0:1);
- break;
- case IE_CORE_NEXT_CHAPTER:
- err = SAMP(NAV_NextTrack)();
- break;
- case IE_CORE_PREVIOUS_CHAPTER:
- err = SAMP(NAV_PreviousTrack)();
- break;
- case IE_CORE_GOTO_ENTRY:
- case IE_CORE_MENU_NUMERICAL_SELECTION:
- if(PM_IsPlaybackProgram(PM_GetPlaybackMode()))
- err = SAMP(NAV_PlayTrack)(SACD_GLOBALS.ProgramList.tracks[(int)Param], SACD_GLOBALS.gbPlayPauseArea? 0:1);
- else
- err = SAMP(NAV_PlayTrack)((int)Param, SACD_GLOBALS.gbPlayPauseArea? 0:1);
- break;
- case IE_CORE_AB_REPEAT:
- if (0 == (int)Param) {
- err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_OFF));
- PM_SetRepeatAB(0);
- break;
- }
- if (PM_GetRepeatAB() & PM_REPEAT_AB_B) {
- err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_OFF));
- PM_SetRepeatAB(0);
- }
- else { //after set A or A-B, set repeat single, then A will never be setted for the dwStartAddress is still there.
- if ((0 == PM_GetRepeatAB()))// && ((g_pCDDANav->m_PositionA).iPlaylistItem < 0)) // so I remove this condition, if this is necessary, let me know please, tonnyg
- {
- err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_A));
- PM_SetRepeatAB(PM_REPEAT_AB_A);
- }
- else {
- err = SAMP(NAV_RepeatAB)(SAMP(NAV_REPEAT_AB_AB));
- PM_SetRepeatAB(PM_REPEAT_AB_B);
- }
- }
- break;
- #if 0 //SAMP doesn't support bookmark.
- case IE_CORE_SET_BOOKMARK:
- #ifdef HW_POWER_ON_RESUME
- NVM_BMK_SET((int)Param);
- #endif
- SetMarker(eBookmark, (WORD)Param - 1);
- break;
- case IE_CORE_GOTO_BOOKMARK:
- OnGoToBookmark((WORD)Param - 1);
- break;
- #endif
- case IE_CORE_SCAN:
- if(0 == (int)Param) //normal speed play
- {
- err = SAMP(NAV_ResumePlay)();
- }
- else
- if(0 < (int)Param) //fast forward
- {
- err = SAMP(NAV_ForwardScan)((SAMP(UInt8)) Param);
- }
- else
- if(0 > (int)Param) //fast backward
- {
- int param = -((int)Param);
- err = SAMP(NAV_BackwardScan)((SAMP(UInt8)) param);
- }
- break;
- case IE_CORE_TICK_ONE_SEC:
- break;
- case IE_CORE_TICK_200:
- // OnTick();
- break;
- case IE_CORE_SEAMLESS_MODE_CHANGE:
- //non_shuffle to shuffle
- if(PM_IsPlaybackShuffle(PM_GetPlaybackMode()))
- err = SAMP(NAV_Shuffle)(TRUE);
- else
- {
- err = SAMP(NAV_Shuffle)(FALSE);
- if(PM_IsPlaybackProgram(PM_GetPlaybackMode()))
- {
- //non_program to program
- err = SAMP(NAV_SetPlaySequence)(SAMP(NAV_PLAY_SEQ_PROGRAM));
- }
- else
- {
- //non_normal to normal
- err = SAMP(NAV_SetPlaySequence)(SAMP(NAV_PLAY_SEQ_ALL));
- }
- }
- if(PM_IsRepeatAll())
- err = SAMP(NAV_Repeat)(SAMP(NAV_REPEAT_ALL));
- else
- if(PM_IsRepeatSingle())
- err = SAMP(NAV_Repeat)(SAMP(NAV_REPEAT_TRACK));
- else
- err = SAMP(NAV_Repeat)(SAMP(NAV_REPEAT_OFF));
- break;
- case IE_CORE_GOTO_TIME:
- case IE_CORE_GOTO_DISC_TIME:
- {
- SAMP(SACD_TimeCode) Timecode;
- if(IE_CORE_GOTO_TIME == Event)
- (ULONG)Param += Nav_SACD_Get_Track_Start_Time(SACD_GLOBALS.currentTrack);
- Timecode.min = (BYTE)(((ULONG)Param)/60);
- Timecode.sec = (BYTE)(((ULONG)Param)%60);
- Timecode.fr = 0;
- err = SAMP(NAV_PlayAtTimecode)(Timecode);
- }
- #ifdef EXINO2 // <<< SEC CH.KO033104
- ie_send(IE_UI_REFRESH_TIME);
- #endif
- break;
- case IE_CORE_CDNAV_INTRO:
- err = SAMP(NAV_IntroScan)(TRUE, (SAMP(UInt8)) SACD_INTRO_TIME);
- break;
- case IE_CORE_SACD_SET_ACTIVE_AREA:
- err = SAMP(NAV_AreaSwitch)((SAMP(SACD_Area)) Param);
- SACD_GLOBALS.activeArea = (SAMP(SACD_Area)) Param;
- break;
- case IE_CORE_SAMP_NAV_ACTIVATED:
- //Do APM settings.
- err = SAMP(NAV_SetProgramList)(&(SACD_GLOBALS.ProgramList));
- err = SAMP(APM_SetInputMode)(SAMP(SACD_IN_DSD));
- #ifdef AUDIO_DAC_SUPPORT_DSD
- err = SAMP(APM_SetOutputMode)(SAMP(APM_OUT_DSD), SAMP(APM_OUT_DSD));
- #else
- err = SAMP(APM_SetOutputMode)(SAMP(APM_OUT_PCM), SAMP(APM_OUT_PCM));
- #endif
- #if 0 //check later.
- err = SAMP(APM_Set6chDownmix)((SAMP(APM_6ch_MixDef))(gps->SACD6ChDownmixMode));
- err = SAMP(APM_Set2chDownmix)((SAMP(APM_2ch_MixDef)) (gps->SACD2ChDownmixMode));
- err = SAMP(APM_SetSpeakers)((SAMP(APM_SpeakerDef)) (gps->SACDSpeakerMode));
- {
- SAMP(UInt16) Attenuation[8];
- Attenuation[0] = gps->SACDAttenuationLeft;
- Attenuation[1] = gps->SACDAttenuationRight;
- Attenuation[2] = gps->SACDAttenuationCenter;
- Attenuation[3] = gps->SACDAttenuationLfe;
- Attenuation[4] = gps->SACDAttenuationLs;
- Attenuation[5] = gps->SACDAttenuationRs;
- Attenuation[6] = gps->SACDAttenuation2CHLeft;
- Attenuation[7] = gps->SACDAttenuation2CHRight;
- err = SAMP(APM_SetAttenuation)(Attenuation);
- }
- {
- SAMP(UInt32) Delay[6];
- Delay[0] = gps->SACDDelayLeft;
- Delay[1] = gps->SACDDelayRight;
- Delay[2] = gps->SACDDelayCenter;
- Delay[3] = gps->SACDDelayLfe;
- Delay[4] = gps->SACDDelayLs;
- Delay[5] = gps->SACDDelayRs;
- err = SAMP(APM_SetDelay)(Delay);
- }
- err = SAMP(APM_SetFilterMode)((SAMP(APM_FilterModeDef)) (gps->SACDFilterMode));
- err = SAMP(APM_SetBassFilters)((SAMP(APM_BassFrequencyDef)) (gps->SACDBassFrequency), (SAMP(APM_BassSlopeDef)) (gps->SACDBassSlope));
- #else
- {
- DEC_LL_OCFG_SETTING ocfg;
- SAMP(APM_6ch_MixDef) sacd_ocfg;
- ocfg = SpeakersConfigTable[gps->SpeakersConfigIndex].mOCFG;
- switch(ocfg)
- {
- case DEC_LL_OCFG_2_1:
- case DEC_LL_OCFG_2_0_SURROUND_COMPATIBLE:
- case DEC_LL_OCFG_1_0:
- case DEC_LL_OCFG_2_0_NORMAL:
- sacd_ocfg = SAMP(APM_MIX_6CH_2_0);
- break;
- case DEC_LL_OCFG_2_2:
- sacd_ocfg = SAMP(APM_MIX_6CH_2_2);
- break;
- case DEC_LL_OCFG_3_2:
- sacd_ocfg = SAMP(APM_MIX_6CH_3_2);
- break;
- case DEC_LL_OCFG_3_0:
- case DEC_LL_OCFG_3_1:
- sacd_ocfg = SAMP(APM_MIX_6CH_3_0);
- break;
- }
- err = SAMP(APM_Set6chDownmix)(sacd_ocfg);
- }
- err = SAMP(APM_Set2chDownmix)(SAMP(APM_MIX_2CH_DOWNMIX));
- {
- SAMP(APM_SpeakerDef) speakerSetting;
- if(SPK_SIZE_SMALL == SpeakersConfigTable[gps->SpeakersConfigIndex].mFrontSpk)
- {
- speakerSetting = SAMP(APM_SSS1);
- }
- else //front speaker is large
- {
- if(SPK_SIZE_LARGE == SpeakersConfigTable[gps->SpeakersConfigIndex].mSurroundSpk)
- speakerSetting = SAMP(APM_LLL1);
- else
- speakerSetting = SAMP(APM_LSS0);
- //sacd todo: check when to set SAMP(APM_LSS0_noLFE).
- }
- err = SAMP(APM_SetSpeakers)(speakerSetting);
- }
- {
- SAMP(UInt16) Attenuation[8];
- memset(Attenuation, 0, 16);
- err = SAMP(APM_SetAttenuation)(Attenuation);
- }
- {
- SAMP(UInt32) Delay[6];
- memset(Delay, 0, 24);
- err = SAMP(APM_SetDelay)(Delay);
- }
- err = SAMP(APM_SetFilterMode)(SAMP(APM_FM_MAX_SNR));
- {
- SAMP(APM_BassFrequencyDef) bassFreq = SAMP(APM_BASS_FREQ_100);
- SAMP(APM_BassSlopeDef) bassSlope = SAMP(APM_BASS_SLOPE_18);
- #if defined(BM_CUTOFF_120HZ)
- bassFreq = SAMP(APM_BASS_FREQ_120);
- #elif defined(BM_CUTOFF_80HZ)
- bassFreq = SAMP(APM_BASS_FREQ_80);
- #endif
- #if defined(BM_SLOPE_24)
- bassSlope = SAMP(APM_BASS_SLOPE_24);
- #elif defined(BM_SLOPE_12)
- bassSlope = SAMP(APM_BASS_SLOPE_12);
- #endif
- err = SAMP(APM_SetBassFilters)(bassFreq, bassSlope);
- }
- #endif
- err = SAMP(APM_SetPcmUpsampling)(SACD_UPSAMPLING_RATE); //active only when output is PCM.
- err = SAMP(APM_SetPIO)(2176); //doesn't matter?
- // err = SAMP(NAV_PlayTrack)(1, SACD_GLOBALS.gbPlayPauseArea? 0:1); //todo: remove later.
- //todo: check later. DAC_SACD_SetMute(FALSE);
- break;
- default:
- dbg_printf(("SACD_Nav: Unexpected Event %xn",Event & 0xFF));
- break;
- }
- break;
- default:
- dbg_printf((" SACD_Nav: Unknown Operation requested %dn", Op));
- break;
- }
- if(err != SAMP(ERR_OK))
- {
- tr_printf((" SACD_Nav: error handling SACD nav event! %dn", Op));
- }
- return 0;
- }
- //jerry todo: remove later.
- //int hold_samp = 1;
- /*
- Desc: initialize and start SAMP.
- rtn: Err_OK, succeed so it's a SACD disc.
- otherwise not a SACD disc.
- */
- static SAMP(ErrCode) Constructor(void)
- {
- void (*lFuroreISR)(void);
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- //TODO: check if stack overflows with the 2 structs.
- // SAMP(SAMP_AreaInfoDef) stereo;
- // SAMP(SAMP_AreaInfoDef) multi;
- SAMP(Bool) bDiscRecognized = FALSE;
- //initialize SACD_GLOBALS
- SACD_GLOBALS.samp_state = SAMP_NOT_ACTIVATED;
- SACD_GLOBALS.nav_state = NAV_NOT_ACTIVATED;
- SACD_GLOBALS.play_speed = 1;
- SACD_GLOBALS.iCurrentTime = 0;
- SACD_GLOBALS.iCurrentAbsTime = 0;
- SACD_GLOBALS.gbPlayPauseArea = 1;
- // SACD_GLOBALS.channels =
- SACD_GLOBALS.currentTrack = 0;
- SACD_GLOBALS.currentIndex = 0;
- #ifndef SACD_AREA_INFO_INSDRAM
- SACD_GLOBALS.StereoAreaInfoPtr = sc_Malloc((sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
- SACD_GLOBALS.MultiAreaInfoPtr = sc_Malloc((sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
- if(NULL == SACD_GLOBALS.StereoAreaInfoPtr || NULL == SACD_GLOBALS.MultiAreaInfoPtr)
- {
- tr_printf(("Fatal! Constructor: can't allocate memory from scratch pad "));
- return SAMP(ERR_FAILED);
- }
- #endif
- #ifndef SACD_AREA_INFO_INSDRAM
- //todo: ask Philips to save Area info In SC.
- SACD_GLOBALS.pAreaStereo = malloc(sizeof(SAMP(SAMP_AreaInfoDef)));
- SACD_GLOBALS.pAreaMulti = malloc(sizeof(SAMP(SAMP_AreaInfoDef)));
- if(NULL == SACD_GLOBALS.pAreaStereo || NULL == SACD_GLOBALS.pAreaMulti)
- {
- tr_printf((" SACD_Nav: Fatal! Heap size too small for SAMP_AreaInfoDefn"));
- }
- #else
- {
- UINT32 temp = 0;
- int i;
- for(i = 0; i < 4; i++)
- {
- sc_SetBytes32(SDRAM_2CH_AREA_INFO_BASE, i*4, 4, (const BYTE *)(&temp));
- sc_SetBytes32(SDRAM_MULTICH_AREA_INFO_BASE, i*4, 4, (const BYTE *)(&temp));
- }
- }
- #endif
- //todo: check later. DAC_SACD_SetMute(TRUE);
- #if 0 //sacd todo: check later.
- //install ISR.
- SAMP(SDM_GetHandler)( &lFuroreISR );
- lErr = SAMP(ISR_Install)( lFuroreISR );
- #endif
- if(SAMP(ERR_OK) != lErr)
- tr_printf((" SACD_Nav: Fatal! Install ISR failedn"));
- //BE_Init
- lErr = SAMP(BE_Init)();
- if(SAMP(ERR_OK) != lErr)
- tr_printf((" SACD_Nav: Fatal! BE_Init failedn"));
- //DAC_Init
- // lErr = SAMP(DAC_Init)();
- if(SAMP(ERR_OK) != lErr)
- tr_printf((" SACD_Nav: Fatal! DAC_Init failedn"));
- //SetEngine type as IIS
- lErr = SAMP(SDM_SetEngineType)(SAMP(SDM_BE_I2S));
- #if 1 //sacd todo: check later.
- //install ISR.
- SAMP(SDM_GetHandler)( &lFuroreISR );
- lErr = SAMP(ISR_Install)( lFuroreISR );
- #endif
- //Set Burst length
- lErr = SAMP(SDM_SetBurstLength)(SACD_BURST_LENGTH);
- //Set Dac Pinning
- #ifdef AUDIO_DAC_SUPPORT_DSD
- lErr = SAMP(SDM_SetDacPinning)(0, 0,
- 0, 0,
- 0, 0,
- 0, 0,
- 0, 0,
- 0, 0,
- SAMP(SDM_DSD_CLOCK), 0, 0);
- //set DSD clock polarity. Doesn't matter with PCM DAC.
- lErr = SAMP(SDM_SetDsdClockPolarity)(1); //TODO: check later.
- //sacd todo: do external mute.
- // DAC_Set_DSD_Mode(1);
- #else
- lErr = SAMP(SDM_SetDacPinning)(SAMP(SDM_PCM_LEFTFRONT_RIGHTFRONT), SAMP(SDM_PIO),
- SAMP(SDM_PCM_CENTER_LFE), SAMP(SDM_PIO),
- SAMP(SDM_PCM_LEFTSURR_RIGHTSURR), SAMP(SDM_PIO),
- SAMP(SDM_PCM_DATACLOCK), SAMP(SDM_PCM_WORDCLOCK),
- SAMP(SDM_PCM_DATACLOCK), SAMP(SDM_PCM_WORDCLOCK),
- SAMP(SDM_PCM_LEFTFRONT_RIGHTFRONT), SAMP(SDM_PIO),
- SAMP(SDM_PIO), SAMP(SDM_PIO), SAMP(SDM_PIO));
- #endif
- {
- #ifdef MASTERCLOCK_256
- SAMP(SDM_AudioClockDef) AudioClock = SAMP(SDM_AUD_CLK_256FS);
- #else
- SAMP(SDM_AudioClockDef) AudioClock = SAMP(SDM_AUD_CLK_384FS);
- #endif
- //set audio clk, e.g. 384fs. valid for DSD stream.
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_DSD), AudioClock);
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_44), AudioClock);
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_88), AudioClock);
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_176), AudioClock);
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_48), AudioClock);
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_96), AudioClock);
- lErr = SAMP(SDM_SetAudioClock)(SAMP(SACD_IN_PCM_192), AudioClock);
- }
- //system clock is 27M hz
- lErr = SAMP(SDM_SetSystemClock)(SYS_CLK);
- //samp init
- lErr = SAMP(SAMP_Init)();
- if(SAMP(ERR_OK) != lErr)
- tr_printf((" SACD_Nav: Fatal! SAMP_Init failedn"));
- //SAMP Subscribe
- lErr = SAMP(SAMP_Subscribe)( SampCallback
- , ( SAMP_ACTIVATED
- | SAMP_NOT_ACTIVATED ) );
- //NAV subscribe
- lErr = SAMP(NAV_Subscribe)( NavCallback
- , ( NAV_ACTIVATED
- | NAV_NOT_ACTIVATED
- | NAV_STARTED
- | NAV_PAUSED
- | NAV_STOPPED
- | NAV_FINISHED
- | NAV_PROGRESS_INFO
- | NAV_MODE_CHANGE
- | NAV_WARNING
- | NAV_ERROR
- | NAV_CHANNELS_CONFIG) );
- //SAMP activate
- #ifdef SACD_AREA_INFO_INSDRAM
- lErr = SAMP(SAMP_Activate)(bDiscRecognized, NULL, NULL, (SAMP(Bool) *)&(SACD_GLOBALS.hybrid));
- #else
- lErr = SAMP(SAMP_Activate)(bDiscRecognized, SACD_GLOBALS.pAreaStereo, SACD_GLOBALS.pAreaMulti, (SAMP(Bool) *)&(SACD_GLOBALS.hybrid));
- #endif
- if(SAMP(ERR_OK) != lErr)
- tr_printf((" SACD_Nav: Fatal! SAMP_Activate failedn"));
- return lErr;
- }
- /*
- desc: kill SAMP.
- */
- static void Destructor(void)
- {
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SAMP(NAV_StateDef) stateDef;
- SAMP(NAV_GetState)(&stateDef);
- //todo: check with Philips jerry cai
- stateDef.PlayState = SAMP(NAV_PLAYING);
- // First make sure it is deactivated!
- switch (stateDef.PlayState)
- {
- case SAMP(NAV_PLAY_CALLED):
- case SAMP(NAV_PLAYING):
- case SAMP(NAV_PAUSE_CALLED):
- //todo: check with philips case SAMP(NAV_PAUSED):
- lErr |= SAMP(NAV_Stop)();
- // fall through
- case SAMP(NAV_STOP_CALLED):
- // fall through
- //todo: check with philips. case SAMP(NAV_STOPPED):
- case SAMP(NAV_ACTIVATING):
- lErr |= SAMP(NAV_Subscribe)( NavCallback, 0);
- // lErr |= SAMP(SAMP_Subscribe)( SampCallback, 0 );
- //sacd todo: check later.
- lErr |= SAMP(SAMP_Deactivate)();
- // fall through
- case SAMP(NAV_DEACTIVATED):
- case SAMP(NAV_NOT_ACTIVATED):
- {
- // Deactivated -> nothing to be done!
- }
- break;
- default:
- {
- tr_printf(("Warning: Nav_SACD_Desctructor: Unknown nav state"));
- }
- break;
- }
- DAC_SACD_SetMute(TRUE);
- //IIS is back to PCM mode. In this order noise is minimized during the transition.
- SAMP(BE_Term)();
- // <<< SEC shKang042304 : when power off, spindle has to be stopped by coremain
- if (g_power_state == POWER_SEQUENCE_OFF_REQUESTED)
- {
- tr_printf(("n auto spindown because of power off !!! n "));
- PE_SACD_AbortPlayback(0);
- }
- // SEC shKang042304 >>>
-
- #ifdef AUDIO_DAC_SUPPORT_DSD
- // DAC_Set_DSD_Mode(0); //back to pcm mode.
- #else
- lErr = SAMP(APM_SetInputMode)(SAMP(SACD_IN_PCM_44));
- lErr = SAMP(APM_SetOutputMode)(SAMP(APM_OUT_BPS), SAMP(APM_OUT_BPS));
- #endif
- lErr |= SAMP(SAMP_Term)();
- SACD_ISR_Uninstall();
- DAC_SACD_SetMute(FALSE);
- //set Furore chip to bypass mode.
- // FuroreSetExternalInputPCMMode();
- #ifndef SACD_AREA_INFO_INSDRAM
- sc_Free(SACD_GLOBALS.StereoAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
- sc_Free(SACD_GLOBALS.MultiAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4);
- #endif
- if(SAMP(ERR_OK) != lErr){
- tr_printf(("FATAL NAV_SACD: fail in destructor.n"));
- }
- }
- /*
- Desc: call back function for SAMP events.
- */
- static void SampCallback(SAMP(BitSet32) Event, void * EventData)
- {
- switch( Event )
- {
- case SAMP_ACTIVATED :
- DAC_Set_DSD_Mode(1); //todo: check later.
- g_disc_is_hybrid_sacd = SACD_GLOBALS.hybrid;
- SACD_GLOBALS.samp_state = SAMP_ACTIVATED;
- #ifdef SACD_AREA_INFO_INSDRAM
- //todo: update SACD_GLOBALS.activeArea
- if(Nav_SACD_Get_Num_Of_Tracks(SAMP(SACD_AREA_MULTICHANNEL)) > 0)
- SACD_GLOBALS.activeArea = SAMP(SACD_AREA_MULTICHANNEL);
- else
- SACD_GLOBALS.activeArea = SAMP(SACD_AREA_STEREO);
- #else
- SaveSACDAreaInfo(SACD_GLOBALS.pAreaStereo, SACD_GLOBALS.pAreaMulti);
- if(SACD_GLOBALS.pAreaMulti->NumberOfTracks > 0)
- SACD_GLOBALS.activeArea = SAMP(SACD_AREA_MULTICHANNEL);
- else
- SACD_GLOBALS.activeArea = SAMP(SACD_AREA_STEREO);
- if(NULL != SACD_GLOBALS.pAreaStereo)
- {
- free(SACD_GLOBALS.pAreaStereo);
- SACD_GLOBALS.pAreaStereo = NULL;
- }
- if(NULL != SACD_GLOBALS.pAreaMulti)
- {
- free(SACD_GLOBALS.pAreaMulti);
- SACD_GLOBALS.pAreaMulti = NULL;
- }
- #endif
- break;
- case SAMP_NOT_ACTIVATED:
- SACD_GLOBALS.samp_state = SAMP_NOT_ACTIVATED;
- ie_send(IE_CORE_SACD_IDENTIFICATION_FAILED);
- break;
- default:
- tr_printf(( "Unknown SAMP event received" ));
- break;
- }
- }
- //extern int track_playing;//jerry todo: remove later.
- /*
- Desc: callback function for NAV events.
- */
- static void NavCallback(SAMP(BitSet32) Event, void * EventData)
- {
- SAMP(ErrCode) lErr = SAMP(ERR_OK);
- SACD_GLOBALS.nav_state = Event;
- switch( Event )
- {
- case NAV_ACTIVATED:
- #if 1 //jerry cai //todo: check later.
- gcs.mstate = MST_DISC_READY; //UI will detect this state change then open SACD menu and issue restart.
- #endif
- gcs.pstate= PST_STOP;
- CLEAR_COP_MASK(0xFFFFFFFFL);
- SET_COP_MASK(COP_RESTART|COP_PLAY|COP_TIME_PLAY|COP_SEAMLESS_MODE_CHANGE);//scan is not allowed by SAMP yet.
- // DAC_SACD_SetMute(FALSE);
- ie_send(IE_CORE_SAMP_NAV_ACTIVATED);
- break;
- case NAV_NOT_ACTIVATED:
- gcs.pstate= PST_STOP;
- CLEAR_COP_MASK(0xFFFFFFFFL);
- SET_COP_MASK(COP_EJECT|COP_SETUP);
- break;
- case NAV_STARTED:
- // track_playing = 1; //jerry todo: remove later.
- #if 0 //jerry cai //todo: check later.
- gcs.mstate = MST_DISC_READY; //UI will detect this state change then open SACD menu and issue restart.
- #endif
- CLEAR_COP_MASK(COP_PLAY);
- SET_COP_MASK(COP_STOP|COP_PAUSE|COP_SCAN|COP_SCAN_BACKWARD|COP_NEXT_CHAPTER|
- COP_PREVIOUS_CHAPTER|COP_REVERSE_PLAY|COP_ABREPEAT);
- gcs.pstate= PST_PLAY;
- {
- SACD_GLOBALS.play_speed = *((SAMP(Int16) *) EventData);
- if(1 != SACD_GLOBALS.play_speed)
- {
- gcs.pstate= PST_SCAN; //either forward or backward
- SET_COP_MASK(COP_PLAY); //for SAMP, play command will resume normal speed playback.
- }
- }
- break;
- case NAV_PAUSED:
- CLEAR_COP_MASK(COP_PAUSE);
- SET_COP_MASK(COP_PLAY); //scan, next/prev is allowed in pause state.
- gcs.pstate= PST_PAUSE;
- break;
- case NAV_STOPPED:
- //Does it mean the whole play list has been finished?
- case NAV_FINISHED:
- CLEAR_COP_MASK(COP_STOP|COP_PAUSE|COP_SCAN|COP_SCAN_BACKWARD|COP_NEXT_CHAPTER|
- COP_PREVIOUS_CHAPTER|COP_REVERSE_PLAY|COP_ABREPEAT); //time play is allowed
- SET_COP_MASK(COP_PLAY);
- gcs.pstate= PST_STOP;
- // <<< SEC shKang042204 : after finishing the total track, has to be a full stop status.
- #ifdef EXINO2
- g_in_full_stop = TRUE;
- #endif // EXINO2
- // SEC shKang042204 >>>
- break;
- case NAV_PROGRESS_INFO:
- {
- SAMP(NAV_ProgressInfoDef) *info = (SAMP(NAV_ProgressInfoDef) *) EventData;
- SACD_GLOBALS.iCurrentTime = info->rel_time.min*60 + info->rel_time.sec;
- #ifdef SACD_DO_NOT_DISPLAY_COUNT_DOWN_IN_PAUSE_AREA
- if(0 == info->index)
- SACD_GLOBALS.iCurrentTime = 0;
- #endif
- SACD_GLOBALS.iCurrentAbsTime = info->abs_time.min*60 + info->abs_time.sec;
- ie_send(IE_UI_TIME_UPDATE);
- if(SACD_GLOBALS.currentTrack != info->track)
- ie_send(IE_UI_TRACK_UPDATE);
- SACD_GLOBALS.currentTrack = info->track;
- SACD_GLOBALS.currentIndex = info->index;
- }
- break;
- case NAV_MODE_CHANGE:
- {
- SAMP(NAV_ModeChangeDef) mode = *(SAMP(NAV_ModeChangeDef) *) EventData;
- if(mode.reshuffled)
- {
- dbg_printf(("SAMP reshuffled"));
- }
- if(mode.repeat_ab_canceled)
- PM_SetRepeatAB(0);
- }
- break;
- case NAV_WARNING:
- {
- SAMP(NAV_WarningCodeDef) warningCode = *(SAMP(NAV_WarningCodeDef) *) EventData;
- dbg_printf(("SAMP EventWarning: 0x%lx ", warningCode));
- }
- break;
- case NAV_ERROR:
- {
- SAMP(NAV_ErrorCodeDef) errorCode = *(SAMP(NAV_ErrorCodeDef) *) EventData;
- dbg_printf(("SAMP Eventerror: 0x%lx ", errorCode));
- }
- break;
- case NAV_CHANNELS_CONFIG:
- {
- SACD_GLOBALS.channels = *((SAMP(SACD_ChannelsConfigDef) *)EventData);
- }
- break;
- default:
- dbg_printf(("SAMP Unkown Event"));
- break;
- }
- }
- /*TODO: ask Philips to put the info directly in Scratch pad*/
- #ifndef SACD_AREA_INFO_INSDRAM
- static void SaveSACDAreaInfo(SAMP(SAMP_AreaInfoDef) *stereo,SAMP(SAMP_AreaInfoDef) *multi)
- {
- sc_Write(SACD_GLOBALS.StereoAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4, (const Sc_cont *)stereo);
- sc_Write(SACD_GLOBALS.MultiAreaInfoPtr, (sizeof(SAMP(SAMP_AreaInfoDef)) + 3)/4, (const Sc_cont *)multi);
- }
- #endif
- UINT16 Nav_SACD_Get_Track_Start_Time(UINT16 trackNo)
- {
- #ifdef SACD_AREA_INFO_INSDRAM
- DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SDRAM_MULTICH_AREA_INFO_BASE :
- SDRAM_2CH_AREA_INFO_BASE;
- #else
- WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SACD_GLOBALS.MultiAreaInfoPtr :
- SACD_GLOBALS.StereoAreaInfoPtr;
- #endif
- WORD i_hAddress;
- char buff[8];
- UINT16 startTime;
- BYTE offset;
- if(trackNo == 0) // track starts from 1.
- return 0;
- trackNo --;
- #ifdef SACD_AREA_INFO_INSDRAM
- sc_GetBytes32(areaStartAddr, TRACK_START_INFO_LOCATION(trackNo), 2, buff);
- startTime = buff[0]*60 + buff[1];
- #else
- offset = TRACK_START_INFO_LOCATION(trackNo)%4;
- i_hAddress = areaStartAddr + TRACK_START_INFO_LOCATION(trackNo)/4;
- sc_Read(i_hAddress, 2, (Sc_cont *)buff);
- startTime = buff[offset]*60 + buff[offset + 1];
- #endif
- return startTime;
- }
- /*
- Desc: Get the length of a track. The information is retrieved from scratch pad.
- */
- UINT16 Nav_SACD_Get_Track_Length(UINT16 trackNo)
- {
- #ifdef SACD_AREA_INFO_INSDRAM
- DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SDRAM_MULTICH_AREA_INFO_BASE :
- SDRAM_2CH_AREA_INFO_BASE;
- #else
- WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == SACD_ACTIVE_AREA)? SACD_GLOBALS.MultiAreaInfoPtr :
- SACD_GLOBALS.StereoAreaInfoPtr;
- #endif
- WORD i_hAddress;
- char buff[8];
- UINT16 time;
- BYTE offset;
- if(trackNo == 0) // track starts from 1.
- return 0;
- #if 0
- startTime = Nav_SACD_Get_Track_Start_Time(trackNo);
- if(trackNo == Nav_SACD_Get_Num_Of_Tracks(SACD_ACTIVE_AREA))
- endTime = Nav_SACD_Get_Total_Time(SACD_ACTIVE_AREA);
- else
- endTime = Nav_SACD_Get_Track_Start_Time(trackNo+1);
- return endTime - startTime;
- #endif
- trackNo --;
- #ifdef SACD_AREA_INFO_INSDRAM
- sc_GetBytes32(areaStartAddr, 5 + Nav_SACD_Get_Num_Of_Tracks(SACD_ACTIVE_AREA)*3 + trackNo*3, 2, buff);
- time = buff[0]*60 + buff[1];
- #else
- offset = TRACK_LEN_INFO_LOCATION(trackNo)%4;
- i_hAddress = areaStartAddr + TRACK_LEN_INFO_LOCATION(trackNo)/4;
- sc_Read(i_hAddress, 2, (Sc_cont *)buff);
- time = buff[offset]*60 + buff[offset + 1];
- #endif
- return time;
- }
- /*
- Desc: get number of tracks in an area.
- */
- UINT16 Nav_SACD_Get_Num_Of_Tracks(SAMP(SACD_Area) area)
- {
- char buff[4];
- UINT16 res;
- #ifdef SACD_AREA_INFO_INSDRAM
- DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SDRAM_MULTICH_AREA_INFO_BASE :
- SDRAM_2CH_AREA_INFO_BASE;
- #else
- WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SACD_GLOBALS.MultiAreaInfoPtr :
- SACD_GLOBALS.StereoAreaInfoPtr;
- #endif
- #ifdef SACD_AREA_INFO_INSDRAM
- sc_GetBytes32(areaStartAddr, 0, 4, buff);
- #else
- sc_Read(areaStartAddr, 1, (Sc_cont *)buff);
- #endif
- res = (UINT16)buff[0];
- res &= 0xff; //todo: check with Philips.
- return res;
- }
- UINT16 Nav_SACD_Get_Total_Time(SAMP(SACD_Area) area)
- {
- char buff[2];
- UINT16 res;
- #ifdef SACD_AREA_INFO_INSDRAM
- DWORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SDRAM_MULTICH_AREA_INFO_BASE :
- SDRAM_2CH_AREA_INFO_BASE;
- #else
- WORD areaStartAddr = (SAMP(SACD_AREA_MULTICHANNEL) == area)? SACD_GLOBALS.MultiAreaInfoPtr :
- SACD_GLOBALS.StereoAreaInfoPtr;
- #endif
- #ifdef SACD_AREA_INFO_INSDRAM
- sc_GetBytes32(areaStartAddr, 2, 2, buff); //tod: was 4 check with Philips.
- #else
- sc_GetBytes(areaStartAddr, 4, 2, buff);
- #endif
- res = (UINT16)buff[0]*60 + buff[1];
- return res;
- }
- #endif // D_SUPPORT_SACD