aec_common.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:11k
- /*****************************************************************************
- * 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_common.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Acoustic Echo Cancellation (AEC) calibration common 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 CAECCMN* g_aec_cmn_ptr;
- static bool g_bIsRunning = false;
- //===========================================================================
- CAECCMN::CAECCMN(void)
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- }
- //---------------------------------------------------------------------------
- CAECCMN::~CAECCMN()
- {
- g_bIsRunning = false;
- ConfirmCallback = NULL;
- }
- //---------------------------------------------------------------------------
- void CAECCMN::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);
- }
- //===========================================================================
- ////////////////////////////// File ///////////////////////////
- //===========================================================================
- static const AnsiString as_SECTION_NAME = "AEC calibration";
- static const AnsiString as_KEY_NAME_NM_DBG = "Normal Mode Debug Parameter";
- static const AnsiString as_KEY_NAME_NM_UP_DIGITAL_GAIN = "Normal Mode uplink digital gain";
- static const AnsiString as_KEY_NAME_NM_DN_DIGITAL_GAIN = "Normal Mode downlink digital gain";
- static const AnsiString as_KEY_NAME_NM_KT_GAIN_STEP = "Normal Mode KT gain step";
- //--------------------------------------------------------------------------
- bool CAECCMN::REQ_Read_From_File(char *filename, unsigned char uc_se_mode_para_num)
- {
- TIniFile *ini_file;
- AnsiString as_data;
- ini_file = new TIniFile(filename);
- if (NULL == ini_file)
- {
- return false;
- }
- //-----------------------------------------------------------------
- // loud speaker mode parameter
- // 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_sAecIni.m_sAecLsIni.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");
- String_To_Array_UnsignedShort(as_data.c_str(), m_sAecIni.m_sAecLsIni.us_dbg, uc_se_mode_para_num);
- // microphone default gain
- m_sAecIni.m_sAecLsIni.uc_mic_gain = ini_file->ReadInteger(as_SECTION_NAME, "microphone default gain", 0);
- // speaker default gain
- m_sAecIni.m_sAecLsIni.uc_speaker_gain = ini_file->ReadInteger(as_SECTION_NAME, "speaker default gain", 18);
- // uplink digital gain
- m_sAecIni.m_sAecLsIni.us_up_digital_gain = ini_file->ReadInteger(as_SECTION_NAME, "uplink digital gain", 0x1400);
- // downlink digital gain
- m_sAecIni.m_sAecLsIni.us_dn_digital_gain = 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_sAecIni.m_sAecLsIni.us_kt_gain[i] = ini_file->ReadInteger(as_SECTION_NAME, as_key_name, 0x3fff);
- }
- //-----------------------------------------------------------------
- // normal mode parameter
- // debug parameter
- as_data = ini_file->ReadString(as_SECTION_NAME,
- as_KEY_NAME_NM_DBG,
- "0,479,0,0,0,0,400,0");
- String_To_Array_UnsignedShort(as_data.c_str(), m_sAecIni.m_sAecNmIni.us_dbg, uc_se_mode_para_num);
- // uplink digital gain
- m_sAecIni.m_sAecNmIni.us_up_digital_gain = (unsigned short) ini_file->ReadInteger(as_SECTION_NAME, as_KEY_NAME_NM_UP_DIGITAL_GAIN, 0x1400);
- // downlink digital gain
- m_sAecIni.m_sAecNmIni.us_dn_digital_gain = (unsigned short) ini_file->ReadInteger(as_SECTION_NAME, as_KEY_NAME_NM_DN_DIGITAL_GAIN, 0x1000);
- for (int i=0; i<3; i++)
- {
- as_key_name = as_KEY_NAME_NM_KT_GAIN_STEP + IntToStr(i+1);
- m_sAecIni.m_sAecNmIni.us_kt_gain[i] = ini_file->ReadInteger(as_SECTION_NAME, as_key_name, 0x3800);
- }
- delete ini_file;
- return true;
- }
- //===========================================================================
- ///////////////////////////// Query ///////////////////////////
- //===========================================================================
- bool CAECCMN::Query_AEC_Support_Start(void)
- {
- g_aec_cmn_ptr = this;
- g_bIsRunning = true;
- bool support = Query_AEC_Support();
- return support;
- }
- //--------------------------------------------------------------------------
- bool CAECCMN::Query_AEC_Support(void)
- {
- META_RESULT MetaResult = META_QueryIfFunctionSupportedByTarget_r(m_META_HANDLE_Obj.Get_MainHandle(), 300, "META_Audio_Tone_Loop_Back_Rec");
- if (MetaResult != META_SUCCESS)
- {
- MetaResult = META_QueryIfFunctionSupportedByTarget_r(m_META_HANDLE_Obj.Get_MainHandle(), 300, "META_Audio_Tone_Loop_Back_Rec_2K_r");
- if (MetaResult != META_SUCCESS)
- {
- return false;
- }
- }
- return true;
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- bool CAECCMN::Query_DRC_Support_Start(void)
- {
- g_aec_cmn_ptr = this;
- g_bIsRunning = true;
- m_bDRCSupport = Query_DRC_Support();
- return m_bDRCSupport;
- }
- //--------------------------------------------------------------------------
- bool CAECCMN::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 CAECCMN::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)
- {
- m_bAec2kSupport = false;
- }
- else
- {
- m_bAec2kSupport = true;
- }
- return m_bAec2kSupport;
- }
- //--------------------------------------------------------------------------
- bool CAECCMN::Query_AEC_NM_Support_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)
- {
- m_bAecNMSupport = false;
- }
- else
- {
- m_bAecNMSupport = true;
- }
- return m_bAecNMSupport;
- }
- //===========================================================================
- //////////////////////////// Global information ///////////////////////////
- //===========================================================================
- E_METAAPP_RESULT_T CAECCMN::Get_ConfirmState(void)
- {
- return m_eConfirmState;
- }
- //---------------------------------------------------------------------------
- void CAECCMN::Get_AecNmIni(S_AEC_NM_INI_T& aec_ini)
- {
- aec_ini = m_sAecIni.m_sAecNmIni;
- }