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
LVC_Mixer_SetTimeConstant(LVMixer3_st * pStream,LVM_INT32 Tc_millisec,LVM_Fs_en Fs,LVM_INT16 NumChannels)48 void LVC_Mixer_SetTimeConstant(LVMixer3_st *pStream,
49 LVM_INT32 Tc_millisec,
50 LVM_Fs_en Fs,
51 LVM_INT16 NumChannels)
52 {
53 LVM_INT32 DeltaTable[9]={1073741824,
54 779132389,
55 715827882,
56 536870912,
57 389566194,
58 357913941,
59 268435456,
60 194783097,
61 178956971};
62 Mix_Private_st *pInstance=(Mix_Private_st *)pStream->PrivateParams;
63 LVM_INT32 Delta=DeltaTable[Fs];
64 Delta=Delta>>(NumChannels-1);
65
66 if(Tc_millisec==0)
67 Delta=0x7FFFFFFF;
68 else
69 Delta=Delta/Tc_millisec;
70
71 if(Delta==0)
72 Delta=1; // If Time Constant is so large that Delta is 0, assign minimum value to Delta
73
74 pInstance->Delta=Delta; // Delta=(2147483647*4*1000)/(NumChannels*SampleRate*Tc_millisec) in Q 0.31 format
75 }
76