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 * Check for error conditions
73 */
74 /* Check for NULL pointer */
75 if (pMemoryTable == LVM_NULL)
76 {
77 return(LVREV_NULLADDRESS);
78 }
79
80 /*
81 * Check all instance parameters are in range
82 */
83 if (pInstanceParams != LVM_NULL)
84 {
85 /*
86 * Call for memory allocation, so check the parameters
87 */
88 /* Check for a non-zero block size */
89 if (pInstanceParams->MaxBlockSize == 0)
90 {
91 return LVREV_OUTOFRANGE;
92 }
93
94 /* Check for a valid number of delay lines */
95 if ((pInstanceParams->NumDelays != LVREV_DELAYLINES_1) &&
96 (pInstanceParams->NumDelays != LVREV_DELAYLINES_2) &&
97 (pInstanceParams->NumDelays != LVREV_DELAYLINES_4))
98 {
99 return LVREV_OUTOFRANGE;
100 }
101 }
102
103 /*
104 * Initialise the InstAlloc instances
105 */
106 InstAlloc_Init(&SlowData, (void *)LVM_NULL);
107 InstAlloc_Init(&FastData, (void *)LVM_NULL);
108 InstAlloc_Init(&FastCoef, (void *)LVM_NULL);
109 InstAlloc_Init(&Temporary, (void *)LVM_NULL);
110
111 /*
112 * Fill in the memory table
113 */
114 if (hInstance == LVM_NULL)
115 {
116 /*
117 * Check for null pointers
118 */
119 if (pInstanceParams == LVM_NULL)
120 {
121 return(LVREV_NULLADDRESS);
122 }
123
124 /*
125 * Select the maximum internal block size
126 */
127 if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_4)
128 {
129 MaxBlockSize = LVREV_MAX_AP3_DELAY;
130 }
131 else if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_2)
132 {
133 MaxBlockSize = LVREV_MAX_AP1_DELAY;
134 }
135 else
136 {
137 MaxBlockSize = LVREV_MAX_AP0_DELAY;
138 }
139
140 if(MaxBlockSize>pInstanceParams->MaxBlockSize)
141 {
142 MaxBlockSize=pInstanceParams->MaxBlockSize;
143 }
144
145 /*
146 * Slow data memory
147 */
148 InstAlloc_AddMember(&SlowData, sizeof(LVREV_Instance_st));
149 pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size = InstAlloc_GetTotal(&SlowData);
150 pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Type = LVM_PERSISTENT_SLOW_DATA;
151 pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;
152
153 /*
154 * Persistent fast data memory
155 */
156 InstAlloc_AddMember(&FastData, sizeof(LVREV_FastData_st));
157 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
158 {
159 InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * sizeof(LVM_FLOAT));
160 InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * sizeof(LVM_FLOAT));
161 InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_FLOAT));
162 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
163 }
164
165 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
166 {
167 InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_FLOAT));
168 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
169 }
170
171 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
172 {
173 InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
174 }
175
176 pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size = InstAlloc_GetTotal(&FastData);
177 pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Type = LVM_PERSISTENT_FAST_DATA;
178 pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
179
180 /*
181 * Persistent fast coefficient memory
182 */
183 InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st));
184 pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size = InstAlloc_GetTotal(&FastCoef);
185 pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Type = LVM_PERSISTENT_FAST_COEF;
186 pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
187
188 /*
189 * Temporary fast memory
190 */
191 /* General purpose scratch memory */
192 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
193 /* Mono->stereo input saved for end mix */
194 InstAlloc_AddMember(&Temporary, 2 * sizeof(LVM_FLOAT) * MaxBlockSize);
195 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
196 {
197 for(i=0; i<4; i++)
198 {
199 /* A Scratch buffer for each delay line */
200 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
201 }
202 }
203
204 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
205 {
206 for(i=0; i<2; i++)
207 {
208 /* A Scratch buffer for each delay line */
209 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
210 }
211 }
212
213 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
214 {
215 for(i=0; i<1; i++)
216 {
217 /* A Scratch buffer for each delay line */
218 InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * MaxBlockSize);
219 }
220 }
221
222 pMemoryTable->Region[LVM_TEMPORARY_FAST].Size = InstAlloc_GetTotal(&Temporary);
223 pMemoryTable->Region[LVM_TEMPORARY_FAST].Type = LVM_TEMPORARY_FAST;
224 pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress = LVM_NULL;
225
226 }
227 else
228 {
229 LVREV_Instance_st *pLVREV_Private = (LVREV_Instance_st *)hInstance;
230
231 /*
232 * Read back memory allocation table
233 */
234 *pMemoryTable = pLVREV_Private->MemoryTable;
235 }
236
237 return(LVREV_SUCCESS);
238 }
239
240 /* End of file */
241