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

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.  *   volume_setting.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  Acoustic volume setting 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 _VOLUME_SETTING_H_
  69. #include "volume_setting.h"
  70. #endif
  71. #ifndef  _MAN_ACTIVE_H_
  72. #include "man_active.h"
  73. #endif
  74. #ifndef  _MAN_FDM_H_
  75. #include "man_fdm.h"
  76. #endif
  77. //===========================================================================
  78. static CVOLSET*  volume_setting_ptr;
  79. static bool g_bIsRunning = false;
  80. //===========================================================================
  81. static void CNF_ReadFromNVRAM(void)
  82. {
  83.     volume_setting_ptr->CNF_ReadFromNVRAM();
  84. }
  85. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86. static void CNF_WriteToNVRAM(void)
  87. {
  88.     volume_setting_ptr->CNF_WriteToNVRAM();
  89. }
  90. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. static void REQ_Get_Runtime_CustVol(void)
  92. {
  93.     volume_setting_ptr->REQ_Get_Runtime_CustVol();
  94. }
  95. //---------------------------------------------------------------------------
  96. static void REQ_Set_Runtime_CustVol(void)
  97. {
  98.     volume_setting_ptr->REQ_Set_Runtime_CustVol();
  99. }
  100. //===========================================================================
  101. CVOLSET::CVOLSET(void)
  102. {
  103.     g_bIsRunning = false;
  104.     ConfirmCallback = NULL;
  105.     m_pcVolSetBuf = NULL;
  106. }
  107. //---------------------------------------------------------------------------
  108. CVOLSET::~CVOLSET()
  109. {
  110.     g_bIsRunning = false;
  111.     ConfirmCallback = NULL;
  112.     ReleaseDynMemory();
  113. }
  114. //---------------------------------------------------------------------------
  115. void CVOLSET::Init(void)
  116. {
  117.     ReleaseDynMemory();
  118. }
  119. //---------------------------------------------------------------------------
  120. void CVOLSET::ReleaseDynMemory(void)
  121. {
  122.     if (NULL == m_pcVolSetBuf)
  123.     {
  124.         delete [] m_pcVolSetBuf;
  125.         m_pcVolSetBuf = NULL;
  126.         m_iVolSetBufSize = 0;
  127.     }
  128. }
  129. //---------------------------------------------------------------------------
  130. void CVOLSET::REQ_Stop(void)
  131. {
  132.     if (!g_bIsRunning)
  133.     {
  134.         return;
  135.     }
  136.     Confirm(METAAPP_STOP);
  137. }
  138. //---------------------------------------------------------------------------
  139. void CVOLSET::Confirm(E_METAAPP_RESULT_T confirm_state)
  140. {
  141.     if (!g_bIsRunning)
  142.     {
  143.         return;
  144.     }
  145.     g_bIsRunning = false;
  146.     if (NULL == ConfirmCallback)
  147.     {
  148.         return;
  149.     }
  150.     m_eConfirmState = confirm_state;
  151.     ActiveMan->SetActiveFunction(ConfirmCallback);
  152. }
  153. //===========================================================================
  154. ///////////////////////////  NVRAM read/write   /////////////////////////////
  155. //===========================================================================
  156. void CVOLSET::REQ_Read_From_NVRAM(bool CustVolExSupport)
  157. {
  158.     volume_setting_ptr = this;
  159.     g_bIsRunning = true;
  160.     m_bCustVolExSupport = CustVolExSupport;
  161.     if (NULL == m_pcVolSetBuf)
  162.     {
  163.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_CUST_ACOUSTIC_DATA_LID",
  164.                                                       &m_iVolSetBufSize
  165.                                                       );
  166.         if (MetaResult != META_SUCCESS)
  167.         {
  168.             Confirm(METAAPP_FAIL);
  169.             return;
  170.         }
  171.         m_pcVolSetBuf = new  char[m_iVolSetBufSize];
  172.    }
  173.    NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  174.    NVRAMMan->REQ_ReadNVRAM_Start("NVRAM_EF_CUST_ACOUSTIC_DATA_LID",
  175.                                  1,
  176.                                   m_iVolSetBufSize,
  177.                                   m_pcVolSetBuf );
  178. }
  179. //-------------------------------------
  180. void CVOLSET::CNF_ReadFromNVRAM(void)
  181. {
  182.     if (!g_bIsRunning)
  183.     {
  184.         return;
  185.     }
  186.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  187.     switch (state)
  188.     {
  189.         case METAAPP_SUCCESS:
  190.         {
  191.             if (!Decompose_CustAcousticVol())
  192.             {
  193.                 Confirm(METAAPP_FAIL);
  194.                 return;
  195.             }
  196.             Confirm(METAAPP_SUCCESS);
  197.        }
  198.        break;
  199.        default:
  200.        {
  201.            Confirm(state);
  202.        }
  203.        break;
  204.    }
  205. }
  206. //---------------------------------------------------------------------------
  207. bool  CVOLSET::Compose_CustAcousticVol(void)
  208. {
  209.     META_RESULT MetaResult;
  210.     if( ! m_bCustVolExSupport )
  211.     {
  212.         MetaResult = META_NVRAM_Compose_CustAcousticVol(&m_sCustVol, m_pcVolSetBuf, m_iVolSetBufSize);
  213.     }
  214.     else
  215.     {   MetaResult = META_NVRAM_Compose_16lvlCustAcousticVol(&m_sCustVolEx, m_pcVolSetBuf, m_iVolSetBufSize);
  216.     }
  217.     if(MetaResult!=META_SUCCESS)     return false;
  218.     return true;
  219. }
  220. //-------------------------------------
  221. bool  CVOLSET::Decompose_CustAcousticVol(void)
  222. {
  223.     META_RESULT MetaResult;
  224.     if (!m_bCustVolExSupport)
  225.     {
  226.         MetaResult = META_NVRAM_Decompose_CustAcousticVol(&m_sCustVol, m_pcVolSetBuf,  m_iVolSetBufSize);
  227.     }
  228.     else
  229.     {   MetaResult = META_NVRAM_Decompose_16lvlCustAcousticVol(&m_sCustVolEx, m_pcVolSetBuf,  m_iVolSetBufSize);
  230.     }
  231.     if (MetaResult != META_SUCCESS)
  232.     {
  233.         return false;
  234.     }
  235.     return true;
  236. }
  237. //===========================================================================
  238. void  CVOLSET::REQ_Write_To_NVRAM(bool CustVolExSupport, bool b_runtime_support)
  239. {
  240.     volume_setting_ptr = this;
  241.     g_bIsRunning = true;
  242.     m_bCustVolExSupport = CustVolExSupport;
  243.     m_bRuntimeSupport   = b_runtime_support;
  244.     if (NULL == m_pcVolSetBuf)
  245.     {
  246.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_CUST_ACOUSTIC_DATA_LID", &m_iVolSetBufSize);
  247.         if (MetaResult != META_SUCCESS)
  248.         {
  249.             Confirm(METAAPP_FAIL);
  250.             return;
  251.         }
  252.         m_pcVolSetBuf = new  char[m_iVolSetBufSize];
  253.     }
  254.     if (!Compose_CustAcousticVol())
  255.     {
  256.         Confirm(METAAPP_FAIL);
  257.         return;
  258.     }
  259.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  260.     NVRAMMan->REQ_WriteNVRAM_Start("NVRAM_EF_CUST_ACOUSTIC_DATA_LID",
  261.                                   1,
  262.                                    m_iVolSetBufSize,
  263.                                    m_pcVolSetBuf);
  264. }
  265. //-------------------------------------
  266. void  CVOLSET::CNF_WriteToNVRAM(void)
  267. {
  268.     if (!g_bIsRunning)
  269.     {
  270.         return;
  271.     }
  272.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  273.     if (METAAPP_SUCCESS == state)
  274.     {
  275.         if (m_bRuntimeSupport)
  276.         {
  277.             ActiveMan->SetActiveFunction(::REQ_Set_Runtime_CustVol);
  278.             return;
  279.         }    
  280.     }
  281.     Confirm(state);
  282. }
  283. //===========================================================================
  284. ///////////////////////////// runtime setting ///////////////////////////////
  285. //===========================================================================
  286. void CVOLSET::REQ_Get_Runtime_CustVol_Start(void)
  287. {
  288.     volume_setting_ptr = this;
  289.     g_bIsRunning = true;
  290.     ActiveMan->SetActiveFunction(::REQ_Get_Runtime_CustVol);
  291. }
  292. //---------------------------------------------------------------------------
  293. void CVOLSET::REQ_Get_Runtime_CustVol(void)
  294. {
  295.     if (!g_bIsRunning)
  296.     {
  297.         return;
  298.     }
  299.     Audio_Get_Profile_Settings_By_Mode_Req_T req;
  300.     Audio_Get_Profile_Settings_By_Mode_Cnf_T cnf;
  301.     unsigned char ucTotalModeNum = 3;
  302.     for (unsigned char ucMode = 0; ucMode < ucTotalModeNum; ucMode++)
  303.     {
  304.         req.m_ucMode = ucMode;
  305.         META_RESULT MetaResult = META_Audio_Get_Audio_Profile_Settings_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req, &cnf);
  306.         if (MetaResult != META_SUCCESS)
  307.         {
  308.             if (MetaResult != META_TIMEOUT)
  309.             {
  310.                 Confirm(METAAPP_FAIL);
  311.                 return;
  312.             }
  313.             else
  314.             {
  315.                 Confirm(METAAPP_TIMEOUT);
  316.                 return;
  317.             }
  318.         }
  319.     }
  320.     Confirm(METAAPP_SUCCESS);
  321. }
  322. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  323. void CVOLSET::REQ_Set_Runtime_CustVol_Start(void)
  324. {
  325.     volume_setting_ptr = this;
  326.     g_bIsRunning = true;
  327.     ActiveMan->SetActiveFunction(::REQ_Set_Runtime_CustVol);
  328. }
  329. //---------------------------------------------------------------------------
  330. void CVOLSET::REQ_Set_Runtime_CustVol(void)
  331. {
  332.     if (!g_bIsRunning)
  333.     {
  334.         return;
  335.     }
  336.     Audio_Set_Profile_Settings_By_Mode_Req_T req;
  337.     Audio_Set_Profile_Settings_By_Mode_Cnf_T cnf;
  338.     unsigned char ucTotalModeNum = 3;
  339.     for (unsigned char ucMode = 0; ucMode < ucTotalModeNum; ucMode++)
  340.     {
  341.         req.mode = ucMode;
  342.         ComposeCustAcousticVol16Lvl(m_sCustVolEx, req);
  343.        // req.m_ucMode = ucMode;
  344.         META_RESULT MetaResult = META_Audio_Set_Audio_Profile_Settings_r(m_META_HANDLE_Obj.Get_MainHandle(), 5000, &req, &cnf);
  345.         if (MetaResult != META_SUCCESS)
  346.         {
  347.             if (MetaResult != META_TIMEOUT)
  348.             {
  349.                 Confirm(METAAPP_FAIL);
  350.                 return;
  351.             }
  352.             else
  353.             {
  354.                 Confirm(METAAPP_TIMEOUT);
  355.                 return;
  356.             }
  357.         }
  358.     }
  359.     Confirm(METAAPP_SUCCESS);
  360. }
  361. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  362. void CVOLSET::ComposeCustAcousticVol(CustAcousticVol_T s_cust_vol, Audio_Get_Profile_Settings_By_Mode_Cnf_T& s_runtime)
  363. {
  364.     s_runtime.sidetone = s_cust_vol.volume_gain[s_runtime.mode][SIDE_TONE_TYPE][0];
  365.     for (int i = 0; i < CUST_VOL_LEVEL_NUM; i++)
  366.     {
  367.         s_runtime.keytone[i] = s_cust_vol.volume_gain[s_runtime.mode][KEYPAD_TONE_TYPE][i];
  368.         s_runtime.mic[i]     = s_cust_vol.volume_gain[s_runtime.mode][MICROPHONE_TYPE][i];
  369.         s_runtime.sound[i]   = s_cust_vol.volume_gain[s_runtime.mode][GMI_TONE_TYPE][i];
  370.         s_runtime.speech[i]  = s_cust_vol.volume_gain[s_runtime.mode][SPEECH_TONE_TYPE][i];
  371.         s_runtime.melody[i]  = s_cust_vol.volume_gain[s_runtime.mode][MELODY_TYPE][i];
  372.     }
  373. }
  374. //---------------------------------------------------------------------------
  375. void CVOLSET::DeComposeCustAcousticVol(Audio_Get_Profile_Settings_By_Mode_Cnf_T s_runtime, CustAcousticVol_T& s_cust_vol)
  376. {
  377.     for (int i = 0; i < CUST_VOL_LEVEL_NUM; i++)
  378.     {
  379.         s_cust_vol.volume_gain[s_runtime.mode][KEYPAD_TONE_TYPE][i] = s_runtime.keytone[i];
  380.         s_cust_vol.volume_gain[s_runtime.mode][MICROPHONE_TYPE][i]  = s_runtime.mic[i];
  381.         s_cust_vol.volume_gain[s_runtime.mode][GMI_TONE_TYPE][i]    = s_runtime.sound[i];
  382.         s_cust_vol.volume_gain[s_runtime.mode][SPEECH_TONE_TYPE][i] = s_runtime.speech[i];
  383.         s_cust_vol.volume_gain[s_runtime.mode][SIDE_TONE_TYPE][i]   = s_runtime.sidetone;
  384.         s_cust_vol.volume_gain[s_runtime.mode][MELODY_TYPE][i]      = s_runtime.melody[i];
  385.     }
  386. }
  387. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  388. void CVOLSET::ComposeCustAcousticVol16Lvl(CustAcousticVol16lvl_T s_cust_vol, Audio_Set_Profile_Settings_By_Mode_Req_T& s_runtime)
  389. {
  390.     for (int i = 0; i < CUST_VOL_LEVEL_NUM; i++)
  391.     {
  392.         //s_runtime. = s_cust_vol.volume_gain[s_runtime.mode][CALL_TONE_TYPE][i];
  393.         s_runtime.keytone[i]            = s_cust_vol.volume_gain[s_runtime.mode][KEYPAD_TONE_TYPE][i];
  394.         s_runtime.mic[i]                = s_cust_vol.volume_gain[s_runtime.mode][MICROPHONE_TYPE][i];
  395.         s_runtime.sound[i]              = s_cust_vol.volume_gain[s_runtime.mode][GMI_TONE_TYPE][i];
  396.         s_runtime.speech[i]             = s_cust_vol.volume_gain[s_runtime.mode][SPEECH_TONE_TYPE][i];
  397.         s_runtime.sidetone              = s_cust_vol.volume_gain[s_runtime.mode][SIDE_TONE_TYPE][i];
  398.         s_runtime.melody[i]             = s_cust_vol.volume_gain[s_runtime.mode][MELODY_TYPE][i];
  399.         s_runtime.tv_out_volume_gain[i] = s_cust_vol.tv_out_volume_gain[i];
  400.     }
  401.     s_runtime.max_melody_volume_gain  = s_cust_vol.max_melody_volume_gain[s_runtime.mode];
  402.     s_runtime.melody_volume_gain_step = s_cust_vol.melody_volume_gain_step[s_runtime.mode];
  403. }
  404. //---------------------------------------------------------------------------
  405. void CVOLSET::DeComposeCustAcousticVol16Lvl(Audio_Get_Profile_Settings_By_Mode_Cnf_T s_runtime, CustAcousticVol16lvl_T& s_cust_vol)
  406. {
  407.     for (int i = 0; i < CUST_VOL_LEVEL_NUM; i++)
  408.     {
  409.         //s_cust_vol.volume_gain[s_runtime.mode][CALL_TONE_TYPE][i]   = s_runtime.
  410.         s_cust_vol.volume_gain[s_runtime.mode][KEYPAD_TONE_TYPE][i] = s_runtime.keytone[i];
  411.         s_cust_vol.volume_gain[s_runtime.mode][MICROPHONE_TYPE][i]  = s_runtime.mic[i];
  412.         s_cust_vol.volume_gain[s_runtime.mode][GMI_TONE_TYPE][i]    = s_runtime.sound[i];
  413.         s_cust_vol.volume_gain[s_runtime.mode][SPEECH_TONE_TYPE][i] = s_runtime.speech[i];
  414.         s_cust_vol.volume_gain[s_runtime.mode][SIDE_TONE_TYPE][i]   = s_runtime.sidetone;
  415.         s_cust_vol.volume_gain[s_runtime.mode][MELODY_TYPE][i]      = s_runtime.melody[i];
  416.     }
  417.     s_cust_vol.max_melody_volume_gain[s_runtime.mode]  = s_runtime.max_melody_volume_gain;
  418.     s_cust_vol.melody_volume_gain_step[s_runtime.mode] = s_runtime.melody_volume_gain_step;
  419. }
  420. //===========================================================================
  421. ///////////////////////////// file read/write ///////////////////////////////
  422. //===========================================================================
  423. bool CVOLSET::REQ_Read_From_File( char *filename, bool CustVolExSupport )
  424. {
  425.     TIniFile   *ini_file;
  426.     AnsiString  data;
  427.     AnsiString  CategoryStr;
  428.     AnsiString  ItemStr;
  429.     int         i, j, k;
  430.     AnsiString VolumeMode[] = { "Normal", "Headset", "Handfree", "TV Out" };
  431.     AnsiString ToneType[] = {"Call Tone", "Keypad Tone", "Microphone", "GMI Tone", "Speech Tone", "Side Tone", "Melody"};
  432.     AnsiString VolumeLevel[] = { "Level 0", "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6"};
  433.     ini_file = new TIniFile( filename );
  434.     if( ini_file == NULL )  return false;
  435.     // Volume level
  436.     for (i=0; i<TOTAL_AUDIO_MODE_NUM-1; i++)
  437.     {
  438.         for (j=0; j<TOTAL_TONE_NUM; j++)
  439.         {
  440.             if( j!= MICROPHONE_INDEX && j!= SIDE_TONE_INDEX && j!=CALL_TONE_INDEX && j!=GMI_TONE_INDEX )
  441.             {
  442.                 CategoryStr = VolumeMode[i] + " Volume Level";
  443.                 ItemStr = ToneType[j];
  444.                 if( ! CustVolExSupport )
  445.                 {
  446.                     m_sCustVol.volume[i][j] = ini_file->ReadInteger(CategoryStr, ItemStr, 3);
  447.                 }
  448.                 else
  449.                 {   m_sCustVolEx.volume[i][j] = ini_file->ReadInteger(CategoryStr, ItemStr, 3);
  450.                 }
  451.             }
  452.         }
  453.    }
  454.    // Volume gain
  455.    for (i=0; i<TOTAL_AUDIO_MODE_NUM-1; i++)
  456.    {
  457.         for (j=0; j<TOTAL_TONE_NUM; j++)
  458.         {
  459.             if( j != MICROPHONE_INDEX && j != SIDE_TONE_INDEX && j!=CALL_TONE_INDEX && j!=GMI_TONE_INDEX )
  460.             {
  461.                 for (k=0; k<TOTAL_VOLUME_LEVEL_NUM; k++)
  462.                 {
  463.                     CategoryStr = VolumeMode[i] + " Volume Gain";
  464.                     ItemStr = ToneType[j] + " " + VolumeLevel[k];
  465.                     if( ! CustVolExSupport )
  466.                     {
  467.                         m_sCustVol.volume_gain[i][j][k] = ini_file->ReadInteger(CategoryStr, ItemStr, 0);
  468.                     }
  469.                     else
  470.                     {   m_sCustVolEx.volume_gain[i][j][k] = ini_file->ReadInteger(CategoryStr, ItemStr, 0);
  471.                     }
  472.                 }
  473.             }
  474.             else if( j == MICROPHONE_INDEX || j == SIDE_TONE_INDEX )
  475.             {
  476.                 CategoryStr = VolumeMode[i] + " Volume Gain";
  477.                 ItemStr = ToneType[j] + " " + VolumeLevel[0];
  478.                 if( ! CustVolExSupport )
  479.                 {
  480.                     m_sCustVol.volume_gain[i][j][0] = ini_file->ReadInteger(CategoryStr, ItemStr, 0);
  481.                 }
  482.                 else
  483.                 {   m_sCustVolEx.volume_gain[i][j][0] = ini_file->ReadInteger(CategoryStr, ItemStr, 0);
  484.                 }
  485.             }
  486.         }
  487.    }
  488.    if( CustVolExSupport )
  489.    {
  490.        for(i=0; i<TOTAL_AUDIO_MODE_NUM; i++)
  491.        {
  492.            CategoryStr = "16 Level Max Melody Volume Gain";
  493.            ItemStr = VolumeMode[i] + " Max Melody Volume Gain";
  494.            m_sCustVolEx.max_melody_volume_gain[i] = ini_file->ReadInteger( CategoryStr, ItemStr, 0 );
  495.        }
  496.        for(i=0; i<TOTAL_AUDIO_MODE_NUM; i++)
  497.        {
  498.            CategoryStr = "16 Level Melody Volume Gain Step";
  499.            ItemStr = VolumeMode[i] + " Melody Volume Gain Step";
  500.            m_sCustVolEx.melody_volume_gain_step[i] = ini_file->ReadInteger( CategoryStr, ItemStr, 0 );
  501.        }
  502.        for( i=0; i<TOTAL_VOLUME_LEVEL_NUM; i++ )
  503.        {
  504.            CategoryStr = "TV Out Volume Gain";
  505.            ItemStr = "TV Out Volume Gain " + IntToStr(i);
  506.            m_sCustVolEx.tv_out_volume_gain[i] = ini_file->ReadInteger( CategoryStr, ItemStr, 0 );
  507.        }
  508.    }
  509.    delete  ini_file;
  510.    return  true;
  511. }
  512. //-----------------------------------------------------------------------------------------------
  513. bool  CVOLSET::REQ_Write_To_File( char *filename, bool hideEnable, bool CustVolExSupport )
  514. {
  515.    TIniFile   *ini_file;
  516.    AnsiString  data;
  517.    AnsiString  CategoryStr;
  518.    AnsiString  ItemStr;
  519.    int         i, j, k;
  520.    AnsiString VolumeMode[] = { "Normal", "Headset", "Handfree", "TV Out" };
  521.    AnsiString ToneType[] = {"Call Tone", "Keypad Tone", "Microphone", "GMI Tone", "Speech Tone", "Side Tone", "Melody"};
  522.    AnsiString VolumeLevel[] = { "Level 0", "Level 1", "Level 2", "Level 3", "Level 4", "Level 5", "Level 6"};
  523.    ini_file = new TIniFile( filename );
  524.    if( ini_file == NULL )  return  false;
  525.    if (ini_file != NULL)
  526.    {
  527.       // Volume level
  528.       for (i=0; i<TOTAL_AUDIO_MODE_NUM-1; i++)
  529.       {
  530.           for (j=0; j<TOTAL_TONE_NUM; j++)
  531.           {
  532.               if( j!= MICROPHONE_INDEX && j!= SIDE_TONE_INDEX && j!=CALL_TONE_INDEX && j!=GMI_TONE_INDEX )
  533.               {
  534.                     CategoryStr = VolumeMode[i] + " Volume Level";
  535.                     ItemStr = ToneType[j];
  536.                     if( ! CustVolExSupport )
  537.                     {
  538.                         ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVol.volume[i][j]  );
  539.                     }
  540.                     else
  541.                     {
  542.                         ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVolEx.volume[i][j]  );
  543.                     }
  544.                }
  545.           }
  546.       }
  547.       for (i=0; i<TOTAL_AUDIO_MODE_NUM-1; i++)
  548.       {
  549.           for (j=0; j<TOTAL_TONE_NUM; j++)
  550.           {
  551.               for (k=0; k<TOTAL_VOLUME_LEVEL_NUM; k++)
  552.               {
  553.                   if( j != MICROPHONE_INDEX && j != SIDE_TONE_INDEX && j!=CALL_TONE_INDEX && j!=GMI_TONE_INDEX )
  554.                   {
  555.                       CategoryStr = VolumeMode[i] + " Volume Gain";
  556.                       ItemStr = ToneType[j] + " " + VolumeLevel[k];
  557.                       if( ! CustVolExSupport )
  558.                       {
  559.                           ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVol.volume_gain[i][j][k] );
  560.                       }
  561.                       else
  562.                       {
  563.                           ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVolEx.volume_gain[i][j][k] );
  564.                       }
  565.                   }
  566.                   else if( j == MICROPHONE_INDEX || j == SIDE_TONE_INDEX )
  567.                   {
  568.                         CategoryStr = VolumeMode[i] + " Volume Gain";
  569.                         ItemStr = ToneType[j] + " " + VolumeLevel[0];
  570.                         if( ! CustVolExSupport )
  571.                         {
  572.                             ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVol.volume_gain[i][j][0] );
  573.                         }
  574.                         else
  575.                         {   ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVolEx.volume_gain[i][j][0] );
  576.                         }
  577.                   }
  578.               }
  579.           }
  580.       }
  581.       if( CustVolExSupport )
  582.       {
  583.           for(i=0; i<TOTAL_AUDIO_MODE_NUM; i++)
  584.           {
  585.               CategoryStr = "16 Level Max Melody Volume Gain";
  586.               ItemStr = VolumeMode[i] + " Max Melody Volume Gain";
  587.               ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVolEx.max_melody_volume_gain[i] );
  588.           }
  589.           for(i=0; i<TOTAL_AUDIO_MODE_NUM; i++)
  590.           {
  591.               CategoryStr = "16 Level Melody Volume Gain Step";
  592.               ItemStr = VolumeMode[i] + " Melody Volume Gain Step";
  593.               ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVolEx.melody_volume_gain_step[i] );
  594.           }
  595.           for( i=0; i<TOTAL_VOLUME_LEVEL_NUM; i++ )
  596.           {
  597.               CategoryStr = "TV Out Volume Gain";
  598.               ItemStr = "TV Out Volume Gain " + IntToStr(i);
  599.               ini_file->WriteInteger( CategoryStr, ItemStr, m_sCustVolEx.tv_out_volume_gain[i] );
  600.           }
  601.       }
  602.       delete  ini_file;
  603.     }
  604.    return  true;
  605. }
  606. //===========================================================================
  607. bool  CVOLSET::REQ_Write_To_nvram_default_audio( char *filename, S_TONE_SUPPORT tone_support, bool CustVolExSupport )
  608. {
  609.     FILE *fs;
  610.     int  i, j, k;
  611.     AnsiString  as_str;
  612.     AnsiString  as_mode[MAX_VOL_CATE+1] = { (AnsiString) "NOR",
  613.                                           (AnsiString) "HED",
  614.                                           (AnsiString) "HND",
  615.                                           (AnsiString) "TVO"
  616.                                         };
  617.     AnsiString  as_type[MAX_VOL_TYPE] = { (AnsiString) "CTN",
  618.                                           (AnsiString) "KEY",
  619.                                           (AnsiString) "MIC",
  620.                                           (AnsiString) "GMI",
  621.                                           (AnsiString) "SPH",
  622.                                           (AnsiString) "SID",
  623.                                           (AnsiString) "MED"
  624.                                         };
  625.     AnsiString  as_comment[MAX_VOL_CATE] = { (AnsiString) "Normal",
  626.                                              (AnsiString) "Headset",
  627.                                              (AnsiString) "Handfree"
  628.                                            };
  629.     fs = fopen( filename, "w" );
  630.     if(fs==0)  return(false);
  631.     fprintf( fs, "#include "kal_release.h"nn");
  632.     if( CustVolExSupport )
  633.     {
  634.         for( i=0; i<MAX_VOL_CATE+1; i++ )
  635.         {
  636.             if( i != TVOUT_MODE )
  637.             {
  638.                 as_str = "#define GAIN_" + as_mode[i] + "_MED_VOL_MAX      " + m_sCustVolEx.max_melody_volume_gain[i] + "n";
  639.             }
  640.             else
  641.             {   as_str = "#define GAIN_" + as_mode[i] + "_VOL_MAX      " + m_sCustVolEx.max_melody_volume_gain[i] + "n";
  642.             }
  643.             fprintf( fs, as_str.c_str() );
  644.         }
  645.         for( i=0; i<MAX_VOL_CATE+1; i++ )
  646.         {
  647.             if( i != TVOUT_MODE )
  648.             {
  649.                 as_str = "#define GAIN_" + as_mode[i] + "_MED_VOL_STEP      " + m_sCustVolEx.melody_volume_gain_step[i] + "n";
  650.             }
  651.             else
  652.             {   as_str = "#define GAIN_" + as_mode[i] + "_VOL_STEP      " + m_sCustVolEx.melody_volume_gain_step[i] + "n";
  653.             }
  654.             fprintf( fs, as_str.c_str() );
  655.         }
  656.         fprintf( fs, "n" );
  657.         for( i=0; i<MAX_VOL_LEVEL; i++ )
  658.         {   as_str = "#define GAIN_TVO_VOL" + IntToStr(i) + "      " + m_sCustVolEx.tv_out_volume_gain[i] + "n";
  659.             fprintf( fs, as_str.c_str() );
  660.         }
  661.     }
  662.     for( i=0; i<MAX_VOL_CATE; i++ )
  663.     {
  664.         as_str = "/* define Gain For " + as_comment[i] + " */n";
  665.         fprintf( fs, as_str.c_str() );
  666.         fprintf( fs, "/* speaker, microphone, loudspeaker, buzzer */n" );
  667.         for( j=0; j<MAX_VOL_TYPE; j++ )
  668.         {
  669.             if( j!=MICROPHONE_INDEX && j!=SIDE_TONE_INDEX && j!=CALL_TONE_INDEX && j!=GMI_TONE_INDEX )
  670.             {
  671.                // if( frmAudio->m_cbTone[j]->Visible )
  672.                 if( tone_support.b_ToneSupport[j] )
  673.                 {
  674.                     if( ! CustVolExSupport )
  675.                     {
  676.                         as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL"  + "      " + m_sCustVol.volume[i][j] + "n";
  677.                     }
  678.                     else
  679.                     {
  680.                         as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL"  + "      " + m_sCustVolEx.volume[i][j] + "n";
  681.                     }
  682.                     fprintf( fs, as_str.c_str() );
  683.                 }
  684.                 for( k=0; k<MAX_VOL_LEVEL; k++ )
  685.                 {
  686.                     if( ! CustVolExSupport )
  687.                     {
  688.                         as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL" + IntToStr(k) + "     " + m_sCustVol.volume_gain[i][j][k] + "n";
  689.                     }
  690.                     else
  691.                     {
  692.                         as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL" + IntToStr(k) + "     " + m_sCustVolEx.volume_gain[i][j][k] + "n";
  693.                     }
  694.                     fprintf( fs, as_str.c_str() );
  695.                 }
  696.                 fprintf( fs, "n" );
  697.             }
  698.             else if( j==MICROPHONE_INDEX || j==SIDE_TONE_INDEX )  // microphone & sidetone only contain one volume level
  699.             {
  700.                 if( ! CustVolExSupport )
  701.                 {
  702.                     as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL"  + "      " + m_sCustVol.volume[i][j] + "n";
  703.                 }
  704.                 else
  705.                 {   as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL"  + "      " + m_sCustVolEx.volume[i][j] + "n";
  706.                 }
  707.                 fprintf( fs, as_str.c_str() );
  708.                 if( ! CustVolExSupport )
  709.                 {
  710.                     as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL" + IntToStr(0) + "     " + m_sCustVol.volume_gain[i][j][0] + "n";
  711.                 }
  712.                 else
  713.                 {   as_str = "#define GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL" + IntToStr(0) + "     " + m_sCustVolEx.volume_gain[i][j][0] + "n";
  714.                 }
  715.                 fprintf( fs, as_str.c_str() );
  716.                 fprintf( fs, "n" );
  717.             }
  718.         }
  719.     }
  720.     // array
  721.     fprintf( fs, "kal_uint8 const NVRAM_EF_CUST_ACOUSTIC_DATA_DEFAULT[] = {" );
  722.     for( i=0; i<MAX_VOL_CATE; i++ )
  723.     {
  724.         fprintf( fs, "n      " );
  725.         as_str = "/* " + as_comment[i] + ": Call Tone, Keypad Tone, Microphone, GMI Tone, Speech Tone, Side Tone */n";
  726.         fprintf( fs, as_str.c_str() );
  727.         for( j=0; j<MAX_VOL_TYPE; j++ )
  728.         {
  729.             fprintf( fs, "      " );
  730.             for( k=0; k<MAX_VOL_LEVEL; k++ )
  731.             {
  732.                 as_str = "GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL" + IntToStr(k) + ", ";
  733.                 fprintf( fs, as_str.c_str() );
  734.             }
  735.             fprintf( fs, "n" );
  736.         }
  737.     }
  738.     for( i=0; i<MAX_VOL_CATE; i++ )
  739.     {
  740.         fprintf( fs, "n      " );
  741.         as_str = "/* " + as_comment[i] + " volume: CTN, SPK, MIC, BUZ, SPH, SID, MED */n";
  742.         fprintf( fs, as_str.c_str() );
  743.         fprintf( fs, "      " );
  744.         for( j=0; j<MAX_VOL_TYPE; j++ )
  745.         {
  746.             as_str = "GAIN_" + as_mode[i] + "_" + as_type[j] + "_VOL";
  747.             fprintf( fs, as_str.c_str() );
  748.             if( i == MAX_VOL_CATE-1 && j == MAX_VOL_TYPE-1 )
  749.             {
  750.                 break;
  751.             }
  752.             fprintf( fs, ", " );
  753.         }
  754.     }
  755.     fprintf( fs, "nn     " );
  756.     as_str = "/* Normal, Headset, Handfree mode melody volume gains */";
  757.     fprintf( fs, as_str.c_str() );
  758.     fprintf( fs, "n      " );
  759.     for( i=0; i<MAX_VOL_CATE; i++ )
  760.     {
  761.         as_str = ", GAIN_" + as_mode[i] + "_MED_VOL_MAX";
  762.         fprintf( fs, as_str.c_str() );
  763.     }
  764.     as_str = ", GAIN_TVO_VOL_MAX,";
  765.     fprintf( fs, as_str.c_str() );
  766.     fprintf( fs, "n      " );
  767.     as_str = "/* Normal, Headset, Handfree mode melody volume gain steps */";
  768.     fprintf( fs, as_str.c_str() );
  769.     fprintf( fs, "n      " );
  770.     for( i=0; i<MAX_VOL_CATE; i++ )
  771.     {
  772.         as_str = " GAIN_" + as_mode[i] + "_MED_VOL_STEP,";
  773.         fprintf( fs, as_str.c_str() );
  774.     }
  775.     as_str = " GAIN_TVO_VOL_STEP,";
  776.     fprintf( fs, as_str.c_str() );
  777.     fprintf( fs, "n      " );
  778.     as_str = "/* TV out volume gains*/";
  779.     fprintf( fs, as_str.c_str() );
  780.     fprintf( fs, "n      " );
  781.     for( i=0; i<MAX_VOL_LEVEL-1; i++ )
  782.     {
  783.         as_str = " GAIN_TVO_VOL" + IntToStr(i) + ",";
  784.         fprintf( fs, as_str.c_str() );
  785.     }
  786.     as_str = " GAIN_TVO_VOL6";
  787.     fprintf( fs, as_str.c_str() );
  788.     fprintf( fs, "n};nn");
  789.     fclose(fs);
  790.     return(true);
  791. }
  792. //===========================================================================
  793. ////////////////////////////        Query         ///////////////////////////
  794. //===========================================================================
  795. bool CVOLSET::Query_CustVolExSupport_Start(void)
  796. {
  797.     META_RESULT  MetaResult = META_QueryIfTargetSupportAcoustic16level_r(m_META_HANDLE_Obj.Get_MainHandle(), 300);
  798.     if (MetaResult != META_SUCCESS)
  799.     {
  800.         return false;
  801.     }
  802.     return true;
  803. }
  804. //--------------------------------------------------------------------------
  805. bool CVOLSET::Query_CustVolRuntime_Support_Start(void)
  806. {
  807.     META_RESULT MetaResult = META_QueryIfFunctionSupportedByTarget_r(m_META_HANDLE_Obj.Get_MainHandle(), 300, "META_Audio_Set_Audio_Profile_Settings_r");
  808.     if(MetaResult!=META_SUCCESS)
  809.     {
  810.         return false;
  811.     }
  812.     return true;
  813. }
  814. //===========================================================================
  815. ////////////////////////////  Export information  ///////////////////////////
  816. //===========================================================================
  817. E_METAAPP_RESULT_T CVOLSET::Get_ConfirmState(void)
  818. {
  819.     return  m_eConfirmState;
  820. }
  821. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  822. CustAcousticVol_T* CVOLSET::Get_CustVol(void)
  823. {
  824.     return &m_sCustVol;
  825. }
  826. //---------------------------------------------------------------------------
  827. void CVOLSET::Set_CustVol(CustAcousticVol_T cust_vol)
  828. {
  829.     m_sCustVol = cust_vol;
  830. }
  831. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  832. CustAcousticVol16lvl_T* CVOLSET::Get_CustVol16(void)
  833. {
  834.     return &m_sCustVolEx;
  835. }
  836. //---------------------------------------------------------------------------
  837. void CVOLSET::Set_CustVol16(CustAcousticVol16lvl_T cust_vol)
  838. {
  839.     m_sCustVolEx = cust_vol;
  840. }
  841. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  842. unsigned char CVOLSET::Get_CustVol(  int cate, int type, bool CustVolExSupport )
  843. {
  844.     if( CustVolExSupport )
  845.     {
  846.         return m_sCustVolEx.volume[cate][type];
  847.     }
  848.     else
  849.     {
  850.         return m_sCustVol.volume[cate][type];
  851.     }
  852. }
  853. //---------------------------------------------------------------------------
  854. void CVOLSET::Set_CustVol( int cate, int type, unsigned char vol, bool CustVolExSupport )
  855. {
  856.     if( CustVolExSupport )
  857.     {
  858.         m_sCustVolEx.volume[cate][type] = vol;
  859.     }
  860.     else
  861.     {
  862.         m_sCustVol.volume[cate][type] = vol;
  863.     }
  864. }
  865. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  866. unsigned char CVOLSET::Get_CustVolGain( int cate, int type, int level, bool CustVolExSupport )
  867. {
  868.     if( CustVolExSupport )
  869.     {
  870.         return m_sCustVolEx.volume_gain[cate][type][level];
  871.     }
  872.     else
  873.     {
  874.         return m_sCustVol.volume_gain[cate][type][level];
  875.     }
  876. }
  877. //---------------------------------------------------------------------------
  878. void CVOLSET::Set_CustVolGain( int cate, int type, int level, unsigned char vol_gain, bool CustVolExSupport )
  879. {
  880.     if( CustVolExSupport )
  881.     {
  882.         m_sCustVolEx.volume_gain[cate][type][level] = vol_gain;
  883.     }
  884.     else
  885.     {
  886.         m_sCustVol.volume_gain[cate][type][level] = vol_gain;
  887.     }
  888. }
  889. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  890. unsigned char CVOLSET::Get_MaxMelodyVolGain( int cate )
  891. {
  892.     return m_sCustVolEx.max_melody_volume_gain[cate];
  893. }
  894. //--------------------------------------------------------------------------
  895. void CVOLSET::Set_MaxMelodyVolGain( int cate, unsigned char vol_gain )
  896. {   m_sCustVolEx.max_melody_volume_gain[cate] = vol_gain;
  897. }
  898. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  899. unsigned char CVOLSET::Get_MelodyVolGainStep( int cate )
  900. {   return m_sCustVolEx.melody_volume_gain_step[cate];
  901. }
  902. //---------------------------------------------------------------------------
  903. void  CVOLSET::Set_MelodyVolGainStep( int cate, unsigned char gain_step )
  904. {   m_sCustVolEx.melody_volume_gain_step[cate] = gain_step;
  905. }
  906. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  907. unsigned char CVOLSET::Get_TvOutVolGain( int level )
  908. {   return m_sCustVolEx.tv_out_volume_gain[level];
  909. }
  910. //---------------------------------------------------------------------------
  911. void CVOLSET::Set_TvOutVolGain( int level, unsigned char vol_gain)
  912. {   m_sCustVolEx.tv_out_volume_gain[level] = vol_gain;
  913. }