summaryrefslogtreecommitdiffstats
path: root/media/libeffects/lvm/lib/Reverb/src/LVREV_GetMemoryTable.c
blob: e16a3d30b89e679756b7201736fc0c7fcfb48506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
 * Copyright (C) 2004-2010 NXP Software
 * Copyright (C) 2010 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/****************************************************************************************/
/*                                                                                      */
/*     Project::                                                                        */
/*     $Author: beq07716 $*/
/*     $Revision: 1007 $*/
/*     $Date: 2010-06-28 14:06:36 +0200 (Mon, 28 Jun 2010) $*/
/*                                                                                      */
/****************************************************************************************/

/****************************************************************************************/
/*                                                                                      */
/*  Includes                                                                            */
/*                                                                                      */
/****************************************************************************************/
#include "LVREV_Private.h"
#include "InstAlloc.h"

/****************************************************************************************/
/*                                                                                      */
/* FUNCTION:                LVREV_GetMemoryTable                                        */
/*                                                                                      */
/* DESCRIPTION:                                                                         */
/*  This function is used for memory allocation and free. It can be called in           */
/*  two ways:                                                                           */
/*                                                                                      */
/*  hInstance = NULL                Returns the memory requirements                     */
/*  hInstance = Instance handle     Returns the memory requirements and allocated       */
/*                                  base addresses.                                     */
/*                                                                                      */
/*  When this function is called for memory allocation (hInstance=NULL) the memory      */
/*  base address pointers are NULL on return.                                           */
/*                                                                                      */
/*  When the function is called for free (hInstance = Instance Handle) the memory       */
/*  table returns the allocated memory and base addresses used during initialisation.   */
/*                                                                                      */
/* PARAMETERS:                                                                          */
/*  hInstance               Instance Handle                                             */
/*  pMemoryTable            Pointer to an empty memory table                            */
/*  pInstanceParams         Pointer to the instance parameters                          */
/*                                                                                      */
/* RETURNS:                                                                             */
/*  LVREV_Success           Succeeded                                                   */
/*  LVREV_NULLADDRESS       When pMemoryTable is NULL                                   */
/*  LVREV_NULLADDRESS       When requesting memory requirements and pInstanceParams     */
/*                          is NULL                                                     */
/*                                                                                      */
/* NOTES:                                                                               */
/*  1.  This function may be interrupted by the LVREV_Process function                  */
/*                                                                                      */
/****************************************************************************************/
LVREV_ReturnStatus_en LVREV_GetMemoryTable(LVREV_Handle_t           hInstance,
                                           LVREV_MemoryTable_st     *pMemoryTable,
                                           LVREV_InstanceParams_st  *pInstanceParams)
{

    INST_ALLOC              SlowData;
    INST_ALLOC              FastData;
    INST_ALLOC              FastCoef;
    INST_ALLOC              Temporary;
    LVM_INT16               i;
    LVM_UINT16              MaxBlockSize;


    /*
     * Check for error conditions
     */
    /* Check for NULL pointer */
    if (pMemoryTable == LVM_NULL)
    {
        return(LVREV_NULLADDRESS);
    }

    /*
     * Check all instance parameters are in range
     */
    if (pInstanceParams != LVM_NULL)
    {
        /*
         * Call for memory allocation, so check the parameters
         */
        /* Check for a non-zero block size */
        if (pInstanceParams->MaxBlockSize == 0)
        {
            return LVREV_OUTOFRANGE;
        }

        /* Check for a valid number of delay lines */
        if ((pInstanceParams->NumDelays != LVREV_DELAYLINES_1) &&
            (pInstanceParams->NumDelays != LVREV_DELAYLINES_2) &&
            (pInstanceParams->NumDelays != LVREV_DELAYLINES_4))
        {
            return LVREV_OUTOFRANGE;
        }
    }

    /*
     * Initialise the InstAlloc instances
     */
    InstAlloc_Init(&SlowData,  (void *)LVM_NULL);
    InstAlloc_Init(&FastData,  (void *)LVM_NULL);
    InstAlloc_Init(&FastCoef,  (void *)LVM_NULL);
    InstAlloc_Init(&Temporary, (void *)LVM_NULL);


    /*
     * Fill in the memory table
     */
    if (hInstance == LVM_NULL)
    {
        /*
         * Check for null pointers
         */
        if (pInstanceParams == LVM_NULL)
        {
            return(LVREV_NULLADDRESS);
        }


        /*
         * Select the maximum internal block size
         */
        if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_4)
        {
            MaxBlockSize = LVREV_MAX_AP3_DELAY;
        }
        else if(pInstanceParams->NumDelays ==LVREV_DELAYLINES_2)
        {
            MaxBlockSize = LVREV_MAX_AP1_DELAY;
        }
        else
        {
            MaxBlockSize = LVREV_MAX_AP0_DELAY;
        }

        if(MaxBlockSize>pInstanceParams->MaxBlockSize)
        {
            MaxBlockSize=pInstanceParams->MaxBlockSize;
        }


        /*
         * Slow data memory
         */
        InstAlloc_AddMember(&SlowData, sizeof(LVREV_Instance_st));
        pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Size         = InstAlloc_GetTotal(&SlowData);
        pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].Type         = LVM_PERSISTENT_SLOW_DATA;
        pMemoryTable->Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;


        /*
         * Persistent fast data memory
         */
        InstAlloc_AddMember(&FastData, sizeof(LVREV_FastData_st));
        if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
        {
            InstAlloc_AddMember(&FastData, LVREV_MAX_T3_DELAY  * sizeof(LVM_INT32));
            InstAlloc_AddMember(&FastData, LVREV_MAX_T2_DELAY  * sizeof(LVM_INT32));
            InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
            InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
        }

        if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
        {
            InstAlloc_AddMember(&FastData, LVREV_MAX_T1_DELAY * sizeof(LVM_INT32));
            InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
        }

        if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
        {
            InstAlloc_AddMember(&FastData, LVREV_MAX_T0_DELAY * sizeof(LVM_INT32));
        }

        pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Size         = InstAlloc_GetTotal(&FastData);
        pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].Type         = LVM_PERSISTENT_FAST_DATA;
        pMemoryTable->Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;


        /*
         * Persistent fast coefficient memory
         */
        InstAlloc_AddMember(&FastCoef, sizeof(LVREV_FastCoef_st));
        pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Size         = InstAlloc_GetTotal(&FastCoef);
        pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].Type         = LVM_PERSISTENT_FAST_COEF;
        pMemoryTable->Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;


        /*
         * Temporary fast memory
         */
        InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);          /* General purpose scratch memory */
        InstAlloc_AddMember(&Temporary, 2*sizeof(LVM_INT32) * MaxBlockSize);        /* Mono->stereo input saved for end mix */

        if(pInstanceParams->NumDelays == LVREV_DELAYLINES_4)
        {
            for(i=0; i<4; i++)
            {
                InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);      /* A Scratch buffer for each delay line */
            }
        }

        if(pInstanceParams->NumDelays == LVREV_DELAYLINES_2)
        {
            for(i=0; i<2; i++)
            {
                InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);      /* A Scratch buffer for each delay line */
            }
        }

        if(pInstanceParams->NumDelays == LVREV_DELAYLINES_1)
        {
            for(i=0; i<1; i++)
            {
                InstAlloc_AddMember(&Temporary, sizeof(LVM_INT32) * MaxBlockSize);      /* A Scratch buffer for each delay line */
            }
        }

        pMemoryTable->Region[LVM_TEMPORARY_FAST].Size         = InstAlloc_GetTotal(&Temporary);
        pMemoryTable->Region[LVM_TEMPORARY_FAST].Type         = LVM_TEMPORARY_FAST;
        pMemoryTable->Region[LVM_TEMPORARY_FAST].pBaseAddress = LVM_NULL;

    }
    else
    {
        LVREV_Instance_st   *pLVREV_Private = (LVREV_Instance_st *)hInstance;


        /*
         * Read back memory allocation table
         */
        *pMemoryTable = pLVREV_Private->MemoryTable;
    }


    return(LVREV_SUCCESS);
}

/* End of file */