aec.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:30k
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * AEC.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Acoustic Echo Cancellation (AEC) calibration in loud speaker mode source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #include <IniFiles.hpp>
- #pragma hdrstop
- #ifndef _AEC_H_
- #include "aec.h"
- #endif
- #ifndef _MAN_ACTIVE_H_
- #include "man_active.h"
- #endif
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- //===========================================================================
- static CAECLS* g_aec_ptr;
- static bool g_bIsRunning = false;
- //============================= static function ==============================
- static void REQ_TimeOut(void)
- {
- g_aec_ptr->REQ_TimeOut();
- }
- //----------------------------------------------------------------------------
- static void REQ_Finish(void)
- {
- g_aec_ptr->REQ_Finish();
- }
- //----------------------------------------------------------------------------
- static void REQ_Read_FIR_From_NVRAM(void)
- {
- g_aec_ptr->REQ_Read_FIR_From_NVRAM();
- }
- //----------------------------------------------------------------------------
- static void CNF_ReadFirFromNVRAM(void)
- {
- g_aec_ptr->CNF_ReadFirFromNVRAM();
- }
- //----------------------------------------------------------------------------
- static void REQ_Write_FIR_To_NVRAM(void)
- {
- g_aec_ptr->REQ_Write_FIR_To_NVRAM();
- }
- //----------------------------------------------------------------------------
- static void CNF_WriteFirToNVRAM(void)
- {
- g_aec_ptr->CNF_WriteFirToNVRAM();
- }
- //----------------------------------------------------------------------------
- static void REQ_Read_Volume_Setting_From_NVRAM(void)
- {
- g_aec_ptr->REQ_Read_Volume_Setting_From_NVRAM();
- }
- //----------------------------------------------------------------------------
- static void CNF_ReadVolSettingFromNVRAM(void)
- {
- g_aec_ptr->CNF_ReadVolSettingFromNVRAM();
- }
- //----------------------------------------------------------------------------
- static void CNF_WriteVolSettingToNVRAM(void)
- {
- g_aec_ptr->CNF_WriteVolSettingToNVRAM();
- }
- //----------------------------------------------------------------------------
- static void REQ_Audio_Tone_Loop_Back_Rec(void)
- {
- g_aec_ptr->REQ_Audio_Tone_Loop_Back_Rec();
- }
- //===========================================================================
- CAECLS::CAECLS(void)
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- m_cpBuf = NULL;
- }
- //---------------------------------------------------------------------------
- CAECLS::~CAECLS( )
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- ReleaseDynMemory();
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CAECLS::AllocateDynMemory(void)
- {
- if (NULL == m_cpBuf)
- {
- if (AEC_TYPE_LOUD_SPEAKER_8K == m_sAEC.e_aec_type)
- {
- m_cpBuf = new char[AEC_BUF_SIZE_8K*AEC_PLAY_FREQ_NUM];
- }
- else
- {
- m_cpBuf = new char[AEC_BUF_SIZE_2K*AEC_PLAY_FREQ_NUM];
- }
- }
- }
- //---------------------------------------------------------------------------
- void CAECLS::ReleaseDynMemory(void)
- {
- if (NULL != m_cpBuf)
- {
- delete [] m_cpBuf;
- m_cpBuf = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void CAECLS::Confirm(E_METAAPP_RESULT_T confirm_state)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- g_bIsRunning = false;
- if (NULL == ConfirmCallback)
- {
- return;
- }
- m_eConfirmState = confirm_state;
- ActiveMan->SetActiveFunction(ConfirmCallback);
- }
- //---------------------------------------------------------------------------
- void CAECLS::REQ_Finish(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- Confirm(METAAPP_SUCCESS);
- }
- //---------------------------------------------------------------------------
- void CAECLS::REQ_Stop(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- g_bIsRunning = false;
- META_CancelAllBlockingCall_r(m_META_HANDLE_Obj.Get_MainHandle());
- Confirm(METAAPP_STOP);
- }
- //---------------------------------------------------------------------------
- void CAECLS::REQ_TimeOut( void )
- {
- if(!g_bIsRunning) return;
- META_CancelAllBlockingCall_r(m_META_HANDLE_Obj.Get_MainHandle());
- Confirm(METAAPP_TIMEOUT);
- }
- //==============================================================================
- void CAECLS::Req_Start(S_AEC_LS_T s_aec)
- {
- g_aec_ptr = this;
- g_bIsRunning = true;
- m_sAEC = s_aec;
- AllocateDynMemory();
- ActiveMan->SetActiveFunction(::REQ_Read_FIR_From_NVRAM);
- }
- //===========================================================================
- void CAECLS::REQ_Read_FIR_From_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- m_cSP_COEF_Obj.ConfirmCallback = ::CNF_ReadFirFromNVRAM;
- m_cSP_COEF_Obj.REQ_Read_From_NVRAM(m_sAEC.e_audio_param_type);
- }
- //-------------------------------------
- void CAECLS::CNF_ReadFirFromNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = m_cSP_COEF_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- m_cSP_COEF_Obj.Get_FirCoef(m_sFirCoeff);
- // set initial RX FIR
- if (!REQ_Set_LoudSpk_FIR_Coeffs(m_sAECFir.s_fir_coeffs))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- // set initial speech enhacement
- if (!REQ_Set_LoudSpk_Speech_Enhacement_FIR_Coeffs(m_sAECSeFir.us_se_fir_coeffs))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- // set initial common parameter
- if (!REQ_Set_Speech_Common_And_Mode_FIR_Coeffs(m_sFirCoeff.us_speech_common_para, m_sAECSeFir.us_se_fir_coeffs))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- m_eStep = AEC_STEP_1;
- ActiveMan->SetActiveFunction(::REQ_Audio_Tone_Loop_Back_Rec);
- }
- break;
- default:
- {
- Confirm(state);
- }
- break;
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CAECLS::REQ_Write_FIR_To_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- m_cSP_COEF_Obj.Set_FirCoef(m_sFirCoeff);
- m_cSP_COEF_Obj.ConfirmCallback = ::CNF_WriteFirToNVRAM;
- m_cSP_COEF_Obj.REQ_Write_To_NVRAM(m_sAEC.e_audio_param_type, m_sAEC.b_fir_runtime_support);
- }
- //-----------------------------------------
- void CAECLS::CNF_WriteFirToNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = m_cSP_COEF_Obj.Get_ConfirmState();
- if (METAAPP_SUCCESS == state)
- {
- ActiveMan->SetActiveFunction(::REQ_Read_Volume_Setting_From_NVRAM);
- }
- else
- {
- Confirm(state);
- }
- }
- //===========================================================================
- void CAECLS::REQ_Read_Volume_Setting_From_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- m_cVOL_SET_Obj.ConfirmCallback = ::CNF_ReadVolSettingFromNVRAM;
- m_cVOL_SET_Obj.REQ_Read_From_NVRAM(m_sAEC.b_cust_vol_16);
- }
- //--------------------------------------------
- void CAECLS::CNF_ReadVolSettingFromNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = m_cVOL_SET_Obj.Get_ConfirmState();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- if (m_sAEC.b_cust_vol_16)
- {
- CustAcousticVol16lvl_T* p_cust_vol = m_cVOL_SET_Obj.Get_CustVol16();
- m_sCustVolEx = *p_cust_vol;
- for (int level=0; level<CUST_VOL_LEVEL_NUM; level++)
- {
- m_sCustVolEx.volume_gain[HANDSFREE_MODE][SPEECH_TONE_TYPE][level] = m_sSpkGain.volume[level];
- m_sCustVolEx.volume_gain[HANDSFREE_MODE][MICROPHONE_TYPE][level] = m_sMicGain.volume;
- }
- m_cVOL_SET_Obj.Set_CustVol16(m_sCustVolEx);
- }
- else
- {
- CustAcousticVol_T* p_cust_vol = m_cVOL_SET_Obj.Get_CustVol();
- m_sCustVol = *p_cust_vol;
- for (int level=0; level<CUST_VOL_LEVEL_NUM; level++)
- {
- m_sCustVol.volume_gain[HANDSFREE_MODE][SPEECH_TONE_TYPE][level] = m_sSpkGain.volume[level];
- m_sCustVol.volume_gain[HANDSFREE_MODE][MICROPHONE_TYPE][level] = m_sMicGain.volume;
- }
- m_cVOL_SET_Obj.Set_CustVol(m_sCustVol);
- }
- REQ_Write_Volume_Setting_To_NVRAM();
- }
- break;
- default:
- {
- Confirm(state);
- }
- break;
- }
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void CAECLS::REQ_Write_Volume_Setting_To_NVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- m_cVOL_SET_Obj.ConfirmCallback = ::CNF_WriteVolSettingToNVRAM;
- m_cVOL_SET_Obj.REQ_Write_To_NVRAM(m_sAEC.b_cust_vol_16, m_sAEC.b_cust_vol_runtime_support);
- }
- //-------------------------------------------------
- void CAECLS::CNF_WriteVolSettingToNVRAM(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- E_METAAPP_RESULT_T state = m_cVOL_SET_Obj.Get_ConfirmState();
- if (state != METAAPP_SUCCESS)
- {
- Confirm(state);
- }
- // write volume gain to file
- bool ok = m_cVOL_SET_Obj.REQ_Write_To_File(m_sAEC.as_volume_gain_file.c_str(), true, m_sAEC.b_cust_vol_16);
- if (!ok)
- {
- Confirm(METAAPP_FAIL);
- }
- else
- {
- Confirm(METAAPP_SUCCESS);
- }
- }
- //---------------------------------------------------------------------------
- void CAECLS::REQ_Audio_Tone_Loop_Back_Rec(void)
- {
- if (!g_bIsRunning)
- {
- return;
- }
- META_RESULT MetaResult;
- Audio_Tone_LoopBackRec_Req req;
- Audio_Tone_LoopBackRec_Cnf cnf_8k;
- Audio_Tone_LoopBackRec_Cnf_2K cnf_2k;
- unsigned short us_freq[] = {500, 750, 1000, 1500, 2000, 2500, 3000, 3500};
- if (!calibrate_mic(&m_sMicGain, m_sAEC.i_micgain, (int) m_sAEC.e_mic_device_type))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- if (!calibrate_spk(&m_sSpkGain, m_sAEC.i_spkgain, (int) m_sAEC.e_speaker_dac_type))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- req.spkgain = m_sSpkGain.cal_gain;
- req.micgain = m_sMicGain.cal_gain;
- req.ulgain = m_usUpDigiGain;
- req.dlgain = m_usDnDigiGain;
- req.amp = m_usKTGain[m_eStep-1];
- for (int i=0; i<AEC_PLAY_FREQ_NUM; i++)
- {
- req.fre = us_freq[i];
- switch (m_sAEC.e_aec_type)
- {
- case AEC_TYPE_LOUD_SPEAKER_8K:
- {
- MetaResult = META_Audio_Tone_Loop_Back_Rec_r(m_META_HANDLE_Obj.Get_MainHandle(), 15000 , &req, &cnf_8k);
- }
- break;
- case AEC_TYPE_LOUD_SPEAKER_2K:
- {
- MetaResult = META_Audio_Tone_Loop_Back_Rec_2K_r(m_META_HANDLE_Obj.Get_MainHandle(), 15000 , &req, &cnf_2k);
- }
- break;
- }
- if (MetaResult != META_SUCCESS)
- {
- if (MetaResult != META_TIMEOUT)
- {
- Confirm(METAAPP_FAIL);
- }
- else
- {
- Confirm(METAAPP_TIMEOUT);
- }
- return;
- }
- if (AEC_TYPE_LOUD_SPEAKER_8K == m_sAEC.e_aec_type)
- {
- memcpy((void *)(m_cpBuf+i*AEC_BUF_SIZE_8K), (void *)cnf_8k.buffer, AEC_BUF_SIZE_8K);
- }
- else
- {
- memcpy((void *)(m_cpBuf+i*AEC_BUF_SIZE_2K), (void *)cnf_2k.buffer, AEC_BUF_SIZE_2K);
- }
- }
- switch (m_eStep)
- {
- case AEC_STEP_1:
- {
- switch (m_sAEC.e_aec_type)
- {
- case AEC_TYPE_LOUD_SPEAKER_8K:
- {
- if (!calibrate_step_1(&m_sResultFir, (short *)m_cpBuf, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- break;
- case AEC_TYPE_LOUD_SPEAKER_2K:
- {
- if (!calibrate_step_1_2k(&m_sResultFir, (short *)m_cpBuf, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- break;
- } // switch (e_aec_type)
- // set FIR result to target RAM
- if (!REQ_Set_LoudSpk_FIR_Coeffs(m_sResultFir.coef))
- {
- Confirm(METAAPP_FAIL);
- }
- m_eStep = AEC_STEP_2;
- ActiveMan->SetActiveFunction(::REQ_Audio_Tone_Loop_Back_Rec);
- }
- break;
- case AEC_STEP_2:
- {
- switch (m_sAEC.e_aec_type)
- {
- case AEC_TYPE_LOUD_SPEAKER_8K:
- {
- if (!calibrate_step_2(&m_sResultFir, (short *)m_cpBuf, m_sResultFir.flt_index, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- break;
- case AEC_TYPE_LOUD_SPEAKER_2K:
- {
- if (!calibrate_step_2_2k(&m_sResultFir, (short *)m_cpBuf, m_sResultFir.flt_index, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- break;
- // case AEC_TYPE_NORMAL_2K:
- // {
- // }
- // break;
- } // switch (m_sAEC.e_aec_type)
- // set result to FIR coefficient structure
- for (int i=0; i<SPEECH_FIR_45_TAPS_NUM; i++)
- {
- m_sFirCoeff.s_speech_output_FIR_coeffs[SPEECH_OUTPUT_FIR_2G_3G_HANDSFREE_IDX][i] = m_sResultFir.coef[i];
- m_sFirCoeff.s_speech_output_FIR_coeffs[SPEECH_OUTPUT_FIR_VOIP_HANDSFREE_IDX][i] = m_sResultFir.coef[i];
- }
- // write output speech FIR to file
- m_cSP_COEF_Obj.Set_FirCoef(m_sFirCoeff);
- if (!m_cSP_COEF_Obj.REQ_Write_Speech_Output_Coeff_To_File(m_sAEC.as_output_speech_fir.c_str(), m_sAEC.e_audio_param_type, SPEECH_OUTPUT_FIR_2G_3G_HANDSFREE_IDX))
- {
- Confirm(METAAPP_FAIL);
- }
- // set FIR result to target RAM
- if (!REQ_Set_LoudSpk_FIR_Coeffs(m_sResultFir.coef))
- {
- Confirm(METAAPP_FAIL);
- }
- m_eStep = AEC_STEP_3;
- ActiveMan->SetActiveFunction(::REQ_Audio_Tone_Loop_Back_Rec);
- }
- break;
- case AEC_STEP_3:
- {
- if ((AUDIO_FIR_VER_W0547_45_TAP == m_sAEC.e_audio_param_type) ||
- (AUDIO_FIR_VER_W0712 == m_sAEC.e_audio_param_type) ||
- (AUDIO_FIR_VER_W0740 == m_sAEC.e_audio_param_type)
- )
- {
- switch (m_sAEC.e_aec_type)
- {
- case AEC_TYPE_LOUD_SPEAKER_8K:
- {
- if (!calibrate_step_3(&m_sResultSEFir, (short *)m_cpBuf, m_sAEC.b_drc_support, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- break;
- case AEC_TYPE_LOUD_SPEAKER_2K:
- {
- if (!calibrate_step_3_2k(&m_sResultSEFir, (short *)m_cpBuf, m_sAEC.b_drc_support, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- break;
- }
- }
- else
- {
- if (!calibrate_step_3_2k_08A(&m_sResultSEFir, (short *)m_cpBuf, m_sAEC.b_drc_support, m_sAEC.b_debug))
- {
- Confirm(METAAPP_FAIL);
- return;
- }
- }
- // write Audcoeff_default.h
- unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_sAEC.e_audio_param_type);
- if ((AUDIO_FIR_VER_W0547_45_TAP == m_sAEC.e_audio_param_type) ||
- (AUDIO_FIR_VER_W0712 == m_sAEC.e_audio_param_type) ||
- (AUDIO_FIR_VER_W0740 == m_sAEC.e_audio_param_type)
- )
- {
- for (int i=0; i<uc_se_mode_para_num; i++)
- {
- m_sFirCoeff.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i] = m_sResultSEFir.sp_enhace[i];
- }
- for (int i = uc_se_mode_para_num; i<SE_MODE_PARA_NUM_16; i++)
- {
- m_sFirCoeff.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i] = 0;
- }
- }
- else
- {
- for (int i=0; i<uc_se_mode_para_num; i++)
- {
- m_sFirCoeff.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i] = m_sResultSEFir.sp_enhace_08A[i];
- }
- for (int i = uc_se_mode_para_num; i<SE_MODE_PARA_NUM_16; i++)
- {
- m_sFirCoeff.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i] = 0;
- }
- }
- if (!REQ_Write_To_Audcoeff_Default(m_sAEC.as_audcoeff_default_h.c_str(), m_sAEC.e_audio_param_type))
- {
- Confirm(METAAPP_FAIL);
- }
- // write FIR to NVRAM
- ActiveMan->SetActiveFunction(::REQ_Write_FIR_To_NVRAM);
- }
- break;
- default:
- {
- }
- break;
- }
- }
- //===========================================================================
- ////////////////////////////// Runtime setting ///////////////////////////
- //===========================================================================
- bool CAECLS::REQ_Set_LoudSpk_FIR_Coeffs(short* p_output_coeff)
- {
- if (!g_bIsRunning)
- {
- return false;
- }
- Audio_Set_LoudSpk_FIR_Coeffs_Req req;
- for (int i=0; i<SPEECH_FIR_45_TAPS_NUM; i++)
- {
- req.out_fir_coeffs[i] = *(p_output_coeff + i);
- }
- for (int i=0; i<SPEECH_FIR_45_TAPS_NUM; i++)
- {
- req.in_fir_coeffs[i] = m_sFirCoeff.s_speech_input_FIR_coeffs[SPEECH_INPUT_FIR_2G_3G_HANDSFREE_IDX][i];
- }
-
- META_RESULT MetaResult = META_Audio_Set_LoudSpk_FIR_Coeffs_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req);
- if (MetaResult != META_SUCCESS)
- {
- if (MetaResult != META_TIMEOUT)
- {
- Confirm(METAAPP_FAIL);
- }
- else
- {
- Confirm(METAAPP_TIMEOUT);
- }
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool CAECLS::REQ_Set_LoudSpk_Speech_Enhacement_FIR_Coeffs(unsigned short *p_coeff)
- {
- if (!g_bIsRunning)
- {
- return false;
- }
- Audio_Set_LoudSpk_Mode_Req req;
- unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_sAEC.e_audio_param_type);
- for (int i=0; i<uc_se_mode_para_num; i++)
- {
- req.speech_loudspk_mode_para[i] = *(p_coeff+i);
- }
- META_RESULT MetaResult = META_Audio_Set_LoudSpk_Mode_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req);
- if (MetaResult != META_SUCCESS)
- {
- if (MetaResult != META_TIMEOUT)
- {
- Confirm(METAAPP_FAIL);
- }
- else
- {
- Confirm(METAAPP_TIMEOUT);
- }
- return false;
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool CAECLS::REQ_Set_Speech_Common_And_Mode_FIR_Coeffs(unsigned short *p_comm_coeff, unsigned short *p_mode_coeff)
- {
- if (!g_bIsRunning)
- {
- return false;
- }
- Audio_Set_Speech_Common_And_Mode_Req req;
- unsigned char uc_se_speech_common_num = m_cSP_COEF_Obj.Get_SpeechCommonParameterNum(m_sAEC.e_audio_param_type);
- for (int i=0; i<uc_se_speech_common_num; i++)
- {
- req.speech_common_para[i] = *(p_comm_coeff+i);
- }
- unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_sAEC.e_audio_param_type);
- for (int i = 0; i < uc_se_mode_para_num; i++)
- {
- req.speech_loudspk_mode_para[i] = *(p_mode_coeff+i);
- }
- for (int i = uc_se_mode_para_num; i < SE_MODE_PARA_NUM_16; i++)
- {
- req.speech_loudspk_mode_para[i] = 0;
- }
- META_RESULT MetaResult = META_Audio_Set_Speech_Common_And_Mode_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req);
- if (MetaResult != META_SUCCESS)
- {
- if (MetaResult != META_TIMEOUT)
- {
- Confirm(METAAPP_FAIL);
- }
- else
- {
- Confirm(METAAPP_TIMEOUT);
- }
- return false;
- }
- return true;
- }
- //===========================================================================
- ////////////////////////////// File ///////////////////////////
- //===========================================================================
- static AnsiString as_SECTION_NAME = "AEC calibration";
- //--------------------------------------------------------------------------
- bool CAECLS::REQ_Read_From_File(char *filename, E_AUDIO_FIR_VER_T audio_param_type)
- {
- TIniFile *ini_file;
- AnsiString as_data;
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- // Rx default FIR
- as_data = ini_file->ReadString(as_SECTION_NAME,
- "Rx default FIR",
- "32767,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" );
- String_To_Array_short(as_data.c_str(), m_sAECFir.s_fir_coeffs, SPEECH_FIR_45_TAPS_NUM);
- // LoudSpeaker Mode Debug Parameter
- as_data = ini_file->ReadString(as_SECTION_NAME,
- "LoudSpeaker Mode Debug Parameter",
- "0,479,0,0,0,0,400,0");
- unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_sAEC.e_audio_param_type);
- String_To_Array_UnsignedShort(as_data.c_str(), m_sAECSeFir.us_se_fir_coeffs, uc_se_mode_para_num);
- // microphone default gain
- m_iMicGain = ini_file->ReadInteger(as_SECTION_NAME, "microphone default gain", 0);
- // speaker default gain
- m_iSpkGain = ini_file->ReadInteger(as_SECTION_NAME, "speaker default gain", 18);
- // uplink digital gain
- m_usUpDigiGain = ini_file->ReadInteger(as_SECTION_NAME, "uplink digital gain", 0x1400);
- // downlink digital gain
- m_usDnDigiGain = ini_file->ReadInteger(as_SECTION_NAME, "downlink digital gain", 0x1000);
- AnsiString as_key_name;
- for (int i=0; i<3; i++)
- {
- as_key_name = "KT gain step" +IntToStr(i+1);
- m_usKTGain[i] = ini_file->ReadInteger(as_SECTION_NAME, as_key_name, 0x3fff);
- }
- delete ini_file;
- return true;
- }
- //---------------------------------------------------------------------------
- bool CAECLS::REQ_Write_To_Audcoeff_Default(char *filename, E_AUDIO_FIR_VER_T audio_param_type)
- {
- if ((AUDIO_FIR_VER_ORG == audio_param_type) || (AUDIO_FIR_VER_W0547 == audio_param_type))
- {
- return false;
- }
- FILE *fs;
- fs = fopen(filename, "w");
- if (NULL == fs)
- {
- return false;
- }
- fprintf(fs, "#ifndef AUDCOEFF_COMMON_DOT_Hn");
- fprintf(fs, "#define AUDCOEFF_COMMON_DOT_Hnn");
- fprintf(fs, "#define DEFAULT_SPEECH_LOUDSPK_MODE_PARA \");
- fprintf(fs, "n");
- fprintf(fs, "{ \");
- fprintf(fs, "n");
- unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_sAEC.e_audio_param_type);
- for (int i=0; i<uc_se_mode_para_num; i++)
- {
- fprintf(fs, "%6d", m_sFirCoeff.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i]);
- if (i != uc_se_mode_para_num - 1)
- {
- fprintf(fs, ",");
- }
- else
- {
- fprintf(fs, " \");
- }
- }
- fprintf(fs, "n}nn");
- fprintf(fs, "#endif // ... AUDCOEFF_COMMON_DOT_Hnn");
-
- fclose(fs);
- return true;
- }
- //---------------------------------------------------------------------------
- bool CAECLS::REQ_Write_Record_To_File(char *filename)
- {
- FILE *fs;
- fs = fopen(filename, "wb");
- if (NULL == fs)
- {
- return false;
- }
- if (AEC_TYPE_LOUD_SPEAKER_8K == m_sAEC.e_aec_type)
- {
- fwrite(m_cpBuf, AEC_BUF_SIZE_8K*AEC_PLAY_FREQ_NUM, 1, fs);
- }
- else
- {
- fwrite(m_cpBuf, AEC_BUF_SIZE_2K*AEC_PLAY_FREQ_NUM, 1, fs);
- }
- fclose(fs);
- return true;
- }
- //===========================================================================
- ///////////////////////////// Query ///////////////////////////
- //===========================================================================
- bool CAECLS::Query_DRC_Support_Start(void)
- {
- g_aec_ptr = this;
- g_bIsRunning = true;
- bool b_DRCSupport = Query_DRC_Support();
- return b_DRCSupport;
- }
- //--------------------------------------------------------------------------
- bool CAECLS::Query_DRC_Support(void)
- {
- META_RESULT MetaResult = META_QueryIfTargetSupportDRC_r(m_META_HANDLE_Obj.Get_MainHandle(), 300);
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- bool CAECLS::Query_Aec2kSupport_Start(void)
- {
- META_RESULT MetaResult = META_QueryIfFunctionSupportedByTarget_r(m_META_HANDLE_Obj.Get_MainHandle(), 500, "META_Audio_Tone_Loop_Back_Rec_2K_r");
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- return true;
- }
- //===========================================================================
- //////////////////////////// Global information ///////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CAECLS::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //---------------------------------------------------------------------------
- int CAECLS::Get_MicGain(void)
- {
- return m_iMicGain;
- }
- //---------------------------------------------------------------------------
- int CAECLS::Get_SpkGain(void)
- {
- return m_iSpkGain;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- E_AEC_RESULT_T CAECLS::Get_Result(void)
- {
- return (E_AEC_RESULT_T) m_sResultSEFir.mechanism;
- }