aec_nm.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:22k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   AEC_nm.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  Acoustic Echo Cancellation (AEC) calibration in normal mode source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  * 
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64.  ****************************************************************************/
  65. //---------------------------------------------------------------------------
  66. #include <IniFiles.hpp>
  67. #pragma hdrstop
  68. #ifndef _AEC_NM_H_
  69. #include "aec_nm.h"
  70. #endif
  71. #ifndef  _MAN_ACTIVE_H_
  72. #include "man_active.h"
  73. #endif
  74. #ifndef  _FT_UTILS_H_
  75. #include "ft_utils.h"
  76. #endif
  77. //---------------------------------------------------------------------------
  78. #pragma package(smart_init)
  79. //===========================================================================
  80. static CAECNM*  g_aec_ptr;
  81. //=============================  static function  ==============================
  82. static void REQ_Read_FIR_From_NVRAM(void)
  83. {
  84.     g_aec_ptr->REQ_Read_FIR_From_NVRAM();
  85. }
  86. //----------------------------------------------------------------------------
  87. static void CNF_ReadFirFromNVRAM(void)
  88. {
  89.     g_aec_ptr->CNF_ReadFirFromNVRAM();
  90. }
  91. //----------------------------------------------------------------------------
  92. static void REQ_Write_FIR_To_NVRAM(void)
  93. {
  94.     g_aec_ptr->REQ_Write_FIR_To_NVRAM();
  95. }
  96. //----------------------------------------------------------------------------
  97. static void CNF_WriteFirToNVRAM(void)
  98. {
  99.     g_aec_ptr->CNF_WriteFirToNVRAM();
  100. }
  101. //----------------------------------------------------------------------------
  102. static void REQ_Read_Volume_Setting_From_NVRAM(void)
  103. {
  104.     g_aec_ptr->REQ_Read_Volume_Setting_From_NVRAM();
  105. }
  106. //----------------------------------------------------------------------------
  107. static void CNF_ReadVolSettingFromNVRAM(void)
  108. {
  109.     g_aec_ptr->CNF_ReadVolSettingFromNVRAM();
  110. }
  111. //----------------------------------------------------------------------------
  112. static void CNF_WriteVolSettingToNVRAM(void)
  113. {
  114.     g_aec_ptr->CNF_WriteVolSettingToNVRAM();
  115. }
  116. //----------------------------------------------------------------------------
  117. static void REQ_Audio_Tone_Loop_Back_Rec(void)
  118. {
  119.     //g_aec_ptr->REQ_Audio_Tone_Loop_Back_Rec();
  120. }
  121. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122. void CAECNM::AllocateDynMemory(void)
  123. {
  124.     m_cpBuf = new char[AEC_BUF_SIZE_2K*AEC_PLAY_FREQ_NUM];
  125. }
  126. //---------------------------------------------------------------------------
  127. void CAECNM::ReleaseDynMemory(void)
  128. {
  129.     if (NULL != m_cpBuf)
  130.     {
  131.         delete [] m_cpBuf;
  132.         m_cpBuf = NULL;
  133.     }
  134. }
  135. //==============================================================================
  136. __fastcall CAECNM::CAECNM(bool CreateSuspended, S_AEC_NM_T *p_s_aec_nm): TThread(CreateSuspended)
  137. {
  138.     g_aec_ptr = this;
  139.     m_psAEC = p_s_aec_nm;
  140. }
  141. //----------------------------------------------------------------------------
  142. void __fastcall CAECNM::Execute(void)
  143. {
  144.     AllocateDynMemory();
  145.     // read FIR from NVRAM
  146.     E_METAAPP_RESULT_T metaapp_result = REQ_Read_FIR_From_NVRAM();
  147.     if (metaapp_result != METAAPP_SUCCESS)
  148.     {
  149.         return;
  150.     }
  151.     if (this->Terminated)
  152.     {
  153.         this->OnTerminate = m_psAEC->ne_onTermByUser;
  154.         return;
  155.     }
  156.     // read MIC gain from NVRAM
  157.     metaapp_result = REQ_Read_Volume_Setting_From_NVRAM();
  158.     if (metaapp_result != METAAPP_SUCCESS)
  159.     {
  160.         return;
  161.     }
  162.     if (this->Terminated)
  163.     {
  164.         this->OnTerminate = m_psAEC->ne_onTermByUser;
  165.         return;
  166.     }
  167.     // set MIC gain to DSP
  168.     micresult s_mic_result;
  169.     unsigned char uc_mic_vol_gain;
  170.     unsigned char uc_max_speaker_gain;
  171.     if (m_psAEC->b_cust_vol_16)
  172.     {
  173.         uc_mic_vol_gain = m_sCustVolEx.volume_gain[NORMAL_MODE][MICROPHONE_TYPE][0];
  174.         uc_max_speaker_gain = m_sCustVolEx.volume_gain[NORMAL_MODE][SPEECH_TONE_TYPE][6];
  175.     }
  176.     else
  177.     {
  178.         uc_mic_vol_gain = m_sCustVol.volume_gain[NORMAL_MODE][MICROPHONE_TYPE][0];
  179.         uc_max_speaker_gain = m_sCustVol.volume_gain[NORMAL_MODE][SPEECH_TONE_TYPE][6];
  180.     }
  181.     bool ok = load_mic(&s_mic_result, uc_mic_vol_gain);
  182.     if (!ok)
  183.     {
  184.         return;
  185.     }
  186.     if (this->Terminated)
  187.     {
  188.         this->OnTerminate = m_psAEC->ne_onTermByUser;
  189.         return;
  190.     }
  191.     // playback & record
  192.     for (E_AEC_STEP_T step = AEC_STEP_1; step <= AEC_STEP_3; step++)
  193.     {
  194.         Audio_Tone_LoopBackRec_Req req;
  195.         req.spkgain = uc_max_speaker_gain;
  196.         req.micgain = uc_mic_vol_gain;
  197.         req.ulgain = m_psAEC->s_ini.us_up_digital_gain;
  198.         req.dlgain = m_psAEC->s_ini.us_dn_digital_gain;
  199.         req.amp = m_psAEC->s_ini.us_kt_gain[step-1];
  200.         E_METAAPP_RESULT_T metaapp_result = REQ_Audio_Tone_Loop_Back_Rec(req);
  201.         if (metaapp_result != METAAPP_SUCCESS)
  202.         {
  203.             return;
  204.         }
  205.         if (this->Terminated)
  206.         {
  207.             this->OnTerminate = m_psAEC->ne_onTermByUser;
  208.             return;
  209.         }
  210.         switch (step)
  211.         {
  212.             case AEC_STEP_1:
  213.             {
  214.                 if (!calibrate_step_1_2k_normal(&s_mic_result, (short *)m_cpBuf, m_psAEC->b_debug))
  215.                 {
  216.                     return;
  217.                 }
  218.                 uc_mic_vol_gain = s_mic_result.volume;
  219.                 if (m_psAEC->b_cust_vol_16)
  220.                 {
  221.                     for (int i=0; i<MAX_VOL_LEVEL; i++)
  222.                     {
  223.                         m_sCustVolEx.volume_gain[NORMAL_MODE][MICROPHONE_TYPE][i] = uc_mic_vol_gain;
  224.                     }
  225.                     m_cVOL_SET_Obj.Set_CustVol16(m_sCustVolEx);
  226.                 }
  227.                 else
  228.                 {
  229.                     for (int i=0; i<MAX_VOL_LEVEL; i++)
  230.                     {
  231.                         m_sCustVol.volume_gain[NORMAL_MODE][MICROPHONE_TYPE][i] = uc_mic_vol_gain;
  232.                     }
  233.                     m_cVOL_SET_Obj.Set_CustVol(m_sCustVol);
  234.                 }
  235.                 metaapp_result = REQ_Write_Volume_Setting_To_NVRAM();
  236.                 if (metaapp_result != METAAPP_SUCCESS)
  237.                 {
  238.                     return;
  239.                 }
  240.             }
  241.             break;
  242.             case AEC_STEP_2:
  243.             {
  244.                 if (!calibrate_step_2_2k_normal(&s_mic_result, (short *)m_cpBuf, m_psAEC->b_debug))
  245.                 {
  246.                     return;
  247.                 }
  248.                 uc_mic_vol_gain = s_mic_result.volume;
  249.                 if (m_psAEC->b_cust_vol_16)
  250.                 {
  251.                     for (int i=0; i<MAX_VOL_LEVEL; i++)
  252.                     {
  253.                         m_sCustVolEx.volume_gain[NORMAL_MODE][MICROPHONE_TYPE][i] = uc_mic_vol_gain;
  254.                     }
  255.                     m_cVOL_SET_Obj.Set_CustVol16(m_sCustVolEx);
  256.                 }
  257.                 else
  258.                 {
  259.                     for (int i=0; i<MAX_VOL_LEVEL; i++)
  260.                     {
  261.                         m_sCustVol.volume_gain[NORMAL_MODE][MICROPHONE_TYPE][i] = uc_mic_vol_gain;
  262.                     }
  263.                     m_cVOL_SET_Obj.Set_CustVol(m_sCustVol);
  264.                 }
  265.                 metaapp_result = REQ_Write_Volume_Setting_To_NVRAM();
  266.                 if (metaapp_result != METAAPP_SUCCESS)
  267.                 {
  268.                     return;
  269.                 }
  270.                 // write volume gain to file
  271.                 bool ok = m_cVOL_SET_Obj.REQ_Write_To_File(m_psAEC->as_volume_gain_file.c_str(), true, m_psAEC->b_cust_vol_16);
  272.                 if (!ok)
  273.                 {
  274.                     return;
  275.                 }
  276.             }
  277.             break;
  278.             case AEC_STEP_3:
  279.             {
  280.                 speresult s_sp_result;
  281.                 if ((AUDIO_FIR_VER_W0547_45_TAP == m_psAEC->e_audio_param_type) ||
  282.                     (AUDIO_FIR_VER_W0712        == m_psAEC->e_audio_param_type) ||
  283.                     (AUDIO_FIR_VER_W0740        == m_psAEC->e_audio_param_type)
  284.                    )
  285.                 {
  286.                     if (!calibrate_step_3_2k_normal(&s_sp_result, (short *)m_cpBuf, &s_mic_result, m_psAEC->b_drc_support, m_psAEC->b_debug))
  287.                     {
  288.                         return;
  289.                     }
  290.                 }
  291.                 else
  292.                 {
  293.                     if (!calibrate_step_3_2k_normal_08A(&s_sp_result, (short *)m_cpBuf, &s_mic_result, m_psAEC->b_drc_support, m_psAEC->b_debug))
  294.                     {
  295.                         return;
  296.                     }
  297.                 }
  298.                 m_psAEC->e_result = (E_AEC_RESULT_T) s_sp_result.mechanism;
  299.                 // write normal mode FIR to NVRAM
  300.                 unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_psAEC->e_audio_param_type);
  301.                 if ((AUDIO_FIR_VER_W0547_45_TAP == m_psAEC->e_audio_param_type) ||
  302.                     (AUDIO_FIR_VER_W0712        == m_psAEC->e_audio_param_type) ||
  303.                     (AUDIO_FIR_VER_W0740        == m_psAEC->e_audio_param_type)
  304.                    )
  305.                 {
  306.                     for (int i=0; i<uc_se_mode_para_num; i++)
  307.                     {
  308.                         m_sFirCoeff.us_speech_mode_para[SPEECH_NORMAL_MODE][i] = s_sp_result.sp_enhace[i];
  309.                     }
  310.                     for (int i = uc_se_mode_para_num; i < SE_MODE_PARA_NUM_16; i++)
  311.                     {
  312.                         m_sFirCoeff.us_speech_mode_para[SPEECH_NORMAL_MODE][i] = 0;
  313.                     }
  314.                 }
  315.                 else
  316.                 {
  317.                     for (int i=0; i<uc_se_mode_para_num; i++)
  318.                     {
  319.                         m_sFirCoeff.us_speech_mode_para[SPEECH_NORMAL_MODE][i] = s_sp_result.sp_enhace_08A[i];
  320.                     }
  321.                     for (int i = uc_se_mode_para_num; i < SE_MODE_PARA_NUM_16; i++)
  322.                     {
  323.                         m_sFirCoeff.us_speech_mode_para[SPEECH_NORMAL_MODE][i] = 0;
  324.                     }
  325.                 }
  326.                 m_cSP_COEF_Obj.Set_FirCoef(m_sFirCoeff);
  327.                 metaapp_result = REQ_Write_FIR_To_NVRAM();
  328.                 if (metaapp_result != METAAPP_SUCCESS)
  329.                 {
  330.                     return;
  331.                 }
  332.                 // write to audcoeff_default.h
  333.                 if (!REQ_Write_To_Audcoeff_Default(m_psAEC->as_audcoeff_default_h.c_str(), m_psAEC->e_audio_param_type))
  334.                 {
  335.                     return;
  336.                 }
  337.             }
  338.             break;
  339.         } // switch(step)
  340.     } // for(step)
  341.     this->OnTerminate = m_psAEC->ne_onTermSuccess;
  342. }
  343. //===========================================================================
  344. E_METAAPP_RESULT_T CAECNM::REQ_Read_FIR_From_NVRAM(void)
  345. {
  346.     DWORD wait_result;
  347.     m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  348.     ResetEvent(m_hEvent);
  349.     m_cSP_COEF_Obj.ConfirmCallback = ::CNF_ReadFirFromNVRAM;
  350.     m_cSP_COEF_Obj.REQ_Read_From_NVRAM(m_psAEC->e_audio_param_type);
  351.     wait_result = WaitForSingleObject(m_hEvent, 5000);
  352.     if (WAIT_TIMEOUT == wait_result)
  353.     {
  354.         return METAAPP_TIMEOUT;
  355.     }
  356.     else if (m_eConfirmState != METAAPP_SUCCESS)
  357.     {
  358.         return m_eConfirmState;
  359.     }
  360.     return METAAPP_SUCCESS;
  361. }
  362. //-------------------------------------
  363. void CAECNM::CNF_ReadFirFromNVRAM(void)
  364. {
  365.     m_eConfirmState = m_cSP_COEF_Obj.Get_ConfirmState();
  366.     if (METAAPP_SUCCESS == m_eConfirmState)
  367.     {
  368.         m_cSP_COEF_Obj.Get_FirCoef(m_sFirCoeff);
  369.     }
  370.     SetEvent(m_hEvent);
  371. }
  372. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  373. E_METAAPP_RESULT_T CAECNM::REQ_Write_FIR_To_NVRAM(void)
  374. {
  375.     m_cSP_COEF_Obj.Set_FirCoef(m_sFirCoeff);
  376.     DWORD wait_result;
  377.     m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  378.     ResetEvent(m_hEvent);
  379.     m_cSP_COEF_Obj.ConfirmCallback = ::CNF_WriteFirToNVRAM;
  380.     m_cSP_COEF_Obj.REQ_Write_To_NVRAM(m_psAEC->e_audio_param_type, m_psAEC->b_fir_runtime_support);
  381.     wait_result = WaitForSingleObject(m_hEvent, 5000);
  382.     if (WAIT_TIMEOUT == wait_result)
  383.     {
  384.         return(METAAPP_TIMEOUT);
  385.     }
  386.     else if (m_eConfirmState != METAAPP_SUCCESS)
  387.     {
  388.         return m_eConfirmState;
  389.     }
  390.     return METAAPP_SUCCESS;
  391. }
  392. //-----------------------------------------
  393. void CAECNM::CNF_WriteFirToNVRAM(void)
  394. {
  395.     m_eConfirmState = m_cSP_COEF_Obj.Get_ConfirmState();
  396.     SetEvent(m_hEvent);
  397.     //if (METAAPP_SUCCESS == m_eConfirmState)
  398.     //{
  399.     //    ActiveMan->SetActiveFunction(::REQ_Read_Volume_Setting_From_NVRAM);
  400.     //}
  401.     //else
  402.    // {
  403.    //     Confirm(state);
  404.    // }
  405. }
  406. //===========================================================================
  407. E_METAAPP_RESULT_T CAECNM::REQ_Read_Volume_Setting_From_NVRAM(void)
  408. {
  409.     DWORD wait_result;
  410.     m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  411.     ResetEvent(m_hEvent);
  412.     m_cVOL_SET_Obj.ConfirmCallback = ::CNF_ReadVolSettingFromNVRAM;
  413.     m_cVOL_SET_Obj.REQ_Read_From_NVRAM(m_psAEC->b_cust_vol_16);
  414.     wait_result = WaitForSingleObject(m_hEvent, 5000);
  415.     if (WAIT_TIMEOUT == wait_result)
  416.     {
  417.         return(METAAPP_TIMEOUT);
  418.     }
  419.     else if (m_eConfirmState != METAAPP_SUCCESS)
  420.     {
  421.         return m_eConfirmState;
  422.     }
  423.     return METAAPP_SUCCESS;
  424. }
  425. //--------------------------------------------
  426. void CAECNM::CNF_ReadVolSettingFromNVRAM(void)
  427. {
  428.     m_eConfirmState = m_cVOL_SET_Obj.Get_ConfirmState();
  429.     if (m_eConfirmState == METAAPP_SUCCESS)
  430.     {
  431.         if (m_psAEC->b_cust_vol_16)
  432.         {
  433.             CustAcousticVol16lvl_T* p_cust_vol = m_cVOL_SET_Obj.Get_CustVol16();
  434.             m_sCustVolEx = *p_cust_vol;
  435.             #if 0
  436.             for (int level=0; level<CUST_VOL_LEVEL_NUM; level++)
  437.             {
  438.                 m_sCustVolEx.volume_gain[HANDSFREE_MODE][SPEECH_TONE_TYPE][level] = m_sSpkGain.volume[level];
  439.                 m_sCustVolEx.volume_gain[HANDSFREE_MODE][MICROPHONE_TYPE][level]  = m_sMicGain.volume;
  440.             }
  441.             m_cVOL_SET_Obj.Set_CustVol16(m_sCustVolEx);
  442.             #endif
  443.         }
  444.         else
  445.         {
  446.             CustAcousticVol_T* p_cust_vol = m_cVOL_SET_Obj.Get_CustVol();
  447.             m_sCustVol = *p_cust_vol;
  448.             #if 0
  449.             for (int level=0; level<CUST_VOL_LEVEL_NUM; level++)
  450.             {
  451.                 m_sCustVol.volume_gain[HANDSFREE_MODE][SPEECH_TONE_TYPE][level] = m_sSpkGain.volume[level];
  452.                 m_sCustVol.volume_gain[HANDSFREE_MODE][MICROPHONE_TYPE][level]  = m_sMicGain.volume;
  453.             }
  454.             m_cVOL_SET_Obj.Set_CustVol(m_sCustVol);
  455.             #endif
  456.         }
  457.             //REQ_Write_Volume_Setting_To_NVRAM();
  458.     }
  459.     SetEvent(m_hEvent);
  460. }
  461. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  462. E_METAAPP_RESULT_T CAECNM::REQ_Write_Volume_Setting_To_NVRAM(void)
  463. {
  464.     DWORD wait_result;
  465.     m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
  466.     ResetEvent(m_hEvent);
  467.     m_cVOL_SET_Obj.ConfirmCallback = ::CNF_WriteVolSettingToNVRAM;
  468.     m_cVOL_SET_Obj.REQ_Write_To_NVRAM(m_psAEC->b_cust_vol_16, m_psAEC->b_cust_vol_runtime_support);
  469.     wait_result = WaitForSingleObject(m_hEvent, 5000);
  470.     if (WAIT_TIMEOUT == wait_result)
  471.     {
  472.         return(METAAPP_TIMEOUT);
  473.     }
  474.     else if (m_eConfirmState != METAAPP_SUCCESS)
  475.     {
  476.         return m_eConfirmState;
  477.     }
  478.     return METAAPP_SUCCESS;
  479. }
  480. //-------------------------------------------------
  481. void CAECNM::CNF_WriteVolSettingToNVRAM(void)
  482. {
  483.     E_METAAPP_RESULT_T state = m_cVOL_SET_Obj.Get_ConfirmState();
  484.     if (state != METAAPP_SUCCESS)
  485.     {
  486.         //Confirm(state);
  487.         return;
  488.     }
  489.     SetEvent(m_hEvent);
  490. #if 0
  491.     // write volume gain to file
  492.     bool ok = m_cVOL_SET_Obj.REQ_Write_To_File(m_psAEC->as_volume_gain_file.c_str(), true, m_psAEC->b_cust_vol_16);
  493.     if (!ok)
  494.     {
  495.         Confirm(METAAPP_FAIL);
  496.     }
  497.     else
  498.     {
  499.         Confirm(METAAPP_SUCCESS);
  500.     }
  501. #endif
  502. }
  503. //---------------------------------------------------------------------------
  504. E_METAAPP_RESULT_T CAECNM::REQ_Audio_Tone_Loop_Back_Rec(Audio_Tone_LoopBackRec_Req req)
  505. {
  506.     META_RESULT MetaResult;
  507.     Audio_Tone_LoopBackRec_Cnf_2K cnf_2k;
  508.     unsigned short us_freq[] = {500, 750, 1000, 1500, 2000, 2500, 3000, 3500};
  509.    // if (!calibrate_mic(&m_sMicGain, m_psAEC->i_micgain, (int) m_psAEC->e_mic_device_type))
  510.    // {
  511.    //     Confirm(METAAPP_FAIL);
  512.    //     return;
  513.    // }
  514.    // if (!calibrate_spk(&m_sSpkGain, m_psAEC->i_spkgain, (int) m_psAEC->e_speaker_dac_type))
  515.    // {
  516.    //     Confirm(METAAPP_FAIL);
  517.    //     return;
  518.    // }
  519. //    req.spkgain = m_sSpkGain.cal_gain;
  520. //    req.micgain = m_sMicGain.cal_gain;
  521. //    req.ulgain  = m_usUpDigiGain;
  522. //    req.dlgain  = m_usDnDigiGain;
  523. //    req.amp     = m_usKTGain[m_eStep-1];
  524.     for (int freq_idx=0; freq_idx<AEC_PLAY_FREQ_NUM; freq_idx++)
  525.     {
  526.         req.fre = us_freq[freq_idx];
  527.         MetaResult = META_Audio_Tone_Loop_Back_Rec_2K_Normal_r(m_META_HANDLE_Obj.Get_MainHandle(), 15000 , &req, &cnf_2k);
  528.         if (MetaResult != META_SUCCESS)
  529.         {
  530.             if (MetaResult != META_TIMEOUT)
  531.             {
  532.                 return METAAPP_FAIL;
  533.             }
  534.             else
  535.             {
  536.                 return METAAPP_TIMEOUT;
  537.             }
  538.         }
  539.         memcpy((void *)(m_cpBuf+freq_idx*AEC_BUF_SIZE_2K), (void *)cnf_2k.buffer, AEC_BUF_SIZE_2K);
  540.     }
  541.     return METAAPP_SUCCESS;
  542. }
  543. //===========================================================================
  544. //////////////////////////////        File        ///////////////////////////
  545. //===========================================================================
  546. bool CAECNM::REQ_Write_To_Audcoeff_Default(char *filename, E_AUDIO_FIR_VER_T audio_param_type)
  547. {
  548.     if ((AUDIO_FIR_VER_ORG == audio_param_type) || (AUDIO_FIR_VER_W0547 == audio_param_type))
  549.     {
  550.         return false;
  551.     }
  552.     FILE *fs;
  553.     fs = fopen(filename, "w");
  554.     if (NULL == fs)
  555.     {
  556.         return false;
  557.     }
  558.    // fprintf(fs, "#ifndef AUDCOEFF_COMMON_DOT_Hn");
  559.    // fprintf(fs, "#define AUDCOEFF_COMMON_DOT_Hnn");
  560.     fprintf(fs, "#define DEFAULT_SPEECH_NORMAL_MODE_PARA \");
  561.     fprintf(fs, "n");
  562.     fprintf(fs, "{ \");
  563.     fprintf(fs, "n");
  564.     unsigned char uc_se_mode_para_num = m_cSP_COEF_Obj.Get_SpeechModeDependentParameterNum(m_psAEC->e_audio_param_type);
  565.     for (int i=0; i<uc_se_mode_para_num; i++)
  566.     {
  567.         fprintf(fs, "%6d", m_sFirCoeff.us_speech_mode_para[SPEECH_NORMAL_MODE][i]);
  568.         if (i != uc_se_mode_para_num - 1)
  569.         {
  570.             fprintf(fs, ",");
  571.         }
  572.         else
  573.         {
  574.             fprintf(fs, " \");
  575.         }
  576.     }
  577.     fprintf(fs, "n}nn");
  578.    // fprintf(fs, "#endif // ... AUDCOEFF_COMMON_DOT_Hnn");
  579.     fclose(fs);
  580.     return true;
  581. }
  582. //---------------------------------------------------------------------------
  583. bool CAECNM::REQ_Write_Record_To_File(char *filename)
  584. {
  585.     FILE *fs;
  586.     fs = fopen(filename, "wb");
  587.     if (NULL == fs)
  588.     {
  589.         return false;
  590.     }
  591.     if (AEC_TYPE_LOUD_SPEAKER_8K == m_psAEC->e_aec_type)
  592.     {
  593.         fwrite(m_cpBuf, AEC_BUF_SIZE_8K*AEC_PLAY_FREQ_NUM, 1, fs);
  594.     }
  595.     else
  596.     {
  597.         fwrite(m_cpBuf, AEC_BUF_SIZE_2K*AEC_PLAY_FREQ_NUM, 1, fs);
  598.     }
  599.     fclose(fs);
  600.     return true;
  601. }