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

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.  *   sp_coef.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  Acoustic FIR coefficient 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. #include <IniFiles.hpp>
  66. #pragma hdrstop
  67. #ifndef  _SP_COEF_H_
  68. #include "sp_coef.h"
  69. #endif
  70. #ifndef  _MAN_ACTIVE_H_
  71. #include "man_active.h"
  72. #endif
  73. #ifndef  _MISC_H_
  74. #include "misc.h"
  75. #endif
  76. #ifndef  _FT_UTILS_H_
  77. #include "ft_utils.h"
  78. #endif
  79. #ifndef  _NVRAM_VER_H_
  80. #include "nvram_ver.h"
  81. #endif
  82. //===========================================================================
  83. static const char  Additional_8k_Output_Name[][32] =
  84. {
  85.    "Additional 8k 1st Output",
  86.    "Additional 8k 2nd Output",
  87.    "Additional 8k 3rd Output",
  88.    "Additional 8k 4th Output",
  89.    "Additional 8k 5th Output",
  90. };
  91. static CSPCOEF*  sp_coef_ptr;
  92. static bool g_bIsRunning;
  93. //===========================================================================
  94. static void CNF_ReadFromNVRAM(void)
  95. {
  96.     sp_coef_ptr->CNF_ReadFromNVRAM();
  97. }
  98. //---------------------------------------------------------------------------
  99. static void CNF_WriteToNVRAM(void)
  100. {
  101.     sp_coef_ptr->CNF_WriteToNVRAM();
  102. }
  103. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  104. static void REQ_Get_Runtime_Audio_Param_Settings(void)
  105. {
  106.     sp_coef_ptr->REQ_Get_Runtime_Audio_Param_Settings();
  107. }
  108. //---------------------------------------------------------------------------
  109. static void REQ_Set_Runtime_Audio_Param_Settings(void)
  110. {
  111.     sp_coef_ptr->REQ_Set_Runtime_Audio_Param_Settings();
  112. }
  113. //===========================================================================
  114. CSPCOEF::CSPCOEF( void )
  115. {
  116.     g_bIsRunning = false;
  117.     ConfirmCallback = 0;
  118.     m_iCoefBufSize = 0;
  119.     m_cpCoefBuf = 0;
  120. }
  121. //---------------------------------------------------------------------------
  122. CSPCOEF::~CSPCOEF( )
  123. {
  124.     g_bIsRunning = false;
  125.     ConfirmCallback = 0;
  126.     if(m_cpCoefBuf)
  127.     {
  128.         delete [] m_cpCoefBuf;
  129.         m_cpCoefBuf = NULL;
  130.     }
  131. }
  132. //---------------------------------------------------------------------------
  133. void  CSPCOEF::REQ_Stop( void )
  134. {
  135.     if(!g_bIsRunning)
  136.     {
  137.         return;
  138.     }
  139.    META_Cancel_r( m_META_HANDLE_Obj.Get_MainHandle(), m_sSPID_COEF );
  140.    Confirm(METAAPP_STOP);
  141.    g_bIsRunning = false;
  142. }
  143. //---------------------------------------------------------------------------
  144. void CSPCOEF::Confirm(E_METAAPP_RESULT_T confirm_state)
  145. {
  146.     if(!g_bIsRunning)  return;
  147.     g_bIsRunning = false;
  148.     if(ConfirmCallback==0)  return;
  149.     m_eConfirmState = confirm_state;
  150.     ActiveMan->SetActiveFunction( ConfirmCallback );
  151. }
  152. //===========================================================================
  153. ///////////////////////////  Compose / decompse  ////////////////////////////
  154. //===========================================================================
  155. void CSPCOEF::Compose_FirCoefOrg(S_FIR_COEFF_T fir, l1audio_param_T &fir_org)
  156. {
  157.     fir_org.Speech_FIR[0]                = fir.s_Speech_FIR[0];
  158.     fir_org.Speech_FIR[1]                = fir.s_Speech_FIR[1];
  159.     fir_org.Melody_FIR[0]                = fir.s_Melody_FIR[0];
  160.     fir_org.Melody_FIR[1]                = fir.s_Melody_FIR[0];
  161.     fir_org.ES_TimeConst                 = fir.us_ES_TimeConst;
  162.     fir_org.ES_VolConst                  = fir.us_ES_VolConst;
  163.     fir_org.ES_TimeConst2                = fir.us_ES_TimeConst2;
  164.     fir_org.ES_VolConst2                 = fir.us_ES_VolConst2;
  165.     fir_org.Media_Playback_Maximum_Swing = fir.us_Media_Playback_Maximum_Swing;
  166. }
  167. //---------------------------------------------------------------------------
  168. void CSPCOEF::DeCompose_FirCoefOrg(l1audio_param_T fir_org, S_FIR_COEFF_T& fir)
  169. {
  170.     fir.s_Speech_FIR[0]                 = fir_org.Speech_FIR[0];
  171.     fir.s_Speech_FIR[1]                 = fir_org.Speech_FIR[1];
  172.     fir.s_Melody_FIR[0]                 = fir_org.Melody_FIR[0];
  173.     fir.s_Melody_FIR[0]                 = fir_org.Melody_FIR[1];
  174.     fir.us_ES_TimeConst                 = fir_org.ES_TimeConst;
  175.     fir.us_ES_VolConst                  = fir_org.ES_VolConst;
  176.     fir.us_ES_TimeConst2                = fir_org.ES_TimeConst2;
  177.     fir.us_ES_VolConst2                 = fir_org.ES_VolConst2;
  178.     fir.us_Media_Playback_Maximum_Swing = fir_org.Media_Playback_Maximum_Swing;
  179. }
  180. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  181. void CSPCOEF::Compose_FirCoef0547(S_FIR_COEFF_T fir, l1audio_param_W0547_T &fir0547)
  182. {
  183.     fir0547.Speech_FIR[0] = fir.s_Speech_FIR[0];
  184.     fir0547.Speech_FIR[1] = fir.s_Speech_FIR[1];
  185.     fir0547.Melody_FIR[0] = fir.s_Melody_FIR[0];
  186.     fir0547.Melody_FIR[1] = fir.s_Melody_FIR[1];
  187.     for (int i = 0; i < SE_SPEECH_COMMON_NUM_12; i++)
  188.     {
  189.         fir0547.Speech_Common_Para[i] = fir.us_speech_common_para[i];
  190.     }
  191.     for (int i = 0; i < SE_MODE_NUM; i++)
  192.     {
  193.         for (int j = 0; j < SE_MODE_PARA_NUM_8; j++)
  194.         {
  195.             fir0547.Speech_ModeDependent_Para[i][j] = fir.us_speech_mode_para[i][j];
  196.         }
  197.     }
  198.     fir0547.Media_Playback_Maximum_Swing = fir.us_Media_Playback_Maximum_Swing;
  199. }
  200. //---------------------------------------------------------------------------
  201. void CSPCOEF::DeCompose_FirCoef0547(l1audio_param_W0547_T fir0547, S_FIR_COEFF_T& fir)
  202. {
  203.     fir.s_Speech_FIR[0] = fir0547.Speech_FIR[0];
  204.     fir.s_Speech_FIR[1] = fir0547.Speech_FIR[1];
  205.     fir.s_Melody_FIR[0] = fir0547.Melody_FIR[0];
  206.     fir.s_Melody_FIR[1] = fir0547.Melody_FIR[1];
  207.     for (int i = 0; i < SE_SPEECH_COMMON_NUM_12; i++)
  208.     {
  209.         fir.us_speech_common_para[i] = fir0547.Speech_Common_Para[i];
  210.     }
  211.     for (int i = 0; i < SE_MODE_NUM; i++)
  212.     {
  213.         for (int j = 0; j < SE_MODE_PARA_NUM_8; j++)
  214.         {
  215.             fir.us_speech_mode_para[i][j]= fir0547.Speech_ModeDependent_Para[i][j];
  216.         }
  217.     }
  218.     fir.us_Media_Playback_Maximum_Swing = fir0547.Media_Playback_Maximum_Swing;
  219. }
  220. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221. void CSPCOEF::Compose_FirCoef0547_45Taps(S_FIR_COEFF_T fir, l1audio_param_W0547_45_T &fir0547_45tap)
  222. {
  223.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  224.     {
  225.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  226.         {
  227.             fir0547_45tap.speech_input_FIR_coeffs[i][j]  = fir.s_speech_input_FIR_coeffs[i][j];
  228.             fir0547_45tap.speech_output_FIR_coeffs[i][j] = fir.s_speech_output_FIR_coeffs[i][j];
  229.         }
  230.     }
  231.     fir0547_45tap.selected_FIR_output_index = fir.us_selected_FIR_output_index;
  232.     for (int i = 0; i < SE_SPEECH_COMMON_NUM_12; i++)
  233.     {
  234.         fir0547_45tap.speech_common_para[i] = fir.us_speech_common_para[i];
  235.     }
  236.     for (int i = 0; i < SE_MODE_PARA_NUM_8; i++)
  237.     {
  238.         fir0547_45tap.speech_normal_mode_para[i]      = fir.us_speech_mode_para[SPEECH_NORMAL_MODE][i];
  239.         fir0547_45tap.speech_earphone_mode_para[i]    = fir.us_speech_mode_para[SPEECH_EARPHONE_MODE][i];
  240.         fir0547_45tap.speech_loudspk_mode_para[i]     = fir.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i];
  241.         fir0547_45tap.speech_bt_earphone_mode_para[i] = fir.us_speech_mode_para[SPEECH_BT_ERAPHONE_MODE][i];
  242.         fir0547_45tap.speech_bt_cordless_mode_para[i] = fir.us_speech_mode_para[SPEECH_BT_CORDLESS_MODE][i];
  243.         fir0547_45tap.speech_aux1_mode_para[i]        = fir.us_speech_mode_para[SPEECH_AUX1_MODE][i];
  244.         fir0547_45tap.speech_aux2_mode_para[i]        = fir.us_speech_mode_para[SPEECH_AUX2_MODE][i];
  245.         fir0547_45tap.speech_aux3_mode_para[i]        = fir.us_speech_mode_para[SPEECH_AUX3_MODE][i];
  246.     }
  247.     fir0547_45tap.Media_Playback_Maximum_Swing = fir.us_Media_Playback_Maximum_Swing;
  248.     for (int i = 0; i < SPEECH_FIR_45_TAPS_NUM; i++)
  249.     {
  250.         fir0547_45tap.Melody_FIR_Output_Coeff_32k_Tbl1[i] = fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i];
  251.     }
  252. }
  253. //---------------------------------------------------------------------------
  254. void CSPCOEF::DeCompose_FirCoef0547_45Taps(l1audio_param_W0547_45_T fir0547_45tap, S_FIR_COEFF_T& fir)
  255. {
  256.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  257.     {
  258.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  259.         {
  260.             fir.s_speech_input_FIR_coeffs[i][j]  = fir0547_45tap.speech_input_FIR_coeffs[i][j];
  261.             fir.s_speech_output_FIR_coeffs[i][j] = fir0547_45tap.speech_output_FIR_coeffs[i][j];
  262.         }
  263.     }
  264.     fir.us_selected_FIR_output_index = fir0547_45tap.selected_FIR_output_index;
  265.     for (int i = 0; i < SE_SPEECH_COMMON_NUM_12; i++)
  266.     {
  267.         fir.us_speech_common_para[i] = fir0547_45tap.speech_common_para[i];
  268.     }
  269.     for (int i = 0; i < SE_MODE_PARA_NUM_8; i++)
  270.     {
  271.         fir.us_speech_mode_para[SPEECH_NORMAL_MODE][i]      = fir0547_45tap.speech_normal_mode_para[i];
  272.         fir.us_speech_mode_para[SPEECH_EARPHONE_MODE][i]    = fir0547_45tap.speech_earphone_mode_para[i];
  273.         fir.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i] = fir0547_45tap.speech_loudspk_mode_para[i];
  274.         fir.us_speech_mode_para[SPEECH_BT_ERAPHONE_MODE][i] = fir0547_45tap.speech_bt_earphone_mode_para[i];
  275.         fir.us_speech_mode_para[SPEECH_BT_CORDLESS_MODE][i] = fir0547_45tap.speech_bt_cordless_mode_para[i] ;
  276.         fir.us_speech_mode_para[SPEECH_AUX1_MODE][i]        = fir0547_45tap.speech_aux1_mode_para[i];
  277.         fir.us_speech_mode_para[SPEECH_AUX2_MODE][i]        = fir0547_45tap.speech_aux2_mode_para[i];
  278.         fir.us_speech_mode_para[SPEECH_AUX3_MODE][i]        = fir0547_45tap.speech_aux3_mode_para[i];
  279.     }
  280.     fir.us_Media_Playback_Maximum_Swing                     = fir0547_45tap.Media_Playback_Maximum_Swing;
  281.     for (int i = 0; i < SPEECH_FIR_45_TAPS_NUM; i++)
  282.     {
  283.         fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i]      = fir0547_45tap.Melody_FIR_Output_Coeff_32k_Tbl1[i];
  284.     }
  285. }
  286. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  287. void CSPCOEF::Compose_FirCoef0712(S_FIR_COEFF_T fir, l1audio_param_W0712_T &fir0712)
  288. {
  289.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  290.     {
  291.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  292.         {
  293.             fir0712.speech_input_FIR_coeffs[i][j]  = fir.s_speech_input_FIR_coeffs[i][j];
  294.             fir0712.speech_output_FIR_coeffs[i][j] = fir.s_speech_output_FIR_coeffs[i][j];
  295.         }
  296.     }
  297.     fir0712.selected_FIR_output_index      = fir.us_selected_FIR_output_index;
  298.     for (int i=0; i < SE_SPEECH_COMMON_NUM_12; i++)
  299.     {
  300.         fir0712.speech_common_para[i] = fir.us_speech_common_para[i];
  301.     }
  302.     for (int i = 0; i < SE_MODE_PARA_NUM_8; i++)
  303.     {
  304.         fir0712.speech_normal_mode_para[i]      = fir.us_speech_mode_para[SPEECH_NORMAL_MODE][i];
  305.         fir0712.speech_earphone_mode_para[i]    = fir.us_speech_mode_para[SPEECH_EARPHONE_MODE][i];
  306.         fir0712.speech_loudspk_mode_para[i]     = fir.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i];
  307.         fir0712.speech_bt_earphone_mode_para[i] = fir.us_speech_mode_para[SPEECH_BT_ERAPHONE_MODE][i];
  308.         fir0712.speech_bt_cordless_mode_para[i] = fir.us_speech_mode_para[SPEECH_BT_CORDLESS_MODE][i];
  309.         fir0712.speech_aux1_mode_para[i]        = fir.us_speech_mode_para[SPEECH_AUX1_MODE][i];
  310.         fir0712.speech_aux2_mode_para[i]        = fir.us_speech_mode_para[SPEECH_AUX2_MODE][i];
  311.         fir0712.speech_aux3_mode_para[i]        = fir.us_speech_mode_para[SPEECH_AUX3_MODE][i];
  312.     }
  313.     fir0712.Media_Playback_Maximum_Swing = fir.us_Media_Playback_Maximum_Swing;
  314.     for (int i = 0; i < MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  315.     {
  316.         fir0712.Melody_FIR_Output_Coeff_32k_Tbl1[i] = fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i];
  317.     }
  318. }
  319. //---------------------------------------------------------------------------
  320. void CSPCOEF::DeCompose_FirCoef0712(l1audio_param_W0712_T fir0712, S_FIR_COEFF_T& fir)
  321. {
  322.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  323.     {
  324.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  325.         {
  326.             fir.s_speech_input_FIR_coeffs[i][j]  = fir0712.speech_input_FIR_coeffs[i][j];
  327.             fir.s_speech_output_FIR_coeffs[i][j] = fir0712.speech_output_FIR_coeffs[i][j];
  328.         }
  329.     }
  330.     fir.us_selected_FIR_output_index = fir0712.selected_FIR_output_index;
  331.     for (int i=0; i < SE_SPEECH_COMMON_NUM_12; i++)
  332.     {
  333.         fir.us_speech_common_para[i] = fir0712.speech_common_para[i];
  334.     }
  335.     for (int i = 0; i < SE_MODE_PARA_NUM_8; i++)
  336.     {
  337.         fir.us_speech_mode_para[SPEECH_NORMAL_MODE][i]      = fir0712.speech_normal_mode_para[i];
  338.         fir.us_speech_mode_para[SPEECH_EARPHONE_MODE][i]    = fir0712.speech_earphone_mode_para[i];
  339.         fir.us_speech_mode_para[SPEECH_LOUDSPEAKER_MODE][i] = fir0712.speech_loudspk_mode_para[i];
  340.         fir.us_speech_mode_para[SPEECH_BT_ERAPHONE_MODE][i] = fir0712.speech_bt_earphone_mode_para[i];
  341.         fir.us_speech_mode_para[SPEECH_BT_CORDLESS_MODE][i] = fir0712.speech_bt_cordless_mode_para[i];
  342.         fir.us_speech_mode_para[SPEECH_AUX1_MODE][i]        = fir0712.speech_aux1_mode_para[i];
  343.         fir.us_speech_mode_para[SPEECH_AUX2_MODE][i]        = fir0712.speech_aux2_mode_para[i];
  344.         fir.us_speech_mode_para[SPEECH_AUX3_MODE][i]        = fir0712.speech_aux3_mode_para[i];
  345.     }
  346.     fir.us_Media_Playback_Maximum_Swing = fir0712.Media_Playback_Maximum_Swing;
  347.     for (int i = 0; i < MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  348.     {
  349.         fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i] = fir0712.Melody_FIR_Output_Coeff_32k_Tbl1[i];
  350.     }
  351. }
  352. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  353. void CSPCOEF::Compose_FirCoef0740(S_FIR_COEFF_T fir, l1audio_param_W0740_T &fir0740)
  354. {
  355.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  356.     {
  357.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  358.         {
  359.             fir0740.speech_input_FIR_coeffs[i][j]  = fir.s_speech_input_FIR_coeffs[i][j];
  360.             fir0740.speech_output_FIR_coeffs[i][j] = fir.s_speech_output_FIR_coeffs[i][j];
  361.         }
  362.     }
  363.     fir0740.selected_FIR_output_index = fir.us_selected_FIR_output_index;
  364.     for (int i=0; i < SE_SPEECH_COMMON_NUM_12; i++)
  365.     {
  366.         fir0740.speech_common_para[i] = fir.us_speech_common_para[i];
  367.     }
  368.     for (int i = 0; i < SE_MODE_NUM; i++)
  369.     {
  370.         for (int j = 0; j < SE_MODE_PARA_NUM_8; j++)
  371.         {
  372.             fir0740.speech_mode_para[i][j] = fir.us_speech_mode_para[i][j];
  373.         }
  374.     }
  375.     fir0740.Media_Playback_Maximum_Swing = fir.us_Media_Playback_Maximum_Swing;
  376.     for (int i = 0; i < MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  377.     {
  378.         fir0740.Melody_FIR_Coeff_Tbl[i] = fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i];
  379.     }
  380.     for (int i = 0; i < 2; i++)
  381.     {
  382.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  383.         {
  384.             fir0740.audio_compensation_coeff[i][j] = fir.s_audio_compensation_coeff[i][j];
  385.         }
  386.     }
  387. }
  388. //----------------------------------------------------------------------------
  389. void CSPCOEF::DeCompose_FirCoef0740(l1audio_param_W0740_T fir0740, S_FIR_COEFF_T& fir)
  390. {
  391.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  392.     {
  393.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  394.         {
  395.             fir.s_speech_input_FIR_coeffs[i][j]  = fir0740.speech_input_FIR_coeffs[i][j];
  396.             fir.s_speech_output_FIR_coeffs[i][j] = fir0740.speech_output_FIR_coeffs[i][j];
  397.         }
  398.     }
  399.     fir0740.selected_FIR_output_index = fir.us_selected_FIR_output_index;
  400.     for (int i=0; i < SE_SPEECH_COMMON_NUM_12; i++)
  401.     {
  402.         fir.us_speech_common_para[i] = fir0740.speech_common_para[i];
  403.     }
  404.     for (int i = 0; i < SE_MODE_NUM; i++)
  405.     {
  406.         for (int j = 0; j < SE_MODE_PARA_NUM_8; j++)
  407.         {
  408.             fir.us_speech_mode_para[i][j] = fir0740.speech_mode_para[i][j];
  409.         }
  410.     }
  411.     fir.us_Media_Playback_Maximum_Swing = fir0740.Media_Playback_Maximum_Swing;
  412.     for (int i = 0; i < MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  413.     {
  414.         fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i] = fir0740.Melody_FIR_Coeff_Tbl[i];
  415.     }
  416.     for (int i = 0; i < 2; i++)
  417.     {
  418.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  419.         {
  420.             fir.s_audio_compensation_coeff[i][j] = fir0740.audio_compensation_coeff[i][j];
  421.         }
  422.     }
  423. }
  424. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  425. void CSPCOEF::Compose_FirCoef0809(S_FIR_COEFF_T fir, l1audio_param_W0809_T &fir0809)
  426. {
  427.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  428.     {
  429.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  430.         {
  431.             fir0809.speech_input_FIR_coeffs[i][j]  = fir.s_speech_input_FIR_coeffs[i][j];
  432.             fir0809.speech_output_FIR_coeffs[i][j] = fir.s_speech_output_FIR_coeffs[i][j];
  433.         }
  434.     }
  435.     fir0809.selected_FIR_output_index = fir.us_selected_FIR_output_index;
  436.     for (int i=0; i < SE_SPEECH_COMMON_NUM_12; i++)
  437.     {
  438.         fir0809.speech_common_para[i] = fir.us_speech_common_para[i];
  439.     }
  440.     for (int i = 0; i < SE_MODE_NUM; i++)
  441.     {
  442.         for (int j = 0; j < SE_MODE_PARA_NUM_16; j++)
  443.         {
  444.             fir0809.speech_mode_para[i][j] = fir.us_speech_mode_para[i][j];
  445.         }
  446.     }
  447.     for (int i = 0; i < SE_VOLUME_MODE_NUM; i++)
  448.     {
  449.         for (int j = 0; j < SE_VOLUME_LEVEL_NUM; j++)
  450.         {
  451.             for (int k = 0; k < SE_VOLUME_LEVEL_NUM; k++)
  452.             {
  453.                 fir0809.speech_volume_para[i][j][k] = fir.us_speech_volume_para[i][j][k];
  454.             }
  455.         }
  456.     }
  457.     fir0809.Media_Playback_Maximum_Swing = fir.us_Media_Playback_Maximum_Swing;
  458.     for (int i = 0; i < MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  459.     {
  460.         fir0809.Melody_FIR_Coeff_Tbl[i] = fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i];
  461.     }
  462.     for (int i = 0; i < 2; i++)
  463.     {
  464.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  465.         {
  466.             fir0809.audio_compensation_coeff[i][j] = fir.s_audio_compensation_coeff[i][j];
  467.         }
  468.     }    
  469. }
  470. //----------------------------------------------------------------------------
  471. void CSPCOEF::DeCompose_FirCoef0809(l1audio_param_W0809_T fir0809, S_FIR_COEFF_T& fir)
  472. {
  473.     for (int i = 0; i < SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  474.     {
  475.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  476.         {
  477.             fir.s_speech_input_FIR_coeffs[i][j] = fir0809.speech_input_FIR_coeffs[i][j];
  478.             fir.s_speech_output_FIR_coeffs[i][j] = fir0809.speech_output_FIR_coeffs[i][j];
  479.         }
  480.     }
  481.     fir.us_selected_FIR_output_index = fir0809.selected_FIR_output_index;
  482.     for (int i=0; i < SE_SPEECH_COMMON_NUM_12; i++)
  483.     {
  484.         fir.us_speech_common_para[i] = fir0809.speech_common_para[i];
  485.     }
  486.     for (int i = 0; i < SE_MODE_NUM; i++)
  487.     {
  488.         for (int j = 0; j < SE_MODE_PARA_NUM_16; j++)
  489.         {
  490.             fir.us_speech_mode_para[i][j] = fir0809.speech_mode_para[i][j];
  491.         }
  492.     }
  493.     for (int i = 0; i < SE_VOLUME_MODE_NUM; i++)
  494.     {
  495.         for (int j = 0; j < SE_VOLUME_LEVEL_NUM; j++)
  496.         {
  497.             for (int k = 0; k < SE_VOLUME_LEVEL_NUM; k++)
  498.             {
  499.                 fir.us_speech_volume_para[i][j][k] = fir0809.speech_volume_para[i][j][k];
  500.             }
  501.         }
  502.     }
  503.     fir.us_Media_Playback_Maximum_Swing = fir0809.Media_Playback_Maximum_Swing;
  504.     for (int i = 0; i < MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  505.     {
  506.         fir.s_Melody_FIR[0].Melody_32k_Output_Coeff[i] = fir0809.Melody_FIR_Coeff_Tbl[i];
  507.     }
  508.     for (int i = 0; i < 2; i++)
  509.     {
  510.         for (int j = 0; j < SPEECH_FIR_45_TAPS_NUM; j++)
  511.         {
  512.             fir.s_audio_compensation_coeff[i][j] = fir0809.audio_compensation_coeff[i][j];
  513.         }
  514.     }
  515. }
  516. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  517. bool CSPCOEF::Decompose_FirCoef(E_AUDIO_FIR_VER_T audio_para_type)
  518. {
  519.     META_RESULT MetaResult;
  520.     switch (audio_para_type)
  521.     {
  522.         case AUDIO_FIR_VER_ORG:
  523.         {
  524.             l1audio_param_T fir_org;
  525.             MetaResult = META_NVRAM_Decompose_AudioParam(&fir_org, m_cpCoefBuf,  m_iCoefBufSize);
  526.             DeCompose_FirCoefOrg(fir_org, m_sFirCoeff);
  527.         }
  528.         break;
  529.         case AUDIO_FIR_VER_W0547:
  530.         {
  531.             l1audio_param_W0547_T fir0547;
  532.             MetaResult = META_NVRAM_Decompose_AudioParam_W0547(&fir0547, m_cpCoefBuf,  m_iCoefBufSize);
  533.             DeCompose_FirCoef0547(fir0547, m_sFirCoeff);
  534.         }
  535.         break;
  536.         case AUDIO_FIR_VER_W0547_45_TAP:
  537.         {
  538.             l1audio_param_W0547_45_T fir0547_45tap;
  539.             MetaResult = META_NVRAM_Decompose_AudioParam_W0547_45(&fir0547_45tap, m_cpCoefBuf,  m_iCoefBufSize);
  540.             DeCompose_FirCoef0547_45Taps(fir0547_45tap, m_sFirCoeff);
  541.         }
  542.         break;
  543.         case AUDIO_FIR_VER_W0712:
  544.         {
  545.             l1audio_param_W0712_T fir0712;
  546.             MetaResult = META_NVRAM_Decompose_AudioParam_W0712(&fir0712, m_cpCoefBuf,  m_iCoefBufSize);
  547.             DeCompose_FirCoef0712(fir0712, m_sFirCoeff);
  548.         }
  549.         break;
  550.         case AUDIO_FIR_VER_W0740:
  551.         {
  552.             l1audio_param_W0740_T fir0740;
  553.             MetaResult = META_NVRAM_Decompose_AudioParam_W0740(&fir0740, m_cpCoefBuf,  m_iCoefBufSize);
  554.             DeCompose_FirCoef0740(fir0740, m_sFirCoeff);
  555.         }
  556.         break;
  557.         case AUDIO_FIR_VER_W0809:
  558.         {
  559.             l1audio_param_W0809_T fir0809;
  560.             MetaResult = META_NVRAM_Decompose_AudioParam_W0809(&fir0809, m_cpCoefBuf,  m_iCoefBufSize);
  561.             DeCompose_FirCoef0809(fir0809, m_sFirCoeff);
  562.         }
  563.         break;
  564.         default:
  565.         {
  566.             return false;
  567.         }
  568.         //break;
  569.     }
  570.     if (MetaResult != META_SUCCESS)
  571.     {
  572.         return false;
  573.     }
  574.     return true;
  575. }
  576. //---------------------------------------------------------------------------
  577. bool CSPCOEF::Compose_FirCoef(E_AUDIO_FIR_VER_T e_audio_para_type)
  578. {
  579.     META_RESULT MetaResult;
  580.     switch (e_audio_para_type)
  581.     {
  582.         case AUDIO_FIR_VER_ORG:
  583.         {
  584.             l1audio_param_T fir_org;
  585.             Compose_FirCoefOrg(m_sFirCoeff, fir_org);
  586.             MetaResult = META_NVRAM_Compose_AudioParam(&fir_org, m_cpCoefBuf, m_iCoefBufSize);
  587.         }
  588.         break;
  589.         case AUDIO_FIR_VER_W0547:
  590.         {
  591.             l1audio_param_W0547_T fir0547;
  592.             Compose_FirCoef0547(m_sFirCoeff, fir0547);
  593.             MetaResult = META_NVRAM_Compose_AudioParam_W0547(&fir0547, m_cpCoefBuf, m_iCoefBufSize);
  594.         }
  595.         break;
  596.         case AUDIO_FIR_VER_W0547_45_TAP:
  597.         {
  598.             l1audio_param_W0547_45_T fir0547_45tap;
  599.             Compose_FirCoef0547_45Taps(m_sFirCoeff, fir0547_45tap);
  600.             MetaResult = META_NVRAM_Compose_AudioParam_W0547_45(&fir0547_45tap, m_cpCoefBuf, m_iCoefBufSize);
  601.         }
  602.         break;
  603.         case AUDIO_FIR_VER_W0712:
  604.         {
  605.             l1audio_param_W0712_T fir0712;
  606.             Compose_FirCoef0712(m_sFirCoeff, fir0712);
  607.             MetaResult = META_NVRAM_Compose_AudioParam_W0712(&fir0712, m_cpCoefBuf, m_iCoefBufSize);
  608.         }
  609.         break;
  610.         case AUDIO_FIR_VER_W0740:
  611.         {
  612.             l1audio_param_W0740_T fir0740;
  613.             Compose_FirCoef0740(m_sFirCoeff, fir0740);
  614.             MetaResult = META_NVRAM_Compose_AudioParam_W0740(&fir0740, m_cpCoefBuf, m_iCoefBufSize);
  615.         }
  616.         break;
  617.         case AUDIO_FIR_VER_W0809:
  618.         {
  619.             l1audio_param_W0809_T fir0809;
  620.             Compose_FirCoef0809(m_sFirCoeff, fir0809);
  621.             MetaResult = META_NVRAM_Compose_AudioParam_W0809(&fir0809, m_cpCoefBuf, m_iCoefBufSize);
  622.         }
  623.         break;
  624.         default:
  625.         {
  626.             return false;
  627.         }
  628.         
  629.     }
  630.     if (MetaResult != META_SUCCESS)
  631.     {
  632.         return false;
  633.     }
  634.     return true;
  635. }
  636. //===========================================================================
  637. void  CSPCOEF::REQ_Read_From_NVRAM(E_AUDIO_FIR_VER_T e_audio_para_type)
  638. {
  639.     sp_coef_ptr = this;
  640.     g_bIsRunning = true;
  641.     m_eAudioParamType = e_audio_para_type;
  642.     if (NULL == m_cpCoefBuf)
  643.     {
  644.         META_RESULT MetaResult = META_NVRAM_GetRecLen( "NVRAM_EF_AUDIO_PARAM_LID",
  645.                                           &m_iCoefBufSize );
  646.         if(MetaResult!=META_SUCCESS)
  647.         {  Confirm( METAAPP_FAIL );  return;  }
  648.         m_cpCoefBuf = new  char[m_iCoefBufSize];
  649.     }
  650.     NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  651.     NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_AUDIO_PARAM_LID",
  652.                                   1, // only 1 record
  653.                                   m_iCoefBufSize,
  654.                                   m_cpCoefBuf );
  655. }
  656. //-------------------------------------
  657. void CSPCOEF::CNF_ReadFromNVRAM(void)
  658. {
  659.     if (!g_bIsRunning)
  660.     {
  661.         return;
  662.     }
  663.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  664.     switch (state)
  665.     {
  666.         case METAAPP_SUCCESS:
  667.         {
  668.             if (!Decompose_FirCoef(m_eAudioParamType))
  669.             {
  670.                 Confirm(METAAPP_FAIL);
  671.                 return;
  672.             }
  673.             Confirm(METAAPP_SUCCESS);
  674.         }
  675.         break;
  676.         default:
  677.         {
  678.             Confirm(state);
  679.         }
  680.         break;
  681.     }
  682. }
  683. //===========================================================================
  684. void  CSPCOEF::REQ_Write_To_NVRAM(E_AUDIO_FIR_VER_T e_audio_para_type, bool b_runtime_support)
  685. {
  686.     sp_coef_ptr = this;
  687.     g_bIsRunning = true;
  688.     m_eAudioParamType = e_audio_para_type;
  689.     m_bRuntimeSupport = b_runtime_support;
  690.     unsigned short lid_ver;
  691.     META_RESULT MetaResult;
  692.     MetaResult = META_NVRAM_GetLIDVersion("NVRAM_EF_AUDIO_PARAM_LID", &lid_ver);
  693.     if (lid_ver > NVRAM_EF_AUDIO_PARAM_LID_VERNO)
  694.     {
  695.         Confirm(METAAPP_NVRAM_LID_VER_NOT_SUPPORT);
  696.         return;
  697.     }
  698.     if (NULL == m_cpCoefBuf)
  699.     {
  700.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_AUDIO_PARAM_LID", &m_iCoefBufSize);
  701.         if(MetaResult!=META_SUCCESS)
  702.         {  Confirm( METAAPP_FAIL );  return;  }
  703.         m_cpCoefBuf = new char[m_iCoefBufSize];
  704.     }
  705.     if (!Compose_FirCoef(m_eAudioParamType))
  706.     {
  707.         Confirm(METAAPP_FAIL);
  708.         return;
  709.     }
  710.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  711.     NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_AUDIO_PARAM_LID",
  712.                                   1,
  713.                                    m_iCoefBufSize,
  714.                                    m_cpCoefBuf );
  715. }
  716. //-------------------------------------
  717. void CSPCOEF::CNF_WriteToNVRAM(void)
  718. {
  719.     if (!g_bIsRunning)
  720.     {
  721.         return;
  722.     }
  723.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  724.     if (METAAPP_SUCCESS == state)
  725.     {
  726.         if ((AUDIO_FIR_VER_ORG          == m_eAudioParamType) ||
  727.             (AUDIO_FIR_VER_W0547        == m_eAudioParamType) ||
  728.             (AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  729.             (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  730.             (AUDIO_FIR_VER_W0740        == m_eAudioParamType)
  731.            )
  732.         {
  733.             Confirm(state);
  734.             return;
  735.         }
  736.         ActiveMan->SetActiveFunction(::REQ_Set_Runtime_Audio_Param_Settings);
  737.     }
  738.     else
  739.     {
  740.         Confirm(state);
  741.     }
  742. }
  743. //===========================================================================
  744. //////////////////////////   Runtime setting   //////////////////////////////
  745. //===========================================================================
  746. void CSPCOEF::REQ_Get_Runtime_Audio_Param_Settings_Start(E_AUDIO_FIR_VER_T e_audio_para_type)
  747. {
  748.     m_eAudioParamType = e_audio_para_type;
  749.     if ((AUDIO_FIR_VER_ORG          == m_eAudioParamType) ||
  750.         (AUDIO_FIR_VER_W0547        == m_eAudioParamType) ||
  751.         (AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  752.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  753.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType)
  754.        )
  755.     {
  756.         return;
  757.     }
  758.     ActiveMan->SetActiveFunction(::REQ_Get_Runtime_Audio_Param_Settings);
  759. }
  760. //---------------------------------------------------------------------------
  761. void CSPCOEF::REQ_Get_Runtime_Audio_Param_Settings(void)
  762. {
  763.     l1audio_param_W0809_T l1audio_param_W0809;
  764.     META_RESULT MetaResult = META_Audio_Get_Audio_Param_Settings_0809_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &l1audio_param_W0809);
  765.     if (MetaResult != META_SUCCESS)
  766.     {
  767.         if (MetaResult != META_TIMEOUT)
  768.         {
  769.             Confirm(METAAPP_FAIL);
  770.             return;
  771.         }
  772.         else
  773.         {
  774.             Confirm(METAAPP_TIMEOUT);
  775.             return;
  776.         }
  777.     }
  778.     DeCompose_FirCoef0809(l1audio_param_W0809, m_sFirCoeff);
  779.     Confirm(METAAPP_SUCCESS);
  780. }
  781. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  782. void CSPCOEF::REQ_Set_Runtime_Audio_Param_Settings_Start(E_AUDIO_FIR_VER_T e_audio_para_type)
  783. {
  784.     m_eAudioParamType = e_audio_para_type;
  785.     if ((AUDIO_FIR_VER_ORG          == m_eAudioParamType) ||
  786.         (AUDIO_FIR_VER_W0547        == m_eAudioParamType) ||
  787.         (AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  788.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  789.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType)
  790.        ) 
  791.     {
  792.         return;
  793.     }
  794.     ActiveMan->SetActiveFunction(::REQ_Set_Runtime_Audio_Param_Settings);
  795. }
  796. //---------------------------------------------------------------------------
  797. void CSPCOEF::REQ_Set_Runtime_Audio_Param_Settings(void)
  798. {
  799.     l1audio_param_W0809_T l1audio_param_W0809;
  800.     Audio_Set_Param_Cnf_T cnf;
  801.     Compose_FirCoef0809(m_sFirCoeff, l1audio_param_W0809);
  802.     META_RESULT MetaResult = META_Audio_Set_Audio_Param_Settings_0809_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &l1audio_param_W0809, &cnf);
  803.     if (MetaResult != META_SUCCESS)
  804.     {
  805.         if (MetaResult != META_TIMEOUT)
  806.         {
  807.             Confirm(METAAPP_FAIL);
  808.             return;
  809.         }
  810.         else
  811.         {
  812.             Confirm(METAAPP_TIMEOUT);
  813.             return;
  814.         }
  815.     }
  816.     Confirm(METAAPP_SUCCESS);
  817. }
  818. //===========================================================================
  819. const AnsiString as_SECTION_NAME = "Acoustic FIR-Coefficient";
  820. const AnsiString as_KEY_NAME_SIFC = "Speech Input";
  821. const AnsiString as_KEY_NAME_SOFC = "Speech Output";
  822. const AnsiString as_KEY_NAME_ACT_OUTPUT_FIR_IDX = "active output FIR index";
  823. const AnsiString as_KEY_NAME_AC[2] = {"Audio compensation (loud speaker)", "Audio compensation (headset)"};
  824. const AnsiString as_KEY_NAME_VOL_MODE[3] = {"Loud speaker", "BT car-kit", "AUX2"};
  825. const AnsiString as_KEY_NAME_VOL_LEVEL = " volume level";
  826. //---------------------------------------------------------------------------
  827. bool  CSPCOEF::REQ_Read_From_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  828. {
  829.     TIniFile   *ini_file;
  830.     AnsiString  as_data;
  831.     char        str[2048];
  832.     ini_file = new TIniFile(filename);
  833.     if (NULL == ini_file)
  834.     {
  835.         return false;
  836.     }
  837.     m_eAudioParamType = e_audio_para_type;
  838.     // const
  839.     switch (e_audio_para_type)
  840.     {
  841.         case AUDIO_FIR_VER_ORG:
  842.         {
  843.             m_sFirCoeff.us_ES_TimeConst = ini_file->ReadInteger(as_SECTION_NAME,
  844.                                                             "Time Constant",
  845.                                                             0);
  846.             m_sFirCoeff.us_ES_VolConst = ini_file->ReadInteger(as_SECTION_NAME,
  847.                                                            "Volume Constant",
  848.                                                            0);
  849.             m_sFirCoeff.us_ES_TimeConst2 = ini_file->ReadInteger(as_SECTION_NAME,
  850.                                                              "Time Constant 2",
  851.                                                              0);
  852.             m_sFirCoeff.us_ES_VolConst2 = ini_file->ReadInteger(as_SECTION_NAME,
  853.                                                            "Volume Constant 2",
  854.                                                            0);
  855.             m_sFirCoeff.us_Media_Playback_Maximum_Swing = ini_file->ReadInteger(as_SECTION_NAME,
  856.                                                                            "Media Playback Max Swing",
  857.                                                                            0);
  858.         }
  859.         break;
  860.         case AUDIO_FIR_VER_W0547:
  861.         case AUDIO_FIR_VER_W0547_45_TAP:
  862.         case AUDIO_FIR_VER_W0712:
  863.         case AUDIO_FIR_VER_W0740:
  864.         case AUDIO_FIR_VER_W0809:
  865.         {
  866.             m_sFirCoeff.us_Media_Playback_Maximum_Swing = ini_file->ReadInteger(as_SECTION_NAME,
  867.                                                                                "Media Playback Max Swing",
  868.                                                                                0);
  869.         }
  870.         break;
  871.     }
  872.     //////////////////////////         8k            ////////////////////////////
  873.     if ((AUDIO_FIR_VER_ORG == m_eAudioParamType) || (AUDIO_FIR_VER_W0547 == m_eAudioParamType))
  874.     {
  875.         short s_data_30tap[SPEECH_FIR_30_TAPS_NUM];
  876.         //L1_SpeechCoeff_T  *p_speech_coef;
  877.         //if(AUDIO_FIR_VER_ORG == m_eAudioParamType)
  878.         //{
  879.         //    p_speech_coef = m_sFirCoeff.Speech_FIR;
  880.         //}
  881.         //else // AUDIO_FIR_VER_W0547
  882.         //{
  883.         //    p_speech_coef = m_sFirCoeff.Speech_FIR;
  884.         //}
  885.         // FIR1
  886.         as_data = ini_file->ReadString(as_SECTION_NAME,
  887.                                        "8k Input (mic)",
  888.                                        "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" );
  889.         strcpy(str, as_data.c_str());
  890.         String_To_Array_short(str, s_data_30tap, SPEECH_FIR_30_TAPS_NUM);
  891.         for (int i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  892.         {
  893.             m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Input_Coeff[i] = s_data_30tap[i];
  894.         }
  895.         as_data = ini_file->ReadString(as_SECTION_NAME,
  896.                                        "8k Output (speaker)",
  897.                                        "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" );
  898.         strcpy(str, as_data.c_str());
  899.         String_To_Array_short( str, s_data_30tap, SPEECH_FIR_30_TAPS_NUM );
  900.         for (int i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  901.         {
  902.             m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff[i] = s_data_30tap[i];
  903.         }
  904.         // FIR2
  905.         as_data = ini_file->ReadString(as_SECTION_NAME,
  906.                                        "8k Input (earphone)",
  907.                                        "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" );
  908.         strcpy(str, as_data.c_str());
  909.         String_To_Array_short(str, s_data_30tap, SPEECH_FIR_30_TAPS_NUM);
  910.         for (int i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  911.         {
  912.             m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Input_Coeff[i] = s_data_30tap[i];
  913.         }
  914.         as_data = ini_file->ReadString(as_SECTION_NAME,
  915.                                        "8k Output (earphone)",
  916.                                        "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" );
  917.         strcpy(str, as_data.c_str());
  918.         String_To_Array_short(str, s_data_30tap, SPEECH_FIR_30_TAPS_NUM);
  919.         for (int i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  920.         {
  921.             m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Output_Coeff[i] = s_data_30tap[i];
  922.         }
  923.     }
  924.     ////////////////////////////////   8k additional      /////////////////////////////////
  925.     if ((AUDIO_FIR_VER_ORG == m_eAudioParamType) || (AUDIO_FIR_VER_W0547 == m_eAudioParamType))
  926.     {
  927.         short s_data_30tap[SPEECH_FIR_30_TAPS_NUM];
  928.        // L1_SpeechCoeff_T  *p_speech_coef;
  929.        // if (AUDIO_FIR_VER_ORG == m_eAudioParamType)
  930.        // {
  931.        //     p_speech_coef = m_sFirCoeff.Speech_FIR;
  932.        // }
  933.        // else // AUDIO_FIR_VER_W0547
  934.       //  {
  935.       //      p_speech_coef = m_sFirCoeff.Speech_FIR;
  936.       //  }
  937.         // active output FIR index
  938.         m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff_Index =
  939.                                               ini_file->ReadInteger(as_SECTION_NAME,
  940.                                               "active output FIR index",
  941.                                               0);
  942.         for (int i=0; i<5; i++)
  943.         {
  944.             as_data = ini_file->ReadString(as_SECTION_NAME,
  945.                                            Additional_8k_Output_Name[i],
  946.                                            "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" );
  947.             strcpy(str, as_data.c_str());
  948.             String_To_Array_short(str, s_data_30tap, SPEECH_FIR_30_TAPS_NUM);
  949.             for (int j=0; j<SPEECH_FIR_30_TAPS_NUM; j++)
  950.             {
  951.                 m_sFirCoeff.s_Speech_FIR[0].Additional_Speech_8k_Output_Coeff[i][j] = s_data_30tap[j];
  952.             }
  953.         }
  954.     }
  955.     ////////////////////////////////   16k      /////////////////////////////////
  956.     if ((AUDIO_FIR_VER_ORG == m_eAudioParamType) || (AUDIO_FIR_VER_W0547 == m_eAudioParamType))
  957.     {
  958.         short s_16kdata[ACOUSTIC_FIR_COEFF_16K_NUM];
  959.         //L1_SpeechCoeff_T  *p_speech_coef;
  960.         //if (AUDIO_FIR_VER_ORG == m_eAudioParamType)
  961.         //{
  962.         //    p_speech_coef = m_sFirCoeff.Speech_FIR;
  963.         //}
  964.         //else // AUDIO_FIR_VER_W0547
  965.         //{
  966.         //    p_speech_coef = m_sFirCoeff.Speech_FIR;
  967.        // }
  968.         // FIR1
  969.         as_data = ini_file->ReadString(as_SECTION_NAME,
  970.                                        "AMR Input (mic)",
  971.                                        "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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" );
  972.         strcpy(str, as_data.c_str());
  973.         String_To_Array_short(str, s_16kdata, ACOUSTIC_FIR_COEFF_16K_NUM);
  974.         for (int i=0; i<ACOUSTIC_FIR_COEFF_16K_NUM; i++)
  975.         {
  976.             m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_16k_Input_Coeff[i] = s_16kdata[i];
  977.         }
  978.         as_data = ini_file->ReadString(as_SECTION_NAME,
  979.                                      "AMR Output (speaker)",
  980.                                      "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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" );
  981.         strcpy(str, as_data.c_str());
  982.         String_To_Array_short(str, s_16kdata, ACOUSTIC_FIR_COEFF_16K_NUM);
  983.         for (int i=0; i<ACOUSTIC_FIR_COEFF_16K_NUM; i++)
  984.         {
  985.             m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_16k_Output_Coeff[i] = s_16kdata[i];
  986.         }
  987.         // FIR2
  988.         as_data = ini_file->ReadString(as_SECTION_NAME,
  989.                                      "AMR Input (earphone)",
  990.                                      "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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" );
  991.         strcpy(str, as_data.c_str());
  992.         String_To_Array_short( str, s_16kdata, ACOUSTIC_FIR_COEFF_16K_NUM );
  993.         for (int i=0; i<ACOUSTIC_FIR_COEFF_16K_NUM; i++)
  994.         {
  995.             m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_16k_Input_Coeff[i] = s_16kdata[i];
  996.         }
  997.         as_data = ini_file->ReadString(as_SECTION_NAME,
  998.                                      "AMR Output (earphone)",
  999.                                      "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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" );
  1000.         strcpy(str, as_data.c_str());
  1001.         String_To_Array_short(str, s_16kdata, ACOUSTIC_FIR_COEFF_16K_NUM);
  1002.         for (int i=0; i<ACOUSTIC_FIR_COEFF_16K_NUM; i++)
  1003.         {
  1004.             m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_16k_Output_Coeff[i] = s_16kdata[i];
  1005.         }
  1006.     }
  1007.     //////////////////////////  Speech input FIR coefficient  ////////////////////////////
  1008.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1009.         (AUDIO_FIR_VER_W0712 == m_eAudioParamType)        ||
  1010.         (AUDIO_FIR_VER_W0740 == m_eAudioParamType)        ||
  1011.         (AUDIO_FIR_VER_W0809 == m_eAudioParamType)
  1012.         )
  1013.     {
  1014.         short speech_input_FIR_coeffs[SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM][SPEECH_FIR_45_TAPS_NUM];
  1015.         for (int i=0; i<SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  1016.         {
  1017.             as_data = ini_file->ReadString(as_SECTION_NAME,
  1018.                                            as_KEY_NAME_SIFC + IntToStr(i),
  1019.                                            "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,0" );
  1020.             strcpy(str, as_data.c_str());
  1021.             String_To_Array_short(str, speech_input_FIR_coeffs[i], SPEECH_FIR_45_TAPS_NUM);
  1022.             switch (m_eAudioParamType)
  1023.             {
  1024.                 case AUDIO_FIR_VER_W0547_45_TAP:
  1025.                 case AUDIO_FIR_VER_W0712:
  1026.                 case AUDIO_FIR_VER_W0740:
  1027.                 case AUDIO_FIR_VER_W0809:
  1028.                 {
  1029.                     for (int j=0; j<SPEECH_FIR_45_TAPS_NUM; j++)
  1030.                     {
  1031.                         m_sFirCoeff.s_speech_input_FIR_coeffs[i][j] = speech_input_FIR_coeffs[i][j];
  1032.                     }
  1033.                 }
  1034.                 break;
  1035.             }
  1036.         }
  1037.     }
  1038.     //////////////////////////  Speech output FIR coefficient  ////////////////////////////
  1039.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1040.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1041.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1042.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1043.        )
  1044.     {
  1045.         switch (m_eAudioParamType)
  1046.         {
  1047.             case AUDIO_FIR_VER_W0547_45_TAP:
  1048.             case AUDIO_FIR_VER_W0712:
  1049.             case AUDIO_FIR_VER_W0740:
  1050.             case AUDIO_FIR_VER_W0809:
  1051.             {
  1052.                 m_sFirCoeff.us_selected_FIR_output_index = ini_file->ReadInteger(as_SECTION_NAME,
  1053.                                                                                   as_KEY_NAME_ACT_OUTPUT_FIR_IDX,
  1054.                                                                                   0);
  1055.             }
  1056.             break;
  1057.         }
  1058.         short speech_output_FIR_coeffs[SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM][SPEECH_FIR_45_TAPS_NUM];
  1059.         for (int i=0; i<SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  1060.         {
  1061.             as_data = ini_file->ReadString(as_SECTION_NAME,
  1062.                                            as_KEY_NAME_SOFC + IntToStr(i),
  1063.                                            "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,0" );
  1064.             strcpy(str, as_data.c_str());
  1065.             String_To_Array_short(str, speech_output_FIR_coeffs[i], SPEECH_FIR_45_TAPS_NUM);
  1066.             switch (m_eAudioParamType)
  1067.             {
  1068.                 case AUDIO_FIR_VER_W0547_45_TAP:
  1069.                 case AUDIO_FIR_VER_W0712:
  1070.                 case AUDIO_FIR_VER_W0740:
  1071.                 case AUDIO_FIR_VER_W0809:
  1072.                 {
  1073.                     for (int j=0; j<SPEECH_FIR_45_TAPS_NUM; j++)
  1074.                     {
  1075.                         m_sFirCoeff.s_speech_output_FIR_coeffs[i][j] = speech_output_FIR_coeffs[i][j];
  1076.                     }
  1077.                 }
  1078.                 break;
  1079.             }
  1080.         }
  1081.     }
  1082.     ///////////////////////////     Melody     //////////////////////////////////
  1083.     short s_Melodydata[MELODY_FIR_COEFF_45_TAPS_NUM];
  1084.     if ((AUDIO_FIR_VER_ORG == m_eAudioParamType) || (AUDIO_FIR_VER_W0547 == m_eAudioParamType))
  1085.     {
  1086.        // L1_MelodyCoeff_T  *p_melody_coef;
  1087.        // if (AUDIO_FIR_VER_ORG == m_eAudioParamType)
  1088.        // {
  1089.        //     p_melody_coef = m_sFirCoeff.Melody_FIR;
  1090.        // }
  1091.        // else // AUDIO_FIR_VER_W0547
  1092.        // {
  1093.        //     p_melody_coef = m_sFirCoeff.Melody_FIR;
  1094.        // }
  1095.         as_data = ini_file->ReadString(as_SECTION_NAME,
  1096.                                        "Melody Output (loud speaker)",
  1097.                                        "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,0" );
  1098.         strcpy(str, as_data.c_str());
  1099.         String_To_Array_short(str, s_Melodydata, MELODY_FIR_COEFF_45_TAPS_NUM);
  1100.         for (int i=0; i<MELODY_FIR_COEFF_45_TAPS_NUM; i++)
  1101.         {
  1102.             m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_LOUD_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff[i] = s_Melodydata[i];
  1103.         }
  1104.         as_data = ini_file->ReadString(as_SECTION_NAME,
  1105.                                        "Melody Output (stereo speaker)",
  1106.                                        "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,0" );
  1107.         strcpy(str, as_data.c_str());
  1108.         String_To_Array_short(str, s_Melodydata, MELODY_FIR_COEFF_45_TAPS_NUM);
  1109.         for (int i=0; i<MELODY_FIR_COEFF_45_TAPS_NUM; i++)
  1110.         {
  1111.             m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_STEREO_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff[i] = s_Melodydata[i];
  1112.         }
  1113.     }
  1114.     else // W0547_45_TAP, W0712, W0740, W0809
  1115.     {
  1116.         switch (m_eAudioParamType)
  1117.         {
  1118.             case AUDIO_FIR_VER_W0547_45_TAP:
  1119.             {
  1120.                 as_data = ini_file->ReadString(as_SECTION_NAME,
  1121.                                                "Melody Output",
  1122.                                               "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,0" );
  1123.                 strcpy(str, as_data.c_str());
  1124.                 String_To_Array_short(str, s_Melodydata, MELODY_FIR_COEFF_45_TAPS_NUM);
  1125.                 for (int i=0; i<MELODY_FIR_COEFF_45_TAPS_NUM; i++)
  1126.                 {
  1127.                     m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_LOUD_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff[i] = s_Melodydata[i];
  1128.                 }
  1129.             }
  1130.             break;
  1131.             case AUDIO_FIR_VER_W0712:
  1132.             case AUDIO_FIR_VER_W0740:
  1133.             case AUDIO_FIR_VER_W0809:
  1134.             {
  1135.                 as_data = ini_file->ReadString(as_SECTION_NAME,
  1136.                                                "Melody Output",
  1137.                                                "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," );
  1138.                 strcpy(str, as_data.c_str());
  1139.                 String_To_Array_short(str, s_Melodydata, MELODY_FIR_COEFF_25_TAPS_NUM);
  1140.                 for (int i=0; i<MELODY_FIR_COEFF_25_TAPS_NUM; i++)
  1141.                 {
  1142.                     m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_LOUD_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff[i] = s_Melodydata[i];
  1143.                 }
  1144.             }
  1145.         }
  1146.     }
  1147.     //////////////////////////         Speech enhancement            ////////////////////////////
  1148.     if (m_eAudioParamType != AUDIO_FIR_VER_ORG)
  1149.     {
  1150.         //unsigned short     usSpeechCommonPara[12];
  1151.         unsigned short     usSpeechModeDependentPara[8][8];
  1152.         //unsigned short     *p_Speech_ModeDependent_Para;
  1153.         //unsigned short     *Speech_ModeDependent_Para_Array[8];
  1154.         const char SECTION_NAME[][64] =
  1155.         {
  1156.             "Normal Mode Parameter",
  1157.             "Earphone Mode Parameter",
  1158.             "Loud Speaker Mode Parameter",
  1159.             "BlueTooth Earphone Mode Parameter",
  1160.             "BlueTooth Cordless Mode Parameter",
  1161.             "AUX1 Mode Parameter",
  1162.             "AUX2 Mode Parameter",
  1163.             "AUX3 Mode Parameter"
  1164.         };
  1165.         switch (m_eAudioParamType)
  1166.         {
  1167.             case AUDIO_FIR_VER_W0547:
  1168.             case AUDIO_FIR_VER_W0547_45_TAP:
  1169.             case AUDIO_FIR_VER_W0712:
  1170.             case AUDIO_FIR_VER_W0740:
  1171.             {
  1172.                 as_data = ini_file->ReadString(as_SECTION_NAME,
  1173.                                                "Speech Common Parameter",
  1174.                                                "0,0,0,0,0,0,0,0,0,0,0,0");
  1175.                 strcpy(str, as_data.c_str());
  1176.                 String_To_Array_UnsignedShort(str, m_sFirCoeff.us_speech_common_para, SE_SPEECH_COMMON_NUM_12);
  1177.             }
  1178.             break;
  1179.             case AUDIO_FIR_VER_W0809:
  1180.             {
  1181.                 as_data = ini_file->ReadString(as_SECTION_NAME,
  1182.                                                "Speech Common Parameter",
  1183.                                                "0,0,0,0,0,0,0,0,");
  1184.                 strcpy(str, as_data.c_str());
  1185.                 String_To_Array_UnsignedShort(str, m_sFirCoeff.us_speech_common_para, SE_SPEECH_COMMON_NUM_12);
  1186.             }
  1187.             break;
  1188.         }
  1189.         switch (m_eAudioParamType)
  1190.         {
  1191.             case AUDIO_FIR_VER_W0547:
  1192.             case AUDIO_FIR_VER_W0547_45_TAP:
  1193.             case AUDIO_FIR_VER_W0712:
  1194.             case AUDIO_FIR_VER_W0740:
  1195.             {
  1196.                 for (int i=0; i<SE_MODE_NUM; i++)
  1197.                 {
  1198.                     as_data = ini_file->ReadString(as_SECTION_NAME,
  1199.                                                    SECTION_NAME[i],
  1200.                                                   "0,0,0,0,0,0,0,0");
  1201.                     strcpy(str, as_data.c_str());
  1202.                     String_To_Array_UnsignedShort(str, usSpeechModeDependentPara[i], SE_MODE_PARA_NUM_8);
  1203.                     for (int j=0; j<SE_MODE_PARA_NUM_8; j++)
  1204.                     {
  1205.                         m_sFirCoeff.us_speech_mode_para[i][j] = usSpeechModeDependentPara[i][SE_MODE_PARA_NUM_8-j-1];
  1206.                     }
  1207.                 }
  1208.             }
  1209.             break;
  1210.             case AUDIO_FIR_VER_W0809:
  1211.             {
  1212.                 for (int i=0; i<SE_MODE_NUM; i++)
  1213.                 {
  1214.                     as_data = ini_file->ReadString(as_SECTION_NAME,
  1215.                                                    SECTION_NAME[i],
  1216.                                                   "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,");
  1217.                     strcpy(str, as_data.c_str());
  1218.                     String_To_Array_UnsignedShort(str, usSpeechModeDependentPara[i], SE_MODE_PARA_NUM_16);
  1219.                     for (int j=0; j<SE_MODE_PARA_NUM_16; j++)
  1220.                     {
  1221.                         m_sFirCoeff.us_speech_mode_para[i][j] = usSpeechModeDependentPara[i][SE_MODE_PARA_NUM_16-j-1];
  1222.                     }
  1223.                 }
  1224.             }
  1225.             break;
  1226.         }
  1227.     }
  1228.     // audio compensation
  1229.     if ((AUDIO_FIR_VER_W0740 == m_eAudioParamType) ||
  1230.         (AUDIO_FIR_VER_W0809 == m_eAudioParamType)
  1231.        )
  1232.     {
  1233.         for (E_AUDIO_COMPENSATION_IDX_T type = AUDIO_COMPENSATION_LOUD_SPEAKER_IDX; type <= AUDIO_COMPENSATION_EARPHONE_IDX; type++)
  1234.         {
  1235.             as_data = ini_file->ReadString(as_SECTION_NAME,
  1236.                                            as_KEY_NAME_AC[type],
  1237.                                            "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,0");
  1238.             String_To_Array_short(as_data.c_str(), m_sFirCoeff.s_audio_compensation_coeff[type], AUDIO_COMPENSATION_TAPS_NUM);
  1239.         }
  1240.     }
  1241.     // volume
  1242.     if (AUDIO_FIR_VER_W0809 == m_eAudioParamType)
  1243.     {
  1244.         for (int i = 0; i < SE_VOLUME_MODE_NUM; i++)
  1245.         {
  1246.             for (int j = 0; j < SE_VOLUME_LEVEL_NUM; j++)
  1247.             {
  1248.                 AnsiString as_key_name = as_KEY_NAME_VOL_MODE[i] + as_KEY_NAME_VOL_LEVEL + IntToStr(j);
  1249.                 as_data = ini_file->ReadString(as_SECTION_NAME,
  1250.                                                as_key_name,
  1251.                                                "0,0,0,0,"
  1252.                                               );
  1253.                 String_To_Array_UnsignedShort(as_data.c_str(), m_sFirCoeff.us_speech_volume_para[i][j], SE_VOLUME_PARAM_NUM);
  1254.             }
  1255.         }
  1256.     }
  1257.     delete  ini_file;
  1258.     return true;
  1259. }
  1260. //===========================================================================
  1261. bool CSPCOEF::REQ_Write_To_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1262. {
  1263.     TIniFile   *ini_file;
  1264.     AnsiString  as_data;
  1265.     char        str[2048];
  1266.     ini_file = new TIniFile(filename);
  1267.     if (NULL == ini_file)
  1268.     {
  1269.         return  false;
  1270.     }
  1271.     m_eAudioParamType = e_audio_para_type;
  1272.     // const
  1273.     switch (e_audio_para_type)
  1274.     {
  1275.         case AUDIO_FIR_VER_ORG:
  1276.         {
  1277.             sprintf(str, "%d", m_sFirCoeff.us_ES_TimeConst);
  1278.             ini_file->WriteString(as_SECTION_NAME,
  1279.                                   "Time Constant",
  1280.                                   str);
  1281.             sprintf(str, "%d", m_sFirCoeff.us_ES_VolConst);
  1282.             ini_file->WriteString(as_SECTION_NAME,
  1283.                                   "Volume Constant",
  1284.                                   str);
  1285.             sprintf(str, "%d", m_sFirCoeff.us_ES_TimeConst2);
  1286.             ini_file->WriteString(as_SECTION_NAME,
  1287.                                   "Time Constant 2",
  1288.                                   str);
  1289.             sprintf(str, "%d", m_sFirCoeff.us_ES_VolConst2);
  1290.             ini_file->WriteString(as_SECTION_NAME,
  1291.                                   "Volume Constant 2",
  1292.                                   str);
  1293.             sprintf(str, "%d", m_sFirCoeff.us_Media_Playback_Maximum_Swing);
  1294.         }
  1295.         break;
  1296.         case AUDIO_FIR_VER_W0547:
  1297.         case AUDIO_FIR_VER_W0547_45_TAP:
  1298.         case AUDIO_FIR_VER_W0712:
  1299.         case AUDIO_FIR_VER_W0740:
  1300.         case AUDIO_FIR_VER_W0809:
  1301.         {
  1302.             sprintf(str, "%d", m_sFirCoeff.us_Media_Playback_Maximum_Swing);
  1303.         }
  1304.         break;
  1305.         default:
  1306.         {
  1307.             return false;
  1308.         }
  1309.     }
  1310.     ini_file->WriteString(as_SECTION_NAME,
  1311.                           "Media Playback Max Swing",
  1312.                           str);
  1313.     /////////////////////////      8k      /////////////////////////////////////
  1314.     if ((AUDIO_FIR_VER_ORG   == m_eAudioParamType) ||
  1315.         (AUDIO_FIR_VER_W0547 == m_eAudioParamType)
  1316.         )
  1317.     {
  1318.         // 8k Input (mic)
  1319.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Input_Coeff, SPEECH_FIR_30_TAPS_NUM, ',');
  1320.         ini_file->WriteString(as_SECTION_NAME,
  1321.                               "8k Input (mic)",
  1322.                               str);
  1323.         // 8k Output (speaker)
  1324.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff, SPEECH_FIR_30_TAPS_NUM, ',');
  1325.         ini_file->WriteString(as_SECTION_NAME,
  1326.                               "8k Output (speaker)",
  1327.                               str);
  1328.         // 8k Input (earphone)
  1329.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Input_Coeff, SPEECH_FIR_30_TAPS_NUM, ',');
  1330.         ini_file->WriteString(as_SECTION_NAME,
  1331.                               "8k Input (earphone)",
  1332.                               str);
  1333.         // 8k Output (earphone)
  1334.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Output_Coeff, SPEECH_FIR_30_TAPS_NUM, ',');
  1335.         ini_file->WriteString(as_SECTION_NAME,
  1336.                                "8k Output (earphone)",
  1337.                                str );
  1338.     }
  1339.     ///////////////////////      8k  additional       ////////////////////////////////////
  1340.     if ((AUDIO_FIR_VER_ORG   == m_eAudioParamType) ||
  1341.         (AUDIO_FIR_VER_W0547 == m_eAudioParamType)
  1342.         )
  1343.     {
  1344.         // active FIR index
  1345.         sprintf(str, "%d", m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff_Index);
  1346.         ini_file->WriteString(as_SECTION_NAME,
  1347.                                "active output FIR index",
  1348.                                str );
  1349.         for (int i=0; i<5; i++)
  1350.         {
  1351.             Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Additional_Speech_8k_Output_Coeff[i], SPEECH_FIR_30_TAPS_NUM, ',');
  1352.             ini_file->WriteString(as_SECTION_NAME,
  1353.                                   Additional_8k_Output_Name[i],
  1354.                                   str);
  1355.         }
  1356.     }
  1357.     ///////////////////////      16k         ////////////////////////////////////
  1358.     if ((AUDIO_FIR_VER_ORG   == m_eAudioParamType) ||
  1359.         (AUDIO_FIR_VER_W0547 == m_eAudioParamType)
  1360.         )
  1361.     {
  1362.         // FIR1
  1363.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_16k_Input_Coeff, ACOUSTIC_FIR_COEFF_16K_NUM, ',');
  1364.         ini_file->WriteString(as_SECTION_NAME,
  1365.                                "AMR Input (mic)",
  1366.                                str);
  1367.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_16k_Output_Coeff, ACOUSTIC_FIR_COEFF_16K_NUM, ',');
  1368.         ini_file->WriteString(as_SECTION_NAME,
  1369.                               "AMR Output (speaker)",
  1370.                               str);
  1371.         // FIR2
  1372.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_16k_Input_Coeff, ACOUSTIC_FIR_COEFF_16K_NUM, ',');
  1373.         ini_file->WriteString(as_SECTION_NAME,
  1374.                                "AMR Input (earphone)",
  1375.                                str);
  1376.         Array_To_String_short(str, m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_16k_Output_Coeff, ACOUSTIC_FIR_COEFF_16K_NUM, ',');
  1377.         ini_file->WriteString(as_SECTION_NAME,
  1378.                                "AMR Output (earphone)",
  1379.                                str);
  1380.     }
  1381.     //////////////////////////  Speech input FIR coefficient  ////////////////////////////
  1382.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1383.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1384.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1385.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1386.        )
  1387.     {
  1388.         for (int i=0; i<SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  1389.         {
  1390.             Array_To_String_short(str, m_sFirCoeff.s_speech_input_FIR_coeffs[i], SPEECH_FIR_45_TAPS_NUM, ',');
  1391.             ini_file->WriteString(as_SECTION_NAME,
  1392.                                   as_KEY_NAME_SIFC + IntToStr(i),
  1393.                                   str);
  1394.         }
  1395.     }
  1396.     //////////////////////////  Speech output FIR coefficient  /////////////////
  1397.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1398.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1399.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1400.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1401.         )
  1402.     {
  1403.         ini_file->WriteString(as_SECTION_NAME,
  1404.                                as_KEY_NAME_ACT_OUTPUT_FIR_IDX,
  1405.                                IntToStr(m_sFirCoeff.us_selected_FIR_output_index));
  1406.         for (int i=0; i<SPEECH_INPUT_FIR_45_TAPS_GROUP_NUM; i++)
  1407.         {
  1408.             Array_To_String_short(str, m_sFirCoeff.s_speech_output_FIR_coeffs[i], SPEECH_FIR_45_TAPS_NUM, ',');
  1409.             ini_file->WriteString(as_SECTION_NAME,
  1410.                                   as_KEY_NAME_SOFC + IntToStr(i),
  1411.                                   str);
  1412.         }
  1413.     }
  1414.     ///////////////////////      Melody      ////////////////////////////////////
  1415.     if ((AUDIO_FIR_VER_ORG   == m_eAudioParamType) ||
  1416.         (AUDIO_FIR_VER_W0547 == m_eAudioParamType)
  1417.        )
  1418.     {
  1419.         // loud speaker
  1420.         Array_To_String_short(str, m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_LOUD_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff, MELODY_FIR_COEFF_45_TAPS_NUM, ',');
  1421.         ini_file->WriteString(as_SECTION_NAME,
  1422.                               "Melody Output (loud speaker)",
  1423.                               str);
  1424.         // stereo speaker
  1425.         Array_To_String_short(str, m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_STEREO_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff, MELODY_FIR_COEFF_45_TAPS_NUM, ',');
  1426.         ini_file->WriteString(as_SECTION_NAME,
  1427.                               "Melody Output (stereo speaker)",
  1428.                               str);
  1429.     }
  1430.     else // W0547_45_TAP, W0712, W0740, W0809
  1431.     {
  1432.         switch (m_eAudioParamType)
  1433.         {
  1434.             case AUDIO_FIR_VER_W0547_45_TAP:
  1435.             {
  1436.                 Array_To_String_short(str, m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_LOUD_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff, MELODY_FIR_COEFF_45_TAPS_NUM, ',');
  1437.             }
  1438.             break;
  1439.             case AUDIO_FIR_VER_W0712:
  1440.             case AUDIO_FIR_VER_W0740:
  1441.             case AUDIO_FIR_VER_W0809:
  1442.             {
  1443.                 Array_To_String_short(str, m_sFirCoeff.s_Melody_FIR[FIR_COEFF_MELODY_LOUD_SPEAKER_MODE_INDEX].Melody_32k_Output_Coeff, MELODY_FIR_COEFF_25_TAPS_NUM, ',');
  1444.             }
  1445.             break;
  1446.         }
  1447.         ini_file->WriteString(as_SECTION_NAME,
  1448.                               "Melody Output",
  1449.                               str);
  1450.     }
  1451.     //////////////////////////         Speech enhancement            ////////////////////////////
  1452.     if (m_eAudioParamType != AUDIO_FIR_VER_ORG)
  1453.     {
  1454.         unsigned short     usSpeechCommonPara[12];
  1455.         unsigned short     usSpeechModeDependentPara[8][8];
  1456.         unsigned short     *p_Speech_ModeDependent_Para;
  1457.         unsigned short     *Speech_ModeDependent_Para_Array[8];
  1458.         const char  SECTION_NAME[][64] =
  1459.         {
  1460.             "Normal Mode Parameter",
  1461.             "Earphone Mode Parameter",
  1462.             "Loud Speaker Mode Parameter",
  1463.             "BlueTooth Earphone Mode Parameter",
  1464.             "BlueTooth Cordless Mode Parameter",
  1465.             "AUX1 Mode Parameter",
  1466.             "AUX2 Mode Parameter",
  1467.             "AUX3 Mode Parameter"
  1468.         };
  1469.         switch (m_eAudioParamType)
  1470.         {
  1471.             case AUDIO_FIR_VER_W0547:
  1472.             case AUDIO_FIR_VER_W0547_45_TAP:
  1473.             case AUDIO_FIR_VER_W0712:
  1474.             case AUDIO_FIR_VER_W0740:
  1475.             {
  1476.                 Array_To_String_UnsignedShort(str, m_sFirCoeff.us_speech_common_para, SE_SPEECH_COMMON_NUM_12, ',');
  1477.                 ini_file->WriteString(as_SECTION_NAME,
  1478.                                       "Speech Common Parameter",
  1479.                                       str);
  1480.             }
  1481.             break;
  1482.             case AUDIO_FIR_VER_W0809:
  1483.             {
  1484.                 Array_To_String_UnsignedShort(str, m_sFirCoeff.us_speech_common_para, SE_SPEECH_COMMON_NUM_12, ',');
  1485.                 ini_file->WriteString(as_SECTION_NAME,
  1486.                                       "Speech Common Parameter",
  1487.                                       str);
  1488.             }
  1489.             break;
  1490.         }
  1491.         switch (m_eAudioParamType)
  1492.         {
  1493.             case AUDIO_FIR_VER_W0547:
  1494.             case AUDIO_FIR_VER_W0547_45_TAP:
  1495.             case AUDIO_FIR_VER_W0712:
  1496.             case AUDIO_FIR_VER_W0740:
  1497.             {
  1498.                 for (int i=0; i<SE_MODE_NUM; i++)
  1499.                 {
  1500.                     for (int j=0; j<SE_MODE_PARA_NUM_8; j++)
  1501.                     {
  1502.                         usSpeechModeDependentPara[i][SE_MODE_PARA_NUM_8-j-1] = m_sFirCoeff.us_speech_mode_para[i][j];
  1503.                     }
  1504.                     Array_To_String_UnsignedShort(str, usSpeechModeDependentPara[i], SE_MODE_PARA_NUM_8, ',');
  1505.                     ini_file->WriteString(as_SECTION_NAME,
  1506.                                           SECTION_NAME[i],
  1507.                                           str
  1508.                                          );
  1509.                }
  1510.             }
  1511.             break;
  1512.             case AUDIO_FIR_VER_W0809:
  1513.             {
  1514.                 for (int i=0; i<SE_MODE_NUM; i++)
  1515.                 {
  1516.                     for (int j=0; j<SE_MODE_PARA_NUM_16; j++)
  1517.                     {
  1518.                         usSpeechModeDependentPara[i][SE_MODE_PARA_NUM_16-j-1] = m_sFirCoeff.us_speech_mode_para[i][j];
  1519.                     }
  1520.                     Array_To_String_UnsignedShort(str, usSpeechModeDependentPara[i], SE_MODE_PARA_NUM_16, ',');
  1521.                     ini_file->WriteString(as_SECTION_NAME,
  1522.                                           SECTION_NAME[i],
  1523.                                           str
  1524.                                          );
  1525.                }
  1526.             }
  1527.             break;
  1528.         }
  1529.     }
  1530.     // auido compensation
  1531.     if ((AUDIO_FIR_VER_W0740 == m_eAudioParamType) ||
  1532.         (AUDIO_FIR_VER_W0809 == m_eAudioParamType)
  1533.        )
  1534.     {
  1535.         for (E_AUDIO_COMPENSATION_IDX_T type = AUDIO_COMPENSATION_LOUD_SPEAKER_IDX; type <= AUDIO_COMPENSATION_EARPHONE_IDX; type++)
  1536.         {
  1537.             Array_To_String_short(str, m_sFirCoeff.s_audio_compensation_coeff[type], AUDIO_COMPENSATION_TAPS_NUM, ',');
  1538.             ini_file->WriteString(as_SECTION_NAME,
  1539.                                   as_KEY_NAME_AC[type],
  1540.                                   str);
  1541.         }
  1542.     }
  1543.      // volume
  1544.     if (AUDIO_FIR_VER_W0809 == m_eAudioParamType)
  1545.     {
  1546.         for (int i = 0; i < SE_VOLUME_MODE_NUM; i++)
  1547.         {
  1548.             for (int j = 0; j < SE_VOLUME_LEVEL_NUM; j++)
  1549.             {
  1550.                 Array_To_String_UnsignedShort(str,  m_sFirCoeff.us_speech_volume_para[i][j], SE_VOLUME_PARAM_NUM, ',');
  1551.                 AnsiString as_key_name = as_KEY_NAME_VOL_MODE[i] + as_KEY_NAME_VOL_LEVEL + IntToStr(j);
  1552.                 ini_file->WriteString(as_SECTION_NAME,
  1553.                                       as_key_name,
  1554.                                       str
  1555.                                       );
  1556.             }
  1557.         }
  1558.     }
  1559.     delete  ini_file;
  1560.     return  true;
  1561. }
  1562. //==============================================================================
  1563. /////////////////////////////////////// FIR 1 //////////////////////////////////
  1564. //==============================================================================
  1565. bool CSPCOEF::REQ_Read_FIR1_Input_Coeff_From_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1566. {
  1567.     m_eAudioParamType = e_audio_para_type;
  1568.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1569.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1570.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1571.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1572.         )
  1573.     {
  1574.         return false;
  1575.     }
  1576.     FILE *fp;
  1577.     bool IsEof;
  1578.     int i;
  1579.     fp = fopen(filename, "r");
  1580.     if (NULL == fp)
  1581.     {
  1582.         return false;
  1583.     }
  1584.     if (!feof(fp))
  1585.     {
  1586.        fscanf( fp, "%d", &m_iCoeffLen);
  1587.     }
  1588.     i=0; // initialize i
  1589.     int coeff;
  1590.     while(!feof(fp) && i< m_iCoeffLen && i<SPEECH_FIR_30_TAPS_NUM)
  1591.     {
  1592.         fscanf(fp, "%d", &coeff);
  1593.         m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Input_Coeff[i] = (short) coeff;
  1594.         i++;
  1595.     }
  1596.     for (i=m_iCoeffLen; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1597.     {
  1598.         m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Input_Coeff[i]=0;
  1599.     }
  1600.     fclose(fp);
  1601.     return true;
  1602. }
  1603. //----------------------------------------------------------------------------
  1604. bool CSPCOEF::REQ_Write_FIR1_Input_Coeff_To_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1605. {
  1606.     m_eAudioParamType = e_audio_para_type;
  1607.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1608.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1609.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1610.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1611.         )
  1612.     {
  1613.         return false;
  1614.     }
  1615.     FILE *fp;
  1616.     int CoeffLength = SPEECH_FIR_30_TAPS_NUM;
  1617.     int i;
  1618.     fp = fopen(filename, "w");
  1619.     if (NULL == fp)
  1620.     {
  1621.         return false;
  1622.     }
  1623.     for (i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1624.     {
  1625.        if (0 == m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Input_Coeff[i])
  1626.        {
  1627.           CoeffLength = i;
  1628.           break;
  1629.        }
  1630.     }
  1631.     fprintf(fp, "%dn", CoeffLength);
  1632.     for (i=0; i<CoeffLength; i++)
  1633.     {
  1634.         fprintf(fp, "%dn", m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Input_Coeff[i]);
  1635.     }
  1636.     fclose(fp);
  1637.     return true;
  1638. }
  1639. //===========================================================================
  1640. bool CSPCOEF::REQ_Read_FIR1_Output_Coeff_From_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1641. {
  1642.     m_eAudioParamType = e_audio_para_type;
  1643.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1644.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1645.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1646.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1647.         )
  1648.     {
  1649.         return false;
  1650.     }
  1651.     FILE *fp;
  1652.     bool IsEof;
  1653.     int i=0;
  1654.     fp = fopen(filename, "r");
  1655.     if (NULL == fp)
  1656.     {
  1657.         return false;
  1658.     }
  1659.     if (!feof(fp))
  1660.     {
  1661.        fscanf(fp, "%d", &m_iCoeffLen);
  1662.     }
  1663.     i=0; // initialize i
  1664.     int coeff;
  1665.     while(!feof(fp) && i< m_iCoeffLen && i<SPEECH_FIR_30_TAPS_NUM)
  1666.     {
  1667.         fscanf( fp, "%d", &coeff);
  1668.         m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff[i] = (short) coeff;
  1669.         i++;
  1670.     }
  1671.     for (i=m_iCoeffLen; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1672.     {
  1673.         m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff[i] = 0;
  1674.     }
  1675.     fclose(fp);
  1676.     return true;
  1677. }
  1678. //---------------------------------------------------------------------------
  1679. bool CSPCOEF::REQ_Write_FIR1_Output_Coeff_To_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1680. {
  1681.     m_eAudioParamType = e_audio_para_type;
  1682.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1683.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1684.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1685.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1686.         )
  1687.     {
  1688.         return false;
  1689.     }
  1690.     FILE *fp;
  1691.     int CoeffLength = SPEECH_FIR_30_TAPS_NUM;
  1692.     int i;
  1693.     fp = fopen(filename, "w");
  1694.     if(fp == NULL)
  1695.     return false;
  1696.     for (i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1697.     {
  1698.        if (0 == m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff[i])
  1699.        {
  1700.           CoeffLength = i;
  1701.           break;
  1702.        }
  1703.     }
  1704.     fprintf(fp, "%dn", CoeffLength);
  1705.     for (i=0; i<CoeffLength; i++)
  1706.     {
  1707.        fprintf(fp, "%dn", m_sFirCoeff.s_Speech_FIR[AUDIO_NORMAL_MODE_INDEX].Speech_8k_Output_Coeff[i]);
  1708.     }
  1709.     fclose(fp);
  1710.     return true;
  1711. }
  1712. //==============================================================================
  1713. /////////////////////////////////////// FIR 2 //////////////////////////////////
  1714. //==============================================================================
  1715. bool CSPCOEF::REQ_Read_FIR2_Input_Coeff_From_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1716. {
  1717.     m_eAudioParamType = e_audio_para_type;
  1718.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1719.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1720.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1721.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1722.         )
  1723.     {
  1724.         return false;
  1725.     }
  1726.     FILE *fp;
  1727.     bool IsEof;
  1728.     int i;
  1729.     fp = fopen(filename, "r");
  1730.     if (NULL == fp)
  1731.     {
  1732.         return false;
  1733.     }
  1734.     if (!feof(fp))
  1735.     {
  1736.        fscanf(fp, "%d", &m_iCoeffLen);
  1737.     }
  1738.     i=0; // initialize i
  1739.     int coeff;
  1740.     while(!feof(fp) && i< m_iCoeffLen && i<SPEECH_FIR_30_TAPS_NUM)
  1741.     {
  1742.         fscanf( fp, "%d", &coeff);
  1743.         m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Input_Coeff[i] = (short) coeff;
  1744.         i++;
  1745.     }
  1746.     for(i=m_iCoeffLen; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1747.     {
  1748.         m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Input_Coeff[i]=0;
  1749.     }
  1750.     fclose(fp);
  1751.     return true;
  1752. }
  1753. //----------------------------------------------------------------------------
  1754. bool CSPCOEF::REQ_Write_FIR2_Input_Coeff_To_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1755. {
  1756.     m_eAudioParamType = e_audio_para_type;
  1757.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1758.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1759.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1760.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1761.         )
  1762.     {
  1763.         return false;
  1764.     }
  1765.     FILE *fp;
  1766.     int CoeffLength = SPEECH_FIR_30_TAPS_NUM;
  1767.     int i;
  1768.     fp = fopen(filename, "w");
  1769.     if(fp == NULL)
  1770.     return false;
  1771.     for (i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1772.     {
  1773.         if (0 == m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Input_Coeff[i])
  1774.         {
  1775.             CoeffLength = i;
  1776.             break;
  1777.         }
  1778.     }
  1779.     fprintf(fp, "%dn", CoeffLength);
  1780.     for (i=0; i<CoeffLength; i++)
  1781.     {
  1782.         fprintf(fp, "%dn", m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Input_Coeff[i]);
  1783.     }
  1784.     fclose(fp);
  1785.     return true;
  1786. }
  1787. //===========================================================================
  1788. bool CSPCOEF::REQ_Read_FIR2_Output_Coeff_From_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1789. {
  1790.     m_eAudioParamType = e_audio_para_type;
  1791.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1792.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1793.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1794.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1795.         )
  1796.     {
  1797.         return false;
  1798.     }
  1799.     FILE *fp;
  1800.     bool IsEof;
  1801.     int i=0;
  1802.     fp = fopen(filename, "r");
  1803.     if(fp == NULL)
  1804.     return false;
  1805.     if (!feof(fp))
  1806.     {
  1807.        fscanf( fp, "%d", &m_iCoeffLen);
  1808.     }
  1809.     i=0; // initialize i
  1810.     int coeff;
  1811.     while (!feof(fp) && i< m_iCoeffLen && i<SPEECH_FIR_30_TAPS_NUM)
  1812.     {
  1813.         fscanf(fp, "%d", &coeff);
  1814.         m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Output_Coeff[i] = (short) coeff;
  1815.         i++;
  1816.     }
  1817.     for (i=m_iCoeffLen; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1818.     {
  1819.         m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Output_Coeff[i] = 0;
  1820.     }
  1821.     fclose(fp);
  1822.     return true;
  1823. }
  1824. //----------------------------------------------------------------------------
  1825. bool CSPCOEF::REQ_Write_FIR2_Output_Coeff_To_File(char *filename, E_AUDIO_FIR_VER_T e_audio_para_type)
  1826. {
  1827.     m_eAudioParamType = e_audio_para_type;
  1828.     if ((AUDIO_FIR_VER_W0547_45_TAP == m_eAudioParamType) ||
  1829.         (AUDIO_FIR_VER_W0712        == m_eAudioParamType) ||
  1830.         (AUDIO_FIR_VER_W0740        == m_eAudioParamType) ||
  1831.         (AUDIO_FIR_VER_W0809        == m_eAudioParamType)
  1832.         )
  1833.     {
  1834.         return false;
  1835.     }
  1836.     FILE *fp;
  1837.     int CoeffLength = SPEECH_FIR_30_TAPS_NUM;
  1838.     fp = fopen(filename, "w");
  1839.     if(fp == NULL)
  1840.     return false;
  1841.     for (int i=0; i<SPEECH_FIR_30_TAPS_NUM; i++)
  1842.     {
  1843.        if (0 == m_sFirCoeff.s_Speech_FIR[AUDIO_HEADSET_MODE_INDEX].Speech_8k_Output_Coeff[i])
  1844.        {
  1845.           CoeffLength = i;
  1846.           break;
  1847.        }
  1848.     }