FreeCalypso > hg > gsm-codec-lib
comparison libtwamr/cbsearch.c @ 328:4614f1a97e1a
libtwamr: integrate cbsearch.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 18 Apr 2024 20:35:02 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
327:2df212a012af | 328:4614f1a97e1a |
---|---|
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 : cbsearch.c | |
11 * Purpose : Inovative codebook search (find index and gain) | |
12 * | |
13 ***************************************************************************** | |
14 */ | |
15 | |
16 /* | |
17 ***************************************************************************** | |
18 * MODULE INCLUDE FILE AND VERSION ID | |
19 ***************************************************************************** | |
20 */ | |
21 #include "namespace.h" | |
22 #include "cbsearch.h" | |
23 | |
24 /* | |
25 ***************************************************************************** | |
26 * INCLUDE FILES | |
27 ***************************************************************************** | |
28 */ | |
29 #include "tw_amr.h" | |
30 #include "typedef.h" | |
31 #include "c2_9pf.h" | |
32 #include "c2_11pf.h" | |
33 #include "c3_14pf.h" | |
34 #include "c4_17pf.h" | |
35 #include "c8_31pf.h" | |
36 #include "c1035pf.h" | |
37 #include "basic_op.h" | |
38 #include "no_count.h" | |
39 #include "cnst.h" | |
40 | |
41 /* | |
42 ***************************************************************************** | |
43 * PUBLIC PROGRAM CODE | |
44 ***************************************************************************** | |
45 */ | |
46 int cbsearch(Word16 x[], /* i : target vector, Q0 */ | |
47 Word16 h[], /* i : impulse response of weighted synthesis */ | |
48 /* filter h[-L_subfr..-1] must be set to */ | |
49 /* zero. Q12 */ | |
50 Word16 T0, /* i : Pitch lag */ | |
51 Word16 pitch_sharp, /* i : Last quantized pitch gain, Q14 */ | |
52 Word16 gain_pit, /* i : Pitch gain, Q14 */ | |
53 Word16 res2[], /* i : Long term prediction residual, Q0 */ | |
54 Word16 code[], /* o : Innovative codebook, Q13 */ | |
55 Word16 y[], /* o : filtered fixed codebook excitation, Q12 */ | |
56 Word16 **anap, /* o : Signs of the pulses */ | |
57 enum Mode mode,/* i : coder mode */ | |
58 Word16 subNr) /* i : subframe number */ | |
59 { | |
60 Word16 index; | |
61 Word16 i, temp, pit_sharpTmp; | |
62 | |
63 /* For MR74, the pre and post CB pitch sharpening is included in the | |
64 * codebook search routine, while for MR122 is it not. | |
65 */ | |
66 | |
67 test (); test (); | |
68 if ((sub (mode, MR475) == 0) || (sub (mode, MR515) == 0)) | |
69 { /* MR475, MR515 */ move16 (); | |
70 *(*anap)++ = code_2i40_9bits(subNr, x, h, T0, pitch_sharp, | |
71 code, y, &index); | |
72 *(*anap)++ = index; /* sign index */ move16 (); | |
73 } | |
74 else if (sub (mode, MR59) == 0) | |
75 { /* MR59 */ | |
76 test (); move16 (); | |
77 *(*anap)++ = code_2i40_11bits(x, h, T0, pitch_sharp, code, y, &index); | |
78 *(*anap)++ = index; /* sign index */ move16 (); | |
79 } | |
80 else if (sub (mode, MR67) == 0) | |
81 { /* MR67 */ | |
82 test (); test (); move16 (); | |
83 *(*anap)++ = code_3i40_14bits(x, h, T0, pitch_sharp, code, y, &index); | |
84 *(*anap)++ = index; /* sign index */ move16 (); | |
85 } | |
86 else if (sub (mode, MR74) == 0 || sub (mode, MR795) == 0) | |
87 { /* MR74, MR795 */ | |
88 test (); test (); test (); move16 (); | |
89 *(*anap)++ = code_4i40_17bits(x, h, T0, pitch_sharp, code, y, &index); | |
90 *(*anap)++ = index; /* sign index */ move16 (); | |
91 } | |
92 else if (sub (mode, MR102) == 0) | |
93 { /* MR102 */ | |
94 test (); test (); test (); | |
95 /*-------------------------------------------------------------* | |
96 * - include pitch contribution into impulse resp. h1[] * | |
97 *-------------------------------------------------------------*/ | |
98 /* pit_sharpTmp = pit_sharp; */ | |
99 /* if (pit_sharpTmp > 1.0) pit_sharpTmp = 1.0; */ | |
100 pit_sharpTmp = shl (pitch_sharp, 1); | |
101 for (i = T0; i < L_SUBFR; i++) | |
102 { | |
103 temp = mult(h[i - T0], pit_sharpTmp); | |
104 h[i] = add(h[i], temp); move16 (); | |
105 } | |
106 | |
107 /*--------------------------------------------------------------* | |
108 * - Innovative codebook search (find index and gain) * | |
109 *--------------------------------------------------------------*/ | |
110 code_8i40_31bits (x, res2, h, code, y, *anap); | |
111 *anap += 7; add(0,0); | |
112 | |
113 /*-------------------------------------------------------* | |
114 * - Add the pitch contribution to code[]. * | |
115 *-------------------------------------------------------*/ | |
116 for (i = T0; i < L_SUBFR; i++) | |
117 { | |
118 temp = mult (code[i - T0], pit_sharpTmp); | |
119 code[i] = add (code[i], temp); move16 (); | |
120 } | |
121 } | |
122 else | |
123 { /* MR122 */ | |
124 /*-------------------------------------------------------------* | |
125 * - include pitch contribution into impulse resp. h1[] * | |
126 *-------------------------------------------------------------*/ | |
127 test (); test (); test (); | |
128 | |
129 /* pit_sharpTmp = gain_pit; */ | |
130 /* if (pit_sharpTmp > 1.0) pit_sharpTmp = 1.0; */ | |
131 pit_sharpTmp = shl (gain_pit, 1); | |
132 | |
133 for (i = T0; i < L_SUBFR; i++) | |
134 { | |
135 temp = mult(h[i - T0], pit_sharpTmp); | |
136 h[i] = add(h[i], temp); move16 (); | |
137 } | |
138 /*--------------------------------------------------------------* | |
139 * - Innovative codebook search (find index and gain) * | |
140 *--------------------------------------------------------------*/ | |
141 | |
142 code_10i40_35bits (x, res2, h, code, y, *anap); | |
143 *anap += 10; add(0,0); | |
144 | |
145 /*-------------------------------------------------------* | |
146 * - Add the pitch contribution to code[]. * | |
147 *-------------------------------------------------------*/ | |
148 for (i = T0; i < L_SUBFR; i++) | |
149 { | |
150 temp = mult (code[i - T0], pit_sharpTmp); | |
151 code[i] = add (code[i], temp); move16 (); | |
152 } | |
153 } | |
154 | |
155 return 0; | |
156 } |