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
24 #include "LVCS.h"
25 #include "LVCS_Private.h"
26 #include "LVCS_Tables.h"
27
28 /****************************************************************************************/
29 /* */
30 /* FUNCTION: LVCS_Memory */
31 /* */
32 /* DESCRIPTION: */
33 /* This function is used for memory allocation and free. It can be called in */
34 /* two ways: */
35 /* */
36 /* hInstance = NULL Returns the memory requirements */
37 /* hInstance = Instance handle Returns the memory requirements and */
38 /* allocated base addresses for the instance */
39 /* */
40 /* When this function is called for memory allocation (hInstance=NULL) it is */
41 /* passed the default capabilities. */
42 /* */
43 /* When called for memory allocation the memory base address pointers are NULL on */
44 /* return. */
45 /* */
46 /* When the function is called for free (hInstance = Instance Handle) the */
47 /* capabilities are ignored and the memory table returns the allocated memory and */
48 /* base addresses used during initialisation. */
49 /* */
50 /* PARAMETERS: */
51 /* hInstance Instance Handle */
52 /* pMemoryTable Pointer to an empty memory definition table */
53 /* pCapabilities Pointer to the default capabilites */
54 /* */
55 /* RETURNS: */
56 /* LVCS_Success Succeeded */
57 /* */
58 /* NOTES: */
59 /* 1. This function may be interrupted by the LVCS_Process function */
60 /* */
61 /****************************************************************************************/
62
LVCS_Memory(LVCS_Handle_t hInstance,LVCS_MemTab_t * pMemoryTable,LVCS_Capabilities_t * pCapabilities)63 LVCS_ReturnStatus_en LVCS_Memory(LVCS_Handle_t hInstance,
64 LVCS_MemTab_t *pMemoryTable,
65 LVCS_Capabilities_t *pCapabilities)
66 {
67
68 LVM_UINT32 ScratchSize;
69 LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance;
70
71
72 /*
73 * Fill in the memory table
74 */
75 if (hInstance == LVM_NULL)
76 {
77 /*
78 * Instance memory
79 */
80 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].Size = (LVM_UINT32)sizeof(LVCS_Instance_t);
81 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].Type = LVCS_PERSISTENT;
82 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;
83
84 /*
85 * Data memory
86 */
87 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Size = (LVM_UINT32)sizeof(LVCS_Data_t);
88 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Type = LVCS_DATA;
89 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
90
91 /*
92 * Coefficient memory
93 */
94 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Size = (LVM_UINT32)sizeof(LVCS_Coefficient_t);
95 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Type = LVCS_COEFFICIENT;
96 pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
97
98 /*
99 * Scratch memory
100 */
101 #ifdef BUILD_FLOAT
102 /* Inplace processing */
103 ScratchSize = (LVM_UINT32) \
104 (LVCS_SCRATCHBUFFERS * sizeof(LVM_FLOAT) * pCapabilities->MaxBlockSize);
105 #else
106 ScratchSize = (LVM_UINT32)(LVCS_SCRATCHBUFFERS*sizeof(LVM_INT16)*pCapabilities->MaxBlockSize); /* Inplace processing */
107 #endif
108 pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].Size = ScratchSize;
109 pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].Type = LVCS_SCRATCH;
110 pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress = LVM_NULL;
111 }
112 else
113 {
114 /* Read back memory allocation table */
115 *pMemoryTable = pInstance->MemoryTable;
116 }
117
118 return(LVCS_SUCCESS);
119 }
120
121
122 /************************************************************************************/
123 /* */
124 /* FUNCTION: LVCS_Init */
125 /* */
126 /* DESCRIPTION: */
127 /* Create and initialisation function for the Concert Sound module */
128 /* */
129 /* This function can be used to create an algorithm instance by calling with */
130 /* hInstance set to LVM_NULL. In this case the algorithm returns the new instance */
131 /* handle. */
132 /* */
133 /* This function can be used to force a full re-initialisation of the algorithm */
134 /* by calling with hInstance = Instance Handle. In this case the memory table */
135 /* should be correct for the instance, this can be ensured by calling the function */
136 /* LVCS_Memory before calling this function. */
137 /* */
138 /* PARAMETERS: */
139 /* hInstance Instance handle */
140 /* pMemoryTable Pointer to the memory definition table */
141 /* pCapabilities Pointer to the capabilities structure */
142 /* */
143 /* RETURNS: */
144 /* LVCS_Success Initialisation succeeded */
145 /* */
146 /* NOTES: */
147 /* 1. The instance handle is the pointer to the base address of the first memory */
148 /* region. */
149 /* 2. This function must not be interrupted by the LVCS_Process function */
150 /* 3. This function must be called with the same capabilities as used for the */
151 /* call to the memory function */
152 /* */
153 /************************************************************************************/
154
LVCS_Init(LVCS_Handle_t * phInstance,LVCS_MemTab_t * pMemoryTable,LVCS_Capabilities_t * pCapabilities)155 LVCS_ReturnStatus_en LVCS_Init(LVCS_Handle_t *phInstance,
156 LVCS_MemTab_t *pMemoryTable,
157 LVCS_Capabilities_t *pCapabilities)
158 {
159
160 LVCS_Instance_t *pInstance;
161 LVCS_VolCorrect_t *pLVCS_VolCorrectTable;
162
163
164 /*
165 * Set the instance handle if not already initialised
166 */
167 if (*phInstance == LVM_NULL)
168 {
169 *phInstance = (LVCS_Handle_t)pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress;
170 }
171 pInstance =(LVCS_Instance_t *)*phInstance;
172
173
174 /*
175 * Save the capabilities in the instance structure
176 */
177 pInstance->Capabilities = *pCapabilities;
178
179 /*
180 * Save the memory table in the instance structure
181 */
182 pInstance->MemoryTable = *pMemoryTable;
183
184
185 /*
186 * Set all initial parameters to invalid to force a full initialisation
187 */
188 pInstance->Params.OperatingMode = LVCS_OFF;
189 pInstance->Params.SpeakerType = LVCS_SPEAKERTYPE_MAX;
190 pInstance->OutputDevice = LVCS_HEADPHONE;
191 pInstance->Params.SourceFormat = LVCS_SOURCEMAX;
192 pInstance->Params.CompressorMode = LVM_MODE_OFF;
193 pInstance->Params.SampleRate = LVM_FS_INVALID;
194 pInstance->Params.EffectLevel = 0;
195 pInstance->Params.ReverbLevel = (LVM_UINT16)0x8000;
196 pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0];
197 pInstance->VolCorrect = pLVCS_VolCorrectTable[0];
198 pInstance->TransitionGain = 0;
199
200 /* These current and target values are intialized again in LVCS_Control.c */
201 LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[0],0,0);
202 /* These current and target values are intialized again in LVCS_Control.c */
203 LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[1],0,0);
204
205 /*
206 * Initialise the bypass variables
207 */
208 pInstance->MSTarget0=0;
209 pInstance->MSTarget1=0;
210 pInstance->bInOperatingModeTransition = LVM_FALSE;
211 pInstance->bTimerDone = LVM_FALSE;
212 pInstance->TimerParams.CallBackParam = 0;
213 pInstance->TimerParams.pCallBack = LVCS_TimerCallBack;
214 pInstance->TimerParams.pCallbackInstance = pInstance;
215 pInstance->TimerParams.pCallBackParams = LVM_NULL;
216
217 return(LVCS_SUCCESS);
218 }
219
220