/* ========================================================================= */ void AFE_Chip_Event_Handler( void *data ) { kal_int16 v_lowest, a_lowest; #if ( defined( __CENTRALIZED_SLEEP_MANAGER__ )&& defined( MTK_SLEEP_ENABLE )) //Be careful.Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag // because the event will happen whenever AP call related function L1Audio_SetFlag( afe.aud_id ); #endif SearchPathWorkingFlag(&v_lowest, &a_lowest); _digitOnly_update_digital_gain(v_lowest, a_lowest); // mic digital gain related /* no hw mute exit, so remove it if(afe.mic_mute){ // AM_DSP_SetSpeechUplinkSwAgcGain(); AM_DSP_SetSpeechUplinkDigitalGain(0); }else { */ if(AM_IsBluetoothOn()) { // for the case of bluetooth use AM_DSP_SetSpeechUplinkSwAgcGain(0); // make agc gain as 0 under bt mode } else { AM_DSP_SetSpeechUplinkSwAgcGain(afe.digitOnly_mic_volume); } /* } */ #if ( defined( __CENTRALIZED_SLEEP_MANAGER__ )&& defined( MTK_SLEEP_ENABLE )) L1Audio_ClearFlag( afe.aud_id ); #endif }
void Del_PcmEx_Start(void (*pcmNway_dl_hdlr)(void), void (*pcmNway_ul_hdlr)(void), uint32 cfgUL1, uint32 cfgUL2, uint32 cfgUL3, uint32 cfgUL4, uint32 cfgDL) { uint32 I; kal_bool flag; // prevent re-entry!! ASSERT(PNW_STATE_IDLE == pcmEx.state); pcmEx.aud_id = L1Audio_GetAudioID(); L1Audio_SetFlag( pcmEx.aud_id ); /*Be careful.Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag*/ // band and am type setting pcmEx.bandInfo = PCMEX_BAND_DYNAMIC; pcmEx.am_type = AM_PCMEX_TYPE_DEDICATION; // pcmEx.dspPcmExMicLen = 0; // pcmEx.dspPcmExSpkLen = 0; pcmEx.cfgUL1 = cfgUL1; pcmEx.cfgUL2 = cfgUL2; pcmEx.cfgUL3 = cfgUL3; pcmEx.cfgUL4 = cfgUL4; pcmEx.cfgDL = cfgDL; pcmEx.pnw_dl_hdlr = pcmNway_dl_hdlr; pcmEx.pnw_ul_hdlr = pcmNway_ul_hdlr; L1Audio_HookHisrHandler(DP_D2C_PCM_EX_DL,(L1Audio_EventHandler)pcmEx_hisrDlHdlr, 0); L1Audio_HookHisrHandler(DP_D2C_PCM_EX_UL,(L1Audio_EventHandler)pcmEx_hisrUlHdlr, 0); // check DSP state and turn on ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) && SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF)); AM_PCM_EX_On(pcmEx.am_type, (uint32)(&pcmEx));//to config pnw SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); // wait for ready for(I = 0; ;I ++){ kal_bool is_ready = true; if( (pcmEx.cfgDL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if( (pcmEx.cfgUL1 & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if(is_ready) break; #ifndef L1D_TEST ASSERT(I < 22); // wait 200ms kal_sleep_task(2); #endif } pcmEx.state = PNW_STATE_RUN; /* the end of configure the SAL */ }
static void dtmf_mcu_Init(kal_uint16 uSampleRate) { kal_uint32 uIntBufSize=0, uPcmBufSize=0, uTotalBufferSize=0; kal_uint8 *pAllocBuf; DTMF_SR uSr=0; memset(&DTMF_SW, 0, sizeof(DTMF_SW)); DTMF_SW.uSampleRate = uSampleRate; switch (DTMF_SW.uSampleRate) { case 8000: uSr = DTMF_8K; break; case 11025: uSr = DTMF_11K; break; case 12000: uSr = DTMF_12K; break; case 16000: uSr = DTMF_16K; break; case 22050: uSr = DTMF_22K; break; case 24000: uSr = DTMF_24K; break; case 32000: uSr = DTMF_32K; break; case 44100: uSr = DTMF_44K; break; case 48000: uSr = DTMF_48K; break; default: ASSERT(0); break; } DTMF_GetBufferSize(&uIntBufSize, &uPcmBufSize, uSr, DTMF_MONO); uTotalBufferSize = uIntBufSize + uPcmBufSize * DTMF_BUFFERED_FRAME_NUMBER; kal_trace( TRACE_GROUP_AUD_PLAYBACK, MCU_DTMF_INIT, uSampleRate, uPcmBufSize, uTotalBufferSize); pAllocBuf = (kal_uint8 *)audio_alloc_mem(uTotalBufferSize); ASSERT(pAllocBuf); ASSERT(uIntBufSize); ASSERT(uPcmBufSize); DTMF_SW.uFrameByte = uPcmBufSize; DTMF_SW.RingBuffer.rb_base = (kal_uint8*)pAllocBuf; DTMF_SW.RingBuffer.rb_size = uPcmBufSize * DTMF_BUFFERED_FRAME_NUMBER; DTMF_SW.RingBuffer.write = uPcmBufSize * uPreSilenceLength; //fill a silence to prevent pop up noise DTMF_SW.RingBuffer.read=0; pAllocBuf += uPcmBufSize * DTMF_BUFFERED_FRAME_NUMBER; DTMF_SW.pHandle = DTMF_Init( (void *)pAllocBuf, DTMF_CONTINUOUS, uSr, DTMF_MONO); ASSERT(DTMF_SW.pHandle); DTMF_SW.uAudId = L1Audio_GetAudioID(); L1Audio_SetFlag( DTMF_SW.uAudId ); L1Audio_SetEventHandler( DTMF_SW.uAudId, dtmf_mcu_Process ); }
uint32 EXT_BGSND_Start(void (*offHdr)(void), void (*DLHisr)(void), //move data from src -> ext void (*ULHisr)(void), //move data from src -> ext kal_int8 DLSNDGain, kal_int8 ULSNDGain /*, void (*EventHandler)(void)*/) { int i, j; kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] Enter"); ASSERT(!(NULL==DLHisr && NULL==ULHisr)); ASSERT(NULL!=offHdr); //without this, we cannot stop DSP BGSND for(i=0; i<MAX_SIZE_EXT_BGSND_SRC; i++){ kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug1 i=%d", i); if(!Ext_BGSnd.is_used[i]){ kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug2 i=%d", i); EXT_BGSND_SRC_T *pSrc = &Ext_BGSnd.src[i]; pSrc->Hdr[BGSND_DL_PROCESS] = DLHisr; pSrc->Hdr[BGSND_UL_PROCESS] = ULHisr; pSrc->offHdr = offHdr; for(j=0; j<MAX_NUM_BGSND_PROCESS; j++){//TODO temp solution pSrc->state[j] = EXT_SRC_STATE_RUN; //pSrc->fSph[j] = true; //TODO //pSrc->gain[j] = 7; //TODO // buffer reset memset(pSrc->buffer[j], 0, sizeof(kal_uint16)*EXT_BGSND_SRC_BUF_SIZE); pSrc->bufSize[j] = EXT_BGSND_SRC_BUF_SIZE; pSrc->bufRead[j] = 0; pSrc->bufWrite[j] = EXT_BGSND_BUF_PTR_DIFF; } if(AM_IsSpeechOn() || AM_IsVoIPOn()){ EXT_BGSND_ConfigMixer(i, true, DLSNDGain, BGSND_DL_PROCESS); EXT_BGSND_ConfigMixer(i, true, ULSNDGain, BGSND_UL_PROCESS); }else{ EXT_BGSND_ConfigMixer(i, false, DLSNDGain, BGSND_DL_PROCESS); EXT_BGSND_ConfigMixer(i, false, ULSNDGain, BGSND_UL_PROCESS); } Ext_BGSnd.is_used[i] = true; if( 0 == Ext_BGSnd.num_src_used++){ kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] selected_src_id=%d num_src_used=%d", i, Ext_BGSnd.num_src_used); // lock DSP for sherif writing. L1Audio_SetFlag( Ext_BGSnd.aud_id ); // REIMIND: Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag1 DSP_BGSND_Start(EXT_BGSND_DLHisr, EXT_BGSND_ULHisr); } kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug3 i=%d", i); break; } kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug4 i=%d", i); } kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug5 i=%d", i); ASSERT(i < MAX_SIZE_EXT_BGSND_SRC); kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] Leave"); return i; }
/** The function starts the background sound playback of the media handle. @bgSnd_hdlr: handler @ULGainLevel: uplink gain level, from 0~7 @DLGainLevel: downlink gain level, from 0~7 */ void BGSND_Start(void (*bgSnd_hisrHandler)(void), void (*bgSnd_offHandler)(void), kal_uint8 ULGainLevel , kal_uint8 DLGainLevel) { kal_trace( TRACE_FUNC, L1SND_ENTER_BGSND_START ); // clean up bgSnd.dspLastSample = 0; bgSnd.endCount = 0; // buffer reset memset(bgSndBuf, 0, sizeof(kal_uint16)*BGSND_BUF_SIZE); bgSnd.pBuf = bgSndBuf; bgSnd.bufSize = BGSND_BUF_SIZE; bgSnd.bufRead = 0; bgSnd.bufWrite = BGSND_BUF_PTR_DIFF; // clear hisr flag bgSnd.isDlHisrCome = false; bgSnd.isUlHisrCome = false; // lock DSP for sherif writing. L1Audio_SetFlag( bgSnd.aud_id ); // REIMIND: Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag1 // L1Audio_SetEventHandler(bgSnd.aud_id, BGSND_eventHandler ); bgSnd.bgSnd_hisrHandler = bgSnd_hisrHandler; #ifdef DSP_BGS_UP_DOWN_INT_SEPERATE L1Audio_HookHisrHandler(D2C_SOUND_EFFECT_INT_ID_DL, bgsndDlHisr, 0); L1Audio_HookHisrHandler(D2C_SOUND_EFFECT_INT_ID_UL, bgsndUlHisr, 0); #else L1Audio_HookHisrHandler(D2C_SOUND_EFFECT_INT_ID_DL, bgsndHisr, 0); #endif bgSnd.bgSnd_offHandler = bgSnd_offHandler; // gain setting and update if(AM_IsSpeechOn()){ BGSND_ConfigULMixer(KAL_TRUE, ULGainLevel); BGSND_ConfigDLMixer(KAL_TRUE, DLGainLevel); } else { BGSND_ConfigULMixer(KAL_FALSE, ULGainLevel); BGSND_ConfigDLMixer(KAL_FALSE, DLGainLevel); } bgsndUpdateMixer(); // Before dynamic download, all application should be off. // But background sound do not need to dynamic download, so the following is unnecessary. // KT_StopAndWait(); // turn on. bgsndOnHandler(); // L1SP_Register_BgsService(bgsndOnHandler, bgsndOffHandler); bgSnd.state = BGSND_STATE_RUN; }
void AVB_Open() { kal_uint32 uWorkingBuffer; kal_trace( TRACE_GROUP_SCO, L1AUDIO_AVB_OPEN, AVB.uState); ASSERT(AVB.uState == AVB_STATE_IDLE); ASSERT(AVB.uSampleRate); PcmSink_StartBT(PCMSINK_BT_SCO); mhdlHookPcmRut(); BLI_GetMemSize(AVB.uSampleRate, AVB.uChannelNumber, AVB_SAMPLE_RATE, AVB_CHANNEL_NUM, &uWorkingBuffer); uWorkingBuffer = (uWorkingBuffer+3) & ~3; AVB.pBuffer = (kal_uint16 *)audio_alloc_mem_cacheable(uWorkingBuffer + AVB_DSP_BUFFER_SIZE + AVB_SRC_BUFFER_SIZE); ASSERT(AVB.pBuffer); AVB.pBLISRC = BLI_Open(AVB.uSampleRate, AVB.uChannelNumber, AVB_SAMPLE_RATE, AVB_CHANNEL_NUM, ((kal_int8*)AVB.pBuffer)+AVB_DSP_BUFFER_SIZE, audio_alloc_ext_mem_cacheable_simplified); ASSERT(AVB.pBLISRC); AVB.PCM.rb_base = ((kal_int8*)AVB.pBuffer)+AVB_DSP_BUFFER_SIZE+uWorkingBuffer; AVB.PCM.rb_size = AVB_SRC_BUFFER_SIZE; AVB.PCM.write = 0; AVB.PCM.read = 0; AVB.uAudID = L1Audio_GetAudioID(); L1Audio_SetFlag( AVB.uAudID ); L1Audio_SetEventHandler( AVB.uAudID, AVB_Process ); AVB.uState = AVB_STATE_RUNING; L1Audio_HookHisrHandler( D2C_AUDIO_VIA_8KBT_ID, AVB_HISR, 0); }
/***************************************************************************** * FUNCTION * TONE_Play * DESCRIPTION * This function is used to play comfort tones. * * PARAMETERS * tonelist - Tone list * RETURNS * None. * GLOBALS AFFECTED * None *****************************************************************************/ void TONE_Play( const L1SP_Tones *tonelist ) { if( L1Audio_CheckFlag( tone.aud_id ) ) return; if (tone.state != TONE_STATE_NONE) return; if( L1Audio_CheckFlag( keytone.aud_id ) ) { KT_StopAndWait(); } L1Audio_SetFlag( tone.aud_id ); tone.tonelist = tonelist; tone.fc_aud_id = L1Audio_FC_HookHandler( (void *)0, toneMsgHandler, 0, (FC_MEDIA_FORMAT_QTMF<<8)|MEDIA_OPERATE_PLAYBACK ); tone.state = TONE_STATE_IDLE; tone.isReentrance = false; tone.seqNum++; tonePlayOn( 0 ); AM_ToneOn(); }
Media_Status I2S_Open( void ){ #ifdef __I2S_UNIT_TEST__ kal_uint16 sr = Media_I2S_INPUT_MODE_SR_UT; #else kal_uint16 sr = Media_I2S_INPUT_MODE_SR; #endif #if defined(MT6256) || defined(MT6255) || defined(MT6250) || defined(MT6260) #if defined(__INTERAL_FM_VIA_I2S__) kal_uint8 isspkmute = 0; #endif #endif #if defined(__VIBRATION_SPEAKER_SUPPORT__) VIBR_Vibration_Deactivate(); #endif PcmSink_TerminateSound(); #if defined(__AUDIO_COMPONENT_SUPPORT__) Media_SetIsDSPDec(KAL_TRUE); // to bypass sink component #endif kal_trace( TRACE_FUNC, L1AUDIO_I2S_ENABLE, ASP_TYPE_I2SBypass, sr ); ASSERT( sr == 32000 || sr == 44100 || sr == 48000 ); ASSERT( I2S_RECORD_STATE_CLOSED == i2s.state); i2s.is_ON = KAL_TRUE; i2s.state = I2S_RECORD_STATE_INIT; i2s.sample_rate = sr; i2s.aud_id = L1Audio_GetAudioID(); #if defined(__BES_LOUDNESS_ON_I2S__) AudioPP_Loudness_Registry(); #endif #if defined(__AUDIO_DSP_LOWPOWER_V2__) #if defined(MT6256) || defined(MT6255) if (!APM_IsLoudnessOn()) #endif #if !(defined(MT6260) && defined(INTERNAL_ANTENNAL_SUPPORT)) AUDLP_Mode(KAL_TRUE, 1); #endif if(AUDLP_Check_LowPower_Status()) { L1Audio_SetFlag_MD2G( i2s.aud_id ); #if defined(MT6250) || defined(MT6260) AUDLP_Set_ClkSwitchMode(KAL_TRUE); AUDLP_SW_Trigger_Event_Setting(KAL_TRUE); AUDLP_SetClkSwitch_26M(KAL_TRUE); #endif } else L1Audio_SetFlag( i2s.aud_id ); #else L1Audio_SetFlag( i2s.aud_id ); #endif ktLock(); KT_StopAndWait(); TONE_StopAndWait(); AM_Force_VBI_END_IN_TASK(); Media_SetSampleRate(sr); Media_SetAudioFormat(MEDIA_FORMAT_UNKNOWN); *DSP_AUDIO_CTRL2 |= DP_PCM_R_DIS; *DSP_AUDIO_FLEXI_CTRL |= (FLEXI_VBI_ENABLE | FLEXI_SD_ENABLE); #if defined(MT6250) || defined(MT6260) *I2S_PLAYERROR_INFO = 0; *I2S_PLAYERROR_CONTROL = 0; #endif #if !defined(__CACHED_BASE_DSP__) DSP_DynamicDownload ( DDID_I2S ); #endif //should add a parameter to indicate input or output AFE_TurnOnEDI( 1, 1, L1SP_I2S_INPUT_SCALE >> 1 ); #if defined(__AUDIO_COMPONENT_SUPPORT__) i2s_sample_rate = i2s.sample_rate; ASSERT(i2s.ihdl==NULL); AudioRoute2Drain_Init(&i2s.ihdl, 0); AudioRoute2Drain_Start(i2s.ihdl); #endif //should not turn on output mode and input mode at the same time if( sr == 32000 ) sr = ASP_FS_32K; else if ( sr == 44100 ) sr = ASP_FS_44K; else sr = ASP_FS_48K; #if defined(MT6260) #if defined(__INTERAL_FM_VIA_I2S__) if(I2S_is_FM()) *HW_MISC_REG |=0x0001; #endif #endif #if defined(__INTERAL_FM_VIA_I2S__) if(!I2S_is_FM()) #endif I2S_Input_GPIO_TurnOn(); #if defined(MT6256) || defined(MT6255) || defined(MT6250) || defined(MT6260) #if defined(__INTERAL_FM_VIA_I2S__) if(!I2S_is_FM()) { if(!AFE_IsSpeakerMuted()) { AFE_MuteSpeaker(L1SP_AUDIO, KAL_TRUE); isspkmute = 1; } } #endif #endif #if defined(MT6250) L1Audio_HookHisrHandler(DP_D2C_I2S_REC_INT, I2S_DspIntHISR, 0); #endif #if defined(__AUDIO_COMPONENT_SUPPORT__) && !defined(MED_MODEM) PcmSink_DepopMute(400); //depop #endif AM_AudioPlaybackOn( ASP_TYPE_I2SBypass, sr ); #if defined(MT6256) || defined(MT6255) || defined(MT6250) || defined(MT6260) #if defined(__INTERAL_FM_VIA_I2S__) if(!I2S_is_FM()) { kal_sleep_task(45); if(isspkmute) AFE_MuteSpeaker(L1SP_AUDIO, KAL_FALSE); } #endif #endif return MEDIA_SUCCESS; }
void DACA_Start(void (*daca_dl_hdlr)(void), void (*daca_ul_hdlr)(void), DACA_APP_TYPE app_type) { uint32 I; //Sal_PCMEx_Config_t cfg_t; //cfg_t.idle = false;//initialized; dacaEx.aud_daca_id = L1Audio_GetAudioID(); L1Audio_SetFlag( dacaEx.aud_daca_id ); L1Audio_HookHisrHandler(DP_D2C_DACA_REQ_DL,(L1Audio_EventHandler)Daca_hisrDlHdlr, 0); L1Audio_HookHisrHandler(DP_D2C_DACA_REQ_UL,(L1Audio_EventHandler)Daca_hisrUlHdlr, 0); dacaEx.daca_dl_hdlr = daca_dl_hdlr; dacaEx.daca_ul_hdlr = daca_ul_hdlr; dacaEx.app_type = app_type; if(app_type & DACA_IN_PHONE_CALL){ dacaEx.am_type = AM_PCMEX_TYPE_DACA_DEDICATION; }else{ dacaEx.am_type = AM_PCMEX_TYPE_DACA_IDLE_WO_ENH; } if(app_type & DACA_USE_NB){ dacaEx.frame_size = 160;//PCMNWAY_BAND_INFO_NB; // cfg_t.band = SAL_PCM_NARROWBAND; }else{ dacaEx.frame_size = 320;//PCMNWAY_BAND_INFO_WB; // cfg_t.band = SAL_PCM_WIDEBAND; } /* the begining of configure the SAL */ if(app_type & DACA_USE_UL){ SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_DACA, SAL_PCMEX_ON); } if(app_type & DACA_USE_DL){ SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_DACA, SAL_PCMEX_ON); } //cfg_t.swi = SAL_PCMEX_SWITCH_ON; //cfg_t.type = SAL_PCMEX_TYPE_DACA; //cfg_t.band = (app_type & DACA_USE_NB) ? SAL_PCM_NARROWBAND : SAL_PCM_WIDEBAND; AM_PCM_EX_On(dacaEx.am_type, &dacaEx); for(dacaEx.state = DACA_STATE, I = 0; ;I ++){ kal_bool is_ready = true; if((dacaEx.app_type & DACA_USE_UL) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_DACA, SAL_PCMEX_RDY))) is_ready = false; if((dacaEx.app_type & DACA_USE_DL) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_DACA, SAL_PCMEX_RDY))) is_ready = false; if(is_ready) break; ASSERT(I < 22); // wait 200ms kal_sleep_task(2); } /* the end of configure the SAL */ }
/** @pcmNway_dl_hdlr @pcmNway_ul_hdlr: */ void Idle_PcmEx_Start(void (*pcmNway_dl_hdlr)(void), void (*pcmNway_ul_hdlr)(void), uint32 cfgUL1, uint32 cfgUL2, uint32 cfgUL3, uint32 cfgUL4, uint32 cfgDL, PCMEX_BAND band, PCMEX_IDLE_ENH_SETTING enhSetting) { uint32 I; kal_bool flag; // prevent re-entry!! ASSERT(PNW_STATE_IDLE == pcmEx.state); pcmEx.aud_id = L1Audio_GetAudioID(); L1Audio_SetFlag( pcmEx.aud_id ); /*Be careful.Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag*/ // band and am type setting pcmEx.bandInfo = band; switch(band){ case PCMEX_BAND_NB: { ASSERT(enhSetting != PCMEX_IDLE_ENH_SETTING_NONE); if(PCMEX_IDLE_ENH_SETTING_DMNR_REC_ONLY_CAL == enhSetting) { // pcmEx.dspPcmExMicLen = 322; //160*2+2 samples(word) // pcmEx.dspPcmExSpkLen = -1; pcmEx.am_type = AM_PCMEX_TYPE_REC_ONLY_CAL; } else if (PCMEX_IDLE_ENH_SETTING_DMNR_CAL == enhSetting) { // pcmEx.dspPcmExMicLen = 322; //160*2+2 samples(word) // pcmEx.dspPcmExSpkLen = 160; pcmEx.am_type = AM_PCMEX_TYPE_REC_PLAY_CAL; } else { // pcmEx.dspPcmExMicLen = 160; // pcmEx.dspPcmExSpkLen = 160; pcmEx.am_type = AM_PCMEX_TYPE_IDLE; } } break; case PCMEX_BAND_WB: { ASSERT(enhSetting != PCMEX_IDLE_ENH_SETTING_NONE); if(PCMEX_IDLE_ENH_SETTING_DMNR_REC_ONLY_CAL == enhSetting) { // pcmEx.dspPcmExMicLen = 642; //320*2+2 samples(word) // pcmEx.dspPcmExSpkLen = -1; pcmEx.am_type = AM_PCMEX_TYPE_REC_ONLY_CAL; } else if (PCMEX_IDLE_ENH_SETTING_DMNR_CAL == enhSetting) { // pcmEx.dspPcmExMicLen = 642; //320*2+2 samples(word) // pcmEx.dspPcmExSpkLen = 160; pcmEx.am_type = AM_PCMEX_TYPE_REC_PLAY_CAL; } else { // pcmEx.dspPcmExMicLen = 320; // pcmEx.dspPcmExSpkLen = 320; pcmEx.am_type = AM_PCMEX_TYPE_IDLE; } } break; default: // include PCMEX_BAND_DYNAMIC and PCMEX_BAND_UNSET cases ASSERT(0); } pcmEx.cfgUL1 = cfgUL1; pcmEx.cfgUL2 = cfgUL2; pcmEx.cfgUL3 = cfgUL3; pcmEx.cfgUL4 = cfgUL4; pcmEx.cfgDL = cfgDL; pcmEx.pnw_dl_hdlr = pcmNway_dl_hdlr; pcmEx.pnw_ul_hdlr = pcmNway_ul_hdlr; L1Audio_HookHisrHandler(DP_D2C_PCM_EX_DL,(L1Audio_EventHandler)pcmEx_hisrDlHdlr, 0); L1Audio_HookHisrHandler(DP_D2C_PCM_EX_UL,(L1Audio_EventHandler)pcmEx_hisrUlHdlr, 0); // check DSP state and turn on ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) && SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF)); AM_PCM_EX_On(pcmEx.am_type, (uint32)(&pcmEx));//to config pnw SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); // wait for ready for(I = 0; ;I ++){ kal_bool is_ready = true; if( (pcmEx.cfgDL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if( (pcmEx.cfgUL1 & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if(is_ready) break; #ifndef L1D_TEST ASSERT(I < 22); // wait 200ms kal_sleep_task(2); #endif } pcmEx.state = PNW_STATE_RUN; if(PCMEX_IDLE_ENH_SETTING_WITH == enhSetting) { pcmEx.isEnhOn = true; SetSpeechEnhancement(true); } /* the end of configure the SAL */ }
/* ========================================================================= */ void SPE_CustomProcess_On(kal_uint16 sph_mode, SPE_Par_Struct *SPE_PAR, kal_uint8 *state) { #if defined( __VOICE_CHANGER_SUPPORT__ ) SPH_VOICE_CHANGER_MODE mode = 0; // Apply VCH only in speech if(!AM_IsSpeechOn()) { return; } if (!VCHIsDcmLoad) { DCM_Load(DYNAMIC_CODE_COMPRESS_VCH , 0, 0); VCHIsDcmLoad = KAL_TRUE; } kal_trace( TRACE_GROUP_AUD_SPE_CSUT, SPEECH_VCH_PROCESS, 1, VCHIsDcmLoad); #endif spe_custom = audio_alloc_mem_cacheable(sizeof(SPE_CUSTOM_STRUCT)); memset(spe_custom, 0, sizeof(SPE_CUSTOM_STRUCT)); /*Copy the actual parameters to control structure*/ spe_custom->aud_id = L1Audio_GetAudioID(); #if defined(__INTERNAL_SPE_ENGINE__) { kal_uint16 i; kal_uint32 aec_mem_size; for(i=0;i<16;i++) spe_custom->Sph_Enh_ctrl.enhance_pars[i] = SPE_PAR->mode_par[i]; for(i=0;i<12;i++) spe_custom->Sph_Enh_ctrl.enhance_pars[i+16] = SPE_PAR->common_par[i]; aec_mem_size = ENH_API_Get_Memory(&spe_custom->Sph_Enh_ctrl); if(aec_mem_size > 0) { spe_custom->working_buffer = audio_alloc_mem_cacheable( aec_mem_size * sizeof(kal_int8) ); memset(spe_custom->working_buffer, 0, aec_mem_size * sizeof(kal_int8)); ENH_API_Alloc(&spe_custom->Sph_Enh_ctrl, (kal_uint32 *)spe_custom->working_buffer); } else spe_custom->working_buffer = NULL; ENH_API_Init(&spe_custom->Sph_Enh_ctrl, SPE_PAR->out_fir, SPE_PAR->in_fir); } #elif defined( __VOICE_CHANGER_SUPPORT__ ) spe_custom->working_buffer = audio_alloc_mem_cacheable( PCM_BUFFER_LENGTH*2*sizeof(kal_uint8)); if(spe_custom->working_buffer != NULL) { memset(spe_custom->working_buffer, 0, PCM_BUFFER_LENGTH*2*sizeof(kal_uint8)); } #endif L1Audio_SetEventHandler(spe_custom->aud_id , spe_custom_task); L1Audio_SetFlag(spe_custom->aud_id); spe_custom->state = SPE_STATE_WORKING; #if defined( __VOICE_CHANGER_SUPPORT__ ) mode = L1SP_GetVoiceChangerMode(); VCHG_Open(8,mode); #endif #if 1 PCM4WAY_Start(spe_custom_hisr_hdlr, 0); #else /* under construction !*/ /* under construction !*/ /* under construction !*/ #endif }
/* ------------------------------------------------------------------------------ */ void L1Audio_Task(unsigned argc, void *argv) { uint32 retrieved_events; uint32 I; uint16 tempID; l1audio.aud_events = kal_create_event_group("L1Audio"); l1audio.hisr = kal_init_hisr(L1AUDIO_HISR); GET_SLEEP_HANDLE(); #if ( defined( __CENTRALIZED_SLEEP_MANAGER__ ) && defined(MTK_SLEEP_ENABLE) && !defined(__AUDIO_POWERON_RESET_DSP__) ) l1audio.md2g_pdn_handle = L1D_MD2G_PWD_GetHandle(); l1audio.l1sm_handle = L1SM_IntGetHandle(); #endif l1audio.runningState = 0; l1audio.disallowSleepState = 0; l1audio.dsp_slow_idle_counter = 0; l1audio.event_flag = 0; l1audio.id_flag = 0; l1audio.media_flag = 0; l1audio.postHisrHandler = (L1Audio_EventHandler)0; l1audio.sema = kal_create_sem( "Aud_Sema", 1 ); l1audio.hisrMagicFlag = 0; for( I = 0; I < MAX_HISR_HANDLER; I++ ) l1audio.hisrMagicNo[I] = 0; tempID = L1Audio_GetAudioID(); L1Audio_SetFlag(tempID); DSP_DynamicDownload_Init(); #ifndef L1D_TEST /// Dynamic download for A/V sync #if defined( DSP_WT_SYN ) && !defined(__AUDIO_COMPONENT_SUPPORT__) DSP_DynamicDownload( DDID_WAVETABLE ); #endif #endif AM_Init(); #if APM_SUPPORT APM_Init(); #endif /// AFE_Init will invoke L1Audio_GetAudioID /// and expect to get the id 0 to make sure /// it has the highest priority in the event group AFE_Init(); #if !defined(__SMART_PHONE_MODEM__) && !defined(__L1_STANDALONE__) && !defined( MED_MODEM ) AVsync_Init(); #endif #if defined(__AUDIO_POWERON_RESET_DSP__) { uint32 _savedMask; _savedMask = SaveAndSetIRQMask(); AFE_Init_status(KAL_TRUE); AFE_RegisterBackup(); RestoreIRQMask(_savedMask); } #endif L1SP_Init(); ktInit( L1Audio_GetAudioID() ); toneInit( L1Audio_GetAudioID() ); mediaInit( L1Audio_GetAudioID() ); #if defined(VR_CYBERON) vrsdInit(); #elif defined(VRSI_CYBERON) vrsiInit(); #endif toneLoopbackRecInit(); #if ( defined(__BT_A2DP_PROFILE__) || defined(SBC_UNIT_TEST) ) //&& !(APM_SUPPORT) SBC_Init(); #endif #if defined(__BES_TS_SUPPORT__) AudioPP_TS_Init(); #endif #ifdef __CTM_SUPPORT__ l1ctm_init(); #endif #ifdef __TWOMICNR_SUPPORT__ Two_Mic_NR_chip_Init(); #endif #if VMI_SUPPORT || defined(VORTP_UNIT_TEST) VMI_Init(); #endif #if VORTP_SUPPORT || defined(VORTP_UNIT_TEST) VoRTP_Init(); #endif #if defined(CYBERON_DIC_TTS) || defined(IFLY_TTS) || defined(SINOVOICE_TTS) ttsInit(); #endif #if defined( DSP_WT_SYN ) && !defined(__AUDIO_COMPONENT_SUPPORT__) DSPSYN_HW_Init(); #endif #if defined( __I2S_INPUT_MODE_SUPPORT__ ) I2S_init(); #endif #if defined(__VOICE_CHANGER_SUPPORT__) VCHG_Initialize(); #endif #if defined(__AUDIO_COMPONENT_SUPPORT__) && !defined(__L1_STANDALONE__) && !defined(MED_MODEM) // KH : for audio component ACU_Init(); #endif #if defined(__CVSD_CODEC_SUPPORT__) { extern void BT_SCO_Init(void); BT_SCO_Init(); } #endif memset( &(l1audio.debug_info), 0, sizeof(l1audio.debug_info) ); AFE_TurnOnFIR( L1SP_SPEECH ); AFE_TurnOnFIR( L1SP_VOICE ); L1Audio_ClearFlag(tempID); L1Audio_FreeAudioID(tempID); l1audio.isInitiated = KAL_TRUE; while( 1 ) { #if VERIFY_DATA_TO_DSP VERIFY_DATA_TO_DSP_SAVE_DATA(); #endif kal_retrieve_eg_events(l1audio.aud_events,0xFFFF,KAL_OR_CONSUME,&retrieved_events,KAL_SUSPEND); l1audio.retrieved_events = retrieved_events; l1audio.events_l1FN = L1I_GetTimeStamp(); for( I = 0; I < MAX_AUDIO_FUNCTIONS; I++ ) { if ( l1audio.retrieved_events & (1<<I) ) { l1audio.evHandler[I]( l1audio.evData[I] ); } } //if( (l1audio.runningState & l1audio.disallowSleepState) == 0 ) if( l1audio.runningState == 0 ) SLEEP_UNLOCK(); } }
/** @type: please refer to P2W_App_Type. 0 for pcm4way CTM, 1 for pcm2way Voice, 2 for pcm2way Voip, 3 for pcm2Way record only(calibration used), 4 for pcm2Way record&playback(calibration used) */ void Extended_PCM2WAY_Start(void (*pcm2way_dl_hdlr)(void), void (*pcm2way_ul_hdlr)(void), uint32 type, uint32 cfgUL, uint32 cfgDL) { uint32 I; kal_bool flag; // Sal_PCMEx_Config_t cfg_t; // cfg_t.idle = false;//initialized pcmEx.aud_id = L1Audio_GetAudioID(); L1Audio_SetFlag( pcmEx.aud_id ); /*Be careful.Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag*/ // for band infomation checking, user should usd PCM2Way_SetFormat() to set format before pcm2way start ASSERT(pcmEx.bandInfo != PCMNWAY_BAND_INFO_UNSET ); pcmEx.app_type = type; // TODO: flag = true; //this flag is used to choose one among multiple options switch (type) { // type checking and pcm2way application type mapping to am type //group1 has the similar settings case P2W_APP_TYPE_UNDER_CALL: if(flag){pcmEx.am_type = AM_PCMEX_TYPE_DEDICATION;flag=false;} case P2W_APP_TYPE_WITHOUT_CALL: if(flag){pcmEx.am_type = AM_PCMEX_TYPE_IDLE_WO_ENH;flag=false;} case P2W_APP_TYPE_VOIP: if(flag){pcmEx.am_type = AM_PCMEX_TYPE_IDLE;flag=false;} if(PCMNWAY_BAND_INFO_WB == PCM2Way_GetBandInfo()){ PCM2WAY_QueryBufSize(P2W_FORMAT_WB_NORMAL, &(pcmEx.u4DspPcmExMicLen), &(pcmEx.u4DspPcmExSpkLen)); } else { PCM2WAY_QueryBufSize(P2W_FORMAT_NORMAL, &(pcmEx.u4DspPcmExMicLen), &(pcmEx.u4DspPcmExSpkLen)); } break; #if defined(__DUAL_MIC_SUPPORT__) || defined(__SMART_PHONE_MODEM__) //group2 has the similar settings case P2W_APP_TYPE_REC_ONLY_CAL: if(flag){pcmEx.am_type = AM_PCMEX_TYPE_REC_ONLY_CAL;flag=false;} case P2W_APP_TYPE_REC_PLAY_CAL: if(flag){pcmEx.am_type = AM_PCMEX_TYPE_REC_PLAY_CAL;flag=false;} if(PCMNWAY_BAND_INFO_NB == PCM2Way_GetBandInfo()){ PCM2WAY_QueryBufSize(P2W_FORMAT_CAL, &(pcmEx.u4DspPcmExMicLen), &(pcmEx.u4DspPcmExSpkLen)); } else if(PCMNWAY_BAND_INFO_WB == PCM2Way_GetBandInfo()){ PCM2WAY_QueryBufSize(P2W_FORMAT_WB_CAL, &(pcmEx.u4DspPcmExMicLen), &(pcmEx.u4DspPcmExSpkLen)); } else { ASSERT(0); // calibration does NOT support dynamic band setting } pcmEx.u4DspPcmExMicLen -= 2; //AGC is put in the sherif instead of buffer break; #endif //__DUAL_MIC_SUPPORT__ || defined(__SMART_PHONE_MODEM__) default: ASSERT(0); } ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) && SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF)); L1Audio_HookHisrHandler(DP_D2C_PCM_EX_DL,(L1Audio_EventHandler)pcmEx_hisrDlHdlr, 0); L1Audio_HookHisrHandler(DP_D2C_PCM_EX_UL,(L1Audio_EventHandler)pcmEx_hisrUlHdlr, 0); pcmEx.pnw_dl_hdlr = pcm2way_dl_hdlr; pcmEx.pnw_ul_hdlr = pcm2way_ul_hdlr; pcmEx.state = PCM2WAY_STATE; pcmEx.cfgUL = cfgUL; pcmEx.cfgDL = cfgDL; /* the begining of configure the SAL */ /* the following is the same as the pcm4way. In the future, it'll be merged together */ /* cfg_t.D2M_ul = cfg_t.M2D_ul = cfg_t.afterEnh_ul = cfg_t.D2M_dl = cfg_t.M2D_dl = cfg_t.afterEnh_dl = false; if(cfgUL & USE_D2M_PATH){ cfg_t.D2M_ul = true; } if(cfgUL & USE_M2D_PATH){ cfg_t.M2D_ul = true; } if(cfgUL & DATA_SELECT_AFTER_ENH){ cfg_t.afterEnh_ul = true; } if(cfgDL & USE_D2M_PATH){ cfg_t.D2M_dl = true; } if(cfgDL & USE_M2D_PATH){ cfg_t.M2D_dl = true; } if(cfgDL & DATA_SELECT_AFTER_ENH){ cfg_t.afterEnh_dl = true; } cfg_t.swi = SAL_PCMEX_SWITCH_ON; cfg_t.type = SAL_PCMEX_TYPE_PNW; if(AM_IsSpeechOn()){ cfg_t.band = SAL_PCM_DYNAMIC; }else{ if(pcmEx.bandInfo == PCMNWAY_BAND_INFO_WB){ cfg_t.band = SAL_PCM_WIDEBAND; }else if (pcmEx.bandInfo == PCMNWAY_BAND_INFO_NB){ cfg_t.band = SAL_PCM_NARROWBAND; }else{ // should never been here ASSERT(0); } } */ AM_PCM_EX_On(pcmEx.am_type, (uint32)(&pcmEx));//to config pnw SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); for(I = 0; ;I ++){ kal_bool is_ready = true; if( (pcmEx.cfgDL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if( (pcmEx.cfgUL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if(is_ready) break; #ifndef L1D_TEST ASSERT(I < 22); // wait 200ms kal_sleep_task(2); #endif } /* the end of configure the SAL */ }
void Extended_PCM4WAY_Start(void (*pcm4way_dl_hdlr)(void), void (*pcm4way_ul_hdlr)(void), uint32 type, uint32 cfgUL, uint32 cfgDL) { uint32 I; pcmEx.aud_id = L1Audio_GetAudioID(); L1Audio_SetFlag( pcmEx.aud_id ); // mapping the pcm4way applicatoin type to am type, and setup the band informtion. pcmEx.app_type = type; switch (type) { case P4W_APP_CTM: case P4W_APP_TYPE_UNDER_CALL: pcmEx.am_type = AM_PCMEX_TYPE_DEDICATION; pcmEx.bandInfo = PCMNWAY_BAND_INFO_DYNAMIC; break; case P4W_APP_TYPE_WITHOUT_CALL: pcmEx.am_type = AM_PCMEX_TYPE_IDLE_WO_ENH; pcmEx.bandInfo = PCMNWAY_BAND_INFO_NB; break; } ASSERT(SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF) && SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_OFF)); L1Audio_HookHisrHandler(DP_D2C_PCM_EX_DL,(L1Audio_EventHandler)pcmEx_hisrDlHdlr, 0); L1Audio_HookHisrHandler(DP_D2C_PCM_EX_UL,(L1Audio_EventHandler)pcmEx_hisrUlHdlr, 0); pcmEx.pnw_dl_hdlr = pcm4way_dl_hdlr; pcmEx.pnw_ul_hdlr = pcm4way_ul_hdlr; pcmEx.state = PCM4WAY_STATE; pcmEx.cfgDL = cfgDL; pcmEx.cfgUL = cfgUL; /* the begining of configure the SAL */ /* cfg_t.D2M_ul = cfg_t.M2D_ul = cfg_t.afterEnh_ul = cfg_t.D2M_dl = cfg_t.M2D_dl = cfg_t.afterEnh_dl = false; if(cfgUL & USE_D2M_PATH){ cfg_t.D2M_ul = true; } if(cfgUL & USE_M2D_PATH){ cfg_t.M2D_ul = true; } if(cfgUL & DATA_SELECT_AFTER_ENH){ cfg_t.afterEnh_ul = true; } if(cfgDL & USE_D2M_PATH){ cfg_t.D2M_dl = true; } if(cfgDL & USE_M2D_PATH){ cfg_t.M2D_dl = true; } if(cfgDL & DATA_SELECT_AFTER_ENH){ cfg_t.afterEnh_dl = true; } cfg_t.swi = SAL_PCMEX_SWITCH_ON; cfg_t.type = SAL_PCMEX_TYPE_PNW; */ AM_PCM_EX_On(pcmEx.am_type, (uint32)(&pcmEx));//to config pnw SAL_PcmEx_SetStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); SAL_PcmEx_SetStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_ON); for(I = 0; ;I ++){ kal_bool is_ready = true; if( (pcmEx.cfgDL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateDL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if( (pcmEx.cfgUL & (USE_D2M_PATH+USE_M2D_PATH)) && (!SAL_PcmEx_CheckStateUL(SAL_PCMEX_TYPE_PNW, SAL_PCMEX_RDY))) is_ready &= false; if(is_ready) break; #ifndef L1D_TEST ASSERT(I < 22); // wait 200ms kal_sleep_task(2); #endif } /* the end of configure the SAL */ }
void KT_Play( uint16 freq1, uint16 freq2, uint16 duration ) { #if defined(KEYTONE_DEBUG) uint8 pressed_key; pressed_key = 0; switch(freq1) { case 697: pressed_key = 1; break; case 770: pressed_key = 4; break; case 852: pressed_key = 7; break; case 941: pressed_key = 10; //* break; } switch(freq2) { case 1209: pressed_key += 0; break; case 1336: pressed_key += 1; break; case 1477: pressed_key += 2; break; } //=================================================================== if(pressed_key == 10) // * KeyFlags = 0x1; else if(pressed_key == 12) // # { if(KeyFlags == 0x3) { switch(KeyCommand) { case 1: Key1Event(); break; case 2: Key2Event(); break; case 3: Key3Event(); break; case 4: Key4Event(); break; case 5: Key5Event(); break; case 6: Key6Event(); break; case 7: Key7Event(); break; case 8: Key8Event(); break; case 9: Key9Event(); break; default: ASSERT(false); } } KeyFlags = 0; } else { if(KeyFlags == 0x1) { switch(pressed_key) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: KeyCommand = pressed_key; KeyFlags = 0x3; break; default: KeyCommand = 0; KeyFlags = 0; } } else KeyFlags = 0; } #ifdef BT_Loopback_Test if(pressed_key == 12) // # KeyFlags1 = 0x11; else if(pressed_key == 10) // * { if(KeyFlags1 == 0x31) { switch(KeyCommand1) { case 1: Key11Event(); break; case 2: Key12Event(); break; case 3: Key13Event(); break; case 4: Key14Event(); break; case 5: Key15Event(); break; case 6: Key16Event(); break; case 7: Key17Event(); break; case 8: Key18Event(); break; case 9: Key19Event(); break; default: ASSERT(false); } } KeyFlags1 = 0; } else { if(KeyFlags1 == 0x11) { switch(pressed_key) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: KeyCommand1 = pressed_key; KeyFlags1 = 0x31; break; default: KeyCommand1 = 0; KeyFlags1 = 0; } } else KeyFlags1 = 0; } //=================================================================== if(pressed_key == 10) // * KeyFlags2 = 0x21; else if(pressed_key == 11) // 0 { if(KeyFlags2 == 0x32) { switch(KeyCommand2) { case 1: Key21Event(); break; case 2: Key22Event(); break; case 3: Key23Event(); break; case 4: Key24Event(); break; case 5: Key25Event(); break; case 6: Key26Event(); break; case 7: Key27Event(); break; case 8: Key28Event(); break; case 9: Key29Event(); break; default: ASSERT(false); } } KeyFlags2 = 0; } else { if(KeyFlags2 == 0x21) { switch(pressed_key) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: KeyCommand2 = pressed_key; KeyFlags2 = 0x32; break; default: KeyCommand2 = 0; KeyFlags = 0; } } else KeyFlags2 = 0; } //=================================================================== if(pressed_key == 12) // # KeyFlags3 = 0x31; else if(pressed_key == 11) // 0 { if(KeyFlags3 == 0x33) { switch(KeyCommand3) { case 1: Key31Event(); break; case 2: Key32Event(); break; case 3: Key33Event(); break; case 4: Key34Event(); break; case 5: Key35Event(); break; case 6: Key36Event(); break; case 7: Key37Event(); break; case 8: Key38Event(); break; case 9: Key39Event(); break; default: ASSERT(false); } } KeyFlags3 = 0; } else { if(KeyFlags3 == 0x31) { switch(pressed_key) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: KeyCommand3 = pressed_key; KeyFlags3 = 0x33; break; default: KeyCommand3 = 0; KeyFlags3 = 0; } } else KeyFlags3 = 0; } return; #endif // #ifdef BT_Loopback_Test #endif//#if defined(KEYTONE_DEBUG) if( keytone.lock > 0 || keytone.volume1 == 0 ) return; if( mediaKeytoneForbidden() || AM_IsDAIMode() ) return; if( L1Audio_CheckFlag( keytone.aud_id ) || L1Audio_CheckFlag( tone.aud_id ) ) return; if (keytone.state != TONE_STATE_NONE) return; L1Audio_SetFlag( keytone.aud_id ); #if defined(__GAIN_TABLE_SUPPORT__) AFE_SetOutputGainControl(L1SP_KEYTONE,keytone.gain); #else AFE_SetOutputVolume( L1SP_KEYTONE, keytone.volume1, keytone.digital_gain_index ); #endif keytone.fc_aud_id = L1Audio_FC_HookHandler( (void *)0, ktMsgHandler, 0, (FC_MEDIA_FORMAT_QTMF<<8)|MEDIA_OPERATE_PLAYBACK ); keytone.state = TONE_STATE_IDLE; keytone.info->freq1 = freq1; keytone.info->freq2 = freq2; keytone.info->freq3 = 0; keytone.info->freq4 = 0; if (duration == 0) { keytone.info->msDur = -1; } else { keytone.info->msDur = duration; } AM_KeyToneOn(); kal_sleep_task(1); keytone.state = TONE_STATE_INIT; keytone.isReentrance = false; keytone.seqNum++; /*workaround for SPEECH DSP MAIN/AUX Mode Task in FCORE*/ #ifdef BGSND_ENABLE if (keytone.sndOffHandler != NULL) keytone.sndOffHandler( keytone.sndHdl ); #endif /*workaround for SPEECH DSP MAIN/AUX Mode Task in FCORE*/ L1Audio_FC_TonePlaybackOn(keytone.fc_aud_id, keytone.info); //AM_KeyToneOn(); }
/***************************************************************************** * FUNCTION * gmiWriteToDSP * DESCRIPTION * This function is the call-back function of GPT for playing notes. *****************************************************************************/ static void gmiWriteToDSP( void *data ) { GMI_Note *note; uint16 I; uint32 curtime; uint32 note_time; uint32 next_time; uint16 rb_count_org; rb_count_org = RB_Count(); curtime = (uint32)(QTMF_COUNTER - gmi.start_time); next_time = curtime; while( !RB_Empty() ) { note = RB_Peek(); note_time = gmi.note_time + note->delta_time; if( note_time > next_time ) { next_time = note_time; } else if( note_time < curtime ) { RB_Consume(); gmi.note_time = note_time; continue; } /* search for the first available DSP tone */ for( I = 0; I < MAX_DPRAM_BUFFER; I++ ) { #if defined(MT6205) if( QTMF_DURA(I) == 0 && gmi.dsp_time[I] <= note_time ) { #else if( QTMF_DURA(I) == 0 ) { #endif QTMF_FREQ(I) = Pitch2Frequency[ note->pitch ]; QTMF_AMP(I) = (uint16)note->amplitude; QTMF_DURA(I) = note->duration << 4; /* QTMF_DURA(I) = (note->duration << 4) + ((note->timbre >> 3) & 0x0F ); */ QTMF_TIME(I) = (uint16)note_time + gmi.start_time; gmi.dsp_time[I] = note_time + note->duration; if( gmi.end_time < gmi.dsp_time[I] ) gmi.end_time = gmi.dsp_time[I]; RB_Consume(); gmi.note_time = note_time; break; } } if( I == MAX_DPRAM_BUFFER ) break; } switch( gmi.state ) { case GMI_STATE_INIT: QTMF_CONTROL = 3; gmi.state = GMI_STATE_PLAY; break; case GMI_STATE_PLAY: if( rb_count_org >= GMI_RB_SIZE/2 && RB_Count() < GMI_RB_SIZE/2 ) L1Audio_SetEvent( gmi.aud_id, (void*)GMI_NOTE_REQUEST ); if( gmi.eof_flag ) gmi.state = GMI_STATE_DATA_COMPLETE; break; case GMI_STATE_DATA_COMPLETE: if( RB_Empty() ) { GPTI_StartItem( gmi.gpt, (gmi.end_time - curtime + 5) * 2, gmiTerminate, 0 ); return; } break; } if( next_time > curtime ) next_time = next_time - curtime; else next_time = 1; GPTI_StartItem( gmi.gpt, next_time, gmiWriteToDSP, 0 ); } /***************************************************************************** * FUNCTION * GMI_Play * DESCRIPTION * This function is used to start melody playing. * * PARAMETERS * gmi_handler - a call back function used to be notified an event that * the end of a song is reached. *****************************************************************************/ void GMI_Play( void (*gmi_handler)( GMI_Event event ) ) { int16 I; if( L1Audio_CheckFlag( gmi.aud_id ) ) return; if( gmi_handler == 0 ) return; if( gmi.state != GMI_STATE_IDLE ) return; L1Audio_SetFlag( gmi.aud_id ); GPTI_StopItem( gmi.gpt ); for( I = 0; I < MAX_DPRAM_BUFFER; I++ ) { gmi.dsp_time[I] = 0; QTMF_DURA(I) = 0; } gmi.rb_head = 0; gmi.rb_tail = 0; gmi.mmi_time = 0; gmi.start_time = QTMF_COUNTER; gmi.end_time = 0; gmi.state = GMI_STATE_INIT; gmi.note_time = 0; gmi.eof_flag = false; gmi.gmi_handler = gmi_handler; gmi.gmi_handler( GMI_NOTE_REQUEST ); AM_MelodyOn(); gmiWriteToDSP( 0 ); } /* end of gmiPlay */