PandA-2024.02
lpc.c
Go to the documentation of this file.
1 /*
2 +--------------------------------------------------------------------------+
3 | CHStone : a suite of benchmark programs for C-based High-Level Synthesis |
4 | ======================================================================== |
5 | |
6 | * Collected and Modified : Y. Hara, H. Tomiyama, S. Honda, |
7 | H. Takada and K. Ishii |
8 | Nagoya University, Japan |
9 | |
10 | * Remark : |
11 | 1. This source code is modified to unify the formats of the benchmark |
12 | programs in CHStone. |
13 | 2. Test vectors are added for CHStone. |
14 | 3. If "main_result" is 0 at the end of the program, the program is |
15 | correctly executed. |
16 | 4. Please follow the copyright of each benchmark program. |
17 +--------------------------------------------------------------------------+
18 */
19 /*
20  * Copyright 1992 by Jutta Degener and Carsten Bormann, Technische
21  * Universitaet Berlin. See the accompanying file "COPYRIGHT" for
22  * details. THERE IS ABSOLUTELY NO WARRANTY FOR THIS SOFTWARE.
23  */
24 
25 /* $Header: /home/kbs/jutta/src/gsm/gsm-1.0/src/RCS/lpc.c,v 1.5 1994/12/30 23:14:54 jutta Exp $ */
26 
27 #include "private.h"
28 #include "add.c"
29 
30 
31 /*
32  * 4.2.4 .. 4.2.7 LPC ANALYSIS SECTION
33  */
34 
35 /* 4.2.4 */
36 
37 
38 void
39 Autocorrelation (word * s /* [0..159] IN/OUT */ ,
40  longword * L_ACF /* [0..8] OUT */ )
41 /*
42  * The goal is to compute the array L_ACF[k]. The signal s[i] must
43  * be scaled in order to avoid an overflow situation.
44  */
45 {
46  register int k, i;
47 
48  word temp;
49  word smax;
50  word scalauto, n;
51  word *sp;
52  word sl;
53 
54  /* Search for the maximum.
55  */
56  smax = 0;
57  for (k = 0; k <= 159; k++)
58  {
59  temp = GSM_ABS (s[k]);
60  if (temp > smax)
61  smax = temp;
62  }
63 
64  /* Computation of the scaling factor.
65  */
66  if (smax == 0)
67  scalauto = 0;
68  else
69  scalauto = 4 - gsm_norm ((longword) smax << 16); /* sub(4,..) */
70 
71  if (scalauto > 0 && scalauto <= 4)
72  {
73  n = scalauto;
74  for (k = 0; k <= 159; k++)
75  s[k] = GSM_MULT_R (s[k], 16384 >> (n - 1));
76  }
77 
78  /* Compute the L_ACF[..].
79  */
80  {
81  sp = s;
82  sl = *sp;
83 
84 #define STEP(k) L_ACF[k] += ((longword)sl * sp[ -(k) ]);
85 
86 #define NEXTI sl = *++sp
87  for (k = 8; k >= 0; k--)
88  L_ACF[k] = 0;
89 
90  STEP (0);
91  NEXTI;
92  STEP (0);
93  STEP (1);
94  NEXTI;
95  STEP (0);
96  STEP (1);
97  STEP (2);
98  NEXTI;
99  STEP (0);
100  STEP (1);
101  STEP (2);
102  STEP (3);
103  NEXTI;
104  STEP (0);
105  STEP (1);
106  STEP (2);
107  STEP (3);
108  STEP (4);
109  NEXTI;
110  STEP (0);
111  STEP (1);
112  STEP (2);
113  STEP (3);
114  STEP (4);
115  STEP (5);
116  NEXTI;
117  STEP (0);
118  STEP (1);
119  STEP (2);
120  STEP (3);
121  STEP (4);
122  STEP (5);
123  STEP (6);
124  NEXTI;
125  STEP (0);
126  STEP (1);
127  STEP (2);
128  STEP (3);
129  STEP (4);
130  STEP (5);
131  STEP (6);
132  STEP (7);
133 
134  for (i = 8; i <= 159; i++)
135  {
136 
137  NEXTI;
138 
139  STEP (0);
140  STEP (1);
141  STEP (2);
142  STEP (3);
143  STEP (4);
144  STEP (5);
145  STEP (6);
146  STEP (7);
147  STEP (8);
148  }
149 
150  for (k = 8; k >= 0; k--)
151  L_ACF[k] <<= 1;
152 
153  }
154  /* Rescaling of the array s[0..159]
155  */
156  if (scalauto > 0)
157  for (k = 159; k >= 0; k--)
158  *s++ <<= scalauto;
159 }
160 
161 /* 4.2.5 */
162 
163 void
164 Reflection_coefficients (longword * L_ACF /* 0...8 IN */ ,
165  register word * r /* 0...7 OUT */ )
166 {
167  register int i, m, n;
168  register word temp;
169  word ACF[9]; /* 0..8 */
170  word P[9]; /* 0..8 */
171  word K[9]; /* 2..8 */
172 
173  /* Schur recursion with 16 bits arithmetic.
174  */
175 
176  if (L_ACF[0] == 0)
177  {
178  for (i = 8; i > 0; i--)
179  *r++ = 0;
180  return;
181  }
182 
183  temp = gsm_norm (L_ACF[0]);
184  for (i = 0; i <= 8; i++)
185  ACF[i] = SASR (L_ACF[i] << temp, 16);
186 
187  /* Initialize array P[..] and K[..] for the recursion.
188  */
189 
190  for (i = 1; i <= 7; i++)
191  K[i] = ACF[i];
192  for (i = 0; i <= 8; i++)
193  P[i] = ACF[i];
194 
195  /* Compute reflection coefficients
196  */
197  for (n = 1; n <= 8; n++, r++)
198  {
199 
200  temp = P[1];
201  temp = GSM_ABS (temp);
202  if (P[0] < temp)
203  {
204  for (i = n; i <= 8; i++)
205  *r++ = 0;
206  return;
207  }
208 
209  *r = gsm_div (temp, P[0]);
210 
211  if (P[1] > 0)
212  *r = -*r; /* r[n] = sub(0, r[n]) */
213  if (n == 8)
214  return;
215 
216  /* Schur recursion
217  */
218  temp = GSM_MULT_R (P[1], *r);
219  P[0] = GSM_ADD (P[0], temp);
220 
221  for (m = 1; m <= 8 - n; m++)
222  {
223  temp = GSM_MULT_R (K[m], *r);
224  P[m] = GSM_ADD (P[m + 1], temp);
225 
226  temp = GSM_MULT_R (P[m + 1], *r);
227  K[m] = GSM_ADD (K[m], temp);
228  }
229  }
230 }
231 
232 /* 4.2.6 */
233 
234 void
235 Transformation_to_Log_Area_Ratios (register word * r /* 0..7 IN/OUT */ )
236 /*
237  * The following scaling for r[..] and LAR[..] has been used:
238  *
239  * r[..] = integer( real_r[..]*32768. ); -1 <= real_r < 1.
240  * LAR[..] = integer( real_LAR[..] * 16384 );
241  * with -1.625 <= real_LAR <= 1.625
242  */
243 {
244  register word temp;
245  register int i;
246 
247 
248  /* Computation of the LAR[0..7] from the r[0..7]
249  */
250  for (i = 1; i <= 8; i++, r++)
251  {
252 
253  temp = *r;
254  temp = GSM_ABS (temp);
255 
256  if (temp < 22118)
257  {
258  temp >>= 1;
259  }
260  else if (temp < 31130)
261  {
262  temp -= 11059;
263  }
264  else
265  {
266  temp -= 26112;
267  temp <<= 2;
268  }
269 
270  *r = *r < 0 ? -temp : temp;
271  }
272 }
273 
274 /* 4.2.7 */
275 
276 void
277 Quantization_and_coding (register word * LAR /* [0..7] IN/OUT */ )
278 {
279  register word temp;
280 
281 
282  /* This procedure needs four tables; the following equations
283  * give the optimum scaling for the constants:
284  *
285  * A[0..7] = integer( real_A[0..7] * 1024 )
286  * B[0..7] = integer( real_B[0..7] * 512 )
287  * MAC[0..7] = maximum of the LARc[0..7]
288  * MIC[0..7] = minimum of the LARc[0..7]
289  */
290 
291 # undef STEP
292 # define STEP( A, B, MAC, MIC ) \
293  temp = GSM_MULT( A, *LAR ); \
294  temp = GSM_ADD( temp, B ); \
295  temp = GSM_ADD( temp, 256 ); \
296  temp = SASR( temp, 9 ); \
297  *LAR = temp>MAC ? MAC - MIC : (temp<MIC ? 0 : temp - MIC); \
298  LAR++;
299 
300  STEP (20480, 0, 31, -32);
301  STEP (20480, 0, 31, -32);
302  STEP (20480, 2048, 15, -16);
303  STEP (20480, -2560, 15, -16);
304 
305  STEP (13964, 94, 7, -8);
306  STEP (15360, -1792, 7, -8);
307  STEP (8534, -341, 3, -4);
308  STEP (9036, -1144, 3, -4);
309 
310 # undef STEP
311 }
312 
313 void
314 __attribute__ ((noinline))
315 Gsm_LPC_Analysis (word * s /* 0..159 signals IN/OUT */ ,
316  word * LARc /* 0..7 LARc's OUT */ )
317 {
318  longword L_ACF[9];
319 
320  Autocorrelation (s, L_ACF);
321  Reflection_coefficients (L_ACF, LARc);
324 }
#define NEXTI
#define GSM_ABS(a)
Definition: private.h:41
#define GSM_ADD(a, b)
Definition: private.h:40
void Autocorrelation(word *s, longword *L_ACF)
Definition: lpc.c:39
#define GSM_MULT_R(a, b)
Definition: private.h:38
const size_t P
Definition: helm.c:5
void Reflection_coefficients(longword *L_ACF, register word *r)
Definition: lpc.c:164
static const uint32_t k[]
Definition: sha-256.c:22
void Transformation_to_Log_Area_Ratios(register word *r)
Definition: lpc.c:235
word gsm_norm(longword a)
Definition: add.c:91
#define SASR(x, by)
Definition: private.h:36
void __attribute__((noinline))
Definition: lpc.c:314
short word
Definition: private.h:30
long longword
Definition: private.h:31
#define STEP(k)
void Quantization_and_coding(register word *LAR)
Definition: lpc.c:277
void Gsm_LPC_Analysis(word *s, word *LARc)
Definition: lpc.c:314
word gsm_div(word num, word denum)
Definition: add.c:126
int sl
Definition: adpcm.c:105

Generated on Mon Feb 12 2024 13:02:49 for PandA-2024.02 by doxygen 1.8.13