Karaoke.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:7k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: Karaoke.c $
- *
- * Description: Interface for creating and manipulating a generic Array.
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 10 $
- * Last Modified by $Author: Chaol $ at $Modtime: 04-03-10 16:53 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/Karaoke/Karaoke.c $
- *
- * 10 04-03-10 16:53 Chaol
- * clean karaoke code
- *
- * 9 04-02-19 15:05 Chaol
- * change DEC_SET_MICROPHONE_ON_OFF
- *
- * 8 2/10/04 11:16p Lotan
- * fix compilation bug
- *
- * 7 2/10/04 7:46p Chaol
- * add karaoke support
- *
- * 6 03-03-20 10:04 Hannahh
- * close the switch "EXTERNAL_KARAOKE"
- *
- * 6 23/04/02 9:30 Nirm
- * - Added dependency in "Config.h".
- *
- * 5 18/02/02 10:59 Atai
- * make global to static
- *
- * 4 16/01/02 8:59 Nirm
- * Changed included header.
- *
- * 3 13/01/02 16:28 Atai
- * Remove old Defines
- *
- * 2 9/01/02 15:24 Nirm
- * Corrected Include-Paths.
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #if (defined(INTERNAL_KARAOKE) || defined(EXTERNAL_KARAOKE) )
- #ifndef D_KEYSHIFT_SINGLE_KEY
- #ifdef _DEBUG
- #define IFTRACE if (gTraceCore)
- #include "DebugDbgMain.h"
- #endif
- #include "Includesysdefs.h"
- #include "Kernelker_api.h"
- #include "KernelEventDef.h"
- #include "Decoderdecoder.h"
- #include "PlaycoreCoremaincoregdef.h"
- #include "PlaycoreKaraokeio_kar.h"
- #include "PlaycoreKaraokeKaraoke.h"
- #include "PlaycorePSps.h"
- /* Vocal Partner is being process if = 1 */
- static int g_VPInProcess = 0;
- static BOOL gb_VoiceDetected = FALSE;
- static BOOL b_last_VoiceDetected = FALSE;
- #ifdef EXTERNAL_KARAOKE
- extern BYTE gc_Karaoke_mode;
- #endif
- #define COUNTER_TO_DEACTIVATE_4EXTERN 80 //Nbr of samples before deactivation of VP
- #define COUNTER_TO_ACTIVATE_4EXTERN 1 //Nbr of samples before activation of VP
- #define COUNTER_TO_DEACTIVATE 200 //Nbr of samples before deactivation of VP
- #define COUNTER_TO_ACTIVATE 10 //Nbr of samples before activation of VP
- #ifdef EXTERNAL_KARAOKE
- #define GET_COUNTER_TO_DEACTIVATE COUNTER_TO_DEACTIVATE_4EXTERN
- #define GET_COUNTER_TO_ACTIVATE COUNTER_TO_ACTIVATE_4EXTERN
- #else
- #define GET_COUNTER_TO_DEACTIVATE COUNTER_TO_DEACTIVATE
- #define GET_COUNTER_TO_ACTIVATE COUNTER_TO_ACTIVATE
- #endif
- /**************************************************************************
- *
- * Function : karSetVocalPartner
- *
- * In : void
- * Out : void
- *
- * Return : void
- *
- * Desc : Manage the activation of the partner function by counting the
- * nbr of sample detection in a short time.
- * This function is called every VSYNC by callback if the karaoke
- * functionalities are activated.
- *
- ***************************************************************************/
- void karSetVocalPartner(void)
- {
- static int cCnt = 0;
- DWORD dCmd;
- /* We assume this function is call for VSYNC, it means every 16 or 20ms (sample)
- depending on video PAL or NTSC. The goal is to activate quickly the VP in case
- the singer starts singing, but we prefer to wait for a while before deactivation
- in case, the singer take only a breath and doesn't really stop singing
- */
- if (TRUE == gb_VoiceDetected)
- {
- if ((VP_DEACTIVATED == gcst.mPartner)&&(PARTNER_SETTING_OFF != gtps.mPartner))
- {
- if (cCnt < GET_COUNTER_TO_ACTIVATE)
- {
- cCnt++;
- }
- else
- {
-
- #ifdef EXTERNAL_KARAOKE
- if(KARAOKE_OFF == gc_Karaoke_mode)
- {
- return;
- }
-
- DEC_SET_MICROPHONE_ON_OFF(MICROPHONE_ON);
- #endif
- dCmd = (((DWORD)PS_UPDATE_PARTNER_STATE)<<16) + (DWORD)VP_ACTIVATED;
- k_ie_send_ex(IE_CORE_UPDATE_PS, (void *)dCmd);
- cCnt=0;
- }
- }
- #ifdef EXTERNAL_KARAOKE
- else if ((KARAOKE_AUTO == gc_Karaoke_mode) && (PARTNER_SETTING_OFF == gtps.mPartner) )
- {
- if(FALSE == b_last_VoiceDetected)
- {
- b_last_VoiceDetected = TRUE;
- cCnt=0;
- }
- else
- {
- if (cCnt < GET_COUNTER_TO_ACTIVATE)
- cCnt++;
- else if(0xFFFF != cCnt)
- {
- cCnt=0xFFFF;
- DEC_SET_MICROPHONE_ON_OFF(MICROPHONE_ON);
- b_last_VoiceDetected = TRUE;
- }
- }
- }
- #endif //EXTERNAL_KARAOKE
- else
- {
- cCnt=0;
- }
- }
- else
- {
- if ((VP_ACTIVATED == gcst.mPartner) && (PARTNER_SETTING_OFF != gtps.mPartner))
- {
- if (cCnt < GET_COUNTER_TO_DEACTIVATE)
- cCnt++;
- else
- {
- #ifdef EXTERNAL_KARAOKE
- if(KARAOKE_OFF == gc_Karaoke_mode)
- {
- return;
- }
- DEC_SET_MICROPHONE_ON_OFF(MICROPHONE_OFF);
- #endif
- dCmd = (((DWORD)PS_UPDATE_PARTNER_STATE)<<16) + (DWORD)VP_DEACTIVATED;
- k_ie_send_ex(IE_CORE_UPDATE_PS, (void *)dCmd);
- cCnt=0;
- }
- }
- #ifdef EXTERNAL_KARAOKE
- else if((KARAOKE_AUTO == gc_Karaoke_mode) && (PARTNER_SETTING_OFF == gtps.mPartner))
- {
- if(b_last_VoiceDetected == TRUE)
- {
- b_last_VoiceDetected = FALSE;
- cCnt=0;
- }
-
- if (cCnt < GET_COUNTER_TO_DEACTIVATE)
- cCnt++;
- else if(0xFFFF != cCnt)
- {
- cCnt=0xFFFF;
- b_last_VoiceDetected = FALSE;
- DEC_SET_MICROPHONE_ON_OFF(MICROPHONE_OFF);
- }
- }
- #endif
- else
- {
- cCnt=0;
- }
- }
- /* Reset this variable for the next callback of this function */
- g_VPInProcess = 0;
- }
- /**************************************************************************
- *
- * Function : karVocalDetection
- *
- * In : void
- * Out : void
- *
- * Return : FALSE if karaoke and partner are inactive
- * TRUE if active
- *
- * Desc : Manage the voice detection, check the VD input only if karaoke
- * functions are activated
- *
- ***************************************************************************/
- int karVocalDetection(void)
- {
- int iResult = FALSE;
- #ifdef EXTERNAL_KARAOKE
- if(IS_KARAOKE_ON && (PARTNER_SETTING_ON == gtps.mPartner))
- {
- gb_VoiceDetected = ioVocalDetection();
- iResult = TRUE;
- }
- #endif
- return iResult;
- }
- /**************************************************************************
- *
- * Function : karKaraokeInit
- *
- * In : void
- * Out : void
- *
- * Return : void
- *
- * Desc : Set the vocal detection, Install the callback function for VD
- * If the 'karVocalDetection' is TRUE, call the 'karSetVocalPartner' to
- * deal with the Vocal Partner, and set 'g_VPInProgress' to 1.
- * 'g_VPInProgress' must be reset before the callback could be recalled.
- *
- ***************************************************************************/
- void karKaraokeInit(void)
- {
- /* Install the callback function for Vocal Detection and Set */
- DEC_install_fast_callback(karVocalDetection, karSetVocalPartner, &g_VPInProcess);
- }
- #endif
- #endif