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 /* */
29 /* FUNCTION: LVREV_GetInstanceHandle */
30 /* */
31 /* DESCRIPTION: */
32 /* This function is used to create a LVREV module instance. It returns the created */
33 /* instance handle through phInstance. All parameters are set to their default, */
34 /* inactive state. */
35 /* */
36 /* PARAMETERS: */
37 /* phInstance pointer to the instance handle */
38 /* pMemoryTable Pointer to the memory definition table */
39 /* pInstanceParams Pointer to the instance parameters */
40 /* */
41 /* RETURNS: */
42 /* LVREV_SUCCESS Succeeded */
43 /* LVREV_NULLADDRESS When phInstance or pMemoryTable or pInstanceParams is NULL */
44 /* LVREV_NULLADDRESS When one of the memory regions has a NULL pointer */
45 /* */
46 /* NOTES: */
47 /* */
48 /****************************************************************************************/
LVREV_GetInstanceHandle(LVREV_Handle_t * phInstance,LVREV_MemoryTable_st * pMemoryTable,LVREV_InstanceParams_st * pInstanceParams)49 LVREV_ReturnStatus_en LVREV_GetInstanceHandle(LVREV_Handle_t *phInstance,
50 LVREV_MemoryTable_st *pMemoryTable,
51 LVREV_InstanceParams_st *pInstanceParams)
52 {
53
54 INST_ALLOC SlowData;
55 INST_ALLOC FastData;
56 INST_ALLOC FastCoef;
57 INST_ALLOC Temporary;
58 LVREV_Instance_st *pLVREV_Private;
59 LVM_INT16 i;
60 LVM_UINT16 MaxBlockSize;
61
62
63 /*
64 * Check for error conditions
65 */
66 /* Check for NULL pointers */
67 if((phInstance == LVM_NULL) || (pMemoryTable == LVM_NULL) || (pInstanceParams == LVM_NULL))
68 {
69 return LVREV_NULLADDRESS;
70 }
71 /* Check the memory table for NULL pointers */
72 for (i = 0; i < LVREV_NR_MEMORY_REGIONS; i++)
73 {
74 if (pMemoryTable->Region[i].Size!=0)
75 {
76 if (pMemoryTable->Region[i].pBaseAddress==LVM_NULL)
77 {
78 return(LVREV_NULLADDRESS);
79 }
80 }
81 }
82
83 /*
84 * Check all instance parameters are in range
85 */
86 /* Check for a non-zero block size */
87 if (pInstanceParams->MaxBlockSize == 0)
88 {
89 return LVREV_OUTOFRANGE;
90 }
91
92 /* Check for a valid number of delay lines */
93 if ((pInstanceParams->NumDelays != LVREV_DELAYLINES_1)&&
94 (pInstanceParams->NumDelays != LVREV_DELAYLINES_2)&&
95 (pInstanceParams->NumDelays != LVREV_DELAYLINES_4))
96 {
97 return LVREV_OUTOFRANGE;
98 }
99
100 /*
101 * Initialise the InstAlloc instances
102 */
103 InstAlloc_Init(&SlowData, pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress);
104 InstAlloc_Init(&FastData, pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress);
105 InstAlloc_Init(&FastCoef, pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress);
106 InstAlloc_Init(&Temporary, pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress);
107
108 /*
109 * Zero all memory regions
110 */
111 #ifdef BUILD_FLOAT
112 LoadConst_Float(0,
113 (LVM_FLOAT *)pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress,
114 (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size) / \
115 sizeof(LVM_FLOAT)));
116 LoadConst_Float(0,
117 (LVM_FLOAT *)pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress,
118 (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size) / \
119 sizeof(LVM_FLOAT)));
120 LoadConst_Float(0,
121 (LVM_FLOAT *)pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress,
122 (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size) / \
123 sizeof(LVM_FLOAT)));
124 LoadConst_Float(0,
125 (LVM_FLOAT *)pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress,
126 (LVM_INT16)((pMemoryTable->Region[LVM_TEMPORARY_FAST].Size) / \
127 sizeof(LVM_FLOAT)));
128 #else
129 LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size)/sizeof(LVM_INT16)));
130 LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size)/sizeof(LVM_INT16)));
131 LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size)/sizeof(LVM_INT16)));
132 LoadConst_16(0, (LVM_INT16 *)pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress, (LVM_INT16)((pMemoryTable->Region[LVM_TEMPORARY_FAST].Size)/sizeof(LVM_INT16)));
133 #endif
134 /*
135 * Set the instance handle if not already initialised
136 */
137 if (*phInstance == LVM_NULL)
138 {
139 *phInstance = InstAlloc_AddMember(&SlowData, sizeof(LVREV_Instance_st));
140 }
141 pLVREV_Private =(LVREV_Instance_st *)*phInstance;
142 pLVREV_Private->MemoryTable = *pMemoryTable;
143
144 if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_4)
145 {
146 MaxBlockSize = LVREV_MAX_AP3_DELAY;
147 }
148 else if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_2)
149 {
150 MaxBlockSize = LVREV_MAX_AP1_DELAY;
151 }
152 else
153 {
154 MaxBlockSize = LVREV_MAX_AP0_DELAY;
155 }
156
157 if(MaxBlockSize>pInstanceParams->MaxBlockSize)
158 {
159 MaxBlockSize=pInstanceParams->MaxBlockSize;
160 }
161
162
163 /*
164 * Set the data, coefficient and temporary memory pointers
165 */
166 pLVREV_Private->pFastData = InstAlloc_AddMember(&FastData, sizeof(LVREV_FastData_st)); /* Fast data memory base address */
167 #ifndef BUILD_FLOAT
168 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
169 {
170 pLVREV_Private->pDelay_T[3] = InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * sizeof(LVM_INT32));
171 pLVREV_Private->pDelay_T[2] = InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * sizeof(LVM_INT32));
172 pLVREV_Private->pDelay_T[1] = InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
173 pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
174
175 for( i = 0; i < 4; i++)
176 {
177 pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* Scratch for each delay line output */
178 }
179
180 LoadConst_32(0,pLVREV_Private->pDelay_T[3] ,(LVM_INT16)LVREV_MAX_T3_DELAY);
181 LoadConst_32(0,pLVREV_Private->pDelay_T[2] ,(LVM_INT16)LVREV_MAX_T2_DELAY);
182 LoadConst_32(0,pLVREV_Private->pDelay_T[1] ,(LVM_INT16)LVREV_MAX_T1_DELAY);
183 LoadConst_32(0,pLVREV_Private->pDelay_T[0] ,(LVM_INT16)LVREV_MAX_T0_DELAY);
184 }
185
186 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
187 {
188 pLVREV_Private->pDelay_T[1] = InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
189 pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
190
191 for( i = 0; i < 2; i++)
192 {
193 pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* Scratch for each delay line output */
194 }
195
196 LoadConst_32(0,pLVREV_Private->pDelay_T[1] , (LVM_INT16)LVREV_MAX_T1_DELAY);
197 LoadConst_32(0,pLVREV_Private->pDelay_T[0] , (LVM_INT16)LVREV_MAX_T0_DELAY);
198 }
199
200 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
201 {
202 pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
203
204 for( i = 0; i < 1; i++)
205 {
206 pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* Scratch for each delay line output */
207 }
208
209 LoadConst_32(0,pLVREV_Private->pDelay_T[0] , (LVM_INT16)LVREV_MAX_T0_DELAY);
210 }
211 #else
212 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
213 {
214 pLVREV_Private->pDelay_T[3] = InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY * \
215 sizeof(LVM_FLOAT));
216 pLVREV_Private->pDelay_T[2] = InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY * \
217 sizeof(LVM_FLOAT));
218 pLVREV_Private->pDelay_T[1] = InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * \
219 sizeof(LVM_FLOAT));
220 pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * \
221 sizeof(LVM_FLOAT));
222
223 for(i = 0; i < 4; i++)
224 {
225 /* Scratch for each delay line output */
226 pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary,
227 sizeof(LVM_FLOAT) * \
228 MaxBlockSize);
229 }
230
231 LoadConst_Float(0, pLVREV_Private->pDelay_T[3], LVREV_MAX_T3_DELAY);
232 LoadConst_Float(0, pLVREV_Private->pDelay_T[2], LVREV_MAX_T2_DELAY);
233 LoadConst_Float(0, pLVREV_Private->pDelay_T[1], LVREV_MAX_T1_DELAY);
234 LoadConst_Float(0, pLVREV_Private->pDelay_T[0], LVREV_MAX_T0_DELAY);
235 }
236
237 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
238 {
239 pLVREV_Private->pDelay_T[1] = InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * \
240 sizeof(LVM_FLOAT));
241 pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * \
242 sizeof(LVM_FLOAT));
243
244 for(i = 0; i < 2; i++)
245 {
246 /* Scratch for each delay line output */
247 pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary,
248 sizeof(LVM_FLOAT) * \
249 MaxBlockSize);
250 }
251
252 LoadConst_Float(0, pLVREV_Private->pDelay_T[1], (LVM_INT16)LVREV_MAX_T1_DELAY);
253 LoadConst_Float(0, pLVREV_Private->pDelay_T[0], (LVM_INT16)LVREV_MAX_T0_DELAY);
254 }
255
256 if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
257 {
258 pLVREV_Private->pDelay_T[0] = InstAlloc_AddMember(&FastData,
259 LVREV_MAX_T0_DELAY * sizeof(LVM_FLOAT));
260
261 for(i = 0; i < 1; i++)
262 {
263 /* Scratch for each delay line output */
264 pLVREV_Private->pScratchDelayLine[i] = InstAlloc_AddMember(&Temporary,
265 sizeof(LVM_FLOAT) * \
266 MaxBlockSize);
267 }
268
269 LoadConst_Float(0, pLVREV_Private->pDelay_T[0], (LVM_INT16)LVREV_MAX_T0_DELAY);
270 }
271 #endif
272 /* All-pass delay buffer addresses and sizes */
273 pLVREV_Private->T[0] = LVREV_MAX_T0_DELAY;
274 pLVREV_Private->T[1] = LVREV_MAX_T1_DELAY;
275 pLVREV_Private->T[2] = LVREV_MAX_T2_DELAY;
276 pLVREV_Private->T[3] = LVREV_MAX_T3_DELAY;
277 pLVREV_Private->AB_Selection = 1; /* Select smoothing A to B */
278
279
280 pLVREV_Private->pFastCoef = InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st)); /* Fast coefficient memory base address */
281 #ifndef BUILD_FLOAT
282 pLVREV_Private->pScratch = InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize); /* General purpose scratch */
283 pLVREV_Private->pInputSave = InstAlloc_AddMember(&Temporary, 2 * sizeof(LVM_INT32) * MaxBlockSize); /* Mono->stereo input save for end mix */
284 LoadConst_32(0, pLVREV_Private->pInputSave, (LVM_INT16)(MaxBlockSize*2));
285 #else
286 /* General purpose scratch */
287 pLVREV_Private->pScratch = InstAlloc_AddMember(&Temporary, sizeof(LVM_FLOAT) * \
288 MaxBlockSize);
289 /* Mono->stereo input save for end mix */
290 pLVREV_Private->pInputSave = InstAlloc_AddMember(&Temporary, 2 * sizeof(LVM_FLOAT) * \
291 MaxBlockSize);
292 LoadConst_Float(0, pLVREV_Private->pInputSave, (LVM_INT16)(MaxBlockSize * 2));
293 #endif
294
295 /*
296 * Save the instance parameters in the instance structure
297 */
298 pLVREV_Private->InstanceParams = *pInstanceParams;
299
300
301 /*
302 * Set the parameters to invalid
303 */
304 pLVREV_Private->CurrentParams.SampleRate = LVM_FS_INVALID;
305 pLVREV_Private->CurrentParams.OperatingMode = LVM_MODE_DUMMY;
306 pLVREV_Private->CurrentParams.SourceFormat = LVM_SOURCE_DUMMY;
307
308 pLVREV_Private->bControlPending = LVM_FALSE;
309 pLVREV_Private->bFirstControl = LVM_TRUE;
310 pLVREV_Private->bDisableReverb = LVM_FALSE;
311
312
313 /*
314 * Set mixer parameters
315 */
316 pLVREV_Private->BypassMixer.CallbackParam2 = 0;
317 pLVREV_Private->BypassMixer.pCallbackHandle2 = pLVREV_Private;
318 pLVREV_Private->BypassMixer.pGeneralPurpose2 = LVM_NULL;
319 pLVREV_Private->BypassMixer.pCallBack2 = BypassMixer_Callback;
320 pLVREV_Private->BypassMixer.CallbackSet2 = LVM_FALSE;
321 pLVREV_Private->BypassMixer.Current2 = 0;
322 pLVREV_Private->BypassMixer.Target2 = 0;
323 pLVREV_Private->BypassMixer.CallbackParam1 = 0;
324 pLVREV_Private->BypassMixer.pCallbackHandle1 = LVM_NULL;
325 pLVREV_Private->BypassMixer.pGeneralPurpose1 = LVM_NULL;
326 pLVREV_Private->BypassMixer.pCallBack1 = LVM_NULL;
327 pLVREV_Private->BypassMixer.CallbackSet1 = LVM_FALSE;
328 pLVREV_Private->BypassMixer.Current1 = 0x00000000;
329 pLVREV_Private->BypassMixer.Target1 = 0x00000000;
330
331 pLVREV_Private->RoomSizeInms = 100; // 100 msec
332
333
334 /*
335 * Set the output gain mixer parameters
336 */
337 pLVREV_Private->GainMixer.CallbackParam = 0;
338 pLVREV_Private->GainMixer.pCallbackHandle = LVM_NULL;
339 pLVREV_Private->GainMixer.pGeneralPurpose = LVM_NULL;
340 pLVREV_Private->GainMixer.pCallBack = LVM_NULL;
341 pLVREV_Private->GainMixer.CallbackSet = LVM_FALSE;
342 #ifndef BUILD_FLOAT
343 pLVREV_Private->GainMixer.Current = 0x03ffffff;
344 pLVREV_Private->GainMixer.Target = 0x03ffffff;
345 #else
346 pLVREV_Private->GainMixer.Current = 0.03125f;//0x03ffffff;
347 pLVREV_Private->GainMixer.Target = 0.03125f;//0x03ffffff;
348 #endif
349
350 /*
351 * Set the All-Pass Filter mixers
352 */
353 for (i=0; i<4; i++)
354 {
355 pLVREV_Private->pOffsetA[i] = pLVREV_Private->pDelay_T[i];
356 pLVREV_Private->pOffsetB[i] = pLVREV_Private->pDelay_T[i];
357 /* Delay tap selection mixer */
358 pLVREV_Private->Mixer_APTaps[i].CallbackParam2 = 0;
359 pLVREV_Private->Mixer_APTaps[i].pCallbackHandle2 = LVM_NULL;
360 pLVREV_Private->Mixer_APTaps[i].pGeneralPurpose2 = LVM_NULL;
361 pLVREV_Private->Mixer_APTaps[i].pCallBack2 = LVM_NULL;
362 pLVREV_Private->Mixer_APTaps[i].CallbackSet2 = LVM_FALSE;
363 pLVREV_Private->Mixer_APTaps[i].Current2 = 0;
364 pLVREV_Private->Mixer_APTaps[i].Target2 = 0;
365 pLVREV_Private->Mixer_APTaps[i].CallbackParam1 = 0;
366 pLVREV_Private->Mixer_APTaps[i].pCallbackHandle1 = LVM_NULL;
367 pLVREV_Private->Mixer_APTaps[i].pGeneralPurpose1 = LVM_NULL;
368 pLVREV_Private->Mixer_APTaps[i].pCallBack1 = LVM_NULL;
369 pLVREV_Private->Mixer_APTaps[i].CallbackSet1 = LVM_FALSE;
370 pLVREV_Private->Mixer_APTaps[i].Current1 = 0;
371 #ifndef BUILD_FLOAT
372 pLVREV_Private->Mixer_APTaps[i].Target1 = 0x7fffffff;
373 #else
374 pLVREV_Private->Mixer_APTaps[i].Target1 = 1;
375 #endif
376 /* Feedforward mixer */
377 pLVREV_Private->Mixer_SGFeedforward[i].CallbackParam = 0;
378 pLVREV_Private->Mixer_SGFeedforward[i].pCallbackHandle = LVM_NULL;
379 pLVREV_Private->Mixer_SGFeedforward[i].pGeneralPurpose = LVM_NULL;
380 pLVREV_Private->Mixer_SGFeedforward[i].pCallBack = LVM_NULL;
381 pLVREV_Private->Mixer_SGFeedforward[i].CallbackSet = LVM_FALSE;
382 pLVREV_Private->Mixer_SGFeedforward[i].Current = 0;
383 pLVREV_Private->Mixer_SGFeedforward[i].Target = 0;
384 /* Feedback mixer */
385 pLVREV_Private->Mixer_SGFeedback[i].CallbackParam = 0;
386 pLVREV_Private->Mixer_SGFeedback[i].pCallbackHandle = LVM_NULL;
387 pLVREV_Private->Mixer_SGFeedback[i].pGeneralPurpose = LVM_NULL;
388 pLVREV_Private->Mixer_SGFeedback[i].pCallBack = LVM_NULL;
389 pLVREV_Private->Mixer_SGFeedback[i].CallbackSet = LVM_FALSE;
390 pLVREV_Private->Mixer_SGFeedback[i].Current = 0;
391 pLVREV_Private->Mixer_SGFeedback[i].Target = 0;
392 /* Feedback gain mixer */
393 pLVREV_Private->FeedbackMixer[i].CallbackParam = 0;
394 pLVREV_Private->FeedbackMixer[i].pCallbackHandle = LVM_NULL;
395 pLVREV_Private->FeedbackMixer[i].pGeneralPurpose = LVM_NULL;
396 pLVREV_Private->FeedbackMixer[i].pCallBack = LVM_NULL;
397 pLVREV_Private->FeedbackMixer[i].CallbackSet = LVM_FALSE;
398 pLVREV_Private->FeedbackMixer[i].Current = 0;
399 pLVREV_Private->FeedbackMixer[i].Target = 0;
400 }
401 /* Delay tap index */
402 pLVREV_Private->A_DelaySize[0] = LVREV_MAX_AP0_DELAY;
403 pLVREV_Private->B_DelaySize[0] = LVREV_MAX_AP0_DELAY;
404 pLVREV_Private->A_DelaySize[1] = LVREV_MAX_AP1_DELAY;
405 pLVREV_Private->B_DelaySize[1] = LVREV_MAX_AP1_DELAY;
406 pLVREV_Private->A_DelaySize[2] = LVREV_MAX_AP2_DELAY;
407 pLVREV_Private->B_DelaySize[2] = LVREV_MAX_AP2_DELAY;
408 pLVREV_Private->A_DelaySize[3] = LVREV_MAX_AP3_DELAY;
409 pLVREV_Private->B_DelaySize[3] = LVREV_MAX_AP3_DELAY;
410
411
412 LVREV_ClearAudioBuffers(*phInstance);
413
414 return LVREV_SUCCESS;
415 }
416
417 /* End of file */
418