• 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_SetTimeConstant                                           */
25 /*                                                                      */
26 /* DESCRIPTION:                                                         */
27 /*  This function calculates the step change for fractional gain for a  */
28 /*  given time constant, sample rate and num channels                   */
29 /*  Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec)      */
30 /*  in Q 0.31 format                                                    */
31 /*                                                                      */
32 /* PARAMETERS:                                                          */
33 /*  pStream     - ptr to Instance Parameter Structure LVMixer3_st for an*/
34 /*                Audio Stream                                          */
35 /*  Tc_millisec - TimeConstant i.e time required in milli second to     */
36 /*                go from linear fractional gain of 0 to 0.99999999     */
37 /*  Fs          - LVM_Fs_en enumerator for Sampling Frequency           */
38 /*  NumChannels - Number of channels in Audio Stream 1=Mono, 2=Stereo   */
39 /*                                                                      */
40 /* UPDATES:                                                             */
41 /*  Delta       - the step change for fractional gain per 4 samples     */
42 /*                in Q0.31 format for a given Time Constant,            */
43 /*                Sample Rate and NumChannels                           */
44 /* RETURNS:                                                             */
45 /*  void                                                                */
46 /************************************************************************/
47 #ifdef BUILD_FLOAT
LVC_Mixer_SetTimeConstant(LVMixer3_FLOAT_st * pStream,LVM_INT32 Tc_millisec,LVM_Fs_en Fs,LVM_INT16 NumChannels)48 void LVC_Mixer_SetTimeConstant(LVMixer3_FLOAT_st *pStream,
49                                LVM_INT32           Tc_millisec,
50                                LVM_Fs_en           Fs,
51                                LVM_INT16           NumChannels)
52 {
53 #ifdef HIGHER_FS
54     LVM_FLOAT   DeltaTable[11] = {0.500000f,/*8000*/
55                                   0.362812f,/*11025*/
56                                   0.333333f,/*12000*/
57                                   0.250000f,/*16000*/
58                                   0.181406f,/*22050*/
59                                   0.166666f,/*24000*/
60                                   0.125000f,/*32000*/
61                                   0.090703f,/*44100*/
62                                   0.083333f,/*48000*/
63                                   0.041667f,/*96000*/
64                                   0.020833f};/*192000*/
65 #else
66     LVM_FLOAT   DeltaTable[9] = {0.500000f,/*8000*/
67                                  0.362812f,/*11025*/
68                                  0.333333f,/*12000*/
69                                  0.250000f,/*16000*/
70                                  0.181406f,/*22050*/
71                                  0.166666f,/*24000*/
72                                  0.125000f,/*32000*/
73                                  0.090703f,/*44100*/
74                                  0.083333f};/*48000*/
75 #endif
76 
77     Mix_Private_FLOAT_st *pInstance = (Mix_Private_FLOAT_st *)pStream->PrivateParams;
78     LVM_FLOAT Delta = DeltaTable[Fs];
79     Delta = Delta / (NumChannels);
80 
81     if(Tc_millisec == 0)
82         Delta = 1.000000f;
83     else
84         Delta = Delta / Tc_millisec;
85 
86     if(Delta == 0)
87         Delta = 0.0000000005f;  /* If Time Constant is so large that Delta is 0, \
88                                   assign minimum value to Delta */
89     pInstance->Delta = Delta;  // Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec)
90 }
91 #else
LVC_Mixer_SetTimeConstant(LVMixer3_st * pStream,LVM_INT32 Tc_millisec,LVM_Fs_en Fs,LVM_INT16 NumChannels)92 void LVC_Mixer_SetTimeConstant(LVMixer3_st *pStream,
93                             LVM_INT32           Tc_millisec,
94                             LVM_Fs_en           Fs,
95                             LVM_INT16           NumChannels)
96 {
97     LVM_INT32   DeltaTable[9]={1073741824,
98                                779132389,
99                                715827882,
100                                536870912,
101                                389566194,
102                                357913941,
103                                268435456,
104                                194783097,
105                                178956971};
106     Mix_Private_st  *pInstance=(Mix_Private_st *)pStream->PrivateParams;
107     LVM_INT32   Delta=DeltaTable[Fs];
108     Delta=Delta>>(NumChannels-1);
109 
110     if(Tc_millisec==0)
111         Delta=0x7FFFFFFF;
112     else
113         Delta=Delta/Tc_millisec;
114 
115     if(Delta==0)
116         Delta=1;                // If Time Constant is so large that Delta is 0, assign minimum value to Delta
117 
118     pInstance->Delta=Delta;     // Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec) in Q 0.31 format
119 }
120 #endif
121