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 "LVCS.h"
     25 #include "LVCS_Private.h"
     26 #include "LVCS_Tables.h"
     27 
     28 /****************************************************************************************/
     29 /*                                                                                      */
     30 /* FUNCTION:                LVCS_Memory                                                 */
     31 /*                                                                                      */
     32 /* DESCRIPTION:                                                                         */
     33 /*  This function is used for memory allocation and free. It can be called in           */
     34 /*  two ways:                                                                           */
     35 /*                                                                                      */
     36 /*      hInstance = NULL                Returns the memory requirements                 */
     37 /*      hInstance = Instance handle     Returns the memory requirements and             */
     38 /*                                      allocated base addresses for the instance       */
     39 /*                                                                                      */
     40 /*  When this function is called for memory allocation (hInstance=NULL) it is           */
     41 /*  passed the default capabilities.                                                    */
     42 /*                                                                                      */
     43 /*  When called for memory allocation the memory base address pointers are NULL on      */
     44 /*  return.                                                                             */
     45 /*                                                                                      */
     46 /*  When the function is called for free (hInstance = Instance Handle) the              */
     47 /*  capabilities are ignored and the memory table returns the allocated memory and      */
     48 /*  base addresses used during initialisation.                                          */
     49 /*                                                                                      */
     50 /* PARAMETERS:                                                                          */
     51 /*  hInstance               Instance Handle                                             */
     52 /*  pMemoryTable            Pointer to an empty memory definition table                 */
     53 /*  pCapabilities           Pointer to the default capabilites                          */
     54 /*                                                                                      */
     55 /* RETURNS:                                                                             */
     56 /*  LVCS_Success            Succeeded                                                   */
     57 /*                                                                                      */
     58 /* NOTES:                                                                               */
     59 /*  1.  This function may be interrupted by the LVCS_Process function                   */
     60 /*                                                                                      */
     61 /****************************************************************************************/
     62 
     63 LVCS_ReturnStatus_en LVCS_Memory(LVCS_Handle_t          hInstance,
     64                                  LVCS_MemTab_t          *pMemoryTable,
     65                                  LVCS_Capabilities_t    *pCapabilities)
     66 {
     67 
     68     LVM_UINT32          ScratchSize;
     69     LVCS_Instance_t     *pInstance = (LVCS_Instance_t *)hInstance;
     70 
     71 
     72     /*
     73      * Fill in the memory table
     74      */
     75     if (hInstance == LVM_NULL)
     76     {
     77         /*
     78          * Instance memory
     79          */
     80         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].Size         = (LVM_UINT32)sizeof(LVCS_Instance_t);
     81         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].Type         = LVCS_PERSISTENT;
     82         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress = LVM_NULL;
     83 
     84         /*
     85          * Data memory
     86          */
     87         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Size         = (LVM_UINT32)sizeof(LVCS_Data_t);
     88         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].Type         = LVCS_DATA;
     89         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_DATA].pBaseAddress = LVM_NULL;
     90 
     91         /*
     92          * Coefficient memory
     93          */
     94         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Size         = (LVM_UINT32)sizeof(LVCS_Coefficient_t);
     95         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].Type         = LVCS_COEFFICIENT;
     96         pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_FAST_COEF].pBaseAddress = LVM_NULL;
     97 
     98         /*
     99          * Scratch memory
    100          */
    101         ScratchSize = (LVM_UINT32)(LVCS_SCRATCHBUFFERS*sizeof(LVM_INT16)*pCapabilities->MaxBlockSize);     /* Inplace processing */
    102         pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].Size         = ScratchSize;
    103         pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].Type         = LVCS_SCRATCH;
    104         pMemoryTable->Region[LVCS_MEMREGION_TEMPORARY_FAST].pBaseAddress = LVM_NULL;
    105     }
    106     else
    107     {
    108         /* Read back memory allocation table */
    109         *pMemoryTable = pInstance->MemoryTable;
    110     }
    111 
    112     return(LVCS_SUCCESS);
    113 }
    114 
    115 
    116 /************************************************************************************/
    117 /*                                                                                  */
    118 /* FUNCTION:                LVCS_Init                                               */
    119 /*                                                                                  */
    120 /* DESCRIPTION:                                                                     */
    121 /*  Create and initialisation function for the Concert Sound module                 */
    122 /*                                                                                  */
    123 /*  This function can be used to create an algorithm instance by calling with       */
    124 /*  hInstance set to LVM_NULL. In this case the algorithm returns the new instance  */
    125 /*  handle.                                                                         */
    126 /*                                                                                  */
    127 /*  This function can be used to force a full re-initialisation of the algorithm    */
    128 /*  by calling with hInstance = Instance Handle. In this case the memory table      */
    129 /*  should be correct for the instance, this can be ensured by calling the function */
    130 /*  LVCS_Memory before calling this function.                                       */
    131 /*                                                                                  */
    132 /* PARAMETERS:                                                                      */
    133 /*  hInstance               Instance handle                                         */
    134 /*  pMemoryTable            Pointer to the memory definition table                  */
    135 /*  pCapabilities           Pointer to the capabilities structure                   */
    136 /*                                                                                  */
    137 /* RETURNS:                                                                         */
    138 /*  LVCS_Success            Initialisation succeeded                                */
    139 /*                                                                                  */
    140 /* NOTES:                                                                           */
    141 /*  1.  The instance handle is the pointer to the base address of the first memory  */
    142 /*      region.                                                                     */
    143 /*  2.  This function must not be interrupted by the LVCS_Process function          */
    144 /*  3.  This function must be called with the same capabilities as used for the     */
    145 /*      call to the memory function                                                 */
    146 /*                                                                                  */
    147 /************************************************************************************/
    148 
    149 LVCS_ReturnStatus_en LVCS_Init(LVCS_Handle_t         *phInstance,
    150                                LVCS_MemTab_t         *pMemoryTable,
    151                                LVCS_Capabilities_t   *pCapabilities)
    152 {
    153 
    154     LVCS_Instance_t                 *pInstance;
    155     LVCS_VolCorrect_t               *pLVCS_VolCorrectTable;
    156 
    157 
    158     /*
    159      * Set the instance handle if not already initialised
    160      */
    161     if (*phInstance == LVM_NULL)
    162     {
    163         *phInstance = (LVCS_Handle_t)pMemoryTable->Region[LVCS_MEMREGION_PERSISTENT_SLOW_DATA].pBaseAddress;
    164     }
    165     pInstance =(LVCS_Instance_t  *)*phInstance;
    166 
    167 
    168     /*
    169      * Save the capabilities in the instance structure
    170      */
    171     pInstance->Capabilities = *pCapabilities;
    172 
    173     /*
    174      * Save the memory table in the instance structure
    175      */
    176     pInstance->MemoryTable = *pMemoryTable;
    177 
    178 
    179     /*
    180      * Set all initial parameters to invalid to force a full initialisation
    181      */
    182     pInstance->Params.OperatingMode  = LVCS_OFF;
    183     pInstance->Params.SpeakerType    = LVCS_SPEAKERTYPE_MAX;
    184     pInstance->OutputDevice          = LVCS_HEADPHONE;
    185     pInstance->Params.SourceFormat   = LVCS_SOURCEMAX;
    186     pInstance->Params.CompressorMode = LVM_MODE_OFF;
    187     pInstance->Params.SampleRate     = LVM_FS_INVALID;
    188     pInstance->Params.EffectLevel    = 0;
    189     pInstance->Params.ReverbLevel    = (LVM_UINT16)0x8000;
    190     pLVCS_VolCorrectTable            = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0];
    191     pInstance->VolCorrect            = pLVCS_VolCorrectTable[0];
    192     pInstance->TransitionGain        = 0;
    193     /* These current and target values are intialized again in LVCS_Control.c */
    194     LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[0],0,0);
    195     /* These current and target values are intialized again in LVCS_Control.c */
    196     LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[1],0,0);
    197 
    198     /*
    199      * Initialise the bypass variables
    200      */
    201     pInstance->MSTarget0=0;
    202     pInstance->MSTarget1=0;
    203     pInstance->bInOperatingModeTransition          = LVM_FALSE;
    204     pInstance->bTimerDone                        = LVM_FALSE;
    205     pInstance->TimerParams.CallBackParam         = 0;
    206     pInstance->TimerParams.pCallBack             = LVCS_TimerCallBack;
    207     pInstance->TimerParams.pCallbackInstance     = pInstance;
    208     pInstance->TimerParams.pCallBackParams       = LVM_NULL;
    209 
    210     return(LVCS_SUCCESS);
    211 }
    212 
    213