FreeCalypso > hg > gsm-codec-lib
annotate libtwamr/q_gain_p.c @ 430:edbbbf1c4ab1
implement twamr-tseq-dec test program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 23:35:41 +0000 |
parents | a01de4e40540 |
children |
rev | line source |
---|---|
369
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * GSM AMR-NB speech codec R98 Version 7.6.0 December 12, 2001 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * R99 Version 3.3.0 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * REL-4 Version 4.1.0 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 * |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 * File : q_gain_p.c |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 * Purpose : Scalar quantization of the pitch gain |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 * |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 /* |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 * MODULE INCLUDE FILE AND VERSION ID |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include "namespace.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "q_gain_p.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 /* |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 * INCLUDE FILES |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 #include "tw_amr.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 #include "typedef.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 #include "basic_op.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 #include "oper_32b.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include "no_count.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 #include "cnst.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 #include "gains_tab.h" |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 * PUBLIC PROGRAM CODE |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 ******************************************************************************** |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 Word16 q_gain_pitch ( /* Return index of quantization */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 enum Mode mode, /* i : AMR mode */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 Word16 gp_limit, /* i : pitch gain limit */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 Word16 *gain, /* i/o: Pitch gain (unquant/quant), Q14 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 Word16 gain_cand[], /* o : pitch gain candidates (3), MR795 only, Q14 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 Word16 gain_cind[] /* o : pitch gain cand. indices (3),MR795 only, Q0 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 ) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 Word16 i, index, err, err_min; |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 err_min = abs_s (sub (*gain, qua_gain_pitch[0])); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 index = 0; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 for (i = 1; i < NB_QUA_PITCH; i++) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 test (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (sub (qua_gain_pitch[i], gp_limit) <= 0) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 err = abs_s (sub (*gain, qua_gain_pitch[i])); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 test (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (sub (err, err_min) < 0) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 err_min = err; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 index = i; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 test (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (sub (mode, MR795) == 0) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 /* in MR795 mode, compute three gain_pit candidates around the index |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 * found in the quantization loop: the index found and the two direct |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 * neighbours, except for the extreme cases (i=0 or i=NB_QUA_PITCH-1), |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 * where the direct neighbour and the neighbour to that is used. |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 Word16 ii; |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 test (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (index == 0) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 ii = index; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 else |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 test (); test (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if ( sub (index, NB_QUA_PITCH-1) == 0 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 || sub (qua_gain_pitch[index+1], gp_limit) > 0) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 ii = sub (index, 2); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 else |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 ii = sub (index, 1); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 /* store candidate indices and values */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 for (i = 0; i < 3; i++) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 gain_cind[i] = ii; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 gain_cand[i] = qua_gain_pitch[ii]; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 ii = add (ii, 1); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 *gain = qua_gain_pitch[index]; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 else |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 /* in MR122 mode, just return the index and gain pitch found. |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 * If bitexactness is required, mask away the two LSBs (because |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 * in the original EFR, gain_pit was scaled Q12) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 test (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 if (sub(mode, MR122) == 0) |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 /* clear 2 LSBits */ |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 *gain = qua_gain_pitch[index] & 0xFFFC; logic16 (); move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 else |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 { |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 *gain = qua_gain_pitch[index]; move16 (); |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 } |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 return index; |
a01de4e40540
libtwamr: integrate q_gain_p.c
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |