Tizen 2.0 Release
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / qua_gain_tbl.cpp
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 /*
30
31  Filename: qua_gain_tbl.cpp
32
33 ------------------------------------------------------------------------------
34  MODULE DESCRIPTION
35
36 ------------------------------------------------------------------------------
37 */
38
39 /*----------------------------------------------------------------------------
40 ; INCLUDES
41 ----------------------------------------------------------------------------*/
42 #include "qua_gain_tbl.h"
43 #include "qua_gain.h"
44
45 /*--------------------------------------------------------------------------*/
46 #ifdef __cplusplus
47 extern "C"
48 {
49 #endif
50
51     /*----------------------------------------------------------------------------
52     ; MACROS
53     ; [Define module specific macros here]
54     ----------------------------------------------------------------------------*/
55
56     /*----------------------------------------------------------------------------
57     ; DEFINES
58     ; [Include all pre-processor statements here. Include conditional
59     ; compile variables also.]
60     ----------------------------------------------------------------------------*/
61
62     /*----------------------------------------------------------------------------
63     ; LOCAL FUNCTION DEFINITIONS
64     ; [List function prototypes here]
65     ----------------------------------------------------------------------------*/
66
67     /*----------------------------------------------------------------------------
68     ; LOCAL VARIABLE DEFINITIONS
69     ; [Variable declaration - defined here and used outside this module]
70     ----------------------------------------------------------------------------*/
71
72     /* The tables contains the following data:
73      *
74      *    g_pitch        (Q14),
75      *    g_fac          (Q12), (g_code = g_code0*g_fac),
76      *    qua_ener_MR122 (Q10), (log2(g_fac))
77      *    qua_ener       (Q10)  (20*log10(g_fac))
78      *
79      *    The log2() and log10() values are calculated on the fixed point value
80      *    (g_fac Q12) and not on the original floating point value of g_fac
81      *    to make the quantizer/MA predictdor use corresponding values.
82      */
83
84     /* table used in 'high' rates: MR67 MR74 */
85
86     const Word16 table_gain_highrates[VQ_SIZE_HIGHRATES*4] =
87     {
88
89         /*
90          * Note: column 4 (qua_ener) contains the original values from IS641
91          *       to ensure bit-exactness; however, they are not exactly the
92          *       rounded value of (20*log10(g_fac))
93          *
94          */
95
96         /*g_pit,    g_fac,  qua_ener_MR122, qua_ener */
97         577,      662,           -2692,   -16214,
98         806,     1836,           -1185,    -7135,
99         3109,     1052,           -2008,   -12086,
100         4181,     1387,           -1600,    -9629,
101         2373,     1425,           -1560,    -9394,
102         3248,     1985,           -1070,    -6442,
103         1827,     2320,            -840,    -5056,
104         941,     3314,            -313,    -1885,
105         2351,     2977,            -471,    -2838,
106         3616,     2420,            -777,    -4681,
107         3451,     3096,            -414,    -2490,
108         2955,     4301,              72,      434,
109         1848,     4500,             139,      836,
110         3884,     5416,             413,     2484,
111         1187,     7210,             835,     5030,
112         3083,     9000,            1163,     7002,
113         7384,      883,           -2267,   -13647,
114         5962,     1506,           -1478,    -8900,
115         5155,     2134,            -963,    -5800,
116         7944,     2009,           -1052,    -6335,
117         6507,     2250,            -885,    -5327,
118         7670,     2752,            -588,    -3537,
119         5952,     3016,            -452,    -2724,
120         4898,     3764,            -125,     -751,
121         6989,     3588,            -196,    -1177,
122         8174,     3978,             -43,     -260,
123         6064,     4404,             107,      645,
124         7709,     5087,             320,     1928,
125         5523,     6021,             569,     3426,
126         7769,     7126,             818,     4926,
127         6060,     7938,             977,     5885,
128         5594,    11487,            1523,     9172,
129         10581,     1356,           -1633,    -9831,
130         9049,     1597,           -1391,    -8380,
131         9794,     2035,           -1033,    -6220,
132         8946,     2415,            -780,    -4700,
133         10296,     2584,            -681,    -4099,
134         9407,     2734,            -597,    -3595,
135         8700,     3218,            -356,    -2144,
136         9757,     3395,            -277,    -1669,
137         10177,     3892,             -75,     -454,
138         9170,     4528,             148,      891,
139         10152,     5004,             296,     1781,
140         9114,     5735,             497,     2993,
141         10500,     6266,             628,     3782,
142         10110,     7631,             919,     5534,
143         8844,     8727,            1117,     6728,
144         8956,    12496,            1648,     9921,
145         12924,      976,           -2119,   -12753,
146         11435,     1755,           -1252,    -7539,
147         12138,     2328,            -835,    -5024,
148         11388,     2368,            -810,    -4872,
149         10700,     3064,            -429,    -2580,
150         12332,     2861,            -530,    -3192,
151         11722,     3327,            -307,    -1848,
152         11270,     3700,            -150,     -904,
153         10861,     4413,             110,      663,
154         12082,     4533,             150,      902,
155         11283,     5205,             354,     2132,
156         11960,     6305,             637,     3837,
157         11167,     7534,             900,     5420,
158         12128,     8329,            1049,     6312,
159         10969,    10777,            1429,     8604,
160         10300,    17376,            2135,    12853,
161         13899,     1681,           -1316,    -7921,
162         12580,     2045,           -1026,    -6179,
163         13265,     2439,            -766,    -4610,
164         14033,     2989,            -465,    -2802,
165         13452,     3098,            -413,    -2482,
166         12396,     3658,            -167,    -1006,
167         13510,     3780,            -119,     -713,
168         12880,     4272,              62,      374,
169         13533,     4861,             253,     1523,
170         12667,     5457,             424,     2552,
171         13854,     6106,             590,     3551,
172         13031,     6483,             678,     4084,
173         13557,     7721,             937,     5639,
174         12957,     9311,            1213,     7304,
175         13714,    11551,            1532,     9221,
176         12591,    15206,            1938,    11667,
177         15113,     1540,           -1445,    -8700,
178         15072,     2333,            -832,    -5007,
179         14527,     2511,            -723,    -4352,
180         14692,     3199,            -365,    -2197,
181         15382,     3560,            -207,    -1247,
182         14133,     3960,             -50,     -300,
183         15102,     4236,              50,      298,
184         14332,     4824,             242,     1454,
185         14846,     5451,             422,     2542,
186         15306,     6083,             584,     3518,
187         14329,     6888,             768,     4623,
188         15060,     7689,             930,     5602,
189         14406,     9426,            1231,     7413,
190         15387,     9741,            1280,     7706,
191         14824,    14271,            1844,    11102,
192         13600,    24939,            2669,    16067,
193         16396,     1969,           -1082,    -6517,
194         16817,     2832,            -545,    -3283,
195         15713,     2843,            -539,    -3248,
196         16104,     3336,            -303,    -1825,
197         16384,     3963,             -49,     -294,
198         16940,     4579,             165,      992,
199         15711,     4599,             171,     1030,
200         16222,     5448,             421,     2537,
201         16832,     6382,             655,     3945,
202         15745,     7141,             821,     4944,
203         16326,     7469,             888,     5343,
204         16611,     8624,            1100,     6622,
205         17028,    10418,            1379,     8303,
206         15905,    11817,            1565,     9423,
207         16878,    14690,            1887,    11360,
208         16515,    20870,            2406,    14483,
209         18142,     2083,            -999,    -6013,
210         19401,     3178,            -375,    -2257,
211         17508,     3426,            -264,    -1589,
212         20054,     4027,             -25,     -151,
213         18069,     4249,              54,      326,
214         18952,     5066,             314,     1890,
215         17711,     5402,             409,     2461,
216         19835,     6192,             610,     3676,
217         17950,     7014,             795,     4784,
218         21318,     7877,             966,     5816,
219         17910,     9289,            1210,     7283,
220         19144,     9290,            1210,     7284,
221         20517,    11381,            1510,     9089,
222         18075,    14485,            1866,    11234,
223         19999,    17882,            2177,    13108,
224         18842,    32764,            3072,    18494
225     };
226
227
228     /* table used in 'low' rates: MR475, MR515, MR59 */
229
230     const Word16 table_gain_lowrates[VQ_SIZE_LOWRATES*4] =
231     {
232         /*g_pit,    g_fac,  qua_ener_MR122, qua_ener */
233         10813,    28753,            2879,    17333,
234         20480,     2785,            -570,    -3431,
235         18841,     6594,             703,     4235,
236         6225,     7413,             876,     5276,
237         17203,    10444,            1383,     8325,
238         21626,     1269,           -1731,   -10422,
239         21135,     4423,             113,      683,
240         11304,     1556,           -1430,    -8609,
241         19005,    12820,            1686,    10148,
242         17367,     2498,            -731,    -4398,
243         17858,     4833,             244,     1472,
244         9994,     2498,            -731,    -4398,
245         17530,     7864,             964,     5802,
246         14254,     1884,           -1147,    -6907,
247         15892,     3153,            -387,    -2327,
248         6717,     1802,           -1213,    -7303,
249         18186,    20193,            2357,    14189,
250         18022,     3031,            -445,    -2678,
251         16711,     5857,             528,     3181,
252         8847,     4014,             -30,     -180,
253         15892,     8970,            1158,     6972,
254         18022,     1392,           -1594,    -9599,
255         16711,     4096,               0,        0,
256         8192,      655,           -2708,   -16305,
257         15237,    13926,            1808,    10884,
258         14254,     3112,            -406,    -2444,
259         14090,     4669,             193,     1165,
260         5406,     2703,            -614,    -3697,
261         13434,     6553,             694,     4180,
262         12451,      901,           -2237,   -13468,
263         12451,     2662,            -637,    -3833,
264         3768,      655,           -2708,   -16305,
265         14745,    23511,            2582,    15543,
266         19169,     2457,            -755,    -4546,
267         20152,     5079,             318,     1913,
268         6881,     4096,               0,        0,
269         20480,     8560,            1089,     6556,
270         19660,      737,           -2534,   -15255,
271         19005,     4259,              58,      347,
272         7864,     2088,            -995,    -5993,
273         11468,    12288,            1623,     9771,
274         15892,     1474,           -1510,    -9090,
275         15728,     4628,             180,     1086,
276         9175,     1433,           -1552,    -9341,
277         16056,     7004,             793,     4772,
278         14827,      737,           -2534,   -15255,
279         15073,     2252,            -884,    -5321,
280         5079,     1228,           -1780,   -10714,
281         13271,    17326,            2131,    12827,
282         16547,     2334,            -831,    -5002,
283         15073,     5816,             518,     3118,
284         3932,     3686,            -156,     -938,
285         14254,     8601,            1096,     6598,
286         16875,      778,           -2454,   -14774,
287         15073,     3809,            -107,     -646,
288         6062,      614,           -2804,   -16879,
289         9338,     9256,            1204,     7251,
290         13271,     1761,           -1247,    -7508,
291         13271,     3522,            -223,    -1343,
292         2457,     1966,           -1084,    -6529,
293         11468,     5529,             443,     2668,
294         10485,      737,           -2534,   -15255,
295         11632,     3194,            -367,    -2212,
296         1474,      778,           -2454,   -14774
297     };
298
299     /*--------------------------------------------------------------------------*/
300 #ifdef __cplusplus
301 }
302 #endif
303
304 /*
305 ------------------------------------------------------------------------------
306  FUNCTION NAME:
307 ------------------------------------------------------------------------------
308  INPUT AND OUTPUT DEFINITIONS
309
310  Inputs:
311     None
312
313  Outputs:
314     None
315
316  Returns:
317     None
318
319  Global Variables Used:
320     None
321
322  Local Variables Needed:
323     None
324
325 ------------------------------------------------------------------------------
326  FUNCTION DESCRIPTION
327
328  None
329
330 ------------------------------------------------------------------------------
331  REQUIREMENTS
332
333  None
334
335 ------------------------------------------------------------------------------
336  REFERENCES
337
338  [1] qua_gain.tab,  UMTS GSM AMR speech codec,
339                     R99 - Version 3.2.0, March 2, 2001
340
341 ------------------------------------------------------------------------------
342  PSEUDO-CODE
343
344
345 ------------------------------------------------------------------------------
346  CAUTION [optional]
347  [State any special notes, constraints or cautions for users of this function]
348
349 ------------------------------------------------------------------------------
350 */
351
352 /*----------------------------------------------------------------------------
353 ; FUNCTION CODE
354 ----------------------------------------------------------------------------*/
355
356
357
358
359
360
361