FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/d_gain_c.c @ 516:5353d7652f65
top Makefile: add hrutil
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 30 Aug 2024 08:15:41 +0000 |
parents | a723d9f9f697 |
children |
rev | line source |
---|---|
339
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : d_gain_c.c |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 /* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 * MODULE INCLUDE FILE AND VERSION ID |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "namespace.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "d_gain_c.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 /* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 * INCLUDE FILES |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "tw_amr.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "typedef.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "basic_op.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "oper_32b.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "no_count.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "cnst.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 #include "log2.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 #include "pow2.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 #include "gc_pred.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 #include "gains_tab.h" |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 /* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 * PUBLIC PROGRAM CODE |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 ******************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 /* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 ************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 * Function : d_gain_code |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 * Purpose : Decode the fixed codebook gain using the received index. |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ************************************************************************** |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 void d_gain_code ( |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 gc_predState *pred_state, /* i/o : MA predictor state */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 enum Mode mode, /* i : AMR mode (MR795 or MR122) */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 Word16 index, /* i : received quantization index */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 Word16 code[], /* i : innovation codevector */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 Word16 *gain_code /* o : decoded innovation gain */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 ) |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 { |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 Word16 gcode0, exp, frac; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 const Word16 *p; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 Word16 qua_ener_MR122, qua_ener; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 Word16 exp_inn_en; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 Word16 frac_inn_en; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 Word32 L_tmp; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 /*-------------- Decode codebook gain ---------------*/ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 /*-------------------------------------------------------------------* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 * predict codebook gain * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 * ~~~~~~~~~~~~~~~~~~~~~ * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 * gc0 = Pow2(int(d)+frac(d)) * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 * = 2^exp + 2^frac * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 * * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 *-------------------------------------------------------------------*/ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 gc_pred(pred_state, mode, code, &exp, &frac, |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 &exp_inn_en, &frac_inn_en); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 p = &qua_gain_code[add (add (index, index), index)]; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 /* Different scalings between MR122 and the other modes */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 test (); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 if (sub(mode, MR122) == 0) |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 gcode0 = extract_l (Pow2 (exp, frac)); /* predicted gain */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 gcode0 = shl (gcode0, 4); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 *gain_code = shl (mult (gcode0, *p++), 1); move16 (); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 else |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 { |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 gcode0 = extract_l (Pow2 (14, frac)); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 L_tmp = L_mult(*p++, gcode0); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 L_tmp = L_shr(L_tmp, sub(9, exp)); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 *gain_code = extract_h(L_tmp); /* Q1 */ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 /*-------------------------------------------------------------------* |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 * update table of past quantized energies * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 *-------------------------------------------------------------------*/ |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 qua_ener_MR122 = *p++; move16(); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 qua_ener = *p++; move16(); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 gc_pred_update(pred_state, qua_ener_MR122, qua_ener); |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 return; |
a723d9f9f697
libtwamr: integrate d_gain_c.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 } |