Home | History | Annotate | Download | only in src
      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 
     24 #include "LVM_Private.h"
     25 #include "LVM_Tables.h"
     26 #include "VectorArithmetic.h"
     27 #include "InstAlloc.h"
     28 
     29 /****************************************************************************************/
     30 /*                                                                                      */
     31 /* FUNCTION:                LVM_GetMemoryTable                                          */
     32 /*                                                                                      */
     33 /* DESCRIPTION:                                                                         */
     34 /*  This function is used for memory allocation and free. It can be called in           */
     35 /*  two ways:                                                                           */
     36 /*                                                                                      */
     37 /*      hInstance = NULL                Returns the memory requirements                 */
     38 /*      hInstance = Instance handle     Returns the memory requirements and             */
     39 /*                                      allocated base addresses for the instance       */
     40 /*                                                                                      */
     41 /*  When this function is called for memory allocation (hInstance=NULL) the memory      */
     42 /*  base address pointers are NULL on return.                                           */
     43 /*                                                                                      */
     44 /*  When the function is called for free (hInstance = Instance Handle) the memory       */
     45 /*  table returns the allocated memory and base addresses used during initialisation.   */
     46 /*                                                                                      */
     47 /* PARAMETERS:                                                                          */
     48 /*  hInstance               Instance Handle                                             */
     49 /*  pMemoryTable            Pointer to an empty memory definition table                 */
     50 /*  pCapabilities           Pointer to the default capabilities                         */
     51 /*                                                                                      */
     52 /* RETURNS:                                                                             */
     53 /*  LVM_SUCCESS             Succeeded                                                   */
     54 /*  LVM_NULLADDRESS         When one of pMemoryTable or pInstParams is NULL             */
     55 /*  LVM_OUTOFRANGE          When any of the Instance parameters are out of range        */
     56 /*                                                                                      */
     57 /* NOTES:                                                                               */
     58 /*  1.  This function may be interrupted by the LVM_Process function                    */
     59 /*  2.  The scratch memory is the largest required by any of the sub-modules plus any   */
     60 /*      additional scratch requirements of the bundle                                   */
     61 /*                                                                                      */
     62 /****************************************************************************************/
     63 
     64 LVM_ReturnStatus_en LVM_GetMemoryTable(LVM_Handle_t         hInstance,
     65                                        LVM_MemTab_t         *pMemoryTable,
     66                                        LVM_InstParams_t     *pInstParams)
     67 {
     68 
     69     LVM_Instance_t      *pInstance = (LVM_Instance_t *)hInstance;
     70     LVM_UINT32          AlgScratchSize;
     71     LVM_UINT32          BundleScratchSize;
     72     LVM_UINT16          InternalBlockSize;
     73     INST_ALLOC          AllocMem[LVM_NR_MEMORY_REGIONS];
     74     LVM_INT16           i;
     75 
     76 
     77     /*
     78      * Check parameters
     79      */
     80     if(pMemoryTable == LVM_NULL)
     81     {
     82         return LVM_NULLADDRESS;
     83     }
     84 
     85 
     86     /*
     87      * Return memory table if the instance has already been created
     88      */
     89     if (hInstance != LVM_NULL)
     90     {
     91        /* Read back memory allocation table */
     92         *pMemoryTable = pInstance->MemoryTable;
     93         return(LVM_SUCCESS);
     94     }
     95 
     96     if(pInstParams == LVM_NULL)
     97     {
     98         return LVM_NULLADDRESS;
     99     }
    100 
    101     /*
    102      *  Power Spectrum Analyser
    103      */
    104     if(pInstParams->PSA_Included > LVM_PSA_ON)
    105     {
    106         return (LVM_OUTOFRANGE);
    107     }
    108 
    109     /*
    110      * Check the instance parameters
    111      */
    112     if( (pInstParams->BufferMode != LVM_MANAGED_BUFFERS) && (pInstParams->BufferMode != LVM_UNMANAGED_BUFFERS) )
    113     {
    114         return (LVM_OUTOFRANGE);
    115     }
    116 
    117     /* N-Band Equalizer */
    118     if( pInstParams->EQNB_NumBands > 32 )
    119     {
    120         return (LVM_OUTOFRANGE);
    121     }
    122 
    123     if(pInstParams->BufferMode == LVM_MANAGED_BUFFERS)
    124     {
    125         if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_MANAGED_MAX_MAXBLOCKSIZE ) )
    126         {
    127             return (LVM_OUTOFRANGE);
    128         }
    129     }
    130     else
    131     {
    132         if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_UNMANAGED_MAX_MAXBLOCKSIZE) )
    133         {
    134             return (LVM_OUTOFRANGE);
    135         }
    136     }
    137 
    138     /*
    139     * Initialise the AllocMem structures
    140     */
    141     for (i=0; i<LVM_NR_MEMORY_REGIONS; i++)
    142     {
    143         InstAlloc_Init(&AllocMem[i], LVM_NULL);
    144     }
    145     InternalBlockSize = (LVM_UINT16)((pInstParams->MaxBlockSize) & MIN_INTERNAL_BLOCKMASK); /* Force to a multiple of MIN_INTERNAL_BLOCKSIZE */
    146 
    147     if (InternalBlockSize < MIN_INTERNAL_BLOCKSIZE)
    148     {
    149         InternalBlockSize = MIN_INTERNAL_BLOCKSIZE;
    150     }
    151 
    152     /* Maximum Internal Black Size should not be more than MAX_INTERNAL_BLOCKSIZE*/
    153     if(InternalBlockSize > MAX_INTERNAL_BLOCKSIZE)
    154     {
    155         InternalBlockSize = MAX_INTERNAL_BLOCKSIZE;
    156     }
    157 
    158     /*
    159     * Bundle requirements
    160     */
    161     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA],
    162         sizeof(LVM_Instance_t));
    163 
    164 
    165     /*
    166      * Set the algorithm and bundle scratch requirements
    167      */
    168     AlgScratchSize    = 0;
    169     if (pInstParams->BufferMode == LVM_MANAGED_BUFFERS)
    170     {
    171         BundleScratchSize = 6 * (MIN_INTERNAL_BLOCKSIZE + InternalBlockSize) * sizeof(LVM_INT16);
    172         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],        /* Scratch buffer */
    173                             BundleScratchSize);
    174         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA],
    175                             sizeof(LVM_Buffer_t));
    176     }
    177 
    178     /*
    179      * Treble Enhancement requirements
    180      */
    181     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    182                         sizeof(LVM_TE_Data_t));
    183     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    184                         sizeof(LVM_TE_Coefs_t));
    185 
    186     /*
    187      * N-Band Equalizer requirements
    188      */
    189     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],      /* Local storage */
    190                         (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t)));
    191     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],      /* User storage */
    192                         (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t)));
    193 
    194     /*
    195      * Concert Sound requirements
    196      */
    197     {
    198         LVCS_MemTab_t           CS_MemTab;
    199         LVCS_Capabilities_t     CS_Capabilities;
    200 
    201         /*
    202          * Set the capabilities
    203          */
    204         CS_Capabilities.MaxBlockSize     = InternalBlockSize;
    205 
    206         /*
    207          * Get the memory requirements
    208          */
    209         LVCS_Memory(LVM_NULL,
    210                     &CS_MemTab,
    211                     &CS_Capabilities);
    212 
    213         /*
    214          * Update the memory allocation structures
    215          */
    216         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    217                             CS_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size);
    218         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    219                             CS_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size);
    220         if (CS_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size > AlgScratchSize) AlgScratchSize = CS_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size;
    221 
    222     }
    223 
    224 
    225     /*
    226      * Dynamic Bass Enhancement requirements
    227      */
    228     {
    229         LVDBE_MemTab_t          DBE_MemTab;
    230         LVDBE_Capabilities_t    DBE_Capabilities;
    231 
    232         /*
    233          * Set the capabilities
    234          */
    235         DBE_Capabilities.SampleRate      = LVDBE_CAP_FS_8000 | LVDBE_CAP_FS_11025 | LVDBE_CAP_FS_12000 | LVDBE_CAP_FS_16000 | LVDBE_CAP_FS_22050 | LVDBE_CAP_FS_24000 | LVDBE_CAP_FS_32000 | LVDBE_CAP_FS_44100 | LVDBE_CAP_FS_48000;
    236         DBE_Capabilities.CentreFrequency = LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_66Hz | LVDBE_CAP_CENTRE_78Hz | LVDBE_CAP_CENTRE_90Hz;
    237         DBE_Capabilities.MaxBlockSize    = InternalBlockSize;
    238 
    239         /*
    240          * Get the memory requirements
    241          */
    242         LVDBE_Memory(LVM_NULL,
    243                     &DBE_MemTab,
    244 
    245                     &DBE_Capabilities);
    246         /*
    247          * Update the bundle table
    248          */
    249         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    250                             DBE_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size);
    251         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    252                             DBE_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size);
    253         if (DBE_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size > AlgScratchSize) AlgScratchSize = DBE_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size;
    254 
    255     }
    256 
    257 
    258     /*
    259      * N-Band equaliser requirements
    260      */
    261     {
    262         LVEQNB_MemTab_t         EQNB_MemTab;            /* For N-Band Equaliser */
    263         LVEQNB_Capabilities_t   EQNB_Capabilities;
    264 
    265         /*
    266          * Set the capabilities
    267          */
    268         EQNB_Capabilities.SampleRate   = LVEQNB_CAP_FS_8000 | LVEQNB_CAP_FS_11025 | LVEQNB_CAP_FS_12000 | LVEQNB_CAP_FS_16000 | LVEQNB_CAP_FS_22050 | LVEQNB_CAP_FS_24000 | LVEQNB_CAP_FS_32000 | LVEQNB_CAP_FS_44100 | LVEQNB_CAP_FS_48000;
    269         EQNB_Capabilities.SourceFormat = LVEQNB_CAP_STEREO | LVEQNB_CAP_MONOINSTEREO;
    270         EQNB_Capabilities.MaxBlockSize = InternalBlockSize;
    271         EQNB_Capabilities.MaxBands     = pInstParams->EQNB_NumBands;
    272 
    273         /*
    274          * Get the memory requirements
    275          */
    276         LVEQNB_Memory(LVM_NULL,
    277                       &EQNB_MemTab,
    278                       &EQNB_Capabilities);
    279 
    280         /*
    281          * Update the bundle table
    282          */
    283         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    284                             EQNB_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size);
    285         InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    286                             EQNB_MemTab.Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size);
    287         if (EQNB_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size > AlgScratchSize) AlgScratchSize = EQNB_MemTab.Region[LVM_MEMREGION_TEMPORARY_FAST].Size;
    288 
    289     }
    290 
    291     /*
    292      * Headroom management memory allocation
    293      */
    294     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    295                        (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t)));
    296     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    297                        (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t)));
    298 
    299 
    300     /*
    301      * Spectrum Analyzer memory requirements
    302      */
    303     {
    304         pLVPSA_Handle_t     hPSAInst = LVM_NULL;
    305         LVPSA_MemTab_t      PSA_MemTab;
    306         LVPSA_InitParams_t  PSA_InitParams;
    307         LVPSA_FilterParam_t FiltersParams[9];
    308         LVPSA_RETURN        PSA_Status;
    309 
    310         if(pInstParams->PSA_Included == LVM_PSA_ON)
    311         {
    312             PSA_InitParams.SpectralDataBufferDuration   = (LVM_UINT16) 500;
    313             PSA_InitParams.MaxInputBlockSize            = (LVM_UINT16) 1000;
    314             PSA_InitParams.nBands                       = (LVM_UINT16) 9;
    315 
    316             PSA_InitParams.pFiltersParams = &FiltersParams[0];
    317             for(i = 0; i < PSA_InitParams.nBands; i++)
    318             {
    319                 FiltersParams[i].CenterFrequency    = (LVM_UINT16) 1000;
    320                 FiltersParams[i].QFactor            = (LVM_UINT16) 25;
    321                 FiltersParams[i].PostGain           = (LVM_INT16)  0;
    322             }
    323 
    324             /*
    325             * Get the memory requirements
    326             */
    327             PSA_Status = LVPSA_Memory (hPSAInst,
    328                                         &PSA_MemTab,
    329                                         &PSA_InitParams);
    330 
    331             if (PSA_Status != LVPSA_OK)
    332             {
    333                 return((LVM_ReturnStatus_en) LVM_ALGORITHMPSA);
    334             }
    335 
    336             /*
    337             * Update the bundle table
    338             */
    339             /* Slow Data */
    340             InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA],
    341                 PSA_MemTab.Region[LVM_PERSISTENT_SLOW_DATA].Size);
    342 
    343             /* Fast Data */
    344             InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    345                 PSA_MemTab.Region[LVM_PERSISTENT_FAST_DATA].Size);
    346 
    347             /* Fast Coef */
    348             InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    349                 PSA_MemTab.Region[LVM_PERSISTENT_FAST_COEF].Size);
    350 
    351             /* Fast Temporary */
    352             InstAlloc_AddMember(&AllocMem[LVM_TEMPORARY_FAST],
    353                                 MAX_INTERNAL_BLOCKSIZE * sizeof(LVM_INT16));
    354 
    355             if (PSA_MemTab.Region[LVM_TEMPORARY_FAST].Size > AlgScratchSize)
    356             {
    357                 AlgScratchSize = PSA_MemTab.Region[LVM_TEMPORARY_FAST].Size;
    358             }
    359         }
    360     }
    361 
    362     /*
    363      * Return the memory table
    364      */
    365     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_SLOW_DATA].Size         = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA]);
    366     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_SLOW_DATA].Type         = LVM_PERSISTENT_SLOW_DATA;
    367     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;
    368 
    369     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size         = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA]);
    370     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Type         = LVM_PERSISTENT_FAST_DATA;
    371     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
    372     if (pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size < 4)
    373     {
    374         pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_DATA].Size = 0;
    375     }
    376 
    377     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size         = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF]);
    378     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Type         = LVM_PERSISTENT_FAST_COEF;
    379     pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
    380     if (pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size < 4)
    381     {
    382         pMemoryTable->Region[LVM_MEMREGION_PERSISTENT_FAST_COEF].Size = 0;
    383     }
    384 
    385     InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],
    386                         AlgScratchSize);
    387     pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Size             = InstAlloc_GetTotal(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST]);
    388     pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Type             = LVM_TEMPORARY_FAST;
    389     pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].pBaseAddress     = LVM_NULL;
    390     if (pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Size < 4)
    391     {
    392         pMemoryTable->Region[LVM_MEMREGION_TEMPORARY_FAST].Size = 0;
    393     }
    394 
    395     return(LVM_SUCCESS);
    396 
    397 }
    398 
    399 
    400 /****************************************************************************************/
    401 /*                                                                                      */
    402 /* FUNCTION:                LVM_GetInstanceHandle                                       */
    403 /*                                                                                      */
    404 /* DESCRIPTION:                                                                         */
    405 /*  This function is used to create a bundle instance. It returns the created instance  */
    406 /*  handle through phInstance. All parameters are set to their default, inactive state. */
    407 /*                                                                                      */
    408 /* PARAMETERS:                                                                          */
    409 /*  phInstance              pointer to the instance handle                              */
    410 /*  pMemoryTable            Pointer to the memory definition table                      */
    411 /*  pInstParams             Pointer to the initialisation capabilities                  */
    412 /*                                                                                      */
    413 /* RETURNS:                                                                             */
    414 /*  LVM_SUCCESS             Initialisation succeeded                                    */
    415 /*  LVM_OUTOFRANGE          When any of the Instance parameters are out of range        */
    416 /*  LVM_NULLADDRESS         When one of phInstance, pMemoryTable or pInstParams are NULL*/
    417 /*                                                                                      */
    418 /* NOTES:                                                                               */
    419 /*  1. This function must not be interrupted by the LVM_Process function                */
    420 /*                                                                                      */
    421 /****************************************************************************************/
    422 
    423 LVM_ReturnStatus_en LVM_GetInstanceHandle(LVM_Handle_t           *phInstance,
    424                                           LVM_MemTab_t           *pMemoryTable,
    425                                           LVM_InstParams_t       *pInstParams)
    426 {
    427 
    428     LVM_ReturnStatus_en     Status = LVM_SUCCESS;
    429     LVM_Instance_t          *pInstance;
    430     INST_ALLOC              AllocMem[LVM_NR_MEMORY_REGIONS];
    431     LVM_INT16               i;
    432     LVM_UINT16              InternalBlockSize;
    433     LVM_INT32               BundleScratchSize;
    434 
    435 
    436     /*
    437      * Check valid points have been given
    438      */
    439     if ((phInstance == LVM_NULL) || (pMemoryTable == LVM_NULL) || (pInstParams == LVM_NULL))
    440     {
    441         return (LVM_NULLADDRESS);
    442     }
    443 
    444     /*
    445      * Check the memory table for NULL pointers
    446      */
    447     for (i=0; i<LVM_NR_MEMORY_REGIONS; i++)
    448     {
    449         if ((pMemoryTable->Region[i].Size != 0) &&
    450             (pMemoryTable->Region[i].pBaseAddress==LVM_NULL))
    451         {
    452             return(LVM_NULLADDRESS);
    453         }
    454     }
    455 
    456     /*
    457      * Check the instance parameters
    458      */
    459     if( (pInstParams->BufferMode != LVM_MANAGED_BUFFERS) && (pInstParams->BufferMode != LVM_UNMANAGED_BUFFERS) )
    460     {
    461         return (LVM_OUTOFRANGE);
    462     }
    463 
    464     if( pInstParams->EQNB_NumBands > 32 )
    465     {
    466         return (LVM_OUTOFRANGE);
    467     }
    468 
    469     if(pInstParams->BufferMode == LVM_MANAGED_BUFFERS)
    470     {
    471         if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_MANAGED_MAX_MAXBLOCKSIZE ) )
    472         {
    473             return (LVM_OUTOFRANGE);
    474         }
    475     }
    476     else
    477     {
    478         if( (pInstParams->MaxBlockSize < LVM_MIN_MAXBLOCKSIZE ) || (pInstParams->MaxBlockSize > LVM_UNMANAGED_MAX_MAXBLOCKSIZE) )
    479         {
    480             return (LVM_OUTOFRANGE);
    481         }
    482     }
    483 
    484     if(pInstParams->PSA_Included > LVM_PSA_ON)
    485     {
    486         return (LVM_OUTOFRANGE);
    487     }
    488 
    489     /*
    490      * Initialise the AllocMem structures
    491      */
    492     for (i=0; i<LVM_NR_MEMORY_REGIONS; i++)
    493     {
    494         InstAlloc_Init(&AllocMem[i],
    495                        pMemoryTable->Region[i].pBaseAddress);
    496     }
    497 
    498 
    499     /*
    500      * Set the instance handle
    501      */
    502     *phInstance  = (LVM_Handle_t)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA],
    503                                                      sizeof(LVM_Instance_t));
    504     pInstance =(LVM_Instance_t  *)*phInstance;
    505 
    506 
    507     /*
    508      * Save the memory table, parameters and capabilities
    509      */
    510     pInstance->MemoryTable    = *pMemoryTable;
    511     pInstance->InstParams     = *pInstParams;
    512 
    513 
    514     /*
    515      * Set the bundle scratch memory and initialse the buffer management
    516      */
    517     InternalBlockSize = (LVM_UINT16)((pInstParams->MaxBlockSize) & MIN_INTERNAL_BLOCKMASK); /* Force to a multiple of MIN_INTERNAL_BLOCKSIZE */
    518     if (InternalBlockSize < MIN_INTERNAL_BLOCKSIZE)
    519     {
    520         InternalBlockSize = MIN_INTERNAL_BLOCKSIZE;
    521     }
    522 
    523     /* Maximum Internal Black Size should not be more than MAX_INTERNAL_BLOCKSIZE*/
    524     if(InternalBlockSize > MAX_INTERNAL_BLOCKSIZE)
    525     {
    526         InternalBlockSize = MAX_INTERNAL_BLOCKSIZE;
    527     }
    528     pInstance->InternalBlockSize = (LVM_INT16)InternalBlockSize;
    529 
    530 
    531     /*
    532      * Common settings for managed and unmanaged buffers
    533      */
    534     pInstance->SamplesToProcess = 0;                /* No samples left to process */
    535     if (pInstParams->BufferMode == LVM_MANAGED_BUFFERS)
    536     {
    537         /*
    538          * Managed buffers required
    539          */
    540         pInstance->pBufferManagement = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA],
    541                                                            sizeof(LVM_Buffer_t));
    542         BundleScratchSize = (LVM_INT32)(6 * (MIN_INTERNAL_BLOCKSIZE + InternalBlockSize) * sizeof(LVM_INT16));
    543         pInstance->pBufferManagement->pScratch = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],   /* Scratch 1 buffer */
    544                                                                      (LVM_UINT32)BundleScratchSize);
    545 
    546         LoadConst_16(0,                                                        /* Clear the input delay buffer */
    547                      (LVM_INT16 *)&pInstance->pBufferManagement->InDelayBuffer,
    548                      (LVM_INT16)(2 * MIN_INTERNAL_BLOCKSIZE));
    549         pInstance->pBufferManagement->InDelaySamples = MIN_INTERNAL_BLOCKSIZE; /* Set the number of delay samples */
    550         pInstance->pBufferManagement->OutDelaySamples = 0;                     /* No samples in the output buffer */
    551         pInstance->pBufferManagement->BufferState = LVM_FIRSTCALL;             /* Set the state ready for the first call */
    552     }
    553 
    554 
    555     /*
    556      * Set default parameters
    557      */
    558     pInstance->Params.OperatingMode    = LVM_MODE_OFF;
    559     pInstance->Params.SampleRate       = LVM_FS_8000;
    560     pInstance->Params.SourceFormat     = LVM_MONO;
    561     pInstance->Params.SpeakerType      = LVM_HEADPHONES;
    562     pInstance->Params.VC_EffectLevel   = 0;
    563     pInstance->Params.VC_Balance       = 0;
    564 
    565     /*
    566      * Set callback
    567      */
    568     pInstance->CallBack = LVM_AlgoCallBack;
    569 
    570 
    571     /*
    572      * DC removal filter
    573      */
    574     DC_2I_D16_TRC_WRA_01_Init(&pInstance->DC_RemovalInstance);
    575 
    576 
    577     /*
    578      * Treble Enhancement
    579      */
    580     pInstance->pTE_Taps  = (LVM_TE_Data_t *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    581                                                                 sizeof(LVM_TE_Data_t));
    582 
    583     pInstance->pTE_State = (LVM_TE_Coefs_t *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    584                                                                  sizeof(LVM_TE_Coefs_t));
    585     pInstance->Params.TE_OperatingMode = LVM_TE_OFF;
    586     pInstance->Params.TE_EffectLevel   = 0;
    587     pInstance->TE_Active               = LVM_FALSE;
    588 
    589 
    590     /*
    591      * Set the volume control and initialise Current to Target
    592      */
    593     pInstance->VC_Volume.MixerStream[0].CallbackParam      = 0;
    594     pInstance->VC_Volume.MixerStream[0].CallbackSet        = 0;
    595     pInstance->VC_Volume.MixerStream[0].pCallbackHandle    = pInstance;
    596     pInstance->VC_Volume.MixerStream[0].pCallBack          = LVM_VCCallBack;
    597 
    598     /* In managed buffering, start with low signal level as delay in buffer management causes a click*/
    599     if (pInstParams->BufferMode == LVM_MANAGED_BUFFERS)
    600     {
    601         LVC_Mixer_Init(&pInstance->VC_Volume.MixerStream[0],0,0);
    602     }
    603     else
    604     {
    605         LVC_Mixer_Init(&pInstance->VC_Volume.MixerStream[0],LVM_MAXINT_16,LVM_MAXINT_16);
    606     }
    607 
    608     LVC_Mixer_SetTimeConstant(&pInstance->VC_Volume.MixerStream[0],0,LVM_FS_8000,2);
    609 
    610     pInstance->VC_VolumedB                  = 0;
    611     pInstance->VC_AVLFixedVolume            = 0;
    612     pInstance->VC_Active                    = LVM_FALSE;
    613 
    614     pInstance->VC_BalanceMix.MixerStream[0].CallbackParam      = 0;
    615     pInstance->VC_BalanceMix.MixerStream[0].CallbackSet        = 0;
    616     pInstance->VC_BalanceMix.MixerStream[0].pCallbackHandle    = pInstance;
    617     pInstance->VC_BalanceMix.MixerStream[0].pCallBack          = LVM_VCCallBack;
    618     LVC_Mixer_Init(&pInstance->VC_BalanceMix.MixerStream[0],LVM_MAXINT_16,LVM_MAXINT_16);
    619     LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[0],LVM_VC_MIXER_TIME,LVM_FS_8000,2);
    620 
    621     pInstance->VC_BalanceMix.MixerStream[1].CallbackParam      = 0;
    622     pInstance->VC_BalanceMix.MixerStream[1].CallbackSet        = 0;
    623     pInstance->VC_BalanceMix.MixerStream[1].pCallbackHandle    = pInstance;
    624     pInstance->VC_BalanceMix.MixerStream[1].pCallBack          = LVM_VCCallBack;
    625     LVC_Mixer_Init(&pInstance->VC_BalanceMix.MixerStream[1],LVM_MAXINT_16,LVM_MAXINT_16);
    626     LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->VC_BalanceMix.MixerStream[1],LVM_VC_MIXER_TIME,LVM_FS_8000,2);
    627     /*
    628      * Set the default EQNB pre-gain and pointer to the band definitions
    629      */
    630     pInstance->pEQNB_BandDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    631                                                     (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t)));
    632     pInstance->pEQNB_UserDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    633                                                    (pInstParams->EQNB_NumBands * sizeof(LVM_EQNB_BandDef_t)));
    634 
    635 
    636     /*
    637      * Initialise the Concert Sound module
    638      */
    639     {
    640         LVCS_Handle_t           hCSInstance;                /* Instance handle */
    641         LVCS_MemTab_t           CS_MemTab;                  /* Memory table */
    642         LVCS_Capabilities_t     CS_Capabilities;            /* Initial capabilities */
    643         LVCS_ReturnStatus_en    LVCS_Status;                /* Function call status */
    644 
    645         /*
    646          * Set default parameters
    647          */
    648         pInstance->Params.VirtualizerReverbLevel    = 100;
    649         pInstance->Params.VirtualizerType           = LVM_CONCERTSOUND;
    650         pInstance->Params.VirtualizerOperatingMode  = LVM_MODE_OFF;
    651         pInstance->CS_Active                        = LVM_FALSE;
    652 
    653         /*
    654          * Set the initialisation capabilities
    655          */
    656         CS_Capabilities.MaxBlockSize    = (LVM_UINT16)InternalBlockSize;
    657         CS_Capabilities.CallBack = pInstance->CallBack;
    658         CS_Capabilities.pBundleInstance = (void*)pInstance;
    659 
    660 
    661         /*
    662          * Get the memory requirements and then set the address pointers, forcing alignment
    663          */
    664         LVCS_Status = LVCS_Memory(LVM_NULL,                /* Get the memory requirements */
    665                                   &CS_MemTab,
    666                                   &CS_Capabilities);
    667         CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = &pInstance->CS_Instance;
    668         CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    669                                                                                                          CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Size);
    670         CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    671                                                                                                          CS_MemTab.Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Size);
    672         CS_MemTab.Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress       = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],
    673                                                                                                          0);
    674 
    675         /*
    676          * Initialise the Concert Sound instance and save the instance handle
    677          */
    678         hCSInstance = LVM_NULL;                            /* Set to NULL to return handle */
    679         LVCS_Status = LVCS_Init(&hCSInstance,              /* Initiailse */
    680                                 &CS_MemTab,
    681                                 &CS_Capabilities);
    682         if (LVCS_Status != LVCS_SUCCESS) return((LVM_ReturnStatus_en)LVCS_Status);
    683         pInstance->hCSInstance = hCSInstance;              /* Save the instance handle */
    684 
    685     }
    686 
    687     /*
    688      * Initialise the Bass Enhancement module
    689      */
    690     {
    691         LVDBE_Handle_t          hDBEInstance;               /* Instance handle */
    692         LVDBE_MemTab_t          DBE_MemTab;                 /* Memory table */
    693         LVDBE_Capabilities_t    DBE_Capabilities;           /* Initial capabilities */
    694         LVDBE_ReturnStatus_en   LVDBE_Status;               /* Function call status */
    695 
    696 
    697         /*
    698          * Set the initialisation parameters
    699          */
    700         pInstance->Params.BE_OperatingMode = LVM_BE_OFF;
    701         pInstance->Params.BE_CentreFreq    = LVM_BE_CENTRE_55Hz;
    702         pInstance->Params.BE_EffectLevel   = 0;
    703         pInstance->Params.BE_HPF           = LVM_BE_HPF_OFF;
    704 
    705         pInstance->DBE_Active              = LVM_FALSE;
    706 
    707 
    708 
    709         /*
    710          * Set the initialisation capabilities
    711          */
    712         DBE_Capabilities.SampleRate      = LVDBE_CAP_FS_8000 | LVDBE_CAP_FS_11025 | LVDBE_CAP_FS_12000 | LVDBE_CAP_FS_16000 | LVDBE_CAP_FS_22050 | LVDBE_CAP_FS_24000 | LVDBE_CAP_FS_32000 | LVDBE_CAP_FS_44100 | LVDBE_CAP_FS_48000;
    713         DBE_Capabilities.CentreFrequency = LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_55Hz | LVDBE_CAP_CENTRE_66Hz | LVDBE_CAP_CENTRE_78Hz | LVDBE_CAP_CENTRE_90Hz;
    714         DBE_Capabilities.MaxBlockSize    = (LVM_UINT16)InternalBlockSize;
    715 
    716 
    717         /*
    718          * Get the memory requirements and then set the address pointers
    719          */
    720         LVDBE_Status = LVDBE_Memory(LVM_NULL,               /* Get the memory requirements */
    721                                     &DBE_MemTab,
    722                                     &DBE_Capabilities);
    723         DBE_MemTab.Region[LVDBE_MEMREGION_INSTANCE].pBaseAddress        = &pInstance->DBE_Instance;
    724         DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    725                                                                                                       DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_DATA].Size);
    726         DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    727                                                                                                       DBE_MemTab.Region[LVDBE_MEMREGION_PERSISTENT_COEF].Size);
    728         DBE_MemTab.Region[LVDBE_MEMREGION_SCRATCH].pBaseAddress         = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],
    729                                                                                                       0);
    730 
    731 
    732         /*
    733          * Initialise the Dynamic Bass Enhancement instance and save the instance handle
    734          */
    735         hDBEInstance = LVM_NULL;                            /* Set to NULL to return handle */
    736         LVDBE_Status = LVDBE_Init(&hDBEInstance,            /* Initiailse */
    737                                   &DBE_MemTab,
    738                                   &DBE_Capabilities);
    739         if (LVDBE_Status != LVDBE_SUCCESS) return((LVM_ReturnStatus_en)LVDBE_Status);
    740         pInstance->hDBEInstance = hDBEInstance;             /* Save the instance handle */
    741     }
    742 
    743 
    744     /*
    745      * Initialise the N-Band Equaliser module
    746      */
    747     {
    748         LVEQNB_Handle_t          hEQNBInstance;             /* Instance handle */
    749         LVEQNB_MemTab_t          EQNB_MemTab;               /* Memory table */
    750         LVEQNB_Capabilities_t    EQNB_Capabilities;         /* Initial capabilities */
    751         LVEQNB_ReturnStatus_en   LVEQNB_Status;             /* Function call status */
    752 
    753 
    754         /*
    755          * Set the initialisation parameters
    756          */
    757         pInstance->Params.EQNB_OperatingMode   = LVM_EQNB_OFF;
    758         pInstance->Params.EQNB_NBands          = 0;
    759         pInstance->Params.pEQNB_BandDefinition = LVM_NULL;
    760         pInstance->EQNB_Active                 = LVM_FALSE;
    761 
    762 
    763         /*
    764          * Set the initialisation capabilities
    765          */
    766         EQNB_Capabilities.SampleRate      = LVEQNB_CAP_FS_8000 | LVEQNB_CAP_FS_11025 | LVEQNB_CAP_FS_12000 | LVEQNB_CAP_FS_16000 | LVEQNB_CAP_FS_22050 | LVEQNB_CAP_FS_24000 | LVEQNB_CAP_FS_32000 | LVEQNB_CAP_FS_44100 | LVEQNB_CAP_FS_48000;
    767         EQNB_Capabilities.MaxBlockSize    = (LVM_UINT16)InternalBlockSize;
    768         EQNB_Capabilities.MaxBands        = pInstParams->EQNB_NumBands;
    769         EQNB_Capabilities.SourceFormat    = LVEQNB_CAP_STEREO | LVEQNB_CAP_MONOINSTEREO;
    770         EQNB_Capabilities.CallBack        = pInstance->CallBack;
    771         EQNB_Capabilities.pBundleInstance  = (void*)pInstance;
    772 
    773 
    774         /*
    775          * Get the memory requirements and then set the address pointers, forcing alignment
    776          */
    777         LVEQNB_Status = LVEQNB_Memory(LVM_NULL,             /* Get the memory requirements */
    778                                       &EQNB_MemTab,
    779                                       &EQNB_Capabilities);
    780         EQNB_MemTab.Region[LVEQNB_MEMREGION_INSTANCE].pBaseAddress        = &pInstance->EQNB_Instance;
    781         EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    782                                                                                                         EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_DATA].Size);
    783         EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    784                                                                                                         EQNB_MemTab.Region[LVEQNB_MEMREGION_PERSISTENT_COEF].Size);
    785         EQNB_MemTab.Region[LVEQNB_MEMREGION_SCRATCH].pBaseAddress         = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],
    786                                                                                                         0);
    787 
    788 
    789         /*
    790          * Initialise the Dynamic Bass Enhancement instance and save the instance handle
    791          */
    792         hEQNBInstance = LVM_NULL;                           /* Set to NULL to return handle */
    793         LVEQNB_Status = LVEQNB_Init(&hEQNBInstance,         /* Initiailse */
    794                                     &EQNB_MemTab,
    795                                     &EQNB_Capabilities);
    796         if (LVEQNB_Status != LVEQNB_SUCCESS) return((LVM_ReturnStatus_en)LVEQNB_Status);
    797         pInstance->hEQNBInstance = hEQNBInstance;           /* Save the instance handle */
    798     }
    799 
    800     /*
    801      * Headroom management memory allocation
    802      */
    803     {
    804         pInstance->pHeadroom_BandDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    805                                                         (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t)));
    806         pInstance->pHeadroom_UserDefs = InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    807                                                        (LVM_HEADROOM_MAX_NBANDS * sizeof(LVM_HeadroomBandDef_t)));
    808 
    809         /* Headroom management parameters initialisation */
    810         pInstance->NewHeadroomParams.NHeadroomBands = 2;
    811         pInstance->NewHeadroomParams.pHeadroomDefinition = pInstance->pHeadroom_BandDefs;
    812         pInstance->NewHeadroomParams.pHeadroomDefinition[0].Limit_Low          = 20;
    813         pInstance->NewHeadroomParams.pHeadroomDefinition[0].Limit_High         = 4999;
    814         pInstance->NewHeadroomParams.pHeadroomDefinition[0].Headroom_Offset    = 3;
    815         pInstance->NewHeadroomParams.pHeadroomDefinition[1].Limit_Low          = 5000;
    816         pInstance->NewHeadroomParams.pHeadroomDefinition[1].Limit_High         = 24000;
    817         pInstance->NewHeadroomParams.pHeadroomDefinition[1].Headroom_Offset    = 4;
    818         pInstance->NewHeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON;
    819 
    820         pInstance->Headroom =0;
    821     }
    822 
    823 
    824     /*
    825      * Initialise the PSA module
    826      */
    827     {
    828         pLVPSA_Handle_t     hPSAInstance = LVM_NULL;   /* Instance handle */
    829         LVPSA_MemTab_t      PSA_MemTab;
    830         LVPSA_RETURN        PSA_Status;                 /* Function call status */
    831         LVPSA_FilterParam_t FiltersParams[9];
    832 
    833         if(pInstParams->PSA_Included==LVM_PSA_ON)
    834         {
    835             pInstance->PSA_InitParams.SpectralDataBufferDuration   = (LVM_UINT16) 500;
    836             pInstance->PSA_InitParams.MaxInputBlockSize            = (LVM_UINT16) 2048;
    837             pInstance->PSA_InitParams.nBands                       = (LVM_UINT16) 9;
    838             pInstance->PSA_InitParams.pFiltersParams               = &FiltersParams[0];
    839             for(i = 0; i < pInstance->PSA_InitParams.nBands; i++)
    840             {
    841                 FiltersParams[i].CenterFrequency    = (LVM_UINT16) 1000;
    842                 FiltersParams[i].QFactor            = (LVM_UINT16) 100;
    843                 FiltersParams[i].PostGain           = (LVM_INT16)  0;
    844             }
    845 
    846             /*Get the memory requirements and then set the address pointers*/
    847             PSA_Status = LVPSA_Memory (hPSAInstance,
    848                                           &PSA_MemTab,
    849                                           &pInstance->PSA_InitParams);
    850 
    851             if (PSA_Status != LVPSA_OK)
    852             {
    853                 return((LVM_ReturnStatus_en) LVM_ALGORITHMPSA);
    854             }
    855 
    856             /* Slow Data */
    857             PSA_MemTab.Region[LVM_PERSISTENT_SLOW_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_SLOW_DATA],
    858                 PSA_MemTab.Region[LVM_PERSISTENT_SLOW_DATA].Size);
    859 
    860 
    861             /* Fast Data */
    862             PSA_MemTab.Region[LVM_PERSISTENT_FAST_DATA].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_DATA],
    863                 PSA_MemTab.Region[LVM_PERSISTENT_FAST_DATA].Size);
    864 
    865 
    866             /* Fast Coef */
    867             PSA_MemTab.Region[LVM_PERSISTENT_FAST_COEF].pBaseAddress = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_PERSISTENT_FAST_COEF],
    868                 PSA_MemTab.Region[LVM_PERSISTENT_FAST_COEF].Size);
    869 
    870             /* Fast Temporary */
    871             pInstance->pPSAInput = InstAlloc_AddMember(&AllocMem[LVM_TEMPORARY_FAST],
    872                                                                      (LVM_UINT32) MAX_INTERNAL_BLOCKSIZE * sizeof(LVM_INT16));
    873 
    874             PSA_MemTab.Region[LVM_TEMPORARY_FAST].pBaseAddress       = (void *)InstAlloc_AddMember(&AllocMem[LVM_MEMREGION_TEMPORARY_FAST],0);
    875 
    876 
    877             /*Initialise PSA instance and save the instance handle*/
    878             pInstance->PSA_ControlParams.Fs = LVM_FS_48000;
    879             pInstance->PSA_ControlParams.LevelDetectionSpeed  = LVPSA_SPEED_MEDIUM;
    880             PSA_Status = LVPSA_Init (&hPSAInstance,
    881                                     &pInstance->PSA_InitParams,
    882                                     &pInstance->PSA_ControlParams,
    883                                     &PSA_MemTab);
    884 
    885             if (PSA_Status != LVPSA_OK)
    886             {
    887                 return((LVM_ReturnStatus_en) LVM_ALGORITHMPSA);
    888             }
    889 
    890             pInstance->hPSAInstance = hPSAInstance;       /* Save the instance handle */
    891             pInstance->PSA_GainOffset = 0;
    892         }
    893         else
    894         {
    895             pInstance->hPSAInstance = LVM_NULL;
    896         }
    897 
    898         /*
    899          * Set the initialisation parameters.
    900          */
    901         pInstance->Params.PSA_PeakDecayRate   = LVM_PSA_SPEED_MEDIUM;
    902         pInstance->Params.PSA_Enable          = LVM_PSA_OFF;
    903     }
    904 
    905     /*
    906      * Copy the initial parameters to the new parameters for correct readback of
    907      * the settings.
    908      */
    909     pInstance->NewParams = pInstance->Params;
    910 
    911 
    912     /*
    913      * Create configuration number
    914      */
    915     pInstance->ConfigurationNumber = 0x00000000;
    916     pInstance->ConfigurationNumber += LVM_CS_MASK;
    917     pInstance->ConfigurationNumber += LVM_EQNB_MASK;
    918     pInstance->ConfigurationNumber += LVM_DBE_MASK;
    919     pInstance->ConfigurationNumber += LVM_VC_MASK;
    920     pInstance->ConfigurationNumber += LVM_PSA_MASK;
    921 
    922     if(((pInstance->ConfigurationNumber  & LVM_CS_MASK)!=0)  ||
    923         ((pInstance->ConfigurationNumber & LVM_DBE_MASK)!=0) ||
    924         ((pInstance->ConfigurationNumber & LVM_EQNB_MASK)!=0)||
    925         ((pInstance->ConfigurationNumber & LVM_TE_MASK)!=0)  ||
    926         ((pInstance->ConfigurationNumber & LVM_VC_MASK)!=0))
    927     {
    928         pInstance->BlickSizeMultiple    = 4;
    929     }
    930     else
    931     {
    932         pInstance->BlickSizeMultiple    = 1;
    933     }
    934 
    935     return(Status);
    936 }
    937 
    938 
    939 /****************************************************************************************/
    940 /*                                                                                      */
    941 /* FUNCTION:                LVM_ClearAudioBuffers                                       */
    942 /*                                                                                      */
    943 /* DESCRIPTION:                                                                         */
    944 /*  This function is used to clear the internal audio buffers of the bundle.            */
    945 /*                                                                                      */
    946 /* PARAMETERS:                                                                          */
    947 /*  hInstance               Instance handle                                             */
    948 /*                                                                                      */
    949 /* RETURNS:                                                                             */
    950 /*  LVM_SUCCESS             Initialisation succeeded                                    */
    951 /*  LVM_NULLADDRESS         Instance or scratch memory has a NULL pointer               */
    952 /*                                                                                      */
    953 /* NOTES:                                                                               */
    954 /*  1. This function must not be interrupted by the LVM_Process function                */
    955 /*                                                                                      */
    956 /****************************************************************************************/
    957 
    958 LVM_ReturnStatus_en LVM_ClearAudioBuffers(LVM_Handle_t  hInstance)
    959 {
    960     LVM_MemTab_t            MemTab;                                     /* Memory table */
    961     LVM_InstParams_t        InstParams;                                 /* Instance parameters */
    962     LVM_ControlParams_t     Params;                                     /* Control Parameters */
    963     LVM_Instance_t          *pInstance  = (LVM_Instance_t  *)hInstance; /* Pointer to Instance */
    964 
    965 
    966     if(hInstance == LVM_NULL){
    967         return LVM_NULLADDRESS;
    968     }
    969 
    970     /* Save the control parameters */ /* coverity[unchecked_value] */ /* Do not check return value internal function calls */
    971     LVM_GetControlParameters(hInstance, &Params);
    972 
    973     /*  Retrieve allocated buffers in memtab */
    974     LVM_GetMemoryTable(hInstance, &MemTab,  LVM_NULL);
    975 
    976     /*  Save the instance parameters */
    977     InstParams = pInstance->InstParams;
    978 
    979     /*  Call  LVM_GetInstanceHandle to re-initialise the bundle */
    980     LVM_GetInstanceHandle( &hInstance,
    981                            &MemTab,
    982                            &InstParams);
    983 
    984     /* Restore control parameters */ /* coverity[unchecked_value] */ /* Do not check return value internal function calls */
    985     LVM_SetControlParameters(hInstance, &Params);
    986 
    987     /* DC removal filter */
    988     DC_2I_D16_TRC_WRA_01_Init(&pInstance->DC_RemovalInstance);
    989 
    990 
    991     return LVM_SUCCESS;
    992 }
    993 
    994 
    995 
    996