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 /*  Includes                                                                            */
21 /*                                                                                      */
22 /****************************************************************************************/
23 #include "LVREV.h"
24 
25 /****************************************************************************************/
26 /*                                                                                      */
27 /*  Tables                                                                              */
28 /*                                                                                      */
29 /****************************************************************************************/
30 
31 /* Table with supported sampling rates.  The table can be indexed using LVM_Fs_en       */
32 #ifndef HIGHER_FS
33 const LVM_UINT16 LVM_FsTable[] = {
34     8000 ,
35     11025,
36     12000,
37     16000,
38     22050,
39     24000,
40     32000,
41     44100,
42     48000
43 };
44 #else
45 const LVM_UINT32 LVM_FsTable[] = {
46     8000 ,
47     11025,
48     12000,
49     16000,
50     22050,
51     24000,
52     32000,
53     44100,
54     48000,
55     88200,
56     96000,
57     176400,
58     192000
59 };
60 #endif
61 /* Table with supported sampling rates.  The table can be indexed using LVM_Fs_en       */
62 #ifndef HIGHER_FS
LVM_GetFsFromTable(LVM_Fs_en FsIndex)63 LVM_UINT16 LVM_GetFsFromTable(LVM_Fs_en FsIndex){
64     if (FsIndex > LVM_FS_48000)
65         return 0;
66 
67     return (LVM_FsTable[FsIndex]);
68 }
69 #else
LVM_GetFsFromTable(LVM_Fs_en FsIndex)70 LVM_UINT32 LVM_GetFsFromTable(LVM_Fs_en FsIndex){
71     if (FsIndex > LVM_FS_192000)
72         return 0;
73 
74     return (LVM_FsTable[FsIndex]);
75 }
76 #endif
77 
78 /* In order to maintain consistant input and out put signal strengths
79    output gain/attenuation is applied. This gain depends on T60 and Rooms
80    size parameters. These polynomial coefficients are calculated experimentally.
81    First value in the table is room size
82    second value is  A0
83    third value is   A1
84    fourth value is  A2
85    fifth value is   A3
86    sixth value is   A4
87 
88      shift value  is to be added array (to use LVM_Polynomial function)
89 
90   The gain is calculated using variable x=(T60*32767/7000)*32768;
91 
92    first values is used to get polynomial set for given room size,
93    For room sizes which are not in the table, linear interpolation can be used.
94 
95   */
96 
97 /* Normalizing output including Reverb Level part (only shift up)*/
98 #ifndef BUILD_FLOAT
99 const LVM_INT32 LVREV_GainPolyTable[24][5]={{1,17547434,128867434,-120988896,50761228,},
100                                             {2,18256869,172666902,-193169292,88345744,},
101                                             {3,16591311,139250151,-149667234,66770059,},
102                                             {4,17379977,170835131,-173579321,76278163,},
103                                             {5,18963512,210364934,-228623519,103435022,},
104                                             {6,17796318,135756417,-144084053,64327698,},
105                                             {7,17454695,174593214,-187513064,85146582,},
106                                             {8,17229257,140715570,-145790588,65361740,},
107                                             {9,17000547,163195946,-176733969,79562130,},
108                                             {10,16711699,142476304,-133339887,58366547,},
109                                             {13,18108419,149223697,-161762020,74397589,},
110                                             {15,16682043,124844884,-134284487,60082180,},
111                                             {17,16627346,120936430,-121766674,53146421,},
112                                             {20,17338325,125432694,-126616983,56534237,},
113                                             {25,16489146,99218217,-94597467,40616506,},
114                                             {30,15582373,84479043,-75365006,30952348,},
115                                             {40,16000669,84896611,-75031127,30696306,},
116                                             {50,15087054,71695031,-59349268,23279669,},
117                                             {60,15830714,68672971,-58211201,23671158,},
118                                             {70,15536061,66657972,-55901437,22560153,},
119                                             {75,15013145,48179917,-24138354,5232074,},
120                                             {80,15688738,50195036,-34206760,11515792,},
121                                             {90,16003322,48323661,-35607378,13153872,},
122                                             {100,15955223,48558201,-33706865,11715792,},
123                                             };
124 #else
125 const LVM_FLOAT LVREV_GainPolyTable[24][5]={{1,1.045909f,7.681098f,-7.211500f,3.025605f,},
126                                             {2,1.088194f,10.291749f,-11.513787f,5.265817f,},
127                                             {3,0.988919f,8.299956f,-8.920862f,3.979806f,},
128                                             {4,1.035927f,10.182567f,-10.346134f,4.546533f,},
129                                             {5,1.130313f,12.538727f,-13.627023f,6.165208f,},
130                                             {6,1.060743f,8.091713f,-8.588079f,3.834230f,},
131                                             {7,1.040381f,10.406566f,-11.176650f,5.075132f,},
132                                             {8,1.026944f,8.387302f,-8.689796f,3.895863f,},
133                                             {9,1.013312f,9.727236f,-10.534165f,4.742272f,},
134                                             {10,0.996095f,8.492249f,-7.947677f,3.478917f,},
135                                             {13,1.079346f,8.894425f,-9.641768f,4.434442f,},
136                                             {15,0.994327f,7.441335f,-8.003979f,3.581177f,},
137                                             {17,0.991067f,7.208373f,-7.257859f,3.167774f,},
138                                             {20,1.033445f,7.476371f,-7.546960f,3.369703f,},
139                                             {25,0.982830f,5.913867f,-5.638448f,2.420932f,},
140                                             {30,0.928782f,5.035343f,-4.492104f,1.844904f,},
141                                             {40,0.953714f,5.060232f,-4.472204f,1.829642f,},
142                                             {50,0.899258f,4.273357f,-3.537492f,1.387576f,},
143                                             {60,0.943584f,4.093228f,-3.469658f,1.410911f,},
144                                             {70,0.926021f,3.973125f,-3.331985f,1.344690f,},
145                                             {75,0.894853f,2.871747f,-1.438758f,0.311856f,},
146                                             {80,0.935122f,2.991857f,-2.038882f,0.686395f,},
147                                             {90,0.953872f,2.880315f,-2.122365f,0.784032f,},
148                                             {100,0.951005f,2.894294f,-2.009086f,0.698316f,},
149 };
150 #endif
151 /* End of file */
152 
153