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