comparison libtwamr/d8_31pf.c @ 335:03198f6b0427

libtwamr: integrate d8_31pf.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 18 Apr 2024 22:35:05 +0000
parents
children
comparison
equal deleted inserted replaced
334:dfaa8f322a8d 335:03198f6b0427
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 : d8_31pf.c
11 * Purpose : Builds the innovative codevector
12 *
13 ********************************************************************************
14 */
15
16 /*
17 ********************************************************************************
18 * MODULE INCLUDE FILE AND VERSION ID
19 ********************************************************************************
20 */
21 #include "namespace.h"
22 #include "d8_31pf.h"
23
24 /*
25 ********************************************************************************
26 * INCLUDE FILES
27 ********************************************************************************
28 */
29 #include "typedef.h"
30 #include "basic_op.h"
31 #include "no_count.h"
32 #include "cnst.h"
33
34 /*
35 ********************************************************************************
36 * LOCAL VARIABLES AND TABLES
37 ********************************************************************************
38 */
39 #define NB_PULSE 8 /* number of pulses */
40
41 /* define values/representation for output codevector and sign */
42 #define POS_CODE 8191
43 #define NEG_CODE 8191
44
45 static void decompress10 (
46 Word16 MSBs, /* i : MSB part of the index */
47 Word16 LSBs, /* i : LSB part of the index */
48 Word16 index1, /* i : index for first pos in pos_index[] */
49 Word16 index2, /* i : index for second pos in pos_index[] */
50 Word16 index3, /* i : index for third pos in pos_index[] */
51 Word16 pos_indx[]) /* o : position of 3 pulses (decompressed) */
52 {
53 Word16 ia, ib, ic;
54
55 /*
56 pos_indx[index1] = ((MSBs-25*(MSBs/25))%5)*2 + (LSBs-4*(LSBs/4))%2;
57 pos_indx[index2] = ((MSBs-25*(MSBs/25))/5)*2 + (LSBs-4*(LSBs/4))/2;
58 pos_indx[index3] = (MSBs/25)*2 + LSBs/4;
59 */
60
61 test ();
62 if (sub(MSBs, 124) > 0)
63 {
64 MSBs = 124; move16 ();
65 }
66
67 ia = mult(MSBs, 1311);
68 ia = sub(MSBs, extract_l(L_shr(L_mult(ia, 25), 1)));
69 ib = shl(sub(ia, extract_l(L_shr(L_mult(mult(ia, 6554), 5), 1))), 1);
70
71 ic = shl(shr(LSBs, 2), 2);
72 ic = sub(LSBs, ic);
73 pos_indx[index1] = add(ib, (ic & 1)); logic16 ();
74
75 ib = shl(mult(ia, 6554), 1);
76 pos_indx[index2] = add(ib, shr(ic, 1));
77
78 pos_indx[index3] = add(shl(mult(MSBs, 1311), 1), shr(LSBs, 2));
79
80 return;
81 }
82
83 /*************************************************************************
84 *
85 * FUNCTION: decompress_code()
86 *
87 * PURPOSE: decompression of the linear codewords to 4+three indeces
88 * one bit from each pulse is made robust to errors by
89 * minimizing the phase shift of a bit error.
90 * 4 signs (one for each track)
91 * i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust
92 * i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust
93 * i3,i7 => one index (5+2) bits, 2-3 LSbs more robust
94 *
95 *************************************************************************/
96 static void decompress_code (
97 Word16 indx[], /* i : position and sign of 8 pulses (compressed) */
98 Word16 sign_indx[], /* o : signs of 4 pulses (signs only) */
99 Word16 pos_indx[] /* o : position index of 8 pulses (position only) */
100 )
101 {
102 Word16 i, ia, ib, MSBs, LSBs, MSBs0_24;
103
104 for (i = 0; i < NB_TRACK_MR102; i++)
105 {
106 sign_indx[i] = indx[i]; move16 ();
107 }
108
109 /*
110 First index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
111 MSBs = indx[NB_TRACK]/8;
112 LSBs = indx[NB_TRACK]%8;
113 */
114 MSBs = shr(indx[NB_TRACK_MR102], 3);
115 LSBs = indx[NB_TRACK_MR102] & 7; logic16 ();
116 decompress10 (MSBs, LSBs, 0, 4, 1, pos_indx);
117
118 /*
119 Second index: 10x10x10 -> 2x5x2x5x2x5-> 125x2x2x2 -> 7+1x3 bits
120 MSBs = indx[NB_TRACK+1]/8;
121 LSBs = indx[NB_TRACK+1]%8;
122 */
123 MSBs = shr(indx[NB_TRACK_MR102+1], 3);
124 LSBs = indx[NB_TRACK_MR102+1] & 7; logic16 ();
125 decompress10 (MSBs, LSBs, 2, 6, 5, pos_indx);
126
127 /*
128 Third index: 10x10 -> 2x5x2x5-> 25x2x2 -> 5+1x2 bits
129 MSBs = indx[NB_TRACK+2]/4;
130 LSBs = indx[NB_TRACK+2]%4;
131 MSBs0_24 = (MSBs*25+12)/32;
132 if ((MSBs0_24/5)%2==1)
133 pos_indx[3] = (4-(MSBs0_24%5))*2 + LSBs%2;
134 else
135 pos_indx[3] = (MSBs0_24%5)*2 + LSBs%2;
136 pos_indx[7] = (MSBs0_24/5)*2 + LSBs/2;
137 */
138 MSBs = shr(indx[NB_TRACK_MR102+2], 2);
139 LSBs = indx[NB_TRACK_MR102+2] & 3; logic16 ();
140
141 MSBs0_24 = shr(add(extract_l(L_shr(L_mult(MSBs, 25), 1)), 12), 5);
142
143 ia = mult(MSBs0_24, 6554) & 1;
144 ib = sub(MSBs0_24, extract_l(L_shr(L_mult(mult(MSBs0_24, 6554), 5), 1)));
145
146 test ();
147 if (sub(ia, 1) == 0)
148 {
149 ib = sub(4, ib);
150 }
151 pos_indx[3] = add(shl(ib, 1), (LSBs & 1)); logic16 ();
152
153 ia = shl(mult(MSBs0_24, 6554), 1);
154 pos_indx[7] = add(ia, shr(LSBs, 1));
155 }
156
157 /*
158 ********************************************************************************
159 * PUBLIC PROGRAM CODE
160 ********************************************************************************
161 */
162 /*************************************************************************
163 *
164 * FUNCTION: dec_8i40_31bits()
165 *
166 * PURPOSE: Builds the innovative codevector from the received
167 * index of algebraic codebook.
168 *
169 * See c8_31pf.c for more details about the algebraic codebook structure.
170 *
171 *************************************************************************/
172
173 void dec_8i40_31bits (
174 Word16 index[], /* i : index of 8 pulses (sign+position) */
175 Word16 cod[] /* o : algebraic (fixed) codebook excitation */
176 )
177 {
178 Word16 i, j, pos1, pos2, sign;
179 Word16 linear_signs[NB_TRACK_MR102];
180 Word16 linear_codewords[NB_PULSE];
181
182 for (i = 0; i < L_CODE; i++)
183 {
184 cod[i] = 0; move16 ();
185 }
186
187 decompress_code (index, linear_signs, linear_codewords);
188
189 /* decode the positions and signs of pulses and build the codeword */
190
191 for (j = 0; j < NB_TRACK_MR102; j++)
192 {
193 /* compute index i */
194
195 i = linear_codewords[j];
196 i = extract_l (L_shr (L_mult (i, 4), 1));
197 pos1 = add (i, j); /* position of pulse "j" */
198
199 test ();
200 if (linear_signs[j] == 0)
201 {
202 sign = POS_CODE; move16 (); /* +1.0 */
203 }
204 else
205 {
206 sign = -NEG_CODE; move16 (); /* -1.0 */
207 }
208
209 cod[pos1] = sign; move16 ();
210
211 /* compute index i */
212
213 i = linear_codewords[add (j, 4)];
214 i = extract_l (L_shr (L_mult (i, 4), 1));
215 pos2 = add (i, j); /* position of pulse "j+4" */
216
217 test ();
218 if (sub (pos2, pos1) < 0)
219 {
220 sign = negate (sign);
221 }
222 cod[pos2] = add (cod[pos2], sign); move16 ();
223 }
224
225 return;
226 }