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