1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: qgain475.cpp
35 Funtions: MR475_quant_store_results
39 ------------------------------------------------------------------------------
42 These modules handle the quantization of pitch and codebook gains for MR475.
44 ------------------------------------------------------------------------------
48 /*----------------------------------------------------------------------------
50 ----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
61 ; Define module specific macros here
62 ----------------------------------------------------------------------------*/
65 /*----------------------------------------------------------------------------
67 ; Include all pre-processor statements here. Include conditional
68 ; compile variables also.
69 ----------------------------------------------------------------------------*/
70 #define MR475_VQ_SIZE 256
72 /*----------------------------------------------------------------------------
73 ; LOCAL FUNCTION DEFINITIONS
74 ; Function Prototype declaration
75 ----------------------------------------------------------------------------*/
77 /*----------------------------------------------------------------------------
78 ; LOCAL VARIABLE DEFINITIONS
79 ; Variable declaration - defined here and used outside this module
80 ----------------------------------------------------------------------------*/
82 /* The table contains the following data:
84 * g_pitch(0) (Q14) // for sub-
85 * g_fac(0) (Q12) // frame 0 and 2
86 * g_pitch(1) (Q14) // for sub-
87 * g_fac(2) (Q12) // frame 1 and 3
90 static const Word16 table_gain_MR475[MR475_VQ_SIZE*4] =
92 /*g_pit(0), g_fac(0), g_pit(1), g_fac(1) */
94 2873, 1135, 2266, 3402,
95 2067, 563, 12677, 647,
96 4132, 1798, 5601, 5285,
98 10912, 2638, 11807, 2494,
99 20490, 797, 5218, 675,
100 6724, 8354, 5282, 1696,
101 1488, 428, 5882, 452,
102 5332, 4072, 3583, 1268,
103 2469, 901, 15894, 1005,
104 14982, 3271, 10331, 4858,
105 3635, 2021, 2596, 835,
106 12360, 4892, 12206, 1704,
107 13432, 1604, 9118, 2341,
108 3968, 1538, 5479, 9936,
109 3795, 417, 1359, 414,
110 3640, 1569, 7995, 3541,
111 11405, 645, 8552, 635,
112 4056, 1377, 16608, 6124,
113 11420, 700, 2007, 607,
114 12415, 1578, 11119, 4654,
115 13680, 1708, 11990, 1229,
116 7996, 7297, 13231, 5715,
117 2428, 1159, 2073, 1941,
118 6218, 6121, 3546, 1804,
119 8925, 1802, 8679, 1580,
120 13935, 3576, 13313, 6237,
121 6142, 1130, 5994, 1734,
122 14141, 4662, 11271, 3321,
123 12226, 1551, 13931, 3015,
124 5081, 10464, 9444, 6706,
125 1689, 683, 1436, 1306,
126 7212, 3933, 4082, 2713,
127 7793, 704, 15070, 802,
128 6299, 5212, 4337, 5357,
129 6676, 541, 6062, 626,
130 13651, 3700, 11498, 2408,
131 16156, 716, 12177, 751,
132 8065, 11489, 6314, 2256,
133 4466, 496, 7293, 523,
134 10213, 3833, 8394, 3037,
135 8403, 966, 14228, 1880,
136 8703, 5409, 16395, 4863,
137 7420, 1979, 6089, 1230,
138 9371, 4398, 14558, 3363,
139 13559, 2873, 13163, 1465,
140 5534, 1678, 13138, 14771,
141 7338, 600, 1318, 548,
142 4252, 3539, 10044, 2364,
143 10587, 622, 13088, 669,
144 14126, 3526, 5039, 9784,
145 15338, 619, 3115, 590,
146 16442, 3013, 15542, 4168,
147 15537, 1611, 15405, 1228,
148 16023, 9299, 7534, 4976,
149 1990, 1213, 11447, 1157,
150 12512, 5519, 9475, 2644,
151 7716, 2034, 13280, 2239,
152 16011, 5093, 8066, 6761,
153 10083, 1413, 5002, 2347,
154 12523, 5975, 15126, 2899,
155 18264, 2289, 15827, 2527,
156 16265, 10254, 14651, 11319,
157 1797, 337, 3115, 397,
158 3510, 2928, 4592, 2670,
159 7519, 628, 11415, 656,
160 5946, 2435, 6544, 7367,
161 8238, 829, 4000, 863,
162 10032, 2492, 16057, 3551,
163 18204, 1054, 6103, 1454,
164 5884, 7900, 18752, 3468,
165 1864, 544, 9198, 683,
166 11623, 4160, 4594, 1644,
167 3158, 1157, 15953, 2560,
168 12349, 3733, 17420, 5260,
169 6106, 2004, 2917, 1742,
170 16467, 5257, 16787, 1680,
171 17205, 1759, 4773, 3231,
172 7386, 6035, 14342, 10012,
173 4035, 442, 4194, 458,
174 9214, 2242, 7427, 4217,
175 12860, 801, 11186, 825,
176 12648, 2084, 12956, 6554,
177 9505, 996, 6629, 985,
178 10537, 2502, 15289, 5006,
179 12602, 2055, 15484, 1653,
180 16194, 6921, 14231, 5790,
181 2626, 828, 5615, 1686,
182 13663, 5778, 3668, 1554,
183 11313, 2633, 9770, 1459,
184 14003, 4733, 15897, 6291,
185 6278, 1870, 7910, 2285,
186 16978, 4571, 16576, 3849,
187 15248, 2311, 16023, 3244,
188 14459, 17808, 11847, 2763,
189 1981, 1407, 1400, 876,
190 4335, 3547, 4391, 4210,
191 5405, 680, 17461, 781,
192 6501, 5118, 8091, 7677,
193 7355, 794, 8333, 1182,
194 15041, 3160, 14928, 3039,
195 20421, 880, 14545, 852,
196 12337, 14708, 6904, 1920,
197 4225, 933, 8218, 1087,
198 10659, 4084, 10082, 4533,
199 2735, 840, 20657, 1081,
200 16711, 5966, 15873, 4578,
201 10871, 2574, 3773, 1166,
202 14519, 4044, 20699, 2627,
203 15219, 2734, 15274, 2186,
204 6257, 3226, 13125, 19480,
205 7196, 930, 2462, 1618,
206 4515, 3092, 13852, 4277,
207 10460, 833, 17339, 810,
208 16891, 2289, 15546, 8217,
209 13603, 1684, 3197, 1834,
210 15948, 2820, 15812, 5327,
211 17006, 2438, 16788, 1326,
212 15671, 8156, 11726, 8556,
213 3762, 2053, 9563, 1317,
214 13561, 6790, 12227, 1936,
215 8180, 3550, 13287, 1778,
216 16299, 6599, 16291, 7758,
217 8521, 2551, 7225, 2645,
218 18269, 7489, 16885, 2248,
219 17882, 2884, 17265, 3328,
220 9417, 20162, 11042, 8320,
221 1286, 620, 1431, 583,
222 5993, 2289, 3978, 3626,
223 5144, 752, 13409, 830,
224 5553, 2860, 11764, 5908,
225 10737, 560, 5446, 564,
226 13321, 3008, 11946, 3683,
227 19887, 798, 9825, 728,
228 13663, 8748, 7391, 3053,
229 2515, 778, 6050, 833,
230 6469, 5074, 8305, 2463,
231 6141, 1865, 15308, 1262,
232 14408, 4547, 13663, 4515,
233 3137, 2983, 2479, 1259,
234 15088, 4647, 15382, 2607,
235 14492, 2392, 12462, 2537,
236 7539, 2949, 12909, 12060,
237 5468, 684, 3141, 722,
238 5081, 1274, 12732, 4200,
239 15302, 681, 7819, 592,
240 6534, 2021, 16478, 8737,
241 13364, 882, 5397, 899,
242 14656, 2178, 14741, 4227,
243 14270, 1298, 13929, 2029,
244 15477, 7482, 15815, 4572,
245 2521, 2013, 5062, 1804,
246 5159, 6582, 7130, 3597,
247 10920, 1611, 11729, 1708,
248 16903, 3455, 16268, 6640,
249 9306, 1007, 9369, 2106,
250 19182, 5037, 12441, 4269,
251 15919, 1332, 15357, 3512,
252 11898, 14141, 16101, 6854,
253 2010, 737, 3779, 861,
254 11454, 2880, 3564, 3540,
255 9057, 1241, 12391, 896,
256 8546, 4629, 11561, 5776,
257 8129, 589, 8218, 588,
258 18728, 3755, 12973, 3149,
259 15729, 758, 16634, 754,
260 15222, 11138, 15871, 2208,
261 4673, 610, 10218, 678,
262 15257, 4146, 5729, 3327,
263 8377, 1670, 19862, 2321,
264 15450, 5511, 14054, 5481,
265 5728, 2888, 7580, 1346,
266 14384, 5325, 16236, 3950,
267 15118, 3744, 15306, 1435,
268 14597, 4070, 12301, 15696,
269 7617, 1699, 2170, 884,
270 4459, 4567, 18094, 3306,
271 12742, 815, 14926, 907,
272 15016, 4281, 15518, 8368,
273 17994, 1087, 2358, 865,
274 16281, 3787, 15679, 4596,
275 16356, 1534, 16584, 2210,
276 16833, 9697, 15929, 4513,
277 3277, 1085, 9643, 2187,
278 11973, 6068, 9199, 4462,
279 8955, 1629, 10289, 3062,
280 16481, 5155, 15466, 7066,
281 13678, 2543, 5273, 2277,
282 16746, 6213, 16655, 3408,
283 20304, 3363, 18688, 1985,
284 14172, 12867, 15154, 15703,
285 4473, 1020, 1681, 886,
286 4311, 4301, 8952, 3657,
287 5893, 1147, 11647, 1452,
288 15886, 2227, 4582, 6644,
289 6929, 1205, 6220, 799,
290 12415, 3409, 15968, 3877,
291 19859, 2109, 9689, 2141,
292 14742, 8830, 14480, 2599,
293 1817, 1238, 7771, 813,
294 19079, 4410, 5554, 2064,
295 3687, 2844, 17435, 2256,
296 16697, 4486, 16199, 5388,
297 8028, 2763, 3405, 2119,
298 17426, 5477, 13698, 2786,
299 19879, 2720, 9098, 3880,
300 18172, 4833, 17336, 12207,
301 5116, 996, 4935, 988,
302 9888, 3081, 6014, 5371,
303 15881, 1667, 8405, 1183,
304 15087, 2366, 19777, 7002,
305 11963, 1562, 7279, 1128,
306 16859, 1532, 15762, 5381,
307 14708, 2065, 20105, 2155,
308 17158, 8245, 17911, 6318,
309 5467, 1504, 4100, 2574,
310 17421, 6810, 5673, 2888,
311 16636, 3382, 8975, 1831,
312 20159, 4737, 19550, 7294,
313 6658, 2781, 11472, 3321,
314 19397, 5054, 18878, 4722,
315 16439, 2373, 20430, 4386,
316 11353, 26526, 11593, 3068,
317 2866, 1566, 5108, 1070,
318 9614, 4915, 4939, 3536,
319 7541, 878, 20717, 851,
320 6938, 4395, 16799, 7733,
321 10137, 1019, 9845, 964,
322 15494, 3955, 15459, 3430,
323 18863, 982, 20120, 963,
324 16876, 12887, 14334, 4200,
325 6599, 1220, 9222, 814,
326 16942, 5134, 5661, 4898,
327 5488, 1798, 20258, 3962,
328 17005, 6178, 17929, 5929,
329 9365, 3420, 7474, 1971,
330 19537, 5177, 19003, 3006,
331 16454, 3788, 16070, 2367,
332 8664, 2743, 9445, 26358,
333 10856, 1287, 3555, 1009,
334 5606, 3622, 19453, 5512,
335 12453, 797, 20634, 911,
336 15427, 3066, 17037, 10275,
337 18883, 2633, 3913, 1268,
338 19519, 3371, 18052, 5230,
339 19291, 1678, 19508, 3172,
340 18072, 10754, 16625, 6845,
341 3134, 2298, 10869, 2437,
342 15580, 6913, 12597, 3381,
343 11116, 3297, 16762, 2424,
344 18853, 6715, 17171, 9887,
345 12743, 2605, 8937, 3140,
346 19033, 7764, 18347, 3880,
347 20475, 3682, 19602, 3380,
348 13044, 19373, 10526, 23124
352 ------------------------------------------------------------------------------
353 FUNCTION NAME: MR475_quant_store_results
354 ------------------------------------------------------------------------------
355 INPUT AND OUTPUT DEFINITIONS
358 pred_st = pointer to structure of type gc_predState
359 p = pointer to selected quantizer table entry (const Word16)
360 gcode0 = predicted CB gain (Word16)
361 exp_gcode0 = exponent of predicted CB gain (Word16)
362 gain_pit = pointer to Pitch gain (Word16)
363 gain_cod = pointer to Code gain (Word16)
366 pred_st points to the updated structure of type gc_predState
367 gain_pit points to Pitch gain
368 gain_cod points to Code gain
369 pOverflow points to overflow indicator (Flag)
374 Global Variables Used:
377 Local Variables Needed:
380 ------------------------------------------------------------------------------
383 This function calculates the final fixed codebook gain and the predictor
384 update values, and updates the gain predictor.
386 ------------------------------------------------------------------------------
391 ------------------------------------------------------------------------------
394 qgain475.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
396 ------------------------------------------------------------------------------
399 static void MR475_quant_store_results(
401 gc_predState *pred_st, // i/o: gain predictor state struct
402 const Word16 *p, // i : pointer to selected quantizer table entry
403 Word16 gcode0, // i : predicted CB gain, Q(14 - exp_gcode0)
404 Word16 exp_gcode0, // i : exponent of predicted CB gain, Q0
405 Word16 *gain_pit, // o : Pitch gain, Q14
406 Word16 *gain_cod // o : Code gain, Q1
410 Word16 g_code, exp, frac, tmp;
413 Word16 qua_ener_MR122; // o : quantized energy error, MR122 version Q10
414 Word16 qua_ener; // o : quantized energy error, Q10
416 // Read the quantized gains
420 //------------------------------------------------------------------*
421 * calculate final fixed codebook gain: *
422 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
425 *------------------------------------------------------------------
427 L_tmp = L_mult(g_code, gcode0);
428 L_tmp = L_shr(L_tmp, sub(10, exp_gcode0));
429 *gain_cod = extract_h(L_tmp);
431 //------------------------------------------------------------------*
432 * calculate predictor update values and update gain predictor: *
433 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
435 * qua_ener = log2(g) *
436 * qua_ener_MR122 = 20*log10(g) *
437 *------------------------------------------------------------------
439 Log2 (L_deposit_l (g_code), &exp, &frac); // Log2(x Q12) = log2(x) + 12
442 tmp = shr_r (frac, 5);
443 qua_ener_MR122 = add (tmp, shl (exp, 10));
445 L_tmp = Mpy_32_16(exp, frac, 24660); // 24660 Q12 ~= 6.0206 = 20*log10(2)
446 qua_ener = pv_round (L_shl (L_tmp, 13)); // Q12 * Q0 = Q13 -> Q10
448 gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
451 ------------------------------------------------------------------------------
453 [State any special notes, constraints or cautions for users of this function]
455 ------------------------------------------------------------------------------
458 static void MR475_quant_store_results(
459 gc_predState *pred_st, /* i/o: gain predictor state struct */
460 const Word16 *p, /* i : pointer to selected quantizer table entry */
461 Word16 gcode0, /* i : predicted CB gain, Q(14 - exp_gcode0) */
462 Word16 exp_gcode0, /* i : exponent of predicted CB gain, Q0 */
463 Word16 *gain_pit, /* o : Pitch gain, Q14 */
464 Word16 *gain_cod, /* o : Code gain, Q1 */
465 Flag *pOverflow /* o : overflow indicator */
474 Word16 qua_ener_MR122; /* o : quantized energy error, MR122 version Q10 */
475 Word16 qua_ener; /* o : quantized energy error, Q10 */
478 /* Read the quantized gains */
482 /*------------------------------------------------------------------*
483 * calculate final fixed codebook gain: *
484 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
487 *------------------------------------------------------------------*/
489 L_tmp = ((Word32) g_code * gcode0) << 1;
490 tmp = 10 - exp_gcode0;
491 L_tmp = L_shr(L_tmp, tmp, pOverflow);
492 *gain_cod = (Word16)(L_tmp >> 16);
494 /*------------------------------------------------------------------*
495 * calculate predictor update values and update gain predictor: *
496 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
498 * qua_ener = log2(g) *
499 * qua_ener_MR122 = 20*log10(g) *
500 *------------------------------------------------------------------*/
502 /* Log2(x Q12) = log2(x) + 12 */
503 Log2((Word32) g_code, &exp, &frac, pOverflow);
506 tmp = shr_r(frac, 5, pOverflow);
507 qua_ener_MR122 = exp << 10;
508 qua_ener_MR122 = tmp + qua_ener_MR122;
510 /* 24660 Q12 ~= 6.0206 = 20*log10(2) */
511 L_tmp = Mpy_32_16(exp, frac, 24660, pOverflow);
514 /* Q12 * Q0 = Q13 -> Q10 */
515 qua_ener = (Word16)((L_tmp + (Word32) 0x00008000L) >> 16);
517 gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
522 /****************************************************************************/
526 ------------------------------------------------------------------------------
527 FUNCTION NAME: MR475_update_unq_pred
528 ------------------------------------------------------------------------------
529 INPUT AND OUTPUT DEFINITIONS
532 pred_st = pointer to structure of type gc_predState
533 exp_gcode0 = predicted CB gain (exponent MSW) (Word16)
534 frac_gcode0 = predicted CB gain (exponent LSW) (Word16)
535 cod_gain_exp = optimum codebook gain (exponent)(Word16)
536 cod_gain_frac = optimum codebook gain (fraction) (Word16)
539 pred_st points to the updated structure of type gc_predState
540 pOverflow points to overflow indicator (Flag)
545 Global Variables Used:
548 Local Variables Needed:
551 ------------------------------------------------------------------------------
554 This module uses the optimum codebook gain and updates the "unquantized"
555 gain predictor with the (bounded) prediction error.
557 ------------------------------------------------------------------------------
562 ------------------------------------------------------------------------------
565 qgain475.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
567 ------------------------------------------------------------------------------
571 MR475_update_unq_pred(
572 gc_predState *pred_st, // i/o: gain predictor state struct
573 Word16 exp_gcode0, // i : predicted CB gain (exponent MSW), Q0
574 Word16 frac_gcode0, // i : predicted CB gain (exponent LSW), Q15
575 Word16 cod_gain_exp, // i : optimum codebook gain (exponent), Q0
576 Word16 cod_gain_frac // i : optimum codebook gain (fraction), Q15
579 Word16 tmp, exp, frac;
580 Word16 qua_ener, qua_ener_MR122;
583 // calculate prediction error factor (given optimum CB gain gcu):
584 // predErrFact = gcu / gcode0
585 // (limit to MIN_PRED_ERR_FACT <= predErrFact <= MAX_PRED_ERR_FACT
586 // -> limit qua_ener*)
588 // calculate prediction error (log):
590 // qua_ener_MR122 = log2(predErrFact)
591 // qua_ener = 20*log10(predErrFact)
593 if (cod_gain_frac <= 0)
595 // if gcu <= 0 -> predErrFact = 0 < MIN_PRED_ERR_FACT
596 // -> set qua_ener(_MR122) directly
597 qua_ener = MIN_QUA_ENER;
598 qua_ener_MR122 = MIN_QUA_ENER_MR122;
602 // convert gcode0 from DPF to standard fraction/exponent format
603 // with normalized frac, i.e. 16384 <= frac <= 32767
604 // Note: exponent correction (exp=exp-14) is done after div_s
605 frac_gcode0 = extract_l (Pow2 (14, frac_gcode0));
607 // make sure cod_gain_frac < frac_gcode0 for div_s
608 if (sub(cod_gain_frac, frac_gcode0) >= 0)
610 cod_gain_frac = shr (cod_gain_frac, 1);
611 cod_gain_exp = add (cod_gain_exp, 1);
616 // = cod_gain_frac/frac_gcode0 * 2^(cod_gain_exp-(exp_gcode0-14))
617 // = div_s (c_g_f, frac_gcode0)*2^-15 * 2^(c_g_e-exp_gcode0+14)
618 // = div_s * 2^(cod_gain_exp-exp_gcode0 - 1)
620 frac = div_s (cod_gain_frac, frac_gcode0);
621 tmp = sub (sub (cod_gain_exp, exp_gcode0), 1);
623 Log2 (L_deposit_l (frac), &exp, &frac);
624 exp = add (exp, tmp);
626 // calculate prediction error (log2, Q10)
627 qua_ener_MR122 = shr_r (frac, 5);
628 qua_ener_MR122 = add (qua_ener_MR122, shl (exp, 10));
630 if (sub(qua_ener_MR122, MIN_QUA_ENER_MR122) < 0)
632 qua_ener = MIN_QUA_ENER;
633 qua_ener_MR122 = MIN_QUA_ENER_MR122;
635 else if (sub(qua_ener_MR122, MAX_QUA_ENER_MR122) > 0)
637 qua_ener = MAX_QUA_ENER;
638 qua_ener_MR122 = MAX_QUA_ENER_MR122;
642 // calculate prediction error (20*log10, Q10)
643 L_tmp = Mpy_32_16(exp, frac, 24660);
644 // 24660 Q12 ~= 6.0206 = 20*log10(2)
645 qua_ener = pv_round (L_shl (L_tmp, 13));
646 // Q12 * Q0 = Q13 -> Q26 -> Q10
650 // update MA predictor memory
651 gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
654 ------------------------------------------------------------------------------
656 [State any special notes, constraints or cautions for users of this function]
658 ------------------------------------------------------------------------------
661 void MR475_update_unq_pred(
662 gc_predState *pred_st, /* i/o: gain predictor state struct */
663 Word16 exp_gcode0, /* i : predicted CB gain (exponent MSW), Q0 */
664 Word16 frac_gcode0, /* i : predicted CB gain (exponent LSW), Q15 */
665 Word16 cod_gain_exp, /* i : optimum codebook gain (exponent), Q0 */
666 Word16 cod_gain_frac, /* i : optimum codebook gain (fraction), Q15 */
667 Flag *pOverflow /* o : overflow indicator */
674 Word16 qua_ener_MR122;
677 /* calculate prediction error factor (given optimum CB gain gcu):
679 * predErrFact = gcu / gcode0
680 * (limit to MIN_PRED_ERR_FACT <= predErrFact <= MAX_PRED_ERR_FACT
681 * -> limit qua_ener*)
683 * calculate prediction error (log):
685 * qua_ener_MR122 = log2(predErrFact)
686 * qua_ener = 20*log10(predErrFact)
690 if (cod_gain_frac <= 0)
692 /* if gcu <= 0 -> predErrFact = 0 < MIN_PRED_ERR_FACT */
693 /* -> set qua_ener(_MR122) directly */
694 qua_ener = MIN_QUA_ENER;
695 qua_ener_MR122 = MIN_QUA_ENER_MR122;
699 /* convert gcode0 from DPF to standard fraction/exponent format */
700 /* with normalized frac, i.e. 16384 <= frac <= 32767 */
701 /* Note: exponent correction (exp=exp-14) is done after div_s */
702 frac_gcode0 = (Word16)(Pow2(14, frac_gcode0, pOverflow));
704 /* make sure cod_gain_frac < frac_gcode0 for div_s */
705 if (cod_gain_frac >= frac_gcode0)
714 = cod_gain_frac/frac_gcode0 * 2^(cod_gain_exp-(exp_gcode0-14))
715 = div_s (c_g_f, frac_gcode0)*2^-15 * 2^(c_g_e-exp_gcode0+14)
716 = div_s * 2^(cod_gain_exp-exp_gcode0 - 1)
718 frac = div_s(cod_gain_frac, frac_gcode0);
719 tmp = cod_gain_exp - exp_gcode0;
722 Log2((Word32) frac, &exp, &frac, pOverflow);
725 /* calculate prediction error (log2, Q10) */
726 qua_ener_MR122 = shr_r(frac, 5, pOverflow);
728 qua_ener_MR122 += tmp;
730 if (qua_ener_MR122 > MAX_QUA_ENER_MR122)
732 qua_ener = MAX_QUA_ENER;
733 qua_ener_MR122 = MAX_QUA_ENER_MR122;
737 /* calculate prediction error (20*log10, Q10) */
738 L_tmp = Mpy_32_16(exp, frac, 24660, pOverflow);
739 /* 24660 Q12 ~= 6.0206 = 20*log10(2) */
740 L_tmp = L_shl(L_tmp, 13, pOverflow);
741 qua_ener = pv_round(L_tmp, pOverflow);
743 /* Q12 * Q0 = Q13 -> Q26 -> Q10 */
747 /* update MA predictor memory */
748 gc_pred_update(pred_st, qua_ener_MR122, qua_ener);
754 /****************************************************************************/
758 ------------------------------------------------------------------------------
759 FUNCTION NAME: MR475_gain_quant
760 ------------------------------------------------------------------------------
761 INPUT AND OUTPUT DEFINITIONS
764 pred_st = pointer to structure of type gc_predState
765 sf0_exp_gcode0 = predicted CB gain (exponent) (Word16)
766 f0_frac_gcode0 = predicted CB gain (fraction) (Word16)
767 sf0_exp_coeff = energy coeff. (exponent part) (Word16)
768 sf0_frac_coeff = energy coeff. ((fraction part) (Word16)
769 sf0_exp_target_en = exponent of target energy (Word16)
770 sf0_frac_target_en = fraction of target energy (Word16)
771 sf1_code_nosharp = innovative codebook vector (Word16)
772 sf1_exp_gcode0 = predicted CB gain (exponent) (Word16)
773 sf1_frac_gcode0 = predicted CB gain (fraction) (Word16)
774 sf1_exp_coeff = energy coeff. (exponent part) (Word16)
775 sf1_frac_coeff = energy coeff. (fraction part) (Word16)
776 sf1_exp_target_en = exponent of target energy (Word16)
777 sf1_frac_target_en = fraction of target energy (Word16)
778 gp_limit = pitch gain limit (Word16)
779 sf0_gain_pit = pointer to Pitch gain (Word16)
780 sf0_gain_cod = pointer to Code gain (Word16)
781 sf1_gain_pit = pointer to Pitch gain (Word16)
782 sf1_gain_cod = pointer to Code gain (Word16)
785 pred_st points to the updated structure of type gc_predState
786 sf0_gain_pit points to Pitch gain
787 sf0_gain_cod points to Code gain
788 sf1_gain_pit points to Pitch gain
789 sf1_gain_cod points to Code gain
792 index = index of quantization
794 Global Variables Used:
797 Local Variables Needed:
800 ------------------------------------------------------------------------------
803 This module provides quantization of pitch and codebook gains for two
804 subframes using the predicted codebook gain.
806 ------------------------------------------------------------------------------
811 ------------------------------------------------------------------------------
814 qgain475.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
816 ------------------------------------------------------------------------------
820 MR475_gain_quant( // o : index of quantization.
821 gc_predState *pred_st, // i/o: gain predictor state struct
823 // data from subframe 0 (or 2)
824 Word16 sf0_exp_gcode0, // i : predicted CB gain (exponent), Q0
825 Word16 sf0_frac_gcode0, // i : predicted CB gain (fraction), Q15
826 Word16 sf0_exp_coeff[], // i : energy coeff. (5), exponent part, Q0
827 Word16 sf0_frac_coeff[], // i : energy coeff. (5), fraction part, Q15
828 // (frac_coeff and exp_coeff computed in
829 // calc_filt_energies())
830 Word16 sf0_exp_target_en, // i : exponent of target energy, Q0
831 Word16 sf0_frac_target_en, // i : fraction of target energy, Q15
833 // data from subframe 1 (or 3)
834 Word16 sf1_code_nosharp[], // i : innovative codebook vector (L_SUBFR)
835 // (whithout pitch sharpening)
836 Word16 sf1_exp_gcode0, // i : predicted CB gain (exponent), Q0
837 Word16 sf1_frac_gcode0, // i : predicted CB gain (fraction), Q15
838 Word16 sf1_exp_coeff[], // i : energy coeff. (5), exponent part, Q0
839 Word16 sf1_frac_coeff[], // i : energy coeff. (5), fraction part, Q15
840 // (frac_coeff and exp_coeff computed in
841 // calc_filt_energies())
842 Word16 sf1_exp_target_en, // i : exponent of target energy, Q0
843 Word16 sf1_frac_target_en, // i : fraction of target energy, Q15
845 Word16 gp_limit, // i : pitch gain limit
847 Word16 *sf0_gain_pit, // o : Pitch gain, Q14
848 Word16 *sf0_gain_cod, // o : Code gain, Q1
850 Word16 *sf1_gain_pit, // o : Pitch gain, Q14
851 Word16 *sf1_gain_cod // o : Code gain, Q1
858 Word16 sf0_gcode0, sf1_gcode0;
859 Word16 g_pitch, g2_pitch, g_code, g2_code, g_pit_cod;
860 Word16 coeff[10], coeff_lo[10], exp_max[10]; // 0..4: sf0; 5..9: sf1
861 Word32 L_tmp, dist_min;
863 *-------------------------------------------------------------------*
864 * predicted codebook gain *
865 * ~~~~~~~~~~~~~~~~~~~~~~~ *
866 * gc0 = 2^exp_gcode0 + 2^frac_gcode0 *
868 * gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0) *
869 *-------------------------------------------------------------------*
871 sf0_gcode0 = extract_l(Pow2(14, sf0_frac_gcode0));
872 sf1_gcode0 = extract_l(Pow2(14, sf1_frac_gcode0));
874 * For each subframe, the error energy (sum) to be minimized consists
875 * of five terms, t[0..4].
877 * t[0] = gp^2 * <y1 y1>
878 * t[1] = -2*gp * <xn y1>
879 * t[2] = gc^2 * <y2 y2>
880 * t[3] = -2*gc * <xn y2>
881 * t[4] = 2*gp*gc * <y1 y2>
885 // determine the scaling exponent for g_code: ec = ec0 - 11
886 exp = sub(sf0_exp_gcode0, 11);
888 // calculate exp_max[i] = s[i]-1
889 exp_max[0] = sub(sf0_exp_coeff[0], 13);
890 exp_max[1] = sub(sf0_exp_coeff[1], 14);
891 exp_max[2] = add(sf0_exp_coeff[2], add(15, shl(exp, 1)));
892 exp_max[3] = add(sf0_exp_coeff[3], exp);
893 exp_max[4] = add(sf0_exp_coeff[4], add(1, exp));
896 // determine the scaling exponent for g_code: ec = ec0 - 11
897 exp = sub(sf1_exp_gcode0, 11);
899 // calculate exp_max[i] = s[i]-1
900 exp_max[5] = sub(sf1_exp_coeff[0], 13);
901 exp_max[6] = sub(sf1_exp_coeff[1], 14);
902 exp_max[7] = add(sf1_exp_coeff[2], add(15, shl(exp, 1)));
903 exp_max[8] = add(sf1_exp_coeff[3], exp);
904 exp_max[9] = add(sf1_exp_coeff[4], add(1, exp));
906 *-------------------------------------------------------------------*
907 * Gain search equalisation: *
908 * ~~~~~~~~~~~~~~~~~~~~~~~~~ *
909 * The MSE for the two subframes is weighted differently if there *
910 * is a big difference in the corresponding target energies *
911 *-------------------------------------------------------------------*
913 // make the target energy exponents the same by de-normalizing the
914 // fraction of the smaller one. This is necessary to be able to compare
917 exp = sf0_exp_target_en - sf1_exp_target_en;
920 sf1_frac_target_en = shr (sf1_frac_target_en, exp);
924 sf0_frac_target_en = shl (sf0_frac_target_en, exp);
927 // assume no change of exponents
930 // test for target energy difference; set exp to +1 or -1 to scale
931 // up/down coefficients for sf 1
933 tmp = shr_r (sf1_frac_target_en, 1); // tmp = ceil(0.5*en(sf1))
934 if (sub (tmp, sf0_frac_target_en) > 0) // tmp > en(sf0)?
936 // target_energy(sf1) > 2*target_energy(sf0)
937 // -> scale up MSE(sf0) by 2 by adding 1 to exponents 0..4
942 tmp = shr (add (sf0_frac_target_en, 3), 2); // tmp=ceil(0.25*en(sf0))
943 if (sub (tmp, sf1_frac_target_en) > 0) // tmp > en(sf1)?
945 // target_energy(sf1) < 0.25*target_energy(sf0)
946 // -> scale down MSE(sf0) by 0.5 by subtracting 1 from
952 for (i = 0; i < 5; i++)
954 exp_max[i] = add (exp_max[i], exp);
957 *-------------------------------------------------------------------*
958 * Find maximum exponent: *
959 * ~~~~~~~~~~~~~~~~~~~~~~ *
961 * For the sum operation, all terms must have the same scaling; *
962 * that scaling should be low enough to prevent overflow. There- *
963 * fore, the maximum scale is determined and all coefficients are *
966 * exp = max(exp_max[i]) + 1; *
967 * e = exp_max[i]-exp; e <= 0! *
969 *-------------------------------------------------------------------*
972 for (i = 1; i < 10; i++)
974 if (sub(exp_max[i], exp) > 0)
979 exp = add(exp, 1); // To avoid overflow
981 p = &sf0_frac_coeff[0];
982 for (i = 0; i < 5; i++) {
983 tmp = sub(exp, exp_max[i]);
984 L_tmp = L_deposit_h(*p++);
985 L_tmp = L_shr(L_tmp, tmp);
986 L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
988 p = &sf1_frac_coeff[0];
989 for (; i < 10; i++) {
990 tmp = sub(exp, exp_max[i]);
991 L_tmp = L_deposit_h(*p++);
992 L_tmp = L_shr(L_tmp, tmp);
993 L_Extract(L_tmp, &coeff[i], &coeff_lo[i]);
996 //-------------------------------------------------------------------*
1000 * For each pair (g_pitch, g_fac) in the table calculate the *
1001 * terms t[0..4] and sum them up; the result is the mean squared *
1002 * error for the quantized gains from the table. The index for the *
1003 * minimum MSE is stored and finally used to retrieve the quantized *
1005 *-------------------------------------------------------------------
1007 // start with "infinite" MSE
1010 p = &table_gain_MR475[0];
1012 for (i = 0; i < MR475_VQ_SIZE; i++)
1014 // subframe 0 (and 2) calculations
1018 g_code = mult(g_code, sf0_gcode0);
1019 g2_pitch = mult(g_pitch, g_pitch);
1020 g2_code = mult(g_code, g_code);
1021 g_pit_cod = mult(g_code, g_pitch);
1023 L_tmp = Mpy_32_16( coeff[0], coeff_lo[0], g2_pitch);
1024 L_tmp = Mac_32_16(L_tmp, coeff[1], coeff_lo[1], g_pitch);
1025 L_tmp = Mac_32_16(L_tmp, coeff[2], coeff_lo[2], g2_code);
1026 L_tmp = Mac_32_16(L_tmp, coeff[3], coeff_lo[3], g_code);
1027 L_tmp = Mac_32_16(L_tmp, coeff[4], coeff_lo[4], g_pit_cod);
1029 tmp = sub (g_pitch, gp_limit);
1031 // subframe 1 (and 3) calculations
1035 if (tmp <= 0 && sub(g_pitch, gp_limit) <= 0)
1037 g_code = mult(g_code, sf1_gcode0);
1038 g2_pitch = mult(g_pitch, g_pitch);
1039 g2_code = mult(g_code, g_code);
1040 g_pit_cod = mult(g_code, g_pitch);
1042 L_tmp = Mac_32_16(L_tmp, coeff[5], coeff_lo[5], g2_pitch);
1043 L_tmp = Mac_32_16(L_tmp, coeff[6], coeff_lo[6], g_pitch);
1044 L_tmp = Mac_32_16(L_tmp, coeff[7], coeff_lo[7], g2_code);
1045 L_tmp = Mac_32_16(L_tmp, coeff[8], coeff_lo[8], g_code);
1046 L_tmp = Mac_32_16(L_tmp, coeff[9], coeff_lo[9], g_pit_cod);
1048 // store table index if MSE for this index is lower
1049 than the minimum MSE seen so far
1050 if (L_sub(L_tmp, dist_min) < (Word32) 0)
1058 *------------------------------------------------------------------*
1059 * read quantized gains and update MA predictor memories *
1060 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
1061 *------------------------------------------------------------------*
1063 // for subframe 0, the pre-calculated gcode0/exp_gcode0 are the same
1064 // as those calculated from the "real" predictor using quantized gains
1065 tmp = shl(index, 2);
1066 MR475_quant_store_results(pred_st,
1067 &table_gain_MR475[tmp],
1073 // calculate new predicted gain for subframe 1 (this time using
1074 // the real, quantized gains)
1075 gc_pred(pred_st, MR475, sf1_code_nosharp,
1076 &sf1_exp_gcode0, &sf1_frac_gcode0,
1077 &sf0_exp_gcode0, &sf0_gcode0); // last two args are dummy
1078 sf1_gcode0 = extract_l(Pow2(14, sf1_frac_gcode0));
1081 MR475_quant_store_results(pred_st,
1082 &table_gain_MR475[tmp],
1091 ------------------------------------------------------------------------------
1093 [State any special notes, constraints or cautions for users of this function]
1095 ------------------------------------------------------------------------------
1098 Word16 MR475_gain_quant( /* o : index of quantization. */
1099 gc_predState *pred_st, /* i/o: gain predictor state struct */
1101 /* data from subframe 0 (or 2) */
1102 Word16 sf0_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
1103 Word16 sf0_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
1104 Word16 sf0_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
1105 Word16 sf0_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
1106 /* (frac_coeff and exp_coeff computed in */
1107 /* calc_filt_energies()) */
1108 Word16 sf0_exp_target_en, /* i : exponent of target energy, Q0 */
1109 Word16 sf0_frac_target_en, /* i : fraction of target energy, Q15 */
1111 /* data from subframe 1 (or 3) */
1112 Word16 sf1_code_nosharp[], /* i : innovative codebook vector (L_SUBFR) */
1113 /* (whithout pitch sharpening) */
1114 Word16 sf1_exp_gcode0, /* i : predicted CB gain (exponent), Q0 */
1115 Word16 sf1_frac_gcode0, /* i : predicted CB gain (fraction), Q15 */
1116 Word16 sf1_exp_coeff[], /* i : energy coeff. (5), exponent part, Q0 */
1117 Word16 sf1_frac_coeff[], /* i : energy coeff. (5), fraction part, Q15 */
1118 /* (frac_coeff and exp_coeff computed in */
1119 /* calc_filt_energies()) */
1120 Word16 sf1_exp_target_en, /* i : exponent of target energy, Q0 */
1121 Word16 sf1_frac_target_en, /* i : fraction of target energy, Q15 */
1123 Word16 gp_limit, /* i : pitch gain limit */
1125 Word16 *sf0_gain_pit, /* o : Pitch gain, Q14 */
1126 Word16 *sf0_gain_cod, /* o : Code gain, Q1 */
1128 Word16 *sf1_gain_pit, /* o : Pitch gain, Q14 */
1129 Word16 *sf1_gain_cod, /* o : Code gain, Q1 */
1130 Flag *pOverflow /* o : overflow indicator */
1146 Word16 coeff_lo[10];
1147 Word16 exp_max[10]; /* 0..4: sf0; 5..9: sf1 */
1151 /*-------------------------------------------------------------------*
1152 * predicted codebook gain *
1153 * ~~~~~~~~~~~~~~~~~~~~~~~ *
1154 * gc0 = 2^exp_gcode0 + 2^frac_gcode0 *
1156 * gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0) *
1157 *-------------------------------------------------------------------*/
1159 sf0_gcode0 = (Word16)(Pow2(14, sf0_frac_gcode0, pOverflow));
1160 sf1_gcode0 = (Word16)(Pow2(14, sf1_frac_gcode0, pOverflow));
1163 * For each subframe, the error energy (sum) to be minimized consists
1164 * of five terms, t[0..4].
1166 * t[0] = gp^2 * <y1 y1>
1167 * t[1] = -2*gp * <xn y1>
1168 * t[2] = gc^2 * <y2 y2>
1169 * t[3] = -2*gc * <xn y2>
1170 * t[4] = 2*gp*gc * <y1 y2>
1175 /* determine the scaling exponent for g_code: ec = ec0 - 11 */
1176 exp = sf0_exp_gcode0 - 11;
1178 /* calculate exp_max[i] = s[i]-1 */
1179 exp_max[0] = (sf0_exp_coeff[0] - 13);
1180 exp_max[1] = (sf0_exp_coeff[1] - 14);
1181 exp_max[2] = (sf0_exp_coeff[2] + (15 + (exp << 1)));
1182 exp_max[3] = (sf0_exp_coeff[3] + exp);
1183 exp_max[4] = (sf0_exp_coeff[4] + (1 + exp));
1186 /* determine the scaling exponent for g_code: ec = ec0 - 11 */
1187 exp = sf1_exp_gcode0 - 11;
1189 /* calculate exp_max[i] = s[i]-1 */
1190 exp_max[5] = (sf1_exp_coeff[0] - 13);
1191 exp_max[6] = (sf1_exp_coeff[1] - 14);
1192 exp_max[7] = (sf1_exp_coeff[2] + (15 + (exp << 1)));
1193 exp_max[8] = (sf1_exp_coeff[3] + exp);
1194 exp_max[9] = (sf1_exp_coeff[4] + (1 + exp));
1196 /*-------------------------------------------------------------------*
1197 * Gain search equalisation: *
1198 * ~~~~~~~~~~~~~~~~~~~~~~~~~ *
1199 * The MSE for the two subframes is weighted differently if there *
1200 * is a big difference in the corresponding target energies *
1201 *-------------------------------------------------------------------*/
1203 /* make the target energy exponents the same by de-normalizing the
1204 fraction of the smaller one. This is necessary to be able to compare
1207 exp = sf0_exp_target_en - sf1_exp_target_en;
1210 sf1_frac_target_en >>= exp;
1214 sf0_frac_target_en >>= (-exp);
1217 /* assume no change of exponents */
1220 /* test for target energy difference; set exp to +1 or -1 to scale
1221 * up/down coefficients for sf 1
1223 tmp = shr_r(sf1_frac_target_en, 1, pOverflow); /* tmp = ceil(0.5*en(sf1)) */
1225 if (tmp > sf0_frac_target_en) /* tmp > en(sf0)? */
1228 * target_energy(sf1) > 2*target_energy(sf0)
1229 * -> scale up MSE(sf0) by 2 by adding 1 to exponents 0..4
1235 tmp = ((sf0_frac_target_en + 3) >> 2); /* tmp=ceil(0.25*en(sf0)) */
1237 if (tmp > sf1_frac_target_en) /* tmp > en(sf1)? */
1240 * target_energy(sf1) < 0.25*target_energy(sf0)
1241 * -> scale down MSE(sf0) by 0.5 by subtracting 1 from
1248 for (i = 0; i < 5; i++)
1253 /*-------------------------------------------------------------------*
1254 * Find maximum exponent: *
1255 * ~~~~~~~~~~~~~~~~~~~~~~ *
1257 * For the sum operation, all terms must have the same scaling; *
1258 * that scaling should be low enough to prevent overflow. There- *
1259 * fore, the maximum scale is determined and all coefficients are *
1262 * exp = max(exp_max[i]) + 1; *
1263 * e = exp_max[i]-exp; e <= 0! *
1265 *-------------------------------------------------------------------*/
1268 for (i = 9; i > 0; i--)
1270 if (exp_max[i] > exp)
1275 exp++; /* To avoid overflow */
1277 p = &sf0_frac_coeff[0];
1278 for (i = 0; i < 5; i++)
1280 tmp = (exp - exp_max[i]);
1281 L_tmp = ((Word32)(*p++) << 16);
1282 L_tmp = L_shr(L_tmp, tmp, pOverflow);
1283 coeff[i] = (Word16)(L_tmp >> 16);
1284 coeff_lo[i] = (Word16)((L_tmp >> 1) - ((L_tmp >> 16) << 15));
1286 p = &sf1_frac_coeff[0];
1289 tmp = exp - exp_max[i];
1290 L_tmp = ((Word32)(*p++) << 16);
1291 L_tmp = L_shr(L_tmp, tmp, pOverflow);
1292 coeff[i] = (Word16)(L_tmp >> 16);
1293 coeff_lo[i] = (Word16)((L_tmp >> 1) - ((L_tmp >> 16) << 15));
1297 /*-------------------------------------------------------------------*
1298 * Codebook search: *
1299 * ~~~~~~~~~~~~~~~~ *
1301 * For each pair (g_pitch, g_fac) in the table calculate the *
1302 * terms t[0..4] and sum them up; the result is the mean squared *
1303 * error for the quantized gains from the table. The index for the *
1304 * minimum MSE is stored and finally used to retrieve the quantized *
1306 *-------------------------------------------------------------------*/
1308 /* start with "infinite" MSE */
1311 p = &table_gain_MR475[0];
1313 for (i = 0; i < MR475_VQ_SIZE; i++)
1315 /* subframe 0 (and 2) calculations */
1319 /* Need to be there OKA */
1320 g_code = (Word16)(((Word32) g_code * sf0_gcode0) >> 15);
1321 g2_pitch = (Word16)(((Word32) g_pitch * g_pitch) >> 15);
1322 g2_code = (Word16)(((Word32) g_code * g_code) >> 15);
1323 g_pit_cod = (Word16)(((Word32) g_code * g_pitch) >> 15);
1326 L_tmp = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch, pOverflow) +
1327 Mpy_32_16(coeff[1], coeff_lo[1], g_pitch, pOverflow) +
1328 Mpy_32_16(coeff[2], coeff_lo[2], g2_code, pOverflow) +
1329 Mpy_32_16(coeff[3], coeff_lo[3], g_code, pOverflow) +
1330 Mpy_32_16(coeff[4], coeff_lo[4], g_pit_cod, pOverflow);
1332 tmp = (g_pitch - gp_limit);
1334 /* subframe 1 (and 3) calculations */
1338 if ((tmp <= 0) && (g_pitch <= gp_limit))
1340 g_code = (Word16)(((Word32) g_code * sf1_gcode0) >> 15);
1341 g2_pitch = (Word16)(((Word32) g_pitch * g_pitch) >> 15);
1342 g2_code = (Word16)(((Word32) g_code * g_code) >> 15);
1343 g_pit_cod = (Word16)(((Word32) g_code * g_pitch) >> 15);
1345 L_tmp += (Mpy_32_16(coeff[5], coeff_lo[5], g2_pitch, pOverflow) +
1346 Mpy_32_16(coeff[6], coeff_lo[6], g_pitch, pOverflow) +
1347 Mpy_32_16(coeff[7], coeff_lo[7], g2_code, pOverflow) +
1348 Mpy_32_16(coeff[8], coeff_lo[8], g_code, pOverflow) +
1349 Mpy_32_16(coeff[9], coeff_lo[9], g_pit_cod, pOverflow));
1351 /* store table index if MSE for this index is lower
1352 than the minimum MSE seen so far */
1353 if (L_tmp < dist_min)
1361 /*------------------------------------------------------------------*
1362 * read quantized gains and update MA predictor memories *
1363 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *
1364 *------------------------------------------------------------------*/
1366 /* for subframe 0, the pre-calculated gcode0/exp_gcode0 are the same
1367 as those calculated from the "real" predictor using quantized gains */
1369 MR475_quant_store_results(pred_st,
1370 &table_gain_MR475[tmp],
1377 /* calculate new predicted gain for subframe 1 (this time using
1378 the real, quantized gains) */
1379 gc_pred(pred_st, MR475, sf1_code_nosharp,
1380 &sf1_exp_gcode0, &sf1_frac_gcode0,
1381 &sf0_exp_gcode0, &sf0_gcode0, /* dummy args */
1384 sf1_gcode0 = (Word16)(Pow2(14, sf1_frac_gcode0, pOverflow));
1387 MR475_quant_store_results(
1389 &table_gain_MR475[tmp],