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 "LVREV_Private.h"
24 #include "InstAlloc.h"
25
26 /****************************************************************************************/
27 /* */
28 /* FUNCTION: LVREV_GetMemoryTable */
29 /* */
30 /* DESCRIPTION: */
31 /* This function is used for memory allocation and free. It can be called in */
32 /* two ways: */
33 /* */
34 /* hInstance = NULL Returns the memory requirements */
35 /* hInstance = Instance handle Returns the memory requirements and allocated */
36 /* base addresses. */
37 /* */
38 /* When this function is called for memory allocation (hInstance=NULL) the memory */
39 /* base address pointers are NULL on return. */
40 /* */
41 /* When the function is called for free (hInstance = Instance Handle) the memory */
42 /* table returns the allocated memory and base addresses used during initialisation. */
43 /* */
44 /* PARAMETERS: */
45 /* hInstance Instance Handle */
46 /* pMemoryTable Pointer to an empty memory table */
47 /* pInstanceParams Pointer to the instance parameters */
48 /* */
49 /* RETURNS: */
50 /* LVREV_Success Succeeded */
51 /* LVREV_NULLADDRESS When pMemoryTable is NULL */
52 /* LVREV_NULLADDRESS When requesting memory requirements and pInstanceParams */
53 /* is NULL */
54 /* */
55 /* NOTES: */
56 /* 1. This function may be interrupted by the LVREV_Process function */
57 /* */
58 /****************************************************************************************/
LVREV_GetMemoryTable(LVREV_Handle_t hInstance,LVREV_MemoryTable_st * pMemoryTable,LVREV_InstanceParams_st * pInstanceParams)59 LVREV_ReturnStatus_en LVREV_GetMemoryTable(LVREV_Handle_t hInstance,
60 LVREV_MemoryTable_st *pMemoryTable,
61 LVREV_InstanceParams_st *pInstanceParams)
62 {
63
64 INST_ALLOC SlowData;
65 INST_ALLOC FastData;
66 INST_ALLOC FastCoef;
67 INST_ALLOC Temporary;
68 LVM_INT16 i;
69 LVM_UINT16 MaxBlockSize;
70
71
72 /*
73 * Check for error conditions
74 */
75 /* Check for NULL pointer */
76 if (pMemoryTable == LVM_NULL)
77 {
78 return(LVREV_NULLADDRESS);
79 }
80
81 /*
82 * Check all instance parameters are in range
83 */
84 if (pInstanceParams != LVM_NULL)
85 {
86 /*
87 * Call for memory allocation, so check the parameters
88 */
89 /* Check for a non-zero block size */
90 if (pInstanceParams->MaxBlockSize == 0)
91 {
92 return LVREV_OUTOFRANGE;
93 }
94
95 /* Check for a valid number of delay lines */
96 if ((pInstanceParams->NumDelays != LVREV_DELAYLINES_1) &&
97 (pInstanceParams->NumDelays != LVREV_DELAYLINES_2) &&
98 (pInstanceParams->NumDelays != LVREV_DELAYLINES_4))
99 {
100 return LVREV_OUTOFRANGE;
101 }
102 }
103
104 /*
105 * Initialise the InstAlloc instances
106 */
107 InstAlloc_Init(&SlowData, (void *)LVM_NULL);
108 InstAlloc_Init(&FastData, (void *)LVM_NULL);
109 InstAlloc_Init(&FastCoef, (void *)LVM_NULL);
110 InstAlloc_Init(&Temporary, (void *)LVM_NULL);
111
112
113 /*
114 * Fill in the memory table
115 */
116 if (hInstance == LVM_NULL)
117 {
118 /*
119 * Check for null pointers
120 */
121 if (pInstanceParams == LVM_NULL)
122 {
123 return(LVREV_NULLADDRESS);
124 }
125
126
127 /*
128 * Select the maximum internal block size
129 */
130 if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_4)
131 {
132 MaxBlockSize = LVREV_MAX_AP3_DELAY;
133 }
134 else if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_2)
135 {
136 MaxBlockSize = LVREV_MAX_AP1_DELAY;
137 }
138 else
139 {
140 MaxBlockSize = LVREV_MAX_AP0_DELAY;
141 }
142
143 if(MaxBlockSize>pInstanceParams->MaxBlockSize)
144 {
145 MaxBlockSize=pInstanceParams->MaxBlockSize;
146 }
147
148
149 /*
150 * Slow data memory
151 */
152 InstAlloc_AddMember(&SlowData, sizeof(LVREV_Instance_st));
153 pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size = InstAlloc_GetTotal(&SlowData);
154 pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Type = LVM_PERSISTENT_SLOW_DATA;
155 pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;
156
157
158 /*
159 * Persistent fast data memory
160 */
161 InstAlloc_AddMember(&FastData, sizeof(LVREV_FastData_st));
162 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
163 {
164 #ifndef BUILD_FLOAT
165 InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * sizeof(LVM_INT32));
166 InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * sizeof(LVM_INT32));
167 InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
168 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
169 #else
170 InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * sizeof(LVM_FLOAT));
171 InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * sizeof(LVM_FLOAT));
172 InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_FLOAT));
173 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
174 #endif
175 }
176
177 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
178 {
179 #ifndef BUILD_FLOAT
180 InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
181 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
182 #else
183 InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_FLOAT));
184 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
185 #endif
186 }
187
188 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
189 {
190 #ifndef BUILD_FLOAT
191 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
192 #else
193 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
194 #endif
195 }
196
197 pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size = InstAlloc_GetTotal(&FastData);
198 pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Type = LVM_PERSISTENT_FAST_DATA;
199 pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
200
201
202 /*
203 * Persistent fast coefficient memory
204 */
205 InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st));
206 pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size = InstAlloc_GetTotal(&FastCoef);
207 pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Type = LVM_PERSISTENT_FAST_COEF;
208 pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
209
210
211 /*
212 * Temporary fast memory
213 */
214 #ifndef BUILD_FLOAT
215 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* General purpose scratch memory */
216 InstAlloc_AddMember(&Temporary, 2*sizeof(LVM_INT32) * MaxBlockSize); /* Mono->stereo input saved for end mix */
217 #else
218 /* General purpose scratch memory */
219 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
220 /* Mono->stereo input saved for end mix */
221 InstAlloc_AddMember(&Temporary, 2 * sizeof(LVM_FLOAT) * MaxBlockSize);
222 #endif
223 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
224 {
225 for(i=0; i<4; i++)
226 {
227 #ifndef BUILD_FLOAT
228 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* A Scratch buffer for each delay line */
229 #else
230 /* A Scratch buffer for each delay line */
231 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
232 #endif
233 }
234 }
235
236 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
237 {
238 for(i=0; i<2; i++)
239 {
240 #ifndef BUILD_FLOAT
241 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* A Scratch buffer for each delay line */
242 #else
243 /* A Scratch buffer for each delay line */
244 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
245 #endif
246 }
247 }
248
249 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
250 {
251 for(i=0; i<1; i++)
252 {
253 #ifndef BUILD_FLOAT
254 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* A Scratch buffer for each delay line */
255 #else
256 /* A Scratch buffer for each delay line */
257 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
258 #endif
259 }
260 }
261
262 pMemoryTable->Region[LVM_TEMPORARY_FAST].Size = InstAlloc_GetTotal(&Temporary);
263 pMemoryTable->Region[LVM_TEMPORARY_FAST].Type = LVM_TEMPORARY_FAST;
264 pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress = LVM_NULL;
265
266 }
267 else
268 {
269 LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
270
271
272 /*
273 * Read back memory allocation table
274 */
275 *pMemoryTable = pLVREV_Private->MemoryTable;
276 }
277
278
279 return(LVREV_SUCCESS);
280 }
281
282 /* End of file */
283