• 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 "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             InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY  * sizeof(LVM_INT32));
165             InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY  * sizeof(LVM_INT32));
166             InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
167             InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
168         }
169 
170         if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
171         {
172             InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
173             InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
174         }
175 
176         if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
177         {
178             InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
179         }
180 
181         pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size         = InstAlloc_GetTotal(&FastData);
182         pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Type         = LVM_PERSISTENT_FAST_DATA;
183         pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
184 
185 
186         /*
187          * Persistent fast coefficient memory
188          */
189         InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st));
190         pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size         = InstAlloc_GetTotal(&FastCoef);
191         pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Type         = LVM_PERSISTENT_FAST_COEF;
192         pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
193 
194 
195         /*
196          * Temporary fast memory
197          */
198         InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);          /* General purpose scratch memory */
199         InstAlloc_AddMember(&Temporary, 2*sizeof(LVM_INT32) * MaxBlockSize);        /* Mono->stereo input saved for end mix */
200 
201         if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
202         {
203             for(i=0; i<4; i++)
204             {
205                 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);      /* A Scratch buffer for each delay line */
206             }
207         }
208 
209         if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
210         {
211             for(i=0; i<2; i++)
212             {
213                 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);      /* A Scratch buffer for each delay line */
214             }
215         }
216 
217         if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
218         {
219             for(i=0; i<1; i++)
220             {
221                 InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);      /* A Scratch buffer for each delay line */
222             }
223         }
224 
225         pMemoryTable->Region[LVM_TEMPORARY_FAST].Size         = InstAlloc_GetTotal(&Temporary);
226         pMemoryTable->Region[LVM_TEMPORARY_FAST].Type         = LVM_TEMPORARY_FAST;
227         pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress = LVM_NULL;
228 
229     }
230     else
231     {
232         LVREV_Instance_st   *pLVREV_Private = (LVREV_Instance_st *)hInstance;
233 
234 
235         /*
236          * Read back memory allocation table
237          */
238         *pMemoryTable = pLVREV_Private->MemoryTable;
239     }
240 
241 
242     return(LVREV_SUCCESS);
243 }
244 
245 /* End of file */
246