Audio3DEffect.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:18k
源码类别:

MTK

开发平台:

C/C++

  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. * Audio3DEffect.c
  40. *
  41. * Project:
  42. * --------
  43. *   MAUI
  44. *
  45. * Description:
  46. * ------------
  47. *   This file is to setup audio 3D sound effect
  48. *
  49. * Author:
  50. * -------
  51. * Wilson Lien (mtk00676)
  52. *
  53. *============================================================================
  54. *             HISTORY
  55. * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Log$
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * 
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * 
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * 
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * 
  74.  *
  75.  * removed!
  76.  * removed!
  77.  * 
  78.  *
  79.  * removed!
  80.  * removed!
  81.  * 
  82.  *
  83.  *------------------------------------------------------------------------------
  84. * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  85. *============================================================================
  86. ****************************************************************************/
  87. #ifndef _AUDIO_3D_EFFECT_C
  88. #define _AUDIO_3D_EFFECT_C
  89. #include "MMI_features.h"
  90. #ifdef __MMI_AUDIO_3D_EFFECT__
  91. #include "stdC.h"
  92. #include "L4Dr1.h"
  93. #include "PixtelDataTypes.h"
  94. #include "kal_trace.h"  /* Debug Info */
  95. #include "DebugInitDef.h"       /* Debug Info */
  96. #include "mmi_trc.h"    /* Debug Info */
  97. #include "CommonScreens.h"
  98. #include "SettingDefs.h"
  99. #include "SettingsGdcl.h"
  100. #include "settingStructs.h"
  101. #include "settingGprots.h"
  102. #include "SettingProt.h"
  103. #include "SettingProfile.h"
  104. #include "NVRAMType.h"
  105. #include "NVRAMProt.h"
  106. #include "NVRAMEnum.h"
  107. #include "mdi_datatype.h"
  108. #include "mdi_audio.h"
  109. #include "Audio3DEffect.h"
  110. #include "wgui_status_icons.h"
  111. /* 
  112.  * Typedef 
  113.  */
  114. /* 
  115.  * Define
  116.  */
  117. /* 
  118.  * Local Variable
  119.  */
  120. audio_3d_effect_struct g_mmi_aud_3d_cntx;
  121. static U16 selected_audio_3d_effect_index = 0;
  122. /* 
  123.  * Local Function
  124.  */
  125. /* 
  126.  * Global Variable
  127.  */
  128. #if defined(MMI_ON_HARDWARE_P)
  129. extern const S16 *audio_3d_effect_table[];
  130. #else 
  131. const S16 *audio_3d_effect_table[MAX_AUDIO_3D_EFFECT_NUM];
  132. #endif 
  133. /* 
  134.  * Global Function
  135.  */
  136. /*****************************************************************************
  137.  * FUNCTION
  138.  *  mmi_aud_3d_effect_init
  139.  * DESCRIPTION
  140.  *  This function is to init 3D effect
  141.  * PARAMETERS
  142.  *  void
  143.  * RETURNS
  144.  *  void
  145.  *****************************************************************************/
  146. void mmi_aud_3d_effect_init(void)
  147. {
  148.     /*----------------------------------------------------------------*/
  149.     /* Local Variables                                                */
  150.     /*----------------------------------------------------------------*/
  151.     /*----------------------------------------------------------------*/
  152.     /* Code Body                                                      */
  153.     /*----------------------------------------------------------------*/
  154.     SetHiliteHandler(MENU_SETTING_AUDIO_3D_EFFECT, mmi_aud_3d_effect_highlight_hdlr);
  155.     SetHintHandler(MENU_SETTING_AUDIO_3D_EFFECT, mmi_aud_3d_effect_hint_hdlr);
  156.     /* Read value from NVRAM and set 3D effect if turned on */
  157.     mmi_aud_3d_read_nvram();
  158.     mmi_aud_3d_init_effect(g_mmi_aud_3d_cntx.index);
  159. }
  160. /*****************************************************************************
  161.  * FUNCTION
  162.  *  mmi_aud_3d_effect_highlight_hdlr
  163.  * DESCRIPTION
  164.  *  This function is the highlight handler of 3d effect item
  165.  * PARAMETERS
  166.  *  void
  167.  * RETURNS
  168.  *  void
  169.  *****************************************************************************/
  170. void mmi_aud_3d_effect_highlight_hdlr(void)
  171. {
  172.     /*----------------------------------------------------------------*/
  173.     /* Local Variables                                                */
  174.     /*----------------------------------------------------------------*/
  175.     /*----------------------------------------------------------------*/
  176.     /* Code Body                                                      */
  177.     /*----------------------------------------------------------------*/
  178.     SetLeftSoftkeyFunction(mmi_entry_aud_3d_effect_list, KEY_EVENT_UP);
  179.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  180.     SetKeyHandler(mmi_entry_aud_3d_effect_list, KEY_RIGHT_ARROW, KEY_EVENT_DOWN);
  181.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  182. }
  183. /*****************************************************************************
  184.  * FUNCTION
  185.  *  mmi_aud_3d_effect_hint_hdlr
  186.  * DESCRIPTION
  187.  *  This function is the hint handler of 3d effect item
  188.  * PARAMETERS
  189.  *  index       [IN]        
  190.  * RETURNS
  191.  *  void
  192.  *****************************************************************************/
  193. void mmi_aud_3d_effect_hint_hdlr(U16 index)
  194. {
  195.     /*----------------------------------------------------------------*/
  196.     /* Local Variables                                                */
  197.     /*----------------------------------------------------------------*/
  198.     /*----------------------------------------------------------------*/
  199.     /* Code Body                                                      */
  200.     /*----------------------------------------------------------------*/
  201.     memset((S8*) hintData[(index)], 0, MAX_SUB_MENU_SIZE);
  202.     if (g_mmi_aud_3d_cntx.index > 0)
  203.     {
  204.         pfnUnicodeStrcpy(
  205.             (S8*) hintData[(index)],
  206.             GetString((U16) (STR_ID_SETTING_AUDIO_3D_EFFECT_SET1 + g_mmi_aud_3d_cntx.index - 1)));
  207.     }
  208.     else
  209.     {
  210.         pfnUnicodeStrcpy((S8*) hintData[(index)], GetString(STR_GLOBAL_NONE));
  211.     }
  212. }
  213. /*****************************************************************************
  214.  * FUNCTION
  215.  *  mmi_aud_3d_effect_list_highlight_hdlr
  216.  * DESCRIPTION
  217.  *  This function is the highlight handler of 3d effect list
  218.  * PARAMETERS
  219.  *  index       [IN]        
  220.  * RETURNS
  221.  *  void
  222.  *****************************************************************************/
  223. void mmi_aud_3d_effect_list_highlight_hdlr(S32 index)
  224. {
  225.     /*----------------------------------------------------------------*/
  226.     /* Local Variables                                                */
  227.     /*----------------------------------------------------------------*/
  228.     /*----------------------------------------------------------------*/
  229.     /* Code Body                                                      */
  230.     /*----------------------------------------------------------------*/
  231.     selected_audio_3d_effect_index = (U16) index;
  232. }
  233. /*****************************************************************************
  234.  * FUNCTION
  235.  *  mmi_aud_3d_effect_list_LSK_hdlr
  236.  * DESCRIPTION
  237.  *  This function is the LSK handler of 3d effect list
  238.  * PARAMETERS
  239.  *  void
  240.  * RETURNS
  241.  *  void
  242.  *****************************************************************************/
  243. void mmi_aud_3d_effect_list_LSK_hdlr(void)
  244. {
  245.     /*----------------------------------------------------------------*/
  246.     /* Local Variables                                                */
  247.     /*----------------------------------------------------------------*/
  248.     /*----------------------------------------------------------------*/
  249.     /* Code Body                                                      */
  250.     /*----------------------------------------------------------------*/
  251.     if (mmi_aud_3d_set_effect(selected_audio_3d_effect_index))
  252.     {
  253.         DisplayPopup(
  254.             (PU8) GetString(STR_GLOBAL_DONE),
  255.             IMG_GLOBAL_ACTIVATED,
  256.             1,
  257.             UI_POPUP_NOTIFYDURATION_TIME,
  258.             SUCCESS_TONE);
  259.     }
  260.     else
  261.     {
  262.         DisplayPopup((PU8) GetString(STR_GLOBAL_ERROR), IMG_GLOBAL_ERROR, 1, UI_POPUP_NOTIFYDURATION_TIME, ERROR_TONE);
  263.     }
  264.     DeleteScreenIfPresent(SCR_ID_SETTING_AUDIO_3D_EFFECT);
  265. }
  266. /*****************************************************************************
  267.  * FUNCTION
  268.  *  mmi_entry_aud_3d_effect_list
  269.  * DESCRIPTION
  270.  *  This function is the entry function of 3D effect list
  271.  * PARAMETERS
  272.  *  void
  273.  * RETURNS
  274.  *  void
  275.  *****************************************************************************/
  276. void mmi_entry_aud_3d_effect_list(void)
  277. {
  278.     /*----------------------------------------------------------------*/
  279.     /* Local Variables                                                */
  280.     /*----------------------------------------------------------------*/
  281.     U8 *guiBuffer;
  282.     U16 audio_3d_list_strings[] = 
  283.     {
  284.         STR_GLOBAL_NONE,
  285.         STR_ID_SETTING_AUDIO_3D_EFFECT_SET1,
  286.         STR_ID_SETTING_AUDIO_3D_EFFECT_SET2,
  287.         STR_ID_SETTING_AUDIO_3D_EFFECT_SET3,
  288.         STR_ID_SETTING_AUDIO_3D_EFFECT_SET4,
  289.         STR_ID_SETTING_AUDIO_3D_EFFECT_SET5,
  290.         STR_ID_SETTING_AUDIO_3D_EFFECT_SET6
  291.     };
  292.     /*----------------------------------------------------------------*/
  293.     /* Code Body                                                      */
  294.     /*----------------------------------------------------------------*/
  295.     EntryNewScreen(SCR_ID_SETTING_AUDIO_3D_EFFECT, NULL, mmi_entry_aud_3d_effect_list, NULL);
  296.     guiBuffer = GetCurrGuiBuffer(SCR_ID_SETTING_AUDIO_3D_EFFECT);
  297.     SetParentHandler(MENU_SETTING_AUDIO_3D_EFFECT);
  298.     RegisterHighlightHandler(mmi_aud_3d_effect_list_highlight_hdlr);
  299.     ShowCategory11Screen(
  300.         STR_ID_SETTING_AUDIO_3D_EFFECT,
  301.         GetRootTitleIcon(MENU_SETTING_SOUND_EFFECT),
  302.         STR_GLOBAL_OK,
  303.         IMG_GLOBAL_OK,
  304.         STR_GLOBAL_BACK,
  305.         IMG_GLOBAL_BACK,
  306.         (S32) (MAX_AUDIO_3D_EFFECT_NUM + 1),
  307.         audio_3d_list_strings,
  308.         (U16) g_mmi_aud_3d_cntx.index,
  309.         guiBuffer);
  310.     SetLeftSoftkeyFunction(mmi_aud_3d_effect_list_LSK_hdlr, KEY_EVENT_UP);
  311.     SetRightSoftkeyFunction(GoBackHistory, KEY_EVENT_UP);
  312.     SetKeyHandler(GoBackHistory, KEY_LEFT_ARROW, KEY_EVENT_DOWN);
  313. }
  314. /*****************************************************************************
  315.  * FUNCTION
  316.  *  mmi_aud_3d_set_effect
  317.  * DESCRIPTION
  318.  *  This function is to set 3d effect by list index
  319.  * PARAMETERS
  320.  *  index       [IN]        
  321.  * RETURNS
  322.  *  void
  323.  *****************************************************************************/
  324. BOOL mmi_aud_3d_set_effect(U16 index)
  325. {
  326.     /*----------------------------------------------------------------*/
  327.     /* Local Variables                                                */
  328.     /*----------------------------------------------------------------*/
  329.     mdi_result result;
  330.     BOOL set_result = TRUE;
  331.     /*----------------------------------------------------------------*/
  332.     /* Code Body                                                      */
  333.     /*----------------------------------------------------------------*/
  334.     if (g_mmi_aud_3d_cntx.index != index)
  335.     {
  336.         g_mmi_aud_3d_cntx.index = index;
  337.         /*
  338.          * Turn off 3D audio effect
  339.          */
  340.         if (index == 0)
  341.         {
  342.             mdi_audio_3d_turn_off();
  343.             HideStatusIcon(STATUS_ICON_3D_SOUND);
  344.         }
  345.         /*
  346.          * Set and turn on audio 3D effect
  347.          */
  348.         else
  349.         {
  350.             mdi_audio_3d_set_coeff((S16*) audio_3d_effect_table[index - 1]);
  351.             result = mdi_audio_3d_turn_on();
  352.             if (result != MDI_AUDIO_SUCCESS)
  353.             {
  354.                 g_mmi_aud_3d_cntx.index = 0;
  355.                 set_result = FALSE;
  356.                 HideStatusIcon(STATUS_ICON_3D_SOUND);
  357.             }
  358.             else
  359.             {
  360.                 ShowStatusIcon(STATUS_ICON_3D_SOUND);
  361.             }
  362.         }
  363.         UpdateStatusIcons();
  364.         /* Write result back to NVRAM */
  365.         mmi_aud_3d_write_nvram();
  366.     }
  367.     return set_result;
  368. }
  369. /*****************************************************************************
  370.  * FUNCTION
  371.  *  mmi_aud_3d_init_effect
  372.  * DESCRIPTION
  373.  *  This function is to set 3d effect at the initialize time
  374.  * PARAMETERS
  375.  *  index       [IN]        
  376.  * RETURNS
  377.  *  void
  378.  *****************************************************************************/
  379. void mmi_aud_3d_init_effect(U16 index)
  380. {
  381.     /*----------------------------------------------------------------*/
  382.     /* Local Variables                                                */
  383.     /*----------------------------------------------------------------*/
  384.     mdi_result result;
  385.     /*----------------------------------------------------------------*/
  386.     /* Code Body                                                      */
  387.     /*----------------------------------------------------------------*/
  388.     /* Set and turn on audio 3D effect */
  389.     if ((index > 0) && (index <= MAX_AUDIO_3D_EFFECT_NUM))
  390.     {
  391.         mdi_audio_3d_set_coeff((S16*) audio_3d_effect_table[index - 1]);
  392.         result = mdi_audio_3d_turn_on();
  393.         if (result == MDI_AUDIO_SUCCESS)
  394.         {
  395.             ShowStatusIcon(STATUS_ICON_3D_SOUND);
  396.             UpdateStatusIcons();            
  397.             return;
  398.         }
  399.     }
  400.     HideStatusIcon(STATUS_ICON_3D_SOUND);
  401.     UpdateStatusIcons();
  402. }
  403. /*****************************************************************************
  404.  * FUNCTION
  405.  *  mmi_aud_3d_read_nvram
  406.  * DESCRIPTION
  407.  *  This function is to read setting from NVRAM
  408.  * PARAMETERS
  409.  *  void
  410.  * RETURNS
  411.  *  void
  412.  *****************************************************************************/
  413. void mmi_aud_3d_read_nvram(void)
  414. {
  415. #ifdef MMI_ON_HARDWARE_P
  416.     /*----------------------------------------------------------------*/
  417.     /* Local Variables                                                */
  418.     /*----------------------------------------------------------------*/
  419.     S16 error;
  420.     U8 read_value;
  421.     /*----------------------------------------------------------------*/
  422.     /* Code Body                                                      */
  423.     /*----------------------------------------------------------------*/
  424.     ReadValue(NVRAM_BYTE_AUDIO_3D_INDEX, &read_value, DS_BYTE, &error);
  425.     if (read_value <= MAX_AUDIO_3D_EFFECT_NUM)
  426.     {
  427.         g_mmi_aud_3d_cntx.index = read_value;
  428.         return;
  429.     }
  430. #endif /* MMI_ON_HARDWARE_P */ 
  431.     g_mmi_aud_3d_cntx.index = 0;
  432. }
  433. /*****************************************************************************
  434.  * FUNCTION
  435.  *  mmi_aud_3d_write_nvram
  436.  * DESCRIPTION
  437.  *  This function is to write settings back to NVRAM
  438.  * PARAMETERS
  439.  *  void
  440.  * RETURNS
  441.  *  void
  442.  *****************************************************************************/
  443. void mmi_aud_3d_write_nvram(void)
  444. {
  445. #ifdef MMI_ON_HARDWARE_P
  446.     /*----------------------------------------------------------------*/
  447.     /* Local Variables                                                */
  448.     /*----------------------------------------------------------------*/
  449.     S16 error;
  450.     U8 write_value = 0;
  451.     /*----------------------------------------------------------------*/
  452.     /* Code Body                                                      */
  453.     /*----------------------------------------------------------------*/
  454.     if (g_mmi_aud_3d_cntx.index <= MAX_AUDIO_3D_EFFECT_NUM)
  455.     {
  456.         write_value = (U8) g_mmi_aud_3d_cntx.index;
  457.     }
  458.     else
  459.     {
  460.         MMI_ASSERT(FALSE);
  461.     }
  462.     WriteValue(NVRAM_BYTE_AUDIO_3D_INDEX, &write_value, DS_BYTE, &error);
  463. #endif /* MMI_ON_HARDWARE_P */ 
  464. }
  465. /*****************************************************************************
  466.  * FUNCTION
  467.  *  mmi_aud_3d_get_status
  468.  * DESCRIPTION
  469.  *  This function is to get 3D effect on/off setting
  470.  * PARAMETERS
  471.  *  void
  472.  * RETURNS
  473.  *  MMI_TRUE: on
  474.  *  MMI_FALSE: off
  475.  *****************************************************************************/
  476. MMI_BOOL mmi_aud_3d_get_status(void)
  477. {
  478.     /*----------------------------------------------------------------*/
  479.     /* Local Variables                                                */
  480.     /*----------------------------------------------------------------*/
  481.     /*----------------------------------------------------------------*/
  482.     /* Code Body                                                      */
  483.     /*----------------------------------------------------------------*/
  484. #ifdef MMI_ON_HARDWARE_P
  485. if((g_mmi_aud_3d_cntx.index > 0) && (g_mmi_aud_3d_cntx.index <= MAX_AUDIO_3D_EFFECT_NUM))
  486. {
  487. return MMI_TRUE;
  488. }
  489. #endif
  490. return MMI_FALSE;
  491. }
  492. #endif /* __MMI_AUDIO_3D_EFFECT__ */ 
  493. #endif /* _AUDIO_3D_EFFECT_C */