• 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 /************************************************************************************/
19 /*                                                                                  */
20 /*    Includes                                                                      */
21 /*                                                                                  */
22 /************************************************************************************/
23 
24 #include "LVEQNB.h"
25 #include "LVEQNB_Coeffs.h"
26 #include "LVEQNB_Tables.h"
27 
28 /************************************************************************************/
29 /*                                                                                  */
30 /*    Sample rate table                                                             */
31 /*                                                                                  */
32 /************************************************************************************/
33 
34 /*
35  * Sample rate table for converting between the enumerated type and the actual
36  * frequency
37  */
38 const LVM_UINT32 LVEQNB_SampleRateTab[] = {8000, /* 8kS/s  */
39                                            11025, 12000, 16000, 22050, 24000,  32000,
40                                            44100, 48000, 88200, 96000, 176400, 192000};
41 
42 /************************************************************************************/
43 /*                                                                                  */
44 /*    Coefficient calculation tables                                                */
45 /*                                                                                  */
46 /************************************************************************************/
47 
48 /*
49  * Table for 2 * Pi / Fs
50  */
51 const LVM_FLOAT LVEQNB_TwoPiOnFsTable[] = {
52         LVEQNB_2PiOn_8000, /* 8kS/s */
53         LVEQNB_2PiOn_11025, LVEQNB_2PiOn_12000, LVEQNB_2PiOn_16000,  LVEQNB_2PiOn_22050,
54         LVEQNB_2PiOn_24000, LVEQNB_2PiOn_32000, LVEQNB_2PiOn_44100,  LVEQNB_2PiOn_48000,
55         LVEQNB_2PiOn_88200, LVEQNB_2PiOn_96000, LVEQNB_2PiOn_176400, LVEQNB_2PiOn_192000};
56 
57 /*
58  * Gain table
59  */
60 const LVM_FLOAT LVEQNB_GainTable[] = {
61         LVEQNB_Gain_Neg15_dB, /* -15dB gain */
62         LVEQNB_Gain_Neg14_dB, LVEQNB_Gain_Neg13_dB, LVEQNB_Gain_Neg12_dB, LVEQNB_Gain_Neg11_dB,
63         LVEQNB_Gain_Neg10_dB, LVEQNB_Gain_Neg9_dB,  LVEQNB_Gain_Neg8_dB,  LVEQNB_Gain_Neg7_dB,
64         LVEQNB_Gain_Neg6_dB,  LVEQNB_Gain_Neg5_dB,  LVEQNB_Gain_Neg4_dB,  LVEQNB_Gain_Neg3_dB,
65         LVEQNB_Gain_Neg2_dB,  LVEQNB_Gain_Neg1_dB,  LVEQNB_Gain_0_dB, /* 0dB gain */
66         LVEQNB_Gain_1_dB,     LVEQNB_Gain_2_dB,     LVEQNB_Gain_3_dB,     LVEQNB_Gain_4_dB,
67         LVEQNB_Gain_5_dB,     LVEQNB_Gain_6_dB,     LVEQNB_Gain_7_dB,     LVEQNB_Gain_8_dB,
68         LVEQNB_Gain_9_dB,     LVEQNB_Gain_10_dB,    LVEQNB_Gain_11_dB,    LVEQNB_Gain_12_dB,
69         LVEQNB_Gain_13_dB,    LVEQNB_Gain_14_dB,    LVEQNB_Gain_15_dB}; /* +15dB gain */
70 /*
71  * D table for 100 / (Gain + 1)
72  */
73 const LVM_FLOAT LVEQNB_DTable[] = {
74         LVEQNB_100D_Neg15_dB, /* -15dB gain */
75         LVEQNB_100D_Neg14_dB, LVEQNB_100D_Neg13_dB, LVEQNB_100D_Neg12_dB, LVEQNB_100D_Neg11_dB,
76         LVEQNB_100D_Neg10_dB, LVEQNB_100D_Neg9_dB,  LVEQNB_100D_Neg8_dB,  LVEQNB_100D_Neg7_dB,
77         LVEQNB_100D_Neg6_dB,  LVEQNB_100D_Neg5_dB,  LVEQNB_100D_Neg4_dB,  LVEQNB_100D_Neg3_dB,
78         LVEQNB_100D_Neg2_dB,  LVEQNB_100D_Neg1_dB,  LVEQNB_100D_0_dB}; /* 0dB gain */
79 /************************************************************************************/
80 /*                                                                                  */
81 /*    Filter polynomial coefficients                                                */
82 /*                                                                                  */
83 /************************************************************************************/
84 
85 /*
86  * Coefficients for calculating the cosine with the equation:
87  *
88  *  Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5)
89  *
90  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
91  * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range
92  * +1.0 to -1.0
93  */
94 const LVM_INT16 LVEQNB_CosCoef[] = {3,      /* Shifts */
95                                     4096,   /* a0 */
96                                     -36,    /* a1 */
97                                     -19725, /* a2 */
98                                     -2671,  /* a3 */
99                                     23730,  /* a4 */
100                                     -9490}; /* a5 */
101 
102 /*
103  * Coefficients for calculating the cosine error with the equation:
104  *
105  *  CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3)
106  *
107  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
108  * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range
109  * 0.0 to 0.0078852986
110  *
111  * This is used to give a double precision cosine over the range 0 to Pi/25 using the
112  * the equation:
113  *
114  * Cos(x) = 1.0 - CosErr(x)
115  */
116 const LVM_INT16 LVEQNB_DPCosCoef[] = {1,     /* Shifts */
117                                       0,     /* a0 */
118                                       -6,    /* a1 */
119                                       16586, /* a2 */
120                                       -44};  /* a3 */
121