comparison libtwamr/c1035pf.c @ 318:6fd6c5fc1aa4

libtwamr: integrate c1035pf.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 18 Apr 2024 18:04:10 +0000
parents
children
comparison
equal deleted inserted replaced
317:675597e63fd8 318:6fd6c5fc1aa4
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 : c1035pf.c
11 * Purpose : Searches a 35 bit algebraic codebook containing
12 * : 10 pulses in a frame of 40 samples.
13 *
14 ********************************************************************************
15 */
16 /*
17 ********************************************************************************
18 * MODULE INCLUDE FILE AND VERSION ID
19 ********************************************************************************
20 */
21 #include "namespace.h"
22 #include "c1035pf.h"
23 /*
24 ********************************************************************************
25 * INCLUDE FILES
26 ********************************************************************************
27 */
28 #include "typedef.h"
29 #include "basic_op.h"
30 #include "no_count.h"
31 #include "cnst.h"
32 #include "inv_sqrt.h"
33 #include "set_sign.h"
34 #include "cor_h.h"
35 #include "s10_8pf.h"
36 #include "graytab.h"
37
38 /*
39 ********************************************************************************
40 * LOCAL VARIABLES AND TABLES
41 ********************************************************************************
42 */
43 #define NB_PULSE 10
44
45 /*
46 ********************************************************************************
47 * LOCAL PROGRAM CODE
48 ********************************************************************************
49 */
50 static void q_p (
51 Word16 *ind, /* Pulse position */
52 Word16 n /* Pulse number */
53 )
54 {
55 Word16 tmp;
56
57 tmp = *ind; move16 ();
58
59 test ();
60 if (sub (n, 5) < 0)
61 {
62 *ind = (tmp & 0x8) | gray[tmp & 0x7]; logic16 (); logic16 ();
63 logic16 (); move16 ();
64 }
65 else
66 {
67 *ind = gray[tmp & 0x7]; logic16 (); move16 ();
68 }
69 }
70
71
72 /*************************************************************************
73 *
74 * FUNCTION: build_code()
75 *
76 * PURPOSE: Builds the codeword, the filtered codeword and index of the
77 * codevector, based on the signs and positions of 10 pulses.
78 *
79 *************************************************************************/
80
81 static void build_code (
82 Word16 codvec[], /* (i) : position of pulses */
83 Word16 sign[], /* (i) : sign of d[n] */
84 Word16 cod[], /* (o) : innovative code vector */
85 Word16 h[], /* (i) : impulse response of weighted synthesis filter*/
86 Word16 y[], /* (o) : filtered innovative code */
87 Word16 indx[] /* (o) : index of 10 pulses (sign+position) */
88 )
89 {
90 Word16 i, j, k, track, index, _sign[NB_PULSE];
91 Word16 *p0, *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8, *p9;
92 Word32 s;
93
94 for (i = 0; i < L_CODE; i++)
95 {
96 cod[i] = 0; move16 ();
97 }
98 for (i = 0; i < NB_TRACK; i++)
99 {
100 indx[i] = -1; move16 ();
101 }
102
103 for (k = 0; k < NB_PULSE; k++)
104 {
105 /* read pulse position */
106 i = codvec[k]; move16 ();
107 /* read sign */
108 j = sign[i]; move16 ();
109
110 index = mult (i, 6554); /* index = pos/5 */
111 /* track = pos%5 */
112 track = sub (i, extract_l (L_shr (L_mult (index, 5), 1)));
113 test ();
114 if (j > 0)
115 {
116 cod[i] = add (cod[i], 4096); move16 ();
117 _sign[k] = 8192; move16 ();
118
119 }
120 else
121 {
122 cod[i] = sub (cod[i], 4096); move16 ();
123 _sign[k] = -8192; move16 ();
124 index = add (index, 8);
125 }
126
127 test (); move16 ();
128 if (indx[track] < 0)
129 {
130 indx[track] = index; move16 ();
131 }
132 else
133 {
134 test (); logic16 (); logic16 ();
135 if (((index ^ indx[track]) & 8) == 0)
136 {
137 /* sign of 1st pulse == sign of 2nd pulse */
138
139 test ();
140 if (sub (indx[track], index) <= 0)
141 {
142 indx[track + 5] = index; move16 ();
143 }
144 else
145 {
146 indx[track + 5] = indx[track];
147 move16 ();
148 indx[track] = index; move16 ();
149 }
150 }
151 else
152 {
153 /* sign of 1st pulse != sign of 2nd pulse */
154
155 test (); logic16 (); logic16 ();
156 if (sub ((indx[track] & 7), (index & 7)) <= 0)
157 {
158 indx[track + 5] = indx[track];
159 move16 ();
160 indx[track] = index; move16 ();
161 }
162 else
163 {
164 indx[track + 5] = index; move16 ();
165 }
166 }
167 }
168 }
169
170 p0 = h - codvec[0]; move16 ();
171 p1 = h - codvec[1]; move16 ();
172 p2 = h - codvec[2]; move16 ();
173 p3 = h - codvec[3]; move16 ();
174 p4 = h - codvec[4]; move16 ();
175 p5 = h - codvec[5]; move16 ();
176 p6 = h - codvec[6]; move16 ();
177 p7 = h - codvec[7]; move16 ();
178 p8 = h - codvec[8]; move16 ();
179 p9 = h - codvec[9]; move16 ();
180
181 for (i = 0; i < L_CODE; i++)
182 {
183 s = 0; move32 ();
184 s = L_mac (s, *p0++, _sign[0]);
185 s = L_mac (s, *p1++, _sign[1]);
186 s = L_mac (s, *p2++, _sign[2]);
187 s = L_mac (s, *p3++, _sign[3]);
188 s = L_mac (s, *p4++, _sign[4]);
189 s = L_mac (s, *p5++, _sign[5]);
190 s = L_mac (s, *p6++, _sign[6]);
191 s = L_mac (s, *p7++, _sign[7]);
192 s = L_mac (s, *p8++, _sign[8]);
193 s = L_mac (s, *p9++, _sign[9]);
194 y[i] = round (s); move16 ();
195 }
196 }
197
198 /*
199 ********************************************************************************
200 * PUBLIC PROGRAM CODE
201 ********************************************************************************
202 */
203 /*************************************************************************
204 *
205 * FUNCTION: code_10i40_35bits()
206 *
207 * PURPOSE: Searches a 35 bit algebraic codebook containing 10 pulses
208 * in a frame of 40 samples.
209 *
210 * DESCRIPTION:
211 * The code contains 10 nonzero pulses: i0...i9.
212 * All pulses can have two possible amplitudes: +1 or -1.
213 * The 40 positions in a subframe are divided into 5 tracks of
214 * interleaved positions. Each track contains two pulses.
215 * The pulses can have the following possible positions:
216 *
217 * i0, i5 : 0, 5, 10, 15, 20, 25, 30, 35.
218 * i1, i6 : 1, 6, 11, 16, 21, 26, 31, 36.
219 * i2, i7 : 2, 7, 12, 17, 22, 27, 32, 37.
220 * i3, i8 : 3, 8, 13, 18, 23, 28, 33, 38.
221 * i4, i9 : 4, 9, 14, 19, 24, 29, 34, 39.
222 *
223 * Each pair of pulses require 1 bit for their signs and 6 bits for their
224 * positions (3 bits + 3 bits). This results in a 35 bit codebook.
225 * The function determines the optimal pulse signs and positions, builds
226 * the codevector, and computes the filtered codevector.
227 *
228 *************************************************************************/
229
230 void code_10i40_35bits (
231 Word16 x[], /* (i) : target vector */
232 Word16 cn[], /* (i) : residual after long term prediction */
233 Word16 h[], /* (i) : impulse response of weighted synthesis filter
234 h[-L_subfr..-1] must be set to zero */
235 Word16 cod[], /* (o) : algebraic (fixed) codebook excitation */
236 Word16 y[], /* (o) : filtered fixed codebook excitation */
237 Word16 indx[] /* (o) : index of 10 pulses (sign + position) */
238 )
239 {
240 Word16 ipos[NB_PULSE], pos_max[NB_TRACK], codvec[NB_PULSE];
241 Word16 dn[L_CODE], sign[L_CODE];
242 Word16 rr[L_CODE][L_CODE], i;
243
244 cor_h_x (h, x, dn, 2);
245 set_sign12k2 (dn, cn, sign, pos_max, NB_TRACK, ipos, STEP);
246 cor_h (h, sign, rr);
247
248 search_10and8i40 (NB_PULSE, STEP, NB_TRACK,
249 dn, rr, ipos, pos_max, codvec);
250
251 build_code (codvec, sign, cod, h, y, indx);
252 for (i = 0; i < 10; i++)
253 {
254 q_p (&indx[i], i);
255 }
256 return;
257 }