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 #include "LVM_Types.h"
19 #include "LVM_Macros.h"
20 #include "LVC_Mixer_Private.h"
21 
22 /************************************************************************/
23 /* FUNCTION:                                                            */
24 /*   LVMixer3_SetTarget                                                 */
25 /*                                                                      */
26 /* DESCRIPTION:                                                         */
27 /*  This function updates the private instance parameters: Shift,Target,*/
28 /*  Current for a given Audio Stream based on new value of TargetGain   */
29 /*                                                                      */
30 /*  This function caclulates the "Shift" required to provide the        */
31 /*  integer part of TargetGain and fractional gain values "Target" and  */
32 /*  "Current" based on maximum(TargetGain,CurrentGain)                  */
33 /*  E.g. CurrentGain=1.9 and TargetGain=2.5 then based on               */
34 /*  MaxGain of 2.5, Shift = 2, Current=1.9/4=0.475, Target=2.5/4=0.625  */
35 /*  Therefore integer gain of 4 is provided by Left Shift of 2 and      */
36 /*  fraction gain is provided through Current=0.475 and Target=0.625    */
37 /* PARAMETERS:                                                          */
38 /*  pStream         - ptr to Instance Parameter Structure LVMixer3_st   */
39 /*                    for an Audio Stream                               */
40 /*  TargetGain      - TargetGain value in Q 16.15 format                */
41 /*                                                                      */
42 /* RETURNS:                                                             */
43 /*  void                                                                */
44 /*                                                                      */
45 /************************************************************************/
LVC_Mixer_SetTarget(LVMixer3_FLOAT_st * pStream,LVM_FLOAT TargetGain)46 void LVC_Mixer_SetTarget(LVMixer3_FLOAT_st *pStream,
47                          LVM_FLOAT         TargetGain)
48 {
49     Mix_Private_FLOAT_st *pInstance = (Mix_Private_FLOAT_st *)pStream->PrivateParams;
50     pInstance->Target = TargetGain;               // Update gain Target
51 }
52