FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/dec_gain.c @ 356:5ccfe176bae1
libtwamr: integrate dec_gain.c
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 05 May 2024 22:24:42 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 355:9beb01439a90 | 356:5ccfe176bae1 |
|---|---|
| 1 /* | |
| 2 ******************************************************************************** | |
| 3 * | |
| 4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 | |
| 5 * R99 Version 3.3.0 | |
| 6 * REL-4 Version 4.1.0 | |
| 7 * | |
| 8 ******************************************************************************** | |
| 9 * | |
| 10 * File : dec_gain.c | |
| 11 * Purpose : Decode the pitch and codebook gains | |
| 12 * | |
| 13 ******************************************************************************** | |
| 14 */ | |
| 15 | |
| 16 /* | |
| 17 ******************************************************************************** | |
| 18 * MODULE INCLUDE FILE AND VERSION ID | |
| 19 ******************************************************************************** | |
| 20 */ | |
| 21 #include "namespace.h" | |
| 22 #include "dec_gain.h" | |
| 23 | |
| 24 /* | |
| 25 ******************************************************************************** | |
| 26 * INCLUDE FILES | |
| 27 ******************************************************************************** | |
| 28 */ | |
| 29 #include <stddef.h> | |
| 30 #include "tw_amr.h" | |
| 31 #include "typedef.h" | |
| 32 #include "basic_op.h" | |
| 33 #include "oper_32b.h" | |
| 34 #include "no_count.h" | |
| 35 #include "cnst.h" | |
| 36 #include "pow2.h" | |
| 37 #include "log2.h" | |
| 38 #include "gc_pred.h" | |
| 39 #include "qua_gain_tab.h" | |
| 40 | |
| 41 /* | |
| 42 ******************************************************************************** | |
| 43 * PUBLIC PROGRAM CODE | |
| 44 ******************************************************************************** | |
| 45 */ | |
| 46 | |
| 47 /************************************************************************* | |
| 48 * | |
| 49 * FUNCTION: Dec_gain() | |
| 50 * | |
| 51 * PURPOSE: Decode the pitch and codebook gains | |
| 52 * | |
| 53 ************************************************************************/ | |
| 54 void Dec_gain( | |
| 55 gc_predState *pred_state, /* i/o: MA predictor state */ | |
| 56 enum Mode mode, /* i : AMR mode */ | |
| 57 Word16 index, /* i : index of quantization. */ | |
| 58 Word16 code[], /* i : Innovative vector. */ | |
| 59 Word16 evenSubfr, /* i : Flag for even subframes */ | |
| 60 Word16 * gain_pit, /* o : Pitch gain. */ | |
| 61 Word16 * gain_cod /* o : Code gain. */ | |
| 62 ) | |
| 63 { | |
| 64 const Word16 *p; | |
| 65 Word16 frac, gcode0, exp, qua_ener, qua_ener_MR122; | |
| 66 Word16 g_code; | |
| 67 Word32 L_tmp; | |
| 68 | |
| 69 /* Read the quantized gains (table depends on mode) */ | |
| 70 index = shl (index, 2); | |
| 71 | |
| 72 test(); test(); test(); | |
| 73 if ( sub (mode, MR102) == 0 | |
| 74 || sub (mode, MR74) == 0 | |
| 75 || sub (mode, MR67) == 0) | |
| 76 { | |
| 77 p = &table_gain_highrates[index]; move16 (); | |
| 78 | |
| 79 *gain_pit = *p++; move16 (); | |
| 80 g_code = *p++; move16 (); | |
| 81 qua_ener_MR122 = *p++; move16 (); | |
| 82 qua_ener = *p; move16 (); | |
| 83 } | |
| 84 else | |
| 85 { | |
| 86 test(); | |
| 87 if (sub (mode, MR475) == 0) | |
| 88 { | |
| 89 index = add (index, shl(sub(1, evenSubfr), 1)); | |
| 90 p = &table_gain_MR475[index]; move16 (); | |
| 91 | |
| 92 *gain_pit = *p++; move16 (); | |
| 93 g_code = *p++; move16 (); | |
| 94 | |
| 95 /*---------------------------------------------------------* | |
| 96 * calculate predictor update values (not stored in 4.75 * | |
| 97 * quantizer table to save space): * | |
| 98 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| 99 * * | |
| 100 * qua_ener = log2(g) * | |
| 101 * qua_ener_MR122 = 20*log10(g) * | |
| 102 *---------------------------------------------------------*/ | |
| 103 | |
| 104 /* Log2(x Q12) = log2(x) + 12 */ | |
| 105 Log2 (L_deposit_l (g_code), &exp, &frac); | |
| 106 exp = sub(exp, 12); | |
| 107 | |
| 108 qua_ener_MR122 = add (shr_r (frac, 5), shl (exp, 10)); | |
| 109 | |
| 110 /* 24660 Q12 ~= 6.0206 = 20*log10(2) */ | |
| 111 L_tmp = Mpy_32_16(exp, frac, 24660); | |
| 112 qua_ener = round (L_shl (L_tmp, 13)); /* Q12 * Q0 = Q13 -> Q10 */ | |
| 113 } | |
| 114 else | |
| 115 { | |
| 116 p = &table_gain_lowrates[index]; move16 (); | |
| 117 | |
| 118 *gain_pit = *p++; move16 (); | |
| 119 g_code = *p++; move16 (); | |
| 120 qua_ener_MR122 = *p++; move16 (); | |
| 121 qua_ener = *p; move16 (); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 /*-------------------------------------------------------------------* | |
| 126 * predict codebook gain * | |
| 127 * ~~~~~~~~~~~~~~~~~~~~~ * | |
| 128 * gc0 = Pow2(int(d)+frac(d)) * | |
| 129 * = 2^exp + 2^frac * | |
| 130 * * | |
| 131 * gcode0 (Q14) = 2^14*2^frac = gc0 * 2^(14-exp) * | |
| 132 *-------------------------------------------------------------------*/ | |
| 133 | |
| 134 gc_pred(pred_state, mode, code, &exp, &frac, NULL, NULL); | |
| 135 | |
| 136 gcode0 = extract_l(Pow2(14, frac)); | |
| 137 | |
| 138 /*------------------------------------------------------------------* | |
| 139 * read quantized gains, update table of past quantized energies * | |
| 140 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * | |
| 141 * st->past_qua_en(Q10) = 20 * Log10(g_fac) / constant * | |
| 142 * = Log2(g_fac) * | |
| 143 * = qua_ener * | |
| 144 * constant = 20*Log10(2) * | |
| 145 *------------------------------------------------------------------*/ | |
| 146 | |
| 147 L_tmp = L_mult(g_code, gcode0); | |
| 148 L_tmp = L_shr(L_tmp, sub(10, exp)); | |
| 149 *gain_cod = extract_h(L_tmp); | |
| 150 | |
| 151 /* update table of past quantized energies */ | |
| 152 | |
| 153 gc_pred_update(pred_state, qua_ener_MR122, qua_ener); | |
| 154 | |
| 155 return; | |
| 156 } |
