• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004-2010 NXP Software
3  * Copyright (C) 2010 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /************************************************************************************/
19 /*                                                                                  */
20 /*  Includes                                                                        */
21 /*                                                                                  */
22 /************************************************************************************/
23 #include <stdlib.h>
24 #include "LVCS.h"
25 #include "LVCS_Private.h"
26 #include "LVCS_Tables.h"
27 
28 /************************************************************************************/
29 /*                                                                                  */
30 /* FUNCTION:                LVCS_Init                                               */
31 /*                                                                                  */
32 /* DESCRIPTION:                                                                     */
33 /*  Create and initialisation function for the Concert Sound module                 */
34 /*                                                                                  */
35 /* PARAMETERS:                                                                      */
36 /*  phInstance              Pointer to instance handle                              */
37 /*  pCapabilities           Pointer to the capabilities structure                   */
38 /*  pScratch                Pointer to scratch buffer                               */
39 /*                                                                                  */
40 /* RETURNS:                                                                         */
41 /*  LVCS_Success            Initialisation succeeded                                */
42 /*  LVDBE_NULLADDRESS       One or more memory has a NULL pointer - malloc failure  */
43 /*                                                                                  */
44 /* NOTES:                                                                           */
45 /*  1.  This function must not be interrupted by the LVCS_Process function          */
46 /*                                                                                  */
47 /************************************************************************************/
48 
LVCS_Init(LVCS_Handle_t * phInstance,LVCS_Capabilities_t * pCapabilities,void * pScratch)49 LVCS_ReturnStatus_en LVCS_Init(LVCS_Handle_t* phInstance, LVCS_Capabilities_t* pCapabilities,
50                                void* pScratch) {
51     LVCS_Instance_t* pInstance;
52     LVCS_VolCorrect_t* pLVCS_VolCorrectTable;
53 
54     /*
55      * Create the instance handle if not already initialised
56      */
57     if (*phInstance == LVM_NULL) {
58         *phInstance = new LVCS_Instance_t{};
59     }
60     pInstance = (LVCS_Instance_t*)*phInstance;
61 
62     /*
63      * Save the capabilities in the instance structure
64      */
65     pInstance->Capabilities = *pCapabilities;
66 
67     pInstance->pScratch = pScratch;
68 
69     /*
70      * Set all initial parameters to invalid to force a full initialisation
71      */
72     pInstance->Params.OperatingMode = LVCS_OFF;
73     pInstance->Params.SpeakerType = LVCS_SPEAKERTYPE_MAX;
74     pInstance->OutputDevice = LVCS_HEADPHONE;
75     pInstance->Params.SourceFormat = LVCS_SOURCEMAX;
76     pInstance->Params.CompressorMode = LVM_MODE_OFF;
77     pInstance->Params.SampleRate = LVM_FS_INVALID;
78     pInstance->Params.EffectLevel = 0;
79     pInstance->Params.ReverbLevel = (LVM_UINT16)0x8000;
80     pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0];
81     pInstance->VolCorrect = pLVCS_VolCorrectTable[0];
82     pInstance->TransitionGain = 0;
83 
84     /* These current and target values are intialized again in LVCS_Control.c */
85     LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[0], 0, 0);
86     /* These current and target values are intialized again in LVCS_Control.c */
87     LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[1], 0, 0);
88 
89     /*
90      * Initialise the bypass variables
91      */
92     pInstance->MSTarget0 = 0;
93     pInstance->MSTarget1 = 0;
94     pInstance->bInOperatingModeTransition = LVM_FALSE;
95     pInstance->bTimerDone = LVM_FALSE;
96     pInstance->TimerParams.CallBackParam = 0;
97     pInstance->TimerParams.pCallBack = LVCS_TimerCallBack;
98     pInstance->TimerParams.pCallbackInstance = pInstance;
99     pInstance->TimerParams.pCallBackParams = LVM_NULL;
100 
101     return (LVCS_SUCCESS);
102 }
103 
104 /************************************************************************************/
105 /*                                                                                  */
106 /* FUNCTION:                LVCS_DeInit                                             */
107 /*                                                                                  */
108 /* DESCRIPTION:                                                                     */
109 /*  Free memories created during the LVCS_Init call including instance handle       */
110 /*                                                                                  */
111 /* PARAMETERS:                                                                      */
112 /*  phInstance              Pointer to instance handle                              */
113 /*                                                                                  */
114 /* NOTES:                                                                           */
115 /*  1.  This function must not be interrupted by the LVCS_Process function          */
116 /*                                                                                  */
117 /************************************************************************************/
LVCS_DeInit(LVCS_Handle_t * phInstance)118 void LVCS_DeInit(LVCS_Handle_t* phInstance) {
119     LVCS_Instance_t* pInstance = (LVCS_Instance_t*)*phInstance;
120     if (pInstance == LVM_NULL) {
121         return;
122     }
123     delete pInstance;
124     *phInstance = LVM_NULL;
125     return;
126 }
127