LVCS_Control.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_GetParameters */ 39/* */ 40/* DESCRIPTION: */ 41/* Request the Concert Sound parameters. The current parameter set is returned */ 42/* via the parameter pointer. */ 43/* */ 44/* PARAMETERS: */ 45/* hInstance Instance handle */ 46/* pParams Pointer to an empty parameter structure */ 47/* */ 48/* RETURNS: */ 49/* LVCS_Success Always succeeds */ 50/* */ 51/* NOTES: */ 52/* 1. This function may be interrupted by the LVCS_Process function */ 53/* */ 54/************************************************************************************/ 55 56LVCS_ReturnStatus_en LVCS_GetParameters(LVCS_Handle_t hInstance, 57 LVCS_Params_t *pParams) 58{ 59 60 LVCS_Instance_t *pInstance =(LVCS_Instance_t *)hInstance; 61 62 *pParams = pInstance->Params; 63 64 return(LVCS_SUCCESS); 65} 66 67 68/************************************************************************************/ 69/* */ 70/* FUNCTION: LVCS_Control */ 71/* */ 72/* DESCRIPTION: */ 73/* Sets or changes the Concert Sound parameters. */ 74/* */ 75/* PARAMETERS: */ 76/* hInstance Instance handle */ 77/* pParams Pointer to a parameter structure */ 78/* */ 79/* RETURNS: */ 80/* LVCS_Success Succeeded */ 81/* */ 82/* NOTES: */ 83/* 1. This function must not be interrupted by the LVCS_Process function */ 84/* */ 85/************************************************************************************/ 86 87LVCS_ReturnStatus_en LVCS_Control(LVCS_Handle_t hInstance, 88 LVCS_Params_t *pParams) 89{ 90 LVM_INT16 Offset; 91 LVCS_Instance_t *pInstance =(LVCS_Instance_t *)hInstance; 92 LVCS_ReturnStatus_en err; 93 LVCS_Modes_en OperatingModeSave = pInstance->Params.OperatingMode; 94 95 if (pParams->SampleRate != pInstance->Params.SampleRate) 96 { 97 pInstance->TimerParams.SamplingRate = LVCS_SampleRateTable[pParams->SampleRate]; 98 } 99 100 /* 101 * If the reverb level has changed 102 */ 103 if(pInstance->Params.ReverbLevel != pParams->ReverbLevel) 104 { 105 err=LVCS_ReverbGeneratorInit(hInstance,pParams); 106 } 107 108 /* 109 * If the sample rate or speaker has changed then perform a full re-initialisation 110 */ 111 if ((pInstance->Params.SampleRate != pParams->SampleRate) || 112 (pInstance->Params.SpeakerType != pParams->SpeakerType)) 113 { 114 const LVCS_VolCorrect_t *pLVCS_VolCorrectTable; 115 116 /* 117 * Output device 118 */ 119 pInstance->OutputDevice = LVCS_HEADPHONE; 120 121 /* 122 * Get the volume correction parameters 123 */ 124 /* Use internal coefficient table */ 125 pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0]; 126 Offset = (LVM_INT16)(pParams->SpeakerType + pParams->SourceFormat*(1+LVCS_EX_HEADPHONES)); 127 128 pInstance->VolCorrect = pLVCS_VolCorrectTable[Offset]; 129 130 LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[0],0,0); 131 132 133 { 134 LVM_UINT32 Gain; 135 const Gain_t *pOutputGainTable = (Gain_t*)&LVCS_OutputGainTable[0]; 136 Gain = (LVM_UINT32)(pOutputGainTable[Offset].Loss * LVM_MAXINT_16); 137 Gain = (LVM_UINT32)pOutputGainTable[Offset].UnprocLoss * (Gain >> 15); 138 Gain=Gain>>15; 139 /* 140 * Apply the gain correction and shift, note the result is in Q3.13 format 141 */ 142 Gain = (Gain * pInstance->VolCorrect.GainMin) >>12; 143 144 LVC_Mixer_Init(&pInstance->BypassMix.Mixer_Instance.MixerStream[1],0,Gain); 145 LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->BypassMix.Mixer_Instance.MixerStream[0], 146 LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); 147 LVC_Mixer_VarSlope_SetTimeConstant(&pInstance->BypassMix.Mixer_Instance.MixerStream[1], 148 LVCS_BYPASS_MIXER_TC,pParams->SampleRate,2); 149 150 } 151 152 153 err=LVCS_SEnhancerInit(hInstance, 154 pParams); 155 156 err=LVCS_ReverbGeneratorInit(hInstance, 157 pParams); 158 159 err=LVCS_EqualiserInit(hInstance, 160 pParams); 161 162 err=LVCS_BypassMixInit(hInstance, 163 pParams); 164 165 } 166 167 168 /* 169 * Check if the effect level or source format has changed 170 */ 171 else if ((pInstance->Params.EffectLevel != pParams->EffectLevel) || 172 (pInstance->Params.SourceFormat != pParams->SourceFormat)) 173 { 174 const LVCS_VolCorrect_t *pLVCS_VolCorrectTable; 175 176 /* 177 * Get the volume correction parameters 178 */ 179 /* Use internal coefficient table */ 180 pLVCS_VolCorrectTable = (LVCS_VolCorrect_t*)&LVCS_VolCorrectTable[0]; 181 Offset = (LVM_INT16)(pParams->SpeakerType + pParams->SourceFormat*(1+LVCS_EX_HEADPHONES)); 182 183 pInstance->VolCorrect = pLVCS_VolCorrectTable[Offset]; 184 185 /* Update the effect level and alpha-mixer gains */ 186 err=LVCS_BypassMixInit(hInstance, 187 pParams); 188 189 if(err != LVCS_SUCCESS) 190 { 191 return err; 192 } 193 } 194 else 195 { 196 pInstance->Params = *pParams; 197 } 198 199 /* 200 * Update the instance parameters 201 */ 202 pInstance->Params = *pParams; 203 204 /* Stay on the current operating mode until the transition is done */ 205 if((pParams->OperatingMode != OperatingModeSave) || 206 (pInstance->bInOperatingModeTransition == LVM_TRUE)){ 207 208 /* Set the reverb delay timeout */ 209 if(pInstance->bInOperatingModeTransition != LVM_TRUE){ 210 pInstance->bTimerDone = LVM_FALSE; 211 pInstance->TimerParams.TimeInMs = (LVM_INT16)(((pInstance->Reverberation.DelaySize << 2)/pInstance->TimerParams.SamplingRate) + 1); 212 LVM_Timer_Init ( &pInstance->TimerInstance, 213 &pInstance->TimerParams); 214 } 215 216 /* Update the effect level and alpha-mixer gains */ 217 err=LVCS_BypassMixInit(hInstance, 218 pParams); 219 220 /* Change transition bypass mixer settings if needed depending on transition type */ 221 if(pParams->OperatingMode != LVCS_OFF){ 222 pInstance->MSTarget0=LVM_MAXINT_16; 223 pInstance->MSTarget1=0; 224 } 225 else 226 { 227 pInstance->Params.OperatingMode = OperatingModeSave; 228 pInstance->MSTarget1=LVM_MAXINT_16; 229 pInstance->MSTarget0=0; 230 } 231 232 233 /* Set transition flag */ 234 pInstance->bInOperatingModeTransition = LVM_TRUE; 235 } 236 237 return(LVCS_SUCCESS); 238} 239 240/****************************************************************************************/ 241/* */ 242/* FUNCTION: LVCS_TimerCallBack */ 243/* */ 244/* DESCRIPTION: */ 245/* CallBack function of the Timer. */ 246/* */ 247/****************************************************************************************/ 248void LVCS_TimerCallBack (void* hInstance, void* pCallBackParams, LVM_INT32 CallbackParam) 249{ 250 LVCS_Instance_t *pInstance = (LVCS_Instance_t *)hInstance; 251 252 /* Avoid warnings because pCallBackParams and CallbackParam are not used*/ 253 if((pCallBackParams != LVM_NULL) || (CallbackParam != 0)){ 254 pCallBackParams = hInstance; 255 CallbackParam = 0; 256 return; 257 } 258 259 pInstance->bTimerDone = LVM_TRUE; 260 261 262 return; 263} 264 265