• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_Init                                                      */
25 /*                                                                      */
26 /* DESCRIPTION:                                                         */
27 /*  This intialization function intializes the private instance         */
28 /*  paramters for a given Audio Stream based on TargetGain and          */
29 /*  CurrentGain                                                         */
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 for an*/
39 /*                Audio Stream                                          */
40 /*  TargetGain  - TargetGain value in Q 16.15 format                    */
41 /*  CurrentGain - CurrentGain value in Q 16.15 format                   */
42 /*                                                                      */
43 /* RETURNS:                                                             */
44 /*  void                                                                */
45 /*                                                                      */
46 /************************************************************************/
47 #ifdef BUILD_FLOAT
LVC_Mixer_Init(LVMixer3_FLOAT_st * pStream,LVM_FLOAT TargetGain,LVM_FLOAT CurrentGain)48 void LVC_Mixer_Init( LVMixer3_FLOAT_st *pStream,
49                      LVM_FLOAT           TargetGain,
50                      LVM_FLOAT           CurrentGain)
51 {
52     LVM_FLOAT MaxGain = TargetGain;
53     Mix_Private_FLOAT_st *pInstance = (Mix_Private_FLOAT_st *)pStream->PrivateParams;
54     if(CurrentGain > MaxGain)
55         MaxGain = CurrentGain;
56     pInstance->Target = TargetGain;   // Update fractional gain Target
57     pInstance->Current = CurrentGain; // Update fractional gain Current
58 }
59 #else
LVC_Mixer_Init(LVMixer3_st * pStream,LVM_INT32 TargetGain,LVM_INT32 CurrentGain)60 void LVC_Mixer_Init( LVMixer3_st *pStream,
61                     LVM_INT32           TargetGain,
62                     LVM_INT32           CurrentGain)
63 {
64     LVM_INT16       Shift=0;
65     LVM_INT32       MaxGain=TargetGain;         // MaxGain is in Q16.15 format
66     Mix_Private_st  *pInstance=(Mix_Private_st *)pStream->PrivateParams;
67     if(CurrentGain>MaxGain)
68         MaxGain=CurrentGain;                    // MaxGain=max(CurrentGain,TargetGain)
69 
70     MaxGain=MaxGain>>15;                        // MaxGain in Q31.0 format i.e Integer part only
71     while(MaxGain>0){                           // Update Shift required to provide integer gain
72         Shift++;
73         MaxGain=MaxGain>>1;
74     }
75     pInstance->Target=TargetGain<<(16-Shift);   // Update fractional gain Target
76     pInstance->Current=CurrentGain<<(16-Shift); // Update fractional gain Current
77     pInstance->Shift=Shift;                     // Update Shift
78 }
79 #endif
80